add a DIVS function as separate and discrete from floor_div
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 10 Jul 2020 20:09:30 +0000 (21:09 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 10 Jul 2020 20:09:30 +0000 (21:09 +0100)
likewise for MODS and MULS

libreriscv
src/soc/decoder/helpers.py
src/soc/decoder/isa/caller.py
src/soc/decoder/pseudo/pywriter.py
src/soc/fu/div/test/test_pipe_caller.py

index 2e8b6bf44d7519bfd2085023649f7e5b9acd3b6f..4aa6408d7d1bfc0246020fa69b0f5f850f8e8e70 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 2e8b6bf44d7519bfd2085023649f7e5b9acd3b6f
+Subproject commit 4aa6408d7d1bfc0246020fa69b0f5f850f8e8e70
index 8cab8d50176856c733567a2522d553f44e1aef52..40ddb08859dea969bae2416b029938554769dcd7 100644 (file)
@@ -1,9 +1,15 @@
 import unittest
 from soc.decoder.selectable_int import SelectableInt, onebit
 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
 
 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
 """
 Links:
 * https://bugs.libre-soc.org/show_bug.cgi?id=324 - add trunc_div and trunc_rem
index 711c9650788a03e2b22a8528694014ff7006ad3f..ef6e46dd6d8bea6c18266cf72a0df5ceb4c1fdad 100644 (file)
@@ -15,7 +15,7 @@ from soc.decoder.selectable_int import (FieldSelectableInt, SelectableInt,
                                         selectconcat)
 from soc.decoder.power_enums import (spr_dict, spr_byname, XER_bits,
                                      insns, InternalOp)
                                         selectconcat)
 from soc.decoder.power_enums import (spr_dict, spr_byname, XER_bits,
                                      insns, InternalOp)
-from soc.decoder.helpers import exts, trunc_div, trunc_rem
+from soc.decoder.helpers import exts
 from soc.consts import PI, MSR
 
 from collections import namedtuple
 from soc.consts import PI, MSR
 
 from collections import namedtuple
index 61d6860d4be127740f33cf5ed44ac27fd7695827..f06d996f388399bb8cd078107bc967f394788bbb 100644 (file)
@@ -21,7 +21,7 @@ header = """\
 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,
 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.decoder.selectable_int import SelectableInt
 from soc.decoder.selectable_int import selectconcat as concat
 from soc.decoder.orderedset import OrderedSet
index ba1531128ea76feea3dfebb156cd8e946314a4e8..02f9f996ae3d05ffae43e89f204be77dd6d4b2db 100644 (file)
@@ -17,6 +17,9 @@ from soc.fu.div.pipeline import DIVBasePipe
 from soc.fu.div.pipe_data import DIVPipeSpec
 import random
 
 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
 
 def get_cu_inputs(dec2, sim):
     """naming (res) must conform to DIVFunctionUnit input regspec
@@ -167,18 +170,32 @@ class DIVTestCase(FHDLTestCase):
             choice = random.choice(insns)
             lst = [f"{choice} 3, 1, 2"]
             initial_regs = [0] * 32
             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)
 
             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
     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):
             self.run_tst_program(Program(lst), initial_regs)
 
     def test_ilang(self):