From 4386dd8bb2d41db227263a947bface79d5acaf0c Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 17 Jan 2022 20:57:03 -0800 Subject: [PATCH] add log2 pseudo-code helper --- src/openpower/decoder/helpers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/openpower/decoder/helpers.py b/src/openpower/decoder/helpers.py index e37d4777..3dba5567 100644 --- 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 -- 2.30.2