From a8c96e04c59d37fe561319e86474f55c497705bb Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 19 Sep 2026 19:11:14 -0700 Subject: Fixed st8 on arm/risc evals --- .../java/com/seaofnodes/simple/Chapter21Test.java | 28 ++++++++++++++++++++++ .../test/java/com/seaofnodes/simple/EvalArm64.java | 2 +- .../test/java/com/seaofnodes/simple/EvalRisc5.java | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'chapter22/src/test/java') diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 77d1e337..5382a2bc 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -11,6 +11,34 @@ import org.junit.Test; import static org.junit.Assert.*; public class Chapter21Test { + @Test public void testRisc64BitStore() { + byte[] mem = new byte[24]; + EvalRisc5 cpu = new EvalRisc5(mem,mem.length); + check64BitStore(mem,cpu::st8,cpu::ld8); + } + + @Test public void testArm64BitStore() { + byte[] mem = new byte[24]; + EvalArm64 cpu = new EvalArm64(mem,mem.length); + check64BitStore(mem,cpu::st8,cpu::ld8); + } + + // Check bytes independently of ld8, including overwrite and adjacent memory. + private static void check64BitStore(byte[] mem, + java.util.function.BiConsumer store, + java.util.function.IntToLongFunction load) { + java.util.Arrays.fill(mem,(byte)0xA5); + for( long value : new long[]{0x0123456789ABCDEFL,0xFEDCBA9876543210L, + -1L,0L,Long.MIN_VALUE,Long.MAX_VALUE} ) { + store.accept(8,value); + for( int i=0; i=8 && i<16 ? (int)(value >>> (8*(i-8)))&0xFF : 0xA5; + assertEquals("byte "+i,expected,mem[i]&0xFF); + } + assertEquals(value,load.applyAsLong(8)); + } + } + @Test @Ignore public void testJig() throws IOException { diff --git a/chapter22/src/test/java/com/seaofnodes/simple/EvalArm64.java b/chapter22/src/test/java/com/seaofnodes/simple/EvalArm64.java index 981799bb..6f596799 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/EvalArm64.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/EvalArm64.java @@ -54,7 +54,7 @@ public class EvalArm64 { public void st1(int x, int val) { _buf[x] = (byte)val; } public void st2(int x, int val) { st1(x,val); st1(x+1,val>> 8); } public void st4(int x, int val) { st2(x,val); st2(x+2,val>>16); } - public void st8(int x, long val) { st4(x,(int)val); st2(x+4,(int)(val>>32)); } + public void st8(int x, long val) { st4(x,(int)val); st4(x+4,(int)(val>>32)); } public int step(int maxops) { int trap = 0; diff --git a/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java b/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java index 0a1c034f..7b918615 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/EvalRisc5.java @@ -58,7 +58,7 @@ public class EvalRisc5 { public void st1(int x, int val) { _buf[x] = (byte)val; } public void st2(int x, int val) { st1(x,val); st1(x+1,val>> 8); } public void st4(int x, int val) {st2(x,val); st2(x+2,val>>16); } - public void st8(int x, long val) { st4(x,(int)val); st2(x+4,(int)(val>>32)); } + public void st8(int x, long val) { st4(x,(int)val); st4(x+4,(int)(val>>32)); } // Note: only a few bits are used. (Machine = 3, User = 0) // Bits 0..1 = privilege. -- cgit v1.2.3