Fix addi instruction, think a commit got lost
authorMichael Nolan <mtnolan2640@gmail.com>
Sun, 5 Apr 2020 18:00:44 +0000 (14:00 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Sun, 5 Apr 2020 18:00:44 +0000 (14:00 -0400)
src/soc/decoder/isa/caller.py
src/soc/decoder/isa/test_caller.py
src/soc/decoder/selectable_int.py

index de54143b5ee2833cfa997cb34acbeaa75f354482..874a06973f3666d63917ce2adcf4a11f4efc4690 100644 (file)
@@ -88,9 +88,11 @@ class ISACaller:
 
     def prep_namespace(self):
         si = yield self.decoder.SI
-        self.namespace.SI = SelectableInt(si, bits=16)
+        self.namespace['SI'] = SelectableInt(si, bits=16)
 
     def call(self, name):
+        yield from self.prep_namespace()
+
         function, read_regs, uninit_regs, write_regs = self.instrs[name]
         input_names = create_args(read_regs | uninit_regs)
         print(input_names)
@@ -108,7 +110,7 @@ class ISACaller:
         for name, output in zip(output_names, results):
             regnum = yield getattr(self.decoder, name)
             print('writing reg %d' % regnum)
-            self.gpr[regnum] = output
+            self.gpr[regnum] = output.narrow(64)
 
 
 def inject():
index 73692f002e5ac018a9723061ba4f7f5a53659393..aa6f23ae90f0fe318d06a99717fc9c48a5780a5c 100644 (file)
@@ -60,10 +60,20 @@ class DecoderTestCase(FHDLTestCase):
             sim = self.run_test_program(program, initial_regs)
             self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))
 
-    def run_test_program(self, prog, initial_regs):
+    def test_addi(self):
+        lst = ["addi 3, 0, 0x1234",
+               "addi 2, 0, 0x4321",
+               "add  1, 3, 2"]
+        with Program(lst) as program:
+            sim = self.run_test_program(program)
+            print(sim.gpr(1))
+            self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))
+
+    def run_test_program(self, prog, initial_regs=[0] * 32):
         simulator = self.run_tst(prog, initial_regs)
         simulator.gpr.dump()
         return simulator
 
+
 if __name__ == "__main__":
     unittest.main()
index fb064fcb383bd54a5bf35bc4d445c2e8fc6a0f10..28e48f2e8d08315da3bf52a72aed6ddd94bfbbb6 100644 (file)
@@ -159,6 +159,10 @@ class SelectableInt:
             return onebit(other == self.value)
         assert False
 
+    def narrow(self, bits):
+        assert bits <= self.bits
+        return SelectableInt(self.value, bits)
+
     def __bool__(self):
         return self.value != 0