Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_zeros(s):
- if len(s) == 1: return ~s
- upper_bits = 1 << ceil_log2(len(s)) - 1
- upper = count_zeros(s[-upper_bits:])
- lower = count_zeros(s[:-upper_bits])
- lower = Cat(lower, C(0, len(upper) - len(lower)))
- msbs = Cat(lower[-1], upper[-1])
- out = Mux(msbs.matches("11"), C(1 << len(upper)),
- Mux(msbs.matches("10"), Cat(lower[:-1], C(1, 2)), Cat(upper, C(0))))
- return out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement