Bug 1113367: SIMD (interpreter): make constructors arguments facultative; r=sunfish
authorBenjamin Bouvier <benj@benj.me>
Mon, 22 Dec 2014 19:22:36 +0100
changeset 221240 d3cb86ccd8a8bc469bac9b43cf7cad2d85c12678
parent 221239 688452a8792116ddcafeec75dfc1cf4af46969f3
child 221241 0b155176f4ebc16aa23bdbe028798c20f9f70ad1
push id53309
push userbenj@benj.me
push dateWed, 24 Dec 2014 13:59:53 +0000
treeherdermozilla-inbound@d3cb86ccd8a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssunfish
bugs1113367
milestone37.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 1113367: SIMD (interpreter): make constructors arguments facultative; r=sunfish
js/src/builtin/SIMD.cpp
js/src/tests/ecma_7/SIMD/coercions.js
js/src/tests/ecma_7/SIMD/constructors.js
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -297,53 +297,46 @@ CreateSimdClass(JSContext *cx, Handle<Gl
 
     return typeDescr;
 }
 
 bool
 SimdTypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-    const unsigned LANES = 4;
 
     Rooted<SimdTypeDescr*> descr(cx, &args.callee().as<SimdTypeDescr>());
     if (args.length() == 1) {
         // SIMD type used as a coercion
         if (!CheckVectorObject(args[0], descr->type())) {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_SIMD_NOT_A_VECTOR);
             return false;
         }
 
         args.rval().setObject(args[0].toObject());
         return true;
     }
 
-    if (args.length() < LANES) {
-        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
-                             args.callee().getClass()->name, "3", "s");
-        return false;
-    }
-
     Rooted<TypedObject*> result(cx, TypedObject::createZeroed(cx, descr, 0));
     if (!result)
         return false;
 
     switch (descr->type()) {
       case SimdTypeDescr::TYPE_INT32: {
         int32_t *mem = reinterpret_cast<int32_t*>(result->typedMem());
         for (unsigned i = 0; i < 4; i++) {
-            if (!ToInt32(cx, args[i], &mem[i]))
+            if (!ToInt32(cx, args.get(i), &mem[i]))
                 return false;
         }
         break;
       }
       case SimdTypeDescr::TYPE_FLOAT32: {
         float *mem = reinterpret_cast<float*>(result->typedMem());
         for (unsigned i = 0; i < 4; i++) {
-            if (!RoundFloat32(cx, args[i], &mem[i]))
+            if (!RoundFloat32(cx, args.get(i), &mem[i]))
                 return false;
         }
         break;
       }
     }
     args.rval().setObject(*result);
     return true;
 }
deleted file mode 100644
--- a/js/src/tests/ecma_7/SIMD/coercions.js
+++ /dev/null
@@ -1,66 +0,0 @@
-// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
-var BUGNUMBER = 1061229;
-var float32x4 = SIMD.float32x4;
-var int32x4 = SIMD.int32x4;
-var {StructType, int32} = TypedObject;
-var summary = 'constructors used as coercions';
-
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- */
-
-function assertCaught(f) {
-    var caught = false;
-    var args = Array.slice(arguments, 1);
-    try {
-        f.apply(null, args);
-    } catch (e) {
-        caught = true;
-        print(e)
-    }
-    assertEq(caught, true);
-}
-
-function test() {
-    var x = int32x4(1, 2, 3, 4);
-    var y = int32x4(x);
-
-    assertEq(x, y);
-
-    assertEq(y.x, x.x);
-    assertEq(y.x, 1);
-    assertEq(y.y, x.y);
-    assertEq(y.y, 2);
-    assertEq(y.z, x.z);
-    assertEq(y.z, 3);
-    assertEq(y.w, x.w);
-    assertEq(y.w, 4);
-
-    assertCaught(int32x4, 3);
-    assertCaught(int32x4, float32x4(1, 2, 3, 4));
-    assertCaught(int32x4, 'pony x 4');
-
-    var x = float32x4(NaN, 13.37, -Infinity, 4);
-    var y = float32x4(x);
-
-    assertEq(x, y);
-
-    assertEq(y.x, x.x);
-    assertEq(y.x, Math.fround(NaN));
-    assertEq(y.y, x.y);
-    assertEq(y.y, Math.fround(13.37));
-    assertEq(y.z, x.z);
-    assertEq(y.z, Math.fround(-Infinity));
-    assertEq(y.w, x.w);
-    assertEq(y.w, Math.fround(4));
-
-    assertCaught(float32x4, 3);
-    assertCaught(float32x4, int32x4(1, 2, 3, 4));
-    assertCaught(float32x4, 'pony x 4');
-
-    if (typeof reportCompare === "function")
-        reportCompare(true, true);
-}
-
-test();
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_7/SIMD/constructors.js
@@ -0,0 +1,66 @@
+// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
+
+var float32x4 = SIMD.float32x4;
+var int32x4 = SIMD.int32x4;
+
+function test() {
+
+    // Constructors.
+    assertEqX4(int32x4(1, 2, 3, 4),         [1,2,3,4]);
+    assertEqX4(int32x4(1, 2, 3),            [1,2,3,0]);
+    assertEqX4(int32x4(1, 2),               [1,2,0,0]);
+    // The 1-argument form is reserved for coercions.
+    assertEqX4(int32x4(),                   [0,0,0,0]);
+    assertEqX4(int32x4(1, 2, 3, 4, 5),      [1,2,3,4]);
+    assertEqX4(int32x4(1, 2, 3, 4, 5, 6),   [1,2,3,4]);
+
+    assertEqX4(float32x4(1, 2, 3, 4),       [1,2,3,4]);
+    assertEqX4(float32x4(1, 2, 3),          [1,2,3,NaN]);
+    assertEqX4(float32x4(1, 2),             [1,2,NaN,NaN]);
+    // The 1-argument form is reserved for coercions.
+    assertEqX4(float32x4(),                 [NaN,NaN,NaN,NaN]);
+    assertEqX4(float32x4(1, 2, 3, 4, 5),    [1,2,3,4]);
+    assertEqX4(float32x4(1, 2, 3, 4, 5, 6), [1,2,3,4]);
+
+    // Constructors used as coercion.
+    var x = int32x4(1, 2, 3, 4);
+    var y = int32x4(x);
+
+    assertEq(x, y);
+
+    assertEq(y.x, x.x);
+    assertEq(y.x, 1);
+    assertEq(y.y, x.y);
+    assertEq(y.y, 2);
+    assertEq(y.z, x.z);
+    assertEq(y.z, 3);
+    assertEq(y.w, x.w);
+    assertEq(y.w, 4);
+
+    assertThrowsInstanceOf(() => int32x4(3), TypeError);
+    assertThrowsInstanceOf(() => int32x4(float32x4(1,2,3,4)), TypeError);
+    assertThrowsInstanceOf(() => int32x4('pony x 4'), TypeError);
+
+    var x = float32x4(NaN, 13.37, -Infinity, 4);
+    var y = float32x4(x);
+
+    assertEq(x, y);
+
+    assertEq(y.x, x.x);
+    assertEq(y.x, Math.fround(NaN));
+    assertEq(y.y, x.y);
+    assertEq(y.y, Math.fround(13.37));
+    assertEq(y.z, x.z);
+    assertEq(y.z, Math.fround(-Infinity));
+    assertEq(y.w, x.w);
+    assertEq(y.w, Math.fround(4));
+
+    assertThrowsInstanceOf(() => float32x4(3), TypeError);
+    assertThrowsInstanceOf(() => float32x4(int32x4(1,2,3,4)), TypeError);
+    assertThrowsInstanceOf(() => float32x4('pony x 4'), TypeError);
+
+    if (typeof reportCompare === "function")
+        reportCompare(true, true);
+}
+
+test();