Bug 993034: SIMD - Rename toType2 into toType and make it fallible; r=nmatsakis
authorBenjamin Bouvier <benj@benj.me>
Wed, 16 Apr 2014 16:21:09 +0200
changeset 198376 6ce48eb7d9602c3efd62ecdbff3ef5c72167c619
parent 198375 1a12d31c2289e073752a472de27b39c82cb10217
child 198377 810593c399531541c8f66376d2195db0fbe5ac1c
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [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 - Rename toType2 into toType and make it fallible; r=nmatsakis
js/src/builtin/SIMD.cpp
js/src/builtin/SIMD.h
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -604,17 +604,18 @@ FuncWith(JSContext *cx, unsigned argc, V
     typename V::Elem *val =
         reinterpret_cast<typename V::Elem *>(
             args[0].toObject().as<TypedObject>().typedMem());
 
     typename Vret::Elem result[Vret::lanes];
     for (int32_t i = 0; i < Vret::lanes; i++) {
         if(args[1].isNumber()) {
             typename Vret::Elem arg1;
-            Vret::toType2(cx, args[1], &arg1);
+            if (!Vret::toType(cx, args[1], &arg1))
+                return false;
             result[i] = OpWith::apply(i, arg1, val[i]);
         } else if (args[1].isBoolean()) {
             result[i] = OpWith::apply(i, args[1].toBoolean(), val[i]);
         }
     }
     RootedObject obj(cx, Create<Vret>(cx, result));
     if (!obj)
         return false;
@@ -638,17 +639,18 @@ FuncShuffle(JSContext *cx, unsigned argc
         }
 
         typename V::Elem *val =
             reinterpret_cast<typename V::Elem *>(
                 args[0].toObject().as<TypedObject>().typedMem());
         typename Vret::Elem result[Vret::lanes];
         for (int32_t i = 0; i < Vret::lanes; i++) {
             typename Vret::Elem arg1;
-            Vret::toType2(cx, args[1], &arg1);
+            if (!Vret::toType(cx, args[1], &arg1))
+                return false;
             result[i] = val[OpShuffle::apply(i * 2, arg1)];
         }
         RootedObject obj(cx, Create<Vret>(cx, result));
         if (!obj)
             return false;
 
         args.rval().setObject(*obj);
         return true;
@@ -664,17 +666,18 @@ FuncShuffle(JSContext *cx, unsigned argc
             reinterpret_cast<typename V::Elem *>(
                 args[0].toObject().as<TypedObject>().typedMem());
         typename V::Elem *val2 =
             reinterpret_cast<typename V::Elem *>(
                 args[1].toObject().as<TypedObject>().typedMem());
         typename Vret::Elem result[Vret::lanes];
         for (int32_t i = 0; i < Vret::lanes; i++) {
             typename Vret::Elem arg2;
-            Vret::toType2(cx, args[2], &arg2);
+            if (!Vret::toType(cx, args[2], &arg2))
+                return false;
             if(i < Vret::lanes / 2) {
                 result[i] = val1[OpShuffle::apply(i * 2, arg2)];
             } else {
                 result[i] = val2[OpShuffle::apply(i * 2, arg2)];
             }
         }
         RootedObject obj(cx, Create<Vret>(cx, result));
         if (!obj)
@@ -769,17 +772,18 @@ FuncSplat(JSContext *cx, unsigned argc, 
 
     if ((args.length() != 1) || (!args[0].isNumber())) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
     typename Vret::Elem result[Vret::lanes];
     for (int32_t i = 0; i < Vret::lanes; i++) {
         typename Vret::Elem arg0;
-        Vret::toType2(cx, args[0], &arg0);
+        if (!Vret::toType(cx, args[0], &arg0))
+            return false;
         result[i] = static_cast<typename Vret::Elem>(arg0);
     }
 
     RootedObject obj(cx, Create<Vret>(cx, result));
     if (!obj)
         return false;
 
     args.rval().setObject(*obj);
--- a/js/src/builtin/SIMD.h
+++ b/js/src/builtin/SIMD.h
@@ -121,40 +121,41 @@ struct Float32x4 {
         X4TypeDescr::TYPE_FLOAT32;
 
     static TypeDescr &GetTypeDescr(GlobalObject &global) {
         return global.float32x4TypeDescr().as<TypeDescr>();
     }
     static Elem toType(Elem a) {
         return a;
     }
-    static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
+    static bool toType(JSContext *cx, JS::HandleValue v, Elem *out) {
         *out = v.toNumber();
+        return true;
     }
-    static void setReturn(CallArgs &args, float value) {
+    static void setReturn(CallArgs &args, Elem value) {
         args.rval().setDouble(JS::CanonicalizeNaN(value));
     }
 };
 
 struct Int32x4 {
     typedef int32_t Elem;
     static const int32_t lanes = 4;
     static const X4TypeDescr::Type type =
         X4TypeDescr::TYPE_INT32;
 
     static TypeDescr &GetTypeDescr(GlobalObject &global) {
         return global.int32x4TypeDescr().as<TypeDescr>();
     }
     static Elem toType(Elem a) {
         return ToInt32(a);
     }
-    static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
-        ToInt32(cx,v,out);
+    static bool toType(JSContext *cx, JS::HandleValue v, Elem *out) {
+        return ToInt32(cx, v, out);
     }
-    static void setReturn(CallArgs &args, int32_t value) {
+    static void setReturn(CallArgs &args, Elem 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)                                       \