Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
byte_order.h File Reference
#include "lib/sysdep/cpu.h"
Include dependency graph for byte_order.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LITTLE_ENDIAN   0x4321
 
#define BIG_ENDIAN   0x1234
 
#define BYTE_ORDER   BIG_ENDIAN
 
#define FOURCC(a, b, c, d)
 convert 4 characters to u32 (at compile time) for easy comparison. More...
 
#define FOURCC_BE(a, b, c, d)
 big-endian version of FOURCC More...
 
#define FOURCC_LE(a, b, c, d)
 little-endian version of FOURCC More...
 
#define FOURCC   FOURCC_BE
 convert 4 characters to u32 (at compile time) for easy comparison. More...
 
#define to_le16(x)   swap16(x)
 
#define to_le32(x)   swap32(x)
 
#define to_le64(x)   swap64(x)
 
#define to_be16(x)   (x)
 
#define to_be32(x)   (x)
 
#define to_be64(x)   (x)
 

Functions

u16 read_le16 (const void *p)
 read a little-endian number from memory into native byte order. More...
 
u32 read_le32 (const void *p)
 
u64 read_le64 (const void *p)
 see read_le16 More...
 
u16 read_be16 (const void *p)
 see read_le16 More...
 
u32 read_be32 (const void *p)
 
u64 read_be64 (const void *p)
 see read_be16 More...
 
void write_le16 (void *p, u16 x)
 see read_be16 More...
 
void write_le32 (void *p, u32 x)
 
void write_le64 (void *p, u64 x)
 see write_le16 More...
 
void write_be16 (void *p, u16 x)
 see write_le16 More...
 
void write_be32 (void *p, u32 x)
 
void write_be64 (void *p, u64 x)
 see write_be16 More...
 
u64 movzx_le64 (const u8 *p, size_t size)
 see write_be16 More...
 
u64 movzx_be64 (const u8 *p, size_t size)
 
i64 movsx_le64 (const u8 *p, size_t size)
 sign-extend <size> (truncated to 8) bytes of little-endian data to i64, starting at address <p> (need not be aligned). More...
 
i64 movsx_be64 (const u8 *p, size_t size)
 
u16 swap16 (const u16 x)
 
u32 swap32 (const u32 x)
 
u64 swap64 (const u64 x)
 

Macro Definition Documentation

◆ BIG_ENDIAN

#define BIG_ENDIAN   0x1234

◆ BYTE_ORDER

#define BYTE_ORDER   BIG_ENDIAN

◆ FOURCC [1/2]

#define FOURCC (   a,
  b,
  c,
 
)

convert 4 characters to u32 (at compile time) for easy comparison.

output is in native byte order; e.g. FOURCC_LE can be used instead.

◆ FOURCC [2/2]

#define FOURCC   FOURCC_BE

convert 4 characters to u32 (at compile time) for easy comparison.

output is in native byte order; e.g. FOURCC_LE can be used instead.

◆ FOURCC_BE

#define FOURCC_BE (   a,
  b,
  c,
 
)
Value:
( ((u32)(u8)a) << 24 | ((u32)(u8)b) << 16 | \
((u32)(u8)c) << 8 | ((u32)(u8)d) << 0 )
uint8_t u8
Definition: types.h:37
uint32_t u32
Definition: types.h:39

big-endian version of FOURCC

◆ FOURCC_LE

#define FOURCC_LE (   a,
  b,
  c,
 
)
Value:
( ((u32)(u8)a) << 0 | ((u32)(u8)b) << 8 | \
((u32)(u8)c) << 16 | ((u32)(u8)d) << 24 )

little-endian version of FOURCC

◆ LITTLE_ENDIAN

#define LITTLE_ENDIAN   0x4321

◆ to_be16

#define to_be16 (   x)    (x)

◆ to_be32

#define to_be32 (   x)    (x)

◆ to_be64

#define to_be64 (   x)    (x)

◆ to_le16

#define to_le16 (   x)    swap16(x)

◆ to_le32

#define to_le32 (   x)    swap32(x)

◆ to_le64

#define to_le64 (   x)    swap64(x)

Function Documentation

◆ movsx_be64()

i64 movsx_be64 ( const u8 p,
size_t  size 
)

◆ movsx_le64()

i64 movsx_le64 ( const u8 p,
size_t  size 
)

sign-extend <size> (truncated to 8) bytes of little-endian data to i64, starting at address <p> (need not be aligned).

◆ movzx_be64()

u64 movzx_be64 ( const u8 p,
size_t  size 
)

◆ movzx_le64()

u64 movzx_le64 ( const u8 p,
size_t  size 
)

see write_be16

zero-extend <size> (truncated to 8) bytes of little-endian data to u64, starting at address <p> (need not be aligned).

◆ read_be16()

u16 read_be16 ( const void *  p)

see read_le16

read a big-endian number from memory into native byte order.

◆ read_be32()

u32 read_be32 ( const void *  p)

◆ read_be64()

u64 read_be64 ( const void *  p)

see read_be16

◆ read_le16()

u16 read_le16 ( const void *  p)

read a little-endian number from memory into native byte order.

◆ read_le32()

u32 read_le32 ( const void *  p)

◆ read_le64()

u64 read_le64 ( const void *  p)

see read_le16

◆ swap16()

u16 swap16 ( const u16  x)

◆ swap32()

u32 swap32 ( const u32  x)

◆ swap64()

u64 swap64 ( const u64  x)

◆ write_be16()

void write_be16 ( void *  p,
u16  x 
)

see write_le16

write a big-endian number to memory in native byte order.

◆ write_be32()

void write_be32 ( void *  p,
u32  x 
)

◆ write_be64()

void write_be64 ( void *  p,
u64  x 
)

see write_be16

◆ write_le16()

void write_le16 ( void *  p,
u16  x 
)

see read_be16

write a little-endian number to memory in native byte order.

◆ write_le32()

void write_le32 ( void *  p,
u32  x 
)

◆ write_le64()

void write_le64 ( void *  p,
u64  x 
)

see write_le16