MMgr v1.0.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
clz.h File Reference

Leading and trailing zero counts: the argument type, the two calls, and the clz dispatch table. More...

#include "mmgr.h"

Go to the source code of this file.

Data Structures

struct  ClzCfg
 Argument for both clz calls: the value to count zeros in. More...
struct  ClzNs
 Type of the clz dispatch table. More...

Functions

embed_iword mmgr_clz_lead (const ClzCfg *args)
 Counts the zero bits above the highest set bit of args->val.
embed_iword mmgr_clz_trail (const ClzCfg *args)
 Counts the zero bits below the lowest set bit of args->val.

Variables

static const ClzNs clz
 Dispatch table instance named clz, with each member set to its mmgr_clz_ function.

Detailed Description

Leading and trailing zero counts: the argument type, the two calls, and the clz dispatch table.

Author
dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Date
2026-08-29
Note
A zero count is how a scan turns a lane mask into a lane index, and so these sit under the SWAR walks instead of being a general utility.
Both run branchless and in a fixed number of steps. A caller pays the same whatever the value is. That is the ground on which they are written out and not reached through a builtin, which is absent on some targets and a call on others.
Warning
Neither distinguishes a value of 0 from a value with one bit set at the end it counts from. A caller that can be handed 0 tests for it first.

Definition in file clz.h.

Function Documentation

◆ mmgr_clz_lead()

embed_iword mmgr_clz_lead ( const ClzCfg * args)

Counts the zero bits above the highest set bit of args->val.

Parameters
[in]argsValue to measure [BORROWS].
Returns
Leading zero count, 0 through 63.
Note
Runs in a fixed number of steps, none of which branches on the value.
Warning
An args->val of 0 returns 63, the same answer as an args->val of 1.

References mmgr_clz_lead().

Referenced by mmgr_clz_lead().

◆ mmgr_clz_trail()

embed_iword mmgr_clz_trail ( const ClzCfg * args)

Counts the zero bits below the lowest set bit of args->val.

Parameters
[in]argsValue to measure [BORROWS].
Returns
Trailing zero count, 0 through 63.
Note
Runs in a fixed number of steps, none of which branches on the value.
Warning
An args->val of 0 returns 63, the same answer as an args->val of 2^63.

References mmgr_clz_trail().

Referenced by mmgr_clz_trail().

Variable Documentation

◆ clz

const ClzNs clz
static

Dispatch table instance named clz, with each member set to its mmgr_clz_ function.

Definition at line 73 of file clz.h.