lkml.org 
[lkml]   [2022]   [Jun]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v4 11/34] vsprintf: Improve number()
From
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

\
 
 \ /
  Last update: 2022-06-21 10:34    [W:0.443 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site