summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/simd.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/lib/simd.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/lib/simd.js')
-rw-r--r--js/src/jit-test/lib/simd.js109
1 files changed, 109 insertions, 0 deletions
diff --git a/js/src/jit-test/lib/simd.js b/js/src/jit-test/lib/simd.js
new file mode 100644
index 000000000..f275c6f08
--- /dev/null
+++ b/js/src/jit-test/lib/simd.js
@@ -0,0 +1,109 @@
+if (!this.hasOwnProperty("SIMD"))
+ quit();
+
+function booleanBinaryX4(op, v, w) {
+ var arr = [];
+ var [varr, warr] = [simdToArray(v), simdToArray(w)];
+ for (var i = 0; i < 4; i++)
+ arr[i] = op(varr[i], warr[i]);
+ return arr;
+}
+
+function binaryX(op, v, w) {
+ var arr = [];
+ var [varr, warr] = [simdToArray(v), simdToArray(w)];
+ [varr, warr] = [varr.map(Math.fround), warr.map(Math.fround)];
+ for (var i = 0; i < varr.length; i++)
+ arr[i] = op(varr[i], warr[i]);
+ return arr.map(Math.fround);
+}
+
+function unaryX4(op, v, coerceFunc) {
+ var arr = [];
+ var varr = simdToArray(v).map(coerceFunc);
+ for (var i = 0; i < 4; i++)
+ arr[i] = op(varr[i]);
+ return arr.map(coerceFunc);
+}
+
+function assertNear(a, b) {
+ assertEq((a != a && b != b) || Math.abs(a - b) < 0.001, true);
+}
+
+function GetType(v) {
+ var pt = Object.getPrototypeOf(v);
+ switch (pt) {
+ case SIMD.Int8x16.prototype: return SIMD.Int8x16;
+ case SIMD.Int16x8.prototype: return SIMD.Int16x8;
+ case SIMD.Int32x4.prototype: return SIMD.Int32x4;
+ case SIMD.Uint8x16.prototype: return SIMD.Uint8x16;
+ case SIMD.Uint16x8.prototype: return SIMD.Uint16x8;
+ case SIMD.Uint32x4.prototype: return SIMD.Uint32x4;
+ case SIMD.Float32x4.prototype: return SIMD.Float32x4;
+ case SIMD.Bool8x16.prototype: return SIMD.Bool8x16;
+ case SIMD.Bool16x8.prototype: return SIMD.Bool16x8;
+ case SIMD.Bool32x4.prototype: return SIMD.Bool32x4;
+ }
+ throw "unexpected SIMD type";
+}
+
+function GetLength(t) {
+ switch (t) {
+ case SIMD.Int8x16: return 16;
+ case SIMD.Int16x8: return 8;
+ case SIMD.Int32x4: return 4;
+ case SIMD.Uint8x16: return 16;
+ case SIMD.Uint16x8: return 8;
+ case SIMD.Uint32x4: return 4;
+ case SIMD.Float32x4: return 4;
+ case SIMD.Bool8x16: return 16;
+ case SIMD.Bool16x8: return 8;
+ case SIMD.Bool32x4: return 4;
+ }
+ throw "unexpected SIMD type";
+}
+
+function assertEqVec(v, w) {
+ var typeV = GetType(v);
+ var lengthV = GetLength(typeV);
+ var ext = typeV.extractLane;
+ assertEq(GetType(w), typeV);
+ for (var i = 0; i < lengthV; i++)
+ assertEq(ext(v, i), ext(w, i));
+}
+
+function assertEqVecArr(v, w) {
+ var typeV = GetType(v);
+ var lengthV = GetLength(typeV);
+ var ext = typeV.extractLane;
+ assertEq(w.length, lengthV);
+
+ for (var i = 0; i < lengthV; i++)
+ assertEq(ext(v, i), w[i]);
+}
+
+function assertEqX4(vec, arr, ...opts) {
+
+ var assertFunc;
+ if (opts.length == 1 && typeof opts[0] !== 'undefined') {
+ assertFunc = opts[0];
+ } else {
+ assertFunc = assertEq;
+ }
+
+ var Type = GetType(vec);
+
+ assertFunc(Type.extractLane(vec, 0), arr[0]);
+ assertFunc(Type.extractLane(vec, 1), arr[1]);
+ assertFunc(Type.extractLane(vec, 2), arr[2]);
+ assertFunc(Type.extractLane(vec, 3), arr[3]);
+}
+
+function simdToArray(vec) {
+ var Type = GetType(vec);
+ var Length = GetLength(Type);
+ var a = [];
+ for (var i = 0; i < Length; i++)
+ a.push(Type.extractLane(vec, i));
+ return a;
+}