add rollover mem test, store "rolls over" a 64-bit boundary
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 30 Dec 2022 13:41:49 +0000 (13:41 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:16 +0000 (19:51 +0100)
src/openpower/decoder/isa/mem.py
src/openpower/decoder/isa/test_mem.py

index 23e2c07eec31bf925436601f0660f8b94fc1a86f..8b3e05631de6a2cc0368d2259be625e50bbbbbf7 100644 (file)
@@ -147,10 +147,20 @@ class Mem:
         if swap:
             v = swap_order(v, width)
         # not misaligned: pass through to Mem._st but we've swapped already
-        if remainder & (width - 1) == 0:
+        misaligned = remainder & (width - 1)
+        if misaligned == 0:
             return self._st(addr, v, width, swap=False)
         shifter, mask = self._get_shifter_mask(width, remainder)
-        print ("mask", hex(shifter), hex(mask))
+        # split into two halves. lower first
+        maxmask = (1 << (self.bytes_per_word)*8) - 1
+        val1 = ((v << shifter) & maxmask) >> shifter
+        self._st(addr+misaligned, val1,
+                 width=width-misaligned, swap=False)
+        # now upper
+        val2 = v >> ((width-misaligned)*8)
+        print ("v, val2", hex(v), hex(val2))
+        self._st(addr+self.bytes_per_word, val2,
+                 width=width-misaligned, swap=False)
 
     def __call__(self, addr, sz):
         val = self.ld(addr.value, sz, swap=False)
index b77344494c7592b6e756271f9cc769918d6b70f3..9a5423af655f1bf091fc894bb6443b49343580f7 100644 (file)
@@ -16,13 +16,13 @@ class TestMem(unittest.TestCase):
         log ("dict", d)
         self.assertEqual(d, [(0, 0x1234567800000000)])
 
-    def test_mem_misalign_st(self):
+    def test_mem_misalign_st_rollover(self):
         m = Mem(row_bytes=8, initial_mem={}, misaligned_ok=True)
-        m.st(4, 0x912345678, width=8, swap=False)
+        m.st(6, 0x912345678, width=8, swap=False)
         d = m.dump()
         log ("dict", d)
-        self.assertEqual(d, [(0, 0x1234567800000000),
-                              8, 0x0000000000000009])
+        self.assertEqual(d, [(0, 0x5678000000000000),
+                             (8, 0x0000000000091234)])
 
 
 if __name__ == '__main__':