MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
cellularum_laboro — bounded string work

Data Structures

struct  CatenaFinitaCfg
 Arguments for the string calls, where each call reads only the members it needs. More...
struct  VerboProgrediorCfg
 Arguments for the single-step compares used to drive a walk. More...
struct  TransfiguroCfg
 Arguments for the conversions from text to number. More...
struct  CellularumLaboroNs
 Type of the cellul dispatch table. More...

Macros

#define MMGR_SIEVE_ROWS
 Max needle offsets the search sieve tests per candidate word.
#define MMGR_FIND_CHAIN_MAX
 Longest haystack over which a mask chain, and not a sieve, settles a one or two byte needle.

Functions

EMBED_HOST_DEVICE CatenaFinitaCfg mmgr_cellul_init (const CatenaFinitaCfg *args)
 Returns a copy of the argument struct.
EMBED_HOST_DEVICE size_t mmgr_cellul_len (const CatenaFinitaCfg *args)
 Returns the bytes in src before its terminator, from args->at on.
EMBED_HOST_DEVICE size_t mmgr_cellul_diff (const CatenaFinitaCfg *args)
 Returns the offset of the first byte where src and other differ.
EMBED_HOST_DEVICE embed_bool mmgr_cellul_eq (const CatenaFinitaCfg *args)
 Reports whether src and other hold the same terminated string.
EMBED_HOST_DEVICE embed_bool mmgr_cellul_starts (const CatenaFinitaCfg *args)
 Reports whether src begins with other.
EMBED_HOST_DEVICE const char * mmgr_cellul_find (const CatenaFinitaCfg *args)
 Finds the first occurrence of other within src.
EMBED_HOST_DEVICE embed_bool mmgr_cellul_has (const CatenaFinitaCfg *args)
 Reports whether other occurs within src.
EMBED_HOST_DEVICE const char * mmgr_cellul_chr (const CatenaFinitaCfg *args)
 Finds the first occurrence of args->byte in src, before the terminator.
EMBED_HOST_DEVICE size_t mmgr_cellul_copy (const CatenaFinitaCfg *args)
 Copies src into dst, and writes at max cap bytes, the terminator among them.
EMBED_HOST_DEVICE embed_bool mmgr_cellul_ws (const CatenaFinitaCfg *args)
 Tests src[at] for whitespace.
EMBED_HOST_DEVICE embed_bool mmgr_cellul_digit (const CatenaFinitaCfg *args)
 Tests src[at] for a decimal digit.
EMBED_HOST_DEVICE embed_iword mmgr_cellul_step_word (const VerboProgrediorCfg *args)
 Compares one word pair and reports whether a walk should continue.
EMBED_HOST_DEVICE embed_iword mmgr_cellul_step_byte (const VerboProgrediorCfg *args)
 Compares one byte pair and reports whether a walk should continue.
EMBED_HOST_DEVICE embed_iword mmgr_cellul_to_long (const TransfiguroCfg *args)
 Reads a signed decimal integer from args->src.
EMBED_HOST_DEVICE embed_word mmgr_cellul_to_ulong (const TransfiguroCfg *args)
 Reads an unsigned decimal integer from args->src.
EMBED_HOST_DEVICE double mmgr_cellul_to_double (const TransfiguroCfg *args)
 Reads a decimal floating point number from args->src.
EMBED_HOST_DEVICE float mmgr_cellul_to_float (const TransfiguroCfg *args)
 Reads a decimal floating point number from args->src and narrows it to float.
EMBED_HOST_DEVICE embed_word mmgr_cellul_to_ulong_in (const TransfiguroCfg *args)
 Reads an unsigned integer in base args->base from args->src.
EMBED_HOST_DEVICE size_t mmgr_cellul_span (const CatenaFinitaCfg *args)
 Counts the bytes at the start of src that the set other holds.
EMBED_HOST_DEVICE size_t mmgr_cellul_span_not (const CatenaFinitaCfg *args)
 Counts the bytes at the start of src that the set other does not hold.
EMBED_HOST_DEVICE const char * mmgr_cellul_chr_last (const CatenaFinitaCfg *args)
 Finds the last occurrence of args->byte in src, before the terminator.
EMBED_HOST_DEVICE size_t mmgr_cellul_span_last (const CatenaFinitaCfg *args)
 Counts the bytes at the end of src's cap bytes that the set other holds.
EMBED_HOST_DEVICE size_t mmgr_cellul_span_not_last (const CatenaFinitaCfg *args)
 Counts the bytes at the end of src's cap bytes that the set other does not hold.

Variables

static const CellularumLaboroNs cellul
 Dispatch table instance named cellul, with each member set to its mmgr_cellul_ function.

Detailed Description

Macro Definition Documentation

◆ MMGR_SIEVE_ROWS

#define MMGR_SIEVE_ROWS

Max needle offsets the search sieve tests per candidate word.

Note
A ceiling and not a count. cellul_pick_rows takes the smallest of this, the needle length and MMGR_SWAR_BYTES. A short needle gets a sieve on fewer offsets than this allows.
cellul_find_core sizes two arrays by it, the chosen offsets and their broadcasts, and reads element 0 of each outside the loop that walks the rest.
Warning
Taken only when MMGR_SIEVE_ROWS is not already defined. A build may supply its own.
A build's own value must be at least 1. At 0 both arrays have zero length and the search still reads element 0 of each, and nothing here asserts against it.

Definition at line 52 of file cellularum_laboro.h.

◆ MMGR_FIND_CHAIN_MAX

#define MMGR_FIND_CHAIN_MAX

Longest haystack over which a mask chain, and not a sieve, settles a one or two byte needle.

Note
Case sensitive searches only. The chain compares its broadcasts with no fold. A folded search takes the sieve at every length, whatever value this holds.
Defaults to no limit, which folds the test away: read_cap <= SIZE_MAX is true for every size_t. A default build emits no comparison and chooses no second path at run time.
The chain settles every start position in a word at once, with no anchor to choose and nothing to verify afterwards. A two byte needle costs it a second read a step and a one byte needle none. The sieve picks its offsets out of the cost table before it reads a haystack byte. It reads a word per offset on top of the one it tests for the terminator. Then it proves every lane that survives in full. Measured with a two byte needle, cycles for the whole call:
n              8      64    2048
Xtensa chain 124     489   13391
Xtensa sieve 187     607   15494
RISC-V chain 124     488   13393
RISC-V sieve 219     680   17059

The chain wins at every length on both parts, and so the default is no limit. The knob stays because that is a measurement and not a proof. A part or a workload that disagrees can say so and leave the walk alone.

Warning
Taken only when MMGR_FIND_CHAIN_MAX is not already defined. A build may supply its own. Zero sends every needle through the sieve.

Definition at line 83 of file cellularum_laboro.h.

Function Documentation

◆ mmgr_cellul_init()

EMBED_HOST_DEVICE CatenaFinitaCfg mmgr_cellul_init ( const CatenaFinitaCfg * args)

Returns a copy of the argument struct.

Parameters
[in]argsStruct to copy [BORROWS].
Returns
A copy of *args.
Note
Copies the members only. It reads nothing they point at.

References mmgr_cellul_init().

Referenced by mmgr_cellul_init().

◆ mmgr_cellul_len()

EMBED_HOST_DEVICE size_t mmgr_cellul_len ( const CatenaFinitaCfg * args)

Returns the bytes in src before its terminator, from args->at on.

Parameters
[in]argsBytes src, the extent cap, and the start offset at [BORROWS].
Returns
Bytes before the terminator, at max cap minus at.
Note
Returns cap minus at when no terminator lies in range.
Warning
args->at must not exceed args->cap, and src must be readable to args->cap. The last partial word comes in whole and gets a mask after. So the read reaches up to MMGR_SWAR_BYTES - 1 bytes past cap.

References mmgr_cellul_len().

Referenced by mmgr_cellul_len().

◆ mmgr_cellul_diff()

EMBED_HOST_DEVICE size_t mmgr_cellul_diff ( const CatenaFinitaCfg * args)

Returns the offset of the first byte where src and other differ.

Parameters
[in]argsBytes src and other, the extent cap, and ci [BORROWS].
Returns
Offset of the first difference, or cap when the two agree throughout.
Note
A terminator does not end the scan. cap is the only bound.
Warning
Both src and other must be readable for cap bytes. The last partial word comes in whole and gets a mask after. The read reaches up to MMGR_SWAR_BYTES - 1 bytes past cap in each.

References mmgr_cellul_diff().

Referenced by mmgr_cellul_diff().

◆ mmgr_cellul_eq()

EMBED_HOST_DEVICE embed_bool mmgr_cellul_eq ( const CatenaFinitaCfg * args)

Reports whether src and other hold the same terminated string.

Parameters
[in]argsBytes src and other, the extent cap, and ci [BORROWS].
Returns
EMBED_TRUE when both reach a terminator with no difference before it.
Warning
Both src and other must be readable for cap bytes. The last partial word comes in whole and gets a mask after. The read reaches up to MMGR_SWAR_BYTES - 1 bytes past cap in each.

References mmgr_cellul_eq().

Referenced by mmgr_cellul_eq().

◆ mmgr_cellul_starts()

EMBED_HOST_DEVICE embed_bool mmgr_cellul_starts ( const CatenaFinitaCfg * args)

Reports whether src begins with other.

Parameters
[in]argsBytes src and other, the extent cap, and ci [BORROWS].
Returns
EMBED_TRUE when other reaches its terminator with no difference before it.
Note
An empty other matches any src.
Warning
Both src and other must be readable for cap bytes. The last partial word comes in whole and gets a mask after. The read reaches up to MMGR_SWAR_BYTES - 1 bytes past cap in each.

References mmgr_cellul_starts().

Referenced by mmgr_cellul_starts().

◆ mmgr_cellul_find()

EMBED_HOST_DEVICE const char * mmgr_cellul_find ( const CatenaFinitaCfg * args)

Finds the first occurrence of other within src.

Parameters
[in]argsHaystack src with cap, needle other with other_cap, and ci [BORROWS].
Returns
Address inside src, or NULL when there is no match [BORROWS].
Note
An empty needle returns src. A needle longer than cap returns NULL.
Warning
src must be readable for cap bytes and other for other_cap bytes. The needle comes in a whole word at a time and gets a mask after. So the read reaches up to MMGR_SWAR_BYTES - 1 bytes past other_cap. The haystack walk holds itself inside cap.

References mmgr_cellul_find().

Referenced by mmgr_cellul_find().

◆ mmgr_cellul_has()

EMBED_HOST_DEVICE embed_bool mmgr_cellul_has ( const CatenaFinitaCfg * args)

Reports whether other occurs within src.

Parameters
[in]argsHaystack src with cap, needle other with other_cap, and ci [BORROWS].
Returns
EMBED_TRUE when mmgr_cellul_find reports a match.
Warning
src must be readable for cap bytes and other for other_cap bytes, with the needle read past other_cap exactly as mmgr_cellul_find describes.

References mmgr_cellul_has().

Referenced by mmgr_cellul_has().

◆ mmgr_cellul_chr()

EMBED_HOST_DEVICE const char * mmgr_cellul_chr ( const CatenaFinitaCfg * args)

Finds the first occurrence of args->byte in src, before the terminator.

Parameters
[in]argsBytes src, the extent cap, and the byte sought [BORROWS].
Returns
Address inside src, or NULL when the byte does not occur [BORROWS].
Note
A byte of 0 returns the terminator's own address, or src plus cap when no terminator is in range.
Warning
src must be readable for cap bytes. The last partial word comes in whole and gets a mask after. The read reaches up to MMGR_SWAR_BYTES - 1 bytes past cap.

References mmgr_cellul_chr().

Referenced by mmgr_cellul_chr().

◆ mmgr_cellul_copy()

EMBED_HOST_DEVICE size_t mmgr_cellul_copy ( const CatenaFinitaCfg * args)

Copies src into dst, and writes at max cap bytes, the terminator among them.

Parameters
[in,out]argsSource src, destination dst, and the destination extent cap [BORROWS].
Returns
Bytes copied, with the terminator not in the count.
Note
A cap of 0 writes nothing at all and not even a terminator.
Warning
dst must be writable for cap bytes and src readable for cap minus one.

References mmgr_cellul_copy().

Referenced by mmgr_cellul_copy().

◆ mmgr_cellul_ws()

EMBED_HOST_DEVICE embed_bool mmgr_cellul_ws ( const CatenaFinitaCfg * args)

Tests src[at] for whitespace.

Parameters
[in]argsBytes src and the offset at [BORROWS].
Returns
EMBED_TRUE for space, tab, newline, carriage return, form feed or vertical tab.
Warning
src[at] must be readable. cap does not bound this call.

References mmgr_cellul_ws().

Referenced by mmgr_cellul_ws().

◆ mmgr_cellul_digit()

EMBED_HOST_DEVICE embed_bool mmgr_cellul_digit ( const CatenaFinitaCfg * args)

Tests src[at] for a decimal digit.

Parameters
[in]argsBytes src and the offset at [BORROWS].
Returns
EMBED_TRUE for the ten decimal digits, '0' through '9'.
Warning
src[at] must be readable. cap does not bound this call.

References mmgr_cellul_digit().

Referenced by mmgr_cellul_digit().

◆ mmgr_cellul_step_word()

EMBED_HOST_DEVICE embed_iword mmgr_cellul_step_word ( const VerboProgrediorCfg * args)

Compares one word pair and reports whether a walk should continue.

Parameters
[in]argsWords word_left and word_right, with ci and end_wins [BORROWS].
Returns
MMGR_SWAR_GO to continue, MMGR_SWAR_YES on agreement, MMGR_SWAR_NO on difference.
Note
MMGR_SWAR_YES means word_left's terminator arrived before the first difference.
end_wins makes a terminator in the same lane as the difference count as agreement.

References mmgr_cellul_step_word().

Referenced by mmgr_cellul_step_word().

◆ mmgr_cellul_step_byte()

EMBED_HOST_DEVICE embed_iword mmgr_cellul_step_byte ( const VerboProgrediorCfg * args)

Compares one byte pair and reports whether a walk should continue.

Parameters
[in]argsBytes byte_left and byte_right, with ci and end_wins [BORROWS].
Returns
MMGR_SWAR_GO to continue, MMGR_SWAR_YES on agreement, MMGR_SWAR_NO on difference.
Note
A byte_left that terminates gives MMGR_SWAR_YES when byte_right also terminates, or when end_wins holds.

References mmgr_cellul_step_byte().

Referenced by mmgr_cellul_step_byte().

◆ mmgr_cellul_to_long()

EMBED_HOST_DEVICE embed_iword mmgr_cellul_to_long ( const TransfiguroCfg * args)

Reads a signed decimal integer from args->src.

Parameters
[in,out]argsText src and the optional end target [BORROWS].
Returns
The value, negated when a minus sign came first.
Note
Skips leading whitespace, then accepts one optional '+' or '-'.
When end is not NULL the call sets it past the last digit, or back to src when no digit came.
Warning
The read stops at the first byte that is not part of the number. No length bounds it.
The digit accumulator is embed_word wide and wraps on a longer run.

References mmgr_cellul_to_long().

Referenced by mmgr_cellul_to_long().

◆ mmgr_cellul_to_ulong()

EMBED_HOST_DEVICE embed_word mmgr_cellul_to_ulong ( const TransfiguroCfg * args)

Reads an unsigned decimal integer from args->src.

Parameters
[in,out]argsText src and the optional end target [BORROWS].
Returns
The accumulated value.
Note
Skips leading whitespace, then accepts one optional '+'. A '-' stops the read.
When end is not NULL the call sets it past the last digit, or back to src when no digit came.
Warning
The read stops at the first byte that is not part of the number. No length bounds it.
The digit accumulator is embed_word wide and wraps on a longer run.

References mmgr_cellul_to_ulong().

Referenced by mmgr_cellul_to_ulong().

◆ mmgr_cellul_to_double()

EMBED_HOST_DEVICE double mmgr_cellul_to_double ( const TransfiguroCfg * args)

Reads a decimal floating point number from args->src.

Parameters
[in,out]argsText src and the optional end target [BORROWS].
Returns
The assembled value.
Note
Accepts whitespace, one optional sign, digits, one optional point, then an optional exponent.
The exponent counts only when at least one digit came before it.
When end is not NULL the call sets it past the number, or back to src when no digit came.
Warning
The read stops at the first byte that is not part of the number. No length bounds it.

References mmgr_cellul_to_double().

Referenced by mmgr_cellul_to_double().

◆ mmgr_cellul_to_float()

EMBED_HOST_DEVICE float mmgr_cellul_to_float ( const TransfiguroCfg * args)

Reads a decimal floating point number from args->src and narrows it to float.

Parameters
[in,out]argsText src and the optional end target [BORROWS].
Returns
The value from mmgr_cellul_to_double, narrowed to float.
Note
Accepts the same input as mmgr_cellul_to_double, with only a different result width.
Warning
The read stops at the first byte that is not part of the number. No length bounds it.

References mmgr_cellul_to_float().

Referenced by mmgr_cellul_to_float().

◆ mmgr_cellul_to_ulong_in()

EMBED_HOST_DEVICE embed_word mmgr_cellul_to_ulong_in ( const TransfiguroCfg * args)

Reads an unsigned integer in base args->base from args->src.

Parameters
[in,out]argsText src, the optional end target and the base [BORROWS].
Returns
The value, negated in its word when a minus sign came first. All ones where the digits pass the word, whatever the sign. 0 where the base is neither 0 nor 2 to 36.
Note
Skips leading whitespace, then accepts one optional '+' or '-'. A base of 16 then accepts one optional 0x or 0X before a digit. A base of 0 reads 0x or 0X before a digit as base 16, a leading 0 as base 8, and any other number as base 10.
A digit is '0' to '9', then a letter of either case for 10 to 35, each below the base. muto.take_in adds it.
When end is not NULL the call sets it past the last digit, or back to src when no digit came.
Warning
The read stops at the first byte that is not a digit of the base. No length bounds it.

References mmgr_cellul_to_ulong_in().

Referenced by mmgr_cellul_to_ulong_in().

◆ mmgr_cellul_span()

EMBED_HOST_DEVICE size_t mmgr_cellul_span ( const CatenaFinitaCfg * args)

Counts the bytes at the start of src that the set other holds.

Parameters
[in]argsBytes src, the extent cap, and the terminated set other [BORROWS].
Returns
The count of bytes before the first byte that other does not hold, the terminator or cap.
Note
An empty set counts 0.
Warning
other must end in a terminator. The aligned words that hold src's first and last bytes are read whole.

References mmgr_cellul_span().

Referenced by mmgr_cellul_span().

◆ mmgr_cellul_span_not()

EMBED_HOST_DEVICE size_t mmgr_cellul_span_not ( const CatenaFinitaCfg * args)

Counts the bytes at the start of src that the set other does not hold.

Parameters
[in]argsBytes src, the extent cap, and the terminated set other [BORROWS].
Returns
The count of bytes before the first byte that other holds, the terminator or cap.
Note
An empty set counts every byte before the terminator or cap.
Warning
other must end in a terminator. The aligned words that hold src's first and last bytes are read whole.

References mmgr_cellul_span_not().

Referenced by mmgr_cellul_span_not().

◆ mmgr_cellul_chr_last()

EMBED_HOST_DEVICE const char * mmgr_cellul_chr_last ( const CatenaFinitaCfg * args)

Finds the last occurrence of args->byte in src, before the terminator.

Parameters
[in]argsBytes src, the extent cap, and the byte sought [BORROWS].
Returns
Address inside src, or NULL when the byte does not occur [BORROWS].
Note
A byte of 0 returns the terminator's own address, or src plus cap when no terminator is in range, as mmgr_cellul_chr does.
Warning
src must be readable for cap bytes.

References mmgr_cellul_chr_last().

Referenced by mmgr_cellul_chr_last().

◆ mmgr_cellul_span_last()

EMBED_HOST_DEVICE size_t mmgr_cellul_span_last ( const CatenaFinitaCfg * args)

Counts the bytes at the end of src's cap bytes that the set other holds.

Parameters
[in]argsBytes src, the extent cap, and the terminated set other [BORROWS].
Returns
The count of bytes after the last byte that other does not hold, or cap.
Note
The count starts at src plus cap and walks down. A terminator is a byte that no set holds, and it stops the count.
An empty set counts 0.
Warning
other must end in a terminator. The aligned words that hold src's first and last bytes are read whole.

References mmgr_cellul_span_last().

Referenced by mmgr_cellul_span_last().

◆ mmgr_cellul_span_not_last()

EMBED_HOST_DEVICE size_t mmgr_cellul_span_not_last ( const CatenaFinitaCfg * args)

Counts the bytes at the end of src's cap bytes that the set other does not hold.

Parameters
[in]argsBytes src, the extent cap, and the terminated set other [BORROWS].
Returns
The count of bytes after the last byte that other holds, or cap.
Note
The count starts at src plus cap and walks down. A terminator is a byte that no set holds, and the count goes past it.
An empty set counts cap.
Warning
other must end in a terminator. The aligned words that hold src's first and last bytes are read whole.

References mmgr_cellul_span_not_last().

Referenced by mmgr_cellul_span_not_last().

Variable Documentation

◆ cellul

const CellularumLaboroNs cellul
static

Dispatch table instance named cellul, with each member set to its mmgr_cellul_ function.

Definition at line 422 of file cellularum_laboro.h.