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

#define SDL_BYTEORDER   SDL_LIL_ENDIAN
 
The two types of endianness
#define SDL_LIL_ENDIAN   1234
 
#define SDL_BIG_ENDIAN   4321
 
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)
 

Functions

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

◆ SDL_BIG_ENDIAN

#define SDL_BIG_ENDIAN   4321

Definition at line 58 of file SDL_endian.h.

◆ SDL_BYTEORDER

#define SDL_BYTEORDER   SDL_LIL_ENDIAN

Definition at line 79 of file SDL_endian.h.

◆ SDL_LIL_ENDIAN

#define SDL_LIL_ENDIAN   1234

Definition at line 57 of file SDL_endian.h.

◆ SDL_SwapBE16

#define SDL_SwapBE16 (   X)    SDL_Swap16(X)

Definition at line 292 of file SDL_endian.h.

◆ SDL_SwapBE32

#define SDL_SwapBE32 (   X)    SDL_Swap32(X)

Definition at line 293 of file SDL_endian.h.

◆ SDL_SwapBE64

#define SDL_SwapBE64 (   X)    SDL_Swap64(X)

Definition at line 294 of file SDL_endian.h.

◆ SDL_SwapFloatBE

#define SDL_SwapFloatBE (   X)    SDL_SwapFloat(X)

Definition at line 295 of file SDL_endian.h.

◆ SDL_SwapFloatLE

#define SDL_SwapFloatLE (   X)    (X)

Definition at line 291 of file SDL_endian.h.

◆ SDL_SwapLE16

#define SDL_SwapLE16 (   X)    (X)

Definition at line 288 of file SDL_endian.h.

◆ SDL_SwapLE32

#define SDL_SwapLE32 (   X)    (X)

Definition at line 289 of file SDL_endian.h.

◆ SDL_SwapLE64

#define SDL_SwapLE64 (   X)    (X)

Definition at line 290 of file SDL_endian.h.

Function Documentation

◆ SDL_Swap16()

SDL_FORCE_INLINE Uint16 SDL_Swap16 ( Uint16  x)

Definition at line 146 of file SDL_endian.h.

References SDL_FORCE_INLINE, SDL_static_cast, and SDL_Swap32().

147 {
148  return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
149 }
uint16_t Uint16
Definition: SDL_stdinc.h:197
#define SDL_static_cast(type, expression)
Definition: SDL_stdinc.h:144

◆ SDL_Swap32()

SDL_FORCE_INLINE Uint32 SDL_Swap32 ( Uint32  x)

Definition at line 206 of file SDL_endian.h.

References SDL_FORCE_INLINE, SDL_static_cast, and SDL_Swap64().

Referenced by SDL_Swap16(), SDL_Swap64(), and SDL_SwapFloat().

207 {
208  return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) |
209  ((x >> 8) & 0x0000FF00) | (x >> 24)));
210 }
uint32_t Uint32
Definition: SDL_stdinc.h:209
#define SDL_static_cast(type, expression)
Definition: SDL_stdinc.h:144

◆ SDL_Swap64()

SDL_FORCE_INLINE Uint64 SDL_Swap64 ( Uint64  x)

Definition at line 253 of file SDL_endian.h.

References SDL_FORCE_INLINE, SDL_static_cast, and SDL_Swap32().

Referenced by SDL_Swap32().

254 {
255  Uint32 hi, lo;
256 
257  /* Separate into high and low 32-bit values and swap them */
258  lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
259  x >>= 32;
260  hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
261  x = SDL_Swap32(lo);
262  x <<= 32;
263  x |= SDL_Swap32(hi);
264  return (x);
265 }
uint32_t Uint32
Definition: SDL_stdinc.h:209
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition: SDL_endian.h:206
#define SDL_static_cast(type, expression)
Definition: SDL_stdinc.h:144

◆ SDL_SwapFloat()

SDL_FORCE_INLINE float SDL_SwapFloat ( float  x)

Definition at line 270 of file SDL_endian.h.

References SDL_Swap32().

271 {
272  union {
273  float f;
274  Uint32 ui32;
275  } swapper;
276  swapper.f = x;
277  swapper.ui32 = SDL_Swap32(swapper.ui32);
278  return swapper.f;
279 }
uint32_t Uint32
Definition: SDL_stdinc.h:209
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition: SDL_endian.h:206