UNPKG

simd

Version:
1,316 lines (1,216 loc) 219 kB
/* vim: set ts=8 sts=2 et sw=2 tw=79: Copyright (C) 2013 This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ // A conforming SIMD.js implementation may contain the following deviations to // normal JS numeric behavior: // - Subnormal numbers may or may not be flushed to zero on input or output of // any SIMD operation. // Many of the operations in SIMD.js have semantics which correspond to scalar // operations in JS, however there are a few differences: // - Vector shifts don't mask the shift count. // - Conversions from float to int32 throw on error. // - Load and store operations throw when out of bounds. module.exports = function (global) { if (typeof global.SIMD === "undefined") { // SIMD module. global.SIMD = {}; } if (typeof module !== "undefined") { // For CommonJS modules } var SIMD = global.SIMD; // private stuff. // Temporary buffers for swizzles and bitcasts. var _f32x4 = new Float32Array(4); var _f64x2 = new Float64Array(_f32x4.buffer); var _i32x4 = new Int32Array(_f32x4.buffer); var _i16x8 = new Int16Array(_f32x4.buffer); var _i8x16 = new Int8Array(_f32x4.buffer); var _f32; var truncatef32; if (typeof Math.fround !== 'undefined') { truncatef32 = Math.fround; } else { _f32 = new Float32Array(1); truncatef32 = function(x) { _f32[0] = x; return _f32[0]; } } // Type checking functions. function isInt32(o) { return (o | 0) === o; } 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); } function minNum(x, y) { return x != x ? y : y != y ? x : Math.min(x, y); } function maxNum(x, y) { return x != x ? y : y != y ? x : Math.max(x, y); } function int32FromFloat(x) { if (x > -2147483649.0 && x < 2147483648.0) return x|0; throw new RangeError("Conversion from floating-point to integer failed"); } function checkLaneIndex(numLanes) { return function(lane) { if (!isInt32(lane)) throw new TypeError('lane index must be an int32'); if (lane < 0 || lane >= numLanes) throw new RangeError('lane index must be in bounds'); } } var check2 = checkLaneIndex(2); var check4 = checkLaneIndex(4); var check8 = checkLaneIndex(8); var check16 = checkLaneIndex(16); var check32 = checkLaneIndex(32); // Save/Restore utilities for implementing bitwise conversions. function saveBool32x4(x) { x = SIMD.Bool32x4.check(x); _i32x4[0] = SIMD.Bool32x4.extractLane(x, 0); _i32x4[1] = SIMD.Bool32x4.extractLane(x, 1); _i32x4[2] = SIMD.Bool32x4.extractLane(x, 2); _i32x4[3] = SIMD.Bool32x4.extractLane(x, 3); } function saveBool16x8(x) { x = SIMD.Bool16x8.check(x); _i16x8[0] = SIMD.Bool16x8.extractLane(x, 0); _i16x8[1] = SIMD.Bool16x8.extractLane(x, 1); _i16x8[2] = SIMD.Bool16x8.extractLane(x, 2); _i16x8[3] = SIMD.Bool16x8.extractLane(x, 3); _i16x8[4] = SIMD.Bool16x8.extractLane(x, 4); _i16x8[5] = SIMD.Bool16x8.extractLane(x, 5); _i16x8[6] = SIMD.Bool16x8.extractLane(x, 6); _i16x8[7] = SIMD.Bool16x8.extractLane(x, 7); } function saveBool8x16(x) { x = SIMD.Bool8x16.check(x); _i8x16[0] = SIMD.Bool8x16.extractLane(x, 0); _i8x16[1] = SIMD.Bool8x16.extractLane(x, 1); _i8x16[2] = SIMD.Bool8x16.extractLane(x, 2); _i8x16[3] = SIMD.Bool8x16.extractLane(x, 3); _i8x16[4] = SIMD.Bool8x16.extractLane(x, 4); _i8x16[5] = SIMD.Bool8x16.extractLane(x, 5); _i8x16[6] = SIMD.Bool8x16.extractLane(x, 6); _i8x16[7] = SIMD.Bool8x16.extractLane(x, 7); _i8x16[8] = SIMD.Bool8x16.extractLane(x, 8); _i8x16[9] = SIMD.Bool8x16.extractLane(x, 9); _i8x16[10] = SIMD.Bool8x16.extractLane(x, 10); _i8x16[11] = SIMD.Bool8x16.extractLane(x, 11); _i8x16[12] = SIMD.Bool8x16.extractLane(x, 12); _i8x16[13] = SIMD.Bool8x16.extractLane(x, 13); _i8x16[14] = SIMD.Bool8x16.extractLane(x, 14); _i8x16[15] = SIMD.Bool8x16.extractLane(x, 15); } function saveFloat64x2(x) { x = SIMD.Float64x2.check(x); _f64x2[0] = SIMD.Float64x2.extractLane(x, 0); _f64x2[1] = SIMD.Float64x2.extractLane(x, 1); } function saveFloat32x4(x) { x = SIMD.Float32x4.check(x); _f32x4[0] = SIMD.Float32x4.extractLane(x, 0); _f32x4[1] = SIMD.Float32x4.extractLane(x, 1); _f32x4[2] = SIMD.Float32x4.extractLane(x, 2); _f32x4[3] = SIMD.Float32x4.extractLane(x, 3); } function saveInt32x4(x) { x = SIMD.Int32x4.check(x); _i32x4[0] = SIMD.Int32x4.extractLane(x, 0); _i32x4[1] = SIMD.Int32x4.extractLane(x, 1); _i32x4[2] = SIMD.Int32x4.extractLane(x, 2); _i32x4[3] = SIMD.Int32x4.extractLane(x, 3); } function saveInt16x8(x) { x = SIMD.Int16x8.check(x); _i16x8[0] = SIMD.Int16x8.extractLane(x, 0); _i16x8[1] = SIMD.Int16x8.extractLane(x, 1); _i16x8[2] = SIMD.Int16x8.extractLane(x, 2); _i16x8[3] = SIMD.Int16x8.extractLane(x, 3); _i16x8[4] = SIMD.Int16x8.extractLane(x, 4); _i16x8[5] = SIMD.Int16x8.extractLane(x, 5); _i16x8[6] = SIMD.Int16x8.extractLane(x, 6); _i16x8[7] = SIMD.Int16x8.extractLane(x, 7); } function saveInt8x16(x) { x = SIMD.Int8x16.check(x); _i8x16[0] = SIMD.Int8x16.extractLane(x, 0); _i8x16[1] = SIMD.Int8x16.extractLane(x, 1); _i8x16[2] = SIMD.Int8x16.extractLane(x, 2); _i8x16[3] = SIMD.Int8x16.extractLane(x, 3); _i8x16[4] = SIMD.Int8x16.extractLane(x, 4); _i8x16[5] = SIMD.Int8x16.extractLane(x, 5); _i8x16[6] = SIMD.Int8x16.extractLane(x, 6); _i8x16[7] = SIMD.Int8x16.extractLane(x, 7); _i8x16[8] = SIMD.Int8x16.extractLane(x, 8); _i8x16[9] = SIMD.Int8x16.extractLane(x, 9); _i8x16[10] = SIMD.Int8x16.extractLane(x, 10); _i8x16[11] = SIMD.Int8x16.extractLane(x, 11); _i8x16[12] = SIMD.Int8x16.extractLane(x, 12); _i8x16[13] = SIMD.Int8x16.extractLane(x, 13); _i8x16[14] = SIMD.Int8x16.extractLane(x, 14); _i8x16[15] = SIMD.Int8x16.extractLane(x, 15); } function restoreBool32x4() { var alias = _i32x4; return SIMD.Bool32x4(alias[0], alias[1], alias[2], alias[3]); } function restoreBool16x8() { var alias = _i16x8; return SIMD.Bool16x8(alias[0], alias[1], alias[2], alias[3], alias[4], alias[5], alias[6], alias[7]); } function restoreBool8x16() { var alias = _i8x16; return SIMD.Bool8x16(alias[0], alias[1], alias[2], alias[3], alias[4], alias[5], alias[6], alias[7], alias[8], alias[9], alias[10], alias[11], alias[12], alias[13], alias[14], alias[15]); } function restoreFloat64x2() { var alias = _f64x2; return SIMD.Float64x2(alias[0], alias[1]); } function restoreFloat32x4() { var alias = _f32x4; return SIMD.Float32x4(alias[0], alias[1], alias[2], alias[3]); } function restoreInt32x4() { var alias = _i32x4; return SIMD.Int32x4(alias[0], alias[1], alias[2], alias[3]); } function restoreInt16x8() { var alias = _i16x8; return SIMD.Int16x8(alias[0], alias[1], alias[2], alias[3], alias[4], alias[5], alias[6], alias[7]); } function restoreInt8x16() { var alias = _i8x16; return SIMD.Int8x16(alias[0], alias[1], alias[2], alias[3], alias[4], alias[5], alias[6], alias[7], alias[8], alias[9], alias[10], alias[11], alias[12], alias[13], alias[14], alias[15]); } if (typeof SIMD.Bool64x2 === "undefined") { /** * Construct a new instance of bool64x2 number. * @constructor */ SIMD.Bool64x2 = function(x, y) { if (!(this instanceof SIMD.Bool64x2)) { return new SIMD.Bool64x2(x, y); } this.x_ = !!x; this.y_ = !!y; } } if (typeof SIMD.Bool64x2.check === "undefined") { /** * Check whether the argument is a bool64x2. * @param {bool64x2} v An instance of bool64x2. * @return {bool64x2} The bool64x2 instance. */ SIMD.Bool64x2.check = function(v) { if (!(v instanceof SIMD.Bool64x2)) { throw new TypeError("argument is not a bool64x2."); } return v; } } if (typeof SIMD.Bool64x2.splat === "undefined") { /** * Construct a new instance of bool64x2 with the same value * in all lanes. * @param {double} value used for all lanes. * @constructor */ SIMD.Bool64x2.splat = function(s) { return SIMD.Bool64x2(s, s); } } if (typeof SIMD.Bool64x2.extractLane === "undefined") { /** * @param {bool64x2} v An instance of bool64x2. * @param {integer} i Index in concatenation of v for lane i * @return {Boolean} The value in lane i of v. */ SIMD.Bool64x2.extractLane = function(v, i) { v = SIMD.Bool64x2.check(v); check2(i); switch(i) { case 0: return v.x_; case 1: return v.y_; } } } if (typeof SIMD.Bool64x2.replaceLane === "undefined") { /** * @param {bool64x2} v An instance of bool64x2. * @param {integer} i Index in concatenation of v for lane i * @param {double} value used for lane i. * @return {bool64x2} New instance of bool64x2 with the values in v and * lane i replaced with {s}. */ SIMD.Bool64x2.replaceLane = function(v, i, s) { v = SIMD.Bool64x2.check(v); check2(i); // Other replaceLane implementations do the replacement in memory, but // this is awkward for bool64x2 without something like Int64Array. return i == 0 ? SIMD.Bool64x2(s, SIMD.Bool64x2.extractLane(v, 1)) : SIMD.Bool64x2(SIMD.Bool64x2.extractLane(v, 0), s); } } if (typeof SIMD.Bool64x2.allTrue === "undefined") { /** * Check if all 2 lanes hold a true value * @param {bool64x2} v An instance of bool64x2. * @return {Boolean} All 2 lanes hold a true value */ SIMD.Bool64x2.allTrue = function(v) { v = SIMD.Bool64x2.check(v); return SIMD.Bool64x2.extractLane(v, 0) && SIMD.Bool64x2.extractLane(v, 1); } } if (typeof SIMD.Bool64x2.anyTrue === "undefined") { /** * Check if any of the 2 lanes hold a true value * @param {bool64x2} v An instance of bool64x2. * @return {Boolean} Any of the 2 lanes holds a true value */ SIMD.Bool64x2.anyTrue = function(v) { v = SIMD.Bool64x2.check(v); return SIMD.Bool64x2.extractLane(v, 0) || SIMD.Bool64x2.extractLane(v, 1); } } if (typeof SIMD.Bool64x2.and === "undefined") { /** * @param {bool64x2} a An instance of bool64x2. * @param {bool64x2} b An instance of bool64x2. * @return {bool64x2} New instance of bool64x2 with values of a & b. */ SIMD.Bool64x2.and = function(a, b) { a = SIMD.Bool64x2.check(a); b = SIMD.Bool64x2.check(b); return SIMD.Bool64x2(SIMD.Bool64x2.extractLane(a, 0) & SIMD.Bool64x2.extractLane(b, 0), SIMD.Bool64x2.extractLane(a, 1) & SIMD.Bool64x2.extractLane(b, 1)); } } if (typeof SIMD.Bool64x2.or === "undefined") { /** * @param {bool64x2} a An instance of bool64x2. * @param {bool64x2} b An instance of bool64x2. * @return {bool64x2} New instance of bool64x2 with values of a | b. */ SIMD.Bool64x2.or = function(a, b) { a = SIMD.Bool64x2.check(a); b = SIMD.Bool64x2.check(b); return SIMD.Bool64x2(SIMD.Bool64x2.extractLane(a, 0) | SIMD.Bool64x2.extractLane(b, 0), SIMD.Bool64x2.extractLane(a, 1) | SIMD.Bool64x2.extractLane(b, 1)); } } if (typeof SIMD.Bool64x2.xor === "undefined") { /** * @param {bool64x2} a An instance of bool64x2. * @param {bool64x2} b An instance of bool64x2. * @return {bool64x2} New instance of bool64x2 with values of a ^ b. */ SIMD.Bool64x2.xor = function(a, b) { a = SIMD.Bool64x2.check(a); b = SIMD.Bool64x2.check(b); return SIMD.Bool64x2(SIMD.Bool64x2.extractLane(a, 0) ^ SIMD.Bool64x2.extractLane(b, 0), SIMD.Bool64x2.extractLane(a, 1) ^ SIMD.Bool64x2.extractLane(b, 1)); } } if (typeof SIMD.Bool64x2.not === "undefined") { /** * @param {bool64x2} a An instance of bool64x2. * @return {bool64x2} New instance of bool64x2 with values of !a */ SIMD.Bool64x2.not = function(a) { a = SIMD.Bool64x2.check(a); return SIMD.Bool64x2(!SIMD.Bool64x2.extractLane(a, 0), !SIMD.Bool64x2.extractLane(a, 1)); } } if (typeof SIMD.Bool64x2.equal === "undefined") { /** * @param {bool64x2} a An instance of bool64x2. * @param {bool64x2} b An instance of bool64x2. * @return {bool64x2} true or false in each lane depending on * the result of a == b. */ SIMD.Bool64x2.equal = function(a, b) { a = SIMD.Bool64x2.check(a); b = SIMD.Bool64x2.check(b); return SIMD.Bool64x2(SIMD.Bool64x2.extractLane(a, 0) == SIMD.Bool64x2.extractLane(b, 0), SIMD.Bool64x2.extractLane(a, 1) == SIMD.Bool64x2.extractLane(b, 1)); } } if (typeof SIMD.Bool64x2.notEqual === "undefined") { /** * @param {bool64x2} a An instance of bool64x2. * @param {bool64x2} b An instance of bool64x2. * @return {bool64x2} true or false in each lane depending on * the result of a != b. */ SIMD.Bool64x2.notEqual = function(a, b) { a = SIMD.Bool64x2.check(a); b = SIMD.Bool64x2.check(b); return SIMD.Bool64x2(SIMD.Bool64x2.extractLane(a, 0) != SIMD.Bool64x2.extractLane(b, 0), SIMD.Bool64x2.extractLane(a, 1) != SIMD.Bool64x2.extractLane(b, 1)); } } if (typeof SIMD.Bool64x2.select === "undefined") { /** * @param {bool64x2} mask Selector mask. An instance of bool64x2 * @param {bool64x2} trueValue Pick lane from here if corresponding * selector lane is 1 * @param {bool64x2} falseValue Pick lane from here if corresponding * selector lane is 0 * @return {bool64x2} Mix of lanes from trueValue or falseValue as * indicated */ SIMD.Bool64x2.select = function(mask, trueValue, falseValue) { mask = SIMD.Bool64x2.check(mask); trueValue = SIMD.Bool64x2.check(trueValue); falseValue = SIMD.Bool64x2.check(falseValue); var tr = SIMD.Bool64x2.and(mask, trueValue); var fr = SIMD.Bool64x2.and(SIMD.Bool64x2.not(mask), falseValue); return SIMD.Bool64x2.or(tr, fr); } } if (typeof SIMD.Bool32x4 === "undefined") { /** * Construct a new instance of Bool32x4 number. * @constructor */ SIMD.Bool32x4 = function(x, y, z, w) { if (!(this instanceof SIMD.Bool32x4)) { return new SIMD.Bool32x4(x, y, z, w); } this.x_ = !!x; this.y_ = !!y; this.z_ = !!z; this.w_ = !!w; } } if (typeof SIMD.Bool32x4.check === "undefined") { /** * Check whether the argument is a Bool32x4. * @param {Bool32x4} v An instance of Bool32x4. * @return {Bool32x4} The Bool32x4 instance. */ SIMD.Bool32x4.check = function(v) { if (!(v instanceof SIMD.Bool32x4)) { throw new TypeError("argument is not a Bool32x4."); } return v; } } if (typeof SIMD.Bool32x4.splat === "undefined") { /** * Construct a new instance of Bool32x4 with the same value * in all lanes. * @param {double} value used for all lanes. * @constructor */ SIMD.Bool32x4.splat = function(s) { return SIMD.Bool32x4(s, s, s, s); } } if (typeof SIMD.Bool32x4.extractLane === "undefined") { /** * @param {Bool32x4} v An instance of Bool32x4. * @param {integer} i Index in concatenation of v for lane i * @return {Boolean} The value in lane i of v. */ SIMD.Bool32x4.extractLane = function(v, i) { v = SIMD.Bool32x4.check(v); check4(i); switch(i) { case 0: return v.x_; case 1: return v.y_; case 2: return v.z_; case 3: return v.w_; } } } if (typeof SIMD.Bool32x4.replaceLane === "undefined") { /** * @param {Bool32x4} v An instance of Bool32x4. * @param {integer} i Index in concatenation of v for lane i * @param {double} value used for lane i. * @return {Bool32x4} New instance of Bool32x4 with the values in v and * lane i replaced with {s}. */ SIMD.Bool32x4.replaceLane = function(v, i, s) { v = SIMD.Bool32x4.check(v); check4(i); saveBool32x4(v); _i32x4[i] = s; return restoreBool32x4(); } } if (typeof SIMD.Bool32x4.allTrue === "undefined") { /** * Check if all 4 lanes hold a true value * @param {Bool32x4} v An instance of Bool32x4. * @return {Boolean} All 4 lanes holds a true value */ SIMD.Bool32x4.allTrue = function(v) { v = SIMD.Bool32x4.check(v); return SIMD.Bool32x4.extractLane(v, 0) && SIMD.Bool32x4.extractLane(v, 1) && SIMD.Bool32x4.extractLane(v, 2) && SIMD.Bool32x4.extractLane(v, 3); } } if (typeof SIMD.Bool32x4.anyTrue === "undefined") { /** * Check if any of the 4 lanes hold a true value * @param {Bool32x4} v An instance of Bool32x4. * @return {Boolean} Any of the 4 lanes holds a true value */ SIMD.Bool32x4.anyTrue = function(v) { v = SIMD.Bool32x4.check(v); return SIMD.Bool32x4.extractLane(v, 0) || SIMD.Bool32x4.extractLane(v, 1) || SIMD.Bool32x4.extractLane(v, 2) || SIMD.Bool32x4.extractLane(v, 3); } } if (typeof SIMD.Bool32x4.and === "undefined") { /** * @param {Bool32x4} a An instance of Bool32x4. * @param {Bool32x4} b An instance of Bool32x4. * @return {Bool32x4} New instance of Bool32x4 with values of a & b. */ SIMD.Bool32x4.and = function(a, b) { a = SIMD.Bool32x4.check(a); b = SIMD.Bool32x4.check(b); return SIMD.Bool32x4(SIMD.Bool32x4.extractLane(a, 0) & SIMD.Bool32x4.extractLane(b, 0), SIMD.Bool32x4.extractLane(a, 1) & SIMD.Bool32x4.extractLane(b, 1), SIMD.Bool32x4.extractLane(a, 2) & SIMD.Bool32x4.extractLane(b, 2), SIMD.Bool32x4.extractLane(a, 3) & SIMD.Bool32x4.extractLane(b, 3)); } } if (typeof SIMD.Bool32x4.or === "undefined") { /** * @param {Bool32x4} a An instance of Bool32x4. * @param {Bool32x4} b An instance of Bool32x4. * @return {Bool32x4} New instance of Bool32x4 with values of a | b. */ SIMD.Bool32x4.or = function(a, b) { a = SIMD.Bool32x4.check(a); b = SIMD.Bool32x4.check(b); return SIMD.Bool32x4(SIMD.Bool32x4.extractLane(a, 0) | SIMD.Bool32x4.extractLane(b, 0), SIMD.Bool32x4.extractLane(a, 1) | SIMD.Bool32x4.extractLane(b, 1), SIMD.Bool32x4.extractLane(a, 2) | SIMD.Bool32x4.extractLane(b, 2), SIMD.Bool32x4.extractLane(a, 3) | SIMD.Bool32x4.extractLane(b, 3)); } } if (typeof SIMD.Bool32x4.xor === "undefined") { /** * @param {Bool32x4} a An instance of Bool32x4. * @param {Bool32x4} b An instance of Bool32x4. * @return {Bool32x4} New instance of Bool32x4 with values of a ^ b. */ SIMD.Bool32x4.xor = function(a, b) { a = SIMD.Bool32x4.check(a); b = SIMD.Bool32x4.check(b); return SIMD.Bool32x4(SIMD.Bool32x4.extractLane(a, 0) ^ SIMD.Bool32x4.extractLane(b, 0), SIMD.Bool32x4.extractLane(a, 1) ^ SIMD.Bool32x4.extractLane(b, 1), SIMD.Bool32x4.extractLane(a, 2) ^ SIMD.Bool32x4.extractLane(b, 2), SIMD.Bool32x4.extractLane(a, 3) ^ SIMD.Bool32x4.extractLane(b, 3)); } } if (typeof SIMD.Bool32x4.not === "undefined") { /** * @param {Bool32x4} a An instance of Bool32x4. * @return {Bool32x4} New instance of Bool32x4 with values of !a */ SIMD.Bool32x4.not = function(a) { a = SIMD.Bool32x4.check(a); return SIMD.Bool32x4(!SIMD.Bool32x4.extractLane(a, 0), !SIMD.Bool32x4.extractLane(a, 1), !SIMD.Bool32x4.extractLane(a, 2), !SIMD.Bool32x4.extractLane(a, 3)); } } if (typeof SIMD.Bool32x4.equal === "undefined") { /** * @param {Bool32x4} a An instance of Bool32x4. * @param {Bool32x4} b An instance of Bool32x4. * @return {Bool32x4} true or false in each lane depending on * the result of a == b. */ SIMD.Bool32x4.equal = function(a, b) { a = SIMD.Bool32x4.check(a); b = SIMD.Bool32x4.check(b); return SIMD.Bool32x4(SIMD.Bool32x4.extractLane(a, 0) == SIMD.Bool32x4.extractLane(b, 0), SIMD.Bool32x4.extractLane(a, 1) == SIMD.Bool32x4.extractLane(b, 1), SIMD.Bool32x4.extractLane(a, 2) == SIMD.Bool32x4.extractLane(b, 2), SIMD.Bool32x4.extractLane(a, 3) == SIMD.Bool32x4.extractLane(b, 3)); } } if (typeof SIMD.Bool32x4.notEqual === "undefined") { /** * @param {Bool32x4} a An instance of Bool32x4. * @param {Bool32x4} b An instance of Bool32x4. * @return {Bool32x4} true or false in each lane depending on * the result of a != b. */ SIMD.Bool32x4.notEqual = function(a, b) { a = SIMD.Bool32x4.check(a); b = SIMD.Bool32x4.check(b); return SIMD.Bool32x4(SIMD.Bool32x4.extractLane(a, 0) != SIMD.Bool32x4.extractLane(b, 0), SIMD.Bool32x4.extractLane(a, 1) != SIMD.Bool32x4.extractLane(b, 1), SIMD.Bool32x4.extractLane(a, 2) != SIMD.Bool32x4.extractLane(b, 2), SIMD.Bool32x4.extractLane(a, 3) != SIMD.Bool32x4.extractLane(b, 3)); } } if (typeof SIMD.Bool32x4.select === "undefined") { /** * @param {Bool32x4} mask Selector mask. An instance of Bool32x4 * @param {Bool32x4} trueValue Pick lane from here if corresponding * selector lane is 1 * @param {Bool32x4} falseValue Pick lane from here if corresponding * selector lane is 0 * @return {Bool32x4} Mix of lanes from trueValue or falseValue as * indicated */ SIMD.Bool32x4.select = function(mask, trueValue, falseValue) { mask = SIMD.Bool32x4.check(mask); trueValue = SIMD.Bool32x4.check(trueValue); falseValue = SIMD.Bool32x4.check(falseValue); var tr = SIMD.Bool32x4.and(mask, trueValue); var fr = SIMD.Bool32x4.and(SIMD.Bool32x4.not(mask), falseValue); return SIMD.Bool32x4.or(tr, fr); } } if (typeof SIMD.Bool16x8 === "undefined") { /** * Construct a new instance of Bool16x8 number. * @constructor */ SIMD.Bool16x8 = function(s0, s1, s2, s3, s4, s5, s6, s7) { if (!(this instanceof SIMD.Bool16x8)) { return new SIMD.Bool16x8(s0, s1, s2, s3, s4, s5, s6, s7); } this.s0_ = !!s0; this.s1_ = !!s1; this.s2_ = !!s2; this.s3_ = !!s3; this.s4_ = !!s4; this.s5_ = !!s5; this.s6_ = !!s6; this.s7_ = !!s7; } } if (typeof SIMD.Bool16x8.check === "undefined") { /** * Check whether the argument is a Bool16x8. * @param {Bool16x8} v An instance of Bool16x8. * @return {Bool16x8} The Bool16x8 instance. */ SIMD.Bool16x8.check = function(v) { if (!(v instanceof SIMD.Bool16x8)) { throw new TypeError("argument is not a Bool16x8."); } return v; } } if (typeof SIMD.Bool16x8.splat === "undefined") { /** * Construct a new instance of Bool16x8 with the same value * in all lanes. * @param {double} value used for all lanes. * @constructor */ SIMD.Bool16x8.splat = function(s) { return SIMD.Bool16x8(s, s, s, s, s, s, s, s); } } if (typeof SIMD.Bool16x8.extractLane === "undefined") { /** * @param {Bool16x8} v An instance of Bool16x8. * @param {integer} i Index in concatenation of v for lane i * @return {Boolean} The value in lane i of v. */ SIMD.Bool16x8.extractLane = function(v, i) { v = SIMD.Bool16x8.check(v); check8(i); switch(i) { case 0: return v.s0_; case 1: return v.s1_; case 2: return v.s2_; case 3: return v.s3_; case 4: return v.s4_; case 5: return v.s5_; case 6: return v.s6_; case 7: return v.s7_; } } } if (typeof SIMD.Bool16x8.replaceLane === "undefined") { /** * @param {Bool16x8} v An instance of Bool16x8. * @param {integer} i Index in concatenation of v for lane i * @param {double} value used for lane i. * @return {Bool16x8} New instance of Bool16x8 with the values in v and * lane i replaced with {s}. */ SIMD.Bool16x8.replaceLane = function(v, i, s) { v = SIMD.Bool16x8.check(v); check8(i); saveBool16x8(v); _i16x8[i] = s; return restoreBool16x8(); } } if (typeof SIMD.Bool16x8.allTrue === "undefined") { /** * Check if all 8 lanes hold a true value * @param {Bool16x8} v An instance of Bool16x8. * @return {Boolean} All 8 lanes holds a true value */ SIMD.Bool16x8.allTrue = function(v) { v = SIMD.Bool16x8.check(v); return SIMD.Bool16x8.extractLane(v, 0) && SIMD.Bool16x8.extractLane(v, 1) && SIMD.Bool16x8.extractLane(v, 2) && SIMD.Bool16x8.extractLane(v, 3) && SIMD.Bool16x8.extractLane(v, 4) && SIMD.Bool16x8.extractLane(v, 5) && SIMD.Bool16x8.extractLane(v, 6) && SIMD.Bool16x8.extractLane(v, 7); } } if (typeof SIMD.Bool16x8.anyTrue === "undefined") { /** * Check if any of the 8 lanes hold a true value * @param {Bool16x8} v An instance of Int16x8. * @return {Boolean} Any of the 8 lanes holds a true value */ SIMD.Bool16x8.anyTrue = function(v) { v = SIMD.Bool16x8.check(v); return SIMD.Bool16x8.extractLane(v, 0) || SIMD.Bool16x8.extractLane(v, 1) || SIMD.Bool16x8.extractLane(v, 2) || SIMD.Bool16x8.extractLane(v, 3) || SIMD.Bool16x8.extractLane(v, 4) || SIMD.Bool16x8.extractLane(v, 5) || SIMD.Bool16x8.extractLane(v, 6) || SIMD.Bool16x8.extractLane(v, 7); } } if (typeof SIMD.Bool16x8.and === "undefined") { /** * @param {Bool16x8} a An instance of Bool16x8. * @param {Bool16x8} b An instance of Bool16x8. * @return {Bool16x8} New instance of Bool16x8 with values of a & b. */ SIMD.Bool16x8.and = function(a, b) { a = SIMD.Bool16x8.check(a); b = SIMD.Bool16x8.check(b); return SIMD.Bool16x8(SIMD.Bool16x8.extractLane(a, 0) & SIMD.Bool16x8.extractLane(b, 0), SIMD.Bool16x8.extractLane(a, 1) & SIMD.Bool16x8.extractLane(b, 1), SIMD.Bool16x8.extractLane(a, 2) & SIMD.Bool16x8.extractLane(b, 2), SIMD.Bool16x8.extractLane(a, 3) & SIMD.Bool16x8.extractLane(b, 3), SIMD.Bool16x8.extractLane(a, 4) & SIMD.Bool16x8.extractLane(b, 4), SIMD.Bool16x8.extractLane(a, 5) & SIMD.Bool16x8.extractLane(b, 5), SIMD.Bool16x8.extractLane(a, 6) & SIMD.Bool16x8.extractLane(b, 6), SIMD.Bool16x8.extractLane(a, 7) & SIMD.Bool16x8.extractLane(b, 7)); } } if (typeof SIMD.Bool16x8.or === "undefined") { /** * @param {Bool16x8} a An instance of Bool16x8. * @param {Bool16x8} b An instance of Bool16x8. * @return {Bool16x8} New instance of Bool16x8 with values of a | b. */ SIMD.Bool16x8.or = function(a, b) { a = SIMD.Bool16x8.check(a); b = SIMD.Bool16x8.check(b); return SIMD.Bool16x8(SIMD.Bool16x8.extractLane(a, 0) | SIMD.Bool16x8.extractLane(b, 0), SIMD.Bool16x8.extractLane(a, 1) | SIMD.Bool16x8.extractLane(b, 1), SIMD.Bool16x8.extractLane(a, 2) | SIMD.Bool16x8.extractLane(b, 2), SIMD.Bool16x8.extractLane(a, 3) | SIMD.Bool16x8.extractLane(b, 3), SIMD.Bool16x8.extractLane(a, 4) | SIMD.Bool16x8.extractLane(b, 4), SIMD.Bool16x8.extractLane(a, 5) | SIMD.Bool16x8.extractLane(b, 5), SIMD.Bool16x8.extractLane(a, 6) | SIMD.Bool16x8.extractLane(b, 6), SIMD.Bool16x8.extractLane(a, 7) | SIMD.Bool16x8.extractLane(b, 7)); } } if (typeof SIMD.Bool16x8.xor === "undefined") { /** * @param {Bool16x8} a An instance of Bool16x8. * @param {Bool16x8} b An instance of Bool16x8. * @return {Bool16x8} New instance of Bool16x8 with values of a ^ b. */ SIMD.Bool16x8.xor = function(a, b) { a = SIMD.Bool16x8.check(a); b = SIMD.Bool16x8.check(b); return SIMD.Bool16x8(SIMD.Bool16x8.extractLane(a, 0) ^ SIMD.Bool16x8.extractLane(b, 0), SIMD.Bool16x8.extractLane(a, 1) ^ SIMD.Bool16x8.extractLane(b, 1), SIMD.Bool16x8.extractLane(a, 2) ^ SIMD.Bool16x8.extractLane(b, 2), SIMD.Bool16x8.extractLane(a, 3) ^ SIMD.Bool16x8.extractLane(b, 3), SIMD.Bool16x8.extractLane(a, 4) ^ SIMD.Bool16x8.extractLane(b, 4), SIMD.Bool16x8.extractLane(a, 5) ^ SIMD.Bool16x8.extractLane(b, 5), SIMD.Bool16x8.extractLane(a, 6) ^ SIMD.Bool16x8.extractLane(b, 6), SIMD.Bool16x8.extractLane(a, 7) ^ SIMD.Bool16x8.extractLane(b, 7)); } } if (typeof SIMD.Bool16x8.not === "undefined") { /** * @param {Bool16x8} a An instance of Bool16x8. * @return {Bool16x8} New instance of Bool16x8 with values of !a */ SIMD.Bool16x8.not = function(a) { a = SIMD.Bool16x8.check(a); return SIMD.Bool16x8(!SIMD.Bool16x8.extractLane(a, 0), !SIMD.Bool16x8.extractLane(a, 1), !SIMD.Bool16x8.extractLane(a, 2), !SIMD.Bool16x8.extractLane(a, 3), !SIMD.Bool16x8.extractLane(a, 4), !SIMD.Bool16x8.extractLane(a, 5), !SIMD.Bool16x8.extractLane(a, 6), !SIMD.Bool16x8.extractLane(a, 7)); } } if (typeof SIMD.Bool16x8.equal === "undefined") { /** * @param {Bool16x8} a An instance of Bool16x8. * @param {Bool16x8} b An instance of Bool16x8. * @return {Bool16x8} true or false in each lane depending on * the result of a == b. */ SIMD.Bool16x8.equal = function(a, b) { a = SIMD.Bool16x8.check(a); b = SIMD.Bool16x8.check(b); return SIMD.Bool16x8(SIMD.Bool16x8.extractLane(a, 0) == SIMD.Bool16x8.extractLane(b, 0), SIMD.Bool16x8.extractLane(a, 1) == SIMD.Bool16x8.extractLane(b, 1), SIMD.Bool16x8.extractLane(a, 2) == SIMD.Bool16x8.extractLane(b, 2), SIMD.Bool16x8.extractLane(a, 3) == SIMD.Bool16x8.extractLane(b, 3), SIMD.Bool16x8.extractLane(a, 4) == SIMD.Bool16x8.extractLane(b, 4), SIMD.Bool16x8.extractLane(a, 5) == SIMD.Bool16x8.extractLane(b, 5), SIMD.Bool16x8.extractLane(a, 6) == SIMD.Bool16x8.extractLane(b, 6), SIMD.Bool16x8.extractLane(a, 7) == SIMD.Bool16x8.extractLane(b, 7)); } } if (typeof SIMD.Bool16x8.notEqual === "undefined") { /** * @param {Bool16x8} a An instance of Bool16x8. * @param {Bool16x8} b An instance of Bool16x8. * @return {Bool16x8} true or false in each lane depending on * the result of a != b. */ SIMD.Bool16x8.notEqual = function(a, b) { a = SIMD.Bool16x8.check(a); b = SIMD.Bool16x8.check(b); return SIMD.Bool16x8(SIMD.Bool16x8.extractLane(a, 0) != SIMD.Bool16x8.extractLane(b, 0), SIMD.Bool16x8.extractLane(a, 1) != SIMD.Bool16x8.extractLane(b, 1), SIMD.Bool16x8.extractLane(a, 2) != SIMD.Bool16x8.extractLane(b, 2), SIMD.Bool16x8.extractLane(a, 3) != SIMD.Bool16x8.extractLane(b, 3), SIMD.Bool16x8.extractLane(a, 4) != SIMD.Bool16x8.extractLane(b, 4), SIMD.Bool16x8.extractLane(a, 5) != SIMD.Bool16x8.extractLane(b, 5), SIMD.Bool16x8.extractLane(a, 6) != SIMD.Bool16x8.extractLane(b, 6), SIMD.Bool16x8.extractLane(a, 7) != SIMD.Bool16x8.extractLane(b, 7)); } } if (typeof SIMD.Bool16x8.select === "undefined") { /** * @param {Bool16x8} mask Selector mask. An instance of Bool16x8 * @param {Bool16x8} trueValue Pick lane from here if corresponding * selector lane is 1 * @param {Bool16x8} falseValue Pick lane from here if corresponding * selector lane is 0 * @return {Bool16x8} Mix of lanes from trueValue or falseValue as * indicated */ SIMD.Bool16x8.select = function(mask, trueValue, falseValue) { mask = SIMD.Bool16x8.check(mask); trueValue = SIMD.Bool16x8.check(trueValue); falseValue = SIMD.Bool16x8.check(falseValue); var tr = SIMD.Bool16x8.and(mask, trueValue); var fr = SIMD.Bool16x8.and(SIMD.Bool16x8.not(mask), falseValue); return SIMD.Bool16x8.or(tr, fr); } } if (typeof SIMD.Bool8x16 === "undefined") { /** * Construct a new instance of Bool8x16 number. * @constructor */ SIMD.Bool8x16 = function(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15) { if (!(this instanceof SIMD.Bool8x16)) { return new SIMD.Bool8x16(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15); } this.s0_ = !!s0; this.s1_ = !!s1; this.s2_ = !!s2; this.s3_ = !!s3; this.s4_ = !!s4; this.s5_ = !!s5; this.s6_ = !!s6; this.s7_ = !!s7; this.s8_ = !!s8; this.s9_ = !!s9; this.s10_ = !!s10; this.s11_ = !!s11; this.s12_ = !!s12; this.s13_ = !!s13; this.s14_ = !!s14; this.s15_ = !!s15; } } if (typeof SIMD.Bool8x16.check === "undefined") { /** * Check whether the argument is a Bool8x16. * @param {Bool8x16} v An instance of Bool8x16. * @return {Bool8x16} The Bool8x16 instance. */ SIMD.Bool8x16.check = function(v) { if (!(v instanceof SIMD.Bool8x16)) { throw new TypeError("argument is not a Bool8x16."); } return v; } } if (typeof SIMD.Bool8x16.splat === "undefined") { /** * Construct a new instance of Bool8x16 with the same value * in all lanes. * @param {double} value used for all lanes. * @constructor */ SIMD.Bool8x16.splat = function(s) { return SIMD.Bool8x16(s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s); } } if (typeof SIMD.Bool8x16.extractLane === "undefined") { /** * @param {Bool8x16} v An instance of Bool8x16. * @param {integer} i Index in concatenation of v for lane i * @return {Boolean} The value in lane i of v. */ SIMD.Bool8x16.extractLane = function(v, i) { v = SIMD.Bool8x16.check(v); check16(i); switch(i) { case 0: return v.s0_; case 1: return v.s1_; case 2: return v.s2_; case 3: return v.s3_; case 4: return v.s4_; case 5: return v.s5_; case 6: return v.s6_; case 7: return v.s7_; case 8: return v.s8_; case 9: return v.s9_; case 10: return v.s10_; case 11: return v.s11_; case 12: return v.s12_; case 13: return v.s13_; case 14: return v.s14_; case 15: return v.s15_; } } } if (typeof SIMD.Bool8x16.replaceLane === "undefined") { /** * @param {Bool8x16} v An instance of Bool8x16. * @param {integer} i Index in concatenation of v for lane i * @param {double} value used for lane i. * @return {Bool8x16} New instance of Bool8x16 with the values in v and * lane i replaced with {s}. */ SIMD.Bool8x16.replaceLane = function(v, i, s) { v = SIMD.Bool8x16.check(v); check16(i); saveBool8x16(v); _i8x16[i] = s; return restoreBool8x16(); } } if (typeof SIMD.Bool8x16.allTrue === "undefined") { /** * Check if all 16 lanes hold a true value * @param {Bool8x16} v An instance of Bool8x16. * @return {Boolean} All 16 lanes holds a true value */ SIMD.Bool8x16.allTrue = function(v) { v = SIMD.Bool8x16.check(v); return SIMD.Bool8x16.extractLane(v, 0) && SIMD.Bool8x16.extractLane(v, 1) && SIMD.Bool8x16.extractLane(v, 2) && SIMD.Bool8x16.extractLane(v, 3) && SIMD.Bool8x16.extractLane(v, 4) && SIMD.Bool8x16.extractLane(v, 5) && SIMD.Bool8x16.extractLane(v, 6) && SIMD.Bool8x16.extractLane(v, 7) && SIMD.Bool8x16.extractLane(v, 8) && SIMD.Bool8x16.extractLane(v, 9) && SIMD.Bool8x16.extractLane(v, 10) && SIMD.Bool8x16.extractLane(v, 11) && SIMD.Bool8x16.extractLane(v, 12) && SIMD.Bool8x16.extractLane(v, 13) && SIMD.Bool8x16.extractLane(v, 14) && SIMD.Bool8x16.extractLane(v, 15); } } if (typeof SIMD.Bool8x16.anyTrue === "undefined") { /** * Check if any of the 16 lanes hold a true value * @param {Bool8x16} v An instance of Bool16x8. * @return {Boolean} Any of the 16 lanes holds a true value */ SIMD.Bool8x16.anyTrue = function(v) { v = SIMD.Bool8x16.check(v); return SIMD.Bool8x16.extractLane(v, 0) || SIMD.Bool8x16.extractLane(v, 1) || SIMD.Bool8x16.extractLane(v, 2) || SIMD.Bool8x16.extractLane(v, 3) || SIMD.Bool8x16.extractLane(v, 4) || SIMD.Bool8x16.extractLane(v, 5) || SIMD.Bool8x16.extractLane(v, 6) || SIMD.Bool8x16.extractLane(v, 7) || SIMD.Bool8x16.extractLane(v, 8) || SIMD.Bool8x16.extractLane(v, 9) || SIMD.Bool8x16.extractLane(v, 10) || SIMD.Bool8x16.extractLane(v, 11) || SIMD.Bool8x16.extractLane(v, 12) || SIMD.Bool8x16.extractLane(v, 13) || SIMD.Bool8x16.extractLane(v, 14) || SIMD.Bool8x16.extractLane(v, 15); } } if (typeof SIMD.Bool8x16.and === "undefined") { /** * @param {Bool8x16} a An instance of Bool8x16. * @param {Bool8x16} b An instance of Bool8x16. * @return {Bool8x16} New instance of Bool8x16 with values of a & b. */ SIMD.Bool8x16.and = function(a, b) { a = SIMD.Bool8x16.check(a); b = SIMD.Bool8x16.check(b); return SIMD.Bool8x16(SIMD.Bool8x16.extractLane(a, 0) & SIMD.Bool8x16.extractLane(b, 0), SIMD.Bool8x16.extractLane(a, 1) & SIMD.Bool8x16.extractLane(b, 1), SIMD.Bool8x16.extractLane(a, 2) & SIMD.Bool8x16.extractLane(b, 2), SIMD.Bool8x16.extractLane(a, 3) & SIMD.Bool8x16.extractLane(b, 3), SIMD.Bool8x16.extractLane(a, 4) & SIMD.Bool8x16.extractLane(b, 4), SIMD.Bool8x16.extractLane(a, 5) & SIMD.Bool8x16.extractLane(b, 5), SIMD.Bool8x16.extractLane(a, 6) & SIMD.Bool8x16.extractLane(b, 6), SIMD.Bool8x16.extractLane(a, 7) & SIMD.Bool8x16.extractLane(b, 7), SIMD.Bool8x16.extractLane(a, 8) & SIMD.Bool8x16.extractLane(b, 8), SIMD.Bool8x16.extractLane(a, 9) & SIMD.Bool8x16.extractLane(b, 9), SIMD.Bool8x16.extractLane(a, 10) & SIMD.Bool8x16.extractLane(b, 10), SIMD.Bool8x16.extractLane(a, 11) & SIMD.Bool8x16.extractLane(b, 11), SIMD.Bool8x16.extractLane(a, 12) & SIMD.Bool8x16.extractLane(b, 12), SIMD.Bool8x16.extractLane(a, 13) & SIMD.Bool8x16.extractLane(b, 13), SIMD.Bool8x16.extractLane(a, 14) & SIMD.Bool8x16.extractLane(b, 14), SIMD.Bool8x16.extractLane(a, 15) & SIMD.Bool8x16.extractLane(b, 15)); } } if (typeof SIMD.Bool8x16.or === "undefined") { /** * @param {Bool8x16} a An instance of Bool8x16. * @param {Bool8x16} b An instance of Bool8x16. * @return {Bool8x16} New instance of Bool8x16 with values of a | b. */ SIMD.Bool8x16.or = function(a, b) { a = SIMD.Bool8x16.check(a); b = SIMD.Bool8x16.check(b); return SIMD.Bool8x16(SIMD.Bool8x16.extractLane(a, 0) | SIMD.Bool8x16.extractLane(b, 0), SIMD.Bool8x16.extractLane(a, 1) | SIMD.Bool8x16.extractLane(b, 1), SIMD.Bool8x16.extractLane(a, 2) | SIMD.Bool8x16.extractLane(b, 2), SIMD.Bool8x16.extractLane(a, 3) | SIMD.Bool8x16.extractLane(b, 3), SIMD.Bool8x16.extractLane(a, 4) | SIMD.Bool8x16.extractLane(b, 4), SIMD.Bool8x16.extractLane(a, 5) | SIMD.Bool8x16.extractLane(b, 5), SIMD.Bool8x16.extractLane(a, 6) | SIMD.Bool8x16.extractLane(b, 6), SIMD.Bool8x16.extractLane(a, 7) | SIMD.Bool8x16.extractLane(b, 7), SIMD.Bool8x16.extractLane(a, 8) | SIMD.Bool8x16.extractLane(b, 8), SIMD.Bool8x16.extractLane(a, 9) | SIMD.Bool8x16.extractLane(b, 9), SIMD.Bool8x16.extractLane(a, 10) | SIMD.Bool8x16.extractLane(b, 10), SIMD.Bool8x16.extractLane(a, 11) | SIMD.Bool8x16.extractLane(b, 11), SIMD.Bool8x16.extractLane(a, 12) | SIMD.Bool8x16.extractLane(b, 12), SIMD.Bool8x16.extractLane(a, 13) | SIMD.Bool8x16.extractLane(b, 13), SIMD.Bool8x16.extractLane(a, 14) | SIMD.Bool8x16.extractLane(b, 14), SIMD.Bool8x16.extractLane(a, 15) | SIMD.Bool8x16.extractLane(b, 15)); } } if (typeof SIMD.Bool8x16.xor === "undefined") { /** * @param {Bool8x16} a An instance of Bool8x16. * @param {Bool8x16} b An instance of Bool8x16. * @return {Bool8x16} New instance of Bool8x16 with values of a ^ b. */ SIMD.Bool8x16.xor = function(a, b) { a = SIMD.Bool8x16.check(a); b = SIMD.Bool8x16.check(b); return SIMD.Bool8x16(SIMD.Bool8x16.extractLane(a, 0) ^ SIMD.Bool8x16.extractLane(b, 0), SIMD.Bool8x16.extractLane(a, 1) ^ SIMD.Bool8x16.extractLane(b, 1), SIMD.Bool8x16.extractLane(a, 2) ^ SIMD.Bool8x16.extractLane(b, 2), SIMD.Bool8x16.extractLane(a, 3) ^ SIMD.Bool8x16.extractLane(b, 3), SIMD.Bool8x16.extractLane(a, 4) ^ SIMD.Bool8x16.extractLane(b, 4), SIMD.Bool8x16.extractLane(a, 5) ^ SIMD.Bool8x16.extractLane(b, 5), SIMD.Bool8x16.extractLane(a, 6) ^ SIMD.Bool8x16.extractLane(b, 6), SIMD.Bool8x16.extractLane(a, 7) ^ SIMD.Bool8x16.extractLane(b, 7), SIMD.Bool8x16.extractLane(a, 8) ^ SIMD.Bool8x16.extractLane(b, 8), SIMD.Bool8x16.extractLane(a, 9) ^ SIMD.Bool8x16.extractLane(b, 9), SIMD.Bool8x16.extractLane(a, 10) ^ SIMD.Bool8x16.extractLane(b, 10), SIMD.Bool8x16.extractLane(a, 11) ^ SIMD.Bool8x16.extractLane(b, 11), SIMD.Bool8x16.extractLane(a, 12) ^ SIMD.Bool8x16.extractLane(b, 12), SIMD.Bool8x16.extractLane(a, 13) ^ SIMD.Bool8x16.extractLane(b, 13), SIMD.Bool8x16.extractLane(a, 14) ^ SIMD.Bool8x16.extractLane(b, 14), SIMD.Bool8x16.extractLane(a, 15) ^ SIMD.Bool8x16.extractLane(b, 15)); } } if (typeof SIMD.Bool8x16.not === "undefined") { /** * @param {Bool8x16} a An instance of Bool8x16. * @return {Bool8x16} New instance of Bool8x16 with values of !a */ SIMD.Bool8x16.not = function(a) { a = SIMD.Bool8x16.check(a); return SIMD.Bool8x16(!SIMD.Bool8x16.extractLane(a, 0), !SIMD.Bool8x16.extractLane(a, 1), !SIMD.Bool8x16.extractLane(a, 2), !SIMD.Bool8x16.extractLane(a, 3), !SIMD.Bool8x16.extractLane(a, 4), !SIMD.Bool8x16.extractLane(a, 5), !SIMD.Bool8x16.extractLane(a, 6), !SIMD.Bool8x16.extractLane(a, 7), !SIMD.Bool8x16.extractLane(a, 8), !SIMD.Bool8x16.extractLane(a, 9), !SIMD.Bool8x16.extractLane(a, 10), !SIMD.Bool8x16.extractLane(a, 11), !SIMD.Bool8x16.extractLane(a, 12), !SIMD.Bool8x16.extractLane(a, 13), !SIMD.Bool8x16.extractLane(a, 14), !SIMD.Bool8x16.extractLane(a, 15)); } } if (typeof SIMD.Bool8x16.equal === "undefined") { /** * @param {Bool8x16} a An instance of Bool8x16. * @param {Bool8x16} b An instance of Bool8x16. * @return {Bool8x16} true or false in each lane depending on * the result of a == b. */ SIMD.Bool8x16.equal = function(a, b) { a = SIMD.Bool8x16.check(a); b = SIMD.Bool8x16.check(b); return SIMD.Bool8x16(SIMD.Bool8x16.extractLane(a, 0) == SIMD.Bool8x16.extractLane(b, 0), SIMD.Bool8x16.extractLane(a, 1) == SIMD.Bool8x16.extractLane(b, 1), SIMD.Bool8x16.extractLane(a, 2) == SIMD.Bool8x16.extractLane(b, 2), SIMD.Bool8x16.extractLane(a, 3) == SIMD.Bool8x16.extractLane(b, 3), SIMD.Bool8x16.extractLane(a, 4) == SIMD.Bool8x16.extractLane(b, 4), SIMD.Bool8x16.extractLane(a, 5) == SIMD.Bool8x16.extractLane(b, 5), SIMD.Bool8x16.extractLane(a, 6) == SIMD.Bool8x16.extractLane(b, 6), SIMD.Bool8x16.extractLane(a, 7) == SIMD.Bool8x16.extractLane(b, 7), SIMD.Bool8x16.extractLane(a, 8) == SIMD.Bool8x16.extractLane(b, 8), SIMD.Bool8x16.extractLane(a, 9) == SIMD.Bool8x16.extractLane(b, 9), SIMD.Bool8x16.extractLane(a, 10) == SIMD.Bool8x16.extractLane(b, 10), SIMD.Bool8x16.extractLane(a, 11) == SIMD.Bool8x16.extractLane(b, 11), SIMD.Bool8x16.extractLane(a, 12) == SIMD.Bool8x16.extractLane(b, 12), SIMD.Bool8x16.extractLane(a, 13) == SIMD.Bool8x16.extractLane(b, 13), SIMD.Bool8x16.extractLane(a, 14) == SIMD.Bool8x16.extractLane(b, 14), SIMD.Bool8x16.extractLane(a, 15) == SIMD.Bool8x16.extractLane(b, 15)); } } if (typeof SIMD.Bool8x16.notEqual === "undefined") { /** * @param {Bool8x16} a An instance of Bool8x16. * @param {Bool8x16} b An instance of Bool8x16. * @return {Bool8x16} true or false in each lane depending on * the result of a != b. */ SIMD.Bool8x16.notEqual = function(a, b) { a = SIMD.Bool8x16.check(a); b = SIMD.Bool8x16.check(b); return SIMD.Bool8x16(SIMD.Bool8x16.extractLane(a, 0) != SIMD.Bool8x16.extractLane(b, 0), SIMD.Bool8x16.extractLane(a, 1) != SIMD.Bool8x16.extractLane(b, 1), SIMD.Bool8x16.extractLane(a, 2) != SIMD.Bool8x16.extractLane(b, 2), SIMD.Bool8x16.extractLane(a, 3) != SIMD.Bool8x16.extractLane(b, 3), SIMD.Bool8x16.extractLane(a, 4) != SIMD.Bool8x16.extractLane(b, 4), SIMD.Bool8x16.extractLane(a, 5) != SIMD.Bool8x16.extractLane(b, 5), SIMD.Bool8x16.extractLane(a, 6) != SIMD.Bool8x16.extractLane(b, 6), SIMD.Bool8x16.extractLane(a, 7) != SIMD.Bool8x16.extractLane(b, 7), SIMD.Bool8x16.extractLane(a, 8) != SIMD.Bool8x16.extractLane(b, 8), SIMD.Bool8x16.extractLane(a, 9) != SIMD.Bool8x16.extractLane(b, 9), SIMD.Bool8x16.extractLane(a, 10) != SIMD.Bool8x16.extractLane(b, 10), SIMD.Bool8x16.extractLane(a, 11) != SIMD.Bool8x16.extractLane(b, 11), SIMD.Bool8x16.extractLane(a, 12) != SIMD.Bool8x16.extractLane(b, 12), SIMD.Bool8x16.extractLane(a, 13) != SIMD.Bool8x16.extractLane(b, 13), SIMD.Bool8x16.extractLane(a, 14) != SIMD.Bool8x16.extractLane(b, 14), SIMD.Bool8x16.extractLane(a, 15) != SIMD.Bool8x16.extractLane(b, 15)); } } if (typeof SIMD.Bool8x16.select === "undefined") { /** * @param {Bool8x16} mask Selector mask. An instance of Bool8x16 * @param {Bool8x16} trueValue Pick lane from here if corresponding * selector lane is 1 * @param {Bool8x16} falseValue Pick lane from here if corresponding * selector lane is 0 * @return {Bool8x16} Mix of lanes from trueValue or falseValue as * indicated */ SIMD.Bool8x16.select = function(mask, trueValue, falseValue) { mask = SIMD.Bool8x16.check(mask); trueValue = SIMD.Bool8x16.check(trueValue); falseValue = SIMD.Bool8x16.check(falseValue); var tr = SIMD.Bool8x16.and(mask, trueValue); var fr = SIMD.Bool8x16.and(SIMD.Bool8x16.not(mask), falseValue); return SIMD.Bool8x16.or(tr, fr); } } if (typeof SIMD.Float32x4 === "undefined") { /** * 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. * @param {double} value used for w lane. * @constructor */ SIMD.Float32x4 = function(x, y, z, w) { if (!(this instanceof SIMD.Float32x4)) { return new SIMD.Float32x4(x, y, z, w);