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
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]