Skip to content

Commit

Permalink
SDL_endian.h: add Watcom inline asm for SDL_Swap16 and SDL_Swap32
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 24, 2018
1 parent cee0250 commit c220940
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/SDL_endian.h
Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit c220940

Please sign in to comment.