MMgr v2.3.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_HOST_DEVICE embed_iword mmgr_clz_lead (const ClzCfg *args)
 Counts the zero bits above the highest set bit of args->val.
EMBED_HOST_DEVICE 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. So these sit under the SWAR walks and not among the general tools.
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 appear in plain code and not through a builtin. A builtin 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 receive 0 tests for it first.

Definition in file clz.h.