From 96ceb57bd40705538fd1da91065d2fb81a608857 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Mon, 6 Dec 2021 22:43:43 +0900 Subject: [PATCH 1/4] replace "& ~(CELL - 1)" with "% CELL" --- others/planck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/others/planck.py b/others/planck.py index edcd64a..af9a59b 100644 --- a/others/planck.py +++ b/others/planck.py @@ -33,7 +33,7 @@ ip = 0 np = 0 def aligned(n): - return (n + CELL - 1) & ~(CELL - 1) + return (n + CELL - 1) % CELL def align(): write(HERE_CELL, aligned(read(HERE_CELL))) From b2fd58b688c052d8a0b1efb81a14cf7a6900b47e Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Mon, 6 Dec 2021 22:44:12 +0900 Subject: [PATCH 2/4] minor style fix --- others/planck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/others/planck.py b/others/planck.py index af9a59b..76e38c8 100644 --- a/others/planck.py +++ b/others/planck.py @@ -57,7 +57,7 @@ def read_byte(addr): def write_byte(addr, c): i = addr >> CELL_SHIFT - m = (addr % CELL)*8 + m = (addr % CELL) * 8 v = memory[i] memory[i] = (v & ~(0xff << m)) | (c&0xff) << m From 3656a1e5c9a0ec1b185a3ac23505b65470c84b2e Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Mon, 6 Dec 2021 23:03:57 +0900 Subject: [PATCH 3/4] fix previous commit --- others/planck.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/others/planck.py b/others/planck.py index 76e38c8..7b2f0c3 100644 --- a/others/planck.py +++ b/others/planck.py @@ -19,6 +19,7 @@ MEMORY_SIZE = 0x10000 memory = array.array('i', [0]*MEMORY_SIZE) CELL = memory.itemsize +CELLm1 = CELL - 1 CELL_SHIFT = CELL.bit_length() - 1 STACK_SIZE = 0x100 @@ -32,8 +33,9 @@ rp = (MEMORY_SIZE - STACK_SIZE) * CELL ip = 0 np = 0 +ALIGN_MASK = CELL - 1 def aligned(n): - return (n + CELL - 1) % CELL + return (n + CELLm1) & ALIGN_MASK def align(): write(HERE_CELL, aligned(read(HERE_CELL))) From 5554c671e856f743380a9ff249fc7f4bee90bd69 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Tue, 7 Dec 2021 02:11:46 +0900 Subject: [PATCH 4/4] fixed a bug of previous commit --- others/planck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/others/planck.py b/others/planck.py index 7b2f0c3..553840d 100644 --- a/others/planck.py +++ b/others/planck.py @@ -33,7 +33,7 @@ rp = (MEMORY_SIZE - STACK_SIZE) * CELL ip = 0 np = 0 -ALIGN_MASK = CELL - 1 +ALIGN_MASK = ~(CELL - 1) def aligned(n): return (n + CELLm1) & ALIGN_MASK