Bug 679804 - Move relational ops to jsinterpinlines. r=dvander
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 27 Jan 2012 15:36:26 +0100
changeset 86819 108db1fb550125a5bc65f6b9edd9c513294df3a5
parent 86818 e2235de2b8e60ae40e12cb05aa6dd8ae1fb186d5
child 86820 7a0a7c36def8a15fce297af412bf1e57a4aaaee1
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs679804
milestone12.0a1
Bug 679804 - Move relational ops to jsinterpinlines. r=dvander
js/src/jsinterp.cpp
js/src/jsinterpinlines.h
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -2296,65 +2296,68 @@ BEGIN_CASE(JSOP_CASE)
         len = GET_JUMP_OFFSET(regs.pc);
         BRANCH(len);
     }
 }
 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;                                                         \
         if (!ToInt32(cx, regs.sp[-2], &i))                                    \
             goto error;                                                       \
         if (!ToInt32(cx, regs.sp[-1], &j))                                    \
             goto error;                                                       \
         i = i OP (j & 31);                                                    \
--- a/js/src/jsinterpinlines.h
+++ b/js/src/jsinterpinlines.h
@@ -767,11 +767,61 @@ SetObjectElementOperation(JSContext *cx,
             }
         }
     } while (0);
 
     Value tmp = value;
     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__ */