Re: x86 gcc lacks simple optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 6 Dec 2013, Konstantin Vladimirov wrote:

Consider code:

int foo(char *t, char *v, int w)
{
int i;

for (i = 1; i != w; ++i)
{
int x = i << 2;

A side note, but something too few people seem to be aware of: writing i<<2 can pessimize code compared to i*4 (and it is never faster). That is because, at a high level, signed multiplication overflow is undefined behavior while shift isn't. At a low level, gcc knows it can implement *4 as a shift anyway.

v[x + 4] = t[x + 4];
}

return 0;
}

--
Marc Glisse




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux