зеркало из https://github.com/mozilla/gecko-dev.git
Bug 679804 - Move relational ops to jsinterpinlines. r=dvander
This commit is contained in:
Родитель
fd97a8a392
Коммит
51914517ae
|
@ -2301,55 +2301,58 @@ END_CASE(JSOP_CASE)
|
|||
|
||||
#undef STRICT_EQUALITY_OP
|
||||
|
||||
#define RELATIONAL_OP(OP) \
|
||||
JS_BEGIN_MACRO \
|
||||
Value &rval = regs.sp[-1]; \
|
||||
Value &lval = regs.sp[-2]; \
|
||||
bool cond; \
|
||||
/* Optimize for two int-tagged operands (typical loop control). */ \
|
||||
if (lval.isInt32() && rval.isInt32()) { \
|
||||
cond = lval.toInt32() OP rval.toInt32(); \
|
||||
} else { \
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, &lval)) \
|
||||
goto error; \
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, &rval)) \
|
||||
goto error; \
|
||||
if (lval.isString() && rval.isString()) { \
|
||||
JSString *l = lval.toString(), *r = rval.toString(); \
|
||||
int32_t result; \
|
||||
if (!CompareStrings(cx, l, r, &result)) \
|
||||
goto error; \
|
||||
cond = result OP 0; \
|
||||
} else { \
|
||||
double l, r; \
|
||||
if (!ToNumber(cx, lval, &l) || !ToNumber(cx, rval, &r)) \
|
||||
goto error; \
|
||||
cond = (l OP r); \
|
||||
} \
|
||||
} \
|
||||
TRY_BRANCH_AFTER_COND(cond, 2); \
|
||||
regs.sp[-2].setBoolean(cond); \
|
||||
regs.sp--; \
|
||||
JS_END_MACRO
|
||||
|
||||
BEGIN_CASE(JSOP_LT)
|
||||
RELATIONAL_OP(<);
|
||||
{
|
||||
bool cond;
|
||||
const Value &lref = regs.sp[-2];
|
||||
const Value &rref = regs.sp[-1];
|
||||
if (!LessThanOperation(cx, lref, rref, &cond))
|
||||
goto error;
|
||||
TRY_BRANCH_AFTER_COND(cond, 2);
|
||||
regs.sp[-2].setBoolean(cond);
|
||||
regs.sp--;
|
||||
}
|
||||
END_CASE(JSOP_LT)
|
||||
|
||||
BEGIN_CASE(JSOP_LE)
|
||||
RELATIONAL_OP(<=);
|
||||
{
|
||||
bool cond;
|
||||
const Value &lref = regs.sp[-2];
|
||||
const Value &rref = regs.sp[-1];
|
||||
if (!LessThanOrEqualOperation(cx, lref, rref, &cond))
|
||||
goto error;
|
||||
TRY_BRANCH_AFTER_COND(cond, 2);
|
||||
regs.sp[-2].setBoolean(cond);
|
||||
regs.sp--;
|
||||
}
|
||||
END_CASE(JSOP_LE)
|
||||
|
||||
BEGIN_CASE(JSOP_GT)
|
||||
RELATIONAL_OP(>);
|
||||
{
|
||||
bool cond;
|
||||
const Value &lref = regs.sp[-2];
|
||||
const Value &rref = regs.sp[-1];
|
||||
if (!GreaterThanOperation(cx, lref, rref, &cond))
|
||||
goto error;
|
||||
TRY_BRANCH_AFTER_COND(cond, 2);
|
||||
regs.sp[-2].setBoolean(cond);
|
||||
regs.sp--;
|
||||
}
|
||||
END_CASE(JSOP_GT)
|
||||
|
||||
BEGIN_CASE(JSOP_GE)
|
||||
RELATIONAL_OP(>=);
|
||||
{
|
||||
bool cond;
|
||||
const Value &lref = regs.sp[-2];
|
||||
const Value &rref = regs.sp[-1];
|
||||
if (!GreaterThanOrEqualOperation(cx, lref, rref, &cond))
|
||||
goto error;
|
||||
TRY_BRANCH_AFTER_COND(cond, 2);
|
||||
regs.sp[-2].setBoolean(cond);
|
||||
regs.sp--;
|
||||
}
|
||||
END_CASE(JSOP_GE)
|
||||
|
||||
#undef RELATIONAL_OP
|
||||
|
||||
#define SIGNED_SHIFT_OP(OP) \
|
||||
JS_BEGIN_MACRO \
|
||||
int32_t i, j; \
|
||||
|
|
|
@ -772,6 +772,56 @@ SetObjectElementOperation(JSContext *cx, JSObject *obj, jsid id, const Value &va
|
|||
return obj->setGeneric(cx, id, &tmp, script->strictModeCode);
|
||||
}
|
||||
|
||||
#define RELATIONAL_OP(OP) \
|
||||
JS_BEGIN_MACRO \
|
||||
Value lval = lhs; \
|
||||
Value rval = rhs; \
|
||||
/* Optimize for two int-tagged operands (typical loop control). */ \
|
||||
if (lval.isInt32() && rval.isInt32()) { \
|
||||
*res = lval.toInt32() OP rval.toInt32(); \
|
||||
} else { \
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, &lval)) \
|
||||
return false; \
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, &rval)) \
|
||||
return false; \
|
||||
if (lval.isString() && rval.isString()) { \
|
||||
JSString *l = lval.toString(), *r = rval.toString(); \
|
||||
int32_t result; \
|
||||
if (!CompareStrings(cx, l, r, &result)) \
|
||||
return false; \
|
||||
*res = result OP 0; \
|
||||
} else { \
|
||||
double l, r; \
|
||||
if (!ToNumber(cx, lval, &l) || !ToNumber(cx, rval, &r)) \
|
||||
return false;; \
|
||||
*res = (l OP r); \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
JS_END_MACRO
|
||||
|
||||
static JS_ALWAYS_INLINE bool
|
||||
LessThanOperation(JSContext *cx, const Value &lhs, const Value &rhs, bool *res) {
|
||||
RELATIONAL_OP(<);
|
||||
}
|
||||
|
||||
static JS_ALWAYS_INLINE bool
|
||||
LessThanOrEqualOperation(JSContext *cx, const Value &lhs, const Value &rhs, bool *res) {
|
||||
RELATIONAL_OP(<=);
|
||||
}
|
||||
|
||||
static JS_ALWAYS_INLINE bool
|
||||
GreaterThanOperation(JSContext *cx, const Value &lhs, const Value &rhs, bool *res) {
|
||||
RELATIONAL_OP(>);
|
||||
}
|
||||
|
||||
static JS_ALWAYS_INLINE bool
|
||||
GreaterThanOrEqualOperation(JSContext *cx, const Value &lhs, const Value &rhs, bool *res) {
|
||||
RELATIONAL_OP(>=);
|
||||
}
|
||||
|
||||
#undef RELATIONAL_OP
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
#endif /* jsinterpinlines_h__ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче