Bug 993034: SIMD - Factor out tests for object and vector in a single function; r=nmatsakis
authorBenjamin Bouvier <benj@benj.me>
Wed, 16 Apr 2014 16:21:29 +0200
changeset 197314 330cc814b05bb6a12e632ef9adfbedf73b4c0861
parent 197313 87e9fc86154e1e3cd5dbb461578db02c842af3d2
child 197315 9c402f8b74fc10a517c03d2d1eb035cdf5499268
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnmatsakis
bugs993034
milestone31.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 993034: SIMD - Factor out tests for object and vector in a single function; r=nmatsakis
js/src/builtin/SIMD.cpp
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -363,19 +363,18 @@ SIMDObject::initClass(JSContext *cx, Han
                                   JSPROP_READONLY | JSPROP_PERMANENT))
     {
         return nullptr;
     }
 
     RootedValue SIMDValue(cx, ObjectValue(*SIMD));
 
     // Everything is set up, install SIMD on the global object.
-    if (!JSObject::defineProperty(cx, global, cx->names().SIMD,  SIMDValue, nullptr, nullptr, 0)) {
+    if (!JSObject::defineProperty(cx, global, cx->names().SIMD, SIMDValue, nullptr, nullptr, 0))
         return nullptr;
-    }
 
     global->setConstructor(JSProto_SIMD, SIMDValue);
 
     // Define float32x4 functions and install as a property of the SIMD object.
     global->setFloat32x4TypeDescr(*float32x4Object);
 
     // Define int32x4 functions and install as a property of the SIMD object.
     global->setInt32x4TypeDescr(*int32x4Object);
@@ -388,22 +387,29 @@ js_InitSIMDClass(JSContext *cx, HandleOb
 {
     JS_ASSERT(obj->is<GlobalObject>());
     Rooted<GlobalObject *> global(cx, &obj->as<GlobalObject>());
     return SIMDObject::initClass(cx, global);
 }
 
 template<typename V>
 static bool
-ObjectIsVector(JSObject &obj) {
+IsVectorObject(HandleValue v)
+{
+    if (!v.isObject())
+        return false;
+
+    JSObject &obj = v.toObject();
     if (!obj.is<TypedObject>())
         return false;
+
     TypeDescr &typeRepr = obj.as<TypedObject>().typeDescr();
     if (typeRepr.kind() != TypeDescr::X4)
         return false;
+
     return typeRepr.as<X4TypeDescr>().type() == V::type;
 }
 
 template<typename V>
 JSObject *
 js::Create(JSContext *cx, typename V::Elem *data)
 {
     typedef typename V::Elem Elem;
@@ -559,28 +565,27 @@ Func(JSContext *cx, unsigned argc, Value
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() != 1 && args.length() != 2) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     RetElem result[Vret::lanes];
     if (args.length() == 1) {
-        if (!args[0].isObject() || !ObjectIsVector<V>(args[0].toObject())) {
+        if (!IsVectorObject<V>(args[0])) {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
 
         Elem *val = reinterpret_cast<Elem *>(args[0].toObject().as<TypedObject>().typedMem());
         for (int32_t i = 0; i < Vret::lanes; i++)
             result[i] = Op::apply(val[i], 0);
     } else {
         JS_ASSERT(args.length() == 2);
-        if(!args[0].isObject() || !ObjectIsVector<V>(args[0].toObject()) ||
-           !args[1].isObject() || !ObjectIsVector<V>(args[1].toObject()))
+        if(!IsVectorObject<V>(args[0]) || !IsVectorObject<V>(args[1]))
         {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
 
         Elem *left = reinterpret_cast<Elem *>(args[0].toObject().as<TypedObject>().typedMem());
         Elem *right = reinterpret_cast<Elem *>(args[1].toObject().as<TypedObject>().typedMem());
         for (int32_t i = 0; i < Vret::lanes; i++)
@@ -598,18 +603,17 @@ Func(JSContext *cx, unsigned argc, Value
 template<typename V, typename 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 ||
-        !args[0].isObject() || !ObjectIsVector<V>(args[0].toObject()) ||
+    if (args.length() != 2 || !IsVectorObject<V>(args[0]) ||
         (!args[1].isNumber() && !args[1].isBoolean()))
     {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     Elem *val = reinterpret_cast<Elem *>(args[0].toObject().as<TypedObject>().typedMem());
     RetElem result[Vret::lanes];
@@ -644,35 +648,32 @@ FuncShuffle(JSContext *cx, unsigned argc
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() != 2 && args.length() != 3) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     RetElem result[Vret::lanes];
     if (args.length() == 2) {
-        if (!args[0].isObject() || !ObjectIsVector<V>(args[0].toObject()) ||
-            !args[1].isNumber())
+        if (!IsVectorObject<V>(args[0]) || !args[1].isNumber())
         {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
 
         Elem *val = reinterpret_cast<Elem *>(args[0].toObject().as<TypedObject>().typedMem());
         Elem arg1;
         if (!Vret::toType(cx, args[1], &arg1))
             return false;
 
         for (int32_t i = 0; i < Vret::lanes; i++)
             result[i] = val[OpShuffle::apply(i * 2, arg1)];
     } else {
         JS_ASSERT(args.length() == 3);
-        if (!args[0].isObject() || !ObjectIsVector<V>(args[0].toObject()) ||
-            !args[1].isObject() || !ObjectIsVector<V>(args[1].toObject()) ||
-            !args[2].isNumber())
+        if (!IsVectorObject<V>(args[0]) || !IsVectorObject<V>(args[1]) || !args[2].isNumber())
         {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
 
         Elem *val1 = reinterpret_cast<Elem *>(args[0].toObject().as<TypedObject>().typedMem());
         Elem *val2 = reinterpret_cast<Elem *>(args[1].toObject().as<TypedObject>().typedMem());
 
@@ -699,18 +700,17 @@ FuncShuffle(JSContext *cx, unsigned argc
 template<typename V, typename Vret>
 static bool
 FuncConvert(JSContext *cx, unsigned argc, Value *vp)
 {
     typedef typename V::Elem Elem;
     typedef typename Vret::Elem RetElem;
 
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 1 ||
-        !args[0].isObject() || !ObjectIsVector<V>(args[0].toObject()))
+    if (args.length() != 1 || !IsVectorObject<V>(args[0]))
     {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     Elem *val = reinterpret_cast<Elem *>(args[0].toObject().as<TypedObject>().typedMem());
     RetElem result[Vret::lanes];
     for (int32_t i = 0; i < Vret::lanes; i++)
@@ -726,18 +726,17 @@ FuncConvert(JSContext *cx, unsigned argc
 
 template<typename V, typename Vret>
 static bool
 FuncConvertBits(JSContext *cx, unsigned argc, Value *vp)
 {
     typedef typename Vret::Elem RetElem;
 
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 1 ||
-        !args[0].isObject() || !ObjectIsVector<V>(args[0].toObject()))
+    if (args.length() != 1 || !IsVectorObject<V>(args[0]))
     {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     RetElem *val = reinterpret_cast<RetElem *>(args[0].toObject().as<TypedObject>().typedMem());
 
     RootedObject obj(cx, Create<Vret>(cx, val));
@@ -823,20 +822,18 @@ Int32x4Bool(JSContext *cx, unsigned argc
     args.rval().setObject(*obj);
     return true;
 }
 
 static bool
 Float32x4Clamp(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 3 ||
-        !args[0].isObject() || !ObjectIsVector<Float32x4>(args[0].toObject()) ||
-        !args[1].isObject() || !ObjectIsVector<Float32x4>(args[1].toObject()) ||
-        !args[2].isObject() || !ObjectIsVector<Float32x4>(args[2].toObject()))
+    if (args.length() != 3 || !IsVectorObject<Float32x4>(args[0]) ||
+        !IsVectorObject<Float32x4>(args[1]) || !IsVectorObject<Float32x4>(args[2]))
     {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     float *val = reinterpret_cast<float *>(args[0].toObject().as<TypedObject>().typedMem());
     float *lowerLimit = reinterpret_cast<float *>(args[1].toObject().as<TypedObject>().typedMem());
     float *upperLimit = reinterpret_cast<float *>(args[2].toObject().as<TypedObject>().typedMem());
@@ -854,20 +851,18 @@ Float32x4Clamp(JSContext *cx, unsigned a
     args.rval().setObject(*obj);
     return true;
 }
 
 static bool
 Int32x4Select(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 3 ||
-        !args[0].isObject() || !ObjectIsVector<Int32x4>(args[0].toObject()) ||
-        !args[1].isObject() || !ObjectIsVector<Float32x4>(args[1].toObject()) ||
-        !args[2].isObject() || !ObjectIsVector<Float32x4>(args[2].toObject()))
+    if (args.length() != 3 || !IsVectorObject<Int32x4>(args[0]) ||
+        !IsVectorObject<Float32x4>(args[1]) || !IsVectorObject<Float32x4>(args[2]))
     {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     int32_t *val = reinterpret_cast<int32_t *>(args[0].toObject().as<TypedObject>().typedMem());
     int32_t *tv = reinterpret_cast<int32_t *>(args[1].toObject().as<TypedObject>().typedMem());
     int32_t *fv = reinterpret_cast<int32_t *>(args[2].toObject().as<TypedObject>().typedMem());