>Last time I looked gcc was not able to generate (did not know about) the bswap instruction.
Perhaps you need to update from that ancient gcc version ;-)
int main(int argc, char **argv) { printf("%d\n", htonl(argc)); return 0; } compiled with gcc-4.5 -O3 -static on x86_64 gives me a bswap in objdump. bswap has been there since 80486.
>some assembly instuctions to cast the value 3 in a 16 bits word to the value 3 in a byte,
Posted Oct 7, 2010 15:38 UTC (Thu) by etienne (subscriber, #25256)
[Link]
> Perhaps you need to update from that ancient gcc version ;-)
Still no GCC-4.5 here and on ia32, if your example no more calls the function "htonl" (which for GCC-4.4.5 is a library function written manually in assembler - I just checked the whole calling sequence by objdump), that is a very welcome improvement!
> Well, wouldn't that be just AND r0, 0xFF.
Unfortunately a register do not have an address to pass to a function, so you need to allocate some temporary space on the stack and copy your register there...