SDL 2.0
SDL_endian.h File Reference
#include "SDL_stdinc.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_endian.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

Swap to native

Byteswap item from the specified endianness to the native endianness.

#define SDL_SwapLE16(X)   (X)
 
#define SDL_SwapLE32(X)   (X)
 
#define SDL_SwapLE64(X)   (X)
 
#define SDL_SwapFloatLE(X)   (X)
 
#define SDL_SwapBE16(X)   SDL_Swap16(X)
 
#define SDL_SwapBE32(X)   SDL_Swap32(X)
 
#define SDL_SwapBE64(X)   SDL_Swap64(X)
 
#define SDL_SwapFloatBE(X)   SDL_SwapFloat(X)
 

The two types of endianness

#define SDL_LIL_ENDIAN   1234
 
#define SDL_BIG_ENDIAN   4321
 
#define SDL_BYTEORDER   SDL_LIL_ENDIAN
 
#define SDL_FLOATWORDORDER   SDL_BYTEORDER
 
#define HAS_BUILTIN_BSWAP16   0
 
#define HAS_BUILTIN_BSWAP32   0
 
#define HAS_BUILTIN_BSWAP64   0
 
#define HAS_BROKEN_BSWAP   0
 
SDL_FORCE_INLINE Uint16 SDL_Swap16 (Uint16 x)
 
SDL_FORCE_INLINE Uint32 SDL_Swap32 (Uint32 x)
 
SDL_FORCE_INLINE Uint64 SDL_Swap64 (Uint64 x)
 
SDL_FORCE_INLINE float SDL_SwapFloat (float x)
 

Detailed Description

Functions for reading and writing endian-specific values

Definition in file SDL_endian.h.

Macro Definition Documentation

◆ HAS_BROKEN_BSWAP

#define HAS_BROKEN_BSWAP   0

Definition at line 138 of file SDL_endian.h.

◆ HAS_BUILTIN_BSWAP16

#define HAS_BUILTIN_BSWAP16   0

Definition at line 135 of file SDL_endian.h.

◆ HAS_BUILTIN_BSWAP32

#define HAS_BUILTIN_BSWAP32   0

Definition at line 136 of file SDL_endian.h.

◆ HAS_BUILTIN_BSWAP64

#define HAS_BUILTIN_BSWAP64   0

Definition at line 137 of file SDL_endian.h.

◆ SDL_BIG_ENDIAN

#define SDL_BIG_ENDIAN   4321

Definition at line 55 of file SDL_endian.h.

◆ SDL_BYTEORDER

#define SDL_BYTEORDER   SDL_LIL_ENDIAN

Definition at line 85 of file SDL_endian.h.

◆ SDL_FLOATWORDORDER

#define SDL_FLOATWORDORDER   SDL_BYTEORDER

Definition at line 108 of file SDL_endian.h.

◆ SDL_LIL_ENDIAN

#define SDL_LIL_ENDIAN   1234

Definition at line 54 of file SDL_endian.h.

◆ SDL_SwapBE16

#define SDL_SwapBE16 (   X)    SDL_Swap16(X)

Definition at line 324 of file SDL_endian.h.

◆ SDL_SwapBE32

#define SDL_SwapBE32 (   X)    SDL_Swap32(X)

Definition at line 325 of file SDL_endian.h.

◆ SDL_SwapBE64

#define SDL_SwapBE64 (   X)    SDL_Swap64(X)

Definition at line 326 of file SDL_endian.h.

◆ SDL_SwapFloatBE

#define SDL_SwapFloatBE (   X)    SDL_SwapFloat(X)

Definition at line 327 of file SDL_endian.h.

◆ SDL_SwapFloatLE

#define SDL_SwapFloatLE (   X)    (X)

Definition at line 323 of file SDL_endian.h.

◆ SDL_SwapLE16

#define SDL_SwapLE16 (   X)    (X)

Definition at line 320 of file SDL_endian.h.

◆ SDL_SwapLE32

#define SDL_SwapLE32 (   X)    (X)

Definition at line 321 of file SDL_endian.h.

◆ SDL_SwapLE64

#define SDL_SwapLE64 (   X)    (X)

Definition at line 322 of file SDL_endian.h.

Function Documentation

◆ SDL_Swap16()

SDL_FORCE_INLINE Uint16 SDL_Swap16 ( Uint16  x)

Definition at line 184 of file SDL_endian.h.

185{
186 return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
187}
uint16_t Uint16
Definition SDL_stdinc.h:210
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:157

References SDL_static_cast.

◆ SDL_Swap32()

SDL_FORCE_INLINE Uint32 SDL_Swap32 ( Uint32  x)

Definition at line 235 of file SDL_endian.h.

236{
237 return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) |
238 ((x >> 8) & 0x0000FF00) | (x >> 24)));
239}
uint32_t Uint32
Definition SDL_stdinc.h:222

References SDL_static_cast.

Referenced by SDL_Swap64(), and SDL_SwapFloat().

◆ SDL_Swap64()

SDL_FORCE_INLINE Uint64 SDL_Swap64 ( Uint64  x)

Definition at line 280 of file SDL_endian.h.

281{
282 Uint32 hi, lo;
283
284 /* Separate into high and low 32-bit values and swap them */
285 lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
286 x >>= 32;
287 hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
288 x = SDL_Swap32(lo);
289 x <<= 32;
290 x |= SDL_Swap32(hi);
291 return (x);
292}
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition SDL_endian.h:235

References SDL_static_cast, and SDL_Swap32().

◆ SDL_SwapFloat()

SDL_FORCE_INLINE float SDL_SwapFloat ( float  x)

Definition at line 297 of file SDL_endian.h.

298{
299 union {
300 float f;
301 Uint32 ui32;
302 } swapper;
303 swapper.f = x;
304 swapper.ui32 = SDL_Swap32(swapper.ui32);
305 return swapper.f;
306}

References SDL_Swap32().