Remove boilerplate code (unaryOp methods in Compiler)

This commit is contained in:
Joshua Warner 2013-12-18 16:43:15 -07:00
parent 07d0f1172f
commit bd7b66a898
4 changed files with 22 additions and 48 deletions

View File

@ -131,12 +131,8 @@ class Compiler {
virtual void exit(Operand* address) = 0; virtual void exit(Operand* address) = 0;
virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0; virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0;
virtual Operand* neg(unsigned size, Operand* a) = 0;
virtual Operand* fneg(unsigned size, Operand* a) = 0;
virtual Operand* abs(unsigned size, Operand* a) = 0;
virtual Operand* fabs(unsigned size, Operand* a) = 0;
virtual Operand* fsqrt(unsigned size, Operand* a) = 0;
virtual Operand* f2f(unsigned aSize, unsigned resSize, Operand* a) = 0; virtual Operand* f2f(unsigned aSize, unsigned resSize, Operand* a) = 0;
virtual Operand* f2i(unsigned aSize, unsigned resSize, Operand* a) = 0; virtual Operand* f2i(unsigned aSize, unsigned resSize, Operand* a) = 0;
virtual Operand* i2f(unsigned aSize, unsigned resSize, Operand* a) = 0; virtual Operand* i2f(unsigned aSize, unsigned resSize, Operand* a) = 0;

View File

@ -99,7 +99,6 @@ const unsigned OperandTypeCount = MemoryOperand + 1;
const int NoRegister = -1; const int NoRegister = -1;
inline bool isBranch(lir::TernaryOperation op) { inline bool isBranch(lir::TernaryOperation op) {
return op > FloatMin; return op > FloatMin;
} }
@ -120,6 +119,14 @@ inline bool isFloatBinaryOp(lir::TernaryOperation op) {
return op >= FloatAdd && op <= FloatMin; return op >= FloatAdd && op <= FloatMin;
} }
inline bool isGeneralUnaryOp(lir::BinaryOperation op) {
return op == Negate || op == Absolute;
}
inline bool isFloatUnaryOp(lir::BinaryOperation op) {
return op == FloatNegate || op == FloatSquareRoot || op == FloatAbsolute;
}
class Operand { }; class Operand { };
class Constant: public Operand { class Constant: public Operand {

View File

@ -2623,40 +2623,11 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* neg(unsigned size, Operand* a) { virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) {
assert(&c, static_cast<Value*>(a)->type == lir::ValueGeneral); assert(&c, (isGeneralUnaryOp(type) and isGeneralValue(a))or(
Value* result = value(&c, lir::ValueGeneral); isFloatUnaryOp(type) and isFloatValue(a)));
appendTranslate(&c, lir::Negate, size, static_cast<Value*>(a), size, result); Value* result = value(&c, static_cast<Value*>(a)->type);
return result; appendTranslate(&c, type, size, static_cast<Value*>(a), size, result);
}
virtual Operand* fneg(unsigned size, Operand* a) {
assert(&c, static_cast<Value*>(a)->type == lir::ValueFloat);
Value* result = value(&c, lir::ValueFloat);
appendTranslate(&c, lir::FloatNegate, size, static_cast<Value*>(a), size, result);
return result;
}
virtual Operand* abs(unsigned size, Operand* a) {
assert(&c, static_cast<Value*>(a)->type == lir::ValueGeneral);
Value* result = value(&c, lir::ValueGeneral);
appendTranslate(&c, lir::Absolute, size, static_cast<Value*>(a), size, result);
return result;
}
virtual Operand* fabs(unsigned size, Operand* a) {
assert(&c, static_cast<Value*>(a)->type == lir::ValueFloat);
Value* result = value(&c, lir::ValueFloat);
appendTranslate
(&c, lir::FloatAbsolute, size, static_cast<Value*>(a), size, result);
return result;
}
virtual Operand* fsqrt(unsigned size, Operand* a) {
assert(&c, static_cast<Value*>(a)->type == lir::ValueFloat);
Value* result = value(&c, lir::ValueFloat);
appendTranslate
(&c, lir::FloatSquareRoot, size, static_cast<Value*>(a), size, result);
return result; return result;
} }

View File

@ -3954,17 +3954,17 @@ intrinsic(MyThread* t, Frame* frame, object target)
if (MATCH(methodName(t, target), "sqrt") if (MATCH(methodName(t, target), "sqrt")
and MATCH(methodSpec(t, target), "(D)D")) and MATCH(methodSpec(t, target), "(D)D"))
{ {
frame->pushLong(c->fsqrt(8, frame->popLong())); frame->pushLong(c->unaryOp(lir::FloatSquareRoot, 8, frame->popLong()));
return true; return true;
} else if (MATCH(methodName(t, target), "abs")) { } else if (MATCH(methodName(t, target), "abs")) {
if (MATCH(methodSpec(t, target), "(I)I")) { if (MATCH(methodSpec(t, target), "(I)I")) {
frame->pushInt(c->abs(4, frame->popInt())); frame->pushInt(c->unaryOp(lir::Absolute, 4, frame->popInt()));
return true; return true;
} else if (MATCH(methodSpec(t, target), "(J)J")) { } else if (MATCH(methodSpec(t, target), "(J)J")) {
frame->pushLong(c->abs(8, frame->popLong())); frame->pushLong(c->unaryOp(lir::Absolute, 8, frame->popLong()));
return true; return true;
} else if (MATCH(methodSpec(t, target), "(F)F")) { } else if (MATCH(methodSpec(t, target), "(F)F")) {
frame->pushInt(c->fabs(4, frame->popInt())); frame->pushInt(c->unaryOp(lir::FloatAbsolute, 4, frame->popInt()));
return true; return true;
} }
} }
@ -4649,7 +4649,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case dneg: { case dneg: {
frame->pushLong(c->fneg(8, frame->popLong())); frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong()));
} break; } break;
case vm::drem: { case vm::drem: {
@ -4766,7 +4766,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case fneg: { case fneg: {
frame->pushInt(c->fneg(4, frame->popInt())); frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt()));
} break; } break;
case vm::frem: { case vm::frem: {
@ -5238,7 +5238,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case ineg: { case ineg: {
frame->pushInt(c->neg(4, frame->popInt())); frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt()));
} break; } break;
case instanceof: { case instanceof: {
@ -5740,7 +5740,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case lneg: case lneg:
frame->pushLong(c->neg(8, frame->popLong())); frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong()));
break; break;
case lookupswitch: { case lookupswitch: {