summaryrefslogtreecommitdiff
path: root/chapter21/src/test/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-04-19 16:43:25 -0700
committerCliff Click <cliffc@acm.org>2025-04-19 16:43:25 -0700
commit0cb35914c6a92be41108a7e3f16801b955967432 (patch)
tree34243eb6be67694b258d169ac1287d78bfa5ca0b /chapter21/src/test/java/com
parent4402980faff51393a4a8d35557f1ed8c06596f23 (diff)
downloadSimple-0cb35914c6a92be41108a7e3f16801b955967432.tar.gz
Simple-0cb35914c6a92be41108a7e3f16801b955967432.zip
Better block layout
Keeps loops self-contained, handles more variants of infinite loops. Fold region-to-regions together, in an effort to have fewer junk jumps
Diffstat (limited to 'chapter21/src/test/java/com')
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter05Test.java2
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter06Test.java4
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter08Test.java4
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter11Test.java2
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java4
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java48
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/MergeSortTest.java2
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/TestRisc5.java13
8 files changed, 35 insertions, 44 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index a584ad5a..d1dfd216 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -100,7 +100,7 @@ else
return a;
""");
code.parse().opto();
- assertEquals("return Phi(Region,Phi(Region,2,3),Phi(Region,4,5));", code.print());
+ assertEquals("return Phi(Region,3,5,2,4);", code.print());
}
@Test
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index 24d12921..b6bc2bf3 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter06Test.java
@@ -145,7 +145,7 @@ else
return a;
""");
code.parse().opto();
- assertEquals("return Phi(Region,3,Phi(Region,4,5));", code.print());
+ assertEquals("return Phi(Region,3,5,4);", code.print());
}
@Test
@@ -258,7 +258,7 @@ if( arg ) {
return a+b+c;
""");
code.parse().opto();
- assertEquals("return (Phi(Region,Phi(Region,2,3),0)+Phi(Region,3,1));", code.print());
+ assertEquals("return Phi(Region,6,1,5);", code.print());
}
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter08Test.java
index 7e90d484..09669cc7 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter08Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter08Test.java
@@ -23,7 +23,7 @@ while(arg < 10) {
return arg;
""");
code.parse().opto();
- assertEquals("return Phi(Region,Phi(Region,Phi(Loop,arg,(Phi_arg+1)),Add),Add);", code.print());
+ assertEquals("return Phi(Region,(Phi(Loop,arg,Add)+1),Add,Phi_arg);", code.print());
assertTrue(code.ctrl() instanceof RegionNode);
Assert.assertEquals( "5", Eval2.eval(code, 1));
Assert.assertEquals("10", Eval2.eval(code, 6));
@@ -46,7 +46,7 @@ while(arg < 10) {
return a;
""");
code.parse().opto();
- assertEquals("return Phi(Loop,1,Phi(Region,Phi_a,(Phi_a+1)));", code.print());
+ assertEquals("return Phi(Loop,1,Phi(Region,Phi_a,(Phi_a+1),Phi_a));", code.print());
assertTrue(code.ctrl() instanceof CProjNode);
}
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index 7e88b60e..f6539ac4 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -321,7 +321,7 @@ while( prime <= arg ) {
return primeCount;
""");
code.parse().opto();
- assertEquals("return Phi(Region,0,Phi(Loop,1,Phi(Region,Phi_primeCount,Phi(Region,(Phi_primeCount+1),Phi_primeCount))));", code.print());
+ assertEquals("return Phi(Region,0,Phi(Loop,1,Phi(Region,Phi_primeCount,Phi_primeCount,(Phi_primeCount+1))));", code.print());
assertEquals("0", Eval2.eval(code, 1)); // No primes 1 or below
assertEquals("1", Eval2.eval(code, 2)); // 2
assertEquals("2", Eval2.eval(code, 3)); // 2, 3
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java
index 8da5cf96..8b138b46 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java
@@ -130,7 +130,7 @@ else {
return rez;
""");
code.parse().opto();
- assertEquals("return Phi(Region,1.2,Phi(Region,2.3,.y));", code.print());
+ assertEquals("return Phi(Region,1.2,.y,2.3);", code.print());
assertEquals("3.14", Eval2.eval(code, 0));
assertEquals("1.2", Eval2.eval(code, 1));
}
@@ -155,7 +155,7 @@ if( iss[arg] )
rez = iss[arg][2].y;
return rez;""");
code.parse().opto().typeCheck();
- assertEquals("return Phi(Region,Phi(Region,.y,1.2),1.2);", code.print());
+ assertEquals("return Phi(Region,1.2,1.2,.y);", code.print());
assertEquals("3.14", Eval2.eval(code, 0));
try { Eval2.eval(code, 10); fail(); } // Fails AIOOBE in Eval2, no range checks
catch( Exception e ) { assertEquals("Index 10 out of bounds for length 2",e.getMessage()); }
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
index 291d4a55..50cb7604 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
@@ -95,31 +95,14 @@ public class Chapter21Test {
// Return register A0 holds fib(8)==55
assertEquals(1.732051,R5.fregs[riscv.FA0 - riscv.F_OFFSET], 0.00001);
- // arm
- EvalArm64 A5 = TestArm64.build("newtonFloat", 0, 10, false);
- A5.fregs[arm.D0 - arm.D_OFFSET] = 3.0;
- int trap_arm = A5.step(1000);
- assertEquals(0,trap_arm);
- assertEquals(1.732051, A5.fregs[arm.D0 - arm.D_OFFSET], 0.00001);
+ //// arm
+ //EvalArm64 A5 = TestArm64.build("newtonFloat", 0, 10, false);
+ //A5.fregs[arm.D0 - arm.D_OFFSET] = 3.0;
+ //int trap_arm = A5.step(1000);
+ //assertEquals(0,trap_arm);
+ //assertEquals(1.732051, A5.fregs[arm.D0 - arm.D_OFFSET], 0.00001);
}
- @Test
- public void testFibPrint() throws IOException {
- String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp"));
- CodeGen code = new CodeGen(src);
-
- code.parse().opto().typeCheck().loopTree().instSelect("arm", "SystemV").GCM().localSched().regAlloc().encode().print_as_hex();
- System.out.print(code.asm());
- }
-
- @Test
- public void testFibPrintRiscv() throws IOException {
- String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp"));
- CodeGen code = new CodeGen(src);
-
- code.parse().opto().typeCheck().loopTree().instSelect("riscv", "SystemV").GCM().localSched().regAlloc().encode().print_as_hex();
- System.out.print(code.asm());
- }
@Test public void testSieve() throws IOException {
// The primes
@@ -143,17 +126,16 @@ public class Chapter21Test {
assertEquals(primes.length, R5.ld4s(ary));
for( int i=0; i<primes.length; i++ )
assertEquals(primes[i], R5.ld4s(ary + 4 + i*4));
- // Evaluate on ARM5 emulator; expect return of an array of primes in the simualted heap.
-
- EvalArm64 A5 = TestArm64.build("sieve", 100, 160, false);
- int trap_arm = A5.step(10000);
- assertEquals(0, trap_arm);
- int ary_arm = (int)A5.regs[arm.X0];
- // Memory layout starting at ary(length,pad, prime1, primt2, prime3, prime4)
- assertEquals(primes.length, A5.ld4s(ary_arm));
- for(int i = 0; i<primes.length; i++)
- assertEquals(primes[i], A5.ld4s(ary_arm + 4 + i * 4));
+ //// Evaluate on ARM5 emulator; expect return of an array of primes in the simulated heap.
+ //EvalArm64 A5 = TestArm64.build("sieve", 100, 160, false);
+ //int trap_arm = A5.step(10000);
+ //assertEquals(0, trap_arm);
+ //int ary_arm = (int)A5.regs[arm.X0];
+ //// Memory layout starting at ary(length,pad, prime1, primt2, prime3, prime4)
+ //assertEquals(primes.length, A5.ld4s(ary_arm));
+ //for(int i = 0; i<primes.length; i++)
+ // assertEquals(primes[i], A5.ld4s(ary_arm + 4 + i * 4));
}
@Test public void testFibExport() throws IOException {
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/MergeSortTest.java b/chapter21/src/test/java/com/seaofnodes/simple/MergeSortTest.java
index a72c7c3a..a1004fb5 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/MergeSortTest.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/MergeSortTest.java
@@ -20,7 +20,7 @@ public class MergeSortTest {
TestC.run("sort", sprimes, 40);
- EvalRisc5 R5 = TestRisc5.build("sort", 0, 36, false);
+ EvalRisc5 R5 = TestRisc5.build("src/test/java/com/seaofnodes/simple/progs", "sort", "merge_sort", 0, 36, false);
// Allocate an array of primes, filled in reverse order
int ps = R5._heap;
R5._heap += (primes.length+1)*8; // 25 primes, and length
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/TestRisc5.java b/chapter21/src/test/java/com/seaofnodes/simple/TestRisc5.java
index 485a0df7..b7642540 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/TestRisc5.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/TestRisc5.java
@@ -1,6 +1,8 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.codegen.CodeGen;
+import com.seaofnodes.simple.node.FunNode;
+import com.seaofnodes.simple.node.Node;
import com.seaofnodes.simple.node.cpus.riscv.riscv;
import java.io.IOException;
import java.nio.file.Files;
@@ -11,11 +13,11 @@ import static org.junit.Assert.*;
public abstract class TestRisc5 {
public static EvalRisc5 build( String file, int arg, int spills, boolean print) throws IOException {
- return build("src/test/java/com/seaofnodes/simple/progs",file, arg, spills, print);
+ return build("src/test/java/com/seaofnodes/simple/progs",file, null, arg, spills, print);
}
// Compile and run a simple program
- public static EvalRisc5 build( String dir, String file, int arg, int spills, boolean print) throws IOException {
+ public static EvalRisc5 build( String dir, String file, String main, int arg, int spills, boolean print) throws IOException {
// Compile and export Simple
String src = Files.readString(Path.of(dir+"/"+file+".smp"));
CodeGen code = new CodeGen(src).driver("riscv", "SystemV",null);
@@ -35,6 +37,13 @@ public abstract class TestRisc5 {
// Initial incoming int arg
R5.regs[riscv.A0] = arg;
// malloc memory starts at 64K and goes up
+
+ // Look up starting PC or zero if not given
+ if( main!=null )
+ for( Node use : code._start._outputs )
+ if( use instanceof FunNode fun && main.equals(fun._name) )
+ R5._pc = code._encoding._opStart[fun._nid];
+
return R5;
}