From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 330DB3502A7 for ; Sat, 7 Feb 2026 15:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770476815; cv=none; b=OJww2zzZpV88qfwWN9rmEzY46XBGKhwPQhfb7vqCRC3NFZ5+RlwZd3gq8lisHtpWE3vIpUMicoHbz6YOXLUcrSOcoFqVxrSdqjcNr/HH64KCeSU8/iQIwOLa3/ZQ4b2RxN9nO2j6JTqdPCqsbfoxq+aMZx2XbFPxZ1stgKe4Rnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770476815; c=relaxed/simple; bh=+uBmqLkRMd08ZvPZ6fDMSyTBZrv5tvtS3QoJDzY1goo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ShY6EaJhIUunxaeGYAFPvo7Bbou1U7lX2+RbNzs9rlEE7QlaYzVL3w8kwsbXlTqDCj7M8bQqEFl2MXFCDvsXA9OHmLptmGEkSKuhSdS+56KnJNm+TVNMUjgv5qmjGehz495EVzAKa9Dq3/+VWAxeIydwWKWxeXAPK2H6trUuzuA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=ntzU9HPc; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="ntzU9HPc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1770476812; bh=AA9DVw5IoB+ey/ElEl9Rk0Ys16BF3h73igv2zhIpx0g=; h=From:Message-ID:From; b=ntzU9HPchED0lPYVyZqsWBODyk5WLnt5YtHD9JZhgqJ4v35c+kmVYS6aHjJlWFfP+ EE6Dy1h7g9Yhw2gL8LZKiWLXiWrl/yWL0BKxsLLBQ3mKsa5CcJzl2/h6KF6kh5CQgl U4zqxrE67LgBZ6S5TiQEyT7jxchQx2eo2f2gQwiA= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 2402DC0B44; Sat, 07 Feb 2026 16:06:52 +0100 (CET) Date: Sat, 7 Feb 2026 16:06:51 +0100 From: Willy Tarreau To: david.laight.linux@gmail.com Cc: Thomas =?iso-8859-1?Q?Wei=DFschuh?= , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH next] tools/nolibc: Optimise and common up number to ascii functions Message-ID: References: <20260203151316.24506-1-david.laight.linux@gmail.com> 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-Disposition: inline In-Reply-To: <20260203151316.24506-1-david.laight.linux@gmail.com> Hi David, On Tue, Feb 03, 2026 at 03:13:15PM +0000, david.laight.linux@gmail.com wrote: > From: David Laight > > 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 down. > Also makes it cheap to add octal support to vfprintf for completeness. > > Signed-off-by: David Laight OK, I had a long series of tests on it, including with older compilers going back to gcc-4.7 and on various archs. Except for code that would previously only use utoh(), the new code is slightly smaller in the vast majority of cases. And this combined with the added flexibility looks like a good addition. The code is not trivial (as every time we're dealing with number representation) but it's well documented, so I'm personally fine with the change. I'm just having a few comments below: > -static __attribute__((unused)) > -int utoh_r(unsigned long in, char *buffer) > +#define __U64TOA_RECIP(base) ((base) & 1 ? ~0ull / (base) : (1ull << 63) / ((base) / 2)) Please rename this macro to have _NOBLIC_ as a prefix. > +#if defined(__SIZEOF_INT128__) && !defined(__mips__) Out of curiosity, why !mips ? I tried with -mabi=64 and the function size dropped from 0x120 to 0xc0 (lost 1/3 of its size). > + q = ((unsigned __int128)in * recip) >> 64; > +#else (...) Once the macro is renamed, feel free to add: Acked-by: Willy Tarreau Thanks! Willy