summaryrefslogtreecommitdiff
path: root/chapter21/src/test/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-03-31 15:24:16 -0700
committerCliff Click <cliffc@acm.org>2025-03-31 15:24:16 -0700
commit22318a9654f4a6c3f26e6ad6800a875c16f472a2 (patch)
tree3984bbe785775ca1711ac1a78ca14a311c5897b7 /chapter21/src/test/java/com
parent760e2b4f57ceac91017ad018f2e9234af351bf5b (diff)
downloadSimple-22318a9654f4a6c3f26e6ad6800a875c16f472a2.tar.gz
Simple-22318a9654f4a6c3f26e6ad6800a875c16f472a2.zip
Fix encoding FIB
Use common utility for walking CFG chains of empty blocks
Diffstat (limited to 'chapter21/src/test/java/com')
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java8
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/progs/fib.smp13
2 files changed, 21 insertions, 0 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
index e3b69593..b1b39d6a 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
@@ -23,6 +23,7 @@ public class Chapter21Test {
static void testCPU( String src, String cpu, String os, int spills, String stop ) {
CodeGen code = new CodeGen(src);
code.parse().opto().typeCheck().instSelect(PORTS,cpu,os).GCM().localSched().regAlloc().encode();
+ String s = code.asm();
int delta = spills>>3;
if( delta==0 ) delta = 1;
assertEquals("Expect spills:",spills,code._regAlloc._spillScaled,delta);
@@ -69,6 +70,13 @@ public class Chapter21Test {
testCPU(src,"arm" , "SystemV",5,"return (add,.[],(mul,.[],1000));");
}
+ @Test
+ public void testFib() throws IOException {
+ String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/fib.smp"));
+ testCPU(src,"x86_64_v2", "SystemV",24,null);
+ testCPU(src,"riscv" , "SystemV",16,null);
+ testCPU(src,"arm" , "SystemV",16,null);
+ }
@Test
public void testExport() throws IOException {
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/fib.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/fib.smp
new file mode 100644
index 00000000..fd6ed218
--- /dev/null
+++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/fib.smp
@@ -0,0 +1,13 @@
+// -*- mode: java; -*-
+val fib = {int n ->
+ int f1=1;
+ int f2=1;
+ while( n-- > 1 ){
+ int temp = f1+f2;
+ f1=f2;
+ f2=temp;
+ }
+ return f2;
+};
+
+fib(10);