Backed out changeset 776c989112f1 (bug 1031203)

This commit is contained in:
Carsten "Tomcat" Book 2014-12-23 11:51:08 +01:00
parent 3ce0451234
commit 592726d322
24 changed files with 124 additions and 1113 deletions

View File

@ -6,7 +6,6 @@
*/
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var fround = Math.fround;
@ -16,60 +15,41 @@ function boolToSimdLogical(b) {
}
function testEqualFloat32x4(v, w) {
testBinaryCompare(v, w, float32x4.equal, (x, y) => boolToSimdLogical(fround(x) == fround(y)));
testBinaryFunc(v, w, float32x4.equal, (x, y) => boolToSimdLogical(fround(x) == fround(y)));
}
function testNotEqualFloat32x4(v, w) {
testBinaryCompare(v, w, float32x4.notEqual, (x, y) => boolToSimdLogical(fround(x) != fround(y)));
testBinaryFunc(v, w, float32x4.notEqual, (x, y) => boolToSimdLogical(fround(x) != fround(y)));
}
function testLessThanFloat32x4(v, w) {
testBinaryCompare(v, w, float32x4.lessThan, (x, y) => boolToSimdLogical(fround(x) < fround(y)));
testBinaryFunc(v, w, float32x4.lessThan, (x, y) => boolToSimdLogical(fround(x) < fround(y)));
}
function testLessThanOrEqualFloat32x4(v, w) {
testBinaryCompare(v, w, float32x4.lessThanOrEqual, (x, y) => boolToSimdLogical(fround(x) <= fround(y)));
testBinaryFunc(v, w, float32x4.lessThanOrEqual, (x, y) => boolToSimdLogical(fround(x) <= fround(y)));
}
function testGreaterThanFloat32x4(v, w) {
testBinaryCompare(v, w, float32x4.greaterThan, (x, y) => boolToSimdLogical(fround(x) > fround(y)));
testBinaryFunc(v, w, float32x4.greaterThan, (x, y) => boolToSimdLogical(fround(x) > fround(y)));
}
function testGreaterThanOrEqualFloat32x4(v, w) {
testBinaryCompare(v, w, float32x4.greaterThanOrEqual, (x, y) => boolToSimdLogical(fround(x) >= fround(y)));
}
function testEqualFloat64x2(v, w) {
testBinaryCompare(v, w, float64x2.equal, (x, y) => boolToSimdLogical(x == y));
}
function testNotEqualFloat64x2(v, w) {
testBinaryCompare(v, w, float64x2.notEqual, (x, y) => boolToSimdLogical(x != y));
}
function testLessThanFloat64x2(v, w) {
testBinaryCompare(v, w, float64x2.lessThan, (x, y) => boolToSimdLogical(x < y));
}
function testLessThanOrEqualFloat64x2(v, w) {
testBinaryCompare(v, w, float64x2.lessThanOrEqual, (x, y) => boolToSimdLogical(x <= y));
}
function testGreaterThanFloat64x2(v, w) {
testBinaryCompare(v, w, float64x2.greaterThan, (x, y) => boolToSimdLogical(x > y));
}
function testGreaterThanOrEqualFloat64x2(v, w) {
testBinaryCompare(v, w, float64x2.greaterThanOrEqual, (x, y) => boolToSimdLogical(x >= y));
testBinaryFunc(v, w, float32x4.greaterThanOrEqual, (x, y) => boolToSimdLogical(fround(x) >= fround(y)));
}
function testEqualInt32x4(v, w) {
testBinaryCompare(v, w, int32x4.equal, (x, y) => boolToSimdLogical(x == y));
testBinaryFunc(v, w, int32x4.equal, (x, y) => boolToSimdLogical(x == y));
}
function testNotEqualInt32x4(v, w) {
testBinaryCompare(v, w, int32x4.notEqual, (x, y) => boolToSimdLogical(x != y));
testBinaryFunc(v, w, int32x4.notEqual, (x, y) => boolToSimdLogical(x != y));
}
function testLessThanInt32x4(v, w) {
testBinaryCompare(v, w, int32x4.lessThan, (x, y) => boolToSimdLogical(x < y));
testBinaryFunc(v, w, int32x4.lessThan, (x, y) => boolToSimdLogical(x < y));
}
function testLessThanOrEqualInt32x4(v, w) {
testBinaryCompare(v, w, int32x4.lessThanOrEqual, (x, y) => boolToSimdLogical(x <= y));
testBinaryFunc(v, w, int32x4.lessThanOrEqual, (x, y) => boolToSimdLogical(x <= y));
}
function testGreaterThanInt32x4(v, w) {
testBinaryCompare(v, w, int32x4.greaterThan, (x, y) => boolToSimdLogical(x > y));
testBinaryFunc(v, w, int32x4.greaterThan, (x, y) => boolToSimdLogical(x > y));
}
function testGreaterThanOrEqualInt32x4(v, w) {
testBinaryCompare(v, w, int32x4.greaterThanOrEqual, (x, y) => boolToSimdLogical(x >= y));
testBinaryFunc(v, w, int32x4.greaterThanOrEqual, (x, y) => boolToSimdLogical(x >= y));
}
function test() {
@ -95,32 +75,6 @@ function test() {
}
}
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 int32x4val = [
int32x4(1, 2, 3, 4),
int32x4(-1, -2, -3, -4),

View File

@ -0,0 +1,54 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 946042;
var float32x4 = SIMD.float32x4;
function testMaxFloat32(v, w) {
return testBinaryFunc(v, w, float32x4.max, (x, y) => Math.fround(Math.max(x, y)));
}
function testMinFloat32(v, w) {
return testBinaryFunc(v, w, float32x4.min, (x, y) => Math.fround(Math.min(x, y)));
}
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);
}
function testMinNumFloat32(v, w) {
return testBinaryFunc(v, w, float32x4.minNum, minNum);
}
function test() {
print(BUGNUMBER + ": " + summary);
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);
}
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,14 +1,14 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 946042;
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float32x4/float64x2 clamp';
var summary = 'float32x4 clamp';
function test() {
print(BUGNUMBER + ": " + summary);
// FIXME -- Bug 1068028: Amend to check for correctness of NaN/-0 border cases once the semantics are defined.
// FIXME -- Bug 1068028: Amend to check for correctness of NaN border cases once the semantics are defined.
var a = float32x4(-20, 10, 30, 0.5);
var lower = float32x4(2, 1, 50, 0);
@ -37,24 +37,6 @@ function test() {
assertEq(i.z, 10);
assertEq(i.w, -10);
var j = float64x2(-20, 10);
var k = float64x2(2.125, 3);
var lower3 = float64x2(2, 1);
var upper3 = float64x2(2.5, 5);
var l = float64x2.clamp(j, lower3, upper3);
assertEq(l.x, 2);
assertEq(l.y, 5);
var m = float64x2.clamp(k, lower3, upper3);
assertEq(m.x, 2.125);
assertEq(m.y, 3);
var n = float64x2(-5, 5);
var lower4 = float64x2(-Infinity, 0);
var upper4 = float64x2(+Infinity, +Infinity);
var p = float64x2.clamp(n, lower4, upper4);
assertEq(p.x, -5);
assertEq(p.y, 5);
if (typeof reportCompare === "function")
reportCompare(true, true);
}

View File

@ -1,60 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var summary = 'float32x4 fromFloat64x2';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float64x2(1, 2);
var c = float32x4.fromFloat64x2(a);
assertEq(c.x, 1);
assertEq(c.y, 2);
assertEq(c.z, 0);
assertEq(c.w, 0);
var d = float64x2(-0, NaN);
var f = float32x4.fromFloat64x2(d);
assertEq(f.x, -0);
assertEq(f.y, NaN);
assertEq(f.z, 0);
assertEq(f.w, 0);
var g = float64x2(Infinity, -Infinity);
var i = float32x4.fromFloat64x2(g);
assertEq(i.x, Infinity);
assertEq(i.y, -Infinity);
assertEq(i.z, 0);
assertEq(i.w, 0);
var j = Math.pow(2, 25) - 1;
var k = -Math.pow(2, 25);
var l = float64x2(j, k);
var m = float32x4.fromFloat64x2(l);
assertEq(m.x, Math.fround(j));
assertEq(m.y, Math.fround(k));
assertEq(m.z, 0);
assertEq(m.w, 0);
var o = Math.pow(2, 1000);
var p = Math.pow(2, -1000);
var q = float64x2(o, p);
var r = float32x4.fromFloat64x2(q);
assertEq(r.x, Math.fround(o));
assertEq(r.y, Math.fround(p));
assertEq(r.z, 0);
assertEq(r.w, 0);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,43 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float32x4 fromFloat64x2Bits';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float64x2(2.000000473111868, 512.0001225471497);
var b = float32x4.fromFloat64x2Bits(a);
assertEq(b.x, 1.0);
assertEq(b.y, 2.0);
assertEq(b.z, 3.0);
assertEq(b.w, 4.0);
var c = float64x2(-0, NaN);
var d = float32x4.fromFloat64x2Bits(c);
assertEq(d.x, 0);
assertEq(d.y, -0);
assertEq(d.z, 0);
assertEq(d.w, NaN);
var e = float64x2(Infinity, -Infinity);
var f = float32x4.fromFloat64x2Bits(e);
assertEq(f.x, 0);
assertEq(f.y, NaN);
assertEq(f.z, 0);
assertEq(f.w, NaN);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,77 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var summary = 'float64x2 arithmetic';
/*
* 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 reciprocal(a) { return 1 / a; }
function reciprocalSqrt(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 testReciprocal(v) {
return testUnaryFunc(v, float64x2.reciprocal, reciprocal);
}
function testReciprocalSqrt(v) {
return testUnaryFunc(v, float64x2.reciprocalSqrt, reciprocalSqrt);
}
function testSqrt(v) {
return testUnaryFunc(v, float64x2.sqrt, Math.sqrt);
}
function test() {
print(BUGNUMBER + ": " + summary);
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)]])
{
testAdd(v, w);
testSub(v, w);
testMul(v, w);
testDiv(v, w);
testAbs(v);
testNeg(v);
testReciprocal(v);
testSqrt(v);
}
for (v of [float64x2(1, 0.25), float64x2(3, 0.5),
float64x2(-0, NaN), float64x2(+Infinity, -Infinity)])
{
testReciprocalSqrt(v);
}
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,30 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var summary = 'float64x2 alignment';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
function test() {
print(BUGNUMBER + ": " + summary);
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);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,41 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var summary = 'float64x2 fromFloat32x4';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float32x4(100, 200, 300, 400);
var c = float64x2.fromFloat32x4(a);
assertEq(c.x, 100);
assertEq(c.y, 200);
var d = float32x4(NaN, -0, NaN, -0);
var f = float64x2.fromFloat32x4(d);
assertEq(f.x, NaN);
assertEq(f.y, -0);
var g = float32x4(Infinity, -Infinity, Infinity, -Infinity);
var i = float64x2.fromFloat32x4(g);
assertEq(i.x, Infinity);
assertEq(i.y, -Infinity);
var j = float32x4(13.37, 12.853, 49.97, 53.124);
var l = float64x2.fromFloat32x4(j);
assertEq(l.x, Math.fround(13.37));
assertEq(l.y, Math.fround(12.853));
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,32 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float64x2 fromFloat32x4Bits';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float32x4(0, 1.875, 0, 2);
var c = float64x2.fromFloat32x4Bits(a);
assertEq(c.x, 1.0);
assertEq(c.y, 2.0);
var d = float32x4(NaN, -0, Infinity, -Infinity);
var f = float64x2.fromFloat32x4Bits(d);
assertEq(f.x, -1.058925634e-314);
assertEq(f.y, -1.404448428688076e+306);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,31 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float64x2 fromInt32x4';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = int32x4(1, 2, 3, 4);
var c = float64x2.fromInt32x4(a);
assertEq(c.x, 1);
assertEq(c.y, 2);
var d = int32x4(INT32_MAX, INT32_MIN, 0, 0);
var f = float64x2.fromInt32x4(d);
assertEq(f.x, INT32_MAX);
assertEq(f.y, INT32_MIN);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,31 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float64x2 fromInt32x4Bits';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = int32x4(0x00000000, 0x3ff00000, 0x0000000, 0x40000000);
var c = float64x2.fromInt32x4Bits(a);
assertEq(c.x, 1.0);
assertEq(c.y, 2.0);
var d = int32x4(0xabcdef12, 0x3ff00000, 0x21fedcba, 0x40000000);
var f = float64x2.fromInt32x4Bits(d);
assertEq(f.x, 1.0000006400213732);
assertEq(f.y, 2.0000002532866263);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,47 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float64x2 getters';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
// Create a float64x2 and check that the getters work:
var f = float64x2(11, 22);
assertEq(f.x, 11);
assertEq(f.y, 22);
// Test that the getters work when called reflectively:
var g = f.__lookupGetter__("x");
assertEq(g.call(f), 11);
// Test that getters cannot be applied to various incorrect things:
assertThrowsInstanceOf(function() {
g.call({})
}, TypeError, "Getter applicable to random objects");
assertThrowsInstanceOf(function() {
g.call(0xDEADBEEF)
}, TypeError, "Getter applicable to integers");
assertThrowsInstanceOf(function() {
var T = new TypedObject.StructType({x: TypedObject.float64,
y: TypedObject.float64});
var v = new T({x: 11, y: 22});
g.call(v)
}, TypeError, "Getter applicable to structs");
assertThrowsInstanceOf(function() {
var t = new int32x4(1, 2, 3, 4);
g.call(t)
}, TypeError, "Getter applicable to int32x4");
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,51 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float64x2 handles';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
var ArrayType = TypedObject.ArrayType;
var float64 = TypedObject.float64;
var Handle = TypedObject.Handle;
function test() {
print(BUGNUMBER + ": " + summary);
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, "w");
}, TypeError, "Creating a float64 handle to prop via ctor");
assertThrowsInstanceOf(function() {
var h = float64.handle();
Handle.move(h, array, 1, "w");
}, TypeError, "Creating a float64 handle to prop via move");
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");
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,36 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var summary = 'float64x2 reify';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
var ArrayType = TypedObject.ArrayType;
function test() {
print(BUGNUMBER + ": " + summary);
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(f.y, 4);
assertEq(array[1].y, 4);
array[1] = float64x2(7, 8);
assertEq(f.y, 4);
assertEq(array[1].y, 8);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,34 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'float64x2 select';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = int32x4.bool(true, true, false, false);
var b = SIMD.float64x2(1, 2);
var c = SIMD.float64x2(3, 4);
var d = SIMD.float64x2.select(a, b, c);
assertEq(d.x, 1);
assertEq(d.y, 4);
var e = SIMD.float64x2(NaN, -0);
var f = SIMD.float64x2(+Infinity, -Infinity);
var g = SIMD.float64x2.select(a, e, f);
assertEq(g.x, NaN);
assertEq(g.y, -Infinity);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,45 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var summary = 'float64x2 setter';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
var ArrayType = TypedObject.ArrayType;
function test() {
print(BUGNUMBER + ": " + summary);
var Array = float64x2.array(3);
var array = new Array([float64x2(1, 2),
float64x2(3, 4),
float64x2(5, 6)]);
assertEq(array[1].y, 4);
// Test that we are allowed to write float64x2 values into array,
// but not other things.
array[1] = float64x2(7, 8);
assertEq(array[1].y, 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");
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,36 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var summary = 'float64x2 with';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float64x2(1, 2);
var x = float64x2.withX(a, 5);
var y = float64x2.withY(a, 5);
assertEq(x.x, 5);
assertEq(x.y, 2);
assertEq(y.x, 1);
assertEq(y.y, 5);
var b = float64x2(NaN, -0);
var x1 = float64x2.withX(b, Infinity);
var y1 = float64x2.withY(b, -Infinity);
assertEq(x1.x, Infinity);
assertEq(x1.y, -0);
assertEq(y1.x, NaN);
assertEq(y1.y, -Infinity);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,51 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'int32x4 fromFloat64x2';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float64x2(1, 2.2);
var c = int32x4.fromFloat64x2(a);
assertEq(c.x, 1);
assertEq(c.y, 2);
assertEq(c.z, 0);
assertEq(c.w, 0);
var d = float64x2(NaN, -0);
var f = int32x4.fromFloat64x2(d);
assertEq(f.x, 0);
assertEq(f.y, 0);
assertEq(f.z, 0);
assertEq(f.w, 0);
var g = float64x2(Infinity, -Infinity);
var i = int32x4.fromFloat64x2(g);
assertEq(i.x, 0);
assertEq(i.y, 0);
assertEq(i.z, 0);
assertEq(i.w, 0);
var j = Math.pow(2, 31);
var k = -Math.pow(2, 31) - 1;
var m = float64x2(j, k);
var l = int32x4.fromFloat64x2(m);
assertEq(l.x, INT32_MIN);
assertEq(l.y, INT32_MAX);
assertEq(l.z, 0);
assertEq(l.w, 0);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -1,49 +0,0 @@
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))
var BUGNUMBER = 1031203;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
var summary = 'int32x4 fromFloat64x2Bits';
/*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
print(BUGNUMBER + ": " + summary);
var a = float64x2(1.0, 2.0);
var c = int32x4.fromFloat64x2Bits(a);
assertEq(c.x, 0x00000000);
assertEq(c.y, 0x3FF00000);
assertEq(c.z, 0x00000000);
assertEq(c.w, 0x40000000);
var d = float64x2(+Infinity, -Infinity);
var f = int32x4.fromFloat64x2Bits(d);
assertEq(f.x, 0x00000000);
assertEq(f.y, 0x7ff00000);
assertEq(f.z, 0x00000000);
assertEq(f.w, -0x100000);
var g = float64x2(-0, NaN);
var i = int32x4.fromFloat64x2Bits(g);
assertEq(i.x, 0x00000000);
assertEq(i.y, -0x80000000);
assertEq(i.z, 0x00000000);
assertEq(i.w, 0x7ff80000);
var j = float64x2(1.0000006400213732, 2.0000002532866263);
var l = int32x4.fromFloat64x2Bits(j);
assertEq(l.x, -0x543210ee);
assertEq(l.y, 0x3ff00000);
assertEq(l.z, 0x21fedcba);
assertEq(l.w, 0x40000000);
if (typeof reportCompare === "function")
reportCompare(true, true);
}
test();

View File

@ -5,11 +5,11 @@
* https://creativecommons.org/publicdomain/zero/1.0/
*/
// Our array for int32x4 and float32x4 will have 16 elements
const SIZE_32_ARRAY = 16;
const SIZE_64_ARRAY = 8;
// Our float32array will have 16 elements
const SIZE_ARRAY = 16;
const SIZE_BYTES = SIZE_32_ARRAY * 4;
// 1 float32 == 4 bytes
const SIZE_BYTES = SIZE_ARRAY * 4;
function MakeComparator(kind, arr) {
var bpe = arr.BYTES_PER_ELEMENT;
@ -28,14 +28,10 @@ function MakeComparator(kind, arr) {
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) {
@ -53,38 +49,31 @@ function MakeComparator(kind, arr) {
return new typedArrayCtor(new Uint8Array(asArray).buffer);
}
var assertFunc = (lanes == 2) ? assertEqX2 : assertEqX4;
var type = SIMD[kind];
return {
loadX: function(index) {
var v = type.loadX(arr, index);
assertFunc(v, slice(index, 1));
var v = SIMD[kind].loadX(arr, index);
assertEqX4(v, slice(index, 1));
},
loadXY: function(index) {
if (lanes < 4)
return;
var v = type.loadXY(arr, index);
assertFunc(v, slice(index, 2));
var v = SIMD[kind].loadXY(arr, index);
assertEqX4(v, slice(index, 2));
},
loadXYZ: function(index) {
if (lanes < 4)
return;
var v = type.loadXYZ(arr, index);
assertFunc(v, slice(index, 3));
loadXYZ: function(index) {
var v = SIMD[kind].loadXYZ(arr, index);
assertEqX4(v, slice(index, 3));
},
load: function(index) {
var v = type.load(arr, index);
assertFunc(v, slice(index, 4));
var v = SIMD[kind].load(arr, index);
assertEqX4(v, slice(index, 4));
}
}
}
function testLoad(kind, TA) {
var lanes = TA.length / 4;
for (var i = TA.length; i--;)
for (var i = SIZE_ARRAY; i--;)
TA[i] = i;
for (var ta of [
@ -108,7 +97,7 @@ function testLoad(kind, TA) {
var C = MakeComparator(kind, ta);
var bpe = ta.BYTES_PER_ELEMENT;
var lastValidArgLoadX = (SIZE_BYTES - (lanes == 4 ? 4 : 8)) / bpe | 0;
var lastValidArgLoadX = (SIZE_BYTES - 4) / bpe | 0;
var lastValidArgLoadXY = (SIZE_BYTES - 8) / bpe | 0;
var lastValidArgLoadXYZ = (SIZE_BYTES - 12) / bpe | 0;
var lastValidArgLoad = (SIZE_BYTES - 16) / bpe | 0;
@ -132,30 +121,25 @@ function testLoad(kind, TA) {
C.loadXY(2);
C.loadXY(3);
C.loadXY(lastValidArgLoadXY);
assertThrowsInstanceOf(() => SIMD[kind].loadXY(ta, lastValidArgLoadXY + 1), RangeError);
C.loadXYZ(0);
C.loadXYZ(1);
C.loadXYZ(2);
C.loadXYZ(3);
C.loadXYZ(lastValidArgLoadXYZ);
if (lanes >= 4) {
assertThrowsInstanceOf(() => SIMD[kind].loadXY(ta, lastValidArgLoadXY + 1), RangeError);
assertThrowsInstanceOf(() => SIMD[kind].loadXYZ(ta, lastValidArgLoadXYZ + 1), RangeError);
}
assertThrowsInstanceOf(() => SIMD[kind].loadXYZ(ta, lastValidArgLoadXYZ + 1), RangeError);
}
if (lanes == 4) {
// Test ToInt32 behavior
var v = SIMD[kind].load(TA, 12.5);
assertEqX4(v, [12, 13, 14, 15]);
// Test ToInt32 behavior
var v = SIMD[kind].load(TA, 12.5);
assertEqX4(v, [12, 13, 14, 15]);
var obj = {
valueOf: function() { return 12 }
}
var v = SIMD[kind].load(TA, obj);
assertEqX4(v, [12, 13, 14, 15]);
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"); }
@ -163,9 +147,8 @@ function testLoad(kind, TA) {
assertThrowsInstanceOf(() => SIMD[kind].load(TA, obj), TypeError);
}
testLoad('float32x4', new Float32Array(SIZE_32_ARRAY));
testLoad('float64x2', new Float64Array(SIZE_64_ARRAY));
testLoad('int32x4', new Int32Array(SIZE_32_ARRAY));
testLoad('float32x4', new Float32Array(SIZE_ARRAY));
testLoad('int32x4', new Int32Array(SIZE_ARRAY));
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -1,85 +0,0 @@
// |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();

View File

@ -1,13 +1,3 @@
function assertEqX2(v, arr) {
try {
assertEq(v.x, arr[0]);
assertEq(v.y, arr[1]);
} catch (e) {
print("stack trace:", e.stack);
throw e;
}
}
function assertEqX4(v, arr) {
try {
assertEq(v.x, arr[0]);
@ -20,51 +10,14 @@ function assertEqX4(v, arr) {
}
}
function simdLength(v) {
var pt = Object.getPrototypeOf(v);
if (pt === SIMD.int32x4.prototype || pt === SIMD.float32x4.prototype) {
return 4;
} else if (pt === SIMD.float64x2.prototype) {
return 2;
} else {
throw new TypeError("Unknown SIMD kind.");
}
}
function assertEqVec(v, arr) {
var lanes = simdLength(v);
if (lanes == 4)
assertEqX4(v, arr);
else if (lanes == 2)
assertEqX2(v, arr);
else
throw new TypeError("Unknown SIMD kind.");
}
function simdToArray(v) {
var lanes = simdLength(v);
if (lanes == 4)
return [v.x, v.y, v.z, v.w];
else if (lanes == 2)
return [v.x, v.y];
else
throw new TypeError("Unknown SIMD kind.");
return [v.x, v.y, v.z, v.w];
}
const INT32_MAX = Math.pow(2, 31) - 1;
const INT32_MIN = -Math.pow(2, 31);
assertEq(INT32_MAX + 1 | 0, INT32_MIN);
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);
@ -76,19 +29,6 @@ function testBinaryFunc(v, w, simdFunc, func) {
assertEq(observed[i], expected[i]);
}
function testBinaryCompare(v, w, simdFunc, func) {
var varr = simdToArray(v);
var warr = simdToArray(w);
var inLanes = simdLength(v);
var observed = simdToArray(simdFunc(v, w));
assertEq(observed.length, 4);
for (var i = 0; i < 4; i++) {
var j = ((i * inLanes) / 4) | 0;
assertEq(observed[i], func(varr[j], warr[j]));
}
}
function testBinaryScalarFunc(v, scalar, simdFunc, func) {
var varr = simdToArray(v);

View File

@ -31,19 +31,17 @@ function testStore(ta, kind, i, v) {
SIMD[kind].storeX(ta, i, v);
assertChanged(ta, i, [v.x]);
reset(ta);
SIMD[kind].storeXY(ta, i, v);
assertChanged(ta, i, [v.x, v.y]);
reset(ta);
SIMD[kind].storeXYZ(ta, i, v);
assertChanged(ta, i, [v.x, v.y, v.z]);
reset(ta);
SIMD[kind].store(ta, i, v);
assertChanged(ta, i, simdToArray(v));
if (simdLength(v) > 2) {
reset(ta);
SIMD[kind].storeXY(ta, i, v);
assertChanged(ta, i, [v.x, v.y]);
reset(ta);
SIMD[kind].storeXYZ(ta, i, v);
assertChanged(ta, i, [v.x, v.y, v.z]);
}
assertChanged(ta, i, [v.x, v.y, v.z, v.w]);
}
function testStoreInt32x4() {
@ -80,32 +78,8 @@ function testStoreFloat32x4() {
assertThrowsInstanceOf(() => SIMD.int32x4.store(F32, 0, v), TypeError);
}
function testStoreFloat64x2() {
var F64 = new Float64Array(16);
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);
}
testStoreInt32x4();
testStoreFloat32x4();
testStoreFloat64x2();
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -6,62 +6,28 @@
*/
var float32x4 = SIMD.float32x4;
var float64x2 = SIMD.float64x2;
var int32x4 = SIMD.int32x4;
function swizzle2(arr, x, y) {
return [arr[x], arr[y]];
}
function swizzle4(arr, x, y, z, w) {
function swizzle(arr, x, y, z, w) {
return [arr[x], arr[y], arr[z], arr[w]];
}
function getNumberOfLanesFromType(type) {
switch (type) {
case float32x4:
case int32x4:
return 4;
case float64x2:
return 2;
}
throw new TypeError("Unknown SIMD type.");
}
function testSwizzleForType(type) {
var lanes = getNumberOfLanesFromType(type);
var v = lanes == 4 ? type(1, 2, 3, 4) : type(1, 2);
var v = type(1,2,3,4);
assertThrowsInstanceOf(() => type.swizzle() , TypeError);
assertThrowsInstanceOf(() => type.swizzle(v, 0) , TypeError);
assertThrowsInstanceOf(() => type.swizzle(v, 0, 1) , TypeError);
assertThrowsInstanceOf(() => type.swizzle(v, 0, 1, 2) , TypeError);
assertThrowsInstanceOf(() => type.swizzle(v, 0, 1, 2, 4) , TypeError);
assertThrowsInstanceOf(() => type.swizzle(v, 0, 1, 2, -1) , TypeError);
assertThrowsInstanceOf(() => type.swizzle(0, 1, 2, 3, v) , TypeError);
if (lanes == 2) {
assertThrowsInstanceOf(() => type.swizzle(v, 0, -1) , TypeError);
assertThrowsInstanceOf(() => type.swizzle(v, 0, 2) , TypeError);
} else {
assertEq(lanes, 4);
assertThrowsInstanceOf(() => type.swizzle(v, 0, 1), TypeError);
}
// Test all possible swizzles.
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 {
assertEq(lanes, 2);
var x, y;
for (var i = 0; i < Math.pow(2, 2); i++) {
x = i % 2;
y = i > 1 ? 1 : 0;
assertEqVec(type.swizzle(v, x, y), swizzle2(simdToArray(v), x, y));
}
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];
assertEqX4(type.swizzle(v, x, y, z, w), swizzle(simdToArray(v), x, y, z, w));
}
// Test that the lane inputs are converted into an int32.
@ -70,12 +36,7 @@ function testSwizzleForType(type) {
x: 0,
valueOf: function() { return this.x++ }
};
if (lanes == 4) {
assertEqVec(type.swizzle(v, obj, obj, obj, obj), swizzle4(simdToArray(v), 0, 1, 2, 3));
} else {
assertEq(lanes, 2);
assertEqVec(type.swizzle(v, obj, obj), swizzle2(simdToArray(v), 0, 1));
}
assertEqX4(type.swizzle(v, obj, obj, obj, obj), swizzle(simdToArray(v), 0, 1, 2, 3));
// Object for which ToInt32 will fail.
obj = {
@ -104,21 +65,7 @@ function testSwizzleFloat32x4() {
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) {
function shuffle(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],
@ -126,50 +73,24 @@ function shuffle4(lhsa, rhsa, x, y, z, w) {
}
function testShuffleForType(type) {
var lanes = getNumberOfLanesFromType(type);
var lhs, rhs;
if (lanes == 4) {
lhs = type(1, 2, 3, 4);
rhs = type(5, 6, 7, 8);
} else {
assertEq(lanes, 2);
lhs = type(1, 2);
rhs = type(3, 4);
}
var lhs = type(1,2,3,4);
var rhs = type(5,6,7,8);
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) , TypeError);
assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 1, 2) , TypeError);
assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 1, 2, -1) , TypeError);
assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 1, 2, 8) , TypeError);
assertThrowsInstanceOf(() => type.shuffle(lhs, 0, 1, 2, 7, rhs) , TypeError);
if (lanes == 2) {
assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 4) , TypeError);
assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, -1) , TypeError);
} else {
assertEq(lanes, 4);
assertThrowsInstanceOf(() => type.shuffle(lhs, rhs, 0, 1) , TypeError);
}
// Test all possible shuffles.
var x, y, z, w;
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 {
assertEq(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));
}
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];
assertEqX4(type.shuffle(lhs, rhs, x, y, z, w),
shuffle(simdToArray(lhs), simdToArray(rhs), x, y, z, w));
}
// Test that the lane inputs are converted into an int32.
@ -178,14 +99,8 @@ function testShuffleForType(type) {
x: 0,
valueOf: function() { return this.x++ }
};
if (lanes == 4) {
assertEqVec(type.shuffle(lhs, rhs, obj, obj, obj, obj),
shuffle4(simdToArray(lhs),simdToArray(rhs), 0, 1, 2, 3));
} else {
assertEq(lanes, 2);
assertEqVec(type.shuffle(lhs, rhs, obj, obj),
shuffle2(simdToArray(lhs),simdToArray(rhs), 0, 1));
}
assertEqX4(type.shuffle(lhs, rhs, obj, obj, obj, obj),
shuffle(simdToArray(lhs),simdToArray(rhs), 0, 1, 2, 3));
// Object for which ToInt32 will fail.
obj = {
@ -214,22 +129,10 @@ function testShuffleFloat32x4() {
testShuffleForType(float32x4);
}
function testShuffleFloat64x2() {
var v = float64x2(1, 2);
assertThrowsInstanceOf(function() {
float32x4.shuffle(v, v, 0, 0, 0, 0);
}, TypeError);
testShuffleForType(float64x2);
}
testSwizzleInt32x4();
testSwizzleFloat32x4();
testSwizzleFloat64x2();
testShuffleInt32x4();
testShuffleFloat32x4();
testShuffleFloat64x2();
if (typeof reportCompare === "function")
reportCompare(true, true);