diff options
Diffstat (limited to 'chapter21/src/test/java/com')
| -rw-r--r-- | chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java | 8 | ||||
| -rw-r--r-- | chapter21/src/test/java/com/seaofnodes/simple/progs/fib.smp | 13 |
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); |
