MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoria_operor — block copy, move, compare, scan, fill

Data Structures

struct  MemoriaCfg
 Arguments for the memor calls. More...
struct  MemoriaOperorNs
 Type of the memor dispatch table. More...

Functions

EMBED_HOST_DEVICE void mmgr_memor_cpy (const MemoriaCfg *args)
 Copies args->bytes from args->src to args->dst, on an upward walk.
EMBED_HOST_DEVICE void mmgr_memor_move_up (const MemoriaCfg *args)
 Copies args->bytes from args->src to args->dst, on a downward walk from the far end.
EMBED_HOST_DEVICE embed_iword mmgr_memor_cmp (const MemoriaCfg *args)
 Compares args->bytes of args->src against args->other.
EMBED_HOST_DEVICE const void * mmgr_memor_chr (const MemoriaCfg *args)
 Finds the first byte in args->src equal to args->val, within args->bytes.
EMBED_HOST_DEVICE void mmgr_memor_set (const MemoriaCfg *args)
 Writes args->val into args->bytes of args->dst.
EMBED_HOST_DEVICE embed_bool mmgr_memor_sort (const MemoriaCfg *args)
 Sorts args->count elements of args->bytes bytes each at args->dst in the order of args->order.
EMBED_HOST_DEVICE size_t mmgr_memor_run (const MemoriaCfg *args)
 Counts the bytes at the start of args->src equal to args->val, within args->bytes.
EMBED_HOST_DEVICE size_t mmgr_memor_run_last (const MemoriaCfg *args)
 Counts the bytes at the end of args->src equal to args->val, within args->bytes.

Variables

static const MemoriaOperorNs memor
 Dispatch table instance named memor.

Detailed Description

Function Documentation

◆ mmgr_memor_cpy()

EMBED_HOST_DEVICE void mmgr_memor_cpy ( const MemoriaCfg * args)

Copies args->bytes from args->src to args->dst, on an upward walk.

Parameters
[in]argsDestination, source and count [BORROWS].
Note
Moves whole words first, then the rest of the bytes one at a time.
Warning
The backend's argument type qualifies both pointers restrict, and so the regions must not overlap.
args->dst must be writable and args->src readable for args->bytes.

References mmgr_memor_cpy().

Referenced by mmgr_memor_cpy().

◆ mmgr_memor_move_up()

EMBED_HOST_DEVICE void mmgr_memor_move_up ( const MemoriaCfg * args)

Copies args->bytes from args->src to args->dst, on a downward walk from the far end.

Parameters
[in]argsDestination, source and count [BORROWS].
Note
Works back from the end. An args->dst above args->src is safe even when the regions overlap.
Warning
args->dst must be writable and args->src readable for args->bytes.

References mmgr_memor_move_up().

Referenced by mmgr_memor_move_up().

◆ mmgr_memor_cmp()

EMBED_HOST_DEVICE embed_iword mmgr_memor_cmp ( const MemoriaCfg * args)

Compares args->bytes of args->src against args->other.

Parameters
[in]argsThe two regions and the count [BORROWS].
Returns
The difference of the first unequal byte pair, or 0 when every byte matches.
Note
The sign follows the bytes that differ, and so the result orders the two regions.
Warning
Both regions must be readable for args->bytes rounded up to a whole word. A count that does not fill the last one still reads a whole word at a time.

References mmgr_memor_cmp().

Referenced by mmgr_memor_cmp().

◆ mmgr_memor_chr()

EMBED_HOST_DEVICE const void * mmgr_memor_chr ( const MemoriaCfg * args)

Finds the first byte in args->src equal to args->val, within args->bytes.

Parameters
[in]argsRegion, count and the byte sought [BORROWS].
Returns
Address of the match, or NULL when the byte does not occur [BORROWS].
Note
A terminator is not special. The search covers all args->bytes.
Warning
args->src must be readable for args->bytes rounded up to a whole word. A count that does not fill the last one still reads a whole word at a time.

References mmgr_memor_chr().

Referenced by mmgr_memor_chr().

◆ mmgr_memor_set()

EMBED_HOST_DEVICE void mmgr_memor_set ( const MemoriaCfg * args)

Writes args->val into args->bytes of args->dst.

Parameters
[in]argsDestination, count and the byte to write [BORROWS].
Note
Stores whole words built from args->val, then finishes byte by byte.
Warning
args->dst must be writable for args->bytes.

References mmgr_memor_set().

Referenced by mmgr_memor_set().

◆ mmgr_memor_sort()

EMBED_HOST_DEVICE embed_bool mmgr_memor_sort ( const MemoriaCfg * args)

Sorts args->count elements of args->bytes bytes each at args->dst in the order of args->order.

Parameters
[in]argsThe elements, the room, the count, the size of one element and the order [BORROWS].
Returns
EMBED_TRUE where the elements are in order. EMBED_FALSE where args->bytes is 0 or a pointer is NULL, which leaves the elements as they were. Fewer than two elements are in order already.
Note
args->order answers 0 or less where its left element comes at or before its right one, as the compare of qsort answers. Two elements that order as equal keep the order that they had.
A bottom-up merge sort: each pass merges runs of twice the width of the pass before, from args->dst into args->scratch and back. Every element moves log2 of args->count times, and MMgr takes no memory of its own.
theory/linea/Linea/Sort.lean proves that the sort keeps the elements and leaves them in order, where the order is transitive and total.
Warning
args->dst and args->scratch must each hold args->count times args->bytes bytes, and must not overlap.

References mmgr_memor_sort().

Referenced by mmgr_memor_sort().

◆ mmgr_memor_run()

EMBED_HOST_DEVICE size_t mmgr_memor_run ( const MemoriaCfg * args)

Counts the bytes at the start of args->src equal to args->val, within args->bytes.

Parameters
[in]argsRegion, count and the byte counted [BORROWS].
Returns
The count of bytes before the first byte that is not args->val, or args->bytes.
Note
A terminator is not special. A byte of 0 counts as any other byte does.
The walk reads aligned words, and a mask clears the lanes outside the region. No step tests a single byte.
Warning
The aligned words that hold the region's first and last bytes are read whole.

References mmgr_memor_run().

Referenced by mmgr_memor_run().

◆ mmgr_memor_run_last()

EMBED_HOST_DEVICE size_t mmgr_memor_run_last ( const MemoriaCfg * args)

Counts the bytes at the end of args->src equal to args->val, within args->bytes.

Parameters
[in]argsRegion, count and the byte counted [BORROWS].
Returns
The count of bytes after the last byte that is not args->val, or args->bytes.
Note
A terminator is not special. A byte of 0 counts as any other byte does.
The walk reads aligned words down from the end, and a mask clears the lanes outside the region. No step tests a single byte.
Warning
The aligned words that hold the region's first and last bytes are read whole.

References mmgr_memor_run_last().

Referenced by mmgr_memor_run_last().

Variable Documentation

◆ memor

const MemoriaOperorNs memor
static

Dispatch table instance named memor.

Note
cpy and move_down both point at mmgr_memor_cpy. Every other member has its own function.
There is no mmgr_memor_move_down. A destination below the source is what the upward walk already handles. So the table names that walk twice and carries no second copy of it.

Definition at line 159 of file memoria_operor.h.