From 751e8f6b96a393bbd74f48fe54b9321286b1b9af Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 30 Dec 2022 13:41:49 +0000 Subject: [PATCH] add rollover mem test, store "rolls over" a 64-bit boundary --- src/openpower/decoder/isa/mem.py | 14 ++++++++++++-- src/openpower/decoder/isa/test_mem.py | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/openpower/decoder/isa/mem.py b/src/openpower/decoder/isa/mem.py index 23e2c07e..8b3e0563 100644 --- a/src/openpower/decoder/isa/mem.py +++ b/src/openpower/decoder/isa/mem.py @@ -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) diff --git a/src/openpower/decoder/isa/test_mem.py b/src/openpower/decoder/isa/test_mem.py index b7734449..9a5423af 100644 --- a/src/openpower/decoder/isa/test_mem.py +++ b/src/openpower/decoder/isa/test_mem.py @@ -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__': -- 2.30.2