Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fastest way to single hex digit => decimal

Name: Anonymous 2012-01-06 8:46

char hexchartodec_map[256] = {
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  0,  0,  0,  0,  0,  0,
        0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
};

char hexchartodec(char i) {
        return hexchartodec_map[i];
}

Name: Anonymous 2012-01-06 14:13

>>6
GHC -S -O:
    movq %r14,%rax
    movq %rax,%rcx
    andq $64,%rcx
    sarq $6,%rcx
    movq %rax,%rdx
    andq $15,%rdx
    addq $9,%rdx
    imulq %rcx,%rdx
    movq %rax,%rcx
    andq $16,%rcx
    sarq $4,%rcx
    movq %rax,%rbx
    andq $15,%rbx
    imulq %rcx,%rbx
    addq %rdx,%rbx
    jmp *0(%rbp)


GCC -march=core2 -O4 -S (on a simple C conversion taking unsigned char and returning unsigned int):
    movzbl  %dil, %edi
    movl    %edi, %edx
    movl    %edi, %eax
    andl    $64, %edi
    andl    $16, %edx
    andl    $15, %eax
    sarl    $6, %edi
    sarl    $4, %edx
    imull   %eax, %edx
    addl    $9, %eax
    imull   %edi, %eax
    addl    %edx, %eax
    ret

Name: Anonymous 2012-01-06 14:16

>>15
GHC -fvia-c -S -O:
    movq    %r14, %rax
    movq    %r14, %rdx
    andl    $15, %edx
    movq    %r14, %rcx
    andl    $16, %ecx
    sarq    $4, %rcx
    imulq   %rdx, %rcx
    andl    $64, %eax
    sarq    $6, %rax
    addq    $9, %rdx
    imulq   %rax, %rdx
    leaq    (%rcx,%rdx), %rbx
    jmp *0(%rbp)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List