• [^] # Re: Tu utilises un tableau

    Posté par . En réponse au message Coût d'un accès mémoire.. Évalué à 1.

    Chez moi ça marche.

    static const uint8_t func[256] = {232, 21, 174 /*.....*/};
    static uint8_t macros_are_for_wimps(uint8_t v) {
     return func[v];
    }
    int main(int argc, char* argv[]) {
     if (argc <= 1)
     return 0;
     return macros_are_for_wimps(atoi(argv[1]));
    }
    
    
    main:
    .LFB1:
     .cfi_startproc
     movl 0,ドル %eax
     cmpl 1,ドル %edi
     jle .L6
     subq 8,ドル %rsp
     .cfi_def_cfa_offset 16
     movq 8(%rsi), %rdi
     call atoi
     movzbl %al, %eax
     movzbl func(%rax), %eax <------
     addq 8,ドル %rsp
     .cfi_def_cfa_offset 8
    .L6:
     rep
     ret
     .cfi_endproc
    
    

    Et c'est du gcc -O, hein, c'est presque le flag d'optimisation que je met tout le temps même en debug.