# HG changeset patch # User Morris Meyer # Date 1370105082 14400 # Node ID 204e8f3209e9d43bb6a6bdea8f54d1ff199d7550 # Parent 2d1687e63484fed179e7b971cd5c895a7d37a90b SPARCMacroAssembler synthetic instructions and SPARCTestOp diff -r 2d1687e63484 -r 204e8f3209e9 graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Fri May 31 21:55:53 2013 -0400 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Sat Jun 01 12:44:42 2013 -0400 @@ -607,6 +607,12 @@ return x & ((1 << 10) - 1); } + @Override + @SuppressWarnings("unused") + public void jmp(Label l) { + new Bpa(this, l); + } + public static class Add extends Fmt3b { public Add(SPARCAssembler masm, Register src1, int simm13, Register dst) { super(masm, Ops.ArithOp.getValue(), Op3s.Add.getValue(), src1.encoding(), simm13, dst.encoding()); @@ -691,6 +697,30 @@ } } + public static class Bpcc extends Fmt2c { + public Bpcc(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.CarryClear.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpcc(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.CarryClear.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpcs extends Fmt2c { + public Bpcs(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.CarrySet.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpcs(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.CarrySet.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + public static class Bpe extends Fmt2c { public Bpe(SPARCAssembler masm, CC cc, int simmm19) { super(masm, Ops.BranchOp.getValue(), 0, Condition.Equal.getValue(), @@ -703,6 +733,78 @@ } } + public static class Bpg extends Fmt2c { + public Bpg(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Greater.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpg(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Greater.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpge extends Fmt2c { + public Bpge(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.GreaterEqual.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpge(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.GreaterEqual.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpgu extends Fmt2c { + public Bpgu(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.GreaterUnsigned.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpgu(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.GreaterUnsigned.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpl extends Fmt2c { + public Bpl(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Less.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpl(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Less.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bple extends Fmt2c { + public Bple(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.LessEqual.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bple(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.LessEqual.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpleu extends Fmt2c { + public Bpleu(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.LessEqualUnsigned.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpleu(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.LessEqualUnsigned.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + public static class Bpn extends Fmt2c { public Bpn(SPARCAssembler masm, CC cc, int simmm19) { super(masm, Ops.BranchOp.getValue(), 0, Condition.Never.getValue(), @@ -727,6 +829,54 @@ } } + public static class Bpneg extends Fmt2c { + public Bpneg(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Negative.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpneg(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Negative.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bppos extends Fmt2c { + public Bppos(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Positive.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bppos(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.Positive.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpvc extends Fmt2c { + public Bpvc(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.OverflowClear.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpvc(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.OverflowClear.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + + public static class Bpvs extends Fmt2c { + public Bpvs(SPARCAssembler masm, CC cc, int simmm19) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.OverflowSet.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, simmm19); + } + public Bpvs(SPARCAssembler masm, CC cc, Label label) { + super(masm, Ops.BranchOp.getValue(), 0, Condition.OverflowSet.getValue(), + Op2s.Bp.getValue(), cc.getValue(), 1, + label.isBound() ? label.position() : patchUnbound(masm, label)); + } + } + private static int patchUnbound(SPARCAssembler masm, Label label) { label.addPatchAt(masm.codeBuffer.position()); return 0; @@ -836,12 +986,6 @@ } } - @Override - @SuppressWarnings("unused") - public void jmp(Label l) { - new Bpa(this, l); - } - public static class Jmpl extends Fmt3b { public Jmpl(SPARCAssembler asm, SPARCAddress src, Register dst) { super(asm, Ops.ArithOp.getValue(), Op3s.Jmpl.getValue(), @@ -899,8 +1043,9 @@ } public static class Membar extends Fmt3b { - public Membar(SPARCAssembler masm, MembarMask mask) { - super(masm, Ops.ArithOp.getValue(), 0, Op3s.Membar.getValue(), 0xf, mask.getValue()); + public Membar(SPARCAssembler masm, int barriers) { + super(masm, Ops.ArithOp.getValue(), Op3s.Membar.getValue(), + SPARC.r15.encoding(), ImmedTrue | barriers, SPARC.r0.encoding()); } } @@ -1193,35 +1338,38 @@ } @Deprecated - public final void stbar() { - emitInt(Ops.ArithOp.getValue() | Op3s.Membar.getValue() | 0x0003C000); + public static class Stbar extends Fmt3b { + public Stbar(SPARCAssembler masm) { + super(masm, Ops.ArithOp.getValue(), Op3s.Membar.getValue(), + SPARC.r15.encoding(), 0, SPARC.r0.encoding()); + } } public static class Stb extends Fmt3b { - public Stb(SPARCAssembler masm, SPARCAddress src, Register dst) { + public Stb(SPARCAssembler masm, Register dst, SPARCAddress addr) { super(masm, Ops.ArithOp.getValue(), Op3s.Stb.getValue(), - src.getBase().encoding(), src.getDisplacement(), dst.encoding()); + addr.getBase().encoding(), addr.getDisplacement(), dst.encoding()); } } public static class Sth extends Fmt3b { - public Sth(SPARCAssembler masm, SPARCAddress src, Register dst) { + public Sth(SPARCAssembler masm, Register dst, SPARCAddress addr) { super(masm, Ops.ArithOp.getValue(), Op3s.Sth.getValue(), - src.getBase().encoding(), src.getDisplacement(), dst.encoding()); + addr.getBase().encoding(), addr.getDisplacement(), dst.encoding()); } } public static class Stw extends Fmt3b { - public Stw(SPARCAssembler masm, SPARCAddress src, Register dst) { + public Stw(SPARCAssembler masm, Register dst, SPARCAddress addr) { super(masm, Ops.ArithOp.getValue(), Op3s.Stw.getValue(), - src.getBase().encoding(), src.getDisplacement(), dst.encoding()); + addr.getBase().encoding(), addr.getDisplacement(), dst.encoding()); } } public static class Stx extends Fmt3b { - public Stx(SPARCAssembler masm, SPARCAddress src, Register dst) { + public Stx(SPARCAssembler masm, Register dst, SPARCAddress addr) { super(masm, Ops.ArithOp.getValue(), Op3s.Stx.getValue(), - src.getBase().encoding(), src.getDisplacement(), dst.encoding()); + addr.getBase().encoding(), addr.getDisplacement(), dst.encoding()); } } diff -r 2d1687e63484 -r 204e8f3209e9 graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java Fri May 31 21:55:53 2013 -0400 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java Sat Jun 01 12:44:42 2013 -0400 @@ -32,72 +32,193 @@ } @SuppressWarnings("unused") - public static class Cmp { + public static class Bclr { - public Cmp(SPARCAssembler masm, Register a, Register b) { - new Subcc(masm, a, b, SPARC.r0); + public Bclr(SPARCAssembler asm, Register src, Register dst) { + new Andn(asm, dst, src, dst); } - public Cmp(SPARCAssembler masm, Register a, int simm13) { - new Subcc(masm, a, simm13, SPARC.r0); + public Bclr(SPARCAssembler asm, int simm13, Register dst) { + new Andn(asm, dst, simm13, dst); + } + } + + @SuppressWarnings("unused") + public static class Bset { + + public Bset(SPARCAssembler asm, Register src, Register dst) { + new Or(asm, dst, src, dst); + } + + public Bset(SPARCAssembler asm, int simm13, Register dst) { + new Or(asm, dst, simm13, dst); + } + } + + @SuppressWarnings("unused") + public static class Btog { + + public Btog(SPARCAssembler asm, Register src, Register dst) { + new Xor(asm, dst, src, dst); + } + + public Btog(SPARCAssembler asm, int simm13, Register dst) { + new Xor(asm, dst, simm13, dst); } } @SuppressWarnings("unused") - public static class Setuw { + public static class Btst { + + public Btst(SPARCAssembler asm, Register src1, Register src2) { + new Andcc(asm, src1, src2, SPARC.g0); + } + + public Btst(SPARCAssembler asm, Register src1, int simm13) { + new Andcc(asm, src1, simm13, SPARC.g0); + } + } + + @SuppressWarnings("unused") + public static class Clr { + + public Clr(SPARCAssembler asm, Register dst) { + new Or(asm, SPARC.g0, SPARC.g0, dst); + } - public Setuw(SPARCAssembler masm, int value, Register dst) { - if (value >= 0 && ((value & 0x3FFF) == 0)) { - new Sethi(masm, hi22(value), dst); - } else if (-4095 <= value && value <= 4096) { - // or g0, value, dst - new Or(masm, SPARC.r0, value, dst); - } else { - new Sethi(masm, hi22(value), dst); - new Or(masm, dst, lo10(value), dst); - } + public Clr(SPARCAssembler asm, SPARCAddress addr) { + new Stw(asm, SPARC.g0, addr); + } + } + + @SuppressWarnings("unused") + public static class Clrb { + + public Clrb(SPARCAssembler asm, SPARCAddress addr) { + new Stb(asm, SPARC.g0, addr); + } + } + + @SuppressWarnings("unused") + public static class Clrh { + + public Clrh(SPARCAssembler asm, SPARCAddress addr) { + new Sth(asm, SPARC.g0, addr); + } + } + + @SuppressWarnings("unused") + public static class Clrx { + + public Clrx(SPARCAssembler asm, SPARCAddress addr) { + new Stx(asm, SPARC.g0, addr); } } @SuppressWarnings("unused") - public static class Setx { + public static class Clruw { + + public Clruw(SPARCAssembler asm, Register src1, Register dst) { + assert src1.encoding() != dst.encoding(); + new Srl(asm, src1, SPARC.g0, dst); + } + + public Clruw(SPARCAssembler asm, Register dst) { + new Srl(asm, dst, SPARC.g0, dst); + } + } + + @SuppressWarnings("unused") + public static class Cmp { + + public Cmp(SPARCAssembler asm, Register a, Register b) { + new Subcc(asm, a, b, SPARC.g0); + } + + public Cmp(SPARCAssembler asm, Register a, int simm13) { + new Subcc(asm, a, simm13, SPARC.g0); + } + } - public Setx(SPARCAssembler masm, long value, Register tmp, Register dst) { - int hi = (int) (value >> 32); - int lo = (int) (value & ~0); + @SuppressWarnings("unused") + public static class Dec { + + public Dec(SPARCAssembler asm, Register dst) { + new Sub(asm, dst, 1, dst); + } + + public Dec(SPARCAssembler asm, int simm13, Register dst) { + new Sub(asm, dst, simm13, dst); + } + } + + @SuppressWarnings("unused") + public static class Deccc { + + public Deccc(SPARCAssembler asm, Register dst) { + new Subcc(asm, dst, 1, dst); + } + + public Deccc(SPARCAssembler asm, int simm13, Register dst) { + new Subcc(asm, dst, simm13, dst); + } + } + + @SuppressWarnings("unused") + public static class Inc { - if (isSimm13(lo) && value == lo) { - new Or(masm, SPARC.r0, lo, dst); - } else if (hi == 0) { - new Sethi(masm, lo, dst); // hardware version zero-extends to upper 32 - if (lo10(lo) != 0) { - new Or(masm, dst, lo10(lo), dst); - } - } else if (hi == -1) { - new Sethi(masm, ~lo, dst); // hardware version zero-extends to upper 32 - new Xor(masm, dst, lo10(lo) ^ ~lo10(~0), dst); - } else if (lo == 0) { - if (isSimm13(hi)) { - new Or(masm, SPARC.r0, hi, dst); - } else { - new Sethi(masm, hi, dst); // hardware version zero-extends to upper 32 - if (lo10(hi) != 0) { - new Or(masm, dst, lo10(hi), dst); - } - } - new Sllx(masm, dst, 32, dst); - } else { - new Sethi(masm, hi, tmp); - new Sethi(masm, lo, dst); // macro assembler version sign-extends - if (lo10(hi) != 0) { - new Or(masm, tmp, lo10(hi), tmp); - } - if (lo10(lo) != 0) { - new Or(masm, dst, lo10(lo), dst); - } - new Sllx(masm, tmp, 32, tmp); - new Or(masm, dst, tmp, dst); - } + public Inc(SPARCAssembler asm, Register dst) { + new Add(asm, dst, 1, dst); + } + + public Inc(SPARCAssembler asm, int simm13, Register dst) { + new Add(asm, dst, simm13, dst); + } + } + + @SuppressWarnings("unused") + public static class Inccc { + + public Inccc(SPARCAssembler asm, Register dst) { + new Addcc(asm, dst, 1, dst); + } + + public Inccc(SPARCAssembler asm, int simm13, Register dst) { + new Addcc(asm, dst, simm13, dst); + } + } + + @SuppressWarnings("unused") + public static class Jmp { + + public Jmp(SPARCAssembler asm, SPARCAddress address) { + new Jmpl(asm, address, SPARC.g0); + } + } + + @SuppressWarnings("unused") + public static class Neg { + + public Neg(SPARCAssembler asm, Register src2, Register dst) { + assert src2.encoding() != dst.encoding(); + new Sub(asm, SPARC.g0, src2, dst); + } + + public Neg(SPARCAssembler asm, Register dst) { + new Sub(asm, SPARC.g0, dst, dst); + } + } + + @SuppressWarnings("unused") + public static class Not { + + public Not(SPARCAssembler asm, Register src1, Register dst) { + assert src1.encoding() != dst.encoding(); + new Xnor(asm, src1, SPARC.g0, dst); + } + + public Not(SPARCAssembler asm, Register dst) { + new Xnor(asm, dst, SPARC.g0, dst); } } @@ -126,4 +247,74 @@ } } + @SuppressWarnings("unused") + public static class Setuw { + + public Setuw(SPARCAssembler asm, int value, Register dst) { + if (value >= 0 && ((value & 0x3FFF) == 0)) { + new Sethi(asm, hi22(value), dst); + } else if (-4095 <= value && value <= 4096) { + new Or(asm, SPARC.g0, value, dst); + } else { + new Sethi(asm, hi22(value), dst); + new Or(asm, dst, lo10(value), dst); + } + } + } + + @SuppressWarnings("unused") + public static class Setx { + + public Setx(SPARCAssembler asm, long value, Register tmp, Register dst) { + int hi = (int) (value >> 32); + int lo = (int) (value & ~0); + + if (isSimm13(lo) && value == lo) { + new Or(asm, SPARC.g0, lo, dst); + } else if (hi == 0) { + new Sethi(asm, lo, dst); // hardware version zero-extends to upper 32 + if (lo10(lo) != 0) { + new Or(asm, dst, lo10(lo), dst); + } + } else if (hi == -1) { + new Sethi(asm, ~lo, dst); // hardware version zero-extends to upper 32 + new Xor(asm, dst, lo10(lo) ^ ~lo10(~0), dst); + } else if (lo == 0) { + if (isSimm13(hi)) { + new Or(asm, SPARC.g0, hi, dst); + } else { + new Sethi(asm, hi, dst); // hardware version zero-extends to upper 32 + if (lo10(hi) != 0) { + new Or(asm, dst, lo10(hi), dst); + } + } + new Sllx(asm, dst, 32, dst); + } else { + new Sethi(asm, hi, tmp); + new Sethi(asm, lo, dst); // macro assembler version sign-extends + if (lo10(hi) != 0) { + new Or(asm, tmp, lo10(hi), tmp); + } + if (lo10(lo) != 0) { + new Or(asm, dst, lo10(lo), dst); + } + new Sllx(asm, tmp, 32, tmp); + new Or(asm, dst, tmp, dst); + } + } + } + + @SuppressWarnings("unused") + public static class Signx { + + public Signx(SPARCAssembler asm, Register src1, Register dst) { + assert src1.encoding() != dst.encoding(); + new Sra(asm, src1, SPARC.g0, dst); + } + + public Signx(SPARCAssembler asm, Register dst) { + new Sra(asm, dst, SPARC.g0, dst); + } + } + } diff -r 2d1687e63484 -r 204e8f3209e9 graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Fri May 31 21:55:53 2013 -0400 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Sat Jun 01 12:44:42 2013 -0400 @@ -24,6 +24,7 @@ package com.oracle.graal.compiler.sparc; import static com.oracle.graal.api.code.ValueUtil.*; +import static com.oracle.graal.lir.LIRValueUtil.*; import static com.oracle.graal.lir.sparc.SPARCArithmetic.*; import static com.oracle.graal.lir.sparc.SPARCCompare.*; @@ -41,12 +42,7 @@ import com.oracle.graal.compiler.gen.LIRGenerator; import com.oracle.graal.compiler.target.LIRGenLowerable; import com.oracle.graal.graph.GraalInternalError; -import com.oracle.graal.lir.FrameMap; -import com.oracle.graal.lir.LIR; -import com.oracle.graal.lir.LIRFrameState; -import com.oracle.graal.lir.LIRInstruction; -import com.oracle.graal.lir.LabelRef; -import com.oracle.graal.lir.Variable; +import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.*; import com.oracle.graal.lir.sparc.*; import com.oracle.graal.lir.sparc.SPARCArithmetic.Op1Stack; @@ -61,9 +57,12 @@ import com.oracle.graal.lir.sparc.SPARCControlFlow.SequentialSwitchOp; import com.oracle.graal.lir.sparc.SPARCControlFlow.TableSwitchOp; import com.oracle.graal.lir.sparc.SPARCMove.LoadOp; +import com.oracle.graal.lir.sparc.SPARCMove.MembarOp; import com.oracle.graal.lir.sparc.SPARCMove.MoveFromRegOp; import com.oracle.graal.lir.sparc.SPARCMove.MoveToRegOp; +import com.oracle.graal.lir.sparc.SPARCMove.StackLoadAddressOp; import com.oracle.graal.lir.sparc.SPARCMove.StoreOp; +import com.oracle.graal.lir.sparc.SPARCTestOp; import com.oracle.graal.nodes.BreakpointNode; import com.oracle.graal.nodes.DeoptimizingNode; import com.oracle.graal.nodes.DirectCallTargetNode; @@ -165,12 +164,38 @@ @Override public void emitOverflowCheckBranch(LabelRef label, boolean negated) { - throw new InternalError("NYI"); + // append(new BranchOp(negated ? ConditionFlag.NoOverflow : ConditionFlag.Overflow, label)); } @Override public void emitIntegerTestBranch(Value left, Value right, boolean negated, LabelRef label) { - throw new InternalError("NYI"); + emitIntegerTest(left, right); + append(new BranchOp(negated ? Condition.NE : Condition.EQ, label)); + } + + private void emitIntegerTest(Value a, Value b) { + assert a.getKind().getStackKind() == Kind.Int || a.getKind() == Kind.Long; + if (LIRValueUtil.isVariable(b)) { + append(new SPARCTestOp(load(b), loadNonConst(a))); + } else { + append(new SPARCTestOp(load(a), loadNonConst(b))); + } + } + + @Override + public Variable load(Value value) { + if (!isVariable(value)) { + return emitMove(value); + } + return (Variable) value; + } + + @Override + public Value loadNonConst(Value value) { + if (isConstant(value) && !canInlineConstant((Constant) value)) { + return emitMove(value); + } + return value; } @Override @@ -357,7 +382,9 @@ @Override public Value emitAddress(StackSlot address) { - throw new InternalError("NYI"); + Variable result = newVariable(target().wordKind); + append(new StackLoadAddressOp(result, address)); + return result; } @Override @@ -666,7 +693,10 @@ @Override public void emitMembar(int barriers) { - throw new InternalError("NYI"); + int necessaryBarriers = target.arch.requiredBarriers(barriers); + if (target.isMP && necessaryBarriers != 0) { + append(new MembarOp(necessaryBarriers)); + } } @Override diff -r 2d1687e63484 -r 204e8f3209e9 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Fri May 31 21:55:53 2013 -0400 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Sat Jun 01 12:44:42 2013 -0400 @@ -22,11 +22,10 @@ */ package com.oracle.graal.lir.sparc; -import static com.oracle.graal.api.code.ValueUtil.asRegister; -import static com.oracle.graal.api.code.ValueUtil.isConstant; -import static com.oracle.graal.api.code.ValueUtil.isRegister; +import static com.oracle.graal.api.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; +import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.sparc.SPARCAddress; import com.oracle.graal.asm.sparc.SPARCAssembler; @@ -37,6 +36,7 @@ import com.oracle.graal.asm.sparc.SPARCAssembler.Ldsw; import com.oracle.graal.asm.sparc.SPARCAssembler.Lduw; import com.oracle.graal.asm.sparc.SPARCAssembler.Ldx; +import com.oracle.graal.asm.sparc.SPARCAssembler.Membar; import com.oracle.graal.asm.sparc.SPARCAssembler.Or; import com.oracle.graal.asm.sparc.SPARCAssembler.Stb; import com.oracle.graal.asm.sparc.SPARCAssembler.Sth; @@ -54,24 +54,6 @@ public class SPARCMove { - public static class NullCheckOp extends SPARCLIRInstruction { - - @Use({REG}) protected AllocatableValue input; - @State protected LIRFrameState state; - - public NullCheckOp(Variable input, LIRFrameState state) { - this.input = input; - this.state = state; - } - - @Override - @SuppressWarnings("unused") - public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) { - tasm.recordImplicitException(masm.codeBuffer.position(), state); - new NullCheck(masm, new SPARCAddress(asRegister(input), 0)); - } - } - public static class LoadOp extends SPARCLIRInstruction { private final Kind kind; @@ -121,50 +103,18 @@ } } - public static class StoreOp extends SPARCLIRInstruction { + @SuppressWarnings("unused") + public static class MembarOp extends SPARCLIRInstruction { - private final Kind kind; - @Use({COMPOSITE}) protected SPARCAddressValue address; - @Use({REG}) protected AllocatableValue input; - @State protected LIRFrameState state; + private final int barriers; - public StoreOp(Kind kind, SPARCAddressValue address, AllocatableValue input, LIRFrameState state) { - this.kind = kind; - this.address = address; - this.input = input; - this.state = state; + public MembarOp(final int barriers) { + this.barriers = barriers; } @Override - @SuppressWarnings("unused") - public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) { - assert isRegister(input); - SPARCAddress addr = address.toAddress(); - switch (kind) { - case Byte: - new Stb(masm, addr, asRegister(input)); - break; - case Short: - new Sth(masm, addr, asRegister(input)); - break; - case Int: - new Stw(masm, addr, asRegister(input)); - break; - case Long: - new Stx(masm, addr, asRegister(input)); - break; - case Float: - new Stx(masm, addr, asRegister(input)); - break; - case Double: - new Stx(masm, addr, asRegister(input)); - break; - case Object: - new Stx(masm, addr, asRegister(input)); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + address.getKind()); - } + public void emitCode(TargetMethodAssembler tasm, SPARCAssembler asm) { + new Membar(asm, barriers); } } @@ -222,6 +172,88 @@ } } + public static class NullCheckOp extends SPARCLIRInstruction { + + @Use({REG}) protected AllocatableValue input; + @State protected LIRFrameState state; + + public NullCheckOp(Variable input, LIRFrameState state) { + this.input = input; + this.state = state; + } + + @Override + @SuppressWarnings("unused") + public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) { + tasm.recordImplicitException(masm.codeBuffer.position(), state); + new NullCheck(masm, new SPARCAddress(asRegister(input), 0)); + } + } + + @SuppressWarnings("unused") + public static class StackLoadAddressOp extends SPARCLIRInstruction { + + @Def({REG}) protected AllocatableValue result; + @Use({STACK, UNINITIALIZED}) protected StackSlot slot; + + public StackLoadAddressOp(AllocatableValue result, StackSlot slot) { + this.result = result; + this.slot = slot; + } + + @Override + public void emitCode(TargetMethodAssembler tasm, SPARCAssembler asm) { + new Ldx(asm, (SPARCAddress) tasm.asAddress(slot), asLongReg(result)); + } + } + + public static class StoreOp extends SPARCLIRInstruction { + + private final Kind kind; + @Use({COMPOSITE}) protected SPARCAddressValue address; + @Use({REG}) protected AllocatableValue input; + @State protected LIRFrameState state; + + public StoreOp(Kind kind, SPARCAddressValue address, AllocatableValue input, LIRFrameState state) { + this.kind = kind; + this.address = address; + this.input = input; + this.state = state; + } + + @Override + @SuppressWarnings("unused") + public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) { + assert isRegister(input); + SPARCAddress addr = address.toAddress(); + switch (kind) { + case Byte: + new Stb(masm, asRegister(input), addr); + break; + case Short: + new Sth(masm, asRegister(input), addr); + break; + case Int: + new Stw(masm, asRegister(input), addr); + break; + case Long: + new Stx(masm, asRegister(input), addr); + break; + case Float: + new Stx(masm, asRegister(input), addr); + break; + case Double: + new Stx(masm, asRegister(input), addr); + break; + case Object: + new Stx(masm, asRegister(input), addr); + break; + default: + throw GraalInternalError.shouldNotReachHere("missing: " + address.getKind()); + } + } + } + public static void move(TargetMethodAssembler tasm, SPARCAssembler masm, Value result, Value input) { if (isRegister(input)) { if (isRegister(result)) { diff -r 2d1687e63484 -r 204e8f3209e9 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTestOp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCTestOp.java Sat Jun 01 12:44:42 2013 -0400 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.lir.sparc; + +import static com.oracle.graal.api.code.ValueUtil.*; +import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.asm.sparc.*; +import com.oracle.graal.asm.sparc.SPARCAssembler.Ldsw; +import com.oracle.graal.asm.sparc.SPARCAssembler.Ldx; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Cmp; +import com.oracle.graal.graph.*; +import com.oracle.graal.lir.asm.*; + +public class SPARCTestOp extends SPARCLIRInstruction { + + @Use({REG}) protected Value x; + @Use({REG, STACK, CONST}) protected Value y; + + public SPARCTestOp(Value x, Value y) { + this.x = x; + this.y = y; + } + + @Override + @SuppressWarnings("unused") + public void emitCode(TargetMethodAssembler tasm, SPARCAssembler asm) { + if (isRegister(y)) { + switch (x.getKind()) { + case Int: + new Cmp(asm, asIntReg(x), asIntReg(y)); + break; + case Long: + new Cmp(asm, asLongReg(x), asLongReg(y)); + break; + default: + throw GraalInternalError.shouldNotReachHere(); + } + } else if (isConstant(y)) { + switch (x.getKind()) { + case Int: + new Cmp(asm, asIntReg(x), tasm.asIntConst(y)); + break; + case Long: + new Cmp(asm, asLongReg(x), tasm.asIntConst(y)); + break; + default: + throw GraalInternalError.shouldNotReachHere(); + } + } else { + switch (x.getKind()) { + case Int: + new Ldsw(asm, (SPARCAddress) tasm.asIntAddr(y), asIntReg(y)); + new Cmp(asm, asIntReg(x), asIntReg(y)); + break; + case Long: + new Ldx(asm, (SPARCAddress) tasm.asLongAddr(y), asLongReg(y)); + new Cmp(asm, asLongReg(x), asLongReg(y)); + break; + default: + throw GraalInternalError.shouldNotReachHere(); + } + } + } + +}