# HG changeset patch # User Stefan Anzinger # Date 1398316884 -7200 # Node ID 18c8ef7df8b542fb61c833e88242bb5c401518cd # Parent 12f2b3baa163dc8dc035ad4a1eb7c9b69a741760 Implementing LNEG and check for the right condition code register. diff -r 12f2b3baa163 -r 18c8ef7df8b5 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 Sat Apr 19 15:32:02 2014 +0200 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Apr 24 07:21:24 2014 +0200 @@ -33,9 +33,11 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.sparc.*; +import com.oracle.graal.asm.sparc.SPARCAssembler.CC; import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.debug.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.JumpOp; import com.oracle.graal.lir.sparc.*; @@ -282,18 +284,21 @@ @Override public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) { boolean mirrored = emitCompare(left, right); + // TTY.print(String.format("Cond: l: %s r: %s cond: %s, mirrored: %b\n", left, right, cond, +// mirrored)); Condition finalCondition = mirrored ? cond.mirror() : cond; + CC cCode = getCCodeForKind(left.getKind()); Variable result = newVariable(trueValue.getKind()); switch (left.getKind().getStackKind()) { case Int: case Long: case Object: - append(new CondMoveOp(result, finalCondition, load(trueValue), loadNonConst(falseValue))); + append(new CondMoveOp(result, finalCondition, cCode, load(trueValue), loadNonConst(falseValue))); break; case Float: case Double: - append(new FloatCondMoveOp(result, finalCondition, unorderedIsTrue, load(trueValue), load(falseValue))); + append(new FloatCondMoveOp(result, finalCondition, cCode, unorderedIsTrue, load(trueValue), load(falseValue))); break; default: throw GraalInternalError.shouldNotReachHere("" + left.getKind()); @@ -301,6 +306,18 @@ return result; } + private static CC getCCodeForKind(Kind kind) { + switch (kind) { + case Int: + return CC.Icc; + case Long: + return CC.Xcc; + case Float: + return CC.Fcc0; + } + throw GraalInternalError.shouldNotReachHere("" + kind); + } + /** * This method emits the compare instruction, and may reorder the operands. It returns true if * it did so. @@ -348,7 +365,8 @@ public Variable emitIntegerTestMove(Value left, Value right, Value trueValue, Value falseValue) { emitIntegerTest(left, right); Variable result = newVariable(trueValue.getKind()); - append(new CondMoveOp(result, Condition.EQ, load(trueValue), loadNonConst(falseValue))); + CC cCode = getCCodeForKind(left.getKind()); + append(new CondMoveOp(result, Condition.EQ, cCode, load(trueValue), loadNonConst(falseValue))); return result; } @@ -460,6 +478,9 @@ case Int: append(new Op1Stack(INEG, result, input)); break; + case Long: + append(new Op1Stack(LNEG, result, input)); + break; case Float: append(new Op1Stack(FNEG, result, input)); break; diff -r 12f2b3baa163 -r 18c8ef7df8b5 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Sat Apr 19 15:32:02 2014 +0200 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Thu Apr 24 07:21:24 2014 +0200 @@ -539,6 +539,17 @@ } else { switch (opcode) { case LREM: + new Sdivx(asLongReg(src1), asLongReg(src2), asLongReg(scratch1)).emit(masm); + exceptionOffset = masm.position(); + new Mulx(asLongReg(scratch1), asLongReg(src2), asLongReg(scratch2)).emit(masm); + new Sub(asLongReg(src1), asLongReg(scratch2), asLongReg(dst)).emit(masm); + break; + case IREM: + new Sdivx(asIntReg(src1), asIntReg(src2), asIntReg(scratch1)).emit(masm); + exceptionOffset = masm.position(); + new Mulx(asIntReg(scratch1), asIntReg(src2), asIntReg(scratch2)).emit(masm); + new Sub(asIntReg(src1), asIntReg(scratch2), asIntReg(dst)).emit(masm); + break; case LUREM: throw GraalInternalError.unimplemented(); default: @@ -560,6 +571,9 @@ case INEG: new Neg(asIntReg(src), asIntReg(dst)).emit(masm); break; + case LNEG: + new Neg(asLongReg(src), asLongReg(dst)).emit(masm); + break; case INOT: new Not(asIntReg(src), asIntReg(dst)).emit(masm); break; diff -r 12f2b3baa163 -r 18c8ef7df8b5 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Sat Apr 19 15:32:02 2014 +0200 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Thu Apr 24 07:21:24 2014 +0200 @@ -275,17 +275,19 @@ @Use({REG, STACK, CONST}) protected Value falseValue; private final ConditionFlag condition; + private final CC cCode; - public CondMoveOp(Variable result, Condition condition, Variable trueValue, Value falseValue) { + public CondMoveOp(Variable result, Condition condition, CC cCode, Variable trueValue, Value falseValue) { this.result = result; this.condition = intCond(condition); this.trueValue = trueValue; this.falseValue = falseValue; + this.cCode = CC.Icc; } @Override public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { - cmove(crb, masm, result, false, condition, false, trueValue, falseValue); + cmove(crb, masm, result, false, condition, cCode, false, trueValue, falseValue); } } @@ -297,27 +299,30 @@ @Alive({REG}) protected Value falseValue; private final ConditionFlag condition; private final boolean unorderedIsTrue; + private final CC cCode; - public FloatCondMoveOp(Variable result, Condition condition, boolean unorderedIsTrue, Variable trueValue, Variable falseValue) { + public FloatCondMoveOp(Variable result, Condition condition, CC cCode, boolean unorderedIsTrue, Variable trueValue, Variable falseValue) { this.result = result; this.condition = floatCond(condition); this.unorderedIsTrue = unorderedIsTrue; this.trueValue = trueValue; this.falseValue = falseValue; + this.cCode = cCode; } @Override public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { - cmove(crb, masm, result, true, condition, unorderedIsTrue, trueValue, falseValue); + cmove(crb, masm, result, true, condition, cCode, unorderedIsTrue, trueValue, falseValue); } } - private static void cmove(CompilationResultBuilder crb, SPARCMacroAssembler masm, Value result, boolean isFloat, ConditionFlag condition, boolean unorderedIsTrue, Value trueValue, Value falseValue) { + private static void cmove(CompilationResultBuilder crb, SPARCMacroAssembler masm, Value result, boolean isFloat, ConditionFlag condition, CC cCode, boolean unorderedIsTrue, Value trueValue, + Value falseValue) { // check that we don't overwrite an input operand before it is used. assert !result.equals(trueValue); SPARCMove.move(crb, masm, result, falseValue); - cmove(crb, masm, result, condition, trueValue); + cmove(crb, masm, result, condition, cCode, trueValue); if (isFloat) { if (unorderedIsTrue && !trueOnUnordered(condition)) { @@ -330,7 +335,7 @@ } } - private static void cmove(CompilationResultBuilder crb, SPARCMacroAssembler masm, Value result, ConditionFlag cond, Value other) { + private static void cmove(CompilationResultBuilder crb, SPARCMacroAssembler masm, Value result, ConditionFlag cond, CC cCode, Value other) { if (!isRegister(other)) { SPARCMove.move(crb, masm, result, other); throw new InternalError("result should be scratch"); @@ -338,10 +343,9 @@ assert !asRegister(other).equals(asRegister(result)) : "other already overwritten by previous move"; switch (other.getKind()) { case Int: - // XXX CC depends on compare - new Movcc(cond, CC.Icc, asRegister(other), asRegister(result)).emit(masm); + case Long: + new Movcc(cond, cCode, asRegister(other), asRegister(result)).emit(masm); break; - case Long: default: throw GraalInternalError.shouldNotReachHere(); }