summaryrefslogtreecommitdiff
path: root/chapter22/src
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-05-09 13:09:14 -0700
committerCliff Click <cliffc@acm.org>2025-05-09 13:09:14 -0700
commit05c529f379c9c82387916aba7f83f7a215829e37 (patch)
treee6de0b24fe0783db0fb0536ce9658483715457cc /chapter22/src
parent239d52984594c2011ea3093e90a3aa68faad6fbd (diff)
downloadSimple-05c529f379c9c82387916aba7f83f7a215829e37.tar.gz
Simple-05c529f379c9c82387916aba7f83f7a215829e37.zip
muli & setx86 encoding bugs
Missed lazy-default-mem-phi fixup
Diffstat (limited to 'chapter22/src')
-rw-r--r--chapter22/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java2
-rw-r--r--chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MulIX86.java4
-rw-r--r--chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java2
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java6
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java2
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java2
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java3
7 files changed, 11 insertions, 10 deletions
diff --git a/chapter22/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java b/chapter22/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java
index 3fc69be0..e936ee58 100644
--- a/chapter22/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java
+++ b/chapter22/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java
@@ -117,7 +117,7 @@ public class MemMergeNode extends Node {
void _merge( MemMergeNode that, RegionNode r) {
int len = Math.max(nIns(),that.nIns());
- for( int i = 2; i < len; i++)
+ for( int i = 1; i < len; i++)
if( alias(i) != that.alias(i) ) { // No need for redundant Phis
// If we are in lazy phi mode we need to a lookup
// by alias as it will trigger a phi creation
diff --git a/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MulIX86.java b/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MulIX86.java
index d1056787..b1d81983 100644
--- a/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MulIX86.java
+++ b/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MulIX86.java
@@ -18,13 +18,13 @@ public class MulIX86 extends MachConcreteNode implements MachNode {
enc.add1(x86_64_v2.rex(src, dst, 0));
// opcode; 0x69 or 0x6B
enc.add1( 0x69 + (x86_64_v2.imm8(_imm) ? 2 : 0) );
- enc.add1( x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, src, dst) );
+ enc.add1( x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, dst, src) );
// immediate(4 bytes) 32 bits or (1 byte)8 bits
if( x86_64_v2.imm8(_imm) ) enc.add1(_imm);
else enc.add4(_imm);
}
// General form: "addi dst += #imm"
@Override public void asm(CodeGen code, SB sb) {
- sb.p(code.reg(this)).p(" ").p(glabel()).p("= #").p(_imm);
+ sb.p(code.reg(this)).p(" = ").p(code.reg(in(1))).p(" * #").p(_imm);
}
}
diff --git a/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java b/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java
index b8279da4..775ea8eb 100644
--- a/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java
+++ b/chapter22/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java
@@ -39,7 +39,7 @@ public class SetX86 extends MachConcreteNode implements MachNode {
enc.add1(x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, 0, dst));
// low 8 bites are set, now zero extend for next instruction
- if( dst >= 8 ) enc.add1(x86_64_v2.rex(dst, dst, 0, false));
+ if( dst >= 4 ) enc.add1(x86_64_v2.rex(dst, dst, 0, false));
enc.add1(0x0F); // opcode
enc.add1(0xB6); // opcode
enc.add1(x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, dst, dst));
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java
index b370cd3c..d7572782 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java
+++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java
@@ -25,7 +25,7 @@ return 0;
public void testString() throws IOException {
String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp"));
CodeGen code = new CodeGen(src).parse().opto().typeCheck().GCM().localSched();
- assertEquals("Stop[ return Phi(Region,._hashCode,Phi(Region,123456789,Phi(Loop,0,(.[]+((Phi_hash<<5)-Phi_hash))))); return Phi(Region,1,0,0,1); ]", code._stop.toString());
+ assertEquals("Stop[ return Phi(Region,1,0,0,1); return Phi(Region,._hashCode,Phi(Region,123456789,Phi(Loop,0,(.[]+((Phi_hash<<5)-Phi_hash))))); ]", code._stop.toString());
//assertEquals("-4898613127354160978", Eval2.eval(code, 2));
}
@@ -81,7 +81,7 @@ return 0;
@Test
public void testBasic8() {
CodeGen code = new CodeGen("return arg * 6;").driver(Phase.LocalSched,"x86_64_v2", "SystemV");
- assertEquals("return (muli,arg);", code._stop.toString());
+ assertEquals("return (muli,arg,6);", code._stop.toString());
}
@Test
@@ -316,7 +316,7 @@ val fcn = arg ? { int x -> x*x; } : { int x -> x+x; };
return fcn(2)*10 + fcn(3);
""");
code.driver(Phase.LocalSched,"x86_64_v2", "SystemV");
- assertEquals("Stop[ return (shli,Parm_x($fun2,int)); return (mul,Parm_x($fun1,int),x); return (add,#2,(muli,#2)); ]", code.print());
+ assertEquals("Stop[ return (shli,Parm_x($fun2,int)); return (mul,Parm_x($fun1,int),x); return (add,#2,(muli,#2,10)); ]", code.print());
}
@Test
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java
index f0b31065..4c4ac4e4 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java
+++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java
@@ -104,7 +104,7 @@ return sqrt(arg) + sqrt(cast_int);
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,"riscv" , "SystemV", 5,null);
- testCPU(src,"arm" , "SystemV", 6,null);
+ testCPU(src,"arm" , "SystemV", 3,null);
}
@Test
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java
index e589d5a4..77d1e337 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java
+++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java
@@ -66,7 +66,7 @@ public class Chapter21Test {
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,"riscv" , "SystemV", 5,null);
- testCPU(src,"arm" , "SystemV", 6,null);
+ testCPU(src,"arm" , "SystemV", 3,null);
}
@Test public void testStringExport() throws IOException {
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java
index 4b15124c..55ab97ca 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java
+++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java
@@ -15,7 +15,8 @@ public class Chapter22Test {
@Test @Ignore
public void testJig() throws IOException {
- String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
+ //String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
+ String src = Files.readString(Path.of("doc/examples/BubbleSort.smp"));
testCPU(src,"x86_64_v2", "Win64" ,-1,null);
testCPU(src,"riscv" , "SystemV",-1,null);
testCPU(src,"arm" , "SystemV",-1,null);