From d766a6e842478996a520702a659f6653bbb3491b Mon Sep 17 00:00:00 2001 From: "Matthias J. Kannwischer" Date: Mon, 16 Dec 2024 11:22:39 +0800 Subject: [PATCH] selftest: allocate twice the memory and place pointer in the middle This allows to access memory at negative offsets. --- slothy/helper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/slothy/helper.py b/slothy/helper.py index 4bd9230b..ae8be212 100644 --- a/slothy/helper.py +++ b/slothy/helper.py @@ -1362,8 +1362,10 @@ def run_code(code, txt=None): for r in regs: initial_register_contents[r] = int.from_bytes(os.urandom(16)) for (reg, sz) in address_registers.items(): - initial_register_contents[reg] = cur_ram - cur_ram += sz + # allocate 2*sz and place pointer in the middle + # this makes sure that memory can be accessed at negative offsets + initial_register_contents[reg] = cur_ram + sz + cur_ram += 2*sz final_regs_old, final_mem_old = run_code(codeA, txt="old") final_regs_new, final_mem_new = run_code(codeB, txt="new")