summaryrefslogtreecommitdiff
path: root/chapter21/src/test/java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-04-29 13:27:32 -0700
committerCliff Click <cliffc@acm.org>2025-04-29 13:27:32 -0700
commit7e1deb4cbd52c7ebbec78e2ceeb35875e83c6e3a (patch)
treec159f8dd2522f6be8e582b8abca0f491d94559d3 /chapter21/src/test/java
parentfe52d80f4a25b2df1954b42395123de652b953df (diff)
downloadSimple-7e1deb4cbd52c7ebbec78e2ceeb35875e83c6e3a.tar.gz
Simple-7e1deb4cbd52c7ebbec78e2ceeb35875e83c6e3a.zip
Minor bugs
When passing AND receiving arguments on the stack (win64 passes only 4 args in registers, and requires backing stack store), the RA math was off. Bug triggered need for a stack-stack spill, now done. Inlining also hides the bug, since there are no large-argument calls afterwards. x86 store-immediate encoded an 8byte imm but the op only takes a 4byte imm. Making a 1-reg regmask with reg>64 math wrong. "popular constant" RA split would trigger when spanning calls; visit pattern for multi-users would then skip a user. Encoding would pad fun headers to 16bytes, then expand x86 short jumps to long jumps, messing up the padding. Call/End/Node visiting in RA would double-visit trailing projections. GCM not treating Calls as memory kills.
Diffstat (limited to 'chapter21/src/test/java')
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java9
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp71
2 files changed, 68 insertions, 12 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
index ea23728c..c626c14e 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
@@ -15,9 +15,10 @@ public class Chapter21Test {
@Test
public void testJig() throws IOException {
String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
- testCPU(src,"x86_64_v2", "Win64" ,-1,null);
- testCPU(src,"riscv" , "SystemV",-1,null);
- testCPU(src,"arm" , "SystemV",-1,null);
+ 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);
}
static void testCPU( String src, String cpu, String os, int spills, String stop ) {
@@ -64,7 +65,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);
}
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 00c2a161..b82b3f42 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp
+++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/jig.smp
@@ -1,9 +1,64 @@
// -*- mode: java; -*-
-struct s0 {
- i16 v1;
- u8 v2;
-};
-s0 !l4Hi9BCnsd = new s0;
-if( new s0.v2+arg )
- while(1) l4Hi9BCnsd=new s0;
-while(new s0.v2+new s0.v1<=0) {}
+// 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);
+};