summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/Chapter20Test.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter20Test.java')
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter20Test.java62
1 files changed, 30 insertions, 32 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/src/test/java/com/seaofnodes/simple/Chapter20Test.java
index 02de57a2..17b0fd0a 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter20Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter20Test.java
@@ -1,7 +1,6 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.codegen.CodeGen;
-import java.io.IOException;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -11,7 +10,7 @@ public class Chapter20Test {
public void testJig() {
CodeGen code = new CodeGen("return 0;");
code.parse().opto().typeCheck();
- assertEquals("return 0;", code._stop.toString());
+ assertEquals("return 0;", code.print());
assertEquals("0", Eval2.eval(code, 2));
}
@@ -20,10 +19,10 @@ public class Chapter20Test {
code.driver(CodeGen.Phase.RegAlloc,cpu,os);
int delta = spills>>3;
if( delta==0 ) delta = 1;
- if( spills != -1 )
+ if( spills != -1 && !CodeGen.iterSeedOverridden() )
assertEquals("Expect spills:",spills,code._regAlloc._spillScaled,delta);
if( stop != null )
- assertEquals(stop, code._stop.toString());
+ assertEquals(stop, code.print());
}
private static void testAllCPUs( String src, int spills, String stop ) {
@@ -50,41 +49,40 @@ public class Chapter20Test {
String src =
"""
// Newtons approximation to the square root
-val sqrt = { int x ->
+val _sqrt = { int x ->
int guess = x;
while( 1 ) {
- int next = (x/guess + guess)/2;
+ int next = (x/guess + guess)>>1;
if( next == guess ) return guess;
guess = next;
}
};
-int cast_int = arg+2;
-return sqrt(arg) + sqrt(cast_int);
+return _sqrt(arg) + _sqrt(arg+2);
""";
- testCPU(src,"x86_64_v2", "Win64" ,55,null);
+ testCPU(src,"x86_64_v2", "win64" ,38,null);
testCPU(src,"riscv" , "SystemV",19,null);
testCPU(src,"arm" , "SystemV",19,null);
}
@Test
- public void testNewtonFloat() throws IOException {
+ public void testNewtonFloat() {
String src =
"""
-val test_sqrt = { flt x ->
+val _test_sqrt_noInline = { flt x ->
flt epsilon = 1e-15;
flt guess = x;
while( 1 ) {
flt next = (x/guess + guess)/2;
- if( guess-epsilon <= next & next <= guess+epsilon ) return guess;
- //if( guess==next ) return guess;
+ if( guess-epsilon <= next && next <= guess+epsilon )
+ return guess;
guess = next;
}
};
-flt farg = arg; return test_sqrt(farg) + test_sqrt(farg+2.0);
+flt farg = arg; return _test_sqrt_noInline(farg) + _test_sqrt_noInline(farg+2.0);
""";
- testCPU(src,"x86_64_v2", "SystemV",39,null);
- testCPU(src,"riscv" , "SystemV",17,null);
- testCPU(src,"arm" , "SystemV",18,null);
+ testCPU(src,"x86_64_v2", "SystemV",65,null);
+ testCPU(src,"riscv" , "SystemV",35,null);
+ testCPU(src,"arm" , "SystemV",35,null);
}
@Test
@@ -98,7 +96,7 @@ flt farg = arg; return test_sqrt(farg) + test_sqrt(farg+2.0);
@Test
- public void testArray1() throws IOException {
+ public void testArray1() {
String src =
"""
int[] !ary = new int[arg];
@@ -111,13 +109,13 @@ for( int i=0; i<ary#-1; i++ )
return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6
""";
testCPU(src,"x86_64_v2", "SystemV",-1,"return .[];");
- testCPU(src,"riscv" , "SystemV", 8,"return (add,.[],(mul,.[],1000));");
+ testCPU(src,"riscv" , "SystemV", 7,"return (add,.[],(mul,.[],1000));");
testCPU(src,"arm" , "SystemV", 5,"return (add,.[],(mul,.[],1000));");
}
@Test
- public void testString() throws IOException {
+ public void testString() {
String src =
"""
struct String {
@@ -150,17 +148,17 @@ val _hashCodeString = { String self ->
return hash;
};
""";
- testCPU(src,"x86_64_v2", "SystemV", 9,null);
- testCPU(src,"riscv" , "SystemV", 3,null);
- testCPU(src,"arm" , "SystemV", 3,null);
+ testCPU(src,"x86_64_v2", "SystemV",18,null);
+ testCPU(src,"riscv" , "SystemV", 5,null);
+ testCPU(src,"arm" , "SystemV", 4,null);
}
@Test
public void testCast() {
String src = "struct Bar { int x; }; var b = arg ? new Bar; return b ? b.x++ + b.x++ : -1;";
- testCPU(src,"x86_64_v2", "SystemV",2,null);
- testCPU(src,"riscv" , "SystemV",2,null);
- testCPU(src,"arm" , "SystemV",2,null);
+ testCPU(src,"x86_64_v2", "SystemV",3,null);
+ testCPU(src,"riscv" , "SystemV",3,null);
+ testCPU(src,"arm" , "SystemV",3,null);
}
@Test
@@ -172,15 +170,15 @@ val _hashCodeString = { String self ->
@Test
public void testFlags1() {
String src = """
-bool b1 = arg == 1;
+bool _b1 = arg == 1;
bool b2 = arg == 2;
-if (b2) if (b1) return 1;
-if (b1) return 2;
+if (b2) if (_b1) return 1;
+if (_b1) return 2;
return 0;
""";
- testCPU(src,"x86_64_v2", "SystemV",0,"return Phi(Region,1,2,0);");
- testCPU(src,"riscv" , "SystemV",0,"return Phi(Region,1,2,0);");
- testCPU(src,"arm" , "SystemV",0,"return Phi(Region,1,2,0);");
+ testCPU(src,"x86_64_v2", "SystemV",0,"return Phi(Region,2,0,1);");
+ testCPU(src,"riscv" , "SystemV",0,"return Phi(Region,2,0,1);");
+ testCPU(src,"arm" , "SystemV",0,"return Phi(Region,2,0,1);");
}
@Test