Re: [PATCH v2 next 04/11] tools/nolibc/printf: Output pad characters in 16 byte chunks

From: David Laight

Date: Sat Feb 07 2026 - 18:43:17 EST


On Sat, 7 Feb 2026 20:38:36 +0100
Willy Tarreau <w@xxxxxx> wrote:

> On Fri, Feb 06, 2026 at 07:11:14PM +0000, david.laight.linux@xxxxxxxxx wrote:
> > From: David Laight <david.laight.linux@xxxxxxxxx>
> >
> > Simple to do and saves calls to the callback function.
>
> +20 bytes here but OK for me.

I think some of those come back when I change all the variables to 'int'.
Some, but not all, is because width is 32bit but len is 64bit.
The final change that did:
width -= len;
...
while (width > 0)
saved a surprising amount provided the ... contained some code.
Breath on the code (or compiler version) and you easily get +/-60 bytes.

David

>
> > Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
>
> Acked-by: Willy Tarreau <w@xxxxxx>
>
> > ---
> >
> > Changes for v2:
> > Formally patch 3, unchanged.
> >
> > tools/include/nolibc/stdio.h | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
> > index 552f09d51d82..c044a6b3babe 100644
> > --- a/tools/include/nolibc/stdio.h
> > +++ b/tools/include/nolibc/stdio.h
> > @@ -355,10 +355,12 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list
> > outstr = fmt;
> > len = ofs - 1;
> > flush_str:
> > - while (width-- > len) {
> > - if (cb(state, " ", 1) != 0)
> > + while (width > len) {
> > + unsigned int pad_len = ((width - len - 1) & 15) + 1;
> > + width -= pad_len;
> > + written += pad_len;
> > + if (cb(state, " ", pad_len) != 0)
> > return -1;
> > - written += 1;
> > }
> > if (cb(state, outstr, len) != 0)
> > return -1;
>
> Willy