Re: [PATCH v4 11/34] vsprintf: Improve number()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux