changeset 7920:2e3e4b691835

Remove duplicate code in DivOp.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 04 Mar 2013 16:48:17 +0100
parents 0ae70d44ec9a
children 1b591118d01e
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java
diffstat 2 files changed, 16 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Mon Mar 04 16:48:11 2013 +0100
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Mon Mar 04 16:48:17 2013 +0100
@@ -46,7 +46,6 @@
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.BinaryRegReg;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.BinaryRegStack;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.BinaryRegStackConst;
-import com.oracle.graal.lir.amd64.AMD64Arithmetic.DivOp;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.DivRemOp;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.Unary1Op;
 import com.oracle.graal.lir.amd64.AMD64Arithmetic.Unary2Op;
@@ -505,15 +504,19 @@
         return false;
     }
 
+    private void emitDivRem(AMD64Arithmetic op, Value a, Value b) {
+        AllocatableValue rax = AMD64.rax.asValue(a.getKind());
+        emitMove(rax, a);
+        append(new DivRemOp(op, rax, asAllocatable(b), state()));
+    }
+
     public Value[] emitIntegerDivRem(Value a, Value b) {
         switch (a.getKind()) {
             case Int:
-                emitMove(RAX_I, a);
-                append(new DivRemOp(IDIVREM, RAX_I, load(b), state()));
+                emitDivRem(IDIVREM, a, b);
                 return new Value[]{emitMove(RAX_I), emitMove(RDX_I)};
             case Long:
-                emitMove(RAX_L, a);
-                append(new DivRemOp(LDIVREM, RAX_L, load(b), state()));
+                emitDivRem(LDIVREM, a, b);
                 return new Value[]{emitMove(RAX_L), emitMove(RDX_L)};
             default:
                 throw GraalInternalError.shouldNotReachHere();
@@ -524,12 +527,10 @@
     public Value emitDiv(Value a, Value b) {
         switch (a.getKind()) {
             case Int:
-                emitMove(RAX_I, a);
-                append(new DivOp(IDIV, RAX_I, RAX_I, load(b), state()));
+                emitDivRem(IDIV, a, b);
                 return emitMove(RAX_I);
             case Long:
-                emitMove(RAX_L, a);
-                append(new DivOp(LDIV, RAX_L, RAX_L, load(b), state()));
+                emitDivRem(LDIV, a, b);
                 return emitMove(RAX_L);
             case Float: {
                 Variable result = newVariable(a.getKind());
@@ -550,12 +551,10 @@
     public Value emitRem(Value a, Value b) {
         switch (a.getKind()) {
             case Int:
-                emitMove(RAX_I, a);
-                append(new DivOp(IREM, RDX_I, RAX_I, load(b), state()));
+                emitDivRem(IREM, a, b);
                 return emitMove(RDX_I);
             case Long:
-                emitMove(RAX_L, a);
-                append(new DivOp(LREM, RDX_L, RAX_L, load(b), state()));
+                emitDivRem(LREM, a, b);
                 return emitMove(RDX_L);
             case Float: {
                 RuntimeCallTarget stub = runtime.lookupRuntimeCall(ARITHMETIC_FREM);
@@ -574,12 +573,10 @@
     public Variable emitUDiv(Value a, Value b) {
         switch (a.getKind()) {
             case Int:
-                emitMove(RAX_I, a);
-                append(new DivOp(IUDIV, RAX_I, RAX_I, load(b), state()));
+                emitDivRem(IUDIV, a, b);
                 return emitMove(RAX_I);
             case Long:
-                emitMove(RAX_L, a);
-                append(new DivOp(LUDIV, RAX_L, RAX_L, load(b), state()));
+                emitDivRem(LUDIV, a, b);
                 return emitMove(RAX_L);
             default:
                 throw GraalInternalError.shouldNotReachHere();
@@ -590,12 +587,10 @@
     public Variable emitURem(Value a, Value b) {
         switch (a.getKind()) {
             case Int:
-                emitMove(RAX_I, a);
-                append(new DivOp(IUREM, RDX_I, RAX_I, load(b), state()));
+                emitDivRem(IUREM, a, b);
                 return emitMove(RDX_I);
             case Long:
-                emitMove(RAX_L, a);
-                append(new DivOp(LUREM, RDX_L, RAX_L, load(b), state()));
+                emitDivRem(LUREM, a, b);
                 return emitMove(RDX_L);
             default:
                 throw GraalInternalError.shouldNotReachHere();
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java	Mon Mar 04 16:48:11 2013 +0100
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java	Mon Mar 04 16:48:17 2013 +0100
@@ -276,39 +276,6 @@
         }
     }
 
-    public static class DivOp extends AMD64LIRInstruction {
-        @Opcode private final AMD64Arithmetic opcode;
-        @Def protected Value result;
-        @Use protected Value x;
-        @Alive protected Value y;
-        @Temp protected Value temp;
-        @State protected LIRFrameState state;
-
-        public DivOp(AMD64Arithmetic opcode, Value result, Value x, Value y, LIRFrameState state) {
-            this.opcode = opcode;
-            this.result = result;
-            this.x = x;
-            this.y = y;
-            this.temp = asRegister(result) == AMD64.rax ? AMD64.rdx.asValue(result.getKind()) : AMD64.rax.asValue(result.getKind());
-            this.state = state;
-        }
-
-        @Override
-        public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-            emit(tasm, masm, opcode, result, y, state);
-        }
-
-        @Override
-        protected void verify() {
-            super.verify();
-            // left input in rax, right input in any register but rax and rdx, result quotient in rax, result remainder in rdx
-            assert asRegister(x) == AMD64.rax;
-            assert differentRegisters(y, AMD64.rax.asValue(), AMD64.rdx.asValue());
-            assert (name().endsWith("DIV") && asRegister(result) == AMD64.rax) || (name().endsWith("REM") && asRegister(result) == AMD64.rdx);
-            verifyKind(opcode, result, x, y);
-        }
-    }
-
 
     @SuppressWarnings("unused")
     protected static void emit(TargetMethodAssembler tasm, AMD64MacroAssembler masm, AMD64Arithmetic opcode, AllocatableValue result) {