# HG changeset patch # User Stefan Anzinger # Date 1406346508 25200 # Node ID fa14ceabaf152eb1fe7ada2fcda44ac0f5bbc898 # Parent b1af1727a783d1845a67b7801871bf62185f8f45 [SPARC] Implement irem diff -r b1af1727a783 -r fa14ceabaf15 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_irem.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_irem.java Thu Jul 24 16:03:29 2014 -0700 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_irem.java Fri Jul 25 20:48:28 2014 -0700 @@ -34,6 +34,16 @@ return a % b; } + // Left as constant + public static int test2(int b) { + return 13 % b; + } + + // Right as constant + public static int test3(int a) { + return a % 13; + } + @Test public void run0() throws Throwable { runTest("test", 1, 2); @@ -54,4 +64,33 @@ runTest("test", 135, 7); } + @Test + public void run20() throws Throwable { + runTest("test2", 2); + } + + @Test + public void run21() throws Throwable { + runTest("test2", 20000000); + } + + @Test + public void run22() throws Throwable { + runTest("test2", -20000000); + } + + @Test + public void run30() throws Throwable { + runTest("test3", 2); + } + + @Test + public void run31() throws Throwable { + runTest("test3", 200000000); + } + + @Test + public void run32() throws Throwable { + runTest("test3", -200000000); + } } diff -r b1af1727a783 -r fa14ceabaf15 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 Thu Jul 24 16:03:29 2014 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Fri Jul 25 20:48:28 2014 -0700 @@ -250,8 +250,8 @@ @Def({REG}) protected Value result; @Use({REG, CONST}) protected Value x; @Alive({REG, CONST}) protected Value y; - @Def({REG}) protected Value scratch1; - @Def({REG}) protected Value scratch2; + @Temp({REG}) protected Value scratch1; + @Temp({REG}) protected Value scratch2; @State protected LIRFrameState state; public RemOp(SPARCArithmetic opcode, Value result, Value x, Value y, LIRFrameState state, LIRGeneratorTool gen) { @@ -549,11 +549,6 @@ default: throw GraalInternalError.shouldNotReachHere("not implemented"); } - } else if (isConstant(src1)) { - switch (opcode) { - default: - throw GraalInternalError.shouldNotReachHere(); - } } else if (isConstant(src2)) { switch (opcode) { case IREM: @@ -577,18 +572,27 @@ throw GraalInternalError.shouldNotReachHere(); } } else { + Value srcLeft = src1; switch (opcode) { case LREM: + if (isConstant(src1)) { + new Setx(crb.asLongConst(src1), asLongReg(scratch2), false).emit(masm); + srcLeft = scratch2; + } exceptionOffset = masm.position(); - new Sdivx(asLongReg(src1), asLongReg(src2), asLongReg(scratch1)).emit(masm); - new Mulx(asLongReg(scratch1), asLongReg(src2), asLongReg(scratch2)).emit(masm); - new Sub(asLongReg(src1), asLongReg(scratch2), asLongReg(dst)).emit(masm); + new Sdivx(asLongReg(srcLeft), asLongReg(src2), asLongReg(scratch1)).emit(masm); + new Mulx(asLongReg(scratch1), asLongReg(src2), asLongReg(scratch1)).emit(masm); + new Sub(asLongReg(srcLeft), asLongReg(scratch1), asLongReg(dst)).emit(masm); break; case IREM: + if (isConstant(src1)) { + new Setx(crb.asIntConst(src1), asIntReg(scratch2), false).emit(masm); + srcLeft = scratch2; + } exceptionOffset = masm.position(); - new Sdivx(asIntReg(src1), asIntReg(src2), asIntReg(scratch1)).emit(masm); - new Mulx(asIntReg(scratch1), asIntReg(src2), asIntReg(scratch2)).emit(masm); - new Sub(asIntReg(src1), asIntReg(scratch2), asIntReg(dst)).emit(masm); + new Sdivx(asIntReg(srcLeft), asIntReg(src2), asIntReg(scratch1)).emit(masm); + new Mulx(asIntReg(scratch1), asIntReg(src2), asIntReg(scratch1)).emit(masm); + new Sub(asIntReg(srcLeft), asIntReg(scratch1), asIntReg(dst)).emit(masm); break; case LUREM: throw GraalInternalError.unimplemented();