MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
endian — byte order

Data Structures

struct  EndianCfg
 Arguments for the endian calls, where each call reads only the members it needs. More...
struct  EndianNs
 Type of an endian dispatch table. More...

Enumerations

enum  mmgr_endian_width {
  MMGR_ENDIAN_16 ,
  MMGR_ENDIAN_32 ,
  MMGR_ENDIAN_64
}
 Width of one endian read or write, counted in bytes. More...

Functions

EMBED_HOST_DEVICE size_t mmgr_wr_le (const EndianCfg *args)
 Writes args->width bytes of args->val to args->dst and does not reverse them.
EMBED_HOST_DEVICE uint64_t mmgr_rd_le (const EndianCfg *args)
 Reads args->width bytes from args->src and does not reverse them.
EMBED_HOST_DEVICE size_t mmgr_wr_be (const EndianCfg *args)
 Reverses args->val, then writes args->width bytes of it to args->dst.
EMBED_HOST_DEVICE uint64_t mmgr_rd_be (const EndianCfg *args)
 Reads args->width bytes from args->src, then reverses them.
EMBED_HOST_DEVICE uint64_t mmgr_endian_rev (const EndianCfg *args)
 Reverses the byte order of args->val at args->width bytes.

Variables

static const EndianNs parva_extremitas
 Dispatch table instance named parva_extremitas, the little endian order.
static const EndianNs magna_extremitas
 Dispatch table instance named magna_extremitas, the big endian order.

Detailed Description

Enumeration Type Documentation

◆ mmgr_endian_width

Width of one endian read or write, counted in bytes.

Note
The enumerators are the byte counts themselves, and so the implementation switches on them directly.
One byte on every compiler, through EMBED_ENUM_BYTE.
Warning
Nothing holds a value to these three. The switches in endian.c test 2 and 4 and take everything else on the default arm, which moves eight bytes.
Enumerator
MMGR_ENDIAN_16 

Two bytes.

MMGR_ENDIAN_32 

Four bytes.

MMGR_ENDIAN_64 

Eight bytes.

Definition at line 41 of file endian.h.

Function Documentation

◆ mmgr_wr_le()

EMBED_HOST_DEVICE size_t mmgr_wr_le ( const EndianCfg * args)

Writes args->width bytes of args->val to args->dst and does not reverse them.

Parameters
[in,out]argsDestination, value and width [BORROWS].
Returns
args->width.
Warning
args->dst must be writable for args->width bytes. Nothing checks it. endian.c passes it to proxim.put16, put32 or put64, each of which stores through it with no test.
args->width must be one of the mmgr_endian_width enumerators. Any other value writes eight bytes.

References mmgr_wr_le().

Referenced by mmgr_wr_le().

◆ mmgr_rd_le()

EMBED_HOST_DEVICE uint64_t mmgr_rd_le ( const EndianCfg * args)

Reads args->width bytes from args->src and does not reverse them.

Parameters
[in]argsSource and width [BORROWS].
Returns
The value read, in the low args->width bytes.
Warning
args->src must be readable for args->width bytes. Nothing checks it. endian.c passes it to proxim.load16, load32 or load64, each of which reads through it with no test.
args->width must be one of the mmgr_endian_width enumerators. Any other value reads eight bytes.

References mmgr_rd_le().

Referenced by mmgr_rd_le().

◆ mmgr_wr_be()

EMBED_HOST_DEVICE size_t mmgr_wr_be ( const EndianCfg * args)

Reverses args->val, then writes args->width bytes of it to args->dst.

Parameters
[in,out]argsDestination, value and width [BORROWS].
Returns
args->width.
Warning
args->dst must be writable for args->width bytes. Nothing checks it. endian.c passes it to proxim.put16, put32 or put64, each of which stores through it with no test.
args->width must be one of the mmgr_endian_width enumerators. Any other value writes eight bytes. One above eight wraps the reversal's shift count, and a width of 0 shifts by 64, which has no definition.

References mmgr_wr_be().

Referenced by mmgr_wr_be().

◆ mmgr_rd_be()

EMBED_HOST_DEVICE uint64_t mmgr_rd_be ( const EndianCfg * args)

Reads args->width bytes from args->src, then reverses them.

Parameters
[in]argsSource and width [BORROWS].
Returns
The reversed value, in the low args->width bytes.
Warning
args->src must be readable for args->width bytes. Nothing checks it. endian.c passes it to proxim.load16, load32 or load64, each of which reads through it with no test.
args->width must be one of the mmgr_endian_width enumerators. Any other value reads eight bytes. One above eight wraps the reversal's shift count, and a width of 0 shifts by 64, which has no definition.

References mmgr_rd_be().

Referenced by mmgr_rd_be().

◆ mmgr_endian_rev()

EMBED_HOST_DEVICE uint64_t mmgr_endian_rev ( const EndianCfg * args)

Reverses the byte order of args->val at args->width bytes.

Parameters
[in]argsValue and width [BORROWS].
Returns
The reversed value, right-aligned into the low args->width bytes.
Note
Reads args->val and args->width, alone, and so it touches no buffer and dst and src take no part.
Both tables point rev at this one function, which reverses whatever it receives with no reference to either order.
Warning
args->width must be one of the mmgr_endian_width enumerators. 8 minus it wraps as unsigned arithmetic does. A width above eight wraps into a very large shift count, and a width of 0 shifts a 64-bit value by 64, which has no definition.

References mmgr_endian_rev().

Referenced by mmgr_endian_rev().

Variable Documentation

◆ parva_extremitas

const EndianNs parva_extremitas
static

Dispatch table instance named parva_extremitas, the little endian order.

Note
wr and rd move bytes as they lie, and so they land in the host's own order. This module never consults EMBED_BIG_ENDIAN. So the name holds on a little endian host and this table writes big endian bytes on a big endian one.
rev is the same function both tables use.

Definition at line 150 of file endian.h.

◆ magna_extremitas

const EndianNs magna_extremitas
static

Dispatch table instance named magna_extremitas, the big endian order.

Note
wr reverses before its write and rd reverses after its read, and so the bytes land in the reverse of the host's own order. That is big endian on a little endian host, as the name records, and little endian on a big endian one.
rev is the same function as in parva_extremitas.

Definition at line 164 of file endian.h.