[JAEGER] Added JSOP_ADD,SUB,MUL,DIV,MOD.

This commit is contained in:
David Anderson
2010-06-04 19:31:46 -07:00
parent d584e5fc77
commit aa425f1920
4 changed files with 262 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
#include "MethodJIT.h"
#include "jsnum.h"
#include "jsbool.h"
#include "jslibmath.h"
#include "Compiler.h"
#include "StubCalls.h"
#include "assembler/jit/ExecutableAllocator.h"
@@ -453,6 +454,26 @@ mjit::Compiler::generateMethod()
jsop_bitop(op);
END_CASE(JSOP_RSH)
BEGIN_CASE(JSOP_ADD)
jsop_binary(op, stubs::Add);
END_CASE(JSOP_ADD)
BEGIN_CASE(JSOP_SUB)
jsop_binary(op, stubs::Sub);
END_CASE(JSOP_SUB)
BEGIN_CASE(JSOP_MUL)
jsop_binary(op, stubs::Mul);
END_CASE(JSOP_MUL)
BEGIN_CASE(JSOP_DIV)
jsop_binary(op, stubs::Div);
END_CASE(JSOP_DIV)
BEGIN_CASE(JSOP_MOD)
jsop_binary(op, stubs::Mod);
END_CASE(JSOP_MOD)
BEGIN_CASE(JSOP_VOID)
frame.pop();
frame.push(UndefinedTag());
@@ -867,3 +888,72 @@ mjit::Compiler::emitStubCmpOp(BoolStub stub, jsbytecode *target, JSOp fused)
}
}
void
mjit::Compiler::jsop_binary(JSOp op, VoidStub stub)
{
FrameEntry *rhs = frame.peek(-1);
FrameEntry *lhs = frame.peek(-2);
if (lhs->isConstant() && rhs->isConstant()) {
const Value &L = lhs->getValue();
const Value &R = rhs->getValue();
if ((L.isPrimitive() && R.isPrimitive()) &&
(op != JSOP_ADD || (!L.isString() && !R.isString())))
{
/* Constant fold. */
double dL, dR;
ValueToNumber(cx, L, &dL);
ValueToNumber(cx, R, &dR);
switch (op) {
case JSOP_ADD:
dL += dR;
break;
case JSOP_SUB:
dL -= dR;
break;
case JSOP_MUL:
dL *= dR;
break;
case JSOP_DIV:
if (dR == 0) {
#ifdef XP_WIN
if (JSDOUBLE_IS_NaN(dR))
dL = js_NaN;
else
#endif
if (dL == 0 || JSDOUBLE_IS_NaN(dL))
dL = js_NaN;
else if (JSDOUBLE_IS_NEG(dL) != JSDOUBLE_IS_NEG(dR))
dL = cx->runtime->negativeInfinityValue.asDouble();
else
dL = cx->runtime->positiveInfinityValue.asDouble();
} else {
dL /= dR;
}
break;
case JSOP_MOD:
if (dL == 0)
dL = js_NaN;
else
dL = js_fmod(dR, dL);
break;
default:
JS_NOT_REACHED("NYI");
break;
}
frame.popn(2);
Value v;
v.setNumber(dL);
frame.push(v);
return;
}
}
/* Can't constant fold, slow paths. */
prepareStubCall();
stubCall(stub, Uses(2), Defs(1));
frame.popn(2);
frame.pushSynced();
}