d44457fc32
* bump snarkvm rev * update default gitignore * impl leo execute * bump snarkvm 0.14.5 * modify examples wip * update run.sh examples * impl env file * clippy warning * fix auction example * fix auction example env * generate new private key for new env - tests failing due to env not found err * commit error changes * Fix tests; clippy * Get examples working * leo build checks that build dir is well formed; clippy * Clean up * Update examples/README.md Co-authored-by: d0cd <pranavsaig@gmail.com> Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> * do not commit .avm files * use snarkvm commands --------- Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> Co-authored-by: Pranav Gaddamadugu <pranav@aleo.org> Co-authored-by: d0cd <pranavsaig@gmail.com> |
||
---|---|---|
.. | ||
build | ||
inputs | ||
src | ||
.env | ||
.gitignore | ||
program.json | ||
README.md |
src/ntzgaudet.leo
Build Guide
To compile and run this Leo program, run:
leo run
The Algorithm
This algorithm is described in "Hacker's Delight, 2nd edition" by Henry S. Warren, section 5-4, section 5-24, as interesting due to being branch-free, not using table lookups, and having parallelism. It is attributed to Dean Gaudet in private communication to Henry S. Warren.
First we isolate the rightmost 1
bit in the 32-bit input by
using the C idiom x & (-x)
. In Leo, the -x
is
written as 0u32.sub_wrapped(x)
. The result is stored in y
.
Then we compute six intermediate variables that count different numbers
of trailing zeros. The first variable, bz
, just counts 1 if y
is completely zero.
To get the other five variables, we do binary search in parallel, using 5 masks,
each looking at a different symmetric pattern of 16 bits. For example, b4
counts 16 if
the low 16 bits are zero and counts zero otherwise. Then b3
uses a mask y & 0x00FF00FF
to count eight 0-bits if the result is zero and zero 0-bits
otherwise. The masks for b2
, b1
, and b0
can count four, two, and
one 0-bits similarly.
The varables bz, b4, .., b0
are all independent, and their values are added up
for the result.