diff options
Diffstat (limited to 'chapter21/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java | 15 | ||||
| -rw-r--r-- | chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp | 64 |
2 files changed, 8 insertions, 71 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java index c626c14e..d8a5cebc 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -12,13 +12,12 @@ import static org.junit.Assert.*; public class Chapter21Test { - @Test + @Test @Ignore public void testJig() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); - CodeGen code = new CodeGen(src).driver("x86_64_v2","Win64","build/objs/jigS.o"); - //testCPU(src,"x86_64_v2", "Win64" ,-1,null); - //testCPU(src,"riscv" , "SystemV",-1,null); - //testCPU(src,"arm" , "SystemV",-1,null); + testCPU(src,"x86_64_v2", "Win64" ,-1,null); + testCPU(src,"riscv" , "SystemV",-1,null); + testCPU(src,"arm" , "SystemV",-1,null); } static void testCPU( String src, String cpu, String os, int spills, String stop ) { @@ -65,7 +64,7 @@ public class Chapter21Test { @Test public void testString() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp")); - //testCPU(src,"x86_64_v2", "SystemV", 9,null); + testCPU(src,"x86_64_v2", "SystemV", 9,null); testCPU(src,"riscv" , "SystemV", 5,null); testCPU(src,"arm" , "SystemV", 6,null); } @@ -180,7 +179,7 @@ public class Chapter21Test { int p2 = ps+4*8+2*8; EvalRisc5 R5 = TestRisc5.build("person", ps, 0, false); R5.regs[riscv.A1] = 1; // Index 1 - R5.st4(ps,3); // Length + R5.st8(ps,3); // Length R5.st8(ps+1*8,p0); R5.st8(ps+2*8,p1); R5.st8(ps+3*8,p2); @@ -196,7 +195,7 @@ public class Chapter21Test { EvalArm64 A5 = TestArm64.build("person", ps, 0, false); A5.regs[arm.X1] = 1; // Index 1 - A5.st4(ps, 3); + A5.st8(ps, 3); A5.st8(ps+1*8,p0); A5.st8(ps+2*8,p1); A5.st8(ps+3*8,p2); diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp index b82b3f42..1daeee09 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp @@ -1,64 +1,2 @@ // -*- mode: java; -*- -// based on the top-down version from https://en.wikipedia.org/wiki/Merge_sort - -val merge_sort = { int[] a, int[] b, int n -> - copy_array (a, 0, n, b); - split_merge(a, 0, n, b); -}; - -val split_merge = { int[] b, int begin, int end, int[] a -> - if (end - begin <= 1) - return 0; - int middle = (end + begin) / 2; - split_merge(a, begin, middle, b); - split_merge(a, middle, end, b); - merge(b, begin, middle, end, a); - return 0; -}; - -val merge = { int[] b, int begin, int middle, int end, int[] a -> - int i = begin, j = middle; - - for (int k = begin; k < end; k++) { - // && and || - bool cond = false; - if (i < middle) { - if (j >= end) cond = true; - else if (a[i] <= a[j]) cond = true; - } - if (cond) b[k] = a[i++]; - else b[k] = a[j++]; - } -}; - -val copy_array = { int[] a, int begin, int end, int[] b -> - for (int k = begin; k < end; k++) - b[k] = a[k]; -}; - -val eq = { int[] a, int[] b, int n -> - int result = 1; - int i = 0; - while (i < n) { - if (a[i] != b[i]) { - result = 0; - break; - } - i = i + 1; - } - return result; -}; - -val main = { -> - int[] !a = new int[10]; - a[0] = 10; a[1] = 9; a[2] = 8; a[3] = 7; a[4] = 6; - a[5] = 5; a[6] = 4; a[7] = 3; a[8] = 2; a[9] = 1; - int[] !b = new int[10]; - b[0] = 0; b[1] = 0; b[2] = 0; b[3] = 0; b[4] = 0; - b[5] = 0; b[6] = 0; b[7] = 0; b[8] = 0; b[9] = 0; - int[] !expect = new int[10]; - expect[0] = 1; expect[1] = 2; expect[2] = 3; expect[3] = 4; expect[4] = 5; - expect[5] = 6; expect[6] = 7; expect[7] = 8; expect[8] = 9; expect[9] = 10; - merge_sort(a, b, 10); - return eq(a,expect,10); -}; +return 0; |
