Re: [PATCH v3 next 02/17] tools/nolibc: Optimise and common up the number to ascii functions

From: David Laight

Date: Wed Feb 25 2026 - 17:09:14 EST


On Wed, 25 Feb 2026 22:40:29 +0100
Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:

> On 2026-02-23 10:17:20+0000, david.laight.linux@xxxxxxxxx wrote:
> > From: David Laight <david.laight.linux@xxxxxxxxx>
> >
> > Implement u[64]to[ah]_r() using a common function that uses multiply
> > by reciprocal to generate the least significant digit first and then
> > reverses the string.
> >
> > On 32bit this is five multiplies (with 64bit product) for each output
> > digit. I think the old utoa_r() always did 36 multiplies and a lot
> > of subtracts - so this is likely faster even for 32bit values.
> > Definitely better for 64bit values (especially small ones).
> >
> > Clearly shifts are faster for base 16, but reversing the output buffer
> > makes a big difference.
> >
> > Sharing the code reduces the footprint (unless gcc decides to constant
> > fold the functions).
> > Definitely helps vfprintf() where the constants get loaded and a single
> > call is done.
> > Also makes it cheap to add octal support to vfprintf for completeness.
> >
> > Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
>
> Applied, thanks.
>
> Some changes I did:
> * Do not use int128 for sparc on clang, as it will also use __multi3.
> * Apply Willy's Ack from v1.

Thanks.
I thought I'd gone through looking for Acks - must have missed that one.

David

>
> (...)