Home page > Debian > Byte swap and amd64..
Byte swap and amd64..
Friday 15 August 2008, by
Some really weird issue just poped to my eyes today, while coding some big->little endian code for liquidsoap.
We have a 2 bytes swaping code that does the following:
((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
However, this is not working at all on my amd64/x86_64 box (core2duo CPU). I get a horrible saturated sound..
So, I copy-pasted this from oss4:
static inline short
bswap_16 (short x)
{
short y = 0;
unsigned char *a = ((unsigned char *) &x) + 1;
unsigned char *b = (unsigned char *) &y;
*b++ = *a--;
*b++ = *a--;
return y;
}.. which is working.. !
So, I’m stuck with one function that I understand, should be working, but isn’t, and one that I don’t understand, but is working..
May a C guru give me some pointers about this issue ? I believe it’s connected to some sort of architecture specific issue... Thanks in advance !!
PS: the bswap_16 function included in byteswap.h from libc6-dev doesn’t work either, and yields the same saturated sound..

7 Forum messages