Re: [LAD] Bit shift

From: <karl@email-addr-hidden>
Date: Wed Mar 13 2019 - 01:09:17 EET

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
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@lists.linuxaudio.org
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Wed Mar 13 04:15:01 2019

This archive was generated by hypermail 2.1.8 : Wed Mar 13 2019 - 04:15:01 EET