aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--src/jsifier.js3
-rw-r--r--src/library.js68
-rw-r--r--src/parseTools.js29
-rw-r--r--src/simd.js1031
-rw-r--r--system/include/emscripten/emmintrin.h87
-rw-r--r--system/include/emscripten/vector.h20
-rw-r--r--system/include/emscripten/xmmintrin.h131
-rw-r--r--tests/test_core.py496
9 files changed, 1406 insertions, 460 deletions
diff --git a/AUTHORS b/AUTHORS
index 2b2b21ed..b03bfe7b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -110,3 +110,4 @@ a license to everyone to use it as detailed in LICENSE.)
* John Vilk <jvilk@cs.umass.edu>
* Daniel Baulig <dbaulig@fb.com> (copyright owned by Facebook, Inc.)
* Lu Wang <coolwanglu@gmail.com>
+* Heidi Pan <heidi.pan@intel.com> (copyright owned by Intel)
diff --git a/src/jsifier.js b/src/jsifier.js
index cb753e57..fb6c5ba8 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1373,8 +1373,9 @@ function JSify(data, functionsOnly, givenFunctions) {
function insertelementHandler(item) {
var base = getVectorBaseType(item.type);
var ident = ensureVector(item.ident, base);
+ var laneOp = ((base == 'float') ? 'SIMD.float32x4.with' : 'SIMD.int32x4.with');
//return ident + '.with' + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + finalizeLLVMParameter(item.value) + ')';
- return 'SIMD.with' + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + ident + ',' + finalizeLLVMParameter(item.value) + ')';
+ return laneOp + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + ident + ',' + finalizeLLVMParameter(item.value) + ')';
}
function extractelementHandler(item) {
var base = getVectorBaseType(item.type);
diff --git a/src/library.js b/src/library.js
index 128bb211..faca945c 100644
--- a/src/library.js
+++ b/src/library.js
@@ -8736,8 +8736,72 @@ LibraryManager.library = {
// emscripten vector ops
//============================
- emscripten_float32x4_signmask__inline: function(x) {
- return x + '.signMask()';
+ emscripten_float32x4_signmask__inline: function(a) {
+ return 'SIMD.float32x4.bitsToInt32x4(' + a + ').signMask';
+ },
+
+ emscripten_float32x4_min__inline: function(a, b) {
+ return 'SIMD.float32x4.min(' + a + ', ' + b + ')';
+ },
+
+ emscripten_float32x4_max__inline: function(a, b) {
+ return 'SIMD.float32x4.max(' + a + ', ' + b + ')';
+ },
+
+ emscripten_float32x4_sqrt__inline: function(a) {
+ return 'SIMD.float32x4.sqrt(' + a + ')';
+ },
+
+ emscripten_float32x4_lessThan__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThan(' + a + ', ' + b + '))';
+ },
+
+ emscripten_float32x4_lessThanOrEqual__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThanOrEqual(' + a + ', ' + b + '))';
+ },
+
+ emscripten_float32x4_equal__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.equal(' + a + ', ' + b + '))';
+ },
+
+ emscripten_float32x4_greaterThanOrEqual__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.greaterThanOrEqual(' + a + ', ' + b + '))';
+ },
+
+ emscripten_float32x4_greaterThan__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.greaterThan(' + a + ', ' + b + '))';
+ },
+
+ emscripten_float32x4_and__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
+ },
+
+ emscripten_float32x4_andNot__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.int32x4.not(SIMD.float32x4.bitsToInt32x4(' + a + ')), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
+ },
+
+ emscripten_float32x4_or__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.or(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
+ },
+
+ emscripten_float32x4_xor__inline: function(a, b) {
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.xor(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
+ },
+
+ emscripten_int32x4_bitsToFloat32x4__inline: function(a) {
+ return 'SIMD.int32x4.bitsToFloat32x4(' + a + ')';
+ },
+
+ emscripten_int32x4_toFloat32x4__inline: function(a) {
+ return 'SIMD.int32x4.toFloat32x4(' + a + ')';
+ },
+
+ emscripten_float32x4_bitsToInt32x4__inline: function(a) {
+ return 'SIMD.float32x4.bitsToInt32x4(' + a + ')';
+ },
+
+ emscripten_float32x4_toInt32x4__inline: function(a) {
+ return 'SIMD.float32x4.toInt32x4(' + a + ')';
},
//============================
diff --git a/src/parseTools.js b/src/parseTools.js
index 134cb89a..ffd7c758 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -362,7 +362,7 @@ function getVectorNativeType(type) {
function getSIMDName(type) {
switch (type) {
- case 'i32': return 'uint';
+ case 'i32': return 'int';
case 'float': return 'float';
default: throw 'getSIMDName ' + type;
}
@@ -2372,29 +2372,28 @@ function processMathop(item) {
// vector/SIMD operation
Types.usesSIMD = true;
switch (op) {
- case 'fadd': return 'SIMD.add(' + idents[0] + ',' + idents[1] + ')';
- case 'fsub': return 'SIMD.sub(' + idents[0] + ',' + idents[1] + ')';
- case 'fmul': return 'SIMD.mul(' + idents[0] + ',' + idents[1] + ')';
- case 'fdiv': return 'SIMD.div(' + idents[0] + ',' + idents[1] + ')';
- case 'add' : return 'SIMD.addu32(' + idents[0] + ',' + idents[1] + ')';
- case 'sub' : return 'SIMD.subu32(' + idents[0] + ',' + idents[1] + ')';
- case 'mul' : return 'SIMD.mulu32(' + idents[0] + ',' + idents[1] + ')';
- case 'udiv': return 'SIMD.divu32(' + idents[0] + ',' + idents[1] + ')';
+ case 'fadd': return 'SIMD.float32x4.add(' + idents[0] + ',' + idents[1] + ')';
+ case 'fsub': return 'SIMD.float32x4.sub(' + idents[0] + ',' + idents[1] + ')';
+ case 'fmul': return 'SIMD.float32x4.mul(' + idents[0] + ',' + idents[1] + ')';
+ case 'fdiv': return 'SIMD.float32x4.div(' + idents[0] + ',' + idents[1] + ')';
+ case 'add' : return 'SIMD.int32x4.add(' + idents[0] + ',' + idents[1] + ')';
+ case 'sub' : return 'SIMD.int32x4.sub(' + idents[0] + ',' + idents[1] + ')';
+ case 'mul' : return 'SIMD.int32x4.mul(' + idents[0] + ',' + idents[1] + ')';
case 'bitcast': {
var inType = item.params[0].type;
var outType = item.type;
if (inType === '<4 x float>') {
assert(outType === '<4 x i32>');
- return 'SIMD.float32x4BitsToUint32x4(' + idents[0] + ')';
+ return 'SIMD.float32x4.bitsToInt32x4(' + idents[0] + ')';
} else {
assert(inType === '<4 x i32>');
assert(outType === '<4 x float>');
- return 'SIMD.uint32x4BitsToFloat32x4(' + idents[0] + ')';
+ return 'SIMD.int32x4.bitsToFloat32x4(' + idents[0] + ')';
}
}
- case 'and': return 'SIMD.and(' + idents[0] + ',' + idents[1] + ')';
- case 'or': return 'SIMD.or(' + idents[0] + ',' + idents[1] + ')';
- case 'xor': return 'SIMD.xor(' + idents[0] + ',' + idents[1] + ')';
+ case 'and': return 'SIMD.int32x4.and(' + idents[0] + ',' + idents[1] + ')';
+ case 'or': return 'SIMD.int32x4.or(' + idents[0] + ',' + idents[1] + ')';
+ case 'xor': return 'SIMD.int32x4.xor(' + idents[0] + ',' + idents[1] + ')';
default: throw 'vector op todo: ' + dump(item);
}
}
@@ -2698,7 +2697,7 @@ var simdLane = ['x', 'y', 'z', 'w'];
function ensureVector(ident, base) {
Types.usesSIMD = true;
- return ident == 0 ? base + '32x4.zero()' : ident;
+ return ident == 0 ? base + '32x4.splat(0)' : ident;
}
function ensureValidFFIType(type) {
diff --git a/src/simd.js b/src/simd.js
index bbb12d0a..c7f5ff48 100644
--- a/src/simd.js
+++ b/src/simd.js
@@ -20,8 +20,10 @@
https://github.com/johnmccutchan/ecmascript_simd/blob/master/src/ecmascript_simd.js
*/
+"use strict";
+
/**
- * Construct a new instance of a float32x4 number.
+ * Construct a new instance of float32x4 number.
* @param {double} value used for x lane.
* @param {double} value used for y lane.
* @param {double} value used for z lane.
@@ -40,7 +42,7 @@ function float32x4(x, y, z, w) {
}
/**
- * Construct a new instance of a float32x4 number with 0.0 in all lanes.
+ * Construct a new instance of float32x4 number with 0.0 in all lanes.
* @constructor
*/
float32x4.zero = function() {
@@ -48,7 +50,7 @@ float32x4.zero = function() {
}
/**
- * Construct a new instance of a float32x4 number with the same value
+ * Construct a new instance of float32x4 number with the same value
* in all lanes.
* @param {double} value used for all lanes.
* @constructor
@@ -87,18 +89,18 @@ Object.defineProperty(float32x4.prototype, 'signMask', {
});
/**
- * Construct a new instance of a uint32x4 number.
+ * Construct a new instance of int32x4 number.
* @param {integer} 32-bit unsigned value used for x lane.
* @param {integer} 32-bit unsigned value used for y lane.
* @param {integer} 32-bit unsigned value used for z lane.
* @param {integer} 32-bit unsigned value used for w lane.
* @constructor
*/
-function uint32x4(x, y, z, w) {
- if (!(this instanceof uint32x4)) {
- return new uint32x4(x, y, z, w);
+function int32x4(x, y, z, w) {
+ if (!(this instanceof int32x4)) {
+ return new int32x4(x, y, z, w);
}
- this.storage_ = new Uint32Array(4);
+ this.storage_ = new Int32Array(4);
this.storage_[0] = x;
this.storage_[1] = y;
this.storage_[2] = z;
@@ -106,7 +108,7 @@ function uint32x4(x, y, z, w) {
}
/**
- * Construct a new instance of a uint32x4 number with 0xFFFFFFFF or 0x0 in each
+ * Construct a new instance of int32x4 number with 0xFFFFFFFF or 0x0 in each
* lane, depending on the truth value in x, y, z, and w.
* @param {boolean} flag used for x lane.
* @param {boolean} flag used for y lane.
@@ -114,59 +116,59 @@ function uint32x4(x, y, z, w) {
* @param {boolean} flag used for w lane.
* @constructor
*/
-uint32x4.bool = function(x, y, z, w) {
- return uint32x4(x ? 0xFFFFFFFF : 0x0,
- y ? 0xFFFFFFFF : 0x0,
- z ? 0xFFFFFFFF : 0x0,
- w ? 0xFFFFFFFF : 0x0);
+int32x4.bool = function(x, y, z, w) {
+ return int32x4(x ? -1 : 0x0,
+ y ? -1 : 0x0,
+ z ? -1 : 0x0,
+ w ? -1 : 0x0);
}
/**
- * Construct a new instance of a uint32x4 number with the same value
+ * Construct a new instance of int32x4 number with the same value
* in all lanes.
* @param {integer} value used for all lanes.
* @constructor
*/
-uint32x4.splat = function(s) {
- return uint32x4(s, s, s, s);
+int32x4.splat = function(s) {
+ return int32x4(s, s, s, s);
}
-Object.defineProperty(uint32x4.prototype, 'x', {
+Object.defineProperty(int32x4.prototype, 'x', {
get: function() { return this.storage_[0]; }
});
-Object.defineProperty(uint32x4.prototype, 'y', {
+Object.defineProperty(int32x4.prototype, 'y', {
get: function() { return this.storage_[1]; }
});
-Object.defineProperty(uint32x4.prototype, 'z', {
+Object.defineProperty(int32x4.prototype, 'z', {
get: function() { return this.storage_[2]; }
});
-Object.defineProperty(uint32x4.prototype, 'w',
+Object.defineProperty(int32x4.prototype, 'w',
{ get: function() { return this.storage_[3]; }
});
-Object.defineProperty(uint32x4.prototype, 'flagX', {
+Object.defineProperty(int32x4.prototype, 'flagX', {
get: function() { return this.storage_[0] != 0x0; }
});
-Object.defineProperty(uint32x4.prototype, 'flagY', {
+Object.defineProperty(int32x4.prototype, 'flagY', {
get: function() { return this.storage_[1] != 0x0; }
});
-Object.defineProperty(uint32x4.prototype, 'flagZ', {
+Object.defineProperty(int32x4.prototype, 'flagZ', {
get: function() { return this.storage_[2] != 0x0; }
});
-Object.defineProperty(uint32x4.prototype, 'flagW',
+Object.defineProperty(int32x4.prototype, 'flagW',
{ get: function() { return this.storage_[3] != 0x0; }
});
/**
* Extract the sign bit from each lane return them in the first 4 bits.
*/
-Object.defineProperty(uint32x4.prototype, 'signMask', {
+Object.defineProperty(int32x4.prototype, 'signMask', {
get: function() {
var mx = (this.storage_[0] & 0x80000000) >>> 31;
var my = (this.storage_[1] & 0x80000000) >>> 31;
@@ -287,414 +289,580 @@ Float32x4Array.prototype.setAt = function(i, v) {
this.storage_[i*4+3] = v.w;
}
+
+function Int32x4Array(a, b, c) {
+
+ function isNumber(o) {
+ return typeof o == "number" || (typeof o == "object" && o.constructor === Number);
+ }
+
+ function isTypedArray(o) {
+ return (o instanceof Int8Array) ||
+ (o instanceof Uint8Array) ||
+ (o instanceof Uint8ClampedArray) ||
+ (o instanceof Int16Array) ||
+ (o instanceof Uint16Array) ||
+ (o instanceof Int32Array) ||
+ (o instanceof Uint32Array) ||
+ (o instanceof Float32Array) ||
+ (o instanceof Float64Array) ||
+ (o instanceof Int32x4Array) ||
+ (o instanceof Float32x4Array);
+ }
+
+ function isArrayBuffer(o) {
+ return (o instanceof ArrayBuffer);
+ }
+
+ if (isNumber(a)) {
+ this.storage_ = new Int32Array(a*4);
+ this.length_ = a;
+ this.byteOffset_ = 0;
+ return;
+ } else if (isTypedArray(a)) {
+ if (!(a instanceof Int32x4Array)) {
+ throw "Copying typed array of non-Int32x4Array is unimplemented.";
+ }
+ this.storage_ = new Int32Array(a.length * 4);
+ this.length_ = a.length;
+ this.byteOffset_ = 0;
+ // Copy floats.
+ for (var i = 0; i < a.length*4; i++) {
+ this.storage_[i] = a.storage_[i];
+ }
+ } else if (isArrayBuffer(a)) {
+ if ((b != undefined) && (b % Int32x4Array.BYTES_PER_ELEMENT) != 0) {
+ throw "byteOffset must be a multiple of 16.";
+ }
+ if (c != undefined) {
+ c *= 4;
+ this.storage_ = new Int32Array(a, b, c);
+ }
+ else {
+ // Note: new Int32Array(a, b) is NOT equivalent to new Float32Array(a, b, undefined)
+ this.storage_ = new Int32Array(a, b);
+ }
+ this.length_ = this.storage_.length / 4;
+ this.byteOffset_ = b != undefined ? b : 0;
+ } else {
+ throw "Unknown type of first argument.";
+ }
+}
+
+Object.defineProperty(Int32x4Array.prototype, 'length',
+ { get: function() { return this.length_; }
+});
+
+Object.defineProperty(Int32x4Array.prototype, 'byteLength',
+ { get: function() { return this.length_ * Int32x4Array.BYTES_PER_ELEMENT; }
+});
+
+Object.defineProperty(Int32x4Array, 'BYTES_PER_ELEMENT',
+ { get: function() { return 16; }
+});
+
+Object.defineProperty(Int32x4Array.prototype, 'BYTES_PER_ELEMENT',
+ { get: function() { return 16; }
+});
+
+Object.defineProperty(Int32x4Array.prototype, 'byteOffset',
+ { get: function() { return this.byteOffset_; }
+});
+
+Object.defineProperty(Int32x4Array.prototype, 'buffer',
+ { get: function() { return this.storage_.buffer; }
+});
+
+Int32x4Array.prototype.getAt = function(i) {
+ if (i < 0) {
+ throw "Index must be >= 0.";
+ }
+ if (i >= this.length) {
+ throw "Index out of bounds.";
+ }
+ var x = this.storage_[i*4+0];
+ var y = this.storage_[i*4+1];
+ var z = this.storage_[i*4+2];
+ var w = this.storage_[i*4+3];
+ return float32x4(x, y, z, w);
+}
+
+Int32x4Array.prototype.setAt = function(i, v) {
+ if (i < 0) {
+ throw "Index must be >= 0.";
+ }
+ if (i >= this.length) {
+ throw "Index out of bounds.";
+ }
+ if (!(v instanceof int32x4)) {
+ throw "Value is not a int32x4.";
+ }
+ this.storage_[i*4+0] = v.x;
+ this.storage_[i*4+1] = v.y;
+ this.storage_[i*4+2] = v.z;
+ this.storage_[i*4+3] = v.w;
+}
+
var SIMD = (function () {
return {
- /**
- * @return {float32x4} New instance of float32x4 with absolute values of
- * t.
- */
- abs: function(t) {
- return new float32x4(Math.abs(t.x), Math.abs(t.y), Math.abs(t.z),
- Math.abs(t.w));
- },
- /**
- * @return {float32x4} New instance of float32x4 with negated values of
- * t.
- */
- neg: function(t) {
- return new float32x4(-t.x, -t.y, -t.z, -t.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with a + b.
- */
- add: function(a, b) {
- return new float32x4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with a - b.
- */
- sub: function(a, b) {
- return new float32x4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with a * b.
- */
- mul: function(a, b) {
- return new float32x4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with a / b.
- */
- div: function(a, b) {
- return new float32x4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with t's values clamped
- * between lowerLimit and upperLimit.
- */
- clamp: function(t, lowerLimit, upperLimit) {
- var cx = t.x < lowerLimit.x ? lowerLimit.x : t.x;
- var cy = t.y < lowerLimit.y ? lowerLimit.y : t.y;
- var cz = t.z < lowerLimit.z ? lowerLimit.z : t.z;
- var cw = t.w < lowerLimit.w ? lowerLimit.w : t.w;
- cx = cx > upperLimit.x ? upperLimit.x : cx;
- cy = cy > upperLimit.y ? upperLimit.y : cy;
- cz = cz > upperLimit.z ? upperLimit.z : cz;
- cw = cw > upperLimit.w ? upperLimit.w : cw;
- return new float32x4(cx, cy, cz, cw);
- },
- /**
- * @return {float32x4} New instance of float32x4 with the minimum value of
- * t and other.
- */
- min: function(t, other) {
- var cx = t.x > other.x ? other.x : t.x;
- var cy = t.y > other.y ? other.y : t.y;
- var cz = t.z > other.z ? other.z : t.z;
- var cw = t.w > other.w ? other.w : t.w;
- return new float32x4(cx, cy, cz, cw);
- },
- /**
- * @return {float32x4} New instance of float32x4 with the maximum value of
- * t and other.
- */
- max: function(t, other) {
- var cx = t.x < other.x ? other.x : t.x;
- var cy = t.y < other.y ? other.y : t.y;
- var cz = t.z < other.z ? other.z : t.z;
- var cw = t.w < other.w ? other.w : t.w;
- return new float32x4(cx, cy, cz, cw);
- },
- /**
- * @return {float32x4} New instance of float32x4 with reciprocal value of
- * t.
- */
- reciprocal: function(t) {
- return new float32x4(1.0 / t.x, 1.0 / t.y, 1.0 / t.z, 1.0 / t.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with square root of the
- * reciprocal value of t.
- */
- reciprocalSqrt: function(t) {
- return new float32x4(Math.sqrt(1.0 / t.x), Math.sqrt(1.0 / t.y),
- Math.sqrt(1.0 / t.z), Math.sqrt(1.0 / t.w));
- },
- /**
- * @return {float32x4} New instance of float32x4 with values of t
- * scaled by s.
- */
- scale: function(t, s) {
- return new float32x4(s * t.x, s * t.y, s * t.z, s * t.w);
- },
- /**
- * @return {float32x4} New instance of float32x4 with square root of
- * values of t.
- */
- sqrt: function(t) {
- return new float32x4(Math.sqrt(t.x), Math.sqrt(t.y),
- Math.sqrt(t.z), Math.sqrt(t.w));
- },
- /**
- * @param {float32x4} t An instance of float32x4 to be shuffled.
- * @param {integer} mask One of the 256 shuffle masks, for example, SIMD.XXXX.
- * @return {float32x4} New instance of float32x4 with lanes shuffled.
- */
- shuffle: function(t, mask) {
- var _x = (mask) & 0x3;
- var _y = (mask >> 2) & 0x3;
- var _z = (mask >> 4) & 0x3;
- var _w = (mask >> 6) & 0x3;
- return new float32x4(t.storage_[_x], t.storage_[_y], t.storage_[_z],
- t.storage_[_w]);
+ float32x4: {
+ /**
+ * @return {float32x4} New instance of float32x4 with absolute values of
+ * t.
+ */
+ abs: function(t) {
+ return new float32x4(Math.abs(t.x), Math.abs(t.y), Math.abs(t.z),
+ Math.abs(t.w));
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with negated values of
+ * t.
+ */
+ neg: function(t) {
+ return new float32x4(-t.x, -t.y, -t.z, -t.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with a + b.
+ */
+ add: function(a, b) {
+ return new float32x4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with a - b.
+ */
+ sub: function(a, b) {
+ return new float32x4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with a * b.
+ */
+ mul: function(a, b) {
+ return new float32x4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with a / b.
+ */
+ div: function(a, b) {
+ return new float32x4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with t's values clamped
+ * between lowerLimit and upperLimit.
+ */
+ clamp: function(t, lowerLimit, upperLimit) {
+ var cx = t.x < lowerLimit.x ? lowerLimit.x : t.x;
+ var cy = t.y < lowerLimit.y ? lowerLimit.y : t.y;
+ var cz = t.z < lowerLimit.z ? lowerLimit.z : t.z;
+ var cw = t.w < lowerLimit.w ? lowerLimit.w : t.w;
+ cx = cx > upperLimit.x ? upperLimit.x : cx;
+ cy = cy > upperLimit.y ? upperLimit.y : cy;
+ cz = cz > upperLimit.z ? upperLimit.z : cz;
+ cw = cw > upperLimit.w ? upperLimit.w : cw;
+ return new float32x4(cx, cy, cz, cw);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with the minimum value of
+ * t and other.
+ */
+ min: function(t, other) {
+ var cx = t.x > other.x ? other.x : t.x;
+ var cy = t.y > other.y ? other.y : t.y;
+ var cz = t.z > other.z ? other.z : t.z;
+ var cw = t.w > other.w ? other.w : t.w;
+ return new float32x4(cx, cy, cz, cw);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with the maximum value of
+ * t and other.
+ */
+ max: function(t, other) {
+ var cx = t.x < other.x ? other.x : t.x;
+ var cy = t.y < other.y ? other.y : t.y;
+ var cz = t.z < other.z ? other.z : t.z;
+ var cw = t.w < other.w ? other.w : t.w;
+ return new float32x4(cx, cy, cz, cw);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with reciprocal value of
+ * t.
+ */
+ reciprocal: function(t) {
+ return new float32x4(1.0 / t.x, 1.0 / t.y, 1.0 / t.z, 1.0 / t.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with square root of the
+ * reciprocal value of t.
+ */
+ reciprocalSqrt: function(t) {
+ return new float32x4(Math.sqrt(1.0 / t.x), Math.sqrt(1.0 / t.y),
+ Math.sqrt(1.0 / t.z), Math.sqrt(1.0 / t.w));
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with values of t
+ * scaled by s.
+ */
+ scale: function(t, s) {
+ return new float32x4(s * t.x, s * t.y, s * t.z, s * t.w);
+ },
+ /**
+ * @return {float32x4} New instance of float32x4 with square root of
+ * values of t.
+ */
+ sqrt: function(t) {
+ return new float32x4(Math.sqrt(t.x), Math.sqrt(t.y),
+ Math.sqrt(t.z), Math.sqrt(t.w));
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4 to be shuffled.
+ * @param {integer} mask One of the 256 shuffle masks, for example, SIMD.XXXX.
+ * @return {float32x4} New instance of float32x4 with lanes shuffled.
+ */
+ shuffle: function(t, mask) {
+ var _x = (mask) & 0x3;
+ var _y = (mask >> 2) & 0x3;
+ var _z = (mask >> 4) & 0x3;
+ var _w = (mask >> 6) & 0x3;
+ return new float32x4(t.storage_[_x], t.storage_[_y], t.storage_[_z],
+ t.storage_[_w]);
+ },
+ /**
+ * @param {float32x4} t1 An instance of float32x4 to be shuffled. XY lanes in result
+ * @param {float32x4} t2 An instance of float32x4 to be shuffled. ZW lanes in result
+ * @param {integer} mask One of the 256 shuffle masks, for example, SIMD.XXXX.
+ * @return {float32x4} New instance of float32x4 with lanes shuffled.
+ */
+ shuffleMix: function(t1, t2, mask) {
+ var _x = (mask) & 0x3;
+ var _y = (mask >> 2) & 0x3;
+ var _z = (mask >> 4) & 0x3;
+ var _w = (mask >> 6) & 0x3;
+ return new float32x4(t1.storage_[_x], t1.storage_[_y], t2.storage_[_z],
+ t2.storage_[_w]);
+ },
+ /**
+ * @param {double} value used for x lane.
+ * @return {float32x4} New instance of float32x4 with the values in t and
+ * x replaced with {x}.
+ */
+ withX: function(t, x) {
+ return new float32x4(x, t.y, t.z, t.w);
+ },
+ /**
+ * @param {double} value used for y lane.
+ * @return {float32x4} New instance of float32x4 with the values in t and
+ * y replaced with {y}.
+ */
+ withY: function(t, y) {
+ return new float32x4(t.x, y, t.z, t.w);
+ },
+ /**
+ * @param {double} value used for z lane.
+ * @return {float32x4} New instance of float32x4 with the values in t and
+ * z replaced with {z}.
+ */
+ withZ: function(t, z) {
+ return new float32x4(t.x, t.y, z, t.w);
+ },
+ /**
+ * @param {double} value used for w lane.
+ * @return {float32x4} New instance of float32x4 with the values in t and
+ * w replaced with {w}.
+ */
+ withW: function(t, w) {
+ return new float32x4(t.x, t.y, t.z, w);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @param {float32x4} other An instance of float32x4.
+ * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
+ * the result of t < other.
+ */
+ lessThan: function(t, other) {
+ var cx = t.x < other.x;
+ var cy = t.y < other.y;
+ var cz = t.z < other.z;
+ var cw = t.w < other.w;
+ return int32x4.bool(cx, cy, cz, cw);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @param {float32x4} other An instance of float32x4.
+ * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
+ * the result of t <= other.
+ */
+ lessThanOrEqual: function(t, other) {
+ var cx = t.x <= other.x;
+ var cy = t.y <= other.y;
+ var cz = t.z <= other.z;
+ var cw = t.w <= other.w;
+ return int32x4.bool(cx, cy, cz, cw);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @param {float32x4} other An instance of float32x4.
+ * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
+ * the result of t == other.
+ */
+ equal: function(t, other) {
+ var cx = t.x == other.x;
+ var cy = t.y == other.y;
+ var cz = t.z == other.z;
+ var cw = t.w == other.w;
+ return int32x4.bool(cx, cy, cz, cw);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @param {float32x4} other An instance of float32x4.
+ * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
+ * the result of t != other.
+ */
+ notEqual: function(t, other) {
+ var cx = t.x != other.x;
+ var cy = t.y != other.y;
+ var cz = t.z != other.z;
+ var cw = t.w != other.w;
+ return int32x4.bool(cx, cy, cz, cw);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @param {float32x4} other An instance of float32x4.
+ * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
+ * the result of t >= other.
+ */
+ greaterThanOrEqual: function(t, other) {
+ var cx = t.x >= other.x;
+ var cy = t.y >= other.y;
+ var cz = t.z >= other.z;
+ var cw = t.w >= other.w;
+ return int32x4.bool(cx, cy, cz, cw);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @param {float32x4} other An instance of float32x4.
+ * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
+ * the result of t > other.
+ */
+ greaterThan: function(t, other) {
+ var cx = t.x > other.x;
+ var cy = t.y > other.y;
+ var cz = t.z > other.z;
+ var cw = t.w > other.w;
+ return int32x4.bool(cx, cy, cz, cw);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @return {int32x4} a bit-wise copy of t as a int32x4.
+ */
+ bitsToInt32x4: function(t) {
+ var alias = new Int32Array(t.storage_.buffer);
+ return new int32x4(alias[0], alias[1], alias[2], alias[3]);
+ },
+ /**
+ * @param {float32x4} t An instance of float32x4.
+ * @return {int32x4} with a integer to float conversion of t.
+ */
+ toInt32x4: function(t) {
+ var a = new int32x4(t.storage_[0], t.storage_[1], t.storage_[2],
+ t.storage_[3]);
+ return a;
+ }
},
- /**
- * @param {double} value used for x lane.
- * @return {float32x4} New instance of float32x4 with the values in t and
- * x replaced with {x}.
- */
- withX: function(t, x) {
- return new float32x4(x, t.y, t.z, t.w);
- },
- /**
- * @param {double} value used for y lane.
- * @return {float32x4} New instance of float32x4 with the values in t and
- * y replaced with {y}.
- */
- withY: function(t, y) {
- return new float32x4(t.x, y, t.z, t.w);
- },
- /**
- * @param {double} value used for z lane.
- * @return {float32x4} New instance of float32x4 with the values in t and
- * z replaced with {z}.
- */
- withZ: function(t, z) {
- return new float32x4(t.x, t.y, z, t.w);
- },
- /**
- * @param {double} value used for w lane.
- * @return {float32x4} New instance of float32x4 with the values in t and
- * w replaced with {w}.
- */
- withW: function(t, w) {
- return new float32x4(t.x, t.y, t.z, w);
- },
- /**
- * @param {float32x4} t An instance of a float32x4.
- * @param {float32x4} other An instance of a float32x4.
- * @return {uint32x4} 0xFFFFFFFF or 0x0 in each lane depending on
- * the result of t < other.
- */
- lessThan: function(t, other) {
- var cx = t.x < other.x;
- var cy = t.y < other.y;
- var cz = t.z < other.z;
- var cw = t.w < other.w;
- return uint32x4.bool(cx, cy, cz, cw);
- },
- /**
- * @param {float32x4} t An instance of a float32x4.
- * @param {float32x4} other An instance of a float32x4.
- * @return {uint32x4} 0xFFFFFFFF or 0x0 in each lane depending on
- * the result of t <= other.
- */
- lessThanOrEqual: function(t, other) {
- var cx = t.x <= other.x;
- var cy = t.y <= other.y;
- var cz = t.z <= other.z;
- var cw = t.w <= other.w;
- return uint32x4.bool(cx, cy, cz, cw);
- },
- /**
- * @param {float32x4} t An instance of a float32x4.
- * @param {float32x4} other An instance of a float32x4.
- * @return {uint32x4} 0xFFFFFFFF or 0x0 in each lane depending on
- * the result of t == other.
- */
- equal: function(t, other) {
- var cx = t.x == other.x;
- var cy = t.y == other.y;
- var cz = t.z == other.z;
- var cw = t.w == other.w;
- return uint32x4.bool(cx, cy, cz, cw);
- },
- /**
- * @param {float32x4} t An instance of a float32x4.
- * @param {float32x4} other An instance of a float32x4.
- * @return {uint32x4} 0xFFFFFFFF or 0x0 in each lane depending on
- * the result of t != other.
- */
- notEqual: function(t, other) {
- var cx = t.x != other.x;
- var cy = t.y != other.y;
- var cz = t.z != other.z;
- var cw = t.w != other.w;
- return uint32x4.bool(cx, cy, cz, cw);
- },
- /**
- * @param {float32x4} t An instance of a float32x4.
- * @param {float32x4} other An instance of a float32x4.
- * @return {uint32x4} 0xFFFFFFFF or 0x0 in each lane depending on
- * the result of t >= other.
- */
- greaterThanOrEqual: function(t, other) {
- var cx = t.x >= other.x;
- var cy = t.y >= other.y;
- var cz = t.z >= other.z;
- var cw = t.w >= other.w;
- return uint32x4.bool(cx, cy, cz, cw);
- },
- /**
- * @param {float32x4} t An instance of a float32x4.
- * @param {float32x4} other An instance of a float32x4.
- * @return {uint32x4} 0xFFFFFFFF or 0x0 in each lane depending on
- * the result of t > other.
- */
- greaterThan: function(t, other) {
- var cx = t.x > other.x;
- var cy = t.y > other.y;
- var cz = t.z > other.z;
- var cw = t.w > other.w;
- return uint32x4.bool(cx, cy, cz, cw);
- },
- /**
- * @param {uint32x4} a An instance of a uint32x4.
- * @param {uint32x4} b An instance of a uint32x4.
- * @return {uint32x4} New instance of uint32x4 with values of a & b.
- */
- and: function(a, b) {
- return new uint32x4(a.x & b.x, a.y & b.y, a.z & b.z, a.w & b.w);
- },
- /**
- * @param {uint32x4} a An instance of a uint32x4.
- * @param {uint32x4} b An instance of a uint32x4.
- * @return {uint32x4} New instance of uint32x4 with values of a | b.
- */
- or: function(a, b) {
- return new uint32x4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w);
- },
- /**
- * @param {uint32x4} a An instance of a uint32x4.
- * @param {uint32x4} b An instance of a uint32x4.
- * @return {uint32x4} New instance of uint32x4 with values of a ^ b.
- */
- xor: function(a, b) {
- return new uint32x4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
- },
- /**
- * @param