From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- js/src/tests/ecma_7/SIMD/ToSource.js | 56 + js/src/tests/ecma_7/SIMD/binary-operations.js | 785 ++++++++++++ js/src/tests/ecma_7/SIMD/bug1023145.js | 14 + js/src/tests/ecma_7/SIMD/bug953270.js | 24 + js/src/tests/ecma_7/SIMD/check.js | 214 ++++ js/src/tests/ecma_7/SIMD/comparisons.js | 349 ++++++ js/src/tests/ecma_7/SIMD/constructors.js | 226 ++++ js/src/tests/ecma_7/SIMD/conversions.js | 1261 ++++++++++++++++++++ js/src/tests/ecma_7/SIMD/float64x2-arithmetic.js | 69 ++ js/src/tests/ecma_7/SIMD/load-floats.js | 19 + js/src/tests/ecma_7/SIMD/load-int16x8.js | 17 + js/src/tests/ecma_7/SIMD/load-int32x4.js | 18 + js/src/tests/ecma_7/SIMD/load-int8x16.js | 17 + js/src/tests/ecma_7/SIMD/load-sab-buffer-compat.js | 49 + js/src/tests/ecma_7/SIMD/load-unsigned-integers.js | 22 + js/src/tests/ecma_7/SIMD/minmax.js | 85 ++ js/src/tests/ecma_7/SIMD/replaceLane.js | 226 ++++ js/src/tests/ecma_7/SIMD/select-bitselect.js | 133 +++ js/src/tests/ecma_7/SIMD/shell.js | 580 +++++++++ js/src/tests/ecma_7/SIMD/shifts.js | 202 ++++ js/src/tests/ecma_7/SIMD/splat.js | 97 ++ js/src/tests/ecma_7/SIMD/store.js | 264 ++++ js/src/tests/ecma_7/SIMD/swizzle-shuffle.js | 507 ++++++++ js/src/tests/ecma_7/SIMD/toString.js | 90 ++ js/src/tests/ecma_7/SIMD/typedobjects.js | 1077 +++++++++++++++++ js/src/tests/ecma_7/SIMD/unary-operations.js | 410 +++++++ 26 files changed, 6811 insertions(+) create mode 100644 js/src/tests/ecma_7/SIMD/ToSource.js create mode 100644 js/src/tests/ecma_7/SIMD/binary-operations.js create mode 100644 js/src/tests/ecma_7/SIMD/bug1023145.js create mode 100644 js/src/tests/ecma_7/SIMD/bug953270.js create mode 100644 js/src/tests/ecma_7/SIMD/check.js create mode 100644 js/src/tests/ecma_7/SIMD/comparisons.js create mode 100644 js/src/tests/ecma_7/SIMD/constructors.js create mode 100644 js/src/tests/ecma_7/SIMD/conversions.js create mode 100644 js/src/tests/ecma_7/SIMD/float64x2-arithmetic.js create mode 100644 js/src/tests/ecma_7/SIMD/load-floats.js create mode 100644 js/src/tests/ecma_7/SIMD/load-int16x8.js create mode 100644 js/src/tests/ecma_7/SIMD/load-int32x4.js create mode 100644 js/src/tests/ecma_7/SIMD/load-int8x16.js create mode 100644 js/src/tests/ecma_7/SIMD/load-sab-buffer-compat.js create mode 100644 js/src/tests/ecma_7/SIMD/load-unsigned-integers.js create mode 100644 js/src/tests/ecma_7/SIMD/minmax.js create mode 100644 js/src/tests/ecma_7/SIMD/replaceLane.js create mode 100644 js/src/tests/ecma_7/SIMD/select-bitselect.js create mode 100644 js/src/tests/ecma_7/SIMD/shell.js create mode 100644 js/src/tests/ecma_7/SIMD/shifts.js create mode 100644 js/src/tests/ecma_7/SIMD/splat.js create mode 100644 js/src/tests/ecma_7/SIMD/store.js create mode 100644 js/src/tests/ecma_7/SIMD/swizzle-shuffle.js create mode 100644 js/src/tests/ecma_7/SIMD/toString.js create mode 100644 js/src/tests/ecma_7/SIMD/typedobjects.js create mode 100644 js/src/tests/ecma_7/SIMD/unary-operations.js (limited to 'js/src/tests/ecma_7/SIMD') diff --git a/js/src/tests/ecma_7/SIMD/ToSource.js b/js/src/tests/ecma_7/SIMD/ToSource.js new file mode 100644 index 000000000..e5efa12a3 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/ToSource.js @@ -0,0 +1,56 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +function test() { + var Float32x4 = SIMD.Float32x4; + var f = Float32x4(11, 22, 33, 44); + assertEq(f.toSource(), "SIMD.Float32x4(11, 22, 33, 44)"); + + var Float64x2 = SIMD.Float64x2; + var f = Float64x2(11, 22, 33, 44); + assertEq(f.toSource(), "SIMD.Float64x2(11, 22)"); + + var Int8x16 = SIMD.Int8x16; + var f = Int8x16(11, 22, 33, 44, -11, -22, -33, -44, 1, 2, 3, 4, -1, -2, -3, -4); + assertEq(f.toSource(), "SIMD.Int8x16(11, 22, 33, 44, -11, -22, -33, -44, 1, 2, 3, 4, -1, -2, -3, -4)"); + + var Int16x8 = SIMD.Int16x8; + var f = Int16x8(11, 22, 33, 44, -11, -22, -33, -44); + assertEq(f.toSource(), "SIMD.Int16x8(11, 22, 33, 44, -11, -22, -33, -44)"); + + var Int32x4 = SIMD.Int32x4; + var f = Int32x4(11, 22, 33, 44); + assertEq(f.toSource(), "SIMD.Int32x4(11, 22, 33, 44)"); + + var Uint8x16 = SIMD.Uint8x16; + var f = Uint8x16(11, 22, 33, 44, 245, 234, 223, 212, 1, 2, 3, 4, 255, 254, 0, 250); + assertEq(f.toSource(), "SIMD.Uint8x16(11, 22, 33, 44, 245, 234, 223, 212, 1, 2, 3, 4, 255, 254, 0, 250)"); + + var Uint16x8 = SIMD.Uint16x8; + var f = Uint16x8(11, 22, 33, 44, 65535, 65534, 65533, 65532); + assertEq(f.toSource(), "SIMD.Uint16x8(11, 22, 33, 44, 65535, 65534, 65533, 65532)"); + + var Uint32x4 = SIMD.Uint32x4; + var f = Uint32x4(11, 22, 4294967295, 4294967294); + assertEq(f.toSource(), "SIMD.Uint32x4(11, 22, 4294967295, 4294967294)"); + + var Bool8x16 = SIMD.Bool8x16; + var f = Bool8x16(true, true, false, false, false, true, true, false, true, true, true, true, false, false, false, false); + assertEq(f.toSource(), "SIMD.Bool8x16(true, true, false, false, false, true, true, false, true, true, true, true, false, false, false, false)"); + + var Bool16x8 = SIMD.Bool16x8; + var f = Bool16x8(true, true, false, false, true, false, false, true); + assertEq(f.toSource(), "SIMD.Bool16x8(true, true, false, false, true, false, false, true)"); + + var Bool32x4 = SIMD.Bool32x4; + var f = Bool32x4(true, true, false, false); + assertEq(f.toSource(), "SIMD.Bool32x4(true, true, false, false)"); + + var Bool64x2 = SIMD.Bool64x2; + var f = Bool64x2(true, false); + assertEq(f.toSource(), "SIMD.Bool64x2(true, false)"); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/binary-operations.js b/js/src/tests/ecma_7/SIMD/binary-operations.js new file mode 100644 index 000000000..04b035309 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/binary-operations.js @@ -0,0 +1,785 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) +var Float32x4 = SIMD.Float32x4; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +// Float32x4. +function testFloat32x4add() { + function addf(a, b) { + return Math.fround(Math.fround(a) + Math.fround(b)); + } + + var vals = [ + [[1, 2, 3, 4], [10, 20, 30, 40]], + [[1.57, 2.27, 3.57, 4.19], [10.31, 20.49, 30.41, 40.72]], + [[NaN, -0, Infinity, -Infinity], [0, -0, -Infinity, -Infinity]] + ]; + + for (var [v,w] of vals) { + testBinaryFunc(Float32x4(...v), Float32x4(...w), Float32x4.add, addf); + } +} + +function testFloat32x4div() { + function divf(a, b) { + return Math.fround(Math.fround(a) / Math.fround(b)); + } + + var vals = [ + [[1, 2, 3, 4], [10, 20, 30, 40]], + [[1.26, 2.03, 3.17, 4.59], [11.025, 17.3768, 29.1957, 46.4049]], + [[0, -0, Infinity, -Infinity], [1, 1, -Infinity, Infinity]] + ]; + + for (var [v,w] of vals) { + testBinaryFunc(Float32x4(...v), Float32x4(...w), Float32x4.div, divf); + } +} + +function testFloat32x4mul() { + function mulf(a, b) { + return Math.fround(Math.fround(a) * Math.fround(b)); + } + + var vals = [ + [[1, 2, 3, 4], [10, 20, 30, 40]], + [[1.66, 2.57, 3.73, 4.12], [10.67, 20.68, 30.02, 40.58]], + [[NaN, -0, Infinity, -Infinity], [NaN, -0, -Infinity, 0]] + ]; + + for (var [v,w] of vals) { + testBinaryFunc(Float32x4(...v), Float32x4(...w), Float32x4.mul, mulf); + } +} + +function testFloat32x4sub() { + function subf(a, b) { + return Math.fround(Math.fround(a) - Math.fround(b)); + } + + var vals = [ + [[1, 2, 3, 4], [10, 20, 30, 40]], + [[1.34, 2.95, 3.17, 4.29], [10.18, 20.43, 30.63, 40.38]], + [[NaN, -0, -Infinity, -Infinity], [NaN, -0, Infinity, -Infinity]] + ]; + + for (var [v,w] of vals) { + testBinaryFunc(Float32x4(...v), Float32x4(...w), Float32x4.sub, subf); + } +} + +// Helper for saturating arithmetic. +// See SIMD.js, 5.1.25 Saturate(descriptor, x) +function saturate(lower, upper, x) { + x = x | 0; + if (x > upper) + return upper; + if (x < lower) + return lower; + return x; +} + +var i8x16vals = [ + [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]], + [[INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, -2, -3, -4, -5, -6, -7, -8, -9], + [1, 1, -1, -1, INT8_MAX, INT8_MAX, INT8_MIN, INT8_MIN, 8, 9, 10, 11, 12, 13, 14, 15]] +]; + +// Int8x16. +function testInt8x16add() { + function addi(a, b) { + return (a + b) << 24 >> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.add, addi); + } +} + +function testInt8x16and() { + function andi(a, b) { + return (a & b) << 24 >> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.and, andi); + } +} + +function testInt8x16mul() { + function muli(x, y) { + return (x * y) << 24 >> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.mul, muli); + } +} + +function testInt8x16or() { + function ori(a, b) { + return (a | b) << 24 >> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.or, ori); + } +} + +function testInt8x16sub() { + function subi(a, b) { + return (a - b) << 24 >> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.sub, subi); + } +} + +function testInt8x16xor() { + function xori(a, b) { + return (a ^ b) << 24 >> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.xor, xori); + } +} + +function testInt8x16addSaturate() { + function satadd(a, b) { + return saturate(INT8_MIN, INT8_MAX, a + b); + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.addSaturate, satadd); + } +} + +function testInt8x16subSaturate() { + function satsub(a, b) { + return saturate(INT8_MIN, INT8_MAX, a - b); + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Int8x16(...v), Int8x16(...w), Int8x16.subSaturate, satsub); + } +} + +// Uint8x16. +function testUint8x16add() { + function addi(a, b) { + return (a + b) << 24 >>> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.add, addi); + } +} + +function testUint8x16and() { + function andi(a, b) { + return (a & b) << 24 >>> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.and, andi); + } +} + +function testUint8x16mul() { + function muli(x, y) { + return (x * y) << 24 >>> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.mul, muli); + } +} + +function testUint8x16or() { + function ori(a, b) { + return (a | b) << 24 >>> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.or, ori); + } +} + +function testUint8x16sub() { + function subi(a, b) { + return (a - b) << 24 >>> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.sub, subi); + } +} + +function testUint8x16xor() { + function xori(a, b) { + return (a ^ b) << 24 >>> 24; + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.xor, xori); + } +} + +function testUint8x16addSaturate() { + function satadd(a, b) { + return saturate(0, UINT8_MAX, a + b); + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.addSaturate, satadd); + } +} + +function testUint8x16subSaturate() { + function satsub(a, b) { + return saturate(0, UINT8_MAX, a - b); + } + + for (var [v,w] of i8x16vals) { + testBinaryFunc(Uint8x16(...v), Uint8x16(...w), Uint8x16.subSaturate, satsub); + } +} + +var i16x8vals = [ + [[1, 2, 3, 4, 5, 6, 7, 8], + [10, 20, 30, 40, 50, 60, 70, 80]], + [[INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN], + [1, 1, -1, -1, INT16_MAX, INT16_MAX, INT16_MIN, INT16_MIN]] +]; + +// Int16x8. +function testInt16x8add() { + function addi(a, b) { + return (a + b) << 16 >> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.add, addi); + } +} + +function testInt16x8and() { + function andi(a, b) { + return (a & b) << 16 >> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.and, andi); + } +} + +function testInt16x8mul() { + function muli(x, y) { + return (x * y) << 16 >> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.mul, muli); + } +} + +function testInt16x8or() { + function ori(a, b) { + return (a | b) << 16 >> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.or, ori); + } +} + +function testInt16x8sub() { + function subi(a, b) { + return (a - b) << 16 >> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.sub, subi); + } +} + +function testInt16x8xor() { + function xori(a, b) { + return (a ^ b) << 16 >> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.xor, xori); + } +} + +function testInt16x8addSaturate() { + function satadd(a, b) { + return saturate(INT16_MIN, INT16_MAX, a + b); + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.addSaturate, satadd); + } +} + +function testInt16x8subSaturate() { + function satsub(a, b) { + return saturate(INT16_MIN, INT16_MAX, a - b); + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Int16x8(...v), Int16x8(...w), Int16x8.subSaturate, satsub); + } +} + +// Uint16x8. +function testUint16x8add() { + function addi(a, b) { + return (a + b) << 16 >>> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.add, addi); + } +} + +function testUint16x8and() { + function andi(a, b) { + return (a & b) << 16 >>> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.and, andi); + } +} + +function testUint16x8mul() { + function muli(x, y) { + return (x * y) << 16 >>> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.mul, muli); + } +} + +function testUint16x8or() { + function ori(a, b) { + return (a | b) << 16 >>> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.or, ori); + } +} + +function testUint16x8sub() { + function subi(a, b) { + return (a - b) << 16 >>> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.sub, subi); + } +} + +function testUint16x8xor() { + function xori(a, b) { + return (a ^ b) << 16 >>> 16; + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.xor, xori); + } +} + +function testUint16x8addSaturate() { + function satadd(a, b) { + return saturate(0, UINT16_MAX, a + b); + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.addSaturate, satadd); + } +} + +function testUint16x8subSaturate() { + function satsub(a, b) { + return saturate(0, UINT16_MAX, a - b); + } + + for (var [v,w] of i16x8vals) { + testBinaryFunc(Uint16x8(...v), Uint16x8(...w), Uint16x8.subSaturate, satsub); + } +} + +var i32x4vals = [ + [[1, 2, 3, 4], [10, 20, 30, 40]], + [[INT32_MAX, INT32_MIN, INT32_MAX, INT32_MIN], [1, -1, 0, 0]], + [[INT32_MAX, INT32_MIN, INT32_MAX, INT32_MIN], [INT32_MIN, INT32_MAX, INT32_MAX, INT32_MIN]], + [[INT32_MAX, INT32_MIN, INT32_MAX, INT32_MIN], [-1, -1, INT32_MIN, INT32_MIN]], + [[INT32_MAX, INT32_MIN, INT32_MAX, INT32_MIN], [-1, 1, INT32_MAX, INT32_MIN]], + [[UINT32_MAX, 0, UINT32_MAX, 0], [1, -1, 0, 0]], + [[UINT32_MAX, 0, UINT32_MAX, 0], [-1, -1, INT32_MIN, INT32_MIN]], + [[UINT32_MAX, 0, UINT32_MAX, 0], [1, -1, 0, 0]], + [[UINT32_MAX, 0, UINT32_MAX, 0], [-1, 1, INT32_MAX, INT32_MIN]] +]; + +// Int32x4. +function testInt32x4add() { + function addi(a, b) { + return (a + b) | 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Int32x4(...v), Int32x4(...w), Int32x4.add, addi); + } +} + +function testInt32x4and() { + function andi(a, b) { + return (a & b) | 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Int32x4(...v), Int32x4(...w), Int32x4.and, andi); + } +} + +function testInt32x4mul() { + function muli(x, y) { + // Deal with lost precision in the 53-bit double mantissa. + // Compute two 48-bit products. Truncate and combine them. + var hi = (x * (y >>> 16)) | 0; + var lo = (x * (y & 0xffff)) | 0; + return (lo + (hi << 16)) | 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Int32x4(...v), Int32x4(...w), Int32x4.mul, muli); + } +} + +function testInt32x4or() { + function ori(a, b) { + return (a | b) | 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Int32x4(...v), Int32x4(...w), Int32x4.or, ori); + } +} + +function testInt32x4sub() { + function subi(a, b) { + return (a - b) | 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Int32x4(...v), Int32x4(...w), Int32x4.sub, subi); + } +} + +function testInt32x4xor() { + function xori(a, b) { + return (a ^ b) | 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Int32x4(...v), Int32x4(...w), Int32x4.xor, xori); + } +} + +// Uint32x4. +function testUint32x4add() { + function addi(a, b) { + return (a + b) >>> 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Uint32x4(...v), Uint32x4(...w), Uint32x4.add, addi); + } +} + +function testUint32x4and() { + function andi(a, b) { + return (a & b) >>> 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Uint32x4(...v), Uint32x4(...w), Uint32x4.and, andi); + } +} + +function testUint32x4mul() { + function muli(x, y) { + // Deal with lost precision in the 53-bit double mantissa. + // Compute two 48-bit products. Truncate and combine them. + var hi = (x * (y >>> 16)) >>> 0; + var lo = (x * (y & 0xffff)) >>> 0; + return (lo + (hi << 16)) >>> 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Uint32x4(...v), Uint32x4(...w), Uint32x4.mul, muli); + } +} + +function testUint32x4or() { + function ori(a, b) { + return (a | b) >>> 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Uint32x4(...v), Uint32x4(...w), Uint32x4.or, ori); + } +} + +function testUint32x4sub() { + function subi(a, b) { + return (a - b) >>> 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Uint32x4(...v), Uint32x4(...w), Uint32x4.sub, subi); + } +} + +function testUint32x4xor() { + function xori(a, b) { + return (a ^ b) >>> 0; + } + + for (var [v,w] of i32x4vals) { + testBinaryFunc(Uint32x4(...v), Uint32x4(...w), Uint32x4.xor, xori); + } +} + +var b8x16vals = [ + [[true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false], + [false, true, false, true, false, true, false, true, true, true, true, true, false, false, false, false]] +]; + +function testBool8x16and() { + function andb(a, b) { + return a && b; + } + + for (var [v,w] of b8x16vals) { + testBinaryFunc(Bool8x16(...v), Bool8x16(...w), Bool8x16.and, andb); + } +} + +function testBool8x16or() { + function orb(a, b) { + return a || b; + } + + for (var [v,w] of b8x16vals) { + testBinaryFunc(Bool8x16(...v), Bool8x16(...w), Bool8x16.or, orb); + } +} + +function testBool8x16xor() { + function xorb(a, b) { + return a != b; + } + + for (var [v,w] of b8x16vals) { + testBinaryFunc(Bool8x16(...v), Bool8x16(...w), Bool8x16.xor, xorb); + } +} + +var b16x8vals = [ + [[true, true, true, true, false, false, false, false], + [false, true, false, true, false, true, false, true]] +]; + +function testBool16x8and() { + function andb(a, b) { + return a && b; + } + + for (var [v,w] of b16x8vals) { + testBinaryFunc(Bool16x8(...v), Bool16x8(...w), Bool16x8.and, andb); + } +} + +function testBool16x8or() { + function orb(a, b) { + return a || b; + } + + for (var [v,w] of b16x8vals) { + testBinaryFunc(Bool16x8(...v), Bool16x8(...w), Bool16x8.or, orb); + } +} + +function testBool16x8xor() { + function xorb(a, b) { + return a != b; + } + + for (var [v,w] of b16x8vals) { + testBinaryFunc(Bool16x8(...v), Bool16x8(...w), Bool16x8.xor, xorb); + } +} + +var b32x4vals = [ + [[true, true, false, false], [false, true, false, true]] +]; + +function testBool32x4and() { + function andb(a, b) { + return a && b; + } + + for (var [v,w] of b32x4vals) { + testBinaryFunc(Bool32x4(...v), Bool32x4(...w), Bool32x4.and, andb); + } +} + +function testBool32x4or() { + function orb(a, b) { + return a || b; + } + + for (var [v,w] of b32x4vals) { + testBinaryFunc(Bool32x4(...v), Bool32x4(...w), Bool32x4.or, orb); + } +} + +function testBool32x4xor() { + function xorb(a, b) { + return a != b; + } + + for (var [v,w] of b32x4vals) { + testBinaryFunc(Bool32x4(...v), Bool32x4(...w), Bool32x4.xor, xorb); + } +} + +var b64x2vals = [ + [[false, false], [false, true], [true, false], [true, true]] +]; + +function testBool64x2and() { + function andb(a, b) { + return a && b; + } + + for (var [v,w] of b64x2vals) { + testBinaryFunc(Bool64x2(...v), Bool64x2(...w), Bool64x2.and, andb); + } +} + +function testBool64x2or() { + function orb(a, b) { + return a || b; + } + + for (var [v,w] of b64x2vals) { + testBinaryFunc(Bool64x2(...v), Bool64x2(...w), Bool64x2.or, orb); + } +} + +function testBool64x2xor() { + function xorb(a, b) { + return a != b; + } + + for (var [v,w] of b64x2vals) { + testBinaryFunc(Bool64x2(...v), Bool64x2(...w), Bool64x2.xor, xorb); + } +} + +function test() { + testFloat32x4add(); + testFloat32x4div(); + testFloat32x4mul(); + testFloat32x4sub(); + + testInt8x16add(); + testInt8x16and(); + testInt8x16mul(); + testInt8x16or(); + testInt8x16sub(); + testInt8x16xor(); + testInt8x16addSaturate(); + testInt8x16subSaturate(); + + testUint8x16add(); + testUint8x16and(); + testUint8x16mul(); + testUint8x16or(); + testUint8x16sub(); + testUint8x16xor(); + testUint8x16addSaturate(); + testUint8x16subSaturate(); + + testInt16x8add(); + testInt16x8and(); + testInt16x8mul(); + testInt16x8or(); + testInt16x8sub(); + testInt16x8xor(); + testInt16x8addSaturate(); + testInt16x8subSaturate(); + + testUint16x8add(); + testUint16x8and(); + testUint16x8mul(); + testUint16x8or(); + testUint16x8sub(); + testUint16x8xor(); + testUint16x8addSaturate(); + testUint16x8subSaturate(); + + testInt32x4add(); + testInt32x4and(); + testInt32x4mul(); + testInt32x4or(); + testInt32x4sub(); + testInt32x4xor(); + + testUint32x4add(); + testUint32x4and(); + testUint32x4mul(); + testUint32x4or(); + testUint32x4sub(); + testUint32x4xor(); + + testBool8x16and(); + testBool8x16or(); + testBool8x16xor(); + + testBool16x8and(); + testBool16x8or(); + testBool16x8xor(); + + testBool32x4and(); + testBool32x4or(); + testBool32x4xor(); + + testBool64x2and(); + testBool64x2or(); + testBool64x2xor(); + + if (typeof reportCompare === "function") { + reportCompare(true, true); + } +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/bug1023145.js b/js/src/tests/ecma_7/SIMD/bug1023145.js new file mode 100644 index 000000000..45f44afb5 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/bug1023145.js @@ -0,0 +1,14 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +delete Object.prototype.__proto__; +var Int32x4 = SIMD.Int32x4; +var ar = Int32x4.array(1); +var array = new ar([Int32x4(1, 2, 3, 4)]); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/bug953270.js b/js/src/tests/ecma_7/SIMD/bug953270.js new file mode 100644 index 000000000..db6a0d7cb --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/bug953270.js @@ -0,0 +1,24 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +// Check that NaN normalization is applied when extracting the x lane +// out, after bit conversion has occurred. + +var Int32x4 = SIMD.Int32x4; +var a = Int32x4((4294967295), 200, 300, 400); +var c = SIMD.Float32x4.fromInt32x4Bits(a); + +// NaN canonicalization occurs when extracting out x lane: +assertEq(SIMD.Float32x4.extractLane(c, 0), NaN); + +// but underlying bits are faithfully transmitted +// (though reinterpreted as a signed integer): +var d = SIMD.Int32x4.fromFloat32x4Bits(c); +assertEq(SIMD.Int32x4.extractLane(d, 0), -1); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/check.js b/js/src/tests/ecma_7/SIMD/check.js new file mode 100644 index 000000000..77ef381be --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/check.js @@ -0,0 +1,214 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +function test() { + + var i4 = SIMD.Int32x4(1,2,3,4); + var i8 = SIMD.Int16x8(1,2,3,4,5,6,7,8); + var i16 = SIMD.Int8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); + var u4 = SIMD.Uint32x4(1,2,3,4); + var u8 = SIMD.Uint16x8(1,2,3,4,5,6,7,8); + var u16 = SIMD.Uint8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); + var f4 = SIMD.Float32x4(NaN, -0, Infinity, 13.37); + var f2 = SIMD.Float64x2(-0, 13.37); + var b2 = SIMD.Bool64x2(true, false); + var b4 = SIMD.Bool32x4(true, true, false, false); + var b8 = SIMD.Bool16x8(true, true, false, false, true, true, false, false); + var b16 = SIMD.Bool8x16(true, true, false, false, true, true, false, false, true, true, false, false, true, true, false, false); + + 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(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.check({}), TypeError); + + var ci8 = SIMD.Int16x8.check(i8); + assertEqX8(ci8, simdToArray(i8)); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.check({}), TypeError); + + var ci16 = SIMD.Int8x16.check(i16); + assertEqX16(ci16, simdToArray(i16)); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.check({}), TypeError); + + var cu4 = SIMD.Uint32x4.check(u4); + assertEqX4(cu4, simdToArray(u4)); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.check({}), TypeError); + + var cu8 = SIMD.Uint16x8.check(u8); + assertEqX8(cu8, simdToArray(u8)); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.check({}), TypeError); + + var cu16 = SIMD.Uint8x16.check(u16); + assertEqX16(cu16, simdToArray(u16)); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.check({}), TypeError); + + var cf4 = SIMD.Float32x4.check(f4); + assertEqX4(cf4, simdToArray(f4)); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.check(b16), 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(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.check({}), TypeError); + + var cb2 = SIMD.Bool64x2.check(b2); + assertEqX2(cb2, simdToArray(b2)); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool64x2.check({}), TypeError); + + var cb4 = SIMD.Bool32x4.check(b4); + assertEqX4(cb4, simdToArray(b4)); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool32x4.check({}), TypeError); + + var cb8 = SIMD.Bool16x8.check(b8); + assertEqX8(cb8, simdToArray(b8)); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check(b16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool16x8.check({}), TypeError); + + var cb16 = SIMD.Bool8x16.check(b16); + assertEqX16(cb16, simdToArray(b16)); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(f4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(f2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(i4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(i8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(i16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(u4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(u8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(u16), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(b2), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(b4), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check(b8), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check("i swear i'm a vector"), TypeError); + assertThrowsInstanceOf(() => SIMD.Bool8x16.check({}), TypeError); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); + diff --git a/js/src/tests/ecma_7/SIMD/comparisons.js b/js/src/tests/ecma_7/SIMD/comparisons.js new file mode 100644 index 000000000..2ca54b14e --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/comparisons.js @@ -0,0 +1,349 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +var fround = Math.fround; + + +function testEqualFloat32x4(v, w) { + testBinaryCompare(v, w, Float32x4.equal, (x, y) => fround(x) == fround(y), Bool32x4); +} +function testNotEqualFloat32x4(v, w) { + testBinaryCompare(v, w, Float32x4.notEqual, (x, y) => fround(x) != fround(y), Bool32x4); +} +function testLessThanFloat32x4(v, w) { + testBinaryCompare(v, w, Float32x4.lessThan, (x, y) => fround(x) < fround(y), Bool32x4); +} +function testLessThanOrEqualFloat32x4(v, w) { + testBinaryCompare(v, w, Float32x4.lessThanOrEqual, (x, y) => fround(x) <= fround(y), Bool32x4); +} +function testGreaterThanFloat32x4(v, w) { + testBinaryCompare(v, w, Float32x4.greaterThan, (x, y) => fround(x) > fround(y), Bool32x4); +} +function testGreaterThanOrEqualFloat32x4(v, w) { + testBinaryCompare(v, w, Float32x4.greaterThanOrEqual, (x, y) => fround(x) >= fround(y), Bool32x4); +} + +function testEqualFloat64x2(v, w) { + testBinaryCompare(v, w, Float64x2.equal, (x, y) => x == y, Bool64x2); +} +function testNotEqualFloat64x2(v, w) { + testBinaryCompare(v, w, Float64x2.notEqual, (x, y) => x != y, Bool64x2); +} +function testLessThanFloat64x2(v, w) { + testBinaryCompare(v, w, Float64x2.lessThan, (x, y) => x < y, Bool64x2); +} +function testLessThanOrEqualFloat64x2(v, w) { + testBinaryCompare(v, w, Float64x2.lessThanOrEqual, (x, y) => x <= y, Bool64x2); +} +function testGreaterThanFloat64x2(v, w) { + testBinaryCompare(v, w, Float64x2.greaterThan, (x, y) => x > y, Bool64x2); +} +function testGreaterThanOrEqualFloat64x2(v, w) { + testBinaryCompare(v, w, Float64x2.greaterThanOrEqual, (x, y) => x >= y, Bool64x2); +} + +function testEqualInt8x16(v, w) { + testBinaryCompare(v, w, Int8x16.equal, (x, y) => x == y, Bool8x16); +} +function testNotEqualInt8x16(v, w) { + testBinaryCompare(v, w, Int8x16.notEqual, (x, y) => x != y, Bool8x16); +} +function testLessThanInt8x16(v, w) { + testBinaryCompare(v, w, Int8x16.lessThan, (x, y) => x < y, Bool8x16); +} +function testLessThanOrEqualInt8x16(v, w) { + testBinaryCompare(v, w, Int8x16.lessThanOrEqual, (x, y) => x <= y, Bool8x16); +} +function testGreaterThanInt8x16(v, w) { + testBinaryCompare(v, w, Int8x16.greaterThan, (x, y) => x > y, Bool8x16); +} +function testGreaterThanOrEqualInt8x16(v, w) { + testBinaryCompare(v, w, Int8x16.greaterThanOrEqual, (x, y) => x >= y, Bool8x16); +} + +function testEqualInt16x8(v, w) { + testBinaryCompare(v, w, Int16x8.equal, (x, y) => x == y, Bool16x8); +} +function testNotEqualInt16x8(v, w) { + testBinaryCompare(v, w, Int16x8.notEqual, (x, y) => x != y, Bool16x8); +} +function testLessThanInt16x8(v, w) { + testBinaryCompare(v, w, Int16x8.lessThan, (x, y) => x < y, Bool16x8); +} +function testLessThanOrEqualInt16x8(v, w) { + testBinaryCompare(v, w, Int16x8.lessThanOrEqual, (x, y) => x <= y, Bool16x8); +} +function testGreaterThanInt16x8(v, w) { + testBinaryCompare(v, w, Int16x8.greaterThan, (x, y) => x > y, Bool16x8); +} +function testGreaterThanOrEqualInt16x8(v, w) { + testBinaryCompare(v, w, Int16x8.greaterThanOrEqual, (x, y) => x >= y, Bool16x8); +} + +function testEqualInt32x4(v, w) { + testBinaryCompare(v, w, Int32x4.equal, (x, y) => x == y, Bool32x4); +} +function testNotEqualInt32x4(v, w) { + testBinaryCompare(v, w, Int32x4.notEqual, (x, y) => x != y, Bool32x4); +} +function testLessThanInt32x4(v, w) { + testBinaryCompare(v, w, Int32x4.lessThan, (x, y) => x < y, Bool32x4); +} +function testLessThanOrEqualInt32x4(v, w) { + testBinaryCompare(v, w, Int32x4.lessThanOrEqual, (x, y) => x <= y, Bool32x4); +} +function testGreaterThanInt32x4(v, w) { + testBinaryCompare(v, w, Int32x4.greaterThan, (x, y) => x > y, Bool32x4); +} +function testGreaterThanOrEqualInt32x4(v, w) { + testBinaryCompare(v, w, Int32x4.greaterThanOrEqual, (x, y) => x >= y, Bool32x4); +} + +function testEqualUint8x16(v, w) { + testBinaryCompare(v, w, Uint8x16.equal, (x, y) => x == y, Bool8x16); +} +function testNotEqualUint8x16(v, w) { + testBinaryCompare(v, w, Uint8x16.notEqual, (x, y) => x != y, Bool8x16); +} +function testLessThanUint8x16(v, w) { + testBinaryCompare(v, w, Uint8x16.lessThan, (x, y) => x < y, Bool8x16); +} +function testLessThanOrEqualUint8x16(v, w) { + testBinaryCompare(v, w, Uint8x16.lessThanOrEqual, (x, y) => x <= y, Bool8x16); +} +function testGreaterThanUint8x16(v, w) { + testBinaryCompare(v, w, Uint8x16.greaterThan, (x, y) => x > y, Bool8x16); +} +function testGreaterThanOrEqualUint8x16(v, w) { + testBinaryCompare(v, w, Uint8x16.greaterThanOrEqual, (x, y) => x >= y, Bool8x16); +} + +function testEqualUint16x8(v, w) { + testBinaryCompare(v, w, Uint16x8.equal, (x, y) => x == y, Bool16x8); +} +function testNotEqualUint16x8(v, w) { + testBinaryCompare(v, w, Uint16x8.notEqual, (x, y) => x != y, Bool16x8); +} +function testLessThanUint16x8(v, w) { + testBinaryCompare(v, w, Uint16x8.lessThan, (x, y) => x < y, Bool16x8); +} +function testLessThanOrEqualUint16x8(v, w) { + testBinaryCompare(v, w, Uint16x8.lessThanOrEqual, (x, y) => x <= y, Bool16x8); +} +function testGreaterThanUint16x8(v, w) { + testBinaryCompare(v, w, Uint16x8.greaterThan, (x, y) => x > y, Bool16x8); +} +function testGreaterThanOrEqualUint16x8(v, w) { + testBinaryCompare(v, w, Uint16x8.greaterThanOrEqual, (x, y) => x >= y, Bool16x8); +} + +function testEqualUint32x4(v, w) { + testBinaryCompare(v, w, Uint32x4.equal, (x, y) => x == y, Bool32x4); +} +function testNotEqualUint32x4(v, w) { + testBinaryCompare(v, w, Uint32x4.notEqual, (x, y) => x != y, Bool32x4); +} +function testLessThanUint32x4(v, w) { + testBinaryCompare(v, w, Uint32x4.lessThan, (x, y) => x < y, Bool32x4); +} +function testLessThanOrEqualUint32x4(v, w) { + testBinaryCompare(v, w, Uint32x4.lessThanOrEqual, (x, y) => x <= y, Bool32x4); +} +function testGreaterThanUint32x4(v, w) { + testBinaryCompare(v, w, Uint32x4.greaterThan, (x, y) => x > y, Bool32x4); +} +function testGreaterThanOrEqualUint32x4(v, w) { + testBinaryCompare(v, w, Uint32x4.greaterThanOrEqual, (x, y) => x >= y, Bool32x4); +} + +function test() { + var Float32x4val = [ + Float32x4(1, 20, 30, 4), + Float32x4(10, 2, 3, 40), + Float32x4(9.999, 2.1234, 30.4443, 4), + Float32x4(10, 2.1233, 30.4444, 4.0001), + Float32x4(NaN, -Infinity, +Infinity, -0), + Float32x4(+Infinity, NaN, -0, -Infinity), + Float32x4(13.37, 42.42, NaN, 0) + ]; + + var v, w; + for (v of Float32x4val) { + for (w of Float32x4val) { + testEqualFloat32x4(v, w); + testNotEqualFloat32x4(v, w); + testLessThanFloat32x4(v, w); + testLessThanOrEqualFloat32x4(v, w); + testGreaterThanFloat32x4(v, w); + testGreaterThanOrEqualFloat32x4(v, w); + } + } + + var Float64x2val = [ + Float64x2(1, 20), + Float64x2(10, 2), + Float64x2(9.999, 2.1234), + Float64x2(10, 2.1233), + Float64x2(30.4443, 4), + Float64x2(30.4444, 4.0001), + Float64x2(NaN, -Infinity), + Float64x2(+Infinity, NaN), + Float64x2(+Infinity, -0), + Float64x2(-0, -Infinity), + Float64x2(13.37, 42.42), + Float64x2(NaN, 0) + ]; + + for (v of Float64x2val) { + for (w of Float64x2val) { + testEqualFloat64x2(v, w); + testNotEqualFloat64x2(v, w); + testLessThanFloat64x2(v, w); + testLessThanOrEqualFloat64x2(v, w); + testGreaterThanFloat64x2(v, w); + testGreaterThanOrEqualFloat64x2(v, w); + } + } + + var Int8x16val = [ + Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Int8x16(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16), + Int8x16(-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16), + Int8x16(1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16), + Int8x16(INT8_MAX, INT8_MAX, INT8_MIN, INT8_MIN, INT8_MIN + 1, INT8_MAX - 1, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16), + Int8x16(INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX - 1, INT8_MIN + 1, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16) + ]; + + for (v of Int8x16val) { + for (w of Int8x16val) { + testEqualInt8x16(v, w); + testNotEqualInt8x16(v, w); + testLessThanInt8x16(v, w); + testLessThanOrEqualInt8x16(v, w); + testGreaterThanInt8x16(v, w); + testGreaterThanOrEqualInt8x16(v, w); + } + } + + var Int16x8val = [ + Int16x8(1, 2, 3, 4, 5, 6, 7, 8), + Int16x8(-1, -2, -3, -4, -5, -6, -7, -8), + Int16x8(-1, 2, -3, 4, -5, 6, -7, 8), + Int16x8(1, -2, 3, -4, 5, -6, 7, -8), + Int16x8(INT16_MAX, INT16_MAX, INT16_MIN, INT16_MIN, INT16_MIN + 1, INT16_MAX - 1, -7, -8), + Int16x8(INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX - 1, INT16_MIN + 1, 7, -8) + ]; + + for (v of Int16x8val) { + for (w of Int16x8val) { + testEqualInt16x8(v, w); + testNotEqualInt16x8(v, w); + testLessThanInt16x8(v, w); + testLessThanOrEqualInt16x8(v, w); + testGreaterThanInt16x8(v, w); + testGreaterThanOrEqualInt16x8(v, w); + } + } + + var Int32x4val = [ + Int32x4(1, 2, 3, 4), + Int32x4(-1, -2, -3, -4), + Int32x4(-1, 2, -3, 4), + Int32x4(1, -2, 3, -4), + Int32x4(INT32_MAX, INT32_MAX, INT32_MIN, INT32_MIN), + Int32x4(INT32_MAX, INT32_MIN, INT32_MAX, INT32_MIN) + ]; + + for (v of Int32x4val) { + for (w of Int32x4val) { + testEqualInt32x4(v, w); + testNotEqualInt32x4(v, w); + testLessThanInt32x4(v, w); + testLessThanOrEqualInt32x4(v, w); + testGreaterThanInt32x4(v, w); + testGreaterThanOrEqualInt32x4(v, w); + } + } + + var Uint8x16val = [ + Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Uint8x16(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16), + Uint8x16(-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16), + Uint8x16(1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16), + Uint8x16(UINT8_MAX, UINT8_MAX, 0, 0, 0 + 1, UINT8_MAX - 1, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16), + Uint8x16(UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX - 1, 0 + 1, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16) + ]; + + for (v of Uint8x16val) { + for (w of Uint8x16val) { + testEqualUint8x16(v, w); + testNotEqualUint8x16(v, w); + testLessThanUint8x16(v, w); + testLessThanOrEqualUint8x16(v, w); + testGreaterThanUint8x16(v, w); + testGreaterThanOrEqualUint8x16(v, w); + } + } + + var Uint16x8val = [ + Uint16x8(1, 2, 3, 4, 5, 6, 7, 8), + Uint16x8(-1, -2, -3, -4, -5, -6, -7, -8), + Uint16x8(-1, 2, -3, 4, -5, 6, -7, 8), + Uint16x8(1, -2, 3, -4, 5, -6, 7, -8), + Uint16x8(UINT16_MAX, UINT16_MAX, 0, 0, 0 + 1, UINT16_MAX - 1, -7, -8), + Uint16x8(UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX - 1, 0 + 1, 7, -8) + ]; + + for (v of Uint16x8val) { + for (w of Uint16x8val) { + testEqualUint16x8(v, w); + testNotEqualUint16x8(v, w); + testLessThanUint16x8(v, w); + testLessThanOrEqualUint16x8(v, w); + testGreaterThanUint16x8(v, w); + testGreaterThanOrEqualUint16x8(v, w); + } + } + + var Uint32x4val = [ + Uint32x4(1, 2, 3, 4), + Uint32x4(-1, -2, -3, -4), + Uint32x4(-1, 2, -3, 4), + Uint32x4(1, -2, 3, -4), + Uint32x4(UINT32_MAX, UINT32_MAX, 0, 0), + Uint32x4(UINT32_MAX, 0, UINT32_MAX, 0) + ]; + + for (v of Uint32x4val) { + for (w of Uint32x4val) { + testEqualUint32x4(v, w); + testNotEqualUint32x4(v, w); + testLessThanUint32x4(v, w); + testLessThanOrEqualUint32x4(v, w); + testGreaterThanUint32x4(v, w); + testGreaterThanOrEqualUint32x4(v, w); + } + } + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/constructors.js b/js/src/tests/ecma_7/SIMD/constructors.js new file mode 100644 index 000000000..a10edb343 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/constructors.js @@ -0,0 +1,226 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +var Float64x2 = SIMD.Float64x2; +var Float32x4 = SIMD.Float32x4; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +function TestInt8x16Ctor() { + // Constructors. + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), [1,2,3,4,5,6,7,8,9,10,11,12,13,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), [1,2,3,4,5,6,7,8,9,10,11,12,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), [1,2,3,4,5,6,7,8,9,10,11,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), [1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9), [1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8), [1,2,3,4,5,6,7,8,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7), [1,2,3,4,5,6,7,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6), [1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5), [1,2,3,4,5,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4), [1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3), [1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2), [1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1), [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); + assertEqX16(Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); +} + +function TestInt16x8Ctor() { + // Constructors. + assertEqX8(Int16x8(1, 2, 3, 4, 5, 6, 7, 8), [1,2,3,4,5,6,7,8]); + assertEqX8(Int16x8(1, 2, 3, 4, 5, 6, 7), [1,2,3,4,5,6,7,0]); + assertEqX8(Int16x8(1, 2, 3, 4, 5, 6), [1,2,3,4,5,6,0,0]); + assertEqX8(Int16x8(1, 2, 3, 4, 5), [1,2,3,4,5,0,0,0]); + assertEqX8(Int16x8(1, 2, 3, 4), [1,2,3,4,0,0,0,0]); + assertEqX8(Int16x8(1, 2, 3), [1,2,3,0,0,0,0,0]); + assertEqX8(Int16x8(1, 2), [1,2,0,0,0,0,0,0]); + assertEqX8(Int16x8(1), [1,0,0,0,0,0,0,0]); + assertEqX8(Int16x8(), [0,0,0,0,0,0,0,0]); + assertEqX8(Int16x8(1, 2, 3, 4, 5, 6, 7, 8, 9), [1,2,3,4,5,6,7,8]); + assertEqX8(Int16x8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), [1,2,3,4,5,6,7,8]); +} + +function TestInt32x4Ctor() { + // 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]); + assertEqX4(Int32x4(1), [1,0,0,0]); + 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]); +} + +function TestUint8x16Ctor() { + // Constructors. + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), [1,2,3,4,5,6,7,8,9,10,11,12,13,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), [1,2,3,4,5,6,7,8,9,10,11,12,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), [1,2,3,4,5,6,7,8,9,10,11,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), [1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9), [1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8), [1,2,3,4,5,6,7,8,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7), [1,2,3,4,5,6,7,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6), [1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5), [1,2,3,4,5,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4), [1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3), [1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2), [1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1), [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); + assertEqX16(Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); +} + +function TestUint16x8Ctor() { + // Constructors. + assertEqX8(Uint16x8(1, 2, 3, 4, 5, 6, 7, 8), [1,2,3,4,5,6,7,8]); + assertEqX8(Uint16x8(1, 2, 3, 4, 5, 6, 7), [1,2,3,4,5,6,7,0]); + assertEqX8(Uint16x8(1, 2, 3, 4, 5, 6), [1,2,3,4,5,6,0,0]); + assertEqX8(Uint16x8(1, 2, 3, 4, 5), [1,2,3,4,5,0,0,0]); + assertEqX8(Uint16x8(1, 2, 3, 4), [1,2,3,4,0,0,0,0]); + assertEqX8(Uint16x8(1, 2, 3), [1,2,3,0,0,0,0,0]); + assertEqX8(Uint16x8(1, 2), [1,2,0,0,0,0,0,0]); + assertEqX8(Uint16x8(1), [1,0,0,0,0,0,0,0]); + assertEqX8(Uint16x8(), [0,0,0,0,0,0,0,0]); + assertEqX8(Uint16x8(1, 2, 3, 4, 5, 6, 7, 8, 9), [1,2,3,4,5,6,7,8]); + assertEqX8(Uint16x8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), [1,2,3,4,5,6,7,8]); +} + +function TestUint32x4Ctor() { + // Constructors. + assertEqX4(Uint32x4(1, 2, 3, 4), [1,2,3,4]); + assertEqX4(Uint32x4(1, 2, 3), [1,2,3,0]); + assertEqX4(Uint32x4(1, 2), [1,2,0,0]); + assertEqX4(Uint32x4(1), [1,0,0,0]); + assertEqX4(Uint32x4(), [0,0,0,0]); + assertEqX4(Uint32x4(1, 2, 3, 4, 5), [1,2,3,4]); + assertEqX4(Uint32x4(1, 2, 3, 4, 5, 6), [1,2,3,4]); +} + +function TestFloat32x4Ctor() { + 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]); + assertEqX4(Float32x4(1), [1,NaN,NaN,NaN]); + 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]); +} + +function TestFloat64x2Ctor() { + assertEqX2(Float64x2(1, 2), [1,2]); + assertEqX2(Float64x2(1), [1,NaN]); + assertEqX2(Float64x2(), [NaN,NaN]); + assertEqX2(Float64x2(1, 2, 3), [1,2]); + assertEqX2(Float64x2(1, 2, 3, 4), [1,2]); + assertEqX2(Float64x2(1, 2, 3, 4, 5), [1,2]); + assertEqX2(Float64x2(1, 2, 3, 4, 5), [1,2]); + assertEqX2(Float64x2(1, 2, 3, 4, 5, 6), [1,2]); +} + +function TestBool8x16Ctor() { + assertEqX16(Bool8x16(false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true), + [false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true]); + assertEqX16(Bool8x16(false, true, true, false, false, true, true, false, false, true, true, false, false, true, true), + [false, true, true, false, false, true, true, false, false, true, true, false, false, true, true, false]); + assertEqX16(Bool8x16(true, true, false, false, true, true, false, false, true, true, false, false, true, true), + [true, true, false, false, true, true, false, false, true, true, false, false, true, true, false, false]); + assertEqX16(Bool8x16(true, false, false, true, true, false, false, true, true, false, false, true, true), + [true, false, false, true, true, false, false, true, true, false, false, true, true, false, false, false]); + assertEqX16(Bool8x16(false, false, true, true, false, false, true, true, false, false, true, true), + [false, false, true, true, false, false, true, true, false, false, true, true, false, false, false, false]); + assertEqX16(Bool8x16(false, true, true, false, false, true, true, false, false, true, true), + [false, true, true, false, false, true, true, false, false, true, true, false, false, false, false, false]); + assertEqX16(Bool8x16(true, true, false, false, true, true, false, false, true, true), + [true, true, false, false, true, true, false, false, true, true, false, false, false, false, false, false]); + assertEqX16(Bool8x16(true, false, false, true, true, false, false, true, true), + [true, false, false, true, true, false, false, true, true, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(false, false, true, true, false, false, true, true), + [false, false, true, true, false, false, true, true, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(false, true, true, false, false, true, true), + [false, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(true, true, false, false, true, true), + [true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(true, false, false, true, true), + [true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(false, false, true, true), + [false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(false, true, true), + [false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(true, true), + [true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(true), + [true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(), + [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16(false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true, false), + [false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true]); + assertEqX16(Bool8x16(false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true, false, true), + [false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true]); +} + +function TestBool16x8Ctor() { + assertEqX8(Bool16x8(false, false, true, true, false, false, true, true), [false, false, true, true, false, false, true, true]); + assertEqX8(Bool16x8(false, true, true, false, false, true, true), [false, true, true, false, false, true, true, false]); + assertEqX8(Bool16x8(true, true, false, false, true, true), [true, true, false, false, true, true, false, false]); + assertEqX8(Bool16x8(true, false, false, true, true), [true, false, false, true, true, false, false, false]); + assertEqX8(Bool16x8(false, false, true, true), [false, false, true, true, false, false, false, false]); + assertEqX8(Bool16x8(false, true, true), [false, true, true, false, false, false, false, false]); + assertEqX8(Bool16x8(true, true), [true, true, false, false, false, false, false, false]); + assertEqX8(Bool16x8(true), [true, false, false, false, false, false, false, false]); + assertEqX8(Bool16x8(), [false, false, false, false, false, false, false, false]); + assertEqX8(Bool16x8(false, false, true, true, false, false, true, true, true), [false, false, true, true, false, false, true, true]); + assertEqX8(Bool16x8(false, false, true, true, false, false, true, true, true, true), [false, false, true, true, false, false, true, true]); +} + +function TestBool32x4Ctor() { + assertEqX4(Bool32x4(false, false, true, true), [false, false, true, true]); + assertEqX4(Bool32x4(false, false, true), [false, false, true, false]); + assertEqX4(Bool32x4(false, true), [false, true, false, false]); + assertEqX4(Bool32x4(true), [true, false, false, false]); + assertEqX4(Bool32x4(), [false, false, false, false]); + assertEqX4(Bool32x4(false, false, true, true, false), [false, false, true, true]); + assertEqX4(Bool32x4(false, false, true, true, false, true), [false, false, true, true]); +} + +function TestBool64x2Ctor() { + assertEqX2(Bool64x2(false, true), [false, true]); + assertEqX2(Bool64x2(true), [true, false]); + assertEqX2(Bool64x2(), [false, false]); + assertEqX2(Bool64x2(false, true, true), [false, true]); + assertEqX2(Bool64x2(false, true, true, true), [false, true]); +} + +function test() { + TestFloat32x4Ctor(); + TestFloat64x2Ctor(); + TestInt8x16Ctor(); + TestInt16x8Ctor(); + TestInt32x4Ctor(); + TestUint8x16Ctor(); + TestUint16x8Ctor(); + TestUint32x4Ctor(); + TestBool8x16Ctor(); + TestBool16x8Ctor(); + TestBool32x4Ctor(); + TestBool64x2Ctor(); + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); + diff --git a/js/src/tests/ecma_7/SIMD/conversions.js b/js/src/tests/ecma_7/SIMD/conversions.js new file mode 100644 index 000000000..05b2487ac --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/conversions.js @@ -0,0 +1,1261 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; + +function testFloat32x4FromFloat64x2Bits() { + var valsExp = [ + [[2.000000473111868, 512.0001225471497], [1.0, 2.0, 3.0, 4.0]], + [[-0, NaN], [0, -0, 0, NaN]], + [[Infinity, -Infinity], [0, NaN, 0, NaN]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Float32x4.fromFloat64x2Bits(Float64x2(...v)), w); + } +} + +function testFloat32x4FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var f32 = new Float32Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [f32[0], f32[1], f32[2], f32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, + INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN]]; + for (var v of vals) { + var i = Int8x16(...v); + assertEqX4(Float32x4.fromInt8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Float32x4.fromInt8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testFloat32x4FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var f32 = new Float32Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [f32[0], f32[1], f32[2], f32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, + UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0]]; + for (var v of vals) { + var i = Uint8x16(...v); + assertEqX4(Float32x4.fromUint8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Float32x4.fromUint8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testFloat32x4FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var f32 = new Float32Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [f32[0], f32[1], f32[2], f32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX]]; + for (var v of vals) { + var i = Int16x8(...v); + assertEqX4(Float32x4.fromInt16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Float32x4.fromInt16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testFloat32x4FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var f32 = new Float32Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [f32[0], f32[1], f32[2], f32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX]]; + for (var v of vals) { + var i = Uint16x8(...v); + assertEqX4(Float32x4.fromUint16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Float32x4.fromUint16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testFloat32x4FromInt32x4() { + function expected(v) { + return v.map(Math.fround); + } + var vals = [ + [1, 2, 3, 4], + [INT32_MIN, INT32_MAX, Math.pow(2, 30) - 1, -Math.pow(2, 30)] + ]; + + for (var v of vals) { + assertEqX4(Float32x4.fromInt32x4(Int32x4(...v)), expected(v)); + } + + // Check that rounding to nearest, even is applied. + { + var num = makeFloat(0, 150 + 2, 0); + var next = makeFloat(0, 150 + 2, 1); + assertEq(num + 4, next); + + v = Float32x4.fromInt32x4(Int32x4(num, num + 1, num + 2, num + 3)); + assertEqX4(v, [num, num, /* even */ num, next]); + } + + { + var num = makeFloat(0, 150 + 2, 1); + var next = makeFloat(0, 150 + 2, 2); + assertEq(num + 4, next); + + v = Float32x4.fromInt32x4(Int32x4(num, num + 1, num + 2, num + 3)); + assertEqX4(v, [num, num, /* even */ next, next]); + } + + { + var last = makeFloat(0, 157, 0x7fffff); + + assertEq(last, Math.fround(last), "float"); + assertEq(last < Math.pow(2, 31), true, "less than 2**31"); + assertEq(last | 0, last, "it should be an integer, as exponent >= 150"); + + var diff = (Math.pow(2, 31) - 1) - last; + v = Float32x4.fromInt32x4(Int32x4(Math.pow(2, 31) - 1, + Math.pow(2, 30) + 1, + last + (diff / 2) | 0, // nearest is last + last + (diff / 2) + 1 | 0 // nearest is Math.pow(2, 31) + )); + assertEqX4(v, [Math.pow(2, 31), + Math.pow(2, 30), + last, + Math.pow(2, 31) + ]); + } +} + +function testFloat32x4FromUint32x4() { + function expected(v) { + return v.map(Math.fround); + } + var vals = [ + [1, 2, 3, 4], + [0, UINT32_MAX, Math.pow(2, 30) - 1, Math.pow(2, 31)] + ]; + + for (var v of vals) { + assertEqX4(Float32x4.fromUint32x4(Uint32x4(...v)), expected(v)); + } + + // Check that rounding to nearest, even is applied. + { + var num = makeFloat(0, 150 + 2, 0); + var next = makeFloat(0, 150 + 2, 1); + assertEq(num + 4, next); + + v = Float32x4.fromUint32x4(Uint32x4(num, num + 1, num + 2, num + 3)); + assertEqX4(v, [num, num, /* even */ num, next]); + } + + { + var num = makeFloat(0, 150 + 2, 1); + var next = makeFloat(0, 150 + 2, 2); + assertEq(num + 4, next); + + v = Float32x4.fromUint32x4(Uint32x4(num, num + 1, num + 2, num + 3)); + assertEqX4(v, [num, num, /* even */ next, next]); + } + + { + var last = makeFloat(0, 157, 0x7fffff); + + assertEq(last, Math.fround(last), "float"); + assertEq(last < Math.pow(2, 31), true, "less than 2**31"); + assertEq(last | 0, last, "it should be an integer, as exponent >= 150"); + + var diff = (Math.pow(2, 31) - 1) - last; + v = Float32x4.fromUint32x4(Uint32x4(Math.pow(2, 31) - 1, + Math.pow(2, 30) + 1, + last + (diff / 2) | 0, // nearest is last + last + (diff / 2) + 1 | 0 // nearest is Math.pow(2, 31) + )); + assertEqX4(v, [Math.pow(2, 31), + Math.pow(2, 30), + last, + Math.pow(2, 31) + ]); + } +} + +function testFloat32x4FromInt32x4Bits() { + var valsExp = [ + [[100, 200, 300, 400], [1.401298464324817e-43, 2.802596928649634e-43, 4.203895392974451e-43, 5.605193857299268e-43]], + [[INT32_MIN, INT32_MAX, 0, 0], [-0, NaN, 0, 0]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Float32x4.fromInt32x4Bits(Int32x4(...v)), w); + } +} + +function testFloat32x4FromUint32x4Bits() { + var valsExp = [ + [[100, 200, 300, 400], [1.401298464324817e-43, 2.802596928649634e-43, 4.203895392974451e-43, 5.605193857299268e-43]], + [[INT32_MIN, INT32_MAX, 0, 0], [-0, NaN, 0, 0]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Float32x4.fromUint32x4Bits(Uint32x4(...v)), w); + } +} + +function testFloat64x2FromFloat32x4Bits() { + var valsExp = [ + [[0, 1.875, 0, 2], [1.0, 2.0]], + [[NaN, -0, Infinity, -Infinity], [-1.058925634e-314, -1.404448428688076e+306]] + ]; + + for (var [v,w] of valsExp) { + assertEqX2(Float64x2.fromFloat32x4Bits(Float32x4(...v)), w); + } +} + +function testFloat64x2FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var f64 = new Float64Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [f64[0], f64[1]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, + INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN]]; + + for (var v of vals) { + var f = Int8x16(...v); + assertEqX2(Float64x2.fromInt8x16Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX2(Float64x2.fromInt8x16Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testFloat64x2FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var f64 = new Float64Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [f64[0], f64[1]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, + UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0]]; + + for (var v of vals) { + var f = Uint8x16(...v); + assertEqX2(Float64x2.fromUint8x16Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX2(Float64x2.fromUint8x16Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testFloat64x2FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var f64 = new Float64Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [f64[0], f64[1]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX]]; + + for (var v of vals) { + var f = Int16x8(...v); + assertEqX2(Float64x2.fromInt16x8Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX2(Float64x2.fromInt16x8Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testFloat64x2FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var f64 = new Float64Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [f64[0], f64[1]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX]]; + + for (var v of vals) { + var f = Uint16x8(...v); + assertEqX2(Float64x2.fromUint16x8Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX2(Float64x2.fromUint16x8Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testFloat64x2FromInt32x4Bits() { + var valsExp = [ + [[0x00000000, 0x3ff00000, 0x0000000, 0x40000000], [1.0, 2.0]], + [[0xabcdef12, 0x3ff00000, 0x21fedcba, 0x40000000], [1.0000006400213732, 2.0000002532866263]] + ]; + + for (var [v,w] of valsExp) { + assertEqX2(Float64x2.fromInt32x4Bits(Int32x4(...v)), w); + } +} + +function testFloat64x2FromUint32x4Bits() { + var valsExp = [ + [[0x00000000, 0x3ff00000, 0x0000000, 0x40000000], [1.0, 2.0]], + [[0xabcdef12, 0x3ff00000, 0x21fedcba, 0x40000000], [1.0000006400213732, 2.0000002532866263]] + ]; + + for (var [v,w] of valsExp) { + assertEqX2(Float64x2.fromUint32x4Bits(Uint32x4(...v)), w); + } +} + +function testInt32x4FromFloat32x4() { + var d = Float32x4(1.1, 2.2, 3.3, 4.6); + assertEqX4(Int32x4.fromFloat32x4(d), [1, 2, 3, 4]); + + var d = Float32x4(NaN, 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Int32x4.fromFloat32x4(d), RangeError); + + var d = Float32x4(Infinity, 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Int32x4.fromFloat32x4(d), RangeError); + + var d = Float32x4(-Infinity, 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Int32x4.fromFloat32x4(d), RangeError); + + // Test high boundaries: float(0, 157, 0x7fffff) < INT32_MAX < float(0, 158, 0) + var d = Float32x4(makeFloat(0, 127 + 31, 0), 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Int32x4.fromFloat32x4(d), RangeError); + + var lastFloat = makeFloat(0, 127 + 30, 0x7FFFFF); + var d = Float32x4(lastFloat, 0, 0, 0); + var e = SIMD.Int32x4.fromFloat32x4(d); + assertEqX4(e, [lastFloat, 0, 0, 0]); + + // Test low boundaries + assertEq(makeFloat(1, 127 + 31, 0), INT32_MIN); + var d = Float32x4(makeFloat(1, 127 + 31, 0), 0, 0, 0); + var e = SIMD.Int32x4.fromFloat32x4(d); + assertEqX4(e, [INT32_MIN, 0, 0, 0]); + + var d = Float32x4(makeFloat(1, 127 + 31, 1), 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Int32x4.fromFloat32x4(d), RangeError); +} + +function testUint32x4FromFloat32x4() { + var d = Float32x4(1.1, 2.2, -0.9, 4.6); + assertEqX4(Uint32x4.fromFloat32x4(d), [1, 2, 0, 4]); + + var d = Float32x4(NaN, 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Uint32x4.fromFloat32x4(d), RangeError); + + var d = Float32x4(Infinity, 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Uint32x4.fromFloat32x4(d), RangeError); + + var d = Float32x4(-Infinity, 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Uint32x4.fromFloat32x4(d), RangeError); + + // Test high boundaries: float(0, 158, 0x7fffff) < UINT32_MAX < float(0, 159, 0) + var d = Float32x4(makeFloat(0, 127 + 32, 0), 0, 0, 0); + assertThrowsInstanceOf(() => SIMD.Uint32x4.fromFloat32x4(d), RangeError); + + var lastFloat = makeFloat(0, 127 + 31, 0x7FFFFF); + var d = Float32x4(lastFloat, 0, 0, 0); + var e = SIMD.Uint32x4.fromFloat32x4(d); + assertEqX4(e, [lastFloat, 0, 0, 0]); +} + +function testInt32x4FromFloat32x4Bits() { + var valsExp = [ + [[1, 2, 3, 4], [0x3f800000 | 0, 0x40000000 | 0, 0x40400000 | 0, 0x40800000 | 0]], + [[NaN, -0, Infinity, -Infinity], [0x7fc00000 | 0, 0x80000000 | 0, 0x7f800000 | 0, 0xff800000 | 0]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Int32x4.fromFloat32x4Bits(Float32x4(...v)), w); + } +} + +function testUint32x4FromFloat32x4Bits() { + var valsExp = [ + [[1, 2, 3, 4], [0x3f800000, 0x40000000, 0x40400000, 0x40800000]], + [[NaN, -0, Infinity, -Infinity], [0x7fc00000, 0x80000000, 0x7f800000, 0xff800000]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Uint32x4.fromFloat32x4Bits(Float32x4(...v)), w); + } +} + +function testInt32x4FromFloat64x2Bits() { + var valsExp = [ + [[1.0, 2.0], [0x00000000, 0x3FF00000, 0x00000000, 0x40000000]], + [[+Infinity, -Infinity], [0x00000000, 0x7ff00000, 0x00000000, -0x100000]], + [[-0, NaN], [0x00000000, -0x80000000, 0x00000000, 0x7ff80000]], + [[1.0000006400213732, 2.0000002532866263], [-0x543210ee, 0x3ff00000, 0x21fedcba, 0x40000000]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Int32x4.fromFloat64x2Bits(Float64x2(...v)), w); + } +} + +function testUint32x4FromFloat64x2Bits() { + var valsExp = [ + [[1.0, 2.0], [0x00000000, 0x3FF00000, 0x00000000, 0x40000000]], + [[+Infinity, -Infinity], [0x00000000, 0x7ff00000, 0x00000000, 0xfff00000]], + [[-0, NaN], [0x00000000, 0x80000000, 0x00000000, 0x7ff80000]], + [[1.0000006400213732, 2.0000002532866263], [0xabcdef12, 0x3ff00000, 0x21fedcba, 0x40000000]] + ]; + + for (var [v,w] of valsExp) { + assertEqX4(Uint32x4.fromFloat64x2Bits(Float64x2(...v)), w); + } +} + +function testInt32x4FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var i32 = new Int32Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [i32[0], i32[1], i32[2], i32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, + INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN]]; + + for (var v of vals) { + var i = Int8x16(...v); + assertEqX4(Int32x4.fromInt8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Int32x4.fromInt8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt32x4FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var i32 = new Int32Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [i32[0], i32[1], i32[2], i32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, + UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0]]; + + for (var v of vals) { + var i = Uint8x16(...v); + assertEqX4(Int32x4.fromUint8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Int32x4.fromUint8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt32x4FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var i32 = new Int32Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [i32[0], i32[1], i32[2], i32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX]]; + + for (var v of vals) { + var i = Int16x8(...v); + assertEqX4(Int32x4.fromInt16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Int32x4.fromInt16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt32x4FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var i32 = new Int32Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [i32[0], i32[1], i32[2], i32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX]]; + + for (var v of vals) { + var i = Uint16x8(...v); + assertEqX4(Int32x4.fromUint16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Int32x4.fromUint16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt32x4FromUint32x4Bits() { + function expected(v, Buffer) { + var u32 = new Uint32Array(new Buffer(16)); + var i32 = new Int32Array(u32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u32[i] = asArr[i]; + return [i32[0], i32[1], i32[2], i32[3]]; + } + + var vals = [[0, 1, -2, 3], [INT8_MIN, UINT32_MAX, INT32_MIN, INT32_MAX]]; + + for (var v of vals) { + var i = Uint32x4(...v); + assertEqX4(Int32x4.fromUint32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Int32x4.fromUint32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt8x16FromFloat32x4Bits() { + function expected(v, Buffer) { + var f32 = new Float32Array(new Buffer(16)); + var i8 = new Int8Array(f32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) f32[i] = asArr[i]; + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + + var vals = [[1, -2, 3, -4], [Infinity, -Infinity, NaN, -0]]; + + for (var v of vals) { + var f = Float32x4(...v); + assertEqX16(Int8x16.fromFloat32x4Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromFloat32x4Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testInt8x16FromFloat64x2Bits() { + function expected(v, Buffer) { + var f64 = new Float64Array(new Buffer(16)); + var i8 = new Int8Array(f64.buffer); + f64[0] = Float64x2.extractLane(v, 0); + f64[1] = Float64x2.extractLane(v, 1); + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + var vals = [[1, -2], [-3, 4], [Infinity, -Infinity], [NaN, -0]]; + + for (var v of vals) { + var f = Float64x2(...v); + assertEqX16(Int8x16.fromFloat64x2Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromFloat64x2Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testInt8x16FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var i8 = new Int8Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + + var vals = [[0, 1, -2, 3, -4, 5, INT8_MIN, UINT8_MAX, -6, 7, -8, 9, -10, 11, -12, 13]]; + + for (var v of vals) { + var i = Uint8x16(...v); + assertEqX16(Int8x16.fromUint8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromUint8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt8x16FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var i8 = new Int8Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + + var vals = [[0, 1, -2, 3, INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX]]; + for (var v of vals) { + var i = Int16x8(...v); + assertEqX16(Int8x16.fromInt16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromInt16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt8x16FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var i8 = new Int8Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + + var vals = [[0, 1, -2, UINT16_MAX, INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX]]; + for (var v of vals) { + var i = Uint16x8(...v); + assertEqX16(Int8x16.fromUint16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromUint16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt8x16FromInt32x4Bits() { + function expected(v, Buffer) { + var i32 = new Int32Array(new Buffer(16)); + var i8 = new Int8Array(i32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) i32[i] = asArr[i]; + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + + var vals = [[0, 1, -2, 3], [INT8_MIN, INT8_MAX, INT32_MIN, INT32_MAX]]; + for (var v of vals) { + var i = Int32x4(...v); + assertEqX16(Int8x16.fromInt32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromInt32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt8x16FromUint32x4Bits() { + function expected(v, Buffer) { + var u32 = new Uint32Array(new Buffer(16)); + var i8 = new Int8Array(u32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) u32[i] = asArr[i]; + return [i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7], + i8[8], i8[9], i8[10], i8[11], i8[12], i8[13], i8[14], i8[15]]; + } + + var vals = [[0, 1, -2, 3], [INT8_MIN, INT8_MAX, INT32_MIN, INT32_MAX]]; + for (var v of vals) { + var i = Uint32x4(...v); + assertEqX16(Int8x16.fromUint32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Int8x16.fromUint32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt16x8FromFloat32x4Bits() { + function expected(v, Buffer) { + var f32 = new Float32Array(new Buffer(16)); + var i16 = new Int16Array(f32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) f32[i] = asArr[i]; + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[1, -2, 3, -4], [Infinity, -Infinity, NaN, -0]]; + + for (var v of vals) { + var f = Float32x4(...v); + assertEqX8(Int16x8.fromFloat32x4Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromFloat32x4Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testInt16x8FromFloat64x2Bits() { + function expected(v, Buffer) { + var f64 = new Float64Array(new Buffer(16)); + var i16 = new Int16Array(f64.buffer); + f64[0] = Float64x2.extractLane(v, 0); + f64[1] = Float64x2.extractLane(v, 1); + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[1, -2], [-3, 4], [Infinity, -Infinity], [NaN, -0]]; + + for (var v of vals) { + var f = Float64x2(...v); + assertEqX8(Int16x8.fromFloat64x2Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromFloat64x2Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testInt16x8FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var i16 = new Int16Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[0, 1, -2, 3, -4, 5, INT8_MIN, INT8_MAX, -6, 7, -8, 9, -10, 11, -12, 13]]; + + for (var v of vals) { + var i = Int8x16(...v); + assertEqX8(Int16x8.fromInt8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromInt8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt16x8FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var i16 = new Int16Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[0, 1, -2, 3, -4, UINT8_MAX, INT8_MIN, INT8_MAX, -6, 7, -8, 9, -10, 11, -12, 13]]; + + for (var v of vals) { + var i = Uint8x16(...v); + assertEqX8(Int16x8.fromUint8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromUint8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt16x8FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var i16 = new Int16Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX]]; + + for (var v of vals) { + var i = Uint16x8(...v); + assertEqX8(Int16x8.fromUint16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromUint16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt16x8FromInt32x4Bits() { + function expected(v, Buffer) { + var i32 = new Int32Array(new Buffer(16)); + var i16 = new Int16Array(i32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) i32[i] = asArr[i]; + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[1, -2, -3, 4], [INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN]]; + + for (var v of vals) { + var i = Int32x4(...v); + assertEqX8(Int16x8.fromInt32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromInt32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testInt16x8FromUint32x4Bits() { + function expected(v, Buffer) { + var u32 = new Uint32Array(new Buffer(16)); + var i16 = new Int16Array(u32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) u32[i] = asArr[i]; + return [i16[0], i16[1], i16[2], i16[3], i16[4], i16[5], i16[6], i16[7]]; + } + + var vals = [[1, -2, -3, 4], [INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN]]; + + for (var v of vals) { + var i = Uint32x4(...v); + assertEqX8(Int16x8.fromUint32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Int16x8.fromUint32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint32x4FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var u32 = new Uint32Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [u32[0], u32[1], u32[2], u32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, + INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN, INT8_MAX, INT8_MIN]]; + + for (var v of vals) { + var i = Int8x16(...v); + assertEqX4(Uint32x4.fromInt8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Uint32x4.fromInt8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint32x4FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var u32 = new Uint32Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [u32[0], u32[1], u32[2], u32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + [0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, + UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0, UINT8_MAX, 0]]; + + for (var v of vals) { + var i = Uint8x16(...v); + assertEqX4(Uint32x4.fromUint8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Uint32x4.fromUint8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint32x4FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var u32 = new Uint32Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [u32[0], u32[1], u32[2], u32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX]]; + + for (var v of vals) { + var i = Int16x8(...v); + assertEqX4(Uint32x4.fromInt16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Uint32x4.fromInt16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint32x4FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var u32 = new Uint32Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [u32[0], u32[1], u32[2], u32[3]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX]]; + + for (var v of vals) { + var i = Uint16x8(...v); + assertEqX4(Uint32x4.fromUint16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Uint32x4.fromUint16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint32x4FromInt32x4Bits() { + function expected(v, Buffer) { + var i32 = new Int32Array(new Buffer(16)); + var u32 = new Uint32Array(i32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i32[i] = asArr[i]; + return [u32[0], u32[1], u32[2], u32[3]]; + } + + var vals = [[0, 1, -2, 3], [INT8_MIN, UINT32_MAX, INT32_MIN, INT32_MAX]]; + + for (var v of vals) { + var i = Int32x4(...v); + assertEqX4(Uint32x4.fromInt32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX4(Uint32x4.fromInt32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint8x16FromFloat32x4Bits() { + function expected(v, Buffer) { + var f32 = new Float32Array(new Buffer(16)); + var u8 = new Uint8Array(f32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) f32[i] = asArr[i]; + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + + var vals = [[1, -2, 3, -4], [Infinity, -Infinity, NaN, -0]]; + + for (var v of vals) { + var f = Float32x4(...v); + assertEqX16(Uint8x16.fromFloat32x4Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromFloat32x4Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testUint8x16FromFloat64x2Bits() { + function expected(v, Buffer) { + var f64 = new Float64Array(new Buffer(16)); + var u8 = new Uint8Array(f64.buffer); + f64[0] = Float64x2.extractLane(v, 0); + f64[1] = Float64x2.extractLane(v, 1); + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + var vals = [[1, -2], [-3, 4], [Infinity, -Infinity], [NaN, -0]]; + + for (var v of vals) { + var f = Float64x2(...v); + assertEqX16(Uint8x16.fromFloat64x2Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromFloat64x2Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testUint8x16FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var u8 = new Uint8Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + + var vals = [[0, 1, -2, 3, -4, 5, INT8_MIN, UINT8_MAX, -6, 7, INT8_MAX, 9, -10, 11, -12, 13]]; + + for (var v of vals) { + var i = Int8x16(...v); + assertEqX16(Uint8x16.fromInt8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromInt8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint8x16FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var u8 = new Uint8Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + + var vals = [[0, 1, -2, 3, INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX]]; + for (var v of vals) { + var i = Int16x8(...v); + assertEqX16(Uint8x16.fromInt16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromInt16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint8x16FromUint16x8Bits() { + function expected(v, Buffer) { + var u16 = new Uint16Array(new Buffer(16)); + var u8 = new Uint8Array(u16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) u16[i] = asArr[i]; + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + + var vals = [[0, 1, -2, UINT16_MAX, INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX]]; + for (var v of vals) { + var i = Uint16x8(...v); + assertEqX16(Uint8x16.fromUint16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromUint16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint8x16FromInt32x4Bits() { + function expected(v, Buffer) { + var i32 = new Int32Array(new Buffer(16)); + var u8 = new Uint8Array(i32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) i32[i] = asArr[i]; + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + + var vals = [[0, 1, -2, 3], [INT8_MIN, INT8_MAX, INT32_MIN, INT32_MAX]]; + for (var v of vals) { + var i = Int32x4(...v); + assertEqX16(Uint8x16.fromInt32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromInt32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint8x16FromUint32x4Bits() { + function expected(v, Buffer) { + var u32 = new Uint32Array(new Buffer(16)); + var u8 = new Uint8Array(u32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) u32[i] = asArr[i]; + return [u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7], + u8[8], u8[9], u8[10], u8[11], u8[12], u8[13], u8[14], u8[15]]; + } + + var vals = [[0, 1, -2, 3], [INT8_MIN, INT8_MAX, INT32_MIN, INT32_MAX]]; + for (var v of vals) { + var i = Uint32x4(...v); + assertEqX16(Uint8x16.fromUint32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX16(Uint8x16.fromUint32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint16x8FromFloat32x4Bits() { + function expected(v, Buffer) { + var f32 = new Float32Array(new Buffer(16)); + var u16 = new Uint16Array(f32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) f32[i] = asArr[i]; + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[1, -2, 3, -4], [Infinity, -Infinity, NaN, -0]]; + + for (var v of vals) { + var f = Float32x4(...v); + assertEqX8(Uint16x8.fromFloat32x4Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromFloat32x4Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testUint16x8FromFloat64x2Bits() { + function expected(v, Buffer) { + var f64 = new Float64Array(new Buffer(16)); + var u16 = new Uint16Array(f64.buffer); + f64[0] = Float64x2.extractLane(v, 0); + f64[1] = Float64x2.extractLane(v, 1); + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[1, -2], [-3, 4], [Infinity, -Infinity], [NaN, -0]]; + + for (var v of vals) { + var f = Float64x2(...v); + assertEqX8(Uint16x8.fromFloat64x2Bits(f), expected(f, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromFloat64x2Bits(f), expected(f, SharedArrayBuffer)); + } +} + +function testUint16x8FromInt8x16Bits() { + function expected(v, Buffer) { + var i8 = new Int8Array(new Buffer(16)); + var u16 = new Uint16Array(i8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) i8[i] = asArr[i]; + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[0, 1, -2, 3, -4, 5, INT8_MIN, INT8_MAX, -6, 7, -8, 9, -10, 11, -12, 13]]; + + for (var v of vals) { + var i = Int8x16(...v); + assertEqX8(Uint16x8.fromInt8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromInt8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint16x8FromUint8x16Bits() { + function expected(v, Buffer) { + var u8 = new Uint8Array(new Buffer(16)); + var u16 = new Uint16Array(u8.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 16; i++) u8[i] = asArr[i]; + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[0, 1, -2, 3, -4, UINT8_MAX, INT8_MIN, INT8_MAX, -6, 7, -8, 9, -10, 11, -12, 13]]; + + for (var v of vals) { + var i = Uint8x16(...v); + assertEqX8(Uint16x8.fromUint8x16Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromUint8x16Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint16x8FromInt16x8Bits() { + function expected(v, Buffer) { + var i16 = new Int16Array(new Buffer(16)); + var u16 = new Uint16Array(i16.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 8; i++) i16[i] = asArr[i]; + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[1, 2, 3, 4, 5, 6, 7, 8], + [INT16_MIN, UINT16_MAX, INT16_MAX, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX]]; + + for (var v of vals) { + var i = Int16x8(...v); + assertEqX8(Uint16x8.fromInt16x8Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromInt16x8Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint16x8FromInt32x4Bits() { + function expected(v, Buffer) { + var i32 = new Int32Array(new Buffer(16)); + var u16 = new Uint16Array(i32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) i32[i] = asArr[i]; + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[1, -2, -3, 4], [INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN]]; + + for (var v of vals) { + var i = Int32x4(...v); + assertEqX8(Uint16x8.fromInt32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromInt32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function testUint16x8FromUint32x4Bits() { + function expected(v, Buffer) { + var u32 = new Uint32Array(new Buffer(16)); + var u16 = new Uint16Array(u32.buffer); + var asArr = simdToArray(v); + for (var i = 0; i < 4; i++) u32[i] = asArr[i]; + return [u16[0], u16[1], u16[2], u16[3], u16[4], u16[5], u16[6], u16[7]]; + } + + var vals = [[1, -2, -3, 4], [INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN]]; + + for (var v of vals) { + var i = Uint32x4(...v); + assertEqX8(Uint16x8.fromUint32x4Bits(i), expected(i, ArrayBuffer)); + if (typeof SharedArrayBuffer != "undefined") + assertEqX8(Uint16x8.fromUint32x4Bits(i), expected(i, SharedArrayBuffer)); + } +} + +function test() { + testFloat32x4FromFloat64x2Bits(); + testFloat32x4FromInt8x16Bits(); + testFloat32x4FromInt16x8Bits(); + testFloat32x4FromInt32x4(); + testFloat32x4FromInt32x4Bits(); + testFloat32x4FromUint8x16Bits(); + testFloat32x4FromUint16x8Bits(); + testFloat32x4FromUint32x4(); + testFloat32x4FromUint32x4Bits(); + + testFloat64x2FromFloat32x4Bits(); + testFloat64x2FromInt8x16Bits(); + testFloat64x2FromInt16x8Bits(); + testFloat64x2FromInt32x4Bits(); + testFloat64x2FromUint8x16Bits(); + testFloat64x2FromUint16x8Bits(); + testFloat64x2FromUint32x4Bits(); + + testInt8x16FromFloat32x4Bits(); + testInt8x16FromFloat64x2Bits(); + testInt8x16FromInt16x8Bits(); + testInt8x16FromInt32x4Bits(); + testInt8x16FromUint8x16Bits(); + testInt8x16FromUint16x8Bits(); + testInt8x16FromUint32x4Bits(); + + testInt16x8FromFloat32x4Bits(); + testInt16x8FromFloat64x2Bits(); + testInt16x8FromInt8x16Bits(); + testInt16x8FromInt32x4Bits(); + testInt16x8FromUint8x16Bits(); + testInt16x8FromUint16x8Bits(); + testInt16x8FromUint32x4Bits(); + + testInt32x4FromFloat32x4(); + testInt32x4FromFloat32x4Bits(); + testInt32x4FromFloat64x2Bits(); + testInt32x4FromInt8x16Bits(); + testInt32x4FromInt16x8Bits(); + testInt32x4FromUint8x16Bits(); + testInt32x4FromUint16x8Bits(); + testInt32x4FromUint32x4Bits(); + + testUint8x16FromFloat32x4Bits(); + testUint8x16FromFloat64x2Bits(); + testUint8x16FromInt8x16Bits(); + testUint8x16FromInt16x8Bits(); + testUint8x16FromInt32x4Bits(); + testUint8x16FromUint16x8Bits(); + testUint8x16FromUint32x4Bits(); + + testUint16x8FromFloat32x4Bits(); + testUint16x8FromFloat64x2Bits(); + testUint16x8FromInt8x16Bits(); + testUint16x8FromInt16x8Bits(); + testUint16x8FromInt32x4Bits(); + testUint16x8FromUint8x16Bits(); + testUint16x8FromUint32x4Bits(); + + testUint32x4FromFloat32x4(); + testUint32x4FromFloat32x4Bits(); + testUint32x4FromFloat64x2Bits(); + testUint32x4FromInt8x16Bits(); + testUint32x4FromInt16x8Bits(); + testUint32x4FromInt32x4Bits(); + testUint32x4FromUint8x16Bits(); + testUint32x4FromUint16x8Bits(); + + if (typeof reportCompare === "function") { + reportCompare(true, true); + } +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/float64x2-arithmetic.js b/js/src/tests/ecma_7/SIMD/float64x2-arithmetic.js new file mode 100644 index 000000000..17c51a9e0 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/float64x2-arithmetic.js @@ -0,0 +1,69 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) +var Float64x2 = SIMD.Float64x2; + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +function add(a, b) { return a + b; } +function sub(a, b) { return a - b; } +function mul(a, b) { return a * b; } +function div(a, b) { return a / b; } +function neg(a) { return -a; } +function reciprocalApproximation(a) { return 1 / a; } +function reciprocalSqrtApproximation(a) { return 1 / Math.sqrt(a); } + +function testAdd(v, w) { + return testBinaryFunc(v, w, Float64x2.add, add); +} +function testSub(v, w) { + return testBinaryFunc(v, w, Float64x2.sub, sub); +} +function testMul(v, w) { + return testBinaryFunc(v, w, Float64x2.mul, mul); +} +function testDiv(v, w) { + return testBinaryFunc(v, w, Float64x2.div, div); +} +function testAbs(v) { + return testUnaryFunc(v, Float64x2.abs, Math.abs); +} +function testNeg(v) { + return testUnaryFunc(v, Float64x2.neg, neg); +} +function testReciprocalApproximation(v) { + return testUnaryFunc(v, Float64x2.reciprocalApproximation, reciprocalApproximation); +} +function testReciprocalSqrtApproximation(v) { + return testUnaryFunc(v, Float64x2.reciprocalSqrtApproximation, reciprocalSqrtApproximation); +} +function testSqrt(v) { + return testUnaryFunc(v, Float64x2.sqrt, Math.sqrt); +} + +function test() { + var v, w; + for ([v, w] of [[Float64x2(1, 2), Float64x2(3, 4)], + [Float64x2(1.894, 2.8909), Float64x2(100.764, 200.987)], + [Float64x2(-1, -2), Float64x2(-14.54, 57)], + [Float64x2(+Infinity, -Infinity), Float64x2(NaN, -0)], + [Float64x2(Math.pow(2, 31), Math.pow(2, -31)), Float64x2(Math.pow(2, -1047), Math.pow(2, -149))]]) + { + testAdd(v, w); + testSub(v, w); + testMul(v, w); + testDiv(v, w); + testAbs(v); + testNeg(v); + testReciprocalApproximation(v); + testSqrt(v); + testReciprocalSqrtApproximation(v); + } + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); + diff --git a/js/src/tests/ecma_7/SIMD/load-floats.js b/js/src/tests/ecma_7/SIMD/load-floats.js new file mode 100644 index 000000000..9ae52dc8c --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/load-floats.js @@ -0,0 +1,19 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var { testLoad } = Helpers; + +testLoad('Float32x4', new Float32Array(SIZE_32_ARRAY)); +testLoad('Float64x2', new Float64Array(SIZE_64_ARRAY)); + +if (typeof SharedArrayBuffer != "undefined") { + testLoad('Float32x4', new Float32Array(new SharedArrayBuffer(SIZE_8_ARRAY))); + testLoad('Float64x2', new Float64Array(new SharedArrayBuffer(SIZE_8_ARRAY))); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/load-int16x8.js b/js/src/tests/ecma_7/SIMD/load-int16x8.js new file mode 100644 index 000000000..a8b90ca15 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/load-int16x8.js @@ -0,0 +1,17 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var { testLoad } = Helpers; + +testLoad('Int16x8', new Int16Array(SIZE_16_ARRAY)); + +if (typeof SharedArrayBuffer != "undefined") { + testLoad('Int16x8', new Int16Array(new SharedArrayBuffer(SIZE_8_ARRAY))); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/load-int32x4.js b/js/src/tests/ecma_7/SIMD/load-int32x4.js new file mode 100644 index 000000000..0719cbc17 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/load-int32x4.js @@ -0,0 +1,18 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var { testLoad } = Helpers; + +testLoad('Int32x4', new Int32Array(SIZE_32_ARRAY)); + +if (typeof SharedArrayBuffer != "undefined") { + testLoad('Int32x4', new Int32Array(new SharedArrayBuffer(SIZE_8_ARRAY))); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); + diff --git a/js/src/tests/ecma_7/SIMD/load-int8x16.js b/js/src/tests/ecma_7/SIMD/load-int8x16.js new file mode 100644 index 000000000..cb6c24285 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/load-int8x16.js @@ -0,0 +1,17 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var { testLoad } = Helpers; + +testLoad('Int8x16', new Int8Array(SIZE_8_ARRAY)); + +if (typeof SharedArrayBuffer != "undefined") { + testLoad('Int8x16', new Int8Array(new SharedArrayBuffer(SIZE_8_ARRAY))); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/load-sab-buffer-compat.js b/js/src/tests/ecma_7/SIMD/load-sab-buffer-compat.js new file mode 100644 index 000000000..fe8fac3ed --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/load-sab-buffer-compat.js @@ -0,0 +1,49 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var { MakeComparator } = Helpers; + +function testSharedArrayBufferCompat() { + var TA = new Float32Array(new SharedArrayBuffer(16*4)); + for (var i = 0; i < 16; i++) + TA[i] = i + 1; + + for (var ta of [ + new Uint8Array(TA.buffer), + new Int8Array(TA.buffer), + new Uint16Array(TA.buffer), + new Int16Array(TA.buffer), + new Uint32Array(TA.buffer), + new Int32Array(TA.buffer), + new Float32Array(TA.buffer), + new Float64Array(TA.buffer) + ]) + { + for (var kind of ['Int32x4', 'Uint32x4', 'Float32x4', 'Float64x2']) { + var comp = MakeComparator(kind, ta); + comp.load(0); + comp.load1(0); + comp.load2(0); + comp.load3(0); + + comp.load(3); + comp.load1(3); + comp.load2(3); + comp.load3(3); + } + + assertThrowsInstanceOf(() => SIMD.Int32x4.load(ta, 1024), RangeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.load(ta, 1024), RangeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.load(ta, 1024), RangeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.load(ta, 1024), RangeError); + } +} + +testSharedArrayBufferCompat(); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/load-unsigned-integers.js b/js/src/tests/ecma_7/SIMD/load-unsigned-integers.js new file mode 100644 index 000000000..381e7b60a --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/load-unsigned-integers.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var { testLoad } = Helpers; + +testLoad('Uint8x16', new Uint8Array(SIZE_8_ARRAY)); +testLoad('Uint16x8', new Uint16Array(SIZE_16_ARRAY)); +testLoad('Uint32x4', new Uint32Array(SIZE_32_ARRAY)); + +if (typeof SharedArrayBuffer != "undefined") { + testLoad('Uint8x16', new Uint8Array(new SharedArrayBuffer(SIZE_8_ARRAY))); + testLoad('Uint16x8', new Uint16Array(new SharedArrayBuffer(SIZE_8_ARRAY))); + testLoad('Uint32x4', new Uint32Array(new SharedArrayBuffer(SIZE_8_ARRAY))); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); + diff --git a/js/src/tests/ecma_7/SIMD/minmax.js b/js/src/tests/ecma_7/SIMD/minmax.js new file mode 100644 index 000000000..9742b70d1 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/minmax.js @@ -0,0 +1,85 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; + +function testMaxFloat32(v, w) { + return testBinaryFunc(v, w, Float32x4.max, (x, y) => Math.fround(Math.max(x, y)), 4); +} +function testMinFloat32(v, w) { + return testBinaryFunc(v, w, Float32x4.min, (x, y) => Math.fround(Math.min(x, y)), 4); +} + +function testMaxFloat64(v, w) { + return testBinaryFunc(v, w, Float64x2.max, (x, y) => Math.max(x, y), 2); +} +function testMinFloat64(v, w) { + return testBinaryFunc(v, w, Float64x2.min, (x, y) => Math.min(x, y), 2); +} + +function maxNum(x, y) { + if (x != x) + return y; + if (y != y) + return x; + return Math.max(x, y); +} + +function minNum(x, y) { + if (x != x) + return y; + if (y != y) + return x; + return Math.min(x, y); +} + +function testMaxNumFloat32(v, w) { + return testBinaryFunc(v, w, Float32x4.maxNum, maxNum, 4); +} +function testMinNumFloat32(v, w) { + return testBinaryFunc(v, w, Float32x4.minNum, minNum, 4); +} + +function testMaxNumFloat64(v, w) { + return testBinaryFunc(v, w, Float64x2.maxNum, maxNum, 2); +} +function testMinNumFloat64(v, w) { + return testBinaryFunc(v, w, Float64x2.minNum, minNum, 2); +} + +function test() { + var v, w; + for ([v, w] of [[Float32x4(1, 20, 30, 4), Float32x4(10, 2, 3, 40)], + [Float32x4(9.999, 2.1234, 30.4443, 4), Float32x4(10, 2.1233, 30.4444, 4.0001)], + [Float32x4(NaN, -Infinity, +Infinity, -0), Float32x4(13.37, 42.42, NaN, 0)]]) + { + testMinFloat32(v, w); + testMaxFloat32(v, w); + testMinNumFloat32(v, w); + testMaxNumFloat32(v, w); + } + + for ([v, w] of [[Float64x2(1, 20), Float64x2(10, 2)], + [Float64x2(30, 4), Float64x2(3, 40)], + [Float64x2(9.999, 2.1234), Float64x2(10, 2.1233)], + [Float64x2(30.4443, 4), Float64x2(30.4444, 4.0001)], + [Float64x2(NaN, -Infinity), Float64x2(13.37, 42.42)], + [Float64x2(+Infinity, -0), Float64x2(NaN, 0)]]) + { + testMinFloat64(v, w); + testMaxFloat64(v, w); + testMinNumFloat64(v, w); + testMaxNumFloat64(v, w); + } + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); + diff --git a/js/src/tests/ecma_7/SIMD/replaceLane.js b/js/src/tests/ecma_7/SIMD/replaceLane.js new file mode 100644 index 000000000..b285dc271 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/replaceLane.js @@ -0,0 +1,226 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +function replaceLaneN(laneIndex, arr, value) { + var copy = arr.slice(); + assertEq(laneIndex <= arr.length, true); + copy[laneIndex] = value; + return copy; +} + +var replaceLane0 = replaceLaneN.bind(null, 0); +var replaceLane1 = replaceLaneN.bind(null, 1); +var replaceLane2 = replaceLaneN.bind(null, 2); +var replaceLane3 = replaceLaneN.bind(null, 3); +var replaceLane4 = replaceLaneN.bind(null, 4); +var replaceLane5 = replaceLaneN.bind(null, 5); +var replaceLane6 = replaceLaneN.bind(null, 6); +var replaceLane7 = replaceLaneN.bind(null, 7); +var replaceLane8 = replaceLaneN.bind(null, 8); +var replaceLane9 = replaceLaneN.bind(null, 9); +var replaceLane10 = replaceLaneN.bind(null, 10); +var replaceLane11 = replaceLaneN.bind(null, 11); +var replaceLane12 = replaceLaneN.bind(null, 12); +var replaceLane13 = replaceLaneN.bind(null, 13); +var replaceLane14 = replaceLaneN.bind(null, 14); +var replaceLane15 = replaceLaneN.bind(null, 15); + +function testReplaceLane(vec, scalar, simdFunc, func) { + var varr = simdToArray(vec); + var observed = simdToArray(simdFunc(vec, scalar)); + var expected = func(varr, scalar); + for (var i = 0; i < observed.length; i++) + assertEq(observed[i], expected[i]); +} + +function test() { + function testType(type, inputs) { + var length = simdToArray(inputs[0][0]).length; + for (var [vec, s] of inputs) { + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 0, y), replaceLane0); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 1, y), replaceLane1); + if (length <= 2) + continue; + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 2, y), replaceLane2); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 3, y), replaceLane3); + if (length <= 4) + continue; + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 4, y), replaceLane4); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 5, y), replaceLane5); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 6, y), replaceLane6); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 7, y), replaceLane7); + if (length <= 8) + continue; + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 8, y), replaceLane8); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 9, y), replaceLane9); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 10, y), replaceLane10); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 11, y), replaceLane11); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 12, y), replaceLane12); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 13, y), replaceLane13); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 14, y), replaceLane14); + testReplaceLane(vec, s, (x,y) => SIMD[type].replaceLane(x, 15, y), replaceLane15); + } + } + + function TestError(){}; + var good = {valueOf: () => 42}; + var bad = {valueOf: () => {throw new TestError(); }}; + + var Float32x4inputs = [ + [Float32x4(1, 2, 3, 4), 5], + [Float32x4(1.87, 2.08, 3.84, 4.17), Math.fround(13.37)], + [Float32x4(NaN, -0, Infinity, -Infinity), 0] + ]; + testType('Float32x4', Float32x4inputs); + + var v = Float32x4inputs[1][0]; + assertEqX4(Float32x4.replaceLane(v, 0), replaceLane0(simdToArray(v), NaN)); + assertEqX4(Float32x4.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Float32x4.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Float32x4.replaceLane(v, 4, good), RangeError); + assertThrowsInstanceOf(() => Float32x4.replaceLane(v, 1.1, good), RangeError); + + var Float64x2inputs = [ + [Float64x2(1, 2), 5], + [Float64x2(1.87, 2.08), Math.fround(13.37)], + [Float64x2(NaN, -0), 0] + ]; + testType('Float64x2', Float64x2inputs); + + var v = Float64x2inputs[1][0]; + assertEqX2(Float64x2.replaceLane(v, 0), replaceLane0(simdToArray(v), NaN)); + assertEqX2(Float64x2.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Float64x2.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Float64x2.replaceLane(v, 2, good), RangeError); + assertThrowsInstanceOf(() => Float64x2.replaceLane(v, 1.1, good), RangeError); + + var Int8x16inputs = [[Int8x16(0, 1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, INT8_MIN, INT8_MAX), 17]]; + testType('Int8x16', Int8x16inputs); + + var v = Int8x16inputs[0][0]; + assertEqX16(Int8x16.replaceLane(v, 0), replaceLane0(simdToArray(v), 0)); + assertEqX16(Int8x16.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Int8x16.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Int8x16.replaceLane(v, 16, good), RangeError); + assertThrowsInstanceOf(() => Int8x16.replaceLane(v, 1.1, good), RangeError); + + var Int16x8inputs = [[Int16x8(0, 1, 2, 3, -1, -2, INT16_MIN, INT16_MAX), 9]]; + testType('Int16x8', Int16x8inputs); + + var v = Int16x8inputs[0][0]; + assertEqX8(Int16x8.replaceLane(v, 0), replaceLane0(simdToArray(v), 0)); + assertEqX8(Int16x8.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Int16x8.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Int16x8.replaceLane(v, 8, good), RangeError); + assertThrowsInstanceOf(() => Int16x8.replaceLane(v, 1.1, good), RangeError); + + var Int32x4inputs = [ + [Int32x4(1, 2, 3, 4), 5], + [Int32x4(INT32_MIN, INT32_MAX, 3, 4), INT32_MIN], + ]; + testType('Int32x4', Int32x4inputs); + + var v = Int32x4inputs[1][0]; + assertEqX4(Int32x4.replaceLane(v, 0), replaceLane0(simdToArray(v), 0)); + assertEqX4(Int32x4.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Int32x4.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Int32x4.replaceLane(v, 4, good), RangeError); + assertThrowsInstanceOf(() => Int32x4.replaceLane(v, 1.1, good), RangeError); + + var Uint8x16inputs = [[Uint8x16(0, 1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, INT8_MIN, UINT8_MAX), 17]]; + testType('Uint8x16', Uint8x16inputs); + + var v = Uint8x16inputs[0][0]; + assertEqX16(Uint8x16.replaceLane(v, 0), replaceLane0(simdToArray(v), 0)); + assertEqX16(Uint8x16.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Uint8x16.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Uint8x16.replaceLane(v, 16, good), RangeError); + assertThrowsInstanceOf(() => Uint8x16.replaceLane(v, 1.1, good), RangeError); + + var Uint16x8inputs = [[Uint16x8(0, 1, 2, 3, -1, -2, INT16_MIN, UINT16_MAX), 9]]; + testType('Uint16x8', Uint16x8inputs); + + var v = Uint16x8inputs[0][0]; + assertEqX8(Uint16x8.replaceLane(v, 0), replaceLane0(simdToArray(v), 0)); + assertEqX8(Uint16x8.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Uint16x8.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Uint16x8.replaceLane(v, 8, good), RangeError); + assertThrowsInstanceOf(() => Uint16x8.replaceLane(v, 1.1, good), RangeError); + + var Uint32x4inputs = [ + [Uint32x4(1, 2, 3, 4), 5], + [Uint32x4(INT32_MIN, UINT32_MAX, INT32_MAX, 4), UINT32_MAX], + ]; + testType('Uint32x4', Uint32x4inputs); + + var v = Uint32x4inputs[1][0]; + assertEqX4(Uint32x4.replaceLane(v, 0), replaceLane0(simdToArray(v), 0)); + assertEqX4(Uint32x4.replaceLane(v, 0, good), replaceLane0(simdToArray(v), good | 0)); + assertThrowsInstanceOf(() => Uint32x4.replaceLane(v, 0, bad), TestError); + assertThrowsInstanceOf(() => Uint32x4.replaceLane(v, 4, good), RangeError); + assertThrowsInstanceOf(() => Uint32x4.replaceLane(v, 1.1, good), RangeError); + + var Bool64x2inputs = [ + [Bool64x2(true, true), false], + ]; + testType('Bool64x2', Bool64x2inputs); + + var v = Bool64x2inputs[0][0]; + assertEqX2(Bool64x2.replaceLane(v, 0), replaceLane0(simdToArray(v), false)); + assertEqX2(Bool64x2.replaceLane(v, 0, true), replaceLane0(simdToArray(v), true)); + assertEqX2(Bool64x2.replaceLane(v, 0, bad), replaceLane0(simdToArray(v), true)); + assertThrowsInstanceOf(() => Bool64x2.replaceLane(v, 4, true), RangeError); + assertThrowsInstanceOf(() => Bool64x2.replaceLane(v, 1.1, false), RangeError); + + var Bool32x4inputs = [ + [Bool32x4(true, true, true, true), false], + ]; + testType('Bool32x4', Bool32x4inputs); + + var v = Bool32x4inputs[0][0]; + assertEqX4(Bool32x4.replaceLane(v, 0), replaceLane0(simdToArray(v), false)); + assertEqX4(Bool32x4.replaceLane(v, 0, true), replaceLane0(simdToArray(v), true)); + assertEqX4(Bool32x4.replaceLane(v, 0, bad), replaceLane0(simdToArray(v), true)); + assertThrowsInstanceOf(() => Bool32x4.replaceLane(v, 4, true), RangeError); + assertThrowsInstanceOf(() => Bool32x4.replaceLane(v, 1.1, false), RangeError); + + var Bool16x8inputs = [ + [Bool16x8(true, true, true, true, true, true, true, true), false], + ]; + + testType('Bool16x8', Bool16x8inputs); + var v = Bool16x8inputs[0][0]; + assertEqX8(Bool16x8.replaceLane(v, 0), replaceLane0(simdToArray(v), false)); + assertEqX8(Bool16x8.replaceLane(v, 0, true), replaceLane0(simdToArray(v), true)); + assertEqX8(Bool16x8.replaceLane(v, 0, bad), replaceLane0(simdToArray(v), true)); + assertThrowsInstanceOf(() => Bool16x8.replaceLane(v, 16, true), RangeError); + assertThrowsInstanceOf(() => Bool16x8.replaceLane(v, 1.1, false), RangeError); + + var Bool8x16inputs = [ + [Bool8x16(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true), false], + ]; + + testType('Bool8x16', Bool8x16inputs); + var v = Bool8x16inputs[0][0]; + assertEqX16(Bool8x16.replaceLane(v, 0), replaceLane0(simdToArray(v), false)); + assertEqX16(Bool8x16.replaceLane(v, 0, true), replaceLane0(simdToArray(v), true)); + assertEqX16(Bool8x16.replaceLane(v, 0, bad), replaceLane0(simdToArray(v), true)); + assertThrowsInstanceOf(() => Bool8x16.replaceLane(v, 16, true), RangeError); + assertThrowsInstanceOf(() => Bool8x16.replaceLane(v, 1.1, false), RangeError); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/select-bitselect.js b/js/src/tests/ecma_7/SIMD/select-bitselect.js new file mode 100644 index 000000000..61fcd1a3f --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/select-bitselect.js @@ -0,0 +1,133 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +function getMask(i, maskLength) { + var args = []; + for (var j = 0; j < maskLength; j++) + args.push((i >> j) & 1); + if (maskLength == 2) + return Bool64x2(...args); + else if (maskLength == 4) + return Bool32x4(...args); + else if (maskLength == 8) + return Bool16x8(...args); + else if (maskLength == 16) + return Bool8x16(...args); + else + throw new Error("Invalid mask length."); +} + +function select(mask, ifTrue, ifFalse) { + var m = simdToArray(mask); + var tv = simdToArray(ifTrue); + var fv = simdToArray(ifFalse); + return m.map(function(v, i) { + return (v ? tv : fv)[i]; + }); +} + +/** + * Tests type.select on all input pairs, for all possible masks. As the mask + * has 4 lanes (for Int32x4) and 2 possible values (true or false), there are 16 possible + * masks. For Int8x16, the mask has 16 lanes and 2 possible values, so there are 256 + * possible masks. For Int16x8, the mask has 8 lanes and 2 possible values, so there + * are 64 possible masks. + */ +function testSelect(type, inputs) { + var x, y; + var maskLength = simdLengthType(type); + for (var i = 0; i < Math.pow(maskLength, 2); i++) { + var mask = getMask(i, maskLength); + for ([x, y] of inputs) + assertEqVec(type.select(mask, x, y), select(mask, x, y)); + } +} + +function test() { + var inputs = [ + [Int8x16(0,4,9,16,25,36,49,64,81,121,-4,-9,-16,-25,-36,-49), Int8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)], + [Int8x16(-1, 2, INT8_MAX, INT8_MIN, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Int8x16(INT8_MAX, -4, INT8_MIN, 42, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)] + ]; + + testSelect(Int8x16, inputs); + + inputs = [ + [Int16x8(0,4,9,16,25,36,49,64), Int16x8(1,2,3,4,5,6,7,8)], + [Int16x8(-1, 2, INT16_MAX, INT16_MIN, 5, 6, 7, 8), + Int16x8(INT16_MAX, -4, INT16_MIN, 42, 5, 6, 7, 8)] + ]; + + testSelect(Int16x8, inputs); + + inputs = [ + [Int32x4(0,4,9,16), Int32x4(1,2,3,4)], + [Int32x4(-1, 2, INT32_MAX, INT32_MIN), Int32x4(INT32_MAX, -4, INT32_MIN, 42)] + ]; + + testSelect(Int32x4, inputs); + + inputs = [ + [Uint8x16(0,4,9,16,25,36,49,64,81,121,-4,-9,-16,-25,-36,-49), Uint8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)], + [Uint8x16(-1, 2, INT8_MAX, INT8_MIN, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Uint8x16(INT8_MAX, -4, INT8_MIN, 42, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)] + ]; + + testSelect(Uint8x16, inputs); + + inputs = [ + [Uint16x8(0,4,9,16,25,36,49,64), Uint16x8(1,2,3,4,5,6,7,8)], + [Uint16x8(-1, 2, INT16_MAX, INT16_MIN, 5, 6, 7, 8), + Uint16x8(INT16_MAX, -4, INT16_MIN, 42, 5, 6, 7, 8)] + ]; + + testSelect(Uint16x8, inputs); + + inputs = [ + [Uint32x4(0,4,9,16), Uint32x4(1,2,3,4)], + [Uint32x4(-1, 2, INT32_MAX, INT32_MIN), Uint32x4(INT32_MAX, -4, INT32_MIN, 42)] + ]; + + testSelect(Uint32x4, inputs); + + inputs = [ + [Float32x4(0.125,4.25,9.75,16.125), Float32x4(1.5,2.75,3.25,4.5)], + [Float32x4(-1.5,-0,NaN,-Infinity), Float32x4(1,-2,13.37,3.13)], + [Float32x4(1.5,2.75,NaN,Infinity), Float32x4(-NaN,-Infinity,9.75,16.125)] + ]; + + testSelect(Float32x4, inputs); + + inputs = [ + [Float64x2(0.125,4.25), Float64x2(9.75,16.125)], + [Float64x2(1.5,2.75), Float64x2(3.25,4.5)], + [Float64x2(-1.5,-0), Float64x2(NaN,-Infinity)], + [Float64x2(1,-2), Float64x2(13.37,3.13)], + [Float64x2(1.5,2.75), Float64x2(NaN,Infinity)], + [Float64x2(-NaN,-Infinity), Float64x2(9.75,16.125)] + ]; + + testSelect(Float64x2, inputs); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/shell.js b/js/src/tests/ecma_7/SIMD/shell.js new file mode 100644 index 000000000..943965390 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/shell.js @@ -0,0 +1,580 @@ +function makeFloat(sign, exp, mantissa) { + assertEq(sign, sign & 0x1); + assertEq(exp, exp & 0xFF); + assertEq(mantissa, mantissa & 0x7FFFFF); + + var i32 = new Int32Array(1); + var f32 = new Float32Array(i32.buffer); + + i32[0] = (sign << 31) | (exp << 23) | mantissa; + return f32[0]; +} + +function makeDouble(sign, exp, mantissa) { + assertEq(sign, sign & 0x1); + assertEq(exp, exp & 0x7FF); + + // Can't use bitwise operations on mantissa, as it might be a double + assertEq(mantissa <= 0xfffffffffffff, true); + var highBits = (mantissa / Math.pow(2, 32)) | 0; + var lowBits = mantissa - highBits * Math.pow(2, 32); + + var i32 = new Int32Array(2); + var f64 = new Float64Array(i32.buffer); + + // Note that this assumes little-endian order, which is the case on tier-1 + // platforms. + i32[0] = lowBits; + i32[1] = (sign << 31) | (exp << 20) | highBits; + return f64[0]; +} + +function GetType(v) { + switch (Object.getPrototypeOf(v)) { + 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.Float64x2.prototype: return SIMD.Float64x2; + case SIMD.Bool8x16.prototype: return SIMD.Bool8x16; + case SIMD.Bool16x8.prototype: return SIMD.Bool16x8; + case SIMD.Bool32x4.prototype: return SIMD.Bool32x4; + case SIMD.Bool64x2.prototype: return SIMD.Bool64x2; + } +} + +function assertEqFloat64x2(v, arr) { + try { + assertEq(SIMD.Float64x2.extractLane(v, 0), arr[0]); + assertEq(SIMD.Float64x2.extractLane(v, 1), arr[1]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqBool64x2(v, arr) { + try { + assertEq(SIMD.Bool64x2.extractLane(v, 0), arr[0]); + assertEq(SIMD.Bool64x2.extractLane(v, 1), arr[1]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqX2(v, arr) { + var Type = GetType(v); + if (Type === SIMD.Float64x2) assertEqFloat64x2(v, arr); + else if (Type === SIMD.Bool64x2) assertEqBool64x2(v, arr); + else throw new TypeError("Unknown SIMD kind."); +} + +function assertEqInt32x4(v, arr) { + try { + for (var i = 0; i < 4; i++) + assertEq(SIMD.Int32x4.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqUint32x4(v, arr) { + try { + for (var i = 0; i < 4; i++) + assertEq(SIMD.Uint32x4.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqFloat32x4(v, arr) { + try { + for (var i = 0; i < 4; i++) + assertEq(SIMD.Float32x4.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqBool32x4(v, arr) { + try { + for (var i = 0; i < 4; i++) + assertEq(SIMD.Bool32x4.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqX4(v, arr) { + var Type = GetType(v); + if (Type === SIMD.Int32x4) assertEqInt32x4(v, arr); + else if (Type === SIMD.Uint32x4) assertEqUint32x4(v, arr); + else if (Type === SIMD.Float32x4) assertEqFloat32x4(v, arr); + else if (Type === SIMD.Bool32x4) assertEqBool32x4(v, arr); + else throw new TypeError("Unknown SIMD kind."); +} + +function assertEqInt16x8(v, arr) { + try { + for (var i = 0; i < 8; i++) + assertEq(SIMD.Int16x8.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqUint16x8(v, arr) { + try { + for (var i = 0; i < 8; i++) + assertEq(SIMD.Uint16x8.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqBool16x8(v, arr) { + try { + for (var i = 0; i < 8; i++){ + assertEq(SIMD.Bool16x8.extractLane(v, i), arr[i]); + } + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqX8(v, arr) { + var Type = GetType(v); + if (Type === SIMD.Int16x8) assertEqInt16x8(v, arr); + else if (Type === SIMD.Uint16x8) assertEqUint16x8(v, arr); + else if (Type === SIMD.Bool16x8) assertEqBool16x8(v, arr); + else throw new TypeError("Unknown x8 vector."); +} + +function assertEqInt8x16(v, arr) { + try { + for (var i = 0; i < 16; i++) + assertEq(SIMD.Int8x16.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqUint8x16(v, arr) { + try { + for (var i = 0; i < 16; i++) + assertEq(SIMD.Uint8x16.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqBool8x16(v, arr) { + try { + for (var i = 0; i < 16; i++) + assertEq(SIMD.Bool8x16.extractLane(v, i), arr[i]); + } catch (e) { + print("stack trace:", e.stack); + throw e; + } +} + +function assertEqX16(v, arr) { + var Type = GetType(v); + if (Type === SIMD.Int8x16) assertEqInt8x16(v, arr); + else if (Type === SIMD.Uint8x16) assertEqUint8x16(v, arr); + else if (Type === SIMD.Bool8x16) assertEqBool8x16(v, arr); + else throw new TypeError("Unknown x16 vector."); +} + +function simdLength(v) { + var pt = Object.getPrototypeOf(v); + if (pt == SIMD.Int8x16.prototype || pt == SIMD.Uint8x16.prototype || + pt === SIMD.Bool8x16.prototype) + return 16; + if (pt == SIMD.Int16x8.prototype || pt == SIMD.Uint16x8.prototype || + pt === SIMD.Bool16x8.prototype) + return 8; + if (pt === SIMD.Int32x4.prototype || pt === SIMD.Uint32x4.prototype || + pt === SIMD.Float32x4.prototype || pt === SIMD.Bool32x4.prototype) + return 4; + if (pt === SIMD.Float64x2.prototype || pt == SIMD.Bool64x2.prototype) + return 2; + throw new TypeError("Unknown SIMD kind."); +} + +function simdLengthType(t) { + if (t == SIMD.Int8x16 || t == SIMD.Uint8x16 || t == SIMD.Bool8x16) + return 16; + else if (t == SIMD.Int16x8 || t == SIMD.Uint16x8 || t == SIMD.Bool16x8) + return 8; + else if (t == SIMD.Int32x4 || t == SIMD.Uint32x4 || t == SIMD.Float32x4 || t == SIMD.Bool32x4) + return 4; + else if (t == SIMD.Float64x2 || t == SIMD.Bool64x2) + return 2; + else + throw new TypeError("Unknown SIMD kind."); +} + +function getAssertFuncFromLength(l) { + if (l == 2) + return assertEqX2; + else if (l == 4) + return assertEqX4; + else if (l == 8) + return assertEqX8; + else if (l == 16) + return assertEqX16; + else + throw new TypeError("Unknown SIMD kind."); +} + +function assertEqVec(v, arr) { + var Type = GetType(v); + if (Type === SIMD.Int8x16) assertEqInt8x16(v, arr); + else if (Type === SIMD.Int16x8) assertEqInt16x8(v, arr); + else if (Type === SIMD.Int32x4) assertEqInt32x4(v, arr); + else if (Type === SIMD.Uint8x16) assertEqUint8x16(v, arr); + else if (Type === SIMD.Uint16x8) assertEqUint16x8(v, arr); + else if (Type === SIMD.Uint32x4) assertEqUint32x4(v, arr); + else if (Type === SIMD.Float32x4) assertEqFloat32x4(v, arr); + else if (Type === SIMD.Float64x2) assertEqFloat64x2(v, arr); + else if (Type === SIMD.Bool8x16) assertEqBool8x16(v, arr); + else if (Type === SIMD.Bool16x8) assertEqBool16x8(v, arr); + else if (Type === SIMD.Bool32x4) assertEqBool32x4(v, arr); + else if (Type === SIMD.Bool64x2) assertEqBool64x2(v, arr); + else throw new TypeError("Unknown SIMD Kind"); +} + +function simdToArray(v) { + var Type = GetType(v); + + function indexes(n) { + var arr = []; + for (var i = 0; i < n; i++) arr.push(i); + return arr; + } + + if (Type === SIMD.Bool8x16) { + return indexes(16).map((i) => SIMD.Bool8x16.extractLane(v, i)); + } + + if (Type === SIMD.Bool16x8) { + return indexes(8).map((i) => SIMD.Bool16x8.extractLane(v, i)); + } + + if (Type === SIMD.Bool32x4) { + return indexes(4).map((i) => SIMD.Bool32x4.extractLane(v, i)); + } + + if (Type === SIMD.Bool64x2) { + return indexes(2).map((i) => SIMD.Bool64x2.extractLane(v, i)); + } + + if (Type === SIMD.Int8x16) { + return indexes(16).map((i) => SIMD.Int8x16.extractLane(v, i)); + } + + if (Type === SIMD.Int16x8) { + return indexes(8).map((i) => SIMD.Int16x8.extractLane(v, i)); + } + + if (Type === SIMD.Int32x4) { + return indexes(4).map((i) => SIMD.Int32x4.extractLane(v, i)); + } + + if (Type === SIMD.Uint8x16) { + return indexes(16).map((i) => SIMD.Uint8x16.extractLane(v, i)); + } + + if (Type === SIMD.Uint16x8) { + return indexes(8).map((i) => SIMD.Uint16x8.extractLane(v, i)); + } + + if (Type === SIMD.Uint32x4) { + return indexes(4).map((i) => SIMD.Uint32x4.extractLane(v, i)); + } + + if (Type === SIMD.Float32x4) { + return indexes(4).map((i) => SIMD.Float32x4.extractLane(v, i)); + } + + if (Type === SIMD.Float64x2) { + return indexes(2).map((i) => SIMD.Float64x2.extractLane(v, i)); + } + + throw new TypeError("Unknown SIMD Kind"); +} + +const INT8_MAX = Math.pow(2, 7) -1; +const INT8_MIN = -Math.pow(2, 7); +assertEq((INT8_MAX + 1) << 24 >> 24, INT8_MIN); +const INT16_MAX = Math.pow(2, 15) - 1; +const INT16_MIN = -Math.pow(2, 15); +assertEq((INT16_MAX + 1) << 16 >> 16, INT16_MIN); +const INT32_MAX = Math.pow(2, 31) - 1; +const INT32_MIN = -Math.pow(2, 31); +assertEq(INT32_MAX + 1 | 0, INT32_MIN); + +const UINT8_MAX = Math.pow(2, 8) - 1; +const UINT16_MAX = Math.pow(2, 16) - 1; +const UINT32_MAX = Math.pow(2, 32) - 1; + +function testUnaryFunc(v, simdFunc, func) { + var varr = simdToArray(v); + + var observed = simdToArray(simdFunc(v)); + var expected = varr.map(function(v, i) { return func(varr[i]); }); + + for (var i = 0; i < observed.length; i++) + assertEq(observed[i], expected[i]); +} + +function testBinaryFunc(v, w, simdFunc, func) { + var varr = simdToArray(v); + var warr = simdToArray(w); + + var observed = simdToArray(simdFunc(v, w)); + var expected = varr.map(function(v, i) { return func(varr[i], warr[i]); }); + + for (var i = 0; i < observed.length; i++) + assertEq(observed[i], expected[i]); +} + +function testBinaryCompare(v, w, simdFunc, func, outType) { + var varr = simdToArray(v); + var warr = simdToArray(w); + + var inLanes = simdLength(v); + var observed = simdToArray(simdFunc(v, w)); + var outTypeLen = simdLengthType(outType); + assertEq(observed.length, outTypeLen); + for (var i = 0; i < outTypeLen; i++) { + var j = ((i * inLanes) / outTypeLen) | 0; + assertEq(observed[i], func(varr[j], warr[j])); + } +} + +function testBinaryScalarFunc(v, scalar, simdFunc, func) { + var varr = simdToArray(v); + + var observed = simdToArray(simdFunc(v, scalar)); + var expected = varr.map(function(v, i) { return func(varr[i], scalar); }); + + for (var i = 0; i < observed.length; i++) + assertEq(observed[i], expected[i]); +} + +// Our array for Int32x4 and Float32x4 will have 16 elements +const SIZE_8_ARRAY = 64; +const SIZE_16_ARRAY = 32; +const SIZE_32_ARRAY = 16; +const SIZE_64_ARRAY = 8; + +const SIZE_BYTES = SIZE_32_ARRAY * 4; + +function MakeComparator(kind, arr, shared) { + var bpe = arr.BYTES_PER_ELEMENT; + var uint8 = (bpe != 1) ? new Uint8Array(arr.buffer) : arr; + + // Size in bytes of a single element in the SIMD vector. + var sizeOfLaneElem; + // Typed array constructor corresponding to the SIMD kind. + var typedArrayCtor; + switch (kind) { + case 'Int8x16': + sizeOfLaneElem = 1; + typedArrayCtor = Int8Array; + break; + case 'Int16x8': + sizeOfLaneElem = 2; + typedArrayCtor = Int16Array; + break; + case 'Int32x4': + sizeOfLaneElem = 4; + typedArrayCtor = Int32Array; + break; + case 'Uint8x16': + sizeOfLaneElem = 1; + typedArrayCtor = Uint8Array; + break; + case 'Uint16x8': + sizeOfLaneElem = 2; + typedArrayCtor = Uint16Array; + break; + case 'Uint32x4': + sizeOfLaneElem = 4; + typedArrayCtor = Uint32Array; + break; + case 'Float32x4': + sizeOfLaneElem = 4; + typedArrayCtor = Float32Array; + break; + case 'Float64x2': + sizeOfLaneElem = 8; + typedArrayCtor = Float64Array; + break; + default: + assertEq(true, false, "unknown SIMD kind"); + } + var lanes = 16 / sizeOfLaneElem; + // Reads (numElemToRead * sizeOfLaneElem) bytes in arr, and reinterprets + // these bytes as a typed array equivalent to the typed SIMD vector. + var slice = function(start, numElemToRead) { + // Read enough bytes + var startBytes = start * bpe; + var endBytes = startBytes + numElemToRead * sizeOfLaneElem; + var asArray = Array.prototype.slice.call(uint8, startBytes, endBytes); + + // If length is less than SIZE_BYTES bytes, fill with 0. + // This is needed for load1, load2, load3 which do only partial + // reads. + for (var i = asArray.length; i < SIZE_BYTES; i++) asArray[i] = 0; + assertEq(asArray.length, SIZE_BYTES); + + return new typedArrayCtor(new Uint8Array(asArray).buffer); + } + + var assertFunc = getAssertFuncFromLength(lanes); + var type = SIMD[kind]; + return { + load1: function(index) { + if (lanes >= 8) // Int8x16 and Int16x8 only support load, no load1/load2/etc. + return + var v = type.load1(arr, index); + assertFunc(v, slice(index, 1)); + }, + + load2: function(index) { + if (lanes !== 4) + return; + var v = type.load2(arr, index); + assertFunc(v, slice(index, 2)); + }, + + load3: function(index) { + if (lanes !== 4) + return; + var v = type.load3(arr, index); + assertFunc(v, slice(index, 3)); + }, + + load: function(index) { + var v = type.load(arr, index); + assertFunc(v, slice(index, lanes)); + } + } +} + +function testLoad(kind, TA) { + var lanes = TA.length / 4; + for (var i = TA.length; i--;) + TA[i] = i; + + for (var ta of [ + new Uint8Array(TA.buffer), + new Int8Array(TA.buffer), + new Uint16Array(TA.buffer), + new Int16Array(TA.buffer), + new Uint32Array(TA.buffer), + new Int32Array(TA.buffer), + new Float32Array(TA.buffer), + new Float64Array(TA.buffer) + ]) + { + // Invalid args + assertThrowsInstanceOf(() => SIMD[kind].load(), TypeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta), TypeError); + assertThrowsInstanceOf(() => SIMD[kind].load("hello", 0), TypeError); + // Indexes must be integers, there is no rounding. + assertThrowsInstanceOf(() => SIMD[kind].load(ta, 1.5), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, -1), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, "hello"), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, NaN), RangeError); + // Try to trip up the bounds checking. Int32 is enough for everybody. + assertThrowsInstanceOf(() => SIMD[kind].load(ta, 0x100000000), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, 0x80000000), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, 0x40000000), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, 0x20000000), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, (1<<30) * (1<<23) - 1), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load(ta, (1<<30) * (1<<23)), RangeError); + + // Valid and invalid reads + var C = MakeComparator(kind, ta); + var bpe = ta.BYTES_PER_ELEMENT; + + var lastValidArgLoad1 = (SIZE_BYTES - (16 / lanes)) / bpe | 0; + var lastValidArgLoad2 = (SIZE_BYTES - 8) / bpe | 0; + var lastValidArgLoad3 = (SIZE_BYTES - 12) / bpe | 0; + var lastValidArgLoad = (SIZE_BYTES - 16) / bpe | 0; + + C.load(0); + C.load(1); + C.load(2); + C.load(3); + C.load(lastValidArgLoad); + + C.load1(0); + C.load1(1); + C.load1(2); + C.load1(3); + C.load1(lastValidArgLoad1); + + C.load2(0); + C.load2(1); + C.load2(2); + C.load2(3); + C.load2(lastValidArgLoad2); + + C.load3(0); + C.load3(1); + C.load3(2); + C.load3(3); + C.load3(lastValidArgLoad3); + + assertThrowsInstanceOf(() => SIMD[kind].load(ta, lastValidArgLoad + 1), RangeError); + if (lanes <= 4) { + assertThrowsInstanceOf(() => SIMD[kind].load1(ta, lastValidArgLoad1 + 1), RangeError); + } + if (lanes == 4) { + assertThrowsInstanceOf(() => SIMD[kind].load2(ta, lastValidArgLoad2 + 1), RangeError); + assertThrowsInstanceOf(() => SIMD[kind].load3(ta, lastValidArgLoad3 + 1), RangeError); + } + + // Indexes are coerced with ToNumber. Try some strings that + // CanonicalNumericIndexString() would reject. + C.load("1.0e0"); + C.load(" 2"); + } + + if (lanes == 4) { + // Test ToNumber behavior. + var obj = { + valueOf: function() { return 12 } + } + var v = SIMD[kind].load(TA, obj); + assertEqX4(v, [12, 13, 14, 15]); + } + + var obj = { + valueOf: function() { throw new TypeError("i ain't a number"); } + } + assertThrowsInstanceOf(() => SIMD[kind].load(TA, obj), TypeError); +} + +var Helpers = { + testLoad, + MakeComparator +}; diff --git a/js/src/tests/ecma_7/SIMD/shifts.js b/js/src/tests/ecma_7/SIMD/shifts.js new file mode 100644 index 000000000..1d81f7483 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/shifts.js @@ -0,0 +1,202 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; + +// Int8 shifts. +function lsh8(a, b) { + return (a << (b & 7)) << 24 >> 24; +} +function rsha8(a, b) { + return (a >> (b & 7)) << 24 >> 24; +} +function rshl8(a, b) { + return (a >>> (b & 7)) << 24 >> 24; +} + +// Int16 shifts. +function lsh16(a, b) { + return (a << (b & 15)) << 16 >> 16; +} +function rsha16(a, b) { + return (a >> (b & 15)) << 16 >> 16; +} +function rshl16(a, b) { + return (a >>> (b & 15)) << 16 >> 16; +} + +// Int32 shifts. +function lsh32(a, b) { + return (a << (b & 31)) | 0; +} +function rsha32(a, b) { + return (a >> (b & 31)) | 0; +} +function rshl32(a, b) { + return (a >>> (b & 31)) | 0; +} + +// Uint8 shifts. +function ulsh8(a, b) { + return (a << (b & 7)) << 24 >>> 24; +} +function ursha8(a, b) { + return ((a << 24 >> 24) >> (b & 7)) << 24 >>> 24; +} +function urshl8(a, b) { + return (a >>> (b & 7)) << 24 >>> 24; +} + +// Uint16 shifts. +function ulsh16(a, b) { + return (a << (b & 15)) << 16 >>> 16; +} +function ursha16(a, b) { + return ((a << 16 >> 16) >> (b & 15)) << 16 >>> 16; +} +function urshl16(a, b) { + return (a >>> (b & 15)) << 16 >>> 16; +} + +// Uint32 shifts. +function ulsh32(a, b) { + return (a << (b & 31)) >>> 0; +} +function ursha32(a, b) { + return ((a | 0) >> (b & 31)) >>> 0; +} +function urshl32(a, b) { + return (a >>> (b & 31)) >>> 0; +} + +function test() { + function TestError() {}; + + var good = {valueOf: () => 21}; + var bad = {valueOf: () => {throw new TestError(); }}; + + for (var v of [ + Int8x16(-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16), + Int8x16(INT8_MAX, INT8_MIN, INT8_MAX - 1, INT8_MIN + 1) + ]) + { + for (var bits = -2; bits < 12; bits++) { + testBinaryScalarFunc(v, bits, Int8x16.shiftLeftByScalar, lsh8); + testBinaryScalarFunc(v, bits, Int8x16.shiftRightByScalar, rsha8); + } + // Test that the shift count is coerced to an int32. + testBinaryScalarFunc(v, undefined, Int8x16.shiftLeftByScalar, lsh8); + testBinaryScalarFunc(v, 3.5, Int8x16.shiftLeftByScalar, lsh8); + testBinaryScalarFunc(v, good, Int8x16.shiftLeftByScalar, lsh8); + } + for (var v of [ + Int16x8(-1, 2, -3, 4, -5, 6, -7, 8), + Int16x8(INT16_MAX, INT16_MIN, INT16_MAX - 1, INT16_MIN + 1) + ]) + { + for (var bits = -2; bits < 20; bits++) { + testBinaryScalarFunc(v, bits, Int16x8.shiftLeftByScalar, lsh16); + testBinaryScalarFunc(v, bits, Int16x8.shiftRightByScalar, rsha16); + } + // Test that the shift count is coerced to an int32. + testBinaryScalarFunc(v, undefined, Int16x8.shiftLeftByScalar, lsh16); + testBinaryScalarFunc(v, 3.5, Int16x8.shiftLeftByScalar, lsh16); + testBinaryScalarFunc(v, good, Int16x8.shiftLeftByScalar, lsh16); + } + for (var v of [ + Int32x4(-1, 2, -3, 4), + Int32x4(INT32_MAX, INT32_MIN, INT32_MAX - 1, INT32_MIN + 1) + ]) + { + for (var bits = -2; bits < 36; bits++) { + testBinaryScalarFunc(v, bits, Int32x4.shiftLeftByScalar, lsh32); + testBinaryScalarFunc(v, bits, Int32x4.shiftRightByScalar, rsha32); + } + // Test that the shift count is coerced to an int32. + testBinaryScalarFunc(v, undefined, Int32x4.shiftLeftByScalar, lsh32); + testBinaryScalarFunc(v, 3.5, Int32x4.shiftLeftByScalar, lsh32); + testBinaryScalarFunc(v, good, Int32x4.shiftLeftByScalar, lsh32); + } + + for (var v of [ + Uint8x16(-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16), + Uint8x16(INT8_MAX, INT8_MIN, INT8_MAX - 1, INT8_MIN + 1, UINT8_MAX, UINT8_MAX - 1) + ]) + { + for (var bits = -2; bits < 12; bits++) { + testBinaryScalarFunc(v, bits, Uint8x16.shiftLeftByScalar, ulsh8); + testBinaryScalarFunc(v, bits, Uint8x16.shiftRightByScalar, urshl8); + } + // Test that the shift count is coerced to an int32. + testBinaryScalarFunc(v, undefined, Uint8x16.shiftLeftByScalar, ulsh8); + testBinaryScalarFunc(v, 3.5, Uint8x16.shiftLeftByScalar, ulsh8); + testBinaryScalarFunc(v, good, Uint8x16.shiftLeftByScalar, ulsh8); + } + for (var v of [ + Uint16x8(-1, 2, -3, 4, -5, 6, -7, 8), + Uint16x8(INT16_MAX, INT16_MIN, INT16_MAX - 1, INT16_MIN + 1, UINT16_MAX, UINT16_MAX - 1) + ]) + { + for (var bits = -2; bits < 20; bits++) { + testBinaryScalarFunc(v, bits, Uint16x8.shiftLeftByScalar, ulsh16); + testBinaryScalarFunc(v, bits, Uint16x8.shiftRightByScalar, urshl16); + } + // Test that the shift count is coerced to an int32. + testBinaryScalarFunc(v, undefined, Uint16x8.shiftLeftByScalar, ulsh16); + testBinaryScalarFunc(v, 3.5, Uint16x8.shiftLeftByScalar, ulsh16); + testBinaryScalarFunc(v, good, Uint16x8.shiftLeftByScalar, ulsh16); + } + for (var v of [ + Uint32x4(-1, 2, -3, 4), + Uint32x4(UINT32_MAX, UINT32_MAX - 1, 0, 1), + Uint32x4(INT32_MAX, INT32_MIN, INT32_MAX - 1, INT32_MIN + 1) + ]) + { + for (var bits = -2; bits < 36; bits++) { + testBinaryScalarFunc(v, bits, Uint32x4.shiftLeftByScalar, ulsh32); + testBinaryScalarFunc(v, bits, Uint32x4.shiftRightByScalar, urshl32); + } + // Test that the shift count is coerced to an int32. + testBinaryScalarFunc(v, undefined, Uint32x4.shiftLeftByScalar, ulsh32); + testBinaryScalarFunc(v, 3.5, Uint32x4.shiftLeftByScalar, ulsh32); + testBinaryScalarFunc(v, good, Uint32x4.shiftLeftByScalar, ulsh32); + } + + var v = SIMD.Int8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); + assertThrowsInstanceOf(() => SIMD.Int8x16.shiftLeftByScalar(v, bad), TestError); + assertThrowsInstanceOf(() => SIMD.Int8x16.shiftRightByScalar(v, bad), TestError); + + var v = SIMD.Int16x8(1,2,3,4,5,6,7,8); + assertThrowsInstanceOf(() => SIMD.Int16x8.shiftLeftByScalar(v, bad), TestError); + assertThrowsInstanceOf(() => SIMD.Int16x8.shiftRightByScalar(v, bad), TestError); + + var v = SIMD.Int32x4(1,2,3,4); + assertThrowsInstanceOf(() => SIMD.Int32x4.shiftLeftByScalar(v, bad), TestError); + assertThrowsInstanceOf(() => SIMD.Int32x4.shiftRightByScalar(v, bad), TestError); + + var v = SIMD.Uint8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); + assertThrowsInstanceOf(() => SIMD.Uint8x16.shiftLeftByScalar(v, bad), TestError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.shiftRightByScalar(v, bad), TestError); + + var v = SIMD.Uint16x8(1,2,3,4,5,6,7,8); + assertThrowsInstanceOf(() => SIMD.Uint16x8.shiftLeftByScalar(v, bad), TestError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.shiftRightByScalar(v, bad), TestError); + + var v = SIMD.Uint32x4(1,2,3,4); + assertThrowsInstanceOf(() => SIMD.Uint32x4.shiftLeftByScalar(v, bad), TestError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.shiftRightByScalar(v, bad), TestError); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/splat.js b/js/src/tests/ecma_7/SIMD/splat.js new file mode 100644 index 000000000..1ab7ec98c --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/splat.js @@ -0,0 +1,97 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +var Float64x2 = SIMD.Float64x2; +var Float32x4 = SIMD.Float32x4; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; + +function TestSplatX16(type, inputs, coerceFunc) { + for (var x of inputs) { + assertEqX16(SIMD[type].splat(x), [x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x].map(coerceFunc)); + } +} + +function TestSplatX8(type, inputs, coerceFunc) { + for (var x of inputs) { + assertEqX8(SIMD[type].splat(x), [x, x, x, x, x, x, x, x].map(coerceFunc)); + } +} + +function TestSplatX4(type, inputs, coerceFunc) { + for (var x of inputs) { + assertEqX4(SIMD[type].splat(x), [x, x, x, x].map(coerceFunc)); + } +} + +function TestSplatX2(type, inputs, coerceFunc) { + for (var x of inputs) { + assertEqX2(SIMD[type].splat(x), [x, x].map(coerceFunc)); + } +} + +function test() { + function TestError(){}; + + var good = {valueOf: () => 19.89}; + var bad = {valueOf: () => { throw new TestError(); }}; + + TestSplatX16('Int8x16', [0, 1, 2, -1, -2, 3, -3, 4, -4, 5, -5, 6, INT8_MIN, INT8_MAX, INT8_MIN - 1, INT8_MAX + 1], (x) => x << 24 >> 24); + assertEqX16(Int8x16.splat(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + assertThrowsInstanceOf(() => SIMD.Int8x16.splat(bad), TestError); + + TestSplatX8('Int16x8', [0, 1, 2, -1, INT16_MIN, INT16_MAX, INT16_MIN - 1, INT16_MAX + 1], (x) => x << 16 >> 16); + assertEqX8(Int16x8.splat(), [0, 0, 0, 0, 0, 0, 0, 0]); + assertThrowsInstanceOf(() => SIMD.Int16x8.splat(bad), TestError); + + TestSplatX4('Int32x4', [0, undefined, 3.5, 42, -1337, INT32_MAX, INT32_MAX + 1, good], (x) => x | 0); + assertEqX4(SIMD.Int32x4.splat(), [0, 0, 0, 0]); + assertThrowsInstanceOf(() => SIMD.Int32x4.splat(bad), TestError); + + TestSplatX16('Uint8x16', [0, 1, 2, -1, -2, 3, -3, 4, -4, 5, -5, 6, INT8_MIN, INT8_MAX, INT8_MIN - 1, INT8_MAX + 1], (x) => x << 24 >>> 24); + assertEqX16(Uint8x16.splat(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + assertThrowsInstanceOf(() => SIMD.Uint8x16.splat(bad), TestError); + + TestSplatX8('Uint16x8', [0, 1, 2, -1, INT16_MIN, INT16_MAX, INT16_MIN - 1, INT16_MAX + 1], (x) => x << 16 >>> 16); + assertEqX8(Uint16x8.splat(), [0, 0, 0, 0, 0, 0, 0, 0]); + assertThrowsInstanceOf(() => SIMD.Uint16x8.splat(bad), TestError); + + TestSplatX4('Uint32x4', [0, undefined, 3.5, 42, INT32_MAX, INT32_MIN, UINT32_MAX, UINT32_MAX + 1, good], (x) => x >>> 0); + assertEqX4(SIMD.Uint32x4.splat(), [0, 0, 0, 0]); + assertThrowsInstanceOf(() => SIMD.Uint32x4.splat(bad), TestError); + + TestSplatX4('Float32x4', [0, undefined, 3.5, 42, -13.37, Infinity, NaN, -0, good], (x) => Math.fround(x)); + assertEqX4(SIMD.Float32x4.splat(), [NaN, NaN, NaN, NaN]); + assertThrowsInstanceOf(() => SIMD.Float32x4.splat(bad), TestError); + + TestSplatX2('Float64x2', [0, undefined, 3.5, 42, -13.37, Infinity, NaN, -0, good], (x) => +x); + assertEqX2(SIMD.Float64x2.splat(), [NaN, NaN]); + assertThrowsInstanceOf(() => SIMD.Float64x2.splat(bad), TestError); + + TestSplatX16('Bool8x16', [true, false], (x) => !!x); + assertEqX16(Bool8x16.splat(), [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]); + assertEqX16(Bool8x16.splat(bad), [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]); + + TestSplatX8('Bool16x8', [true, false], (x) => !!x); + assertEqX8(Bool16x8.splat(), [false, false, false, false, false, false, false, false]); + assertEqX8(Bool16x8.splat(bad), [true, true, true, true, true, true, true, true]); + + TestSplatX4('Bool32x4', [true, false], (x) => !!x); + assertEqX4(SIMD.Bool32x4.splat(), [false, false, false, false]); + assertEqX4(SIMD.Bool32x4.splat(bad), [true, true, true, true]); + + TestSplatX2('Bool64x2', [true, false], (x) => !!x); + assertEqX2(SIMD.Bool64x2.splat(), [false, false]); + assertEqX2(SIMD.Bool64x2.splat(bad), [true, true]); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/store.js b/js/src/tests/ecma_7/SIMD/store.js new file mode 100644 index 000000000..ef3c2249e --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/store.js @@ -0,0 +1,264 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +// As SIMD.*.store is entirely symmetric to SIMD.*.load, this file just +// contains basic tests to store on one single TypedArray kind, while load is +// exhaustively tested. See load.js for more details. + +const POISON = 42; + +function reset(ta) { + for (var i = 0; i < ta.length; i++) + ta[i] = POISON + i; +} + +function assertChanged(ta, from, expected) { + var i = 0; + for (; i < from; i++) + assertEq(ta[i], POISON + i); + for (; i < from + expected.length; i++) + assertEq(ta[i], expected[i - from]); + for (; i < ta.length; i++) + assertEq(ta[i], POISON + i); +} + +function testStore(ta, kind, i, v) { + var asArr = simdToArray(v); + + reset(ta); + SIMD[kind].store(ta, i, v); + assertChanged(ta, i, asArr); + + var length = asArr.length; + if (length >= 8) // Int8x16 and Int16x8 only support store, and not store1/store2/etc. + return; + + reset(ta); + SIMD[kind].store1(ta, i, v); + assertChanged(ta, i, [asArr[0]]); + if (length > 2) { + reset(ta); + SIMD[kind].store2(ta, i, v); + assertChanged(ta, i, [asArr[0], asArr[1]]); + + reset(ta); + SIMD[kind].store3(ta, i, v); + assertChanged(ta, i, [asArr[0], asArr[1], asArr[2]]); + } +} + +function testStoreInt8x16(Buffer) { + var I8 = new Int8Array(new Buffer(32)); + + var v = SIMD.Int8x16(0, 1, INT8_MAX, INT8_MIN, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + testStore(I8, 'Int8x16', 0, v); + testStore(I8, 'Int8x16', 1, v); + testStore(I8, 'Int8x16', 2, v); + testStore(I8, 'Int8x16', 16, v); + + assertThrowsInstanceOf(() => SIMD.Int8x16.store(I8), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.store(I8, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.store(I8, 0, v), TypeError); +} + +function testStoreInt16x8(Buffer) { + var I16 = new Int16Array(new Buffer(64)); + + var v = SIMD.Int16x8(0, 1, INT16_MAX, INT16_MIN, 4, 5, 6, 7); + testStore(I16, 'Int16x8', 0, v); + testStore(I16, 'Int16x8', 1, v); + testStore(I16, 'Int16x8', 2, v); + testStore(I16, 'Int16x8', 24, v); + + assertThrowsInstanceOf(() => SIMD.Int16x8.store(I16), TypeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.store(I16, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Int8x16.store(I16, 0, v), TypeError); +} + +function testStoreInt32x4(Buffer) { + var I32 = new Int32Array(new Buffer(64)); + + var v = SIMD.Int32x4(0, 1, Math.pow(2,31) - 1, -Math.pow(2, 31)); + testStore(I32, 'Int32x4', 0, v); + testStore(I32, 'Int32x4', 1, v); + testStore(I32, 'Int32x4', 2, v); + testStore(I32, 'Int32x4', 12, v); + + assertThrowsInstanceOf(() => SIMD.Int32x4.store(I32), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.store(I32, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.store(I32, 0, v), TypeError); +} + +function testStoreUint8x16(Buffer) { + var I8 = new Uint8Array(new Buffer(32)); + + var v = SIMD.Uint8x16(0, 1, INT8_MAX, INT8_MIN, UINT8_MAX, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + testStore(I8, 'Uint8x16', 0, v); + testStore(I8, 'Uint8x16', 1, v); + testStore(I8, 'Uint8x16', 2, v); + testStore(I8, 'Uint8x16', 16, v); + + assertThrowsInstanceOf(() => SIMD.Uint8x16.store(I8), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.store(I8, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.store(I8, 0, v), TypeError); +} + +function testStoreUint16x8(Buffer) { + var I16 = new Uint16Array(new Buffer(64)); + + var v = SIMD.Uint16x8(0, 1, INT16_MAX, INT16_MIN, 4, 5, 6, 7); + testStore(I16, 'Uint16x8', 0, v); + testStore(I16, 'Uint16x8', 1, v); + testStore(I16, 'Uint16x8', 2, v); + testStore(I16, 'Uint16x8', 24, v); + + assertThrowsInstanceOf(() => SIMD.Uint16x8.store(I16), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint16x8.store(I16, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint8x16.store(I16, 0, v), TypeError); +} + +function testStoreUint32x4(Buffer) { + var I32 = new Uint32Array(new Buffer(64)); + + var v = SIMD.Uint32x4(0, 1, Math.pow(2,31) - 1, -Math.pow(2, 31)); + testStore(I32, 'Uint32x4', 0, v); + testStore(I32, 'Uint32x4', 1, v); + testStore(I32, 'Uint32x4', 2, v); + testStore(I32, 'Uint32x4', 12, v); + + assertThrowsInstanceOf(() => SIMD.Uint32x4.store(I32), TypeError); + assertThrowsInstanceOf(() => SIMD.Uint32x4.store(I32, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.store(I32, 0, v), TypeError); +} + +function testStoreFloat32x4(Buffer) { + var F32 = new Float32Array(new Buffer(64)); + + var v = SIMD.Float32x4(1,2,3,4); + testStore(F32, 'Float32x4', 0, v); + testStore(F32, 'Float32x4', 1, v); + testStore(F32, 'Float32x4', 2, v); + testStore(F32, 'Float32x4', 12, v); + + var v = SIMD.Float32x4(NaN, -0, -Infinity, 5e-324); + testStore(F32, 'Float32x4', 0, v); + testStore(F32, 'Float32x4', 1, v); + testStore(F32, 'Float32x4', 2, v); + testStore(F32, 'Float32x4', 12, v); + + assertThrowsInstanceOf(() => SIMD.Float32x4.store(F32), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.store(F32, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.store(F32, 0, v), TypeError); +} + +function testStoreFloat64x2(Buffer) { + var F64 = new Float64Array(new Buffer(128)); + + var v = SIMD.Float64x2(1, 2); + testStore(F64, 'Float64x2', 0, v); + testStore(F64, 'Float64x2', 1, v); + testStore(F64, 'Float64x2', 14, v); + + var v = SIMD.Float64x2(NaN, -0); + testStore(F64, 'Float64x2', 0, v); + testStore(F64, 'Float64x2', 1, v); + testStore(F64, 'Float64x2', 14, v); + + var v = SIMD.Float64x2(-Infinity, +Infinity); + testStore(F64, 'Float64x2', 0, v); + testStore(F64, 'Float64x2', 1, v); + testStore(F64, 'Float64x2', 14, v); + + assertThrowsInstanceOf(() => SIMD.Float64x2.store(F64), TypeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.store(F64, 0), TypeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.store(F64, 0, v), TypeError); +} + +function testSharedArrayBufferCompat() { + var I32 = new Int32Array(new SharedArrayBuffer(16*4)); + var TA = I32; + + var I8 = new Int8Array(TA.buffer); + var I16 = new Int16Array(TA.buffer); + var F32 = new Float32Array(TA.buffer); + var F64 = new Float64Array(TA.buffer); + + var Int8x16 = SIMD.Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + var Int16x8 = SIMD.Int16x8(1, 2, 3, 4, 5, 6, 7, 8); + var Int32x4 = SIMD.Int32x4(1, 2, 3, 4); + var Uint8x16 = SIMD.Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + var Uint16x8 = SIMD.Uint16x8(1, 2, 3, 4, 5, 6, 7, 8); + var Uint32x4 = SIMD.Uint32x4(1, 2, 3, 4); + var Float32x4 = SIMD.Float32x4(1, 2, 3, 4); + var Float64x2 = SIMD.Float64x2(1, 2); + + for (var ta of [ + new Uint8Array(TA.buffer), + new Int8Array(TA.buffer), + new Uint16Array(TA.buffer), + new Int16Array(TA.buffer), + new Uint32Array(TA.buffer), + new Int32Array(TA.buffer), + new Float32Array(TA.buffer), + new Float64Array(TA.buffer) + ]) + { + SIMD.Int8x16.store(ta, 0, Int8x16); + for (var i = 0; i < 16; i++) assertEq(I8[i], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16][i]); + + SIMD.Int16x8.store(ta, 0, Int16x8); + for (var i = 0; i < 8; i++) assertEq(I16[i], [1, 2, 3, 4, 5, 6, 7, 8][i]); + + SIMD.Int32x4.store(ta, 0, Int32x4); + for (var i = 0; i < 4; i++) assertEq(I32[i], [1, 2, 3, 4][i]); + + SIMD.Uint8x16.store(ta, 0, Uint8x16); + for (var i = 0; i < 16; i++) assertEq(I8[i], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16][i]); + + SIMD.Uint16x8.store(ta, 0, Uint16x8); + for (var i = 0; i < 8; i++) assertEq(I16[i], [1, 2, 3, 4, 5, 6, 7, 8][i]); + + SIMD.Uint32x4.store(ta, 0, Uint32x4); + for (var i = 0; i < 4; i++) assertEq(I32[i], [1, 2, 3, 4][i]); + + SIMD.Float32x4.store(ta, 0, Float32x4); + for (var i = 0; i < 4; i++) assertEq(F32[i], [1, 2, 3, 4][i]); + + SIMD.Float64x2.store(ta, 0, Float64x2); + for (var i = 0; i < 2; i++) assertEq(F64[i], [1, 2][i]); + + assertThrowsInstanceOf(() => SIMD.Int8x16.store(ta, 1024, Int8x16), RangeError); + assertThrowsInstanceOf(() => SIMD.Int16x8.store(ta, 1024, Int16x8), RangeError); + assertThrowsInstanceOf(() => SIMD.Int32x4.store(ta, 1024, Int32x4), RangeError); + assertThrowsInstanceOf(() => SIMD.Float32x4.store(ta, 1024, Float32x4), RangeError); + assertThrowsInstanceOf(() => SIMD.Float64x2.store(ta, 1024, Float64x2), RangeError); + } +} + +testStoreInt8x16(ArrayBuffer); +testStoreInt16x8(ArrayBuffer); +testStoreInt32x4(ArrayBuffer); +testStoreUint8x16(ArrayBuffer); +testStoreUint16x8(ArrayBuffer); +testStoreUint32x4(ArrayBuffer); +testStoreFloat32x4(ArrayBuffer); +testStoreFloat64x2(ArrayBuffer); + +if (typeof SharedArrayBuffer != "undefined") { + testStoreInt8x16(SharedArrayBuffer); + testStoreInt16x8(SharedArrayBuffer); + testStoreInt32x4(SharedArrayBuffer); + testStoreUint8x16(SharedArrayBuffer); + testStoreUint16x8(SharedArrayBuffer); + testStoreUint32x4(SharedArrayBuffer); + testStoreFloat32x4(SharedArrayBuffer); + testStoreFloat64x2(SharedArrayBuffer); + testSharedArrayBufferCompat(); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/swizzle-shuffle.js b/js/src/tests/ecma_7/SIMD/swizzle-shuffle.js new file mode 100644 index 000000000..7af98e2a7 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/swizzle-shuffle.js @@ -0,0 +1,507 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; + +function swizzle2(arr, x, y) { + return [arr[x], arr[y]]; +} + +function swizzle4(arr, x, y, z, w) { + return [arr[x], arr[y], arr[z], arr[w]]; +} + +function swizzle8(arr, s0, s1, s2, s3, s4, s5, s6, s7) { + return [arr[s0], arr[s1], arr[s2], arr[s3], arr[s4], arr[s5], arr[s6], arr[s7]]; +} + +function swizzle16(arr, s0, s1, s2, s3, s4, s5, s6, s7, + s8, s9, s10, s11, s12, s13, s14, s15) { + return [arr[s0], arr[s1], arr[s2], arr[s3], arr[s4], arr[s5], arr[s6], arr[s7], + arr[s8], arr[s9], arr[s10], arr[s11], arr[s12], arr[s13], arr[s14], arr[s15]]; +} + +function getNumberOfLanesFromType(type) { + switch (type) { + case Int8x16: + case Uint8x16: + return 16; + case Int16x8: + case Uint16x8: + return 8; + case Float32x4: + case Int32x4: + case Uint32x4: + return 4; + case Float64x2: + return 2; + } + throw new TypeError("Unknown SIMD type."); +} + +function testSwizzleForType(type) { + var lanes = getNumberOfLanesFromType(type); + var v; + switch (lanes) { + case 2: + v = type(1, 2); + break; + case 4: + v = type(1, 2, 3, 4); + break; + case 8: + v = type(1, 2, 3, 4, 5, 6, 7, 8); + break; + case 16: + v = type(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + break; + } + + assertThrowsInstanceOf(() => type.swizzle() , TypeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0) , TypeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 1, 2) , TypeError); + assertThrowsInstanceOf(() => type.swizzle(0, 1, 2, 3, v) , TypeError); + + // Test all possible swizzles. + if (lanes == 2) { + var x, y; + for (var i = 0; i < Math.pow(2, 2); i++) { + [x, y] = [x & 1, (y >> 1) & 1]; + assertEqVec(type.swizzle(v, x, y), swizzle2(simdToArray(v), x, y)); + } + } else if (lanes == 4) { + var x, y, z, w; + for (var i = 0; i < Math.pow(4, 4); i++) { + [x, y, z, w] = [i & 3, (i >> 2) & 3, (i >> 4) & 3, (i >> 6) & 3]; + assertEqVec(type.swizzle(v, x, y, z, w), swizzle4(simdToArray(v), x, y, z, w)); + } + } else if (lanes == 8) { + var vals = [[1, 2, 1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 5, 6, 7], + [7, 6, 5, 4, 3, 2, 1, 0], [5, 3, 2, 6, 1, 7, 4, 0]]; + for (var t of vals) { + assertEqVec(type.swizzle(v, ...t), swizzle8(simdToArray(v), ...t)); + } + } else { + assertEq(lanes, 16); + + var vals = [[11, 2, 11, 2, 11, 2, 11, 2, 11, 2, 11, 2, 11, 2, 11, 2], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], + [5, 14, 3, 2, 6, 9, 1, 10, 7, 11, 4, 0, 13, 15, 8, 12]]; + for (var t of vals) { + assertEqVec(type.swizzle(v, ...t), swizzle16(simdToArray(v), ...t)); + } + } + + // Test that we throw if an lane argument doesn't coerce to an integer in bounds. + if (lanes == 2) { + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, undefined), RangeError); + + type.swizzle(v, 0, "00.0"); + type.swizzle(v, 0, null); + type.swizzle(v, 0, false); + type.swizzle(v, 0, true); + + // In bounds is [0, 1] + assertThrowsInstanceOf(() => type.swizzle(v, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 2), RangeError); + } else if (lanes == 4) { + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, undefined), RangeError); + + type.swizzle(v, 0, 0, 0, "00.0"); + type.swizzle(v, 0, 0, 0, null); + type.swizzle(v, 0, 0, 0, false); + type.swizzle(v, 0, 0, 0, true); + + // In bounds is [0, 3] + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 4), RangeError); + } else if (lanes == 8) { + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, undefined), RangeError); + + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, "00.0"); + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, null); + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, false); + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, true); + + // In bounds is [0, 7] + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 8), RangeError); + } else { + assertEq(lanes, 16); + + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, undefined), RangeError); + + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "00.0"); + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); + type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true); + + // In bounds is [0, 15] + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16), RangeError); + } +} + +function testSwizzleInt8x16() { + var v = Int16x8(1, 2, 3, 4, 5, 6, 7, 8); + + assertThrowsInstanceOf(function() { + Int8x16.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Int8x16); +} + +function testSwizzleInt16x8() { + var v = Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + assertThrowsInstanceOf(function() { + Int16x8.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Int16x8); +} + +function testSwizzleInt32x4() { + var v = Int32x4(1, 2, 3, 4); + + assertThrowsInstanceOf(function() { + Float32x4.swizzle(v, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Int32x4); +} + +function testSwizzleUint8x16() { + var v = Uint16x8(1, 2, 3, 4, 5, 6, 7, 8); + + assertThrowsInstanceOf(function() { + Uint8x16.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Uint8x16); +} + +function testSwizzleUint16x8() { + var v = Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + assertThrowsInstanceOf(function() { + Uint16x8.swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Uint16x8); +} + +function testSwizzleUint32x4() { + var v = Uint32x4(1, 2, 3, 4); + + assertThrowsInstanceOf(function() { + Float32x4.swizzle(v, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Uint32x4); +} + +function testSwizzleFloat32x4() { + var v = Float32x4(1, 2, 3, 4); + + assertThrowsInstanceOf(function() { + Int32x4.swizzle(v, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Float32x4); +} + +function testSwizzleFloat64x2() { + var v = Float64x2(1, 2); + + assertThrowsInstanceOf(function() { + Float32x4.swizzle(v, 0, 0, 0, 0); + }, TypeError); + + testSwizzleForType(Float64x2); +} + +function shuffle2(lhsa, rhsa, x, y) { + return [(x < 2 ? lhsa : rhsa)[x % 2], + (y < 2 ? lhsa : rhsa)[y % 2]]; +} +function shuffle4(lhsa, rhsa, x, y, z, w) { + return [(x < 4 ? lhsa : rhsa)[x % 4], + (y < 4 ? lhsa : rhsa)[y % 4], + (z < 4 ? lhsa : rhsa)[z % 4], + (w < 4 ? lhsa : rhsa)[w % 4]]; +} + +function shuffle8(lhsa, rhsa, s0, s1, s2, s3, s4, s5, s6, s7, s8) { + return [(s0 < 8 ? lhsa : rhsa)[s0 % 8], + (s1 < 8 ? lhsa : rhsa)[s1 % 8], + (s2 < 8 ? lhsa : rhsa)[s2 % 8], + (s3 < 8 ? lhsa : rhsa)[s3 % 8], + (s4 < 8 ? lhsa : rhsa)[s4 % 8], + (s5 < 8 ? lhsa : rhsa)[s5 % 8], + (s6 < 8 ? lhsa : rhsa)[s6 % 8], + (s7 < 8 ? lhsa : rhsa)[s7 % 8]]; +} + +function shuffle16(lhsa, rhsa, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15) { + return [(s0 < 16 ? lhsa : rhsa)[s0 % 16], + (s1 < 16 ? lhsa : rhsa)[s1 % 16], + (s2 < 16 ? lhsa : rhsa)[s2 % 16], + (s3 < 16 ? lhsa : rhsa)[s3 % 16], + (s4 < 16 ? lhsa : rhsa)[s4 % 16], + (s5 < 16 ? lhsa : rhsa)[s5 % 16], + (s6 < 16 ? lhsa : rhsa)[s6 % 16], + (s7 < 16 ? lhsa : rhsa)[s7 % 16], + (s8 < 16 ? lhsa : rhsa)[s8 % 16], + (s9 < 16 ? lhsa : rhsa)[s9 % 16], + (s10 < 16 ? lhsa : rhsa)[s10 % 16], + (s11 < 16 ? lhsa : rhsa)[s11 % 16], + (s12 < 16 ? lhsa : rhsa)[s12 % 16], + (s13 < 16 ? lhsa : rhsa)[s13 % 16], + (s14 < 16 ? lhsa : rhsa)[s14 % 16], + (s15 < 16 ? lhsa : rhsa)[s15 % 16]]; +} + +function testShuffleForType(type) { + var lanes = getNumberOfLanesFromType(type); + var lhs, rhs; + if (lanes == 2) { + lhs = type(1, 2); + rhs = type(3, 4); + } else if (lanes == 4) { + lhs = type(1, 2, 3, 4); + rhs = type(5, 6, 7, 8); + } else if (lanes == 8) { + lhs = type(1, 2, 3, 4, 5, 6, 7, 8); + rhs = type(9, 10, 11, 12, 13, 14, 15, 16); + } else { + assertEq(lanes, 16); + + lhs = type(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + rhs = type(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32); + } + + assertThrowsInstanceOf(() => type.shuffle(lhs) , TypeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs) , TypeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0) , TypeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 1, 2) , TypeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, 0, 1, 2, 7, rhs) , TypeError); + + // Test all possible shuffles. + var x, y, z, w; + if (lanes == 2) { + var x, y; + for (var i = 0; i < Math.pow(4, 2); i++) { + [x, y] = [i & 3, (i >> 3) & 3]; + assertEqVec(type.shuffle(lhs, rhs, x, y), + shuffle2(simdToArray(lhs), simdToArray(rhs), x, y)); + } + } else if (lanes == 4) { + var x, y, z, w; + for (var i = 0; i < Math.pow(8, 4); i++) { + [x, y, z, w] = [i & 7, (i >> 3) & 7, (i >> 6) & 7, (i >> 9) & 7]; + assertEqVec(type.shuffle(lhs, rhs, x, y, z, w), + shuffle4(simdToArray(lhs), simdToArray(rhs), x, y, z, w)); + } + } else if (lanes == 8) { + var s0, s1, s2, s3, s4, s5, s6, s7; + var vals = [[15, 8, 15, 8, 15, 8, 15, 8], [9, 7, 9, 7, 9, 7, 9, 7], + [7, 3, 8, 9, 2, 15, 14, 6], [2, 2, 2, 2, 2, 2, 2, 2], + [8, 8, 8, 8, 8, 8, 8, 8], [11, 11, 11, 11, 11, 11, 11, 11]]; + for (var t of vals) { + [s0, s1, s2, s3, s4, s5, s6, s7] = t; + assertEqVec(type.shuffle(lhs, rhs, s0, s1, s2, s3, s4, s5, s6, s7), + shuffle8(simdToArray(lhs), simdToArray(rhs), s0, s1, s2, s3, s4, s5, s6, s7)); + } + } else { + assertEq(lanes, 16); + + var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15; + var vals = [[30, 16, 30, 16, 30, 16, 30, 16, 30, 16, 30, 16, 30, 16, 30, 16], + [19, 17, 19, 17, 19, 17, 19, 17, 19, 17, 19, 17, 19, 17, 19, 17], + [7, 3, 8, 18, 9, 21, 2, 15, 14, 6, 16, 22, 29, 31, 30, 1], + [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], + [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16], + [21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21]]; + for (var t of vals) { + [s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15] = t; + assertEqVec(type.shuffle(lhs, rhs, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15), + shuffle16(simdToArray(lhs), simdToArray(rhs), s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15)); + } + } + + // Test that we throw if an lane argument isn't an int32 or isn't in bounds. + if (lanes == 2) { + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, undefined), RangeError); + + // In bounds is [0, 3] + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 4), RangeError); + } else if (lanes == 4) { + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, undefined), RangeError); + + // In bounds is [0, 7] + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 8), RangeError); + } else if (lanes == 8) { + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, undefined), RangeError); + + // In bounds is [0, 15] + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 16), RangeError); + } else { + assertEq(lanes, 16); + + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {valueOf: function(){return 42}}), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "one"), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, undefined), RangeError); + + // In bounds is [0, 31] + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1), RangeError); + assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32), RangeError); + } +} + +function testShuffleInt8x16() { + var v = Int16x8(1, 2, 3, 4, 5, 6, 7, 8); + + assertThrowsInstanceOf(function() { + Int8x16.shuffle(v, v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Int8x16); +} + +function testShuffleInt16x8() { + var v = Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + assertThrowsInstanceOf(function() { + Int16x8.shuffle(v, v, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Int16x8); +} + +function testShuffleInt32x4() { + var v = Int32x4(1, 2, 3, 4); + + assertThrowsInstanceOf(function() { + Float32x4.shuffle(v, v, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Int32x4); +} + +function testShuffleUint8x16() { + var v = Uint16x8(1, 2, 3, 4, 5, 6, 7, 8); + + assertThrowsInstanceOf(function() { + Uint8x16.shuffle(v, v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Uint8x16); +} + +function testShuffleUint16x8() { + var v = Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + assertThrowsInstanceOf(function() { + Uint16x8.shuffle(v, v, 0, 0, 0, 0, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Uint16x8); +} + +function testShuffleUint32x4() { + var v = Uint32x4(1, 2, 3, 4); + + assertThrowsInstanceOf(function() { + Float32x4.shuffle(v, v, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Uint32x4); +} + +function testShuffleFloat32x4() { + var v = Float32x4(1, 2, 3, 4); + + assertThrowsInstanceOf(function() { + Int32x4.shuffle(v, v, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Float32x4); +} + +function testShuffleFloat64x2() { + var v = Float64x2(1, 2); + + assertThrowsInstanceOf(function() { + Float32x4.shuffle(v, v, 0, 0, 0, 0); + }, TypeError); + + testShuffleForType(Float64x2); +} + +testSwizzleInt8x16(); +testSwizzleInt16x8(); +testSwizzleInt32x4(); +testSwizzleUint8x16(); +testSwizzleUint16x8(); +testSwizzleUint32x4(); +testSwizzleFloat32x4(); +testSwizzleFloat64x2(); +testShuffleInt8x16(); +testShuffleInt16x8(); +testShuffleInt32x4(); +testShuffleUint8x16(); +testShuffleUint16x8(); +testShuffleUint32x4(); +testShuffleFloat32x4(); +testShuffleFloat64x2(); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_7/SIMD/toString.js b/js/src/tests/ecma_7/SIMD/toString.js new file mode 100644 index 000000000..0f8bb7a9b --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/toString.js @@ -0,0 +1,90 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) + +function test() { + var Float32x4 = SIMD.Float32x4; + var f = Float32x4(11, 22, NaN, -44); + assertEq(f.toString(), "SIMD.Float32x4(11, 22, NaN, -44)"); + + // Polyfill check should show that we already have a toString. + assertEq(Float32x4.prototype.hasOwnProperty("toString"), true); + + // This toString method type checks its argument. + var ts = Float32x4.prototype.toString; + assertThrowsInstanceOf(() => ts.call(5), TypeError); + assertThrowsInstanceOf(() => ts.call({}), TypeError); + + // Can't convert SIMD objects to numbers. + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Float64x2 = SIMD.Float64x2; + var f = Float64x2(11, 22); + assertEq(f.toString(), "SIMD.Float64x2(11, 22)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Int8x16 = SIMD.Int8x16; + var f = Int8x16(11, 22, 33, 44, -11, -22, -33, -44, 1, 2, 3, 4, -1, -2, -3, -4); + assertEq(f.toString(), "SIMD.Int8x16(11, 22, 33, 44, -11, -22, -33, -44, 1, 2, 3, 4, -1, -2, -3, -4)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Int16x8 = SIMD.Int16x8; + var f = Int16x8(11, 22, 33, 44, -11, -22, -33, -44); + assertEq(f.toString(), "SIMD.Int16x8(11, 22, 33, 44, -11, -22, -33, -44)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Int32x4 = SIMD.Int32x4; + var f = Int32x4(11, 22, 33, 44); + assertEq(f.toString(), "SIMD.Int32x4(11, 22, 33, 44)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Uint8x16 = SIMD.Uint8x16; + var f = Uint8x16(11, 22, 33, 44, 245, 234, 223, 212, 1, 2, 3, 4, 255, 254, 0, 250); + assertEq(f.toString(), "SIMD.Uint8x16(11, 22, 33, 44, 245, 234, 223, 212, 1, 2, 3, 4, 255, 254, 0, 250)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Uint16x8 = SIMD.Uint16x8; + var f = Uint16x8(11, 22, 33, 44, 65535, 65534, 65533, 65532); + assertEq(f.toString(), "SIMD.Uint16x8(11, 22, 33, 44, 65535, 65534, 65533, 65532)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Uint32x4 = SIMD.Uint32x4; + var f = Uint32x4(11, 22, 4294967295, 4294967294); + assertEq(f.toString(), "SIMD.Uint32x4(11, 22, 4294967295, 4294967294)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Bool8x16 = SIMD.Bool8x16; + var f = Bool8x16(true, true, false, false, false, true, true, false, true, true, true, true, false, false, false, false); + assertEq(f.toString(), "SIMD.Bool8x16(true, true, false, false, false, true, true, false, true, true, true, true, false, false, false, false)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Bool16x8 = SIMD.Bool16x8; + var f = Bool16x8(true, true, false, false, true, false, false, true); + assertEq(f.toString(), "SIMD.Bool16x8(true, true, false, false, true, false, false, true)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Bool32x4 = SIMD.Bool32x4; + var f = Bool32x4(true, true, false, false); + assertEq(f.toString(), "SIMD.Bool32x4(true, true, false, false)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + var Bool64x2 = SIMD.Bool64x2; + var f = Bool64x2(true, false); + assertEq(f.toString(), "SIMD.Bool64x2(true, false)"); + assertThrowsInstanceOf(() => +f, TypeError); + assertThrowsInstanceOf(() => f.valueOf(), TypeError); + + if (typeof reportCompare === "function") + reportCompare(true, true); +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/typedobjects.js b/js/src/tests/ecma_7/SIMD/typedobjects.js new file mode 100644 index 000000000..e4886cf4e --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/typedobjects.js @@ -0,0 +1,1077 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) +var Float32x4 = SIMD.Float32x4; +var Float64x2 = SIMD.Float64x2; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +var {StructType, Handle} = TypedObject; +var {float32, float64, int8, int16, int32, uint8} = TypedObject; + +function testFloat32x4Alignment() { + assertEq(Float32x4.byteLength, 16); + assertEq(Float32x4.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Float32x4}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testFloat32x4Getters() { + var f = Float32x4(11, 22, 33, 44); + assertEq(Float32x4.extractLane(f, 0), 11); + assertEq(Float32x4.extractLane(f, 1), 22); + assertEq(Float32x4.extractLane(f, 2), 33); + assertEq(Float32x4.extractLane(f, 3), 44); + + assertThrowsInstanceOf(() => Float32x4.extractLane(f, 4), RangeError); + assertThrowsInstanceOf(() => Float32x4.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Float32x4.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Float32x4.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Float32x4.extractLane(Int32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Float32x4.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Float32x4.extractLane(f, f), TypeError); +} + +function testFloat32x4Handles() { + var Array = Float32x4.array(3); + var array = new Array([Float32x4(1, 2, 3, 4), + Float32x4(5, 6, 7, 8), + Float32x4(9, 10, 11, 12)]); + + // Test that trying to create handle into the interior of a + // Float32x4 fails. + assertThrowsInstanceOf(function() { + var h = float32.handle(array, 1, 0); + }, TypeError, "Creating a float32 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = float32.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a float32 handle to elem via move"); +} + +function testFloat32x4Reify() { + var Array = Float32x4.array(3); + var array = new Array([Float32x4(1, 2, 3, 4), + Float32x4(5, 6, 7, 8), + Float32x4(9, 10, 11, 12)]); + + // Test that reading array[1] produces a *copy* of Float32x4, not an + // alias into the array. + + var f = array[1]; + assertEq(Float32x4.extractLane(f, 3), 8); + assertEq(Float32x4.extractLane(array[1], 3), 8); + array[1] = Float32x4(15, 16, 17, 18); + assertEq(Float32x4.extractLane(f, 3), 8); + assertEq(Float32x4.extractLane(array[1], 3), 18); +} + +function testFloat32x4Setters() { + var Array = Float32x4.array(3); + var array = new Array([Float32x4(1, 2, 3, 4), + Float32x4(5, 6, 7, 8), + Float32x4(9, 10, 11, 12)]); + assertEq(Float32x4.extractLane(array[1], 3), 8); + + // Test that we are allowed to write Float32x4 values into array, + // but not other things. + + array[1] = Float32x4(15, 16, 17, 18); + assertEq(Float32x4.extractLane(array[1], 3), 18); + + assertThrowsInstanceOf(function() { + array[1] = {x: 15, y: 16, z: 17, w: 18}; + }, TypeError, "Setting Float32x4 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [15, 16, 17, 18]; + }, TypeError, "Setting Float32x4 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 22; + }, TypeError, "Setting Float32x4 from a number"); +} + +function testFloat64x2Alignment() { + assertEq(Float64x2.byteLength, 16); + assertEq(Float64x2.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Float64x2}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testFloat64x2Getters() { + // Create a Float64x2 and check that the getters work: + var f = Float64x2(11, 22); + assertEq(Float64x2.extractLane(f, 0), 11); + assertEq(Float64x2.extractLane(f, 1), 22); + + assertThrowsInstanceOf(() => Float64x2.extractLane(f, 2), RangeError); + assertThrowsInstanceOf(() => Float64x2.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Float64x2.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Float64x2.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Float64x2.extractLane(Float32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Float64x2.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Float64x2.extractLane(f, f), TypeError); +} + +function testFloat64x2Handles() { + var Array = Float64x2.array(3); + var array = new Array([Float64x2(1, 2), + Float64x2(3, 4), + Float64x2(5, 6)]); + + // Test that trying to create handle into the interior of a + // Float64x2 fails. + assertThrowsInstanceOf(function() { + var h = float64.handle(array, 1, 0); + }, TypeError, "Creating a float64 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = float64.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a float64 handle to elem via move"); +} + +function testFloat64x2Reify() { + var Array = Float64x2.array(3); + var array = new Array([Float64x2(1, 2), + Float64x2(3, 4), + Float64x2(5, 6)]); + + // Test that reading array[1] produces a *copy* of Float64x2, not an + // alias into the array. + + var f = array[1]; + assertEq(Float64x2.extractLane(f, 1), 4); + assertEq(Float64x2.extractLane(array[1], 1), 4); + array[1] = Float64x2(7, 8); + assertEq(Float64x2.extractLane(f, 1), 4); + assertEq(Float64x2.extractLane(array[1], 1), 8); +} + +function testFloat64x2Setters() { + var Array = Float64x2.array(3); + var array = new Array([Float64x2(1, 2), + Float64x2(3, 4), + Float64x2(5, 6)]); + assertEq(Float64x2.extractLane(array[1], 1), 4); + + // Test that we are allowed to write Float64x2 values into array, + // but not other things. + + array[1] = Float64x2(7, 8); + assertEq(Float64x2.extractLane(array[1], 1), 8); + + assertThrowsInstanceOf(function() { + array[1] = {x: 7, y: 8 }; + }, TypeError, "Setting Float64x2 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [ 7, 8 ]; + }, TypeError, "Setting Float64x2 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 9; + }, TypeError, "Setting Float64x2 from a number"); +} + +function testInt8x16Alignment() { + assertEq(Int8x16.byteLength, 16); + assertEq(Int8x16.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Int8x16}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testInt8x16Getters() { + // Create a Int8x16 and check that the getters work: + var f = Int8x16(11, 22, 33, 44, 55, 66, 77, 88, 99, 10, 20, 30, 40, 50, 60, 70); + assertEq(Int8x16.extractLane(f, 0), 11); + assertEq(Int8x16.extractLane(f, 1), 22); + assertEq(Int8x16.extractLane(f, 2), 33); + assertEq(Int8x16.extractLane(f, 3), 44); + assertEq(Int8x16.extractLane(f, 4), 55); + assertEq(Int8x16.extractLane(f, 5), 66); + assertEq(Int8x16.extractLane(f, 6), 77); + assertEq(Int8x16.extractLane(f, 7), 88); + assertEq(Int8x16.extractLane(f, 8), 99); + assertEq(Int8x16.extractLane(f, 9), 10); + assertEq(Int8x16.extractLane(f, 10), 20); + assertEq(Int8x16.extractLane(f, 11), 30); + assertEq(Int8x16.extractLane(f, 12), 40); + assertEq(Int8x16.extractLane(f, 13), 50); + assertEq(Int8x16.extractLane(f, 14), 60); + assertEq(Int8x16.extractLane(f, 15), 70); + + assertThrowsInstanceOf(() => Int8x16.extractLane(f, 16), RangeError); + assertThrowsInstanceOf(() => Int8x16.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Int8x16.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Int8x16.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Int8x16.extractLane(Int32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Int8x16.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Int8x16.extractLane(f, f), TypeError); +} + +function testInt8x16Handles() { + var Array = Int8x16.array(3); + var array = new Array([Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Int8x16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + Int8x16(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48)]); + + // Test that trying to create handle into the interior of a + // Int8x16 fails. + assertThrowsInstanceOf(function() { + var h = int8.handle(array, 1, 0); + }, TypeError, "Creating a int8 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = int8.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a int8 handle to elem via move"); +} + +function testInt8x16Reify() { + var Array = Int8x16.array(3); + var array = new Array([Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Int8x16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + Int8x16(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48)]); + + // Test that reading array[1] produces a *copy* of Int8x16, not an + // alias into the array. + + var f = array[1]; + + var sj1 = Int8x16.extractLane(f, 3); + + assertEq(sj1, 20); + assertEq(Int8x16.extractLane(array[1], 3), 20); + array[1] = Int8x16(49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64); + assertEq(Int8x16.extractLane(f, 3), 20); + assertEq(Int8x16.extractLane(array[1], 3), 52); +} + +function testInt8x16Setters() { + var Array = Int8x16.array(3); + var array = new Array([Int8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Int8x16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + Int8x16(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48)]); + assertEq(Int8x16.extractLane(array[1], 3), 20); + + // Test that we are allowed to write Int8x16 values into array, + // but not other things. + + array[1] = Int8x16(49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64); + assertEq(Int8x16.extractLane(array[1], 3), 52); + + assertThrowsInstanceOf(function() { + array[1] = {s0: 49, s1: 50, s2: 51, s3: 52, s4: 53, s5: 54, s6: 55, s7: 56, + s8: 57, s9: 58, s10: 59, s11: 60, s12: 61, s13: 62, s14: 63, s15: 64}; + }, TypeError, "Setting Int8x16 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]; + }, TypeError, "Setting Int8x16 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 52; + }, TypeError, "Setting Int8x16 from a number"); +} + +function testInt16x8Alignment() { + assertEq(Int16x8.byteLength, 16); + assertEq(Int16x8.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Int16x8}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testInt16x8Getters() { + // Create a Int16x8 and check that the getters work: + var f = Int16x8(11, 22, 33, 44, 55, 66, 77, 88); + assertEq(Int16x8.extractLane(f, 0), 11); + assertEq(Int16x8.extractLane(f, 1), 22); + assertEq(Int16x8.extractLane(f, 2), 33); + assertEq(Int16x8.extractLane(f, 3), 44); + assertEq(Int16x8.extractLane(f, 4), 55); + assertEq(Int16x8.extractLane(f, 5), 66); + assertEq(Int16x8.extractLane(f, 6), 77); + assertEq(Int16x8.extractLane(f, 7), 88); + + assertThrowsInstanceOf(() => Int16x8.extractLane(f, 8), RangeError); + assertThrowsInstanceOf(() => Int16x8.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Int16x8.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Int16x8.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Int16x8.extractLane(Int32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Int16x8.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Int16x8.extractLane(f, f), TypeError); +} + +function testInt16x8Handles() { + var Array = Int16x8.array(3); + var array = new Array([Int16x8(1, 2, 3, 4, 5, 6, 7, 8), + Int16x8(9, 10, 11, 12, 13, 14, 15, 16), + Int16x8(17, 18, 19, 20, 21, 22, 23, 24)]); + + // Test that trying to create handle into the interior of a + // Int16x8 fails. + assertThrowsInstanceOf(function() { + var h = int16.handle(array, 1, 0); + }, TypeError, "Creating a int16 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = int16.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a int16 handle to elem via move"); +} + +function testInt16x8Reify() { + var Array = Int16x8.array(3); + var array = new Array([Int16x8(1, 2, 3, 4, 5, 6, 7, 8), + Int16x8(9, 10, 11, 12, 13, 14, 15, 16), + Int16x8(17, 18, 19, 20, 21, 22, 23, 24)]); + + // Test that reading array[1] produces a *copy* of Int16x8, not an + // alias into the array. + + var f = array[1]; + assertEq(Int16x8.extractLane(f, 3), 12); + assertEq(Int16x8.extractLane(array[1], 3), 12); + array[1] = Int16x8(25, 26, 27, 28, 29, 30, 31, 32); + assertEq(Int16x8.extractLane(f, 3), 12); + assertEq(Int16x8.extractLane(array[1], 3), 28); +} + +function testInt16x8Setters() { + var Array = Int16x8.array(3); + var array = new Array([Int16x8(1, 2, 3, 4, 5, 6, 7, 8), + Int16x8(9, 10, 11, 12, 13, 14, 15, 16), + Int16x8(17, 18, 19, 20, 21, 22, 23, 24)]); + assertEq(Int16x8.extractLane(array[1], 3), 12); + + // Test that we are allowed to write Int16x8 values into array, + // but not other things. + + array[1] = Int16x8(25, 26, 27, 28, 29, 30, 31, 32); + assertEq(Int16x8.extractLane(array[1], 3), 28); + + assertThrowsInstanceOf(function() { + array[1] = {s0: 25, s1: 26, s2: 27, s3: 28, s4: 29, s5: 30, s6: 31, s7: 32}; + }, TypeError, "Setting Int16x8 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [25, 26, 27, 28, 29, 30, 31, 32]; + }, TypeError, "Setting Int16x8 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 28; + }, TypeError, "Setting Int16x8 from a number"); +} + +function testInt32x4Alignment() { + assertEq(Int32x4.byteLength, 16); + assertEq(Int32x4.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Int32x4}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testInt32x4Getters() { + // Create a Int32x4 and check that the getters work: + var f = Int32x4(11, 22, 33, 44); + assertEq(Int32x4.extractLane(f, 0), 11); + assertEq(Int32x4.extractLane(f, 1), 22); + assertEq(Int32x4.extractLane(f, 2), 33); + assertEq(Int32x4.extractLane(f, 3), 44); + + assertThrowsInstanceOf(() => Int32x4.extractLane(f, 4), RangeError); + assertThrowsInstanceOf(() => Int32x4.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Int32x4.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Int32x4.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Int32x4.extractLane(Float32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Int32x4.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Int32x4.extractLane(f, f), TypeError); +} + +function testInt32x4Handles() { + var Array = Int32x4.array(3); + var array = new Array([Int32x4(1, 2, 3, 4), + Int32x4(5, 6, 7, 8), + Int32x4(9, 10, 11, 12)]); + + // Test that trying to create handle into the interior of a + // Int32x4 fails. + assertThrowsInstanceOf(function() { + var h = int32.handle(array, 1, 0); + }, TypeError, "Creating a int32 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = int32.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a int32 handle to elem via move"); +} + +function testInt32x4Reify() { + var Array = Int32x4.array(3); + var array = new Array([Int32x4(1, 2, 3, 4), + Int32x4(5, 6, 7, 8), + Int32x4(9, 10, 11, 12)]); + + // Test that reading array[1] produces a *copy* of Int32x4, not an + // alias into the array. + + var f = array[1]; + assertEq(Int32x4.extractLane(f, 3), 8); + assertEq(Int32x4.extractLane(array[1], 3), 8); + array[1] = Int32x4(15, 16, 17, 18); + assertEq(Int32x4.extractLane(f, 3), 8); + assertEq(Int32x4.extractLane(array[1], 3), 18); +} + +function testInt32x4Setters() { + var Array = Int32x4.array(3); + var array = new Array([Int32x4(1, 2, 3, 4), + Int32x4(5, 6, 7, 8), + Int32x4(9, 10, 11, 12)]); + assertEq(Int32x4.extractLane(array[1], 3), 8); + + // Test that we are allowed to write Int32x4 values into array, + // but not other things. + array[1] = Int32x4(15, 16, 17, 18); + assertEq(Int32x4.extractLane(array[1], 3), 18); + + assertThrowsInstanceOf(function() { + array[1] = {x: 15, y: 16, z: 17, w: 18}; + }, TypeError, "Setting Int32x4 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [15, 16, 17, 18]; + }, TypeError, "Setting Int32x4 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 22; + }, TypeError, "Setting Int32x4 from a number"); +} + +function testUint8x16Alignment() { + assertEq(Uint8x16.byteLength, 16); + assertEq(Uint8x16.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Uint8x16}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testUint8x16Getters() { + // Create a Uint8x16 and check that the getters work: + var f = Uint8x16(11, 22, 33, 44, 55, 66, 77, 88, 99, 10, 20, 30, 40, 50, 60, 70); + assertEq(Uint8x16.extractLane(f, 0), 11); + assertEq(Uint8x16.extractLane(f, 1), 22); + assertEq(Uint8x16.extractLane(f, 2), 33); + assertEq(Uint8x16.extractLane(f, 3), 44); + assertEq(Uint8x16.extractLane(f, 4), 55); + assertEq(Uint8x16.extractLane(f, 5), 66); + assertEq(Uint8x16.extractLane(f, 6), 77); + assertEq(Uint8x16.extractLane(f, 7), 88); + assertEq(Uint8x16.extractLane(f, 8), 99); + assertEq(Uint8x16.extractLane(f, 9), 10); + assertEq(Uint8x16.extractLane(f, 10), 20); + assertEq(Uint8x16.extractLane(f, 11), 30); + assertEq(Uint8x16.extractLane(f, 12), 40); + assertEq(Uint8x16.extractLane(f, 13), 50); + assertEq(Uint8x16.extractLane(f, 14), 60); + assertEq(Uint8x16.extractLane(f, 15), 70); + + assertThrowsInstanceOf(() => Uint8x16.extractLane(f, 16), RangeError); + assertThrowsInstanceOf(() => Uint8x16.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Uint8x16.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Uint8x16.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Uint8x16.extractLane(Uint32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Uint8x16.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Uint8x16.extractLane(f, f), TypeError); +} + +function testUint8x16Handles() { + var Array = Uint8x16.array(3); + var array = new Array([Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Uint8x16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + Uint8x16(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48)]); + + // Test that trying to create handle into the interior of a + // Uint8x16 fails. + assertThrowsInstanceOf(function() { + var h = int8.handle(array, 1, 0); + }, TypeError, "Creating a int8 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = int8.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a int8 handle to elem via move"); +} + +function testUint8x16Reify() { + var Array = Uint8x16.array(3); + var array = new Array([Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Uint8x16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + Uint8x16(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48)]); + + // Test that reading array[1] produces a *copy* of Uint8x16, not an + // alias into the array. + + var f = array[1]; + + var sj1 = Uint8x16.extractLane(f, 3); + + assertEq(sj1, 20); + assertEq(Uint8x16.extractLane(array[1], 3), 20); + array[1] = Uint8x16(49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64); + assertEq(Uint8x16.extractLane(f, 3), 20); + assertEq(Uint8x16.extractLane(array[1], 3), 52); +} + +function testUint8x16Setters() { + var Array = Uint8x16.array(3); + var array = new Array([Uint8x16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + Uint8x16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32), + Uint8x16(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48)]); + assertEq(Uint8x16.extractLane(array[1], 3), 20); + + // Test that we are allowed to write Uint8x16 values into array, + // but not other things. + + array[1] = Uint8x16(49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64); + assertEq(Uint8x16.extractLane(array[1], 3), 52); + + assertThrowsInstanceOf(function() { + array[1] = {s0: 49, s1: 50, s2: 51, s3: 52, s4: 53, s5: 54, s6: 55, s7: 56, + s8: 57, s9: 58, s10: 59, s11: 60, s12: 61, s13: 62, s14: 63, s15: 64}; + }, TypeError, "Setting Uint8x16 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]; + }, TypeError, "Setting Uint8x16 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 52; + }, TypeError, "Setting Uint8x16 from a number"); +} + +function testUint16x8Alignment() { + assertEq(Uint16x8.byteLength, 16); + assertEq(Uint16x8.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Uint16x8}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testUint16x8Getters() { + // Create a Uint16x8 and check that the getters work: + var f = Uint16x8(11, 22, 33, 44, 55, 66, 77, 88); + assertEq(Uint16x8.extractLane(f, 0), 11); + assertEq(Uint16x8.extractLane(f, 1), 22); + assertEq(Uint16x8.extractLane(f, 2), 33); + assertEq(Uint16x8.extractLane(f, 3), 44); + assertEq(Uint16x8.extractLane(f, 4), 55); + assertEq(Uint16x8.extractLane(f, 5), 66); + assertEq(Uint16x8.extractLane(f, 6), 77); + assertEq(Uint16x8.extractLane(f, 7), 88); + + assertThrowsInstanceOf(() => Uint16x8.extractLane(f, 8), RangeError); + assertThrowsInstanceOf(() => Uint16x8.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Uint16x8.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Uint16x8.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Uint16x8.extractLane(Uint32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Uint16x8.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Uint16x8.extractLane(f, f), TypeError); +} + +function testUint16x8Handles() { + var Array = Uint16x8.array(3); + var array = new Array([Uint16x8(1, 2, 3, 4, 5, 6, 7, 8), + Uint16x8(9, 10, 11, 12, 13, 14, 15, 16), + Uint16x8(17, 18, 19, 20, 21, 22, 23, 24)]); + + // Test that trying to create handle into the interior of a + // Uint16x8 fails. + assertThrowsInstanceOf(function() { + var h = int16.handle(array, 1, 0); + }, TypeError, "Creating a int16 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = int16.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a int16 handle to elem via move"); +} + +function testUint16x8Reify() { + var Array = Uint16x8.array(3); + var array = new Array([Uint16x8(1, 2, 3, 4, 5, 6, 7, 8), + Uint16x8(9, 10, 11, 12, 13, 14, 15, 16), + Uint16x8(17, 18, 19, 20, 21, 22, 23, 24)]); + + // Test that reading array[1] produces a *copy* of Uint16x8, not an + // alias into the array. + + var f = array[1]; + assertEq(Uint16x8.extractLane(f, 3), 12); + assertEq(Uint16x8.extractLane(array[1], 3), 12); + array[1] = Uint16x8(25, 26, 27, 28, 29, 30, 31, 32); + assertEq(Uint16x8.extractLane(f, 3), 12); + assertEq(Uint16x8.extractLane(array[1], 3), 28); +} + +function testUint16x8Setters() { + var Array = Uint16x8.array(3); + var array = new Array([Uint16x8(1, 2, 3, 4, 5, 6, 7, 8), + Uint16x8(9, 10, 11, 12, 13, 14, 15, 16), + Uint16x8(17, 18, 19, 20, 21, 22, 23, 24)]); + assertEq(Uint16x8.extractLane(array[1], 3), 12); + + // Test that we are allowed to write Uint16x8 values into array, + // but not other things. + + array[1] = Uint16x8(25, 26, 27, 28, 29, 30, 31, 32); + assertEq(Uint16x8.extractLane(array[1], 3), 28); + + assertThrowsInstanceOf(function() { + array[1] = {s0: 25, s1: 26, s2: 27, s3: 28, s4: 29, s5: 30, s6: 31, s7: 32}; + }, TypeError, "Setting Uint16x8 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [25, 26, 27, 28, 29, 30, 31, 32]; + }, TypeError, "Setting Uint16x8 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 28; + }, TypeError, "Setting Uint16x8 from a number"); +} + +function testUint32x4Alignment() { + assertEq(Uint32x4.byteLength, 16); + assertEq(Uint32x4.byteAlignment, 16); + + var Compound = new StructType({c: uint8, d: uint8, f: Uint32x4}); + assertEq(Compound.fieldOffsets.c, 0); + assertEq(Compound.fieldOffsets.d, 1); + assertEq(Compound.fieldOffsets.f, 16); +} + +function testUint32x4Getters() { + // Create a Uint32x4 and check that the getters work: + var f = Uint32x4(11, 22, 33, 44); + assertEq(Uint32x4.extractLane(f, 0), 11); + assertEq(Uint32x4.extractLane(f, 1), 22); + assertEq(Uint32x4.extractLane(f, 2), 33); + assertEq(Uint32x4.extractLane(f, 3), 44); + + assertThrowsInstanceOf(() => Uint32x4.extractLane(f, 4), RangeError); + assertThrowsInstanceOf(() => Uint32x4.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Uint32x4.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Uint32x4.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Uint32x4.extractLane(Float32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Uint32x4.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Uint32x4.extractLane(f, f), TypeError); +} + +function testUint32x4Handles() { + var Array = Uint32x4.array(3); + var array = new Array([Uint32x4(1, 2, 3, 4), + Uint32x4(5, 6, 7, 8), + Uint32x4(9, 10, 11, 12)]); + + // Test that trying to create handle into the interior of a + // Uint32x4 fails. + assertThrowsInstanceOf(function() { + var h = int32.handle(array, 1, 0); + }, TypeError, "Creating a int32 handle to elem via ctor"); + + assertThrowsInstanceOf(function() { + var h = int32.handle(); + Handle.move(h, array, 1, 0); + }, TypeError, "Creating a int32 handle to elem via move"); +} + +function testUint32x4Reify() { + var Array = Uint32x4.array(3); + var array = new Array([Uint32x4(1, 2, 3, 4), + Uint32x4(5, 6, 7, 8), + Uint32x4(9, 10, 11, 12)]); + + // Test that reading array[1] produces a *copy* of Uint32x4, not an + // alias into the array. + + var f = array[1]; + assertEq(Uint32x4.extractLane(f, 3), 8); + assertEq(Uint32x4.extractLane(array[1], 3), 8); + array[1] = Uint32x4(15, 16, 17, 18); + assertEq(Uint32x4.extractLane(f, 3), 8); + assertEq(Uint32x4.extractLane(array[1], 3), 18); +} + +function testUint32x4Setters() { + var Array = Uint32x4.array(3); + var array = new Array([Uint32x4(1, 2, 3, 4), + Uint32x4(5, 6, 7, 8), + Uint32x4(9, 10, 11, 12)]); + assertEq(Uint32x4.extractLane(array[1], 3), 8); + + // Test that we are allowed to write Uint32x4 values into array, + // but not other things. + array[1] = Uint32x4(15, 16, 17, 18); + assertEq(Uint32x4.extractLane(array[1], 3), 18); + + assertThrowsInstanceOf(function() { + array[1] = {x: 15, y: 16, z: 17, w: 18}; + }, TypeError, "Setting Uint32x4 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [15, 16, 17, 18]; + }, TypeError, "Setting Uint32x4 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 22; + }, TypeError, "Setting Uint32x4 from a number"); +} + +function testBool8x16Getters() { + // Create a Bool8x16 and check that the getters work: + var f = Bool8x16(true, false, true, false, true, false, true, false, true, true, false, false, true, true, false, false); + assertEq(Bool8x16.extractLane(f, 0), true); + assertEq(Bool8x16.extractLane(f, 1), false); + assertEq(Bool8x16.extractLane(f, 2), true); + assertEq(Bool8x16.extractLane(f, 3), false); + assertEq(Bool8x16.extractLane(f, 4), true); + assertEq(Bool8x16.extractLane(f, 5), false); + assertEq(Bool8x16.extractLane(f, 6), true); + assertEq(Bool8x16.extractLane(f, 7), false); + assertEq(Bool8x16.extractLane(f, 8), true); + assertEq(Bool8x16.extractLane(f, 9), true); + assertEq(Bool8x16.extractLane(f, 10), false); + assertEq(Bool8x16.extractLane(f, 11), false); + assertEq(Bool8x16.extractLane(f, 12), true); + assertEq(Bool8x16.extractLane(f, 13), true); + assertEq(Bool8x16.extractLane(f, 14), false); + assertEq(Bool8x16.extractLane(f, 15), false); + + assertThrowsInstanceOf(() => Bool8x16.extractLane(f, 16), RangeError); + assertThrowsInstanceOf(() => Bool8x16.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Bool8x16.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Bool8x16.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Bool8x16.extractLane(Float32x4(1, 2, 3, 4), 0), TypeError); + assertThrowsInstanceOf(() => Bool8x16.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Bool8x16.extractLane(f, f), TypeError); +} + +function testBool8x16Reify() { + var Array = Bool8x16.array(3); + var array = new Array([Bool8x16(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false), + Bool8x16(false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true), + Bool8x16(true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false)]); + + // Test that reading array[1] produces a *copy* of Bool8x16, not an + // alias into the array. + + var f = array[1]; + assertEq(Bool8x16.extractLane(f, 2), false); + assertEq(Bool8x16.extractLane(array[1], 2), false); + assertEq(Bool8x16.extractLane(f, 3), true); + assertEq(Bool8x16.extractLane(array[1], 3), true); + array[1] = Bool8x16(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false); + assertEq(Bool8x16.extractLane(f, 3), true); + assertEq(Bool8x16.extractLane(array[1], 3), false); +} + +function testBool8x16Setters() { + var Array = Bool8x16.array(3); + var array = new Array([Bool8x16(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false), + Bool8x16(false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true), + Bool8x16(true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false)]); + + assertEq(Bool8x16.extractLane(array[1], 3), true); + // Test that we are allowed to write Bool8x16 values into array, + // but not other things. + array[1] = Bool8x16(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false); + assertEq(Bool8x16.extractLane(array[1], 3), false); + assertThrowsInstanceOf(function() { + array[1] = {s0: true, s1: true, s2: true, s3: true, s4: true, s5: true, s6: true, s7: true, + s8: false, s9: false, s10: false, s11: false, s12: false, s13: false, s14: false, s15: false}; + }, TypeError, "Setting Bool8x16 from an object"); + assertThrowsInstanceOf(function() { + array[1] = [true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false]; + }, TypeError, "Setting Bool8x16 from an array"); + assertThrowsInstanceOf(function() { + array[1] = false; + }, TypeError, "Setting Bool8x16 from a boolean"); +} + +function testBool16x8Getters() { + // Create a Bool8x16 and check that the getters work: + var f = Bool16x8(true, false, true, false, true, true, false, false); + assertEq(Bool16x8.extractLane(f, 0), true); + assertEq(Bool16x8.extractLane(f, 1), false); + assertEq(Bool16x8.extractLane(f, 2), true); + assertEq(Bool16x8.extractLane(f, 3), false); + assertEq(Bool16x8.extractLane(f, 4), true); + assertEq(Bool16x8.extractLane(f, 5), true); + assertEq(Bool16x8.extractLane(f, 6), false); + assertEq(Bool16x8.extractLane(f, 7), false); + + assertThrowsInstanceOf(() => Bool16x8.extractLane(f, 8), RangeError); + assertThrowsInstanceOf(() => Bool16x8.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Bool16x8.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Bool16x8.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Bool16x8.extractLane(Float32x4(1, 2, 3, 4), 0), TypeError); + assertThrowsInstanceOf(() => Bool16x8.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Bool16x8.extractLane(f, f), TypeError); +} + +function testBool16x8Reify() { + var Array = Bool16x8.array(3); + var array = new Array([Bool16x8(true, false, true, false, true, false, true, false), + Bool16x8(false, true, false, true, false, true, false, true), + Bool16x8(true, true, true, false, true, true, true, false)]); + // Test that reading array[1] produces a *copy* of Bool16x8, not an + // alias into the array. + var f = array[1]; + assertEq(Bool16x8.extractLane(f, 2), false); + assertEq(Bool16x8.extractLane(array[1], 2), false); + assertEq(Bool16x8.extractLane(f, 3), true); + assertEq(Bool16x8.extractLane(array[1], 3), true); + array[1] = Bool16x8(true, false, true, false, true, false, true, false); + assertEq(Bool16x8.extractLane(f, 3), true); + assertEq(Bool16x8.extractLane(array[1], 3), false); +} + +function testBool16x8Setters() { + var Array = Bool16x8.array(3); + var array = new Array([Bool16x8(true, false, true, false, true, false, true, false), + Bool16x8(false, true, false, true, false, true, false, true), + Bool16x8(true, true, true, false, true, true, true, false)]); + + + assertEq(Bool16x8.extractLane(array[1], 3), true); + // Test that we are allowed to write Bool16x8 values into array, + // but not other things. + array[1] = Bool16x8(true, false, true, false, true, false, true, false); + assertEq(Bool16x8.extractLane(array[1], 3), false); + assertThrowsInstanceOf(function() { + array[1] = {s0: false, s1: true, s2: false, s3: true, s4: false, s5: true, s6: false, s7: true}; + }, TypeError, "Setting Bool16x8 from an object"); + assertThrowsInstanceOf(function() { + array[1] = [true, false, false, true, true, true, false, false]; + }, TypeError, "Setting Bool16x8 from an array"); + assertThrowsInstanceOf(function() { + array[1] = false; + }, TypeError, "Setting Bool16x8 from a boolean"); +} + +function testBool32x4Getters() { + // Create a Bool32x4 and check that the getters work: + var f = Bool32x4(true, false, false, true); + assertEq(Bool32x4.extractLane(f, 0), true); + assertEq(Bool32x4.extractLane(f, 1), false); + assertEq(Bool32x4.extractLane(f, 2), false); + assertEq(Bool32x4.extractLane(f, 3), true); + assertThrowsInstanceOf(() => Bool32x4.extractLane(f, 4), RangeError); + assertThrowsInstanceOf(() => Bool32x4.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Bool32x4.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Bool32x4.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Bool32x4.extractLane(Float32x4(1, 2, 3, 4), 0), TypeError); + assertThrowsInstanceOf(() => Bool32x4.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Bool32x4.extractLane(f, f), TypeError); +} + +function testBool32x4Reify() { + var Array = Bool32x4.array(3); + var array = new Array([Bool32x4(true, false, false, true), + Bool32x4(true, false, true, false), + Bool32x4(true, true, true, false)]); + + // Test that reading array[1] produces a *copy* of Bool32x4, not an + // alias into the array. + + var f = array[1]; + assertEq(Bool32x4.extractLane(f, 2), true); + assertEq(Bool32x4.extractLane(array[1], 2), true); + assertEq(Bool32x4.extractLane(f, 3), false); + assertEq(Bool32x4.extractLane(array[1], 3), false); + array[1] = Bool32x4(false, true, false, true); + assertEq(Bool32x4.extractLane(f, 3), false); + assertEq(Bool32x4.extractLane(array[1], 3), true); +} + +function testBool32x4Setters() { + var Array = Bool32x4.array(3); + var array = new Array([Bool32x4(true, false, false, true), + Bool32x4(true, false, true, false), + Bool32x4(true, true, true, false)]); + + + assertEq(Bool32x4.extractLane(array[1], 3), false); + // Test that we are allowed to write Bool32x4 values into array, + // but not other things. + array[1] = Bool32x4(false, true, false, true); + assertEq(Bool32x4.extractLane(array[1], 3), true); + assertThrowsInstanceOf(function() { + array[1] = {x: false, y: true, z: false, w: true}; + }, TypeError, "Setting Bool32x4 from an object"); + assertThrowsInstanceOf(function() { + array[1] = [true, false, false, true]; + }, TypeError, "Setting Bool32x4 from an array"); + assertThrowsInstanceOf(function() { + array[1] = false; + }, TypeError, "Setting Bool32x4 from a number"); +} + +function testBool64x2Getters() { + // Create a Bool64x2 and check that the getters work: + var f = Bool64x2(true, false); + assertEq(Bool64x2.extractLane(f, 0), true); + assertEq(Bool64x2.extractLane(f, 1), false); + + assertThrowsInstanceOf(() => Bool64x2.extractLane(f, 2), RangeError); + assertThrowsInstanceOf(() => Bool64x2.extractLane(f, -1), RangeError); + assertThrowsInstanceOf(() => Bool64x2.extractLane(f, 0.5), RangeError); + assertThrowsInstanceOf(() => Bool64x2.extractLane(f, {}), RangeError); + assertThrowsInstanceOf(() => Bool64x2.extractLane(Bool32x4(1,2,3,4), 0), TypeError); + assertThrowsInstanceOf(() => Bool64x2.extractLane(1, 0), TypeError); + assertThrowsInstanceOf(() => Bool64x2.extractLane(f, f), TypeError); +} + +function testBool64x2Reify() { + var Array = Bool64x2.array(3); + var array = new Array([Bool64x2(true, false), + Bool64x2(false, true), + Bool64x2(true, true)]); + + // Test that reading array[1] produces a *copy* of Bool64x2, not an + // alias into the array. + + var f = array[1]; + assertEq(Bool64x2.extractLane(f, 1), true); + assertEq(Bool64x2.extractLane(array[1], 1), true); + array[1] = Bool64x2(false, false); + assertEq(Bool64x2.extractLane(f, 1), true); + assertEq(Bool64x2.extractLane(array[1], 1), false); +} + +function testBool64x2Setters() { + var Array = Bool64x2.array(3); + var array = new Array([Bool64x2(true, false), + Bool64x2(false, true), + Bool64x2(true, true)]); + assertEq(Bool64x2.extractLane(array[1], 1), true); + + // Test that we are allowed to write Bool64x2 values into array, + // but not other things. + + array[1] = Bool64x2(false, false); + assertEq(Bool64x2.extractLane(array[1], 1), false); + + assertThrowsInstanceOf(function() { + array[1] = {x: false, y: false }; + }, TypeError, "Setting Bool64x2 from an object"); + + assertThrowsInstanceOf(function() { + array[1] = [ false, false ]; + }, TypeError, "Setting Bool64x2 from an array"); + + assertThrowsInstanceOf(function() { + array[1] = 9; + }, TypeError, "Setting Bool64x2 from a number"); +} + + +function test() { + + testFloat32x4Alignment(); + testFloat32x4Getters(); + testFloat32x4Handles(); + testFloat32x4Reify(); + testFloat32x4Setters(); + + testFloat64x2Alignment(); + testFloat64x2Getters(); + testFloat64x2Handles(); + testFloat64x2Reify(); + testFloat64x2Setters(); + + testInt8x16Alignment(); + testInt8x16Getters(); + testInt8x16Handles(); + testInt8x16Reify(); + testInt8x16Setters(); + + testInt16x8Alignment(); + testInt16x8Getters(); + testInt16x8Handles(); + testInt16x8Reify(); + testInt16x8Setters(); + + testInt32x4Alignment(); + testInt32x4Getters(); + testInt32x4Handles(); + testInt32x4Reify(); + testInt32x4Setters(); + + testUint8x16Alignment(); + testUint8x16Getters(); + testUint8x16Handles(); + testUint8x16Reify(); + testUint8x16Setters(); + + testUint16x8Alignment(); + testUint16x8Getters(); + testUint16x8Handles(); + testUint16x8Reify(); + testUint16x8Setters(); + + testUint32x4Alignment(); + testUint32x4Getters(); + testUint32x4Handles(); + testUint32x4Reify(); + testUint32x4Setters(); + + testBool8x16Getters(); + testBool8x16Reify(); + testBool8x16Setters(); + + testBool16x8Getters(); + testBool16x8Reify(); + testBool16x8Setters(); + + testBool32x4Getters(); + testBool32x4Reify(); + testBool32x4Setters(); + + testBool64x2Getters(); + testBool64x2Reify(); + testBool64x2Setters(); + + if (typeof reportCompare === "function") { + reportCompare(true, true); + } +} + +test(); diff --git a/js/src/tests/ecma_7/SIMD/unary-operations.js b/js/src/tests/ecma_7/SIMD/unary-operations.js new file mode 100644 index 000000000..b04d23874 --- /dev/null +++ b/js/src/tests/ecma_7/SIMD/unary-operations.js @@ -0,0 +1,410 @@ +// |reftest| skip-if(!this.hasOwnProperty("SIMD")) +var Float32x4 = SIMD.Float32x4; +var Int8x16 = SIMD.Int8x16; +var Int16x8 = SIMD.Int16x8; +var Int32x4 = SIMD.Int32x4; +var Uint8x16 = SIMD.Uint8x16; +var Uint16x8 = SIMD.Uint16x8; +var Uint32x4 = SIMD.Uint32x4; +var Bool8x16 = SIMD.Bool8x16; +var Bool16x8 = SIMD.Bool16x8; +var Bool32x4 = SIMD.Bool32x4; +var Bool64x2 = SIMD.Bool64x2; + +function testFloat32x4abs() { + function absf(a) { + return Math.abs(Math.fround(a)); + } + + var vals = [ + [-1, 2, -3, 4], + [-1.63, 2.46, -3.17, 4.94], + [NaN, -0, Infinity, -Infinity] + ]; + for (var v of vals) { + assertEqX4(Float32x4.abs(Float32x4(...v)), v.map(absf)); + } +} + +function testFloat32x4neg() { + function negf(a) { + return -1 * Math.fround(a); + } + + var vals = [ + [1, 2, 3, 4], + [0.999, -0.001, 3.78, 4.05], + [NaN, -0, Infinity, -Infinity] + ]; + for (var v of vals) { + assertEqX4(Float32x4.neg(Float32x4(...v)), v.map(negf)); + } +} + +function testFloat32x4reciprocalApproximation() { + function reciprocalf(a) { + return Math.fround(1 / Math.fround(a)); + } + + var vals = [ + [[1, 0.5, 0.25, 0.125], [1, 2, 4, 8]], + [[1.6, 0.8, 0.4, 0.2], [1.6, 0.8, 0.4, 0.2].map(reciprocalf)], + [[NaN, -0, Infinity, -Infinity], [NaN, -Infinity, 0, -0]] + ]; + + for (var [v,w] of vals) { + assertEqX4(Float32x4.reciprocalApproximation(Float32x4(...v)), w); + } +} + +function testFloat32x4reciprocalSqrtApproximation() { + function reciprocalsqrtf(a) { + assertEq(Math.fround(a), a); + return Math.fround(1 / Math.fround(Math.sqrt(a))); + } + + var vals = [ + [[1, 1, 0.25, 0.25], [1, 1, 2, 2]], + [[25, 16, 6.25, 1.5625], [25, 16, 6.25, 1.5625].map(reciprocalsqrtf)], + [[NaN, -0, Infinity, -Infinity], [NaN, -0, Infinity, -Infinity].map(reciprocalsqrtf)], + [[Math.pow(2, 32), Math.pow(2, -32), +0, Math.pow(2, -148)], + [Math.pow(2, -16), Math.pow(2, 16), Infinity, Math.pow(2, 74)]] + ]; + + for (var [v,w] of vals) { + assertEqX4(Float32x4.reciprocalSqrtApproximation(Float32x4(...v)), w); + } +} + +function testFloat32x4sqrt() { + function sqrtf(a) { + return Math.fround(Math.sqrt(Math.fround(a))); + } + + var vals = [ + [[1, 4, 9, 16], [1, 2, 3, 4]], + [[2.7225, 7.3441, 9.4249, -1], [2.7225, 7.3441, 9.4249, -1].map(sqrtf)], + [[NaN, -0, Infinity, -Infinity], [NaN, -0, Infinity, NaN]] + ]; + + for (var [v,w] of vals) { + assertEqX4(Float32x4.sqrt(Float32x4(...v)), w); + } +} + +function testInt8x16neg() { + var vals = [ + [[1, 2, 3, 4, 5, 6, 7, 8, -1, -2, -3, -4, -5, INT8_MAX, INT8_MIN, 0], + [-1, -2, -3, -4, -5, -6, -7, -8, 1, 2, 3, 4, 5, -INT8_MAX, INT8_MIN, 0]] + ]; + for (var [v,w] of vals) { + assertEqX16(Int8x16.neg(Int8x16(...v)), w); + } +} + +function testInt8x16not() { + var vals = [ + [[1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, 0, INT8_MIN, INT8_MAX], + [1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, 0, INT8_MIN, INT8_MAX].map((x) => ~x << 24 >> 24)] + ]; + for (var [v,w] of vals) { + assertEqX16(Int8x16.not(Int8x16(...v)), w); + } +} + +function testInt16x8neg() { + var vals = [ + [[1, 2, 3, -1, -2, 0, INT16_MIN, INT16_MAX], + [-1, -2, -3, 1, 2, 0, INT16_MIN, -INT16_MAX]] + ]; + for (var [v,w] of vals) { + assertEqX8(Int16x8.neg(Int16x8(...v)), w); + } +} + +function testInt16x8not() { + var vals = [ + [[1, 2, 3, -1, -2, 0, INT16_MIN, INT16_MAX], + [1, 2, 3, -1, -2, 0, INT16_MIN, INT16_MAX].map((x) => ~x << 16 >> 16)] + ]; + for (var [v,w] of vals) { + assertEqX8(Int16x8.not(Int16x8(...v)), w); + } +} + +function testInt32x4neg() { + var valsExp = [ + [[1, 2, 3, 4], [-1, -2, -3, -4]], + [[INT32_MAX, INT32_MIN, -0, 0], [-INT32_MAX | 0, -INT32_MIN | 0, 0, 0]] + ]; + for (var [v,w] of valsExp) { + assertEqX4(Int32x4.neg(Int32x4(...v)), w); + } +} + +function testInt32x4not() { + var valsExp = [ + [[1, 2, 3, 4], [-2, -3, -4, -5]], + [[INT32_MAX, INT32_MIN, 0, 0], [~INT32_MAX | 0, ~INT32_MIN | 0, ~0 | 0, ~0 | 0]] + ]; + for (var [v,w] of valsExp) { + assertEqX4(Int32x4.not(Int32x4(...v)), w); + } +} + +function testUint8x16neg() { + var vals = [ + [[ 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, UINT8_MAX, INT8_MAX, 0, 0], + [255, 254, 253, 252, 251, 250, 249, 0, 1, 2, 3, 4, 1, INT8_MAX+2, 0, 0]] + ]; + for (var [v,w] of vals) { + assertEqX16(Uint8x16.neg(Uint8x16(...v)), w); + } +} + +function testUint8x16not() { + var vals = [ + [[1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, 0, INT8_MIN, INT8_MAX], + [1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, 0, INT8_MIN, INT8_MAX].map((x) => ~x << 24 >>> 24)] + ]; + for (var [v,w] of vals) { + assertEqX16(Uint8x16.not(Uint8x16(...v)), w); + } +} + +function testUint16x8neg() { + var vals = [ + [[1, 2, UINT16_MAX, -1, -2, 0, INT16_MIN, INT16_MAX], + [1, 2, UINT16_MAX, -1, -2, 0, INT16_MIN, INT16_MAX].map((x) => -x << 16 >>> 16)] + ]; + for (var [v,w] of vals) { + assertEqX8(Uint16x8.neg(Uint16x8(...v)), w); + } +} + +function testUint16x8not() { + var vals = [ + [[1, 2, UINT16_MAX, -1, -2, 0, INT16_MIN, INT16_MAX], + [1, 2, UINT16_MAX, -1, -2, 0, INT16_MIN, INT16_MAX].map((x) => ~x << 16 >>> 16)] + ]; + for (var [v,w] of vals) { + assertEqX8(Uint16x8.not(Uint16x8(...v)), w); + } +} + +function testUint32x4neg() { + var valsExp = [ + [[1, 2, 3, 4], [-1 >>> 0, -2 >>> 0, -3 >>> 0, -4 >>> 0]], + [[INT32_MAX, INT32_MIN, -0, 0], [-INT32_MAX >>> 0, -INT32_MIN >>> 0, 0, 0]] + ]; + for (var [v,w] of valsExp) { + assertEqX4(Uint32x4.neg(Uint32x4(...v)), w); + } +} + +function testUint32x4not() { + var valsExp = [ + [[1, 2, 3, 4], [~1 >>> 0, ~2 >>> 0, ~3 >>> 0, ~4 >>> 0]], + [[INT32_MAX, INT32_MIN, UINT32_MAX, 0], [~INT32_MAX >>> 0, ~INT32_MIN >>> 0, 0, ~0 >>> 0]] + ]; + for (var [v,w] of valsExp) { + assertEqX4(Uint32x4.not(Uint32x4(...v)), w); + } +} + +function testBool8x16not() { + var valsExp = [ + [[true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false], + [false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true]], + [[true, true, false, false, true, true, false, false, true, true, false, false, true, true, false, false], + [false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true]] + ]; + for (var [v,w] of valsExp) { + assertEqX16(Bool8x16.not(Bool8x16(...v)), w); + } +} + +function testBool8x16allTrue() { + var valsExp = [ + [[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], false], + [[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], true], + [[false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], false], + [[true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true], false], + [[true, false, true, true, true, true, true, true, true, true, true, true, true, true, false, true], false], + [[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], false], + ]; + for (var [v,w] of valsExp) { + assertEq(Bool8x16.allTrue(Bool8x16(...v)), w); + } +} + +function testBool8x16anyTrue() { + var valsExp = [ + [[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false], false], + [[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], true], + [[false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], true], + [[true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true], true], + [[true, false, true, true, true, true, true, true, true, true, true, true, true, true, false, true], true], + [[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false], true], + ]; + for (var [v,w] of valsExp) { + assertEq(Bool8x16.anyTrue(Bool8x16(...v)), w); + } +} + +function testBool16x8not() { + var valsExp = [ + [[true, false, true, false, true, false, true, false], [false, true, false, true, false, true, false, true]], + [[true, true, false, false, true, true, false, false], [false, false, true, true, false, false, true, true]] + ]; + for (var [v,w] of valsExp) { + assertEqX8(Bool16x8.not(Bool16x8(...v)), w); + } +} + +function testBool16x8allTrue() { + var valsExp = [ + [[false, false, false, false, false, false, false, false], false], + [[true, true, true, true, true, true, true, true], true], + [[false, true, true, true, true, true, true, true], false], + [[true, false, true, true, true, true, true, true], false], + [[true, true, true, true, true, true, false, true], false], + [[true, true, true, true, true, true, true, false], false], + ]; + for (var [v,w] of valsExp) { + assertEq(Bool16x8.allTrue(Bool16x8(...v)), w); + } +} + +function testBool16x8anyTrue() { + var valsExp = [ + [[false, false, false, false, false, false, false, false], false], + [[true, true, true, true, true, true, true, true], true], + [[false, false, false, false, false, false, false, true], true], + [[false, false, false, false, false, false, true, false], true], + [[false, true, false, false, false, false, false, true], true], + [[true, false, false, false, false, false, false, false], true], + ]; + for (var [v,w] of valsExp) { + assertEq(Bool16x8.anyTrue(Bool16x8(...v)), w); + } +} + +function testBool32x4not() { + var valsExp = [ + [[true, false, true, false], [false, true, false, true]], + [[true, true, false, false], [false, false, true, true]] + ]; + for (var [v,w] of valsExp) { + assertEqX4(Bool32x4.not(Bool32x4(...v)), w); + } +} + +function testBool32x4allTrue() { + var valsExp = [ + [[false, false, false, false], false], + [[true, false, true, false], false], + [[true, true, true, true], true], + [[true, true, false, false], false] + ]; + for (var [v,w] of valsExp) { + assertEq(Bool32x4.allTrue(Bool32x4(...v)), w); + } +} + +function testBool32x4anyTrue() { + var valsExp = [ + [[false, false, false, false], false], + [[true, false, true, false], true], + [[true, true, true, true], true], + [[true, true, false, false], true] + ]; + for (var [v,w] of valsExp) { + assertEq(Bool32x4.anyTrue(Bool32x4(...v)), w); + } +} + +function testBool64x2not() { + var valsExp = [ + [[false, false], [true, true]], + [[false, true], [true, false]], + [[true, false], [false, true]], + [[true, true], [false, false]] + ]; + for (var [v,w] of valsExp) { + assertEqX2(Bool64x2.not(Bool64x2(...v)), w); + } +} + +function testBool64x2allTrue() { + var valsExp = [ + [[false, false], false], + [[false, true], false], + [[true, false], false], + [[true, true], true] + ]; + for (var [v,w] of valsExp) { + assertEq(Bool64x2.allTrue(Bool64x2(...v)), w); + } +} + +function testBool64x2anyTrue() { + var valsExp = [ + [[false, false], false], + [[false, true], true], + [[true, false], true], + [[true, true], true] + ]; + for (var [v,w] of valsExp) { + assertEq(Bool64x2.anyTrue(Bool64x2(...v)), w); + } +} + +function test() { + testFloat32x4abs(); + testFloat32x4neg(); + testFloat32x4reciprocalApproximation(); + testFloat32x4reciprocalSqrtApproximation(); + testFloat32x4sqrt(); + + testInt8x16neg(); + testInt8x16not(); + + testInt16x8neg(); + testInt16x8not(); + + testInt32x4neg(); + testInt32x4not(); + + testUint8x16neg(); + testUint8x16not(); + + testUint16x8neg(); + testUint16x8not(); + + testUint32x4neg(); + testUint32x4not(); + + testBool8x16not(); + testBool8x16allTrue(); + testBool8x16anyTrue(); + + testBool16x8not(); + testBool16x8allTrue(); + testBool16x8anyTrue(); + + testBool32x4not(); + testBool32x4allTrue(); + testBool32x4anyTrue(); + + testBool64x2not(); + testBool64x2allTrue(); + testBool64x2anyTrue(); + + + if (typeof reportCompare === "function") { + reportCompare(true, true); + } +} + +test(); -- cgit v1.2.3