[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <82fb021d-31bb-4545-cbcc-a7622dbd2e0a@rasmusvillemoes.dk>
Date: Tue, 21 Jun 2022 10:33:37 +0200
From: Rasmus Villemoes <linux@...musvillemoes.dk>
To: Kent Overstreet <kent.overstreet@...il.com>,
linux-kernel@...r.kernel.org, linux-mm@...ck.org, pmladek@...e.com
Cc: rostedt@...dmis.org, enozhatsky@...omium.org, willy@...radead.org
Subject: Re: [PATCH v4 11/34] vsprintf: Improve number()
On 20/06/2022 02.42, Kent Overstreet wrote:
> /* generate full string in tmp[], in reverse order */
> - i = 0;
> - if (num < spec.base)
> - tmp[i++] = hex_asc_upper[num] | locase;
Please don't remove that optimization in a patch titled "improve number()".
> - else if (spec.base != 10) { /* 8 or 16 */
> + if (spec.base == 10) {
> + nr_digits = put_dec(tmp, num) - tmp;
> + } else { /* 8 or 16 */
> int mask = spec.base - 1;
> - int shift = 3;
> + int shift = ilog2((unsigned) spec.base);
>
> - if (spec.base == 16)
> - shift = 4;
So avoiding a branch here may be a good idea, but I'm not sure ilog2()
is very efficient on all arches. Since we know that base is either 8 or
16, we could do "shift = (spec.base/8) + 2".
Rasmus
Powered by blists - more mailing lists