Will Godfrey: > On Wed, 13 Mar 2019 00:09:17 +0100 (CET) > k...@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@lists.linuxaudio.org https://lists.linuxaudio.org/listinfo/linux-audio-dev