From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6BDE2BD59C for ; Sun, 8 Feb 2026 12:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770553234; cv=none; b=faqHN9/VQc7OdPJzVwcQh3gJOyOWcIX6pOB2pBU0D0d6GnKqyQXbiu8GDIO+DoByPerahV7T+7hgdakOsUh/8VHo6YTLyCqL5qrpwalUb24InaiHV5cW0UtLjlPGqsc4Lppi1gCuICClSHJ+6+5qM6AIOlDl7oty0ZOuWGji8v4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770553234; c=relaxed/simple; bh=cNGME1z/2FHjs5tDwJPrDCbngIkdr6inUI31OBkTxNY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P7u6EdiQUY+t6t7g+PaRhjat0dL4vOySGUf1yrZNBR1YnmUsXn3xJBCrm2s+JqVqe/upPqjznYjyjD/izHsuDVt48cHVkR89AGYDGjroXFMud8JvJ0ENuZXaB2nt0Hv3St81nXHdPcMF+eUuH1JEuKZckk1qtUwiXZ/Yd8G11J0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gMh+qrQb; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gMh+qrQb" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48336a6e932so3363805e9.3 for ; Sun, 08 Feb 2026 04:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770553233; x=1771158033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=BpyoA+sLfLCuUDLoMqnmdj586SoJamCxKwvb3GMgJ8g=; b=gMh+qrQbYUc0F4geO+agggh8ufdjIyD4s1aAjGGB/MupdeY8Aw+NTQB62frEImp3wt fMZMr9OUioxiODLwxCTU9I9oSK9WQIPVmd+kk1aYo/VEyXjvTbC/SFQv9c7t/rIsRvzO LVHbn/eGegJ8yn6VA6Vg+8OcBVIaC66oE9bvveUtbenWczY38A0CPW72ZW5ALXYb0Tkv 865VCfINzmenQtKsa0Ha/mp1XLUWIg5RGFgWJ16N1Yw4aQXTLS1Y6t5QDXsB+EVzEPho 8rBflRwvI1fOrzThkU6a974Nb/ndjS4lTgZFS9y2egn1EbevrPHwERFfC1NXzuFMYwj3 tYyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770553233; x=1771158033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BpyoA+sLfLCuUDLoMqnmdj586SoJamCxKwvb3GMgJ8g=; b=bv76iVdCa2JNPPF3CgZ2mkYozU29s8Bi8N/tCgzyHjnPqOLsqSLUV20v4N/oDfJa9R 5juWHxK4iCzExzX7VLv0f0Km/1q3GatHfATaqzysInAFWJJdmRLqKa/+7pV2XkS9J3A1 kq544HnIOhNlE+XY0ugUJyZodYPOmwisxJbm5QTXgXJeh+cEmSWws1Esb7nl8KBQyP7U iEc0l+XfD4vVXyP/vgvN3yg0n/sxvXNvZ4Qd7KyMEFVVSW34sHCx6FM01m7diJwbwInw k64y1N4BRu+QP8NL7qpgut4GkuTODkIe4nmTT1KfXzxbo1hCP+wxeFvuFJQ5kaH5b4BL GM5A== X-Forwarded-Encrypted: i=1; AJvYcCWvm7M3iWiWGN7riJc44vZmjeS4SCMg/MLnIriPl1PFuvaIwKHh6MxTl4AaeR7pzScMSvUDMhuWQkhm/Wc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1hJylje68lyYGjcjgERwLw71jhh1FyytCKsLv/zrMZuS7vueU jW7SVTW0RSwzZhlrGAY5bLhsIgAj5h+4sG0dWhrckwENzh5DlZUZPMc2 X-Gm-Gg: AZuq6aIMLQCMMK6y8p0l1aaHB66W2vrzzfrtOzdIaXiL3BRdCSQOwjH/JTVZ7FCsnEB 8KAZdagerXhCEsf+Lz9j4OH7izKpgFLiAs5w2ZxtVAcQdgv+bJOHbBMDj2FbeiQhFNJKiQYisoA GHPlhm8pEnwTel/6G8H9HJytc5ub5Js3LMx/JeLtJGfCqD7p9FmUr9efjuN18pzsTQqHd8JawqH lxIRBoJNIpKD+u/lg/MIQL7HkD0qK54dL9PN1uoVrgOCc9rPHevu7UJK+5j5i2U3tvmOyK6XPRL 2KbQj6kflfBu6sAxiTX8Q/SxRQTzq9Xto3SSyDW3tpUGKsN0ooAi7I6qj8UOD+BsdmFOYlt0xt3 D0PZNyY0eBGAg55lQfQrnbvC9NLwI+HT0ZFNmi65xBAsTIha6BzIby0YgLwQ5JVvzxGCAKj6tX+ oil2y8KoNm0i5vRfNZnejHbM6wJ+R9c5R1v6PO6Q2TIIboOHz6YpYJ X-Received: by 2002:a05:600c:3b03:b0:47d:403e:4eaf with SMTP id 5b1f17b1804b1-483201e4011mr127903475e9.10.1770553232787; Sun, 08 Feb 2026 04:20:32 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43637e31a01sm9346312f8f.27.2026.02.08.04.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Feb 2026 04:20:32 -0800 (PST) Date: Sun, 8 Feb 2026 12:20:31 +0000 From: David Laight To: Willy Tarreau Cc: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH v2 next 05/11] tools/nolibc/printf: Simplify __nolibc_printf() Message-ID: <20260208122031.355dc213@pumpkin> In-Reply-To: <20260207235019.40f82fca@pumpkin> References: <20260206191121.3602-1-david.laight.linux@gmail.com> <20260206191121.3602-6-david.laight.linux@gmail.com> <20260207235019.40f82fca@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 7 Feb 2026 23:50:19 +0000 David Laight wrote: > On Sat, 7 Feb 2026 21:05:42 +0100 > Willy Tarreau wrote: > > > On Fri, Feb 06, 2026 at 07:11:15PM +0000, david.laight.linux@gmail.com wrote: > > > From: David Laight > > > > > > Move the check for the length modifiers into the format processing > > > between the field width and conversion specifier. > > > This lets the loop be simplified and a 'fast scan' for a format start > > > used. > > > > > > If an error is detected (eg an invalid conversion specifier) then > > > copy the invalid format to the output buffer. > > > > > > Reduces code size by about 10% on x86-64. > > > > I'm surprised, because for me it's the opposite: > > > > $ size hello-patch* > > text data bss dec hex filename > > 1859 48 24 1931 78b hello-patch1 > > 2071 48 24 2143 85f hello-patch2 > > 2091 48 24 2163 873 hello-patch3 > > 2422 48 24 2494 9be hello-patch4 > > > > The whole program grew by almost 16%, and that's a 30% increase since > > the first patch. This is with gcc 15 -Oz. aarch64 however decreased by > > 15 bytes since previous patch. > > > > I have not figured what makes this change yet, I'm still digging. > > Running scripts/bloat-o-meter will give more detail. > > > Willy > > I'm using gcc 12.2 and just running 'make O=xxx' for the test program. > The object looks like what I'd expect, so might be -O2. > > Is it constant folding the #defines. > For me it generating the (1 << (c & 31)) & 0xxxxx as you might hope. Further thoughts: On some of the builds I've done gcc duplicated the code following an 'if' into both the 'then' and 'else' clauses. This isn't good for code size. At one point I had an OPTIMIZER_HIDE_VAR(sign) before the u64to...() block which did help, but that wasn't needed after the last patch or in the patch sequence I posted. (Maybe the 'if (v == 0) ...' block makes a difference.) It might also be worth including the patch that changes u64to...() before doing the size checks. gcc should inline the wrappers - so it definitely changes the way the code is generated. To add octal support (for completeness) I'd explicitly generate the three sets of constants in the printf() code and then call _nolibc_utoa_base(). The octal support is (approx): else if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'o') { base = 8; recip = _NOLIBC_U64TOA_RECIP(8); if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, '#' - 1) sign = '0'; } The last bit could be: sign = ((ch_flags >> n) & 1) * '0'; gcc might be persuaded to do that, but probably needs help. David