Created
July 30, 2018 04:01
-
-
Save pervognsen/f2e0121d2f734932cfcec5a41d5d53b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def funnel_shifter(x, n): | |
assert 2 * 2**len(n) - 1 == len(x) | |
for i, b in enumerate(n): | |
x = when(b, x[2**i:], x[:-2**i]) | |
return x | |
def funnel_right_shifter(x, n): | |
return funnel_shifter(x @ bit[len(x)-1](0), n) | |
def funnel_arithmetic_right_shifter(x, n): | |
return funnel_shifter(x @ rep(x[-1], len(x)-1), n) | |
def funnel_left_shifter(x, n): | |
return funnel_shifter(bit[len(x)-1](0) @ x, ~n) | |
def funnel_right_rotator(x, n): | |
return funnel_shifter(x @ x[:-1], n) | |
def funnel_left_rotator(x, n): | |
return funnel_shifter(x[1:] @ x, ~n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment