From 07d0f1172fe401d8f642b7c97facb4952d3647cc Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 18 Dec 2013 15:22:38 -0700 Subject: [PATCH] Remove boilerplate code (float binaryOp methods in Compiler) --- include/avian/vm/codegen/compiler.h | 6 ---- include/avian/vm/codegen/lir.h | 2 +- src/codegen/compiler.cpp | 48 ----------------------------- src/compile.cpp | 20 ++++++------ 4 files changed, 11 insertions(+), 65 deletions(-) diff --git a/include/avian/vm/codegen/compiler.h b/include/avian/vm/codegen/compiler.h index ab55c0b52d..271661d19a 100644 --- a/include/avian/vm/codegen/compiler.h +++ b/include/avian/vm/codegen/compiler.h @@ -132,12 +132,6 @@ class Compiler { virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* fadd(unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* fsub(unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* fmul(unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* fdiv(unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* frem(unsigned size, Operand* a, Operand* b) = 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; diff --git a/include/avian/vm/codegen/lir.h b/include/avian/vm/codegen/lir.h index 18816b272b..3b6b835c3e 100644 --- a/include/avian/vm/codegen/lir.h +++ b/include/avian/vm/codegen/lir.h @@ -117,7 +117,7 @@ inline bool isGeneralBinaryOp(lir::TernaryOperation op) { } inline bool isFloatBinaryOp(lir::TernaryOperation op) { - return op > FloatAdd && op <= FloatMin; + return op >= FloatAdd && op <= FloatMin; } class Operand { }; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 327d7d27ac..2e698f753f 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2623,54 +2623,6 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* fadd(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == lir::ValueFloat - and static_cast(b)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueFloat); - static_cast(a)->type = static_cast(b)->type = lir::ValueFloat; - appendCombine(&c, lir::FloatAdd, size, static_cast(a), - size, static_cast(b), size, result); - return result; - } - - virtual Operand* fsub(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == lir::ValueFloat - and static_cast(b)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueFloat); - static_cast(a)->type = static_cast(b)->type = lir::ValueFloat; - appendCombine(&c, lir::FloatSubtract, size, static_cast(a), - size, static_cast(b), size, result); - return result; - } - - virtual Operand* fmul(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == lir::ValueFloat - and static_cast(b)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueFloat); - static_cast(a)->type = static_cast(b)->type = lir::ValueFloat; - appendCombine(&c, lir::FloatMultiply, size, static_cast(a), - size, static_cast(b), size, result); - return result; - } - - virtual Operand* fdiv(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == lir::ValueFloat - and static_cast(b)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueFloat); - appendCombine(&c, lir::FloatDivide, size, static_cast(a), - size, static_cast(b), size, result); - return result; - } - - virtual Operand* frem(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == lir::ValueFloat - and static_cast(b)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueFloat); - appendCombine(&c, lir::FloatRemainder, size, static_cast(a), - size, static_cast(b), size, result); - return result; - } - virtual Operand* neg(unsigned size, Operand* a) { assert(&c, static_cast(a)->type == lir::ValueGeneral); Value* result = value(&c, lir::ValueGeneral); diff --git a/src/compile.cpp b/src/compile.cpp index 95c5f73e64..eea2526db6 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4589,7 +4589,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->fadd(8, a, b)); + frame->pushLong(c->binaryOp(lir::FloatAdd, 8, a, b)); } break; case dcmpg: { @@ -4638,14 +4638,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->fdiv(8, a, b)); + frame->pushLong(c->binaryOp(lir::FloatDivide, 8, a, b)); } break; case dmul: { Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->fmul(8, a, b)); + frame->pushLong(c->binaryOp(lir::FloatMultiply, 8, a, b)); } break; case dneg: { @@ -4656,14 +4656,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->frem(8, a, b)); + frame->pushLong(c->binaryOp(lir::FloatRemainder, 8, a, b)); } break; case dsub: { Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->fsub(8, a, b)); + frame->pushLong(c->binaryOp(lir::FloatSubtract, 8, a, b)); } break; case dup: @@ -4706,7 +4706,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->fadd(4, a, b)); + frame->pushInt(c->binaryOp(lir::FloatAdd, 4, a, b)); } break; case fcmpg: { @@ -4755,14 +4755,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->fdiv(4, a, b)); + frame->pushInt(c->binaryOp(lir::FloatDivide, 4, a, b)); } break; case fmul: { Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->fmul(4, a, b)); + frame->pushInt(c->binaryOp(lir::FloatMultiply, 4, a, b)); } break; case fneg: { @@ -4773,14 +4773,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->frem(4, a, b)); + frame->pushInt(c->binaryOp(lir::FloatRemainder, 4, a, b)); } break; case fsub: { Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->fsub(4, a, b)); + frame->pushInt(c->binaryOp(lir::FloatSubtract, 4, a, b)); } break; case getfield: