Bug 943769 Part 1 -- Use macros to declare and define SIMD functions r=nmatsakis
authorHaitao Feng <haitao.feng@intel.com>
Tue, 04 Mar 2014 20:06:25 -0500
changeset 171903 3194cb1d73f6a269f114b84f5e5fcf4a8b835806
parent 171902 3784de966811121594fcf279c254f495742d7bc9
child 171904 7efaabf97f0cc5b22f4b789af7807056f5d9a537
push id26342
push usercbook@mozilla.com
push dateWed, 05 Mar 2014 12:04:59 +0000
treeherdermozilla-central@7f7d0399102a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnmatsakis
bugs943769
milestone30.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 943769 Part 1 -- Use macros to declare and define SIMD functions r=nmatsakis
js/src/builtin/SIMD.cpp
js/src/builtin/SIMD.h
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -869,68 +869,41 @@ Int32x4Select(JSContext *cx, unsigned ar
     RootedObject obj(cx, Create<Float32x4>(cx, *result));
     if (!obj)
         return false;
 
     args.rval().setObject(*obj);
     return true;
 }
 
+#define DEFINE_SIMD_FLOAT32X4_FUNCTION(Name, Func, Operands, Flags, MIRId)     \
+bool                                                                           \
+js::simd_float32x4_##Name(JSContext *cx, unsigned argc, Value *vp)             \
+{                                                                              \
+    return Func(cx, argc, vp);                                                 \
+}
+FLOAT32X4_FUNCTION_LIST(DEFINE_SIMD_FLOAT32X4_FUNCTION)
+#undef DEFINE_SIMD_FLOAT32x4_FUNCTION
+
+#define DEFINE_SIMD_INT32X4_FUNCTION(Name, Func, Operands, Flags, MIRId)       \
+bool                                                                           \
+js::simd_int32x4_##Name(JSContext *cx, unsigned argc, Value *vp)               \
+{                                                                              \
+    return Func(cx, argc, vp);                                                 \
+}
+INT32X4_FUNCTION_LIST(DEFINE_SIMD_INT32X4_FUNCTION)
+#undef DEFINE_SIMD_INT32X4_FUNCTION
+
 const JSFunctionSpec js::Float32x4Methods[] = {
-        JS_FN("abs", (Func<Float32x4, Abs<float, Float32x4>, Float32x4>), 1, 0),
-        JS_FN("neg", (Func<Float32x4, Neg<float, Float32x4>, Float32x4>), 1, 0),
-        JS_FN("reciprocal", (Func<Float32x4, Rec<float, Float32x4>, Float32x4>), 1, 0),
-        JS_FN("reciprocalSqrt", (Func<Float32x4, RecSqrt<float, Float32x4>, Float32x4>), 1, 0),
-        JS_FN("sqrt", (Func<Float32x4, Sqrt<float, Float32x4>, Float32x4>), 1, 0),
-        JS_FN("add", (Func<Float32x4, Add<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("sub", (Func<Float32x4, Sub<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("div", (Func<Float32x4, Div<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("mul", (Func<Float32x4, Mul<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("max", (Func<Float32x4, Maximum<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("min", (Func<Float32x4, Minimum<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("lessThan", (Func<Float32x4, LessThan<float, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("lessThanOrEqual", (Func<Float32x4, LessThanOrEqual<float, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("greaterThan", (Func<Float32x4, GreaterThan<float, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("greaterThanOrEqual", (Func<Float32x4, GreaterThanOrEqual<float, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("equal", (Func<Float32x4, Equal<float, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("notEqual", (Func<Float32x4, NotEqual<float, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withX", (FuncWith<Float32x4, WithX<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("withY", (FuncWith<Float32x4, WithY<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("withZ", (FuncWith<Float32x4, WithZ<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("withW", (FuncWith<Float32x4, WithW<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("shuffle", (FuncShuffle<Float32x4, Shuffle<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("shuffleMix", (FuncShuffle<Float32x4, Shuffle<float, Float32x4>, Float32x4>), 3, 0),
-        JS_FN("scale", (FuncWith<Float32x4, Scale<float, Float32x4>, Float32x4>), 2, 0),
-        JS_FN("clamp", Float32x4Clamp, 3, 0),
-        JS_FN("toInt32x4", (FuncConvert<Float32x4, Int32x4>), 1, 0),
-        JS_FN("bitsToInt32x4", (FuncConvertBits<Float32x4, Int32x4>), 1, 0),
-        JS_FN("zero", (FuncZero<Float32x4>), 0, 0),
-        JS_FN("splat", (FuncSplat<Float32x4>), 0, 0),
+#define SIMD_FLOAT32X4_FUNCTION_ITEM(Name, Func, Operands, Flags, MIRId)       \
+        JS_FN(#Name, js::simd_float32x4_##Name, Operands, Flags),
+        FLOAT32X4_FUNCTION_LIST(SIMD_FLOAT32X4_FUNCTION_ITEM)
+#undef SIMD_FLOAT32x4_FUNCTION_ITEM
         JS_FS_END
 };
 
 const JSFunctionSpec js::Int32x4Methods[] = {
-        JS_FN("not", (Func<Int32x4, Not<int32_t, Int32x4>, Int32x4>), 1, 0),
-        JS_FN("neg", (Func<Int32x4, Neg<int32_t, Int32x4>, Int32x4>), 1, 0),
-        JS_FN("add", (Func<Int32x4, Add<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("sub", (Func<Int32x4, Sub<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("mul", (Func<Int32x4, Mul<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("xor", (Func<Int32x4, Xor<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("and", (Func<Int32x4, And<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("or", (Func<Int32x4, Or<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withX", (FuncWith<Int32x4, WithX<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withY", (FuncWith<Int32x4, WithY<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withZ", (FuncWith<Int32x4, WithZ<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withW", (FuncWith<Int32x4, WithW<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withFlagX", (FuncWith<Int32x4, WithFlagX<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withFlagY", (FuncWith<Int32x4, WithFlagY<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withFlagZ", (FuncWith<Int32x4, WithFlagZ<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("withFlagW", (FuncWith<Int32x4, WithFlagW<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("shuffle", (FuncShuffle<Int32x4, Shuffle<int32_t, Int32x4>, Int32x4>), 2, 0),
-        JS_FN("shuffleMix", (FuncShuffle<Int32x4, Shuffle<int32_t, Int32x4>, Int32x4>), 3, 0),
-        JS_FN("toFloat32x4", (FuncConvert<Int32x4, Float32x4>), 1, 0),
-        JS_FN("bitsToFloat32x4", (FuncConvertBits<Int32x4, Float32x4>), 1, 0),
-        JS_FN("zero", (FuncZero<Int32x4>), 0, 0),
-        JS_FN("splat", (FuncSplat<Int32x4>), 0, 0),
-        JS_FN("select", Int32x4Select, 3, 0),
-        JS_FN("bool", Int32x4Bool, 4, 0),
+#define SIMD_INT32X4_FUNCTION_ITEM(Name, Func, Operands, Flags, MIRId)         \
+        JS_FN(#Name, js::simd_int32x4_##Name, Operands, Flags),
+        INT32X4_FUNCTION_LIST(SIMD_INT32X4_FUNCTION_ITEM)
+#undef SIMD_INT32X4_FUNCTION_ITEM
         JS_FS_END
 };
--- a/js/src/builtin/SIMD.h
+++ b/js/src/builtin/SIMD.h
@@ -13,16 +13,100 @@
 #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)                                                                        \
+  V(zero, (FuncZero<Float32x4>), 0, 0, Zero)
+
+#define FLOAT32X4_UNARY_FUNCTION_LIST(V)                                                                          \
+  V(abs, (Func<Float32x4, Abs<float, Float32x4>, Float32x4>), 1, 0, Abs)                                          \
+  V(bitsToInt32x4, (FuncConvertBits<Float32x4, Int32x4>), 1, 0, BitsToInt32x4)                                    \
+  V(neg, (Func<Float32x4, Neg<float, Float32x4>, Float32x4>), 1, 0, Neg)                                          \
+  V(reciprocal, (Func<Float32x4, Rec<float, Float32x4>, Float32x4>), 1, 0, Reciprocal)                            \
+  V(reciprocalSqrt, (Func<Float32x4, RecSqrt<float, Float32x4>, Float32x4>), 1, 0, ReciprocalSqrt)                \
+  V(splat, (FuncSplat<Float32x4>), 1, 0, Splat)                                                                   \
+  V(sqrt, (Func<Float32x4, Sqrt<float, Float32x4>, Float32x4>), 1, 0, Sqrt)                                       \
+  V(toInt32x4, (FuncConvert<Float32x4, Int32x4>), 1, 0, ToInt32x4)
+
+#define FLOAT32X4_BINARY_FUNCTION_LIST(V)                                                                         \
+  V(add, (Func<Float32x4, Add<float, Float32x4>, Float32x4>), 2, 0, Add)                                          \
+  V(div, (Func<Float32x4, Div<float, Float32x4>, Float32x4>), 2, 0, Div)                                          \
+  V(equal, (Func<Float32x4, Equal<float, Int32x4>, Int32x4>), 2, 0, Equal)                                        \
+  V(greaterThan, (Func<Float32x4, GreaterThan<float, Int32x4>, Int32x4>), 2, 0, GreaterThan)                      \
+  V(greaterThanOrEqual, (Func<Float32x4, GreaterThanOrEqual<float, Int32x4>, Int32x4>), 2, 0, GreaterThanOrEqual) \
+  V(lessThan, (Func<Float32x4, LessThan<float, Int32x4>, Int32x4>), 2, 0, LessThan)                               \
+  V(lessThanOrEqual, (Func<Float32x4, LessThanOrEqual<float, Int32x4>, Int32x4>), 2, 0, LessThanOrEqual)          \
+  V(max, (Func<Float32x4, Maximum<float, Float32x4>, Float32x4>), 2, 0, Max)                                      \
+  V(min, (Func<Float32x4, Minimum<float, Float32x4>, Float32x4>), 2, 0, Min)                                      \
+  V(mul, (Func<Float32x4, Mul<float, Float32x4>, Float32x4>), 2, 0, Mul)                                          \
+  V(notEqual, (Func<Float32x4, NotEqual<float, Int32x4>, Int32x4>), 2, 0, NotEqual)                               \
+  V(shuffle, (FuncShuffle<Float32x4, Shuffle<float, Float32x4>, Float32x4>), 2, 0, Shuffle)                       \
+  V(scale, (FuncWith<Float32x4, Scale<float, Float32x4>, Float32x4>), 2, 0, Scale)                                \
+  V(sub, (Func<Float32x4, Sub<float, Float32x4>, Float32x4>), 2, 0, Sub)                                          \
+  V(withX, (FuncWith<Float32x4, WithX<float, Float32x4>, Float32x4>), 2, 0, WithX)                                \
+  V(withY, (FuncWith<Float32x4, WithY<float, Float32x4>, Float32x4>), 2, 0, WithY)                                \
+  V(withZ, (FuncWith<Float32x4, WithZ<float, Float32x4>, Float32x4>), 2, 0, WithZ)                                \
+  V(withW, (FuncWith<Float32x4, WithW<float, Float32x4>, Float32x4>), 2, 0, WithW)
+
+#define FLOAT32X4_TERNARY_FUNCTION_LIST(V)                                                                        \
+  V(clamp, Float32x4Clamp, 3, 0, Clamp)                                                                           \
+  V(shuffleMix, (FuncShuffle<Float32x4, Shuffle<float, Float32x4>, Float32x4>), 3, 0, ShuffleMix)
+
+#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)                                                                          \
+  V(zero, (FuncZero<Int32x4>), 0, 0, Zero)
+
+#define INT32X4_UNARY_FUNCTION_LIST(V)                                                                            \
+  V(bitsToFloat32x4, (FuncConvertBits<Int32x4, Float32x4>), 1, 0, BitsToFloat32x4)                                \
+  V(neg, (Func<Int32x4, Neg<int32_t, Int32x4>, Int32x4>), 1, 0, Neg)                                              \
+  V(not, (Func<Int32x4, Not<int32_t, Int32x4>, Int32x4>), 1, 0, Not)                                              \
+  V(splat, (FuncSplat<Int32x4>), 0, 0, Splat)                                                                     \
+  V(toFloat32x4, (FuncConvert<Int32x4, Float32x4>), 1, 0, ToFloat32x4)
+
+#define INT32X4_BINARY_FUNCTION_LIST(V)                                                                           \
+  V(add, (Func<Int32x4, Add<int32_t, Int32x4>, Int32x4>), 2, 0, Add)                                              \
+  V(and, (Func<Int32x4, And<int32_t, Int32x4>, Int32x4>), 2, 0, And)                                              \
+  V(mul, (Func<Int32x4, Mul<int32_t, Int32x4>, Int32x4>), 2, 0, Mul)                                              \
+  V(or, (Func<Int32x4, Or<int32_t, Int32x4>, Int32x4>), 2, 0, Or)                                                 \
+  V(sub, (Func<Int32x4, Sub<int32_t, Int32x4>, Int32x4>), 2, 0, Sub)                                              \
+  V(shuffle, (FuncShuffle<Int32x4, Shuffle<int32_t, Int32x4>, Int32x4>), 2, 0, Shuffle)                           \
+  V(withFlagX, (FuncWith<Int32x4, WithFlagX<int32_t, Int32x4>, Int32x4>), 2, 0, WithFlagX)                        \
+  V(withFlagY, (FuncWith<Int32x4, WithFlagY<int32_t, Int32x4>, Int32x4>), 2, 0, WithFlagY)                        \
+  V(withFlagZ, (FuncWith<Int32x4, WithFlagZ<int32_t, Int32x4>, Int32x4>), 2, 0, WithFlagZ)                        \
+  V(withFlagW, (FuncWith<Int32x4, WithFlagW<int32_t, Int32x4>, Int32x4>), 2, 0, WithFlagW)                        \
+  V(withX, (FuncWith<Int32x4, WithX<int32_t, Int32x4>, Int32x4>), 2, 0, WithX)                                    \
+  V(withY, (FuncWith<Int32x4, WithY<int32_t, Int32x4>, Int32x4>), 2, 0, WithY)                                    \
+  V(withZ, (FuncWith<Int32x4, WithZ<int32_t, Int32x4>, Int32x4>), 2, 0, WithZ)                                    \
+  V(withW, (FuncWith<Int32x4, WithW<int32_t, Int32x4>, Int32x4>), 2, 0, WithW)                                    \
+  V(xor, (Func<Int32x4, Xor<int32_t, Int32x4>, Int32x4>), 2, 0, Xor)
+
+#define INT32X4_TERNARY_FUNCTION_LIST(V)                                                                          \
+  V(select, Int32x4Select, 3, 0, Select)                                                                          \
+  V(shuffleMix, (FuncShuffle<Int32x4, Shuffle<int32_t, Int32x4>, Int32x4>), 3, 0, ShuffleMix)
+
+#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)                                                                                \
+  INT32X4_QUARTERNARY_FUNCTION_LIST(V)
+
 namespace js {
 
 class SIMDObject : public JSObject
 {
   public:
     static const Class class_;
     static JSObject* initClass(JSContext *cx, Handle<GlobalObject *> global);
     static bool toString(JSContext *cx, unsigned int argc, jsval *vp);
@@ -68,14 +152,26 @@ struct Int32x4 {
     static void setReturn(CallArgs &args, int32_t value) {
         args.rval().setInt32(value);
     }
 };
 
 template<typename V>
 JSObject *Create(JSContext *cx, typename V::Elem *data);
 
+#define DECLARE_SIMD_FLOAT32X4_FUNCTION(Name, Func, Operands, Flags, MIRId)                                       \
+extern bool                                                                                                       \
+simd_float32x4_##Name(JSContext *cx, unsigned argc, Value *vp);
+FLOAT32X4_FUNCTION_LIST(DECLARE_SIMD_FLOAT32X4_FUNCTION)
+#undef DECLARE_SIMD_FLOAT32X4_FUNCTION
+
+#define DECLARE_SIMD_INT32x4_FUNCTION(Name, Func, Operands, Flags, MIRId)                                         \
+extern bool                                                                                                       \
+simd_int32x4_##Name(JSContext *cx, unsigned argc, Value *vp);
+INT32X4_FUNCTION_LIST(DECLARE_SIMD_INT32x4_FUNCTION)
+#undef DECLARE_SIMD_INT32x4_FUNCTION
+
 }  /* namespace js */
 
 JSObject *
 js_InitSIMDClass(JSContext *cx, js::HandleObject obj);
 
 #endif /* builtin_SIMD_h */