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 0B239284665 for ; Sun, 8 Feb 2026 16:54:28 +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=1770569669; cv=none; b=NMHtQt98XdL119NM0rqaSUfCs0nDxW149EPNkz03iQ+E2BcBTaQv4Gbr1YXH9EQEoNBsPs15+QoXPG26uYngKRZJUT+9OwLlQit51PbUcu86L4och5yCZE7GfQfh989aTiE6xJHULvZLVEc7vzDaX2XXV7nu4JmKEm6KeqCxOhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770569669; c=relaxed/simple; bh=+/caJYbhmgP+CyXgnZOH1KScYan/HrLMS9437GQkMJc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FBD2I/YITw3yxzg81FZymJZP0pIpGAHsMt/a/rgZP/wRtrsxZJ/DPCa/luNOcSsJD3G/AbY+77s0z3e9mEKi/3Ws1Ss+LKc1O/5DVwk307hf/3bJ9Y/K4osRJiXwJ8+DDjGRnyWLM7x87okdfojoZAvEKzQ+DEpkTi96rymwcdA= 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=aA1R2X1n; 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="aA1R2X1n" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48336a6e932so4152805e9.3 for ; Sun, 08 Feb 2026 08:54:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770569667; x=1771174467; 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=8JeEiZ4q/mQg8cW3OGzW+tQfMQfL/3Z+cS/pgAgfdt0=; b=aA1R2X1njXEnodd7YglADtzu/q5YJ8FnH0942aXCXM0LQ3ycZgaXcJSMX5m1PYEuvJ y+w2pwLICwFgE1ZXkEThtM8llEsfqp8m9pqUW2LJ+dsTyoujMsrV2mGYAuyUYVSPmYiz VFgsczNjHVWP09fbL0HAiOz/Bu8HlhbVXlc+7Pks8WZbjbYQZRROfdd7l6OLYfIvN0H+ 0mi3blJkEp+GZlHvnJDiYNfxCcnZCqDoDFKw/SjTWoQobfVRpjsU4o0xpP3wBsOfHnXI Z1qQ1VwEuEqktuIZl/u9TxhqvA31cnYWVFEtVV57JTdeEQGjcNlMOqSd8AqnrJG5JUxJ rSuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770569667; x=1771174467; 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=8JeEiZ4q/mQg8cW3OGzW+tQfMQfL/3Z+cS/pgAgfdt0=; b=YbM8RC+I6+/roQ7KtQXl5P5Ih3dwpWn/JuGcMR0SK4azeBtWKNnBCZrBc82VuBWDtZ X8mJIBDNPNyE89rd7LCBNP/LBom3cR5i/aFrygXRu9XPHOjH+Bfgtih+/Osq7O9pVw23 0QzqkTs4pFcZ+ljuACiufTDpXQDHdswFJqJmSNHmiH9crG0BP7WgDhL6E7P/PZmAdHzv HQSVXlgZjj/hmG7BA1wwR2Da3mtgwLLRz6a/Rv6D95M7lfr+xvTm0XT4+e0hvqt1ov3o aF7UePJHfQKRzTqgmq5RcT+DQCR0ujwrPb4/RvTssqDoCs3GE1fPaqefYutrorDQ5DKF 78uw== X-Forwarded-Encrypted: i=1; AJvYcCUNLQ6jfkz2JhFnuBNy30fGd9rhwVze8lYDZX0auf2rZ/eFuXG39vnSpQsPj9+bWw0Lo017te0J49b4Cqk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+MKOyUBOfY2rOAzM9NiwL25v0jA5KVQK+FMe5JQ5dEs7xRZMy WSI8xmHS2HqRbyjpQebeVkN03ef3f+pYdn0EzgRpXeQrdU5QxiYuLc5k X-Gm-Gg: AZuq6aLqP4dIFNcfpcxt09eQKNMakE5mXn93KFV/qyZ4E7P8z5xfoeSpZviOzLHvcH/ 2wkUcqnw29b/CdO5NUvoy0Qd09VRtmcUNNnjNOHrz68JIeW+K8JIzzbRK8OU41SxW1vsXqZfKTt TDekM6sVv79j1eHZF5aoqirmKyppLJJKQls+724wR4RWEqZs+dzHsnVmi5AgfJgS+ALdbmF5BUa GxiETWQZZ6zotd9SpTM+AlzjTxSzCfJeEo/RF9qutVnIRcropFuQjhcrOxw4cjJe7ZO0LR13aem GSGK4vc/AcB51pCI3/uN74uSnrXgxDUxB5VaUPohBoFNHWwEjBJbZ/91h7Xd4YjOKaGrS0rfp+Y +Yr6EVc1UH8CATABlBSIZn2fTdogIk0lhh2qM1vCPA2QZF3ZeNdggM0h8wrYIvMOO/R8mTPLJPp XsUuxJy6Ec88ka4ZsgDR6Zs5vrDJOl9wNL5y1sieup7/s1sz725Sie X-Received: by 2002:a05:600c:3553:b0:477:9976:9e1a with SMTP id 5b1f17b1804b1-483201dc5bamr126509385e9.6.1770569667225; Sun, 08 Feb 2026 08:54:27 -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 5b1f17b1804b1-48317d33f5fsm270401895e9.5.2026.02.08.08.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Feb 2026 08:54:26 -0800 (PST) Date: Sun, 8 Feb 2026 16:54:25 +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: <20260208165425.3ffd67dc@pumpkin> In-Reply-To: References: <20260206191121.3602-1-david.laight.linux@gmail.com> <20260206191121.3602-6-david.laight.linux@gmail.com> <20260207235019.40f82fca@pumpkin> <20260208122031.355dc213@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 Sun, 8 Feb 2026 15:44:29 +0100 Willy Tarreau wrote: > Hi David, > > On Sun, Feb 08, 2026 at 12:20:31PM +0000, David Laight wrote: > > 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. > > That's common in loops for example. That's also one reason for avoiding > "else" statements in compact code. > > However here I finally found what inflates the code, when disassembling > the whole function: with the move of the multiple "if" statements, > recent compilers managed to turn it into a jump table, that considerably > inflates .rodata and the function as well. By passing -fno-jump-tables, > the size drops by ~500 bytes: That is just insane... That might go away with the patch that changes is all to bit-masks. I'd done some full disassembly comparisons myself to see why changes made the code larger. I had an OPTIMIZER_HIDE_VAR(sign) in there to help, but the final version didn't need it. What this sort of code needs is something to force the compiler to only have one copy of something - I found a proposal for an attribute (or similar) for an asm block to do that, but nothing came of it. > > text data bss dec hex filename > 2422 48 24 2494 9be hello-patch4 > 1917 48 24 1989 7c5 hello-patch4-alt <--- > > Building with gcc before 13 also avoids this table and explains why > you had better code with gcc-12. > > I also noticed that we can reduce the loop by ~40 bytes by moving the > literal copy after after the block that deals with format sequences, > because it eases comparisons, but that's no big deal for now since your > subsequent patches are going to change all that. Some of the early patches are carefully arranged to reduce churn later on. I might add the 'if (v == 0)' clause much earlier to avoid the churn cause by the extra indent when it is added. I'll add some extra comments as you suggested in the other patches. I do know all about optimising for size, and for the 'worst case path'. The latter was some embedded hdlc code that had to finish in 196 clocks. David > > At least I wanted to understand what was causing this difference for > us both, and whether it risked remaining definitive or not, so now > this patch is OK to me. > > Acked-by: Willy Tarreau > > Willy