projects
/
nmutil.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
b5e82ab
)
add clz function
author
Jacob Lifshay
<programmerjake@gmail.com>
Thu, 5 May 2022 05:49:37 +0000
(22:49 -0700)
committer
Jacob Lifshay
<programmerjake@gmail.com>
Thu, 5 May 2022 05:49:37 +0000
(22:49 -0700)
src/nmutil/clz.py
patch
|
blob
|
history
diff --git
a/src/nmutil/clz.py
b/src/nmutil/clz.py
index c94222610bc29c49583a0eb12a01c58bac4760f8..70e0f513c45b52034c9aac5aac8d86dd55d76a38 100644
(file)
--- a/
src/nmutil/clz.py
+++ b/
src/nmutil/clz.py
@@
-12,6
+12,14
@@
import math
"""
+def clz(v, width):
+ """count leading zeros."""
+ assert isinstance(width, int) and 0 <= width
+ max_v = (1 << width) - 1
+ assert isinstance(v, int) and 0 <= v <= max_v
+ return max_v.bit_length() - v.bit_length()
+
+
class CLZ(Elaboratable):
def __init__(self, width):
self.width = width