power_insn: remove the whitespaces properly
[openpower-isa.git] / src / openpower / decoder / helpers.py
index e37d4777ce1d99f85da0f512baa50b8246c60f6d..a81c3f09f75d112e592b86f3f47da8f2786f0b6c 100644 (file)
@@ -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
@@ -462,6 +471,20 @@ class ISACallerHelper:
     def EXTSXL(self, value, bits):
         return SelectableInt(exts(value.value, bits), self.XLEN)
 
+    def DOUBLE2SINGLE(self, FRS):
+        """ DOUBLE2SINGLE has been renamed to FRSP since it is the
+            implementation of the frsp instruction.
+            use SINGLE() or FRSP() instead, or just use struct.pack/unpack
+        """
+        FPSCR = {
+            'UE': SelectableInt(0, 1),
+            'OE': SelectableInt(0, 1),
+            'RN': SelectableInt(0, 2),  # round to nearest, ties to even
+            'XX': SelectableInt(0, 1),
+        }
+        FRT, FPSCR = self.FRSP(FRS, FPSCR)
+        return FRT
+
     def __getattr__(self, attr):
         try:
             return globals()[attr]