Bug 1042244: Instantiate operators template arguments in users; r=nmatsakis
authorBenjamin Bouvier <benj@benj.me>
Mon, 28 Jul 2014 19:27:48 +0200
changeset 196362 e788930eaa26f98b7177cd59808d3c7051c6d28f
parent 196361 b55fe8353becf47b89a565acbfd788fe3a28db3a
child 196363 ba89f7ce6ff2ca8a57dad98b905bc57da8b6cba3
push id46862
push userbenj@benj.me
push dateMon, 28 Jul 2014 17:28:27 +0000
treeherdermozilla-inbound@ba89f7ce6ff2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnmatsakis
bugs1042244
milestone34.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 1042244: Instantiate operators template arguments in users; r=nmatsakis
js/src/builtin/SIMD.cpp
js/src/builtin/SIMD.h
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -572,17 +572,17 @@ static inline bool
 ErrorBadArgs(JSContext *cx)
 {
     JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
     return false;
 }
 
 // Coerces the inputs of type In to the type Coercion, apply the operator Op
 // and converts the result to the type Out.
-template<typename In, typename Coercion, typename Op, typename Out>
+template<typename In, typename Coercion, template<typename C> class Op, typename Out>
 static bool
 CoercedFunc(JSContext *cx, unsigned argc, Value *vp)
 {
     typedef typename Coercion::Elem CoercionElem;
     typedef typename Out::Elem RetElem;
 
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() != 1 && args.length() != 2)
@@ -590,46 +590,46 @@ CoercedFunc(JSContext *cx, unsigned argc
 
     CoercionElem result[Coercion::lanes];
     if (args.length() == 1) {
         if (!IsVectorObject<In>(args[0]))
             return ErrorBadArgs(cx);
 
         CoercionElem *val = TypedObjectMemory<CoercionElem *>(args[0]);
         for (unsigned i = 0; i < Coercion::lanes; i++)
-            result[i] = Op::apply(val[i], 0);
+            result[i] = Op<CoercionElem>::apply(val[i], 0);
     } else {
         JS_ASSERT(args.length() == 2);
         if (!IsVectorObject<In>(args[0]) || !IsVectorObject<In>(args[1]))
             return ErrorBadArgs(cx);
 
         CoercionElem *left = TypedObjectMemory<CoercionElem *>(args[0]);
         CoercionElem *right = TypedObjectMemory<CoercionElem *>(args[1]);
         for (unsigned i = 0; i < Coercion::lanes; i++)
-            result[i] = Op::apply(left[i], right[i]);
+            result[i] = Op<CoercionElem>::apply(left[i], right[i]);
     }
 
     RetElem *coercedResult = reinterpret_cast<RetElem *>(result);
     RootedObject obj(cx, Create<Out>(cx, coercedResult));
     if (!obj)
         return false;
 
     args.rval().setObject(*obj);
     return true;
 }
 
 // Same as above, with Coercion == Out
-template<typename In, typename Op, typename Out>
+template<typename In, template<typename C> class Op, typename Out>
 static bool
 Func(JSContext *cx, unsigned argc, Value *vp)
 {
     return CoercedFunc<In, Out, Op, Out>(cx, argc, vp);
 }
 
-template<typename V, typename OpWith, typename Vret>
+template<typename V, template<typename T> class OpWith, typename Vret>
 static bool
 FuncWith(JSContext *cx, unsigned argc, Value *vp)
 {
     typedef typename V::Elem Elem;
     typedef typename Vret::Elem RetElem;
 
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() != 2 || !IsVectorObject<V>(args[0]) ||
@@ -641,22 +641,22 @@ FuncWith(JSContext *cx, unsigned argc, V
     Elem *val = TypedObjectMemory<Elem *>(args[0]);
     RetElem result[Vret::lanes];
 
     if (args[1].isNumber()) {
         Elem withAsNumber;
         if (!Vret::toType(cx, args[1], &withAsNumber))
             return false;
         for (unsigned i = 0; i < Vret::lanes; i++)
-            result[i] = OpWith::apply(i, withAsNumber, val[i]);
+            result[i] = OpWith<RetElem>::apply(i, withAsNumber, val[i]);
     } else {
         JS_ASSERT(args[1].isBoolean());
         bool withAsBool = args[1].toBoolean();
         for (unsigned i = 0; i < Vret::lanes; i++)
-            result[i] = OpWith::apply(i, withAsBool, val[i]);
+            result[i] = OpWith<RetElem>::apply(i, withAsBool, val[i]);
     }
 
     RootedObject obj(cx, Create<Vret>(cx, result));
     if (!obj)
         return false;
 
     args.rval().setObject(*obj);
     return true;
--- a/js/src/builtin/SIMD.h
+++ b/js/src/builtin/SIMD.h
@@ -13,108 +13,108 @@
 #include "vm/GlobalObject.h"
 
 /*
  * JS SIMD functions.
  * Spec matching polyfill:
  * https://github.com/johnmccutchan/ecmascript_simd/blob/master/src/ecmascript_simd.js
  */
 
-#define FLOAT32X4_NULLARY_FUNCTION_LIST(V)                                                               \
+#define FLOAT32X4_NULLARY_FUNCTION_LIST(V)                                                        \
   V(zero, (FuncZero<Float32x4>), 0, 0, Zero)
 
-#define FLOAT32X4_UNARY_FUNCTION_LIST(V)                                                                 \
-  V(abs, (Func<Float32x4, Abs<float>, Float32x4>), 1, 0, Abs)                                            \
-  V(fromInt32x4Bits, (FuncConvertBits<Int32x4, Float32x4>), 1, 0, FromInt32x4Bits)                       \
-  V(neg, (Func<Float32x4, Neg<float>, Float32x4>), 1, 0, Neg)                                            \
-  V(not, (CoercedFunc<Float32x4, Int32x4, Not<int32_t>, Float32x4>), 1, 0, Not)                          \
-  V(reciprocal, (Func<Float32x4, Rec<float>, Float32x4>), 1, 0, Reciprocal)                              \
-  V(reciprocalSqrt, (Func<Float32x4, RecSqrt<float>, Float32x4>), 1, 0, ReciprocalSqrt)                  \
-  V(splat, (FuncSplat<Float32x4>), 1, 0, Splat)                                                          \
-  V(sqrt, (Func<Float32x4, Sqrt<float>, Float32x4>), 1, 0, Sqrt)                                         \
+#define FLOAT32X4_UNARY_FUNCTION_LIST(V)                                                          \
+  V(abs, (Func<Float32x4, Abs, Float32x4>), 1, 0, Abs)                                            \
+  V(fromInt32x4Bits, (FuncConvertBits<Int32x4, Float32x4>), 1, 0, FromInt32x4Bits)                \
+  V(neg, (Func<Float32x4, Neg, Float32x4>), 1, 0, Neg)                                            \
+  V(not, (CoercedFunc<Float32x4, Int32x4, Not, Float32x4>), 1, 0, Not)                            \
+  V(reciprocal, (Func<Float32x4, Rec, Float32x4>), 1, 0, Reciprocal)                              \
+  V(reciprocalSqrt, (Func<Float32x4, RecSqrt, Float32x4>), 1, 0, ReciprocalSqrt)                  \
+  V(splat, (FuncSplat<Float32x4>), 1, 0, Splat)                                                   \
+  V(sqrt, (Func<Float32x4, Sqrt, Float32x4>), 1, 0, Sqrt)                                         \
   V(fromInt32x4, (FuncConvert<Int32x4, Float32x4> ), 1, 0, FromInt32x4)
 
-#define FLOAT32X4_BINARY_FUNCTION_LIST(V)                                                                \
-  V(add, (Func<Float32x4, Add<float>, Float32x4>), 2, 0, Add)                                            \
-  V(and, (CoercedFunc<Float32x4, Int32x4, And<int32_t>, Float32x4>), 2, 0, And)                          \
-  V(div, (Func<Float32x4, Div<float>, Float32x4>), 2, 0, Div)                                            \
-  V(equal, (Func<Float32x4, Equal<float>, Int32x4>), 2, 0, Equal)                                        \
-  V(greaterThan, (Func<Float32x4, GreaterThan<float>, Int32x4>), 2, 0, GreaterThan)                      \
-  V(greaterThanOrEqual, (Func<Float32x4, GreaterThanOrEqual<float>, Int32x4>), 2, 0, GreaterThanOrEqual) \
-  V(lessThan, (Func<Float32x4, LessThan<float>, Int32x4>), 2, 0, LessThan)                               \
-  V(lessThanOrEqual, (Func<Float32x4, LessThanOrEqual<float>, Int32x4>), 2, 0, LessThanOrEqual)          \
-  V(max, (Func<Float32x4, Maximum<float>, Float32x4>), 2, 0, Max)                                        \
-  V(min, (Func<Float32x4, Minimum<float>, Float32x4>), 2, 0, Min)                                        \
-  V(mul, (Func<Float32x4, Mul<float>, Float32x4>), 2, 0, Mul)                                            \
-  V(notEqual, (Func<Float32x4, NotEqual<float>, Int32x4>), 2, 0, NotEqual)                               \
-  V(shuffle, FuncShuffle<Float32x4>, 2, 0, Shuffle)                                                      \
-  V(or, (CoercedFunc<Float32x4, Int32x4, Or<int32_t>, Float32x4>), 2, 0, Or)                             \
-  V(scale, (FuncWith<Float32x4, Scale<float>, Float32x4>), 2, 0, Scale)                                  \
-  V(sub, (Func<Float32x4, Sub<float>, Float32x4>), 2, 0, Sub)                                            \
-  V(withX, (FuncWith<Float32x4, WithX<float>, Float32x4>), 2, 0, WithX)                                  \
-  V(withY, (FuncWith<Float32x4, WithY<float>, Float32x4>), 2, 0, WithY)                                  \
-  V(withZ, (FuncWith<Float32x4, WithZ<float>, Float32x4>), 2, 0, WithZ)                                  \
-  V(withW, (FuncWith<Float32x4, WithW<float>, Float32x4>), 2, 0, WithW)                                  \
-  V(xor, (CoercedFunc<Float32x4, Int32x4, Xor<int32_t>, Float32x4>), 2, 0, Xor)
+#define FLOAT32X4_BINARY_FUNCTION_LIST(V)                                                         \
+  V(add, (Func<Float32x4, Add, Float32x4>), 2, 0, Add)                                            \
+  V(and, (CoercedFunc<Float32x4, Int32x4, And, Float32x4>), 2, 0, And)                            \
+  V(div, (Func<Float32x4, Div, Float32x4>), 2, 0, Div)                                            \
+  V(equal, (Func<Float32x4, Equal, Int32x4>), 2, 0, Equal)                                        \
+  V(greaterThan, (Func<Float32x4, GreaterThan, Int32x4>), 2, 0, GreaterThan)                      \
+  V(greaterThanOrEqual, (Func<Float32x4, GreaterThanOrEqual, Int32x4>), 2, 0, GreaterThanOrEqual) \
+  V(lessThan, (Func<Float32x4, LessThan, Int32x4>), 2, 0, LessThan)                               \
+  V(lessThanOrEqual, (Func<Float32x4, LessThanOrEqual, Int32x4>), 2, 0, LessThanOrEqual)          \
+  V(max, (Func<Float32x4, Maximum, Float32x4>), 2, 0, Max)                                        \
+  V(min, (Func<Float32x4, Minimum, Float32x4>), 2, 0, Min)                                        \
+  V(mul, (Func<Float32x4, Mul, Float32x4>), 2, 0, Mul)                                            \
+  V(notEqual, (Func<Float32x4, NotEqual, Int32x4>), 2, 0, NotEqual)                               \
+  V(shuffle, FuncShuffle<Float32x4>, 2, 0, Shuffle)                                               \
+  V(or, (CoercedFunc<Float32x4, Int32x4, Or, Float32x4>), 2, 0, Or)                               \
+  V(scale, (FuncWith<Float32x4, Scale, Float32x4>), 2, 0, Scale)                                  \
+  V(sub, (Func<Float32x4, Sub, Float32x4>), 2, 0, Sub)                                            \
+  V(withX, (FuncWith<Float32x4, WithX, Float32x4>), 2, 0, WithX)                                  \
+  V(withY, (FuncWith<Float32x4, WithY, Float32x4>), 2, 0, WithY)                                  \
+  V(withZ, (FuncWith<Float32x4, WithZ, Float32x4>), 2, 0, WithZ)                                  \
+  V(withW, (FuncWith<Float32x4, WithW, Float32x4>), 2, 0, WithW)                                  \
+  V(xor, (CoercedFunc<Float32x4, Int32x4, Xor, Float32x4>), 2, 0, Xor)
 
-#define FLOAT32X4_TERNARY_FUNCTION_LIST(V)                                                               \
-  V(clamp, Float32x4Clamp, 3, 0, Clamp)                                                                  \
+#define FLOAT32X4_TERNARY_FUNCTION_LIST(V)                                                        \
+  V(clamp, Float32x4Clamp, 3, 0, Clamp)                                                           \
   V(shuffleMix, FuncShuffle<Float32x4>, 3, 0, ShuffleMix)
 
-#define FLOAT32X4_FUNCTION_LIST(V)                                                                       \
-  FLOAT32X4_NULLARY_FUNCTION_LIST(V)                                                                     \
-  FLOAT32X4_UNARY_FUNCTION_LIST(V)                                                                       \
-  FLOAT32X4_BINARY_FUNCTION_LIST(V)                                                                      \
+#define FLOAT32X4_FUNCTION_LIST(V)                                                                \
+  FLOAT32X4_NULLARY_FUNCTION_LIST(V)                                                              \
+  FLOAT32X4_UNARY_FUNCTION_LIST(V)                                                                \
+  FLOAT32X4_BINARY_FUNCTION_LIST(V)                                                               \
   FLOAT32X4_TERNARY_FUNCTION_LIST(V)
 
-#define INT32X4_NULLARY_FUNCTION_LIST(V)                                                                 \
+#define INT32X4_NULLARY_FUNCTION_LIST(V)                                                          \
   V(zero, (FuncZero<Int32x4>), 0, 0, Zero)
 
-#define INT32X4_UNARY_FUNCTION_LIST(V)                                                                   \
-  V(fromFloat32x4Bits, (FuncConvertBits<Float32x4, Int32x4>), 1, 0, FromFloat32x4Bits)                   \
-  V(neg, (Func<Int32x4, Neg<int32_t>, Int32x4>), 1, 0, Neg)                                              \
-  V(not, (Func<Int32x4, Not<int32_t>, Int32x4>), 1, 0, Not)                                              \
-  V(splat, (FuncSplat<Int32x4>), 0, 0, Splat)                                                            \
+#define INT32X4_UNARY_FUNCTION_LIST(V)                                                            \
+  V(fromFloat32x4Bits, (FuncConvertBits<Float32x4, Int32x4>), 1, 0, FromFloat32x4Bits)            \
+  V(neg, (Func<Int32x4, Neg, Int32x4>), 1, 0, Neg)                                                \
+  V(not, (Func<Int32x4, Not, Int32x4>), 1, 0, Not)                                                \
+  V(splat, (FuncSplat<Int32x4>), 0, 0, Splat)                                                     \
   V(fromFloat32x4, (FuncConvert<Float32x4, Int32x4>), 1, 0, FromFloat32x4)
 
-#define INT32X4_BINARY_FUNCTION_LIST(V)                                                                  \
-  V(add, (Func<Int32x4, Add<int32_t>, Int32x4>), 2, 0, Add)                                              \
-  V(and, (Func<Int32x4, And<int32_t>, Int32x4>), 2, 0, And)                                              \
-  V(equal, (Func<Int32x4, Equal<int32_t>, Int32x4>), 2, 0, Equal)                                        \
-  V(greaterThan, (Func<Int32x4, GreaterThan<int32_t>, Int32x4>), 2, 0, GreaterThan)                      \
-  V(lessThan, (Func<Int32x4, LessThan<int32_t>, Int32x4>), 2, 0, LessThan)                               \
-  V(mul, (Func<Int32x4, Mul<int32_t>, Int32x4>), 2, 0, Mul)                                              \
-  V(or, (Func<Int32x4, Or<int32_t>, Int32x4>), 2, 0, Or)                                                 \
-  V(sub, (Func<Int32x4, Sub<int32_t>, Int32x4>), 2, 0, Sub)                                              \
-  V(shiftLeft, (Int32x4BinaryScalar<ShiftLeft>), 2, 0, ShiftLeft)                                        \
-  V(shiftRight, (Int32x4BinaryScalar<ShiftRight>), 2, 0, ShiftRight)                                     \
-  V(shiftRightLogical, (Int32x4BinaryScalar<ShiftRightLogical>), 2, 0, ShiftRightLogical)                \
-  V(shuffle, FuncShuffle<Int32x4>, 2, 0, Shuffle)                                                        \
-  V(withFlagX, (FuncWith<Int32x4, WithFlagX<int32_t>, Int32x4>), 2, 0, WithFlagX)                        \
-  V(withFlagY, (FuncWith<Int32x4, WithFlagY<int32_t>, Int32x4>), 2, 0, WithFlagY)                        \
-  V(withFlagZ, (FuncWith<Int32x4, WithFlagZ<int32_t>, Int32x4>), 2, 0, WithFlagZ)                        \
-  V(withFlagW, (FuncWith<Int32x4, WithFlagW<int32_t>, Int32x4>), 2, 0, WithFlagW)                        \
-  V(withX, (FuncWith<Int32x4, WithX<int32_t>, Int32x4>), 2, 0, WithX)                                    \
-  V(withY, (FuncWith<Int32x4, WithY<int32_t>, Int32x4>), 2, 0, WithY)                                    \
-  V(withZ, (FuncWith<Int32x4, WithZ<int32_t>, Int32x4>), 2, 0, WithZ)                                    \
-  V(withW, (FuncWith<Int32x4, WithW<int32_t>, Int32x4>), 2, 0, WithW)                                    \
-  V(xor, (Func<Int32x4, Xor<int32_t>, Int32x4>), 2, 0, Xor)
+#define INT32X4_BINARY_FUNCTION_LIST(V)                                                           \
+  V(add, (Func<Int32x4, Add, Int32x4>), 2, 0, Add)                                                \
+  V(and, (Func<Int32x4, And, Int32x4>), 2, 0, And)                                                \
+  V(equal, (Func<Int32x4, Equal, Int32x4>), 2, 0, Equal)                                          \
+  V(greaterThan, (Func<Int32x4, GreaterThan, Int32x4>), 2, 0, GreaterThan)                        \
+  V(lessThan, (Func<Int32x4, LessThan, Int32x4>), 2, 0, LessThan)                                 \
+  V(mul, (Func<Int32x4, Mul, Int32x4>), 2, 0, Mul)                                                \
+  V(or, (Func<Int32x4, Or, Int32x4>), 2, 0, Or)                                                   \
+  V(sub, (Func<Int32x4, Sub, Int32x4>), 2, 0, Sub)                                                \
+  V(shiftLeft, (Int32x4BinaryScalar<ShiftLeft>), 2, 0, ShiftLeft)                                 \
+  V(shiftRight, (Int32x4BinaryScalar<ShiftRight>), 2, 0, ShiftRight)                              \
+  V(shiftRightLogical, (Int32x4BinaryScalar<ShiftRightLogical>), 2, 0, ShiftRightLogical)         \
+  V(shuffle, FuncShuffle<Int32x4>, 2, 0, Shuffle)                                                 \
+  V(withFlagX, (FuncWith<Int32x4, WithFlagX, Int32x4>), 2, 0, WithFlagX)                          \
+  V(withFlagY, (FuncWith<Int32x4, WithFlagY, Int32x4>), 2, 0, WithFlagY)                          \
+  V(withFlagZ, (FuncWith<Int32x4, WithFlagZ, Int32x4>), 2, 0, WithFlagZ)                          \
+  V(withFlagW, (FuncWith<Int32x4, WithFlagW, Int32x4>), 2, 0, WithFlagW)                          \
+  V(withX, (FuncWith<Int32x4, WithX, Int32x4>), 2, 0, WithX)                                      \
+  V(withY, (FuncWith<Int32x4, WithY, Int32x4>), 2, 0, WithY)                                      \
+  V(withZ, (FuncWith<Int32x4, WithZ, Int32x4>), 2, 0, WithZ)                                      \
+  V(withW, (FuncWith<Int32x4, WithW, Int32x4>), 2, 0, WithW)                                      \
+  V(xor, (Func<Int32x4, Xor, Int32x4>), 2, 0, Xor)
 
-#define INT32X4_TERNARY_FUNCTION_LIST(V)                                                                 \
-  V(select, Int32x4Select, 3, 0, Select)                                                                 \
+#define INT32X4_TERNARY_FUNCTION_LIST(V)                                                          \
+  V(select, Int32x4Select, 3, 0, Select)                                                          \
   V(shuffleMix, FuncShuffle<Int32x4>, 3, 0, ShuffleMix)
 
-#define INT32X4_QUARTERNARY_FUNCTION_LIST(V)                                                             \
+#define INT32X4_QUARTERNARY_FUNCTION_LIST(V)                                                      \
   V(bool, Int32x4Bool, 4, 0, Bool)
 
-#define INT32X4_FUNCTION_LIST(V)                                                                         \
-  INT32X4_NULLARY_FUNCTION_LIST(V)                                                                       \
-  INT32X4_UNARY_FUNCTION_LIST(V)                                                                         \
-  INT32X4_BINARY_FUNCTION_LIST(V)                                                                        \
-  INT32X4_TERNARY_FUNCTION_LIST(V)                                                                       \
+#define INT32X4_FUNCTION_LIST(V)                                                                  \
+  INT32X4_NULLARY_FUNCTION_LIST(V)                                                                \
+  INT32X4_UNARY_FUNCTION_LIST(V)                                                                  \
+  INT32X4_BINARY_FUNCTION_LIST(V)                                                                 \
+  INT32X4_TERNARY_FUNCTION_LIST(V)                                                                \
   INT32X4_QUARTERNARY_FUNCTION_LIST(V)
 
 namespace js {
 
 class SIMDObject : public JSObject
 {
   public:
     static const Class class_;