projects
/
openpower-isa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ea985e2
)
add log2 pseudo-code helper
author
Jacob Lifshay
<programmerjake@gmail.com>
Tue, 18 Jan 2022 04:57:03 +0000
(20:57 -0800)
committer
Jacob Lifshay
<programmerjake@gmail.com>
Tue, 18 Jan 2022 04:57:03 +0000
(20:57 -0800)
src/openpower/decoder/helpers.py
patch
|
blob
|
history
diff --git
a/src/openpower/decoder/helpers.py
b/src/openpower/decoder/helpers.py
index e37d4777ce1d99f85da0f512baa50b8246c60f6d..3dba556771aacd8bda20884a14e0c2be4bc66e1a 100644
(file)
--- a/
src/openpower/decoder/helpers.py
+++ b/
src/openpower/decoder/helpers.py
@@
-360,6
+360,15
@@
def bitrev(val, VL):
return result
+def log2(val):
+ """return the base-2 logarithm of `val`. Only works for powers of 2."""
+ if isinstance(val, SelectableInt):
+ val = val.value
+ retval = val.bit_length() - 1
+ assert val == 2 ** retval, "value is not a power of 2"
+ return retval
+
+
# For these tests I tried to find power instructions that would let me
# isolate each of these helper operations. So for instance, when I was
# testing the MASK() function, I chose rlwinm and rldicl because if I