Mail Archives: djgpp/1997/06/01/20:35:38
In message <5mpb7b$3nm$1 AT news0 DOT xs4all DOT nl>
ellman AT xs4all DOT nl () writes:
> 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.
or
dummy = (data & 0x000000ff) << 24;
dummy = dummy | ((data & 0x0000ff00) << 8);
dummy = dummy | ((data & 0x00FF0000) >> 8);
dummy = dummy | ((data & 0xFF000000) >> 24);
--
Keith Hull - Bournemouth
keithh AT zetnet DOT co DOT uk
keithh AT yeomanh DOT spsxch DOT p4 DOT sps DOT co DOT uk
- Raw text -