by JoshTriplett · 9y ago · 0 comments
#include <stdint.h>
uint32_t testFunction(uint32_t x)
{
return ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | ((x & 0xff000000) >> 24);
}
compiles into: testFunction(unsigned int):
mov eax, edi
bswap eax
ret
Another fun one, that only works with clang: #include <stdint.h>
int testFunction(uint64_t x)
{
int count;
for (count = 0; x; count++)
x &= x - 1;
return count;
}
compiles into: testFunction(unsigned long):
popcnt rax, rdi
rethttps://github.com/llvm-mirror/llvm/blob/master/lib/Transfor...
A smart compiler would not use the new SSE version. (perhaps you didn't set the flags right?)
This is why: http://0x80.pl/articles/sse-popcount.html