[LAD] Bit shift

Jonathan Brickman jeb at ponderworthy.com
Sun Mar 17 17:56:40 CET 2019


That is likely to change depending on GCC optimization setting, no?

J.E.B.

On Sat, Mar 16, 2019, 5:12 PM <karl at aspodata.se> wrote:

> Will Godfrey:
> > 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?
> ...
> > >$ cat a.c
> > >#include <stdint.h>
> > >
> > >int main(int argc, char *argv[]) {
> > >  uint16_t b = argc * 2;
> > >
> > >  return b;
> > >}
> > >$ gcc -S a.c
> ,,,
> > >It seems it just adds the value with itself here.
> ...
> > Thanks, that seems to hold true for a mixture of AMD and Intel machines.
>
> BTW, testing with 4, 8 and 16 instead of 2, it does actually do bit
> shifts:
>
> $ diff a.02.s a.04.s
> 16c16
> <       addl    %eax, %eax
> ---
> >       sall    $2, %eax
> $ diff a.02.s a.08.s
> 16c16
> <       addl    %eax, %eax
> ---
> >       sall    $3, %eax
> $ diff a.02.s a.16.s
> 16c16
> <       addl    %eax, %eax
> ---
> >       sall    $4, %eax
>
> Regards,
> /Karl Hammar
> _______________________________________________
> Linux-audio-dev mailing list
> Linux-audio-dev at lists.linuxaudio.org
> https://lists.linuxaudio.org/listinfo/linux-audio-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.linuxaudio.org/archives/linux-audio-dev/attachments/20190317/a6c02a6f/attachment.html>


More information about the Linux-audio-dev mailing list