Bug 1129491: Add SIMD.{type}.check to the interpreter + tests; r=evilpie
authorBenjamin Bouvier <benj@benj.me>
Thu, 12 Feb 2015 18:20:51 +0100
changeset 229237 099b350c49c49674aa49842334ed53c693497e84
parent 229236 4d4b564c9d8415ddd3df0dc6a0926b357c1a2ae4
child 229238 a1bd894fbfc812f1f3ba524d8088eea1ab5bb474
push id28282
push usercbook@mozilla.com
push dateMon, 16 Feb 2015 15:06:35 +0000
treeherdermozilla-central@09f4968d5f42 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1129491
milestone38.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 1129491: Add SIMD.{type}.check to the interpreter + tests; r=evilpie
js/src/builtin/SIMD.cpp
js/src/builtin/SIMD.h
js/src/tests/ecma_7/SIMD/check.js
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -523,16 +523,20 @@ js::CreateSimd(JSContext *cx, typename V
 
 template JSObject *js::CreateSimd<Float32x4>(JSContext *cx, Float32x4::Elem *data);
 template JSObject *js::CreateSimd<Float64x2>(JSContext *cx, Float64x2::Elem *data);
 template JSObject *js::CreateSimd<Int32x4>(JSContext *cx, Int32x4::Elem *data);
 
 namespace js {
 // Unary SIMD operators
 template<typename T>
+struct Identity {
+    static inline T apply(T x) { return x; }
+};
+template<typename T>
 struct Abs {
     static inline T apply(T x) { return mozilla::Abs(x); }
 };
 template<typename T>
 struct Neg {
     static inline T apply(T x) { return -1 * x; }
 };
 template<typename T>
--- a/js/src/builtin/SIMD.h
+++ b/js/src/builtin/SIMD.h
@@ -17,16 +17,17 @@
 /*
  * JS SIMD functions.
  * Spec matching polyfill:
  * https://github.com/johnmccutchan/ecmascript_simd/blob/master/src/ecmascript_simd.js
  */
 
 #define FLOAT32X4_UNARY_FUNCTION_LIST(V)                                            \
   V(abs, (UnaryFunc<Float32x4, Abs, Float32x4>), 1, 0)                              \
+  V(check, (UnaryFunc<Float32x4, Identity, Float32x4>), 1, 0)                       \
   V(fromFloat64x2, (FuncConvert<Float64x2, Float32x4> ), 1, 0)                      \
   V(fromFloat64x2Bits, (FuncConvertBits<Float64x2, Float32x4>), 1, 0)               \
   V(fromInt32x4, (FuncConvert<Int32x4, Float32x4> ), 1, 0)                          \
   V(fromInt32x4Bits, (FuncConvertBits<Int32x4, Float32x4>), 1, 0)                   \
   V(neg, (UnaryFunc<Float32x4, Neg, Float32x4>), 1, 0)                              \
   V(not, (CoercedUnaryFunc<Float32x4, Int32x4, Not, Float32x4>), 1, 0)              \
   V(reciprocal, (UnaryFunc<Float32x4, Rec, Float32x4>), 1, 0)                       \
   V(reciprocalSqrt, (UnaryFunc<Float32x4, RecSqrt, Float32x4>), 1, 0)               \
@@ -76,16 +77,17 @@
 #define FLOAT32X4_FUNCTION_LIST(V)                                                  \
   FLOAT32X4_UNARY_FUNCTION_LIST(V)                                                  \
   FLOAT32X4_BINARY_FUNCTION_LIST(V)                                                 \
   FLOAT32X4_TERNARY_FUNCTION_LIST(V)                                                \
   FLOAT32X4_SHUFFLE_FUNCTION_LIST(V)
 
 #define FLOAT64X2_UNARY_FUNCTION_LIST(V)                                            \
   V(abs, (UnaryFunc<Float64x2, Abs, Float64x2>), 1, 0)                              \
+  V(check, (UnaryFunc<Float64x2, Identity, Float64x2>), 1, 0)                       \
   V(fromFloat32x4, (FuncConvert<Float32x4, Float64x2> ), 1, 0)                      \
   V(fromFloat32x4Bits, (FuncConvertBits<Float32x4, Float64x2>), 1, 0)               \
   V(fromInt32x4, (FuncConvert<Int32x4, Float64x2> ), 1, 0)                          \
   V(fromInt32x4Bits, (FuncConvertBits<Int32x4, Float64x2>), 1, 0)                   \
   V(neg, (UnaryFunc<Float64x2, Neg, Float64x2>), 1, 0)                              \
   V(reciprocal, (UnaryFunc<Float64x2, Rec, Float64x2>), 1, 0)                       \
   V(reciprocalSqrt, (UnaryFunc<Float64x2, RecSqrt, Float64x2>), 1, 0)               \
   V(splat, (FuncSplat<Float64x2>), 1, 0)                                            \
@@ -124,16 +126,17 @@
 
 #define FLOAT64X2_FUNCTION_LIST(V)                                                  \
   FLOAT64X2_UNARY_FUNCTION_LIST(V)                                                  \
   FLOAT64X2_BINARY_FUNCTION_LIST(V)                                                 \
   FLOAT64X2_TERNARY_FUNCTION_LIST(V)                                                \
   FLOAT64X2_SHUFFLE_FUNCTION_LIST(V)
 
 #define INT32X4_UNARY_FUNCTION_LIST(V)                                              \
+  V(check, (UnaryFunc<Int32x4, Identity, Int32x4>), 1, 0)                           \
   V(fromFloat32x4, (FuncConvert<Float32x4, Int32x4>), 1, 0)                         \
   V(fromFloat32x4Bits, (FuncConvertBits<Float32x4, Int32x4>), 1, 0)                 \
   V(fromFloat64x2, (FuncConvert<Float64x2, Int32x4>), 1, 0)                         \
   V(fromFloat64x2Bits, (FuncConvertBits<Float64x2, Int32x4>), 1, 0)                 \
   V(neg, (UnaryFunc<Int32x4, Neg, Int32x4>), 1, 0)                                  \
   V(not, (UnaryFunc<Int32x4, Not, Int32x4>), 1, 0)                                  \
   V(splat, (FuncSplat<Int32x4>), 0, 0)
 
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_7/SIMD/check.js
@@ -0,0 +1,35 @@
+// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
+
+function test() {
+
+  var i4 = SIMD.int32x4(1,2,3,4);
+  var f4 = SIMD.float32x4(NaN, -0, Infinity, 13.37);
+  var f2 = SIMD.float64x2(-0, 13.37);
+
+  var ci4 = SIMD.int32x4.check(i4);
+  assertEqX4(ci4, simdToArray(i4));
+  assertThrowsInstanceOf(() => SIMD.int32x4.check(f4), TypeError);
+  assertThrowsInstanceOf(() => SIMD.int32x4.check(f2), TypeError);
+  assertThrowsInstanceOf(() => SIMD.int32x4.check("i swear i'm a vector"), TypeError);
+  assertThrowsInstanceOf(() => SIMD.int32x4.check({}), TypeError);
+
+  var cf4 = SIMD.float32x4.check(f4);
+  assertEqX4(cf4, simdToArray(f4));
+  assertThrowsInstanceOf(() => SIMD.float32x4.check(i4), TypeError);
+  assertThrowsInstanceOf(() => SIMD.float32x4.check(f2), TypeError);
+  assertThrowsInstanceOf(() => SIMD.float32x4.check("i swear i'm a vector"), TypeError);
+  assertThrowsInstanceOf(() => SIMD.float32x4.check({}), TypeError);
+
+  var cf2 = SIMD.float64x2.check(f2);
+  assertEqX2(cf2, simdToArray(f2));
+  assertThrowsInstanceOf(() => SIMD.float64x2.check(f4), TypeError);
+  assertThrowsInstanceOf(() => SIMD.float64x2.check(i4), TypeError);
+  assertThrowsInstanceOf(() => SIMD.float64x2.check("i swear i'm a vector"), TypeError);
+  assertThrowsInstanceOf(() => SIMD.float64x2.check({}), TypeError);
+
+  if (typeof reportCompare === "function")
+    reportCompare(true, true);
+}
+
+test();
+