Mail Archives: djgpp/1997/06/07/22:33:04
In article <338F1A19 DOT 474E AT blackmagic DOT tait DOT co DOT nz>,
Bill Currie <billc AT blackmagic DOT tait DOT co DOT nz> wrote:
>If anyone can figure a better way of byte swapping longs (without useing
>bswap), preferably in c, please let me know as gcc can't optimise
>swapBytes(long) or swapBytes(ulong) when called with constants (due to
>the assembly code).
void swapbytes(long *the_variable)
{
register char b0,b1,b2,b3;
b0 = *(((char *)(the_variable)));
b1 = *(((char *)(the_variable))+1);
b2 = *(((char *)(the_variable))+2);
b3 = *(((char *)(the_bariable))+3);
*(((char *)(the_variable))) = b3;
*(((char *)(the_variable))+1) = b2;
*(((char *)(the_variable))+2) = b1;
*(((char *)(the_variable))+3) = b0;
}
If you have some means of detecting wether your program will be comipled for a
486, use inline assembly with the bswap instruction.
AE.
Andrei Ellman -- URL: http://www.xs4all.nl/~ellman/ae-a -- ae1 AT york DOT ac DOT uk
"All I wanna do is have some fun :-) || ae-a AT minster DOT york DOT ac DOT uk
I've got the feeling I'm not the only one" || mailto:ellman AT xs4all DOT nl
-- Sheryl Crow :-) || It's what you make of it.
- Raw text -