diff options
Diffstat (limited to 'chapter21/src/main/java/com')
5 files changed, 17 insertions, 21 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java index 9042de3b..c84e6011 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java @@ -550,7 +550,7 @@ public class RegAlloc { Node n = bb.out(j); if( lrg(n)!=null ) { int slot = _code._mach.stackSlot(lrg(n)._reg); - maxSlot = Math.max(maxSlot,slot); + maxSlot = Math.max(maxSlot,slot+1); } if( !(n instanceof SplitNode lo) ) continue; diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/FunNode.java b/chapter21/src/main/java/com/seaofnodes/simple/node/FunNode.java index 8db30e7d..2e32b75e 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/node/FunNode.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/node/FunNode.java @@ -184,7 +184,7 @@ public class FunNode extends RegionNode { public short _maxSlot = -1; // Max argument slot, set during early Encoding. public short _maxArgSlot = -1; - // Frame adjust, including padding, st during early Encoding + // Frame adjust, including padding, set during early Encoding public short _frameAdjust; diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/FunX86.java b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/FunX86.java index 923fa362..15805fee 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/FunX86.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/FunX86.java @@ -7,7 +7,7 @@ import com.seaofnodes.simple.node.MachNode; public class FunX86 extends FunNode implements MachNode { FunX86( FunNode fun ) { super(fun); } - @Override public String op() { return "addi"; } + @Override public String op() { return "subi"; } @Override public RegMask regmap(int i) { return null; } @Override public RegMask outregmap() { return null; } @Override public void postSelect(CodeGen code) { code.link(this); } @@ -16,15 +16,16 @@ public class FunX86 extends FunNode implements MachNode { // X86, with too many args & spills: // | CALLER | // | argN | // slot 1, required by callER - // +--------+ + // +--------+ // Old frame // | RPC | // slot 0, required by callER + // +--------+ // New frame top + // | PAD16 | // | callee | // slot 3, callEE // | callee | // slot 2, callEE - // | PAD16 | // +--------+ @Override public void encoding( Encoding enc ) { // Stack frame size: _maxSlot - max(arg), padded to 16. - _maxArgSlot = x86_64_v2.maxSlot(enc._fun.sig()); + _maxArgSlot = x86_64_v2.maxArgSlot(enc._fun.sig()); int sz = _maxSlot - _maxArgSlot; // If non-leaf function, pad to 16b if( _hasCalls ) sz = ((sz+1) & -2)+1; @@ -34,11 +35,11 @@ public class FunX86 extends FunNode implements MachNode { // opcode: 0x83, addi rsp with immediate 8 enc.add1( x86_64_v2.REX_W ).add1( 0x83 ); - enc.add1( x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, 0, x86_64_v2.RSP) ); + enc.add1( x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, 0b101, x86_64_v2.RSP) ); enc.add1(sz*8); } @Override public void asm(CodeGen code, SB sb) { - sb.p("rsp += #").p(_frameAdjust*8); + sb.p("rsp -= #").p(_frameAdjust*8); } } diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/RetX86.java b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/RetX86.java index a9da15c6..4faf7cb4 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/RetX86.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/RetX86.java @@ -22,7 +22,7 @@ public class RetX86 extends ReturnNode implements MachNode { if( frameAdjust > 0 ) { enc.add1( x86_64_v2.REX_W ).add1( 0x83 ); enc.add1( x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, 0, x86_64_v2.RSP) ); - enc.add1(frameAdjust*-8); + enc.add1(frameAdjust*8); } enc.add1(0xC3); } diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java index d9bca291..4770bfbb 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java @@ -59,10 +59,10 @@ public class x86_64_v2 extends Machine { public static int REX_WB = 0x49; public enum MOD { - INDIRECT, // [mem] - INDIRECT_disp8, // [mem + 0x12] - INDIRECT_disp32,// [mem + 0x12345678] - DIRECT, // mem + INDIRECT, // [mem] + INDIRECT_disp8, // [mem + 0x12] + INDIRECT_disp32, // [mem + 0x12345678] + DIRECT, // mem }; // opcode included here @@ -249,8 +249,8 @@ public class x86_64_v2 extends Machine { throw Utils.TODO(); // Pass on stack slot } - // Return the max stack slot used by this signature, or 0 - static short maxSlot( TypeFunPtr tfp ) { + // Return the max stack slot used by this signature, or 1 (for RPC) + static short maxArgSlot( TypeFunPtr tfp ) { // Count floats in signature up to index int fcnt=0; for( int i=0; i<tfp.nargs(); i++ ) @@ -265,12 +265,7 @@ public class x86_64_v2 extends Machine { }; if( tfp.nargs()-fcnt >= cargs.length ) throw Utils.TODO(); - return 0; // No stack args - } - - // Return single int/ptr register. Used by CallEnd output and Return input. - static RegMask retMask( TypeFunPtr tfp ) { - return tfp.ret() instanceof TypeFloat ? XMM0_MASK : RAX_MASK; + return 1; // No stack args, plus RPC } |
