MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
verbum_scrutor.h
Go to the documentation of this file.
1/* MMgr - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Commercial OR LicenseRef-Educational
3 *
4 * Every use falls under AGPL-3.0-or-later unless you hold explicit permission, which is either a
5 * negotiated commercial licensing contract or an educator's license issued to you personally.
6 */
7/**
8 * @file verbum_scrutor.h
9 * @brief SWAR byte tests, the lane constants, the arguments, and the lane, mask and word dispatch
10 * tables.
11 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
12 * @date 2026-08-29
13 *
14 * @note One embed_word counts as MMGR_SWAR_BYTES independent lanes. One test covers a whole word at once.
15 * @note A lane mask carries one set bit per lane that matches, in that lane's high bit. mask.spread widens it.
16 * @note The entries whose sense depends on byte order bind through EMBED_BIG_ENDIAN in the tables below.
17 */
18#ifndef MMGR_VERBUM_SCRUTOR_H
19#define MMGR_VERBUM_SCRUTOR_H
20
21/** @addtogroup mod_scrut
22 * @{ */
23
25
26#include "mmgr.h"
27
28EMBED_BEGIN_DECLS
29
30/**
31 * @brief Expands to sizeof(embed_word), and that is how many lanes one word carries.
32 *
33 * @note Eight at EMBED_WORD_BITS 64, four at 32 and two at 16.
34 * @note Also the value both lane index calls report when the mask they receive is empty.
35 */
36#define MMGR_SWAR_BYTES (sizeof(embed_word))
37
38/**
39 * @brief Expands to EMBED_WORD_BITS, the width of a whole word in bits.
40 *
41 * @note This is the word's width and not one lane's, despite the name. A lane is eight bits.
42 * @note Bounds the shift that doubles in scrut_smear and supplies the final shift in scrut_lane_count, both of
43 * which want the whole width.
44 */
45#define MMGR_SWAR_LANE_BITS (EMBED_WORD_BITS)
46
47/**
48 * @brief Expands to a word with 1 in every lane, which is 0x0101...01.
49 *
50 * @note A multiply of it by a byte broadcasts that byte into every lane, and that is how the comparisons start.
51 * @note A multiply of a lane mask by it sums the lanes, and that is how scrut_lane_count counts them.
52 */
53#define MMGR_SWAR_ONES (((embed_word) ~(embed_word)0) / 0xFFu)
54
55/**
56 * @brief Expands to a word with 0x80 in every lane, which is 0x8080...80.
57 *
58 * @note The shape every lane mask takes. A caller can and two masks together lane by lane.
59 * @note An or of it into a word before a subtraction gives each lane a borrow to spend, which retains lanes apart.
60 */
61#define MMGR_VERBUM_SCRUTOR_HIGH (MMGR_SWAR_ONES * 0x80u)
62
63/**
64 * @brief Expands to a word with 0x7F in every lane, which is 0x7F7F...7F.
65 *
66 * @note The complement of MMGR_VERBUM_SCRUTOR_HIGH, and so the two split each lane into its value and its mask bit.
67 * @note scrut_has_zero adds it to make every non-zero lane carry into its high bit.
68 */
69#define MMGR_SWAR_LOW7 (MMGR_SWAR_ONES * 0x7Fu)
70
71/**
72 * @brief Expands to 0, the first of three verdicts a scan step can report.
73 *
74 * @note MMGR_SWAR_GO, MMGR_SWAR_YES and MMGR_SWAR_NO are 0, 1 and 2, and so the three fit in one byte.
75 * @note The three carry no size suffix, and so each takes int in an expression. A scanner that retains a
76 * verdict in a uint8_t converts it on the way in.
77 * @note verbum_scrutor.c reads none of the three. They are here for the scanners that
78 * include it.
79 */
80#define MMGR_SWAR_GO 0
81
82/** @brief Expands to 1, the second of the three verdicts described at MMGR_SWAR_GO. */
83#define MMGR_SWAR_YES 1
84
85/** @brief Expands to 2, the third of the three verdicts described at MMGR_SWAR_GO. */
86#define MMGR_SWAR_NO 2
87
88/**
89 * @brief Expands to 0x60u, the two bits that separate the ASCII blocks a character can fall in.
90 *
91 * @note Passed to lane.fam_eq as the family, with MMGR_FAM_CI as the byte, to pick out the capital block.
92 */
93#define MMGR_FAM_CS 0x60u
94
95/**
96 * @brief Expands to 0x40u, the value the MMGR_FAM_CS bits take across the 0x40 to 0x5F block.
97 *
98 * @note That block holds A through Z along with six other bytes: the at sign, and the five that follow Z.
99 */
100#define MMGR_FAM_CI 0x40u
101
102/**
103 * @brief Arguments for the lane calls.
104 *
105 * @note ge, le and sub7 read word and byte. eq adds ci. xor_ reads word, val and ci. fam_eq adds fam.
106 * @note has_zero, alpha, any_upper and any_digit read word alone.
107 * @note count, first and last read mask alone.
108 */
109typedef struct
110{
111 const embed_word word; /**< The MMGR_SWAR_BYTES bytes under test, one per lane. */
112 const embed_word val; /**< Whole word xor_ compares against, which the caller broadcasts itself. */
113 const embed_word mask; /**< Lane mask the three index calls read. */
114 const uint8_t byte; /**< Byte the call broadcasts into every lane before the compare. */
115 const uint8_t fam; /**< Bits fam_eq retains on both sides before the compare. */
116 const embed_bool ci; /**< Non-zero to let a character match either case. */
118
119/**
120 * @brief Arguments for the mask calls.
121 *
122 * @note spread, drop_first, drop_last and before read mask.
123 * @note bytes_below, lanes_below and run_edge read bytes.
124 * @note run reads both mask and bytes. tail reads bytes and wi, and is the only call that reads wi.
125 */
126typedef struct
127{
128 const embed_word mask; /**< Lane mask to reshape or examine. */
129 const size_t bytes; /**< Byte count under the mask, or the run length wanted. */
130 const size_t wi; /**< Whole words a scan has already covered. */
132
133/**
134 * @brief Arguments for the word calls.
135 *
136 * @note load and load_al read at. fold_lower reads word. count reads bytes.
137 */
138typedef struct
139{
140 const embed_word word; /**< Word fold_lower folds. */
141 const void *const at; /**< Address the two loads read a word from [BORROWS]. */
142 const size_t bytes; /**< Byte count count converts into a word count. */
144
145/**
146 * @brief Type of the lane dispatch table.
147 *
148 * @note EMBED_TABLE_LAYOUT asserts the thirteen members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
149 * nothing else.
150 * @note Eight of the first ten return lane masks. sub7 returns seven bit values and xor_ a whole word.
151 * @note count, first and last return positions instead of words.
152 * @note first and last mean first and last in memory order, as the endian binding below delivers.
153 * @note xor_ carries a trailing underscore because xor is an alternative form of an operator in C++.
154 */
155typedef struct
156{
157 embed_word (*ge)(const ScrutLaneCfg *args); /**< Lanes at or above a byte. */
158 embed_word (*le)(const ScrutLaneCfg *args); /**< Lanes at or below a byte. */
159 embed_word (*sub7)(const ScrutLaneCfg *args); /**< Seven low bits of each lane's difference from a byte. */
160 embed_word (*has_zero)(const ScrutLaneCfg *args); /**< Lanes with zero. */
161 embed_word (*eq)(const ScrutLaneCfg *args); /**< Lanes equal to a byte. */
162 embed_word (*xor_)(const ScrutLaneCfg *args); /**< Lane by lane difference of two words. */
163 embed_word (*fam_eq)(const ScrutLaneCfg *args); /**< Lanes that match a byte within a set of bits. */
164 embed_word (*any_upper)(const ScrutLaneCfg *args); /**< Lanes whose MMGR_FAM_CS bits equal MMGR_FAM_CI. */
165 embed_word (*any_digit)(const ScrutLaneCfg *args); /**< Lanes in the 0x30 to 0x3F block. */
166 embed_word (*alpha)(const ScrutLaneCfg *args); /**< Lanes with an ASCII character. */
167 size_t (*count)(const ScrutLaneCfg *args); /**< How many lanes of a mask hold. */
168 size_t (*first)(const ScrutLaneCfg *args); /**< Index of the first set lane in memory order. */
169 size_t (*last)(const ScrutLaneCfg *args); /**< Index of the last set lane in memory order. */
171EMBED_TABLE_LAYOUT(ScrutLaneNs, ge, le, sub7, has_zero, eq, xor_, fam_eq, any_upper, any_digit, alpha, count, first,
172 last);
173
174/**
175 * @brief Type of the mask dispatch table.
176 *
177 * @note EMBED_TABLE_LAYOUT asserts the nine members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
178 * nothing else.
179 * @note drop_first, drop_last and before all mean memory order, which the endian binding below delivers.
180 */
181typedef struct
182{
183 embed_word (*spread)(const ScrutMaskCfg *args); /**< Widens each set lane to a full byte of ones. */
184 embed_word (*drop_first)(const ScrutMaskCfg *args); /**< Clears the first set lane in memory order. */
185 embed_word (*drop_last)(const ScrutMaskCfg *args); /**< Clears the last set lane in memory order. */
186 embed_word (*bytes_below)(const ScrutMaskCfg *args); /**< Full byte mask over the first bytes of a word. */
187 embed_word (*lanes_below)(const ScrutMaskCfg *args); /**< Lane mask over the first lanes of a word. */
188 embed_word (*before)(const ScrutMaskCfg *args); /**< Lanes ahead of the first set one in memory order. */
189 embed_word (*tail)(const ScrutMaskCfg *args); /**< Lane mask for a scan's last partial word. */
190 embed_word (*run)(const ScrutMaskCfg *args); /**< Lanes that begin a run of set lanes. */
191 embed_word (*run_edge)(const ScrutMaskCfg *args); /**< Lanes too near the end for a run to fit. */
193EMBED_TABLE_LAYOUT(ScrutMaskNs, spread, drop_first, drop_last, bytes_below, lanes_below, before, tail, run, run_edge);
194
195/**
196 * @brief Type of the word dispatch table.
197 *
198 * @note EMBED_TABLE_LAYOUT asserts the four members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
199 * nothing else.
200 * @note Its count member converts a byte count into a word count, where the lane table's count counts lanes.
201 */
202typedef struct
203{
204 embed_word (*load)(const ScrutWordCfg *args); /**< Reads a word from any address. */
205 embed_word (*load_al)(const ScrutWordCfg *args); /**< Reads a word from an aligned address. */
206 embed_word (*fold_lower)(const ScrutWordCfg *args); /**< Turns every character lane to lower case. */
207 size_t (*count)(const ScrutWordCfg *args); /**< Words a scan of a byte count must read. */
209EMBED_TABLE_LAYOUT(ScrutWordNs, load, load_al, fold_lower, count);
210
211/**
212 * @brief Marks the lanes of args->word that are at or above args->byte.
213 *
214 * @param[in] args The word and the byte to compare against [BORROWS].
215 * @return A lane mask with those lanes.
216 * @note Compares bytes as unsigned, and 0x80 and above are the largest values.
217 * @warning args->byte must be under 0x80. At or above it the lanes under 0x80 come out wrong and nothing
218 * diagnoses it.
219 */
220EMBED_HOST_DEVICE embed_word mmgr_scrut_ge(const ScrutLaneCfg *args);
221
222/**
223 * @brief Marks the lanes of args->word that are at or below args->byte.
224 *
225 * @param[in] args The word and the byte to compare against [BORROWS].
226 * @return A lane mask with those lanes.
227 * @note Compares bytes as unsigned, and 0x80 and above are the largest values.
228 * @warning args->byte must be under 0x80, for the reason given on mmgr_scrut_ge.
229 * @note And this with mmgr_scrut_ge to get a range test, as mmgr_scrut_alpha does.
230 */
231EMBED_HOST_DEVICE embed_word mmgr_scrut_le(const ScrutLaneCfg *args);
232
233/**
234 * @brief Subtracts args->byte from every lane of args->word and retains the low seven bits of each result.
235 *
236 * @param[in] args The word and the byte to subtract [BORROWS].
237 * @return The seven low bits of each lane's difference, every lane's high bit clear.
238 * @note Yields values and not a lane mask, unlike every other lane entry but count, first and last.
239 * @warning A lane below args->byte wraps, and so its seven bits are the difference taken modulo 128.
240 * @warning args->byte must be under 0x80, for the reason given on mmgr_scrut_ge: at or above it a borrow reaches
241 * the next lane.
242 */
243EMBED_HOST_DEVICE embed_word mmgr_scrut_sub7(const ScrutLaneCfg *args);
244
245/**
246 * @brief Marks the lanes of args->word that hold zero.
247 *
248 * @param[in] args The word to test [BORROWS].
249 * @return A lane mask with the zero lanes.
250 * @note Reads args->word alone, and byte, val, fam and ci take no part.
251 * @note Apply this to the result of mmgr_scrut_xor to find where two words agreed.
252 */
253EMBED_HOST_DEVICE embed_word mmgr_scrut_has_zero(const ScrutLaneCfg *args);
254
255/**
256 * @brief Marks the lanes of args->word that equal args->byte.
257 *
258 * @param[in] args The word, the byte to find, and the case flag [BORROWS].
259 * @return A lane mask with the lanes that match.
260 * @note Broadcasts args->byte itself, and so the caller passes a single byte and not a whole word.
261 * @note With args->ci set, a character matches either case. Every other byte still compares exactly.
262 */
263EMBED_HOST_DEVICE embed_word mmgr_scrut_eq(const ScrutLaneCfg *args);
264
265/**
266 * @brief Returns the lane by lane difference of args->word and args->val.
267 *
268 * @param[in] args The two words and the case flag [BORROWS].
269 * @return A word whose lanes are zero exactly where the two agreed.
270 * @note Takes a whole word in args->val, and so the caller broadcasts a byte itself if it wants that.
271 * @note With args->ci set, the case bit goes to zero on character lanes, and so the two cases of a character agree.
272 * @note Pass the result to mmgr_scrut_has_zero to turn it into a lane mask.
273 */
274EMBED_HOST_DEVICE embed_word mmgr_scrut_xor(const ScrutLaneCfg *args);
275
276/**
277 * @brief Marks the lanes of args->word that match args->byte once both reduce to the args->fam bits.
278 *
279 * @param[in] args The word, the byte to match, and the bits that count [BORROWS].
280 * @return A lane mask with the lanes that match.
281 * @note args->fam reduces args->byte first, and so bits outside the family take no part on either side.
282 * @note A args->fam of 0xFF makes this an exact match, and an args->fam of 0 marks every lane.
283 */
284EMBED_HOST_DEVICE embed_word mmgr_scrut_fam_eq(const ScrutLaneCfg *args);
285
286/**
287 * @brief Marks the lanes of args->word whose MMGR_FAM_CS bits equal MMGR_FAM_CI, the 0x40 to 0x5F block.
288 *
289 * @param[in] args The word to test [BORROWS].
290 * @return A lane mask with those lanes.
291 * @note Reads args->word alone, since the family and the byte are both fixed.
292 * @warning That block holds six bytes that are not capitals, the at sign and the five after Z. Bit
293 * seven takes no part, and so 0xC0 to 0xDF gets a mark as well. And it with mmgr_scrut_alpha
294 * for characters alone.
295 */
296EMBED_HOST_DEVICE embed_word mmgr_scrut_any_upper(const ScrutLaneCfg *args);
297
298/**
299 * @brief Marks the lanes of args->word that fall in the 0x30 to 0x3F block.
300 *
301 * @param[in] args The word to test [BORROWS].
302 * @return A lane mask with those lanes.
303 * @note Reads args->word alone, since the family and the byte are both fixed.
304 * @warning That block holds six symbols after the nine, and so this marks more than 0 through 9. And it
305 * with mmgr_scrut_le at the character nine when only the ten digits should count.
306 */
307EMBED_HOST_DEVICE embed_word mmgr_scrut_any_digit(const ScrutLaneCfg *args);
308
309/**
310 * @brief Marks the lanes of args->word with an ASCII character, of either case.
311 *
312 * @param[in] args The word to test [BORROWS].
313 * @return A lane mask with the character lanes.
314 * @note Reads args->word alone, and byte, val, fam and ci take no part.
315 * @note A byte at 0x80 or above is never marked, and so this is exact where mmgr_scrut_any_upper is not.
316 * Beyond the ten digits mmgr_scrut_any_digit marks only the six symbols after the nine
317 * and never a high byte.
318 */
319EMBED_HOST_DEVICE embed_word mmgr_scrut_alpha(const ScrutLaneCfg *args);
320
321/**
322 * @brief Counts the set lanes of args->mask.
323 *
324 * @param[in] args The lane mask to count [BORROWS].
325 * @return How many lanes hold, 0 through MMGR_SWAR_BYTES.
326 * @note Reads args->mask alone, and so word, byte, val, fam and ci take no part.
327 * @warning Expects a lane mask, one bit per lane in that lane's high bit. A spread mask counts wrong.
328 */
329EMBED_HOST_DEVICE size_t mmgr_scrut_lane_count(const ScrutLaneCfg *args);
330
331/**
332 * @brief Returns the index of the lowest set lane of args->mask.
333 *
334 * @param[in] args The lane mask to examine [BORROWS].
335 * @return The index, or MMGR_SWAR_BYTES when no lane holds.
336 * @note The lane table reaches this as first on a little endian target and as last on a big endian one. So
337 * prefer lane.first or lane.last when memory order is what matters.
338 * @note A return of MMGR_SWAR_BYTES is one past the last valid index, and that is how an empty mask reports.
339 */
340EMBED_HOST_DEVICE size_t mmgr_scrut_lane_lo(const ScrutLaneCfg *args);
341
342/**
343 * @brief Returns the index of the highest set lane of args->mask.
344 *
345 * @param[in] args The lane mask to examine [BORROWS].
346 * @return The index, or MMGR_SWAR_BYTES when no lane holds.
347 * @note The lane table reaches this as last on a little endian target and as first on a big endian one. So
348 * prefer lane.first or lane.last when memory order is what matters.
349 * @note A return of MMGR_SWAR_BYTES is one past the last valid index, and that is how an empty mask reports.
350 */
351EMBED_HOST_DEVICE size_t mmgr_scrut_lane_hi(const ScrutLaneCfg *args);
352
353/**
354 * @brief Widens every set lane of args->mask from its high bit to a full byte of ones.
355 *
356 * @param[in] args The lane mask to widen [BORROWS].
357 * @return A word with 0xFF in each set lane and 0x00 in the rest.
358 * @note Use the result to select between two words lane by lane, which a lane mask alone cannot do.
359 * @warning The result is not a lane mask any more, and so do not hand it to the count or index entries.
360 */
361EMBED_HOST_DEVICE embed_word mmgr_scrut_spread(const ScrutMaskCfg *args);
362
363/**
364 * @brief Clears the lowest set lane of args->mask.
365 *
366 * @param[in] args The lane mask to reduce [BORROWS].
367 * @return The mask with that lane cleared, or 0 when it contained only one.
368 * @note An empty mask stays empty, and a mask that steps down again and again ends and does not wrap.
369 * @note The mask table reaches this as drop_first on a little endian target and drop_last on a big endian one.
370 */
371EMBED_HOST_DEVICE embed_word mmgr_scrut_drop_lo(const ScrutMaskCfg *args);
372
373/**
374 * @brief Clears the highest set lane of args->mask.
375 *
376 * @param[in] args The lane mask to reduce [BORROWS].
377 * @return The mask with that lane cleared, or 0 when it contained only one.
378 * @note An empty mask stays empty, and a mask that steps down again and again ends and does not wrap.
379 * @note The mask table reaches this as drop_last on a little endian target and drop_first on a big endian one.
380 */
381EMBED_HOST_DEVICE embed_word mmgr_scrut_drop_hi(const ScrutMaskCfg *args);
382
383/**
384 * @brief Builds a mask over the first args->bytes bytes of a word, in memory order.
385 *
386 * @param[in] args The byte count to cover [BORROWS].
387 * @return A word of ones over those bytes and zeros over the rest.
388 * @note Covers the bytes that come first in memory on either byte order.
389 * @note A count of 0 gives an empty mask and a count of MMGR_SWAR_BYTES or more gives a full one.
390 */
391EMBED_HOST_DEVICE embed_word mmgr_scrut_bytes_below(const ScrutMaskCfg *args);
392
393/**
394 * @brief Builds a lane mask over the first args->bytes lanes of a word, in memory order.
395 *
396 * @param[in] args The lane count to cover [BORROWS].
397 * @return A lane mask with those lanes.
398 * @note mmgr_scrut_bytes_below reduced to lane bits, and so this ands cleanly against another lane mask.
399 * @note And a match mask with this to retain a scan off bytes past its count.
400 */
401EMBED_HOST_DEVICE embed_word mmgr_scrut_lanes_below(const ScrutMaskCfg *args);
402
403/**
404 * @brief Returns the lanes that come before the first set lane of args->mask, in memory order.
405 *
406 * @param[in] args The lane mask to examine [BORROWS].
407 * @return A lane mask with those lanes.
408 * @note An empty args->mask reports every lane, since nothing comes first.
409 * @note Count the result to get the same index mmgr_scrut_lane_lo reports on a little endian target.
410 */
411EMBED_HOST_DEVICE embed_word mmgr_scrut_lanes_before(const ScrutMaskCfg *args);
412
413/**
414 * @brief Builds the lane mask for the last partial word of a scan of args->bytes bytes.
415 *
416 * @param[in] args The total byte count and the whole words already covered [BORROWS].
417 * @return A lane mask over the bytes still wanted, or 0 once the walk reaches the count.
418 * @note A word wanted in full gets a full mask, and so this can run on every pass of a scan loop.
419 * @note The only mask entry that reads args->wi.
420 */
421EMBED_HOST_DEVICE embed_word mmgr_scrut_tail_mask(const ScrutMaskCfg *args);
422
423/**
424 * @brief Marks the lanes of args->mask that begin a run of args->bytes set lanes.
425 *
426 * @param[in] args The lane mask and the run length wanted [BORROWS].
427 * @return A lane mask with the lanes each run starts at.
428 * @note A lane that survives is where a run begins, in memory order, on either byte order.
429 * @note A args->bytes of 0 or 1 returns args->mask as it is, since every set lane starts such a run.
430 * @warning Returns 0 for an args->bytes above MMGR_SWAR_BYTES, since no run that long fits in one word.
431 */
432EMBED_HOST_DEVICE embed_word mmgr_scrut_run(const ScrutMaskCfg *args);
433
434/**
435 * @brief Marks the lanes too near the end of a word for a run of args->bytes to fit inside it.
436 *
437 * @param[in] args The run length wanted [BORROWS].
438 * @return A lane mask with those lanes, or 0 when no lane is too near.
439 * @note A run of args->bytes can begin at any of the first MMGR_SWAR_BYTES minus args->bytes plus one lanes.
440 * @note A caller that matches across a word boundary uses this to tell which starts need a second try.
441 * @note Returns 0 for an args->bytes of 0 or 1, since any lane can start such a run, and for any length
442 * above MMGR_SWAR_BYTES, since no lane can.
443 */
444EMBED_HOST_DEVICE embed_word mmgr_scrut_run_edge(const ScrutMaskCfg *args);
445
446/**
447 * @brief Loads one embed_word from args->at.
448 *
449 * @param[in] args Address to load from [BORROWS].
450 * @return The bytes at args->at, one per lane, in the target's own order.
451 * @warning Reads MMGR_SWAR_BYTES bytes even for a caller that wants fewer. args->at must be readable for all of them.
452 * @note Any alignment will do. Use mmgr_scrut_load_al for an address that is on the alignment.
453 */
454EMBED_HOST_DEVICE embed_word mmgr_scrut_load(const ScrutWordCfg *args);
455
456/**
457 * @brief Loads one embed_word from an aligned args->at.
458 *
459 * @param[in] args Address to load from [BORROWS].
460 * @return The bytes at args->at, one per lane, in the target's own order.
461 * @warning Reads MMGR_SWAR_BYTES bytes even for a caller that wants fewer, and args->at must are on a word boundary.
462 * @note Use mmgr_scrut_load when the address may sit anywhere.
463 */
464EMBED_HOST_DEVICE embed_word mmgr_scrut_load_al(const ScrutWordCfg *args);
465
466/**
467 * @brief Returns args->word with every character lane turned to lower case.
468 *
469 * @param[in] args The word to fold [BORROWS].
470 * @return The word with its character lanes lowered and every other lane untouched.
471 * @note Only character lanes change. A digit or a symbol retains bit five exactly as it was.
472 * @note Fold two words and compare them for a case insensitive test over whole words at once.
473 */
474EMBED_HOST_DEVICE embed_word mmgr_scrut_fold_lower(const ScrutWordCfg *args);
475
476/**
477 * @brief Returns how many whole words a scan of args->bytes bytes must read.
478 *
479 * @param[in] args The byte count to convert [BORROWS].
480 * @return The count rounded up. A partial last word still counts as one.
481 * @note A args->bytes of 0 gives 0. A caller loops no times instead of reading one word.
482 * @note Pair this with mask.tail, which supplies the lane mask for that partial last word.
483 */
484EMBED_HOST_DEVICE size_t mmgr_scrut_words(const ScrutWordCfg *args);
485
486/**
487 * @brief Dispatch table instance named lane.
488 *
489 * @note The first eleven members call the mmgr_scrut_ function of the same name on either byte order.
490 * @note first and last bind to lane_lo and lane_hi one way round on a little endian target and the
491 * other way on a big endian one. So both always mean memory order.
492 */
493EMBED_TABLE_STORAGE ScrutLaneNs lane EMBED_UNUSED = {
494 .ge = mmgr_scrut_ge,
495 .le = mmgr_scrut_le,
496 .sub7 = mmgr_scrut_sub7,
497 .has_zero = mmgr_scrut_has_zero,
498 .eq = mmgr_scrut_eq,
499 .xor_ = mmgr_scrut_xor,
500 .fam_eq = mmgr_scrut_fam_eq,
501 .any_upper = mmgr_scrut_any_upper,
502 .any_digit = mmgr_scrut_any_digit,
503 .alpha = mmgr_scrut_alpha,
504 .count = mmgr_scrut_lane_count,
505#if EMBED_BIG_ENDIAN
506 .first = mmgr_scrut_lane_hi,
507 .last = mmgr_scrut_lane_lo,
508#else
509 .first = mmgr_scrut_lane_lo,
510 .last = mmgr_scrut_lane_hi,
511#endif
512};
513
514/**
515 * @brief Dispatch table instance named mask.
516 *
517 * @note drop_first and drop_last bind to drop_lo and drop_hi one way round on a little endian target
518 * and the other way on a big endian one. So both always mean memory order.
519 * @note before reaches mmgr_scrut_lanes_before, which carries the same swap inside itself.
520 */
521EMBED_TABLE_STORAGE ScrutMaskNs mask EMBED_UNUSED = {
522 .spread = mmgr_scrut_spread,
523#if EMBED_BIG_ENDIAN
524 .drop_first = mmgr_scrut_drop_hi,
525 .drop_last = mmgr_scrut_drop_lo,
526#else
527 .drop_first = mmgr_scrut_drop_lo,
528 .drop_last = mmgr_scrut_drop_hi,
529#endif
530 .bytes_below = mmgr_scrut_bytes_below,
531 .lanes_below = mmgr_scrut_lanes_below,
532 .before = mmgr_scrut_lanes_before,
533 .tail = mmgr_scrut_tail_mask,
534 .run = mmgr_scrut_run,
535 .run_edge = mmgr_scrut_run_edge,
536};
537
538/**
539 * @brief Dispatch table instance named verbum, with each member set to its mmgr_scrut_ function.
540 *
541 * @note No member depends on byte order, unlike the lane and mask tables above.
542 */
543EMBED_TABLE_STORAGE ScrutWordNs verbum EMBED_UNUSED = {
544 .load = mmgr_scrut_load,
545 .load_al = mmgr_scrut_load_al,
546 .fold_lower = mmgr_scrut_fold_lower,
547 .count = mmgr_scrut_words,
548};
549
550EMBED_END_DECLS
551
552/** @} */
553
554#endif
EMBED_HOST_DEVICE size_t mmgr_scrut_words(const ScrutWordCfg *args)
Returns how many whole words a scan of args->bytes bytes must read.
EMBED_HOST_DEVICE embed_word mmgr_scrut_fam_eq(const ScrutLaneCfg *args)
Marks the lanes of args->word that match args->byte once both reduce to the args->fam bits.
EMBED_HOST_DEVICE embed_word mmgr_scrut_has_zero(const ScrutLaneCfg *args)
Marks the lanes of args->word that hold zero.
EMBED_HOST_DEVICE embed_word mmgr_scrut_xor(const ScrutLaneCfg *args)
Returns the lane by lane difference of args->word and args->val.
EMBED_HOST_DEVICE embed_word mmgr_scrut_bytes_below(const ScrutMaskCfg *args)
Builds a mask over the first args->bytes bytes of a word, in memory order.
EMBED_HOST_DEVICE embed_word mmgr_scrut_sub7(const ScrutLaneCfg *args)
Subtracts args->byte from every lane of args->word and retains the low seven bits of each result.
EMBED_HOST_DEVICE embed_word mmgr_scrut_lanes_before(const ScrutMaskCfg *args)
Returns the lanes that come before the first set lane of args->mask, in memory order.
EMBED_HOST_DEVICE embed_word mmgr_scrut_le(const ScrutLaneCfg *args)
Marks the lanes of args->word that are at or below args->byte.
EMBED_HOST_DEVICE size_t mmgr_scrut_lane_hi(const ScrutLaneCfg *args)
Returns the index of the highest set lane of args->mask.
EMBED_HOST_DEVICE embed_word mmgr_scrut_drop_lo(const ScrutMaskCfg *args)
Clears the lowest set lane of args->mask.
EMBED_HOST_DEVICE embed_word mmgr_scrut_drop_hi(const ScrutMaskCfg *args)
Clears the highest set lane of args->mask.
EMBED_HOST_DEVICE embed_word mmgr_scrut_spread(const ScrutMaskCfg *args)
Widens every set lane of args->mask from its high bit to a full byte of ones.
EMBED_HOST_DEVICE embed_word mmgr_scrut_lanes_below(const ScrutMaskCfg *args)
Builds a lane mask over the first args->bytes lanes of a word, in memory order.
EMBED_HOST_DEVICE embed_word mmgr_scrut_alpha(const ScrutLaneCfg *args)
Marks the lanes of args->word with an ASCII character, of either case.
EMBED_HOST_DEVICE embed_word mmgr_scrut_run(const ScrutMaskCfg *args)
Marks the lanes of args->mask that begin a run of args->bytes set lanes.
EMBED_HOST_DEVICE embed_word mmgr_scrut_tail_mask(const ScrutMaskCfg *args)
Builds the lane mask for the last partial word of a scan of args->bytes bytes.
EMBED_HOST_DEVICE size_t mmgr_scrut_lane_lo(const ScrutLaneCfg *args)
Returns the index of the lowest set lane of args->mask.
EMBED_HOST_DEVICE embed_word mmgr_scrut_any_upper(const ScrutLaneCfg *args)
Marks the lanes of args->word whose MMGR_FAM_CS bits equal MMGR_FAM_CI, the 0x40 to 0x5F block.
static const ScrutLaneNs lane
Dispatch table instance named lane.
static const ScrutMaskNs mask
Dispatch table instance named mask.
EMBED_HOST_DEVICE size_t mmgr_scrut_lane_count(const ScrutLaneCfg *args)
Counts the set lanes of args->mask.
EMBED_HOST_DEVICE embed_word mmgr_scrut_load(const ScrutWordCfg *args)
Loads one embed_word from args->at.
EMBED_HOST_DEVICE embed_word mmgr_scrut_load_al(const ScrutWordCfg *args)
Loads one embed_word from an aligned args->at.
EMBED_HOST_DEVICE embed_word mmgr_scrut_ge(const ScrutLaneCfg *args)
Marks the lanes of args->word that are at or above args->byte.
EMBED_HOST_DEVICE embed_word mmgr_scrut_run_edge(const ScrutMaskCfg *args)
Marks the lanes too near the end of a word for a run of args->bytes to fit inside it.
EMBED_HOST_DEVICE embed_word mmgr_scrut_eq(const ScrutLaneCfg *args)
Marks the lanes of args->word that equal args->byte.
EMBED_HOST_DEVICE embed_word mmgr_scrut_any_digit(const ScrutLaneCfg *args)
Marks the lanes of args->word that fall in the 0x30 to 0x3F block.
static const ScrutWordNs verbum
Dispatch table instance named verbum, with each member set to its mmgr_scrut_ function.
EMBED_HOST_DEVICE embed_word mmgr_scrut_fold_lower(const ScrutWordCfg *args)
Returns args->word with every character lane turned to lower case.
The embedded_types headers every module builds on.
Typed loads and stores, and the proxim dispatch table.
Arguments for the lane calls.
const embed_bool ci
const embed_word word
const embed_word mask
const embed_word val
const uint8_t byte
const uint8_t fam
Type of the lane dispatch table.
embed_word(*) has_zero(const ScrutLaneCfg *args)
embed_word(*) any_upper(const ScrutLaneCfg *args)
embed_word(*) alpha(const ScrutLaneCfg *args)
embed_word(*) sub7(const ScrutLaneCfg *args)
embed_word(*) le(const ScrutLaneCfg *args)
size_t(*) count(const ScrutLaneCfg *args)
embed_word(*) any_digit(const ScrutLaneCfg *args)
embed_word(*) eq(const ScrutLaneCfg *args)
size_t(*) first(const ScrutLaneCfg *args)
size_t(*) last(const ScrutLaneCfg *args)
embed_word(*) xor_(const ScrutLaneCfg *args)
embed_word(*) ge(const ScrutLaneCfg *args)
embed_word(*) fam_eq(const ScrutLaneCfg *args)
Arguments for the mask calls.
const embed_word mask
const size_t bytes
const size_t wi
Type of the mask dispatch table.
embed_word(*) bytes_below(const ScrutMaskCfg *args)
embed_word(*) lanes_below(const ScrutMaskCfg *args)
embed_word(*) drop_last(const ScrutMaskCfg *args)
embed_word(*) spread(const ScrutMaskCfg *args)
embed_word(*) run_edge(const ScrutMaskCfg *args)
embed_word(*) tail(const ScrutMaskCfg *args)
embed_word(*) drop_first(const ScrutMaskCfg *args)
embed_word(*) before(const ScrutMaskCfg *args)
embed_word(*) run(const ScrutMaskCfg *args)
Arguments for the word calls.
const embed_word word
const size_t bytes
const void *const at
Type of the word dispatch table.
size_t(*) count(const ScrutWordCfg *args)
embed_word(*) load(const ScrutWordCfg *args)
embed_word(*) fold_lower(const ScrutWordCfg *args)
embed_word(*) load_al(const ScrutWordCfg *args)