import unittest
from soc.decoder.selectable_int import SelectableInt
+"""
+Links:
+* https://bugs.libre-soc.org/show_bug.cgi?id=324 - add trunc_div and trunc_rem
+"""
def exts(value, bits):
sign = 1 << (bits - 1)
return (value & (sign - 1)) - (value & sign)
+def trunc_div(n, d):
+ f = getattr(n, "trunc_div", None)
+ if f is not None:
+ return f(d)
+ fr = getattr(d, "rtrunc_div", None)
+ if fr is not None:
+ return fr(n)
+ abs_n = abs(n)
+ abs_d = abs(d)
+ abs_q = n // d
+ if (n < 0) == (d < 0):
+ return abs_q
+ return -abs_q
+
+def trunc_rem(n, d):
+ f = getattr(n, "trunc_rem", None)
+ if f is not None:
+ return f(d)
+ fr = getattr(d, "rtrunc_rem", None)
+ if fr is not None:
+ return fr(n)
+ return n - d * trunc_div(n, d)
+
def EXTS(value):
""" extends sign bit out from current MSB to all 256 bits
from soc.decoder.selectable_int import (FieldSelectableInt, SelectableInt,
selectconcat)
from soc.decoder.power_enums import spr_dict, XER_bits, insns, InternalOp
-from soc.decoder.helpers import exts
+from soc.decoder.helpers import exts, trunc_div, trunc_rem
from collections import namedtuple
import math
import sys
print("args", args)
print("-->", " ".join(map(str, args)))
- from soc.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)
+ from soc.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,
+ trunc_div, trunc_rem)
d = {}
d["print"] = print_
d["EXTS64"] = EXTS64
d["EXTZ64"] = EXTZ64
+ d["trunc_div"] = trunc_div
+ d["trunc_rem"] = trunc_rem
d["SelectableInt"] = SelectableInt
d["concat"] = selectconcat
d["GPR"] = gsc.gpr
from soc.decoder.isa.caller import inject, instruction_info
from soc.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32, MASK,
- ne, eq, gt, ge, lt, le, length)
+ ne, eq, gt, ge, lt, le, length,
+ trunc_div, trunc_rem)
from soc.decoder.selectable_int import SelectableInt
from soc.decoder.selectable_int import selectconcat as concat
from soc.decoder.orderedset import OrderedSet