sign-extend lhax needs 16-64, separate from lwax which is 32-64
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 2 Sep 2020 16:48:17 +0000 (17:48 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 2 Sep 2020 16:48:17 +0000 (17:48 +0100)
src/soc/experiment/compldst_multi.py
src/soc/fu/ldst/test/test_pipe_caller.py

index ecb99e8daf40bcd5806191ee38bf76d39a798f9f..8aa252f86f20c389fa6cc8eaa64150b42fe44898 100644 (file)
@@ -506,7 +506,11 @@ class LDSTCompUnit(RegSpecAPI, Elaboratable):
 
         # then check sign-extend
         with m.If(oper_r.sign_extend):
-            comb += ldd_o.eq(exts(revnorev, 32, 64))  # sign-extend
+            # okok really should "if data_len == 4" and so on here
+            with m.If(oper_r.data_len == 2):
+                comb += ldd_o.eq(exts(revnorev, 16, 64))  # sign-extend hword
+            with m.Else():
+                comb += ldd_o.eq(exts(revnorev, 32, 64))  # sign-extend dword
         with m.Else():
             comb += ldd_o.eq(revnorev)
 
index 662b89d7b5bf40614a67ff423dcb21b77b566ef4..4e3627dd0b81912dd3794e5535d56d97d9851a4f 100644 (file)
@@ -218,3 +218,29 @@ class LDSTTestCase(TestAccumulatorBase):
         self.add_case(Program(lst, bigendian), initial_regs,
                              initial_mem=initial_mem)
 
+    def case_10_load_algebraic_1(self):
+        lst = ["lhax 3, 4, 2"]
+        initial_regs = [0] * 32
+        initial_regs[1] = 0x5678
+        initial_regs[2] = 0x001c
+        initial_regs[4] = 0x0008
+        initial_mem = {0x0000: (0x5432123412345678, 8),
+                       0x0008: (0xabcdef0187654321, 8),
+                       0x0020: (0x0000f00f0000ffff, 8),
+                        }
+        self.add_case(Program(lst, bigendian), initial_regs,
+                             initial_mem=initial_mem)
+
+    def case_10_load_algebraic_2(self):
+        lst = ["lhax 3, 4, 2"]
+        initial_regs = [0] * 32
+        initial_regs[1] = 0x5678
+        initial_regs[2] = 0x001c
+        initial_regs[4] = 0x0008
+        initial_mem = {0x0000: (0x5432123412345678, 8),
+                       0x0008: (0xabcdef0187654321, 8),
+                       0x0020: (0x0000700f0000ffff, 8),
+                        }
+        self.add_case(Program(lst, bigendian), initial_regs,
+                             initial_mem=initial_mem)
+