Bug 1146295: Factor out SIMD type's methods with their definitions class helper; r=h4writer
authorBenjamin Bouvier <benj@benj.me>
Mon, 23 Mar 2015 11:07:50 +0100
changeset 265109 cf48b5413dbce95aff65fe58018efedfbf33fd4f
parent 265108 bf1f3c86e45de07a73b1efe44b6554ae19cdb00e
child 265110 742a3be51627f7b9b4cc187fbff66bb8d7aeb1bf
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersh4writer
bugs1146295
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 1146295: Factor out SIMD type's methods with their definitions class helper; r=h4writer
js/src/builtin/SIMD.cpp
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -24,22 +24,16 @@
 
 using namespace js;
 
 using mozilla::ArrayLength;
 using mozilla::IsFinite;
 using mozilla::IsNaN;
 using mozilla::FloorLog2;
 
-namespace js {
-extern const JSFunctionSpec Float32x4Methods[];
-extern const JSFunctionSpec Float64x2Methods[];
-extern const JSFunctionSpec Int32x4Methods[];
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // SIMD
 
 static const char *laneNames[] = {"lane 0", "lane 1", "lane 2", "lane3"};
 
 static bool
 CheckVectorObject(HandleValue v, SimdTypeDescr::Type expectedType)
 {
@@ -194,30 +188,33 @@ const Class SimdTypeDescr::class_ = {
 // These classes just exist to group together various properties and so on.
 namespace js {
 class Int32x4Defn {
   public:
     static const SimdTypeDescr::Type type = SimdTypeDescr::TYPE_INT32;
     static const JSFunctionSpec TypeDescriptorMethods[];
     static const JSPropertySpec TypedObjectProperties[];
     static const JSFunctionSpec TypedObjectMethods[];
+    static const JSFunctionSpec Methods[];
 };
 class Float32x4Defn {
   public:
     static const SimdTypeDescr::Type type = SimdTypeDescr::TYPE_FLOAT32;
     static const JSFunctionSpec TypeDescriptorMethods[];
     static const JSPropertySpec TypedObjectProperties[];
     static const JSFunctionSpec TypedObjectMethods[];
+    static const JSFunctionSpec Methods[];
 };
 class Float64x2Defn {
   public:
     static const SimdTypeDescr::Type type = SimdTypeDescr::TYPE_FLOAT64;
     static const JSFunctionSpec TypeDescriptorMethods[];
     static const JSPropertySpec TypedObjectProperties[];
     static const JSFunctionSpec TypedObjectMethods[];
+    static const JSFunctionSpec Methods[];
 };
 } // namespace js
 
 const JSFunctionSpec js::Float32x4Defn::TypeDescriptorMethods[] = {
     JS_SELF_HOSTED_FN("toSource", "DescrToSource", 0, 0),
     JS_SELF_HOSTED_FN("array", "ArrayShorthand", 1, 0),
     JS_SELF_HOSTED_FN("equivalent", "TypeDescrEquivalent", 1, 0),
     JS_FS_END
@@ -232,16 +229,24 @@ const JSPropertySpec js::Float32x4Defn::
     JS_PS_END
 };
 
 const JSFunctionSpec js::Float32x4Defn::TypedObjectMethods[] = {
     JS_SELF_HOSTED_FN("toSource", "SimdToSource", 0, 0),
     JS_FS_END
 };
 
+const JSFunctionSpec js::Float32x4Defn::Methods[] = {
+#define SIMD_FLOAT32X4_FUNCTION_ITEM(Name, Func, Operands) \
+    JS_FN(#Name, js::simd_float32x4_##Name, Operands, 0),
+    FLOAT32X4_FUNCTION_LIST(SIMD_FLOAT32X4_FUNCTION_ITEM)
+#undef SIMD_FLOAT32x4_FUNCTION_ITEM
+    JS_FS_END
+};
+
 const JSFunctionSpec js::Float64x2Defn::TypeDescriptorMethods[] = {
     JS_SELF_HOSTED_FN("toSource", "DescrToSource", 0, 0),
     JS_SELF_HOSTED_FN("array", "ArrayShorthand", 1, 0),
     JS_SELF_HOSTED_FN("equivalent", "TypeDescrEquivalent", 1, 0),
     JS_FS_END
 };
 
 const JSPropertySpec js::Float64x2Defn::TypedObjectProperties[] = {
@@ -251,16 +256,24 @@ const JSPropertySpec js::Float64x2Defn::
     JS_PS_END
 };
 
 const JSFunctionSpec js::Float64x2Defn::TypedObjectMethods[] = {
     JS_SELF_HOSTED_FN("toSource", "SimdToSource", 0, 0),
     JS_FS_END
 };
 
+const JSFunctionSpec js::Float64x2Defn::Methods[]  = {
+#define SIMD_FLOAT64X2_FUNCTION_ITEM(Name, Func, Operands) \
+    JS_FN(#Name, js::simd_float64x2_##Name, Operands, 0),
+    FLOAT64X2_FUNCTION_LIST(SIMD_FLOAT64X2_FUNCTION_ITEM)
+#undef SIMD_FLOAT64X2_FUNCTION_ITEM
+    JS_FS_END
+};
+
 const JSFunctionSpec js::Int32x4Defn::TypeDescriptorMethods[] = {
     JS_SELF_HOSTED_FN("toSource", "DescrToSource", 0, 0),
     JS_SELF_HOSTED_FN("array", "ArrayShorthand", 1, 0),
     JS_SELF_HOSTED_FN("equivalent", "TypeDescrEquivalent", 1, 0),
     JS_FS_END,
 };
 
 const JSPropertySpec js::Int32x4Defn::TypedObjectProperties[] = {
@@ -272,16 +285,24 @@ const JSPropertySpec js::Int32x4Defn::Ty
     JS_PS_END
 };
 
 const JSFunctionSpec js::Int32x4Defn::TypedObjectMethods[] = {
     JS_SELF_HOSTED_FN("toSource", "SimdToSource", 0, 0),
     JS_FS_END
 };
 
+const JSFunctionSpec js::Int32x4Defn::Methods[] = {
+#define SIMD_INT32X4_FUNCTION_ITEM(Name, Func, Operands) \
+    JS_FN(#Name, js::simd_int32x4_##Name, Operands, 0),
+    INT32X4_FUNCTION_LIST(SIMD_INT32X4_FUNCTION_ITEM)
+#undef SIMD_INT32X4_FUNCTION_ITEM
+    JS_FS_END
+};
+
 template<typename T>
 static JSObject *
 CreateSimdClass(JSContext *cx, Handle<GlobalObject*> global, HandlePropertyName stringRepr)
 {
     const SimdTypeDescr::Type type = T::type;
 
     RootedObject funcProto(cx, global->getOrCreateFunctionPrototype(cx));
     if (!funcProto)
@@ -386,25 +407,25 @@ SimdTypeDescr::call(JSContext *cx, unsig
 const Class SIMDObject::class_ = {
     "SIMD",
     JSCLASS_HAS_CACHED_PROTO(JSProto_SIMD)
 };
 
 template <typename Defn>
 static JSObject *
 CreateAndBindSimdType(JSContext *cx, Handle<GlobalObject*> global, HandleObject SIMD,
-                      js::ImmutablePropertyNamePtr name, const JSFunctionSpec methodsSpec[])
+                      js::ImmutablePropertyNamePtr name)
 {
     RootedObject typeObject(cx, CreateSimdClass<Defn>(cx, global, name));
     if (!typeObject)
         return nullptr;
 
     // Define float32x4 functions and install as a property of the SIMD object.
     RootedValue typeValue(cx, ObjectValue(*typeObject));
-    if (!JS_DefineFunctions(cx, typeObject, methodsSpec) ||
+    if (!JS_DefineFunctions(cx, typeObject, Defn::Methods) ||
         !DefineProperty(cx, SIMD, name, typeValue, nullptr, nullptr,
                         JSPROP_READONLY | JSPROP_PERMANENT))
     {
         return nullptr;
     }
 
     return typeObject;
 }
@@ -426,34 +447,31 @@ SIMDObject::initClass(JSContext *cx, Han
         return nullptr;
     RootedObject SIMD(cx, NewObjectWithGivenProto(cx, &SIMDObject::class_, objProto,
                                                   SingletonObject));
     if (!SIMD)
         return nullptr;
 
     // float32x4
     RootedObject f32x4(cx);
-    f32x4 = CreateAndBindSimdType<Float32x4Defn>(cx, global, SIMD, cx->names().float32x4,
-                                                 Float32x4Methods);
+    f32x4 = CreateAndBindSimdType<Float32x4Defn>(cx, global, SIMD, cx->names().float32x4);
     if (!f32x4)
         return nullptr;
     global->setFloat32x4TypeDescr(*f32x4);
 
     // float64x2
     RootedObject f64x2(cx);
-    f64x2 = CreateAndBindSimdType<Float64x2Defn>(cx, global, SIMD, cx->names().float64x2,
-                                                 Float64x2Methods);
+    f64x2 = CreateAndBindSimdType<Float64x2Defn>(cx, global, SIMD, cx->names().float64x2);
     if (!f64x2)
         return nullptr;
     global->setFloat64x2TypeDescr(*f64x2);
 
     // int32x4
     RootedObject i32x4(cx);
-    i32x4 = CreateAndBindSimdType<Int32x4Defn>(cx, global, SIMD, cx->names().int32x4,
-                                               Int32x4Methods);
+    i32x4 = CreateAndBindSimdType<Int32x4Defn>(cx, global, SIMD, cx->names().int32x4);
     if (!i32x4)
         return nullptr;
     global->setInt32x4TypeDescr(*i32x4);
 
     // Everything is set up, install SIMD on the global object.
     RootedValue SIMDValue(cx, ObjectValue(*SIMD));
     if (!DefineProperty(cx, global, cx->names().SIMD, SIMDValue, nullptr, nullptr, 0))
         return nullptr;
@@ -1092,31 +1110,8 @@ FLOAT64X2_FUNCTION_LIST(DEFINE_SIMD_FLOA
 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[] = {
-#define SIMD_FLOAT32X4_FUNCTION_ITEM(Name, Func, Operands)         \
-        JS_FN(#Name, js::simd_float32x4_##Name, Operands, 0),
-        FLOAT32X4_FUNCTION_LIST(SIMD_FLOAT32X4_FUNCTION_ITEM)
-#undef SIMD_FLOAT32x4_FUNCTION_ITEM
-        JS_FS_END
-};
-
-const JSFunctionSpec js::Float64x2Methods[] = {
-#define SIMD_FLOAT64X2_FUNCTION_ITEM(Name, Func, Operands)         \
-        JS_FN(#Name, js::simd_float64x2_##Name, Operands, 0),
-        FLOAT64X2_FUNCTION_LIST(SIMD_FLOAT64X2_FUNCTION_ITEM)
-#undef SIMD_FLOAT64X2_FUNCTION_ITEM
-        JS_FS_END
-};
-
-const JSFunctionSpec js::Int32x4Methods[] = {
-#define SIMD_INT32X4_FUNCTION_ITEM(Name, Func, Operands)           \
-        JS_FN(#Name, js::simd_int32x4_##Name, Operands, 0),
-        INT32X4_FUNCTION_LIST(SIMD_INT32X4_FUNCTION_ITEM)
-#undef SIMD_INT32X4_FUNCTION_ITEM
-        JS_FS_END
-};