> I'm grateful to so many folks who replied to my previous post re: byte
> swapping. I am trying to make a music app (running under Linux)
> intelligent about BE and LE soundfiles ... both reading and writing.
> In the process of doing all this ... I am curious about what kind of a
> performance hit I'll be taking wrt. ALWAYS swapping bytes on a LE
> machine (eg., PC).
Very low, as long as you can inline the proper asm opcode:
BSWAP register
This is a one-cycle non-pairable instruction.
If you have 16-bit samples instead of 32-bit (yeah, I know this is more
probable!), then you have even more choices:
One of these:
xchg al,ah
xchg bl,bh
xchg cl,ch
xchg dl,dh
or any of these:
ror ax,8
ror bx,8
ror cx,8
ror dx,8
ror si,8
ror di,8
ror bp,8
You can also use C:
#define swap16(a) ( (((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
Finally, for C code I would just make it portable:
#define GET16BE(src) ((((byte *) src)[0] << 8) | ((byte *) src)[1])
No matter which version you use, it should be easy to be fast enough
that the memory loads & stores are the limiting factor, not the byte
swapping!
Terje
--
Using self-discipline, see http://www.eiffel.com/discipline
"almost all programming can be viewed as an exercise in caching"