import unittest
from soc.decoder.selectable_int import SelectableInt, onebit
-from nmutil.divmod import trunc_div, trunc_rem
+from nmutil.divmod import trunc_divs, trunc_rems
+from operator import floordiv, mod
from soc.decoder.selectable_int import selectltu as ltu
from soc.decoder.selectable_int import selectgtu as gtu
+trunc_div = floordiv
+trunc_rem = mod
+DIVS = trunc_divs
+MODS = trunc_rems
+
"""
Links:
* https://bugs.libre-soc.org/show_bug.cgi?id=324 - add trunc_div and trunc_rem
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, ltu, gtu, length,
- trunc_div, trunc_rem)
+ trunc_divs, trunc_rems, MULS, DIVS, MODS)
from soc.decoder.selectable_int import SelectableInt
from soc.decoder.selectable_int import selectconcat as concat
from soc.decoder.orderedset import OrderedSet
from soc.fu.div.pipe_data import DIVPipeSpec
import random
+def log_rand(n, min_val=1):
+ logrange = random.randint(1, n)
+ return random.randint(min_val, (1<<logrange)-1)
def get_cu_inputs(dec2, sim):
"""naming (res) must conform to DIVFunctionUnit input regspec
choice = random.choice(insns)
lst = [f"{choice} 3, 1, 2"]
initial_regs = [0] * 32
- initial_regs[1] = random.randint(0, (1<<64)-1)
- initial_regs[2] = random.randint(0, (1<<64)-1)
+ initial_regs[1] = log_rand(32)
+ initial_regs[2] = log_rand(32)
self.run_tst_program(Program(lst), initial_regs)
+ def test_divwuo_regression_1(self):
+ lst = ["divwuo. 3, 1, 2"]
+ initial_regs = [0] * 32
+ initial_regs[1] = 0x7591a398c4e32b68
+ initial_regs[2] = 0x48674ab432867d69
+ self.run_tst_program(Program(lst), initial_regs)
+
+ def test_divwuo_1(self):
+ lst = ["divwuo. 3, 1, 2"]
+ initial_regs = [0] * 32
+ initial_regs[1] = 0x50
+ initial_regs[2] = 0x2
+ self.run_tst_program(Program(lst), initial_regs)
+
def test_rand_divwu(self):
insns = ["divwu", "divwu.", "divwuo", "divwuo."]
for i in range(40):
choice = random.choice(insns)
lst = [f"{choice} 3, 1, 2"]
initial_regs = [0] * 32
- initial_regs[1] = random.randint(0, (1<<64)-1)
- initial_regs[2] = random.randint(0, (1<<64)-1)
+ initial_regs[1] = log_rand(32)
+ initial_regs[2] = log_rand(32)
self.run_tst_program(Program(lst), initial_regs)
def test_ilang(self):