Bug 1134638: 16. Use more macros; r=nbp
authorBenjamin Bouvier <benj@benj.me>
Thu, 26 Feb 2015 16:47:04 +0100
changeset 231307 97ce84348766d1addd08238e60b75dfbb8b702e9
parent 231306 8db64625dd3abacc297f5b4b0516603c9bbdec26
child 231308 c4ec1a14df2dfe9839c7c5855dd9aab595326724
push id28348
push userkwierso@gmail.com
push dateMon, 02 Mar 2015 20:13:43 +0000
treeherdermozilla-central@abb7f0d180da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1134638
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1134638: 16. Use more macros; r=nbp
js/src/asmjs/AsmJSValidate.cpp
js/src/builtin/SIMD.h
js/src/jit-test/lib/simd.js
js/src/jit/BaselineIC.cpp
js/src/jit/MCallOptimize.cpp
js/src/jit/MIR.h
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -5858,17 +5858,17 @@ CheckSimdOperationCall(FunctionCompiler 
     switch (global->simdOperation()) {
       case AsmJSSimdOperation_check:
         return CheckSimdCheck(f, call, opType, def, type);
 
 #define OP_CHECK_CASE_LIST_(OP)                                                         \
       case AsmJSSimdOperation_##OP:                                                     \
         return CheckSimdBinary(f, call, opType, MSimdBinaryArith::Op_##OP, def, type);
       ARITH_COMMONX4_SIMD_OP(OP_CHECK_CASE_LIST_)
-      ARITH_FLOAT32X4_SIMD_OP(OP_CHECK_CASE_LIST_)
+      BINARY_ARITH_FLOAT32X4_SIMD_OP(OP_CHECK_CASE_LIST_)
 #undef OP_CHECK_CASE_LIST_
 
       case AsmJSSimdOperation_lessThan:
         return CheckSimdBinary(f, call, opType, MSimdBinaryComp::lessThan, def, type);
       case AsmJSSimdOperation_lessThanOrEqual:
         return CheckSimdBinary(f, call, opType, MSimdBinaryComp::lessThanOrEqual, def, type);
       case AsmJSSimdOperation_equal:
         return CheckSimdBinary(f, call, opType, MSimdBinaryComp::equal, def, type);
--- a/js/src/builtin/SIMD.h
+++ b/js/src/builtin/SIMD.h
@@ -182,68 +182,75 @@
 
 #define INT32X4_FUNCTION_LIST(V)                                                    \
   INT32X4_UNARY_FUNCTION_LIST(V)                                                    \
   INT32X4_BINARY_FUNCTION_LIST(V)                                                   \
   INT32X4_TERNARY_FUNCTION_LIST(V)                                                  \
   INT32X4_QUARTERNARY_FUNCTION_LIST(V)                                              \
   INT32X4_SHUFFLE_FUNCTION_LIST(V)
 
+#define CONVERSION_INT32X4_SIMD_OP(_) \
+    _(fromFloat32x4)                  \
+    _(fromFloat32x4Bits)
 #define FOREACH_INT32X4_SIMD_OP(_)   \
-    _(fromFloat32x4)                 \
-    _(fromFloat32x4Bits)             \
+    CONVERSION_INT32X4_SIMD_OP(_)    \
     _(shiftLeftByScalar)             \
     _(shiftRightArithmeticByScalar)  \
     _(shiftRightLogicalByScalar)
-#define ARITH_FLOAT32X4_SIMD_OP(_)   \
+#define UNARY_ARITH_FLOAT32X4_SIMD_OP(_) \
+    _(abs)                           \
+    _(sqrt)                          \
+    _(reciprocal)                    \
+    _(reciprocalSqrt)
+#define BINARY_ARITH_FLOAT32X4_SIMD_OP(_) \
     _(div)                           \
     _(max)                           \
     _(min)                           \
     _(maxNum)                        \
     _(minNum)
 #define FOREACH_FLOAT32X4_SIMD_OP(_) \
-    ARITH_FLOAT32X4_SIMD_OP(_)       \
-    _(abs)                           \
-    _(sqrt)                          \
-    _(reciprocal)                    \
-    _(reciprocalSqrt)                \
+    UNARY_ARITH_FLOAT32X4_SIMD_OP(_) \
+    BINARY_ARITH_FLOAT32X4_SIMD_OP(_)\
     _(fromInt32x4)                   \
     _(fromInt32x4Bits)
 #define ARITH_COMMONX4_SIMD_OP(_)    \
     _(add)                           \
     _(sub)                           \
     _(mul)
 #define BITWISE_COMMONX4_SIMD_OP(_)  \
     _(and)                           \
     _(or)                            \
     _(xor)
-#define COMP_COMMONX4_SIMD_OP(_)     \
+#define COMP_COMMONX4_TO_INT32X4_SIMD_OP(_) \
     _(lessThan)                      \
     _(lessThanOrEqual)               \
     _(equal)                         \
     _(notEqual)                      \
     _(greaterThan)                   \
     _(greaterThanOrEqual)
 #define WITH_COMMONX4_SIMD_OP(_)     \
     _(withX)                         \
     _(withY)                         \
     _(withZ)                         \
     _(withW)
-#define FOREACH_COMMONX4_SIMD_OP(_)  \
+// TODO: remove when all SIMD calls are inlined (bug 1112155)
+#define ION_COMMONX4_SIMD_OP(_)      \
     ARITH_COMMONX4_SIMD_OP(_)        \
     BITWISE_COMMONX4_SIMD_OP(_)      \
-    COMP_COMMONX4_SIMD_OP(_)         \
     WITH_COMMONX4_SIMD_OP(_)         \
     _(bitselect)                     \
     _(select)                        \
+    _(splat)                         \
+    _(not)                           \
+    _(neg)
+#define FOREACH_COMMONX4_SIMD_OP(_)  \
+    ION_COMMONX4_SIMD_OP(_)          \
+    COMP_COMMONX4_TO_INT32X4_SIMD_OP(_) \
     _(swizzle)                       \
     _(shuffle)                       \
-    _(splat)                         \
-    _(not)                           \
-    _(neg)                           \
     _(load)                          \
     _(loadX)                         \
     _(loadXY)                        \
     _(loadXYZ)                       \
     _(store)                         \
     _(storeX)                        \
     _(storeXY)                       \
     _(storeXYZ)                      \
--- a/js/src/jit-test/lib/simd.js
+++ b/js/src/jit-test/lib/simd.js
@@ -1,8 +1,11 @@
+if (!this.hasOwnProperty("SIMD"))
+    quit();
+
 function binaryX4(op, v, w) {
     var arr = [];
     var [varr, warr] = [simdToArray(v), simdToArray(w)];
     [varr, warr] = [varr.map(Math.fround), warr.map(Math.fround)];
     for (var i = 0; i < 4; i++)
         arr[i] = op(varr[i], warr[i]);
     return arr.map(Math.fround);
 }
--- a/js/src/jit/BaselineIC.cpp
+++ b/js/src/jit/BaselineIC.cpp
@@ -9224,41 +9224,28 @@ GetTemplateObjectForNative(JSContext *cx
         res.set(ObjectCreateImpl(cx, proto, TenuredObject));
         return !!res;
     }
 
     if (JitSupportsSimd()) {
 #define ADD_INT32X4_SIMD_OP_NAME_(OP) || native == js::simd_int32x4_##OP
 #define ADD_FLOAT32X4_SIMD_OP_NAME_(OP) || native == js::simd_float32x4_##OP
        if (false
-           ARITH_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)
-           BITWISE_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)
-           COMP_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)
-           COMP_COMMONX4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
-           WITH_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)
-           || native == js::simd_int32x4_not || native == js::simd_int32x4_neg
-           || native == js::simd_int32x4_fromFloat32x4 || native == js::simd_int32x4_fromFloat32x4Bits
-           || native == js::simd_int32x4_select || native == js::simd_int32x4_bitselect
-           || native == js::simd_int32x4_splat)
+           ION_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)
+           COMP_COMMONX4_TO_INT32X4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)
+           COMP_COMMONX4_TO_INT32X4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
+           CONVERSION_INT32X4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_))
        {
             Rooted<SimdTypeDescr *> descr(cx, &cx->global()->int32x4TypeDescr().as<SimdTypeDescr>());
             res.set(cx->compartment()->jitCompartment()->getSimdTemplateObjectFor(cx, descr));
             return !!res;
        }
        if (false
-           ARITH_COMMONX4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
-           ARITH_FLOAT32X4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
-           BITWISE_COMMONX4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
-           WITH_COMMONX4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
-           || native == js::simd_float32x4_abs || native == js::simd_float32x4_sqrt
-           || native == js::simd_float32x4_reciprocal || native == js::simd_float32x4_reciprocalSqrt
-           || native == js::simd_float32x4_not || native == js::simd_float32x4_neg
-           || native == js::simd_float32x4_fromInt32x4 || native == js::simd_float32x4_fromInt32x4Bits
-           || native == js::simd_float32x4_select || native == js::simd_float32x4_bitselect
-           || native == js::simd_float32x4_splat)
+           FOREACH_FLOAT32X4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_)
+           ION_COMMONX4_SIMD_OP(ADD_FLOAT32X4_SIMD_OP_NAME_))
        {
             Rooted<SimdTypeDescr *> descr(cx, &cx->global()->float32x4TypeDescr().as<SimdTypeDescr>());
             res.set(cx->compartment()->jitCompartment()->getSimdTemplateObjectFor(cx, descr));
             return !!res;
        }
 #undef ADD_INT32X4_SIMD_OP_NAME_
 #undef ADD_FLOAT32X4_SIMD_OP_NAME_
     }
--- a/js/src/jit/MCallOptimize.cpp
+++ b/js/src/jit/MCallOptimize.cpp
@@ -252,77 +252,79 @@ IonBuilder::inlineNativeCall(CallInfo &c
     if (native == testingFunc_assertFloat32)
         return inlineAssertFloat32(callInfo);
 
     // Bound function
     if (native == js::CallOrConstructBoundFunction)
         return inlineBoundFunction(callInfo, target);
 
     // Simd functions
+#define INLINE_FLOAT32X4_SIMD_ARITH_(OP)                                                         \
+    if (native == js::simd_float32x4_##OP)                                                       \
+        return inlineBinarySimd<MSimdBinaryArith>(callInfo, native, MSimdBinaryArith::Op_##OP,   \
+                                                  SimdTypeDescr::TYPE_FLOAT32);
+
 #define INLINE_INT32X4_SIMD_ARITH_(OP)                                                           \
     if (native == js::simd_int32x4_##OP)                                                         \
         return inlineBinarySimd<MSimdBinaryArith>(callInfo, native, MSimdBinaryArith::Op_##OP,   \
                                                   SimdTypeDescr::TYPE_INT32);
+
     ARITH_COMMONX4_SIMD_OP(INLINE_INT32X4_SIMD_ARITH_)
-#undef INLINE_INT32X4_SIMD_ARITH_
-
-#define INLINE_FLOAT32X4_SIMD_ARITH_(OP)                                                         \
-    if (native == js::simd_float32x4_##OP)                                                       \
-        return inlineBinarySimd<MSimdBinaryArith>(callInfo, native, MSimdBinaryArith::Op_##OP,   \
-                                                  SimdTypeDescr::TYPE_FLOAT32);
     ARITH_COMMONX4_SIMD_OP(INLINE_FLOAT32X4_SIMD_ARITH_)
-    ARITH_FLOAT32X4_SIMD_OP(INLINE_FLOAT32X4_SIMD_ARITH_)
+    BINARY_ARITH_FLOAT32X4_SIMD_OP(INLINE_FLOAT32X4_SIMD_ARITH_)
+#undef INLINE_SIMD_ARITH_
 #undef INLINE_FLOAT32X4_SIMD_ARITH_
 
 #define INLINE_SIMD_BITWISE_(OP)                                                                 \
     if (native == js::simd_int32x4_##OP)                                                         \
         return inlineBinarySimd<MSimdBinaryBitwise>(callInfo, native, MSimdBinaryBitwise::OP##_, \
                                                     SimdTypeDescr::TYPE_INT32);                  \
     if (native == js::simd_float32x4_##OP)                                                       \
         return inlineBinarySimd<MSimdBinaryBitwise>(callInfo, native, MSimdBinaryBitwise::OP##_, \
                                                     SimdTypeDescr::TYPE_FLOAT32);
+
     BITWISE_COMMONX4_SIMD_OP(INLINE_SIMD_BITWISE_)
 #undef INLINE_SIMD_BITWISE_
 
 #define INLINE_SIMD_COMPARISON_(OP)                                                                \
     if (native == js::simd_int32x4_##OP)                                                           \
         return inlineCompSimd(callInfo, native, MSimdBinaryComp::OP, SimdTypeDescr::TYPE_INT32);   \
     if (native == js::simd_float32x4_##OP)                                                         \
         return inlineCompSimd(callInfo, native, MSimdBinaryComp::OP, SimdTypeDescr::TYPE_FLOAT32);
-    COMP_COMMONX4_SIMD_OP(INLINE_SIMD_COMPARISON_)
+
+    COMP_COMMONX4_TO_INT32X4_SIMD_OP(INLINE_SIMD_COMPARISON_)
 #undef INLINE_SIMD_COMPARISON_
 
 #define INLINE_SIMD_SETTER_(LANE)                                                                   \
     if (native == js::simd_int32x4_with##LANE)                                                      \
         return inlineSimdWith(callInfo, native, SimdLane::Lane##LANE, SimdTypeDescr::TYPE_INT32);   \
     if (native == js::simd_float32x4_with##LANE)                                                    \
         return inlineSimdWith(callInfo, native, SimdLane::Lane##LANE, SimdTypeDescr::TYPE_FLOAT32);
+
     INLINE_SIMD_SETTER_(X)
     INLINE_SIMD_SETTER_(Y)
     INLINE_SIMD_SETTER_(Z)
     INLINE_SIMD_SETTER_(W)
 #undef INLINE_SIMD_SETTER_
 
     if (native == js::simd_int32x4_not)
         return inlineUnarySimd(callInfo, native, MSimdUnaryArith::not_, SimdTypeDescr::TYPE_INT32);
     if (native == js::simd_int32x4_neg)
         return inlineUnarySimd(callInfo, native, MSimdUnaryArith::neg, SimdTypeDescr::TYPE_INT32);
 
+#define INLINE_SIMD_FLOAT32X4_UNARY_(OP)                                                           \
+    if (native == js::simd_float32x4_##OP)                                                         \
+        return inlineUnarySimd(callInfo, native, MSimdUnaryArith::OP, SimdTypeDescr::TYPE_FLOAT32);
+
+    UNARY_ARITH_FLOAT32X4_SIMD_OP(INLINE_SIMD_FLOAT32X4_UNARY_)
+    INLINE_SIMD_FLOAT32X4_UNARY_(neg)
+#undef INLINE_SIMD_FLOAT32X4_UNARY_
+
     if (native == js::simd_float32x4_not)
         return inlineUnarySimd(callInfo, native, MSimdUnaryArith::not_, SimdTypeDescr::TYPE_FLOAT32);
-    if (native == js::simd_float32x4_neg)
-        return inlineUnarySimd(callInfo, native, MSimdUnaryArith::neg, SimdTypeDescr::TYPE_FLOAT32);
-    if (native == js::simd_float32x4_abs)
-        return inlineUnarySimd(callInfo, native, MSimdUnaryArith::abs, SimdTypeDescr::TYPE_FLOAT32);
-    if (native == js::simd_float32x4_sqrt)
-        return inlineUnarySimd(callInfo, native, MSimdUnaryArith::sqrt, SimdTypeDescr::TYPE_FLOAT32);
-    if (native == js::simd_float32x4_reciprocal)
-        return inlineUnarySimd(callInfo, native, MSimdUnaryArith::reciprocal, SimdTypeDescr::TYPE_FLOAT32);
-    if (native == js::simd_float32x4_reciprocalSqrt)
-        return inlineUnarySimd(callInfo, native, MSimdUnaryArith::reciprocalSqrt, SimdTypeDescr::TYPE_FLOAT32);
 
     typedef bool IsCast;
     if (native == js::simd_float32x4_fromInt32x4)
         return inlineSimdConvert(callInfo, native, IsCast(false), SimdTypeDescr::TYPE_INT32, SimdTypeDescr::TYPE_FLOAT32);
     if (native == js::simd_int32x4_fromFloat32x4)
         return inlineSimdConvert(callInfo, native, IsCast(false), SimdTypeDescr::TYPE_FLOAT32, SimdTypeDescr::TYPE_INT32);
     if (native == js::simd_float32x4_fromInt32x4Bits)
         return inlineSimdConvert(callInfo, native, IsCast(true), SimdTypeDescr::TYPE_INT32, SimdTypeDescr::TYPE_FLOAT32);
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -1893,22 +1893,21 @@ class MSimdShuffle
 };
 
 class MSimdUnaryArith
   : public MUnaryInstruction,
     public SimdSameAsReturnedTypePolicy<0>::Data
 {
   public:
     enum Operation {
-        abs,
+#define OP_LIST_(OP) OP,
+        UNARY_ARITH_FLOAT32X4_SIMD_OP(OP_LIST_)
         neg,
-        not_,
-        reciprocal,
-        reciprocalSqrt,
-        sqrt
+        not_
+#undef OP_LIST_
     };
 
     static const char* OperationName(Operation op) {
         switch (op) {
           case abs:            return "abs";
           case neg:            return "neg";
           case not_:           return "not";
           case reciprocal:     return "reciprocal";
@@ -1965,24 +1964,24 @@ class MSimdUnaryArith
 // the comparison: all bits are set to 1 if the comparison is true, 0 otherwise.
 class MSimdBinaryComp
   : public MBinaryInstruction,
     public SimdAllPolicy::Data
 {
   public:
     enum Operation {
 #define NAME_(x) x,
-        COMP_COMMONX4_SIMD_OP(NAME_)
+        COMP_COMMONX4_TO_INT32X4_SIMD_OP(NAME_)
 #undef NAME_
     };
 
     static const char* OperationName(Operation op) {
         switch (op) {
 #define NAME_(x) case x: return #x;
-        COMP_COMMONX4_SIMD_OP(NAME_)
+        COMP_COMMONX4_TO_INT32X4_SIMD_OP(NAME_)
 #undef NAME_
         }
         MOZ_CRASH("unexpected operation");
     }
 
   private:
     Operation operation_;
 
@@ -2050,25 +2049,25 @@ class MSimdBinaryComp
 class MSimdBinaryArith
   : public MBinaryInstruction,
     public MixPolicy<SimdSameAsReturnedTypePolicy<0>, SimdSameAsReturnedTypePolicy<1> >::Data
 {
   public:
     enum Operation {
 #define OP_LIST_(OP) Op_##OP,
         ARITH_COMMONX4_SIMD_OP(OP_LIST_)
-        ARITH_FLOAT32X4_SIMD_OP(OP_LIST_)
+        BINARY_ARITH_FLOAT32X4_SIMD_OP(OP_LIST_)
 #undef OP_LIST_
     };
 
     static const char* OperationName(Operation op) {
         switch (op) {
 #define OP_CASE_LIST_(OP) case Op_##OP: return #OP;
           ARITH_COMMONX4_SIMD_OP(OP_CASE_LIST_)
-          ARITH_FLOAT32X4_SIMD_OP(OP_CASE_LIST_)
+          BINARY_ARITH_FLOAT32X4_SIMD_OP(OP_CASE_LIST_)
 #undef OP_CASE_LIST_
         }
         MOZ_CRASH("unexpected operation");
     }
 
   private:
     Operation operation_;