Skip to content

Instantly share code, notes, and snippets.

@paniq
Created July 18, 2024 15:08
Show Gist options
  • Save paniq/655941302aa0b278487b10e03ec0b416 to your computer and use it in GitHub Desktop.
Save paniq/655941302aa0b278487b10e03ec0b416 to your computer and use it in GitHub Desktop.
fn bitstripes (n)
-1:u64 // ((1:u64 << n) | 1)
fn logleveld (x)
findmsb x
fn tt->anf (x)
w := (x == 0) 0 (logleveld x)
S := (logleveld w) + 1
x := fold (x) for i in (range S)
w := 1:u64 << i
M0 := bitstripes w
M1 := M0 << w
k := x & M0
k | ((x & M1) ^ (k << w))
pass x S
fn anf->tt (x S)
fold (x) for i in (rrange S)
w := 1:u64 << i
M0 := bitstripes w
M1 := M0 << w
k := x & M0
k | ((x & M1) ^ (k << w))
for x in (range 256:u64)
y S := tt->anf x
x2 := anf->tt y S
print
/nolines
/bin x
/anf y
assert (x == x2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment