Mercurial > sdl-ios-xcode
changeset 848:85af65457959
Avoid using kernel internal headers
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 23 Feb 2004 05:32:52 +0000 |
parents | 0afe0e38e02c |
children | bab227101de4 |
files | include/SDL_endian.h |
diffstat | 1 files changed, 16 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/include/SDL_endian.h Sat Feb 21 00:21:06 2004 +0000 +++ b/include/SDL_endian.h Mon Feb 23 05:32:52 2004 +0000 @@ -54,32 +54,35 @@ extern "C" { #endif -/* The macros used to swap values */ -/* Try to use superfast macros on systems that support them */ -#ifdef linux -#include <asm/byteorder.h> -#ifdef __arch__swab16 -#define SDL_Swap16 __arch__swab16 -#endif -#ifdef __arch__swab32 -#define SDL_Swap32 __arch__swab32 -#endif -#endif /* linux */ /* Use inline functions for compilers that support them, and static functions for those that do not. Because these functions become static for compilers that do not support inline functions, this header should only be included in files that actually use them. */ -#ifndef SDL_Swap16 +#if defined(__GNUC__) && defined(i386) +static __inline__ Uint16 SDL_Swap16(Uint16 D) +{ + __asm__("xchgb %b0,%h0" : "=q" (D) : "0" (D)); + return D; +} +#else static __inline__ Uint16 SDL_Swap16(Uint16 D) { return((D<<8)|(D>>8)); } #endif -#ifndef SDL_Swap32 + +#if defined(__GNUC__) && defined(i386) +static __inline__ Uint32 SDL_Swap32(Uint32 D) +{ + __asm__("bswap %0" : "=r" (D) : "0" (D)); + return D; +} +#else static __inline__ Uint32 SDL_Swap32(Uint32 D) { return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); } #endif + #ifdef SDL_HAS_64BIT_TYPE #ifndef SDL_Swap64 static __inline__ Uint64 SDL_Swap64(Uint64 val) {