Skip to content
Permalink
Browse files

SDL_endian.h: add Watcom inline asm for SDL_Swap16 and SDL_Swap32

  • Loading branch information
sezero committed Mar 24, 2018
1 parent cee0250 commit c2209405ecb88db972b91bef4630184c310e31b6
Showing with 21 additions and 0 deletions.
  1. +21 −0 include/SDL_endian.h
@@ -97,6 +97,12 @@ static __inline__ Uint16 SDL_Swap16(Uint16 x)
__asm__("rorw #8,%0" : "=d" (x) : "0" (x) : "cc");
return x;
}
#elif defined(__WATCOMC__) && defined(__386__)
extern _inline Uint16 SDL_Swap16(Uint16);
#pragma aux SDL_Swap16 = \
"xchg al, ah" \
parm [ax] \
modify [ax];
#else
static __inline__ Uint16 SDL_Swap16(Uint16 x) {
return SDL_static_cast(Uint16, ((x<<8)|(x>>8)));
@@ -132,6 +138,21 @@ static __inline__ Uint32 SDL_Swap32(Uint32 x)
__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc");
return x;
}
#elif defined(__WATCOMC__) && defined(__386__)
extern _inline Uint32 SDL_Swap32(Uint32);
#ifndef __SW_3 /* 486+ */
#pragma aux SDL_Swap32 = \
"bswap eax" \
parm [eax] \
modify [eax];
#else /* 386-only */
#pragma aux SDL_Swap32 = \
"xchg al, ah" \
"ror eax, 16" \
"xchg al, ah" \
parm [eax] \
modify [eax];
#endif
#else
static __inline__ Uint32 SDL_Swap32(Uint32 x) {
return SDL_static_cast(Uint32, ((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)));

0 comments on commit c220940

Please sign in to comment.