lkml.org 
[lkml]   [2010]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: hex_to_bin speedup
1) First of all, I'd worry about code size far more than speed.
this is not fast-path code.
2) Second, given that you're already doing a range test,
the fastest way to perform a tolower() is "c |= 0x20".

Generally it's something like:
int hex_to_bin(char ch)
{
ch -= '0';
if ((unsigned char)ch <= 9)
return ch;
ch |= 0x20;
ch -= 'a' - '0';
if ((unsigned char)ch <= 6)
return ch+10
return -1;
}


that produces the even smaller code:
hex_to_bin_or:
movb 4(%esp), %dl
subl $48, %edx
cmpb $9, %dl
movsbl %dl,%eax
jbe .L10
orl $32, %edx
orl $-1, %eax
subl $49, %edx
cmpb $6, %dl
ja .L10
movsbl %dl,%eax
addl $10, %eax
.L10:
ret



\
 
 \ /
  Last update: 2010-05-28 23:41    [W:0.030 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site