Go to the documentation of this file.
18 #ifndef __LIB_LIBSTD_BYTEORDER_H
19 #define __LIB_LIBSTD_BYTEORDER_H
32 #ifndef __BYTE_ORDER__
33 #error "__BYTE_ORDER__ not defined"
36 #ifndef __ORDER_LITTLE_ENDIAN__
37 #error "__ORDER_LITTLE_ENDIAN__ not defined"
40 #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
41 #error "This implementation only supports little-endian targets: define __BYTE_ORDER__ to __ORDER_LITTLE_ENDIAN__"
56 #define SWAP16(x) ((u16)( \
57 (((u16)(x) & (u16)0x00ffU) << 8) | \
58 (((u16)(x) & (u16)0xff00U) >> 8)))
68 #define SWAP32(x) ((u32)( \
69 (((u32)(x) & (u32)0x000000ffUL) << 24) | \
70 (((u32)(x) & (u32)0x0000ff00UL) << 8) | \
71 (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \
72 (((u32)(x) & (u32)0xff000000UL) >> 24)))
82 #define SWAP64(x) ((u64)( \
83 (((u64)(x) & (u64)0x00000000000000ffUL) << 56) | \
84 (((u64)(x) & (u64)0x000000000000ff00UL) << 40) | \
85 (((u64)(x) & (u64)0x0000000000ff0000UL) << 24) | \
86 (((u64)(x) & (u64)0x00000000ff000000UL) << 8) | \
87 (((u64)(x) & (u64)0x000000ff00000000UL) >> 8) | \
88 (((u64)(x) & (u64)0x0000ff0000000000UL) >> 24) | \
89 (((u64)(x) & (u64)0x00ff000000000000UL) >> 40) | \
90 (((u64)(x) & (u64)0xff00000000000000UL) >> 56)))
108 #define cpu_to_le64(x) ((le64)(u64)(x))
117 #define le64_to_cpu(x) ((u64)(le64)(x))
126 #define cpu_to_le32(x) ((le32)(u32)(x))
135 #define le32_to_cpu(x) ((u32)(le32)(x))
144 #define cpu_to_le16(x) ((le16)(u16)(x))
153 #define le16_to_cpu(x) ((u16)(le16)(x))
162 #define cpu_to_be64(x) ((be64)SWAP64((x)))
171 #define be64_to_cpu(x) SWAP64((u64)(be64)(x))
180 #define cpu_to_be32(x) ((be32)SWAP32((x)))
189 #define be32_to_cpu(x) SWAP32((u32)(be32)(x))
198 #define cpu_to_be16(x) ((be16)SWAP16((x)))
207 #define be16_to_cpu(x) SWAP16((u16)(be16)(x))
#define cpu_to_be32(x)
CPU byte order to big endian 32-bit.
const u32 read32(const void *data)
Read 32-bit integer (no conversion)
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
void write64(void *data, const u64 input)
Write 64-bit integer (no conversion)
const u32 readBe32(const void *data)
Read 32-bit big endian integer.
#define cpu_to_le16(x)
CPU byte order to little endian 16-bit.
const u16 readLe16(const void *data)
Read 16-bit little endian integer.
#define cpu_to_le32(x)
CPU byte order to little endian 32-bit.
const u16 readBe16(const void *data)
Read 16-bit big endian integer.
void writeBe16(void *data, const u16 input)
Write 16-bit big endian integer.
#define cpu_to_be16(x)
CPU byte order to big endian 16-bit.
const u64 read64(const void *data)
Memory read/write functions.
const u64 readBe64(const void *data)
Read 64-bit big endian integer.
void write8(void *data, const u8 input)
Write 8-bit integer.
const u64 readLe64(const void *data)
Read 64-bit little endian integer.
void writeBe64(void *data, const u64 input)
Write 64-bit big endian integer.
void write16(void *data, const u16 input)
Write 16-bit integer (no conversion)
unsigned long long u64
Unsigned 64-bit number.
void writeLe16(void *data, const u16 input)
Write 16-bit little endian integer.
unsigned short u16
Unsigned 16-bit number.
#define le32_to_cpu(x)
Little endian 32-bit to CPU byte order.
#define cpu_to_le64(x)
Integer conversion functions.
unsigned int u32
Unsigned 32-bit number.
#define be64_to_cpu(x)
Big endian 64-bit to CPU byte order.
#define be32_to_cpu(x)
Big endian 32-bit to CPU byte order.
const u32 readLe32(const void *data)
Read 32-bit little endian integer.
const u16 read16(const void *data)
Read 16-bit integer (no conversion)
#define le16_to_cpu(x)
Little endian 16-bit to CPU byte order.
void writeBe32(void *data, const u32 input)
Write 32-bit big endian integer.
unsigned char u8
Unsigned 8-bit number.
void writeLe32(void *data, const u32 input)
Write 32-bit little endian integer.
#define cpu_to_be64(x)
CPU byte order to big endian 64-bit.
void writeLe64(void *data, const u64 input)
Write 64-bit little endian integer.
#define le64_to_cpu(x)
Little endian 64-bit to CPU byte order.
void write32(void *data, const u32 input)
Write 32-bit integer (no conversion)
const u8 read8(const void *data)
Read 8-bit integer.
#define be16_to_cpu(x)
Big endian 16-bit to CPU byte order.