[SDL] amd64 [un]fixes in SDL_endian.h

Albert Cahalan albert at users.sf.net
Tue Jan 25 09:19:16 PST 2005


On Tue, 2005-01-25 at 17:35 +0100, Stephane Marchesin wrote:
> Albert Cahalan wrote:
> 
> >On Sat, 2005-01-22 at 00:40 -0500, Mike Frysinger wrote:
> >
> >>the netbsd fix imported here:
> >>http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/include/SDL_endian.h.diff?r1=1.11&r2=1.12
> >>made our problems go away nicely (i was able to reproduce original build 
> >>failures and confirm the fix on an amd64 dev box)
> >>
> >
> >Doesn't a recent gcc know to use that instruction anyway?
> >I think you can just get rid of the assembly code. The code
> >might even run faster, since gcc would have more information
> >about the code.
> >
> It might be true that removing it might be faster, but the reason is not 
> that gcc has more or less "information about the code".

Perhaps the code merely tests a bit after swapping.
With the assembly, you'll have that xchg instruction.
With plain C code, gcc can just test a different bit
instead of swapping the bytes.

Perhaps the code will save the least-significant byte
of a short into a char. With plain C code, gcc can 
simply shift as needed and store the result.

Here's what Linux does for i386:

swab16 is plain C (with note that gcc handles it)
swab32 is bswap, or for obsolete junk: xchgb,rorl,xchgb
swab64 is bswapl, or for obsolete junk: swab32(),swab32(),xchgl

Here's what Linux does for x86-64:

swab16 is plain C (with note that gcc handles it)
swab32 is bswapl
swab64 is bswapq

I expect that the above will change as older compilers
become less commonly used.

PowerPC would benefit from byteswap operations that take
a pointer. The CPU has load/store instructions that swap
the bytes, but no register-to-register ones that do.
For serious byte swapping, AltiVec would be good to use.






More information about the SDL mailing list