Re: [PATCH 2/2] lib: call native hex_to_bin() inside _kstrtoull()

From: Andy Shevchenko
Date: Mon Jul 18 2011 - 15:05:15 EST


Anyway, I wrote the small performance test case (you can see it in a
new series), which shows significant reduction of the performance
(~12%). So, just drop this patch.

On Mon, Jul 18, 2011 at 1:31 PM, Alexey Dobriyan <adobriyan@xxxxxxxxx> wrote:
> On Mon, Jul 18, 2011 at 11:23 AM, Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>> --- a/lib/kstrtox.c
>> +++ b/lib/kstrtox.c
>> @@ -39,25 +39,18 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
>> Â Â Â Âacc = 0;
>> Â Â Â Âok = 0;
>> Â Â Â Âwhile (*s) {
>> - Â Â Â Â Â Â Â unsigned int val;
>> + Â Â Â Â Â Â Â int val;
>>
>> - Â Â Â Â Â Â Â if ('0' <= *s && *s <= '9')
>> - Â Â Â Â Â Â Â Â Â Â Â val = *s - '0';
>> - Â Â Â Â Â Â Â else if ('a' <= TOLOWER(*s) && TOLOWER(*s) <= 'f')
>> - Â Â Â Â Â Â Â Â Â Â Â val = TOLOWER(*s) - 'a' + 10;
>> - Â Â Â Â Â Â Â else if (*s == '\n' && *(s + 1) == '\0')
>> + Â Â Â Â Â Â Â if (unlikely(*s == '\n' && *(s + 1) == '\0'))
>> Â Â Â Â Â Â Â Â Â Â Â Âbreak;
>> - Â Â Â Â Â Â Â else
>> - Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;
>>
>> - Â Â Â Â Â Â Â if (val >= base)
>> + Â Â Â Â Â Â Â val = hex_to_bin(*s++);
>> + Â Â Â Â Â Â Â if (val >= base || val < 0)
>> Â Â Â Â Â Â Â Â Â Â Â Âreturn -EINVAL;
>> Â Â Â Â Â Â Â Âif (acc > div_u64(ULLONG_MAX - val, base))
>> Â Â Â Â Â Â Â Â Â Â Â Âreturn -ERANGE;
>> Â Â Â Â Â Â Â Âacc = acc * base + val;
>> Â Â Â Â Â Â Â Âok = 1;
>> -
>> - Â Â Â Â Â Â Â s++;
>> Â Â Â Â}
>> Â Â Â Âif (!ok)
>> Â Â Â Â Â Â Â Âreturn -EINVAL;
>
> 1. unlikely() and s++ move don't have anything to do with changes
> 2. I don't understand desire to use some half-thought out API,
> Â in fact, restricting to radix 16 is arbitrary.
> Â Without such restriction hex_to_bin doesn't make sense.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>



--
With Best Regards,
Andy Shevchenko
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—