[LAD] Bit shift

Will J Godfrey WillGodfrey at musically.me.uk
Sat Mar 16 22:45:43 CET 2019


On Wed, 13 Mar 2019 00:09:17 +0100 (CET)
karl at aspodata.se wrote:

>Will Godfrey:
>> Does anyone know if GCC will replace power of 2 multiplications/divisions of
>> unsigned integers with bit shifts?  
>
>Test on your system:
>
>$ cat a.c
>#include <stdint.h>
>
>int main(int argc, char *argv[]) {
>  uint16_t b = argc * 2;
>
>  return b;
>}
>$ gcc -S a.c 
>$ cat a.s 
>...
>main:
>.LFB0:
>        .cfi_startproc
>        pushq   %rbp
>        .cfi_def_cfa_offset 16
>        .cfi_offset 6, -16
>        movq    %rsp, %rbp
>        .cfi_def_cfa_register 6
>        movl    %edi, -20(%rbp)
>        movq    %rsi, -32(%rbp)
>        movl    -20(%rbp), %eax
>        addl    %eax, %eax
>        movw    %ax, -2(%rbp)
>        movzwl  -2(%rbp), %eax
>        popq    %rbp
>        .cfi_def_cfa 7, 8
>        ret
>        .cfi_endproc
>...
>$
>
>It seems it just adds the value with itself here.
>
>Regards,
>/Karl Hammar

Thanks, that seems to hold true for a mixture of AMD and Intel machines.

-- 
It wasn't me! (Well actually, it probably was)

... the hard part is not dodging what life throws at you,
but trying to catch the good bits.


More information about the Linux-audio-dev mailing list