diff --git a/emscripten.py b/emscripten.py index 189b84f5f181..0f61e990631c 100755 --- a/emscripten.py +++ b/emscripten.py @@ -450,16 +450,16 @@ def make_emulated_param(i): asm_setup += '\nvar debug_table_' + sig + ' = ' + json.dumps(debug_tables[sig]) + ';' maths = ['Math.' + func for func in ['floor', 'abs', 'sqrt', 'pow', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'exp', 'log', 'ceil', 'imul', 'min', 'clz32']] - simdfloattypes = ['float32x4'] - simdinttypes = ['int32x4'] + simdfloattypes = ['Float32x4'] + simdinttypes = ['Int32x4'] simdtypes = simdfloattypes + simdinttypes simdfuncs = ['check', 'add', 'sub', 'neg', 'mul', 'equal', 'lessThan', 'greaterThan', 'notEqual', 'lessThanOrEqual', 'greaterThanOrEqual', 'select', 'and', 'or', 'xor', 'not', 'splat', 'swizzle', 'shuffle', - 'withX', 'withY', 'withZ', 'withW', - 'load', 'store', 'loadX', 'storeX', 'loadXY', 'storeXY', 'loadXYZ', 'storeXYZ'] + 'load', 'store', 'load1', 'store1', 'load2', 'store2', 'load3', 'store3', + 'extractLane', 'replaceLane'] simdfloatfuncs = simdfuncs + ['div', 'min', 'max', 'minNum', 'maxNum', 'sqrt', 'abs', 'fromInt32x4', 'fromInt32x4Bits', 'reciprocalApproximation', 'reciprocalSqrtApproximation']; diff --git a/src/ecmascript_simd.js b/src/ecmascript_simd.js index 280d53aecf54..ec3b2bb480e0 100644 --- a/src/ecmascript_simd.js +++ b/src/ecmascript_simd.js @@ -1,4 +1,5 @@ /* + 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 @@ -25,47 +26,52 @@ // Many of the operations in SIMD.js have semantics which correspond to scalar // operations in JS, however there are a few differences: -// - The conversion of integers to booleans uses <0 rather than !=0. // - 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. -if (typeof SIMD === "undefined") { - // SIMD module. We don't use the var keyword here, so that we put the - // SIMD object in the global scope even if this polyfill code is included - // within some other scope. The theory is that we're anticipating a - // future where SIMD is predefined in the global scope. - SIMD = {}; +(function(global) { + +if (typeof global.SIMD === "undefined") { + // SIMD module. + global.SIMD = {}; } -// private stuff. -var _SIMD_PRIVATE = {}; +if (typeof module !== "undefined") { + // For CommonJS modules + module.exports = global.SIMD; +} -// Temporary buffers for swizzles and bitcasts. -_SIMD_PRIVATE._f32x4 = new Float32Array(4); -_SIMD_PRIVATE._f64x2 = new Float64Array(_SIMD_PRIVATE._f32x4.buffer); -_SIMD_PRIVATE._i32x4 = new Int32Array(_SIMD_PRIVATE._f32x4.buffer); -_SIMD_PRIVATE._i16x8 = new Int16Array(_SIMD_PRIVATE._f32x4.buffer); -_SIMD_PRIVATE._i8x16 = new Int8Array(_SIMD_PRIVATE._f32x4.buffer); +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') { - _SIMD_PRIVATE.truncatef32 = Math.fround; + truncatef32 = Math.fround; } else { - _SIMD_PRIVATE._f32 = new Float32Array(1); + _f32 = new Float32Array(1); - _SIMD_PRIVATE.truncatef32 = function(x) { - _SIMD_PRIVATE._f32[0] = x; - return _SIMD_PRIVATE._f32[0]; + truncatef32 = function(x) { + _f32[0] = x; + return _f32[0]; } } // Type checking functions. -_SIMD_PRIVATE.isNumber = function(o) { - return typeof o === "number" || (typeof o === "object" && o.constructor === Number); +function isInt32(o) { + return (o | 0) === o; } -_SIMD_PRIVATE.isTypedArray = function(o) { +function isTypedArray(o) { return (o instanceof Int8Array) || (o instanceof Uint8Array) || (o instanceof Uint8ClampedArray) || @@ -74,3013 +80,3421 @@ _SIMD_PRIVATE.isTypedArray = function(o) { (o instanceof Int32Array) || (o instanceof Uint32Array) || (o instanceof Float32Array) || - (o instanceof Float64Array) || - (o instanceof Int32x4Array) || - (o instanceof Float32x4Array); -} - -_SIMD_PRIVATE.isArrayBuffer = function(o) { - return (o instanceof ArrayBuffer); + (o instanceof Float64Array); } -_SIMD_PRIVATE.minNum = function(x, y) { +function minNum(x, y) { return x != x ? y : y != y ? x : Math.min(x, y); } -_SIMD_PRIVATE.maxNum = function(x, y) { +function maxNum(x, y) { return x != x ? y : y != y ? x : Math.max(x, y); } -_SIMD_PRIVATE.tobool = function(x) { - return x < 0; +function int32FromFloat(x) { + if (x > -2147483649.0 && x < 2147483648.0) + return x|0; + throw new RangeError("Conversion from floating-point to integer failed"); } -_SIMD_PRIVATE.frombool = function(x) { - return !x - 1; +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'); + } } -_SIMD_PRIVATE.int32FromFloat = function(x) { - if (x >= -0x80000000 && x <= 0x7fffffff) - return x|0; - throw new RangeError("Conversion from floating-point to integer failed"); -} +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. -_SIMD_PRIVATE.saveFloat64x2 = function(x) { - x = SIMD.float64x2.check(x); - _SIMD_PRIVATE._f64x2[0] = x.x; - _SIMD_PRIVATE._f64x2[1] = x.y; -} - -_SIMD_PRIVATE.saveFloat32x4 = function(x) { - x = SIMD.float32x4.check(x); - _SIMD_PRIVATE._f32x4[0] = x.x; - _SIMD_PRIVATE._f32x4[1] = x.y; - _SIMD_PRIVATE._f32x4[2] = x.z; - _SIMD_PRIVATE._f32x4[3] = x.w; -} - -_SIMD_PRIVATE.saveInt32x4 = function(x) { - x = SIMD.int32x4.check(x); - _SIMD_PRIVATE._i32x4[0] = x.x; - _SIMD_PRIVATE._i32x4[1] = x.y; - _SIMD_PRIVATE._i32x4[2] = x.z; - _SIMD_PRIVATE._i32x4[3] = x.w; -} - -_SIMD_PRIVATE.saveInt16x8 = function(x) { - x = SIMD.int16x8.check(x); - _SIMD_PRIVATE._i16x8[0] = x.s0; - _SIMD_PRIVATE._i16x8[1] = x.s1; - _SIMD_PRIVATE._i16x8[2] = x.s2; - _SIMD_PRIVATE._i16x8[3] = x.s3; - _SIMD_PRIVATE._i16x8[4] = x.s4; - _SIMD_PRIVATE._i16x8[5] = x.s5; - _SIMD_PRIVATE._i16x8[6] = x.s6; - _SIMD_PRIVATE._i16x8[7] = x.s7; -} - -_SIMD_PRIVATE.saveInt8x16 = function(x) { - x = SIMD.int8x16.check(x); - _SIMD_PRIVATE._i8x16[0] = x.s0; - _SIMD_PRIVATE._i8x16[1] = x.s1; - _SIMD_PRIVATE._i8x16[2] = x.s2; - _SIMD_PRIVATE._i8x16[3] = x.s3; - _SIMD_PRIVATE._i8x16[4] = x.s4; - _SIMD_PRIVATE._i8x16[5] = x.s5; - _SIMD_PRIVATE._i8x16[6] = x.s6; - _SIMD_PRIVATE._i8x16[7] = x.s7; - _SIMD_PRIVATE._i8x16[8] = x.s8; - _SIMD_PRIVATE._i8x16[9] = x.s9; - _SIMD_PRIVATE._i8x16[10] = x.s10; - _SIMD_PRIVATE._i8x16[11] = x.s11; - _SIMD_PRIVATE._i8x16[12] = x.s12; - _SIMD_PRIVATE._i8x16[13] = x.s13; - _SIMD_PRIVATE._i8x16[14] = x.s14; - _SIMD_PRIVATE._i8x16[15] = x.s15; -} - -_SIMD_PRIVATE.restoreFloat64x2 = function() { - var alias = _SIMD_PRIVATE._f64x2; - return SIMD.float64x2(alias[0], alias[1]); -} - -_SIMD_PRIVATE.restoreFloat32x4 = function() { - var alias = _SIMD_PRIVATE._f32x4; - return SIMD.float32x4(alias[0], alias[1], alias[2], alias[3]); -} - -_SIMD_PRIVATE.restoreInt32x4 = function() { - var alias = _SIMD_PRIVATE._i32x4; - return SIMD.int32x4(alias[0], alias[1], alias[2], alias[3]); -} - -_SIMD_PRIVATE.restoreInt16x8 = function() { - var alias = _SIMD_PRIVATE._i16x8; - return SIMD.int16x8(alias[0], alias[1], alias[2], alias[3], +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 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 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]); } -_SIMD_PRIVATE.restoreInt8x16 = function() { - var alias = _SIMD_PRIVATE._i8x16; - return SIMD.int8x16(alias[0], alias[1], alias[2], alias[3], +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.float32x4 === "undefined") { + +if (typeof SIMD.Bool32x4 === "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. + * Construct a new instance of Bool32x4 number. * @constructor */ - SIMD.float32x4 = function(x, y, z, w) { - if (!(this instanceof SIMD.float32x4)) { - return new SIMD.float32x4(x, y, z, w); + SIMD.Bool32x4 = function(x, y, z, w) { + if (!(this instanceof SIMD.Bool32x4)) { + return new SIMD.Bool32x4(x, y, z, w); } - this.x_ = _SIMD_PRIVATE.truncatef32(x); - this.y_ = _SIMD_PRIVATE.truncatef32(y); - this.z_ = _SIMD_PRIVATE.truncatef32(z); - this.w_ = _SIMD_PRIVATE.truncatef32(w); + this.x_ = !!x; + this.y_ = !!y; + this.z_ = !!z; + this.w_ = !!w; } - - Object.defineProperty(SIMD.float32x4.prototype, 'x', { - get: function() { return this.x_; } - }); - - Object.defineProperty(SIMD.float32x4.prototype, 'y', { - get: function() { return this.y_; } - }); - - Object.defineProperty(SIMD.float32x4.prototype, 'z', { - get: function() { return this.z_; } - }); - - Object.defineProperty(SIMD.float32x4.prototype, 'w', { - get: function() { return this.w_; } - }); - - /** - * Extract the sign bit from each lane return them in the first 4 bits. - */ - Object.defineProperty(SIMD.float32x4.prototype, 'signMask', { - get: function() { - var mx = (this.x < 0.0 || 1/this.x === -Infinity); - var my = (this.y < 0.0 || 1/this.y === -Infinity); - var mz = (this.z < 0.0 || 1/this.z === -Infinity); - var mw = (this.w < 0.0 || 1/this.w === -Infinity); - return mx | my << 1 | mz << 2 | mw << 3; - } - }); } -if (typeof SIMD.float32x4.check === "undefined") { +if (typeof SIMD.Bool32x4.check === "undefined") { /** - * Check whether the argument is a float32x4. - * @param {float32x4} v An instance of float32x4. - * @return {float32x4} The float32x4 instance. + * Check whether the argument is a Bool32x4. + * @param {Bool32x4} v An instance of Bool32x4. + * @return {Bool32x4} The Bool32x4 instance. */ - SIMD.float32x4.check = function(v) { - if (!(v instanceof SIMD.float32x4)) { - throw new TypeError("argument is not a float32x4."); + SIMD.Bool32x4.check = function(v) { + if (!(v instanceof SIMD.Bool32x4)) { + throw new TypeError("argument is not a Bool32x4."); } return v; } } -if (typeof SIMD.float32x4.splat === "undefined") { +if (typeof SIMD.Bool32x4.splat === "undefined") { /** - * Construct a new instance of float32x4 number with the same value + * Construct a new instance of Bool32x4 with the same value * in all lanes. * @param {double} value used for all lanes. * @constructor */ - SIMD.float32x4.splat = function(s) { - return SIMD.float32x4(s, s, s, s); + SIMD.Bool32x4.splat = function(s) { + return SIMD.Bool32x4(s, s, s, s); } } -if (typeof SIMD.float32x4.fromFloat64x2 === "undefined") { +if (typeof SIMD.Bool32x4.extractLane === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {float32x4} A float32x4 with .x and .y from t + * @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.float32x4.fromFloat64x2 = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.float32x4(t.x, t.y, 0, 0); + 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.float32x4.fromInt32x4 === "undefined") { +if (typeof SIMD.Bool32x4.replaceLane === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @return {float32x4} An integer to float conversion copy of t. + * @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.float32x4.fromInt32x4 = function(t) { - t = SIMD.int32x4.check(t); - return SIMD.float32x4(t.x, t.y, t.z, t.w); + SIMD.Bool32x4.replaceLane = function(v, i, s) { + v = SIMD.Bool32x4.check(v); + check4(i); + saveBool32x4(v); + _i32x4[i] = s; + return restoreBool32x4(); } } -if (typeof SIMD.float32x4.fromFloat64x2Bits === "undefined") { +if (typeof SIMD.Bool32x4.allTrue === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {float32x4} a bit-wise copy of t as a float32x4. - */ - SIMD.float32x4.fromFloat64x2Bits = function(t) { - _SIMD_PRIVATE.saveFloat64x2(t); - return _SIMD_PRIVATE.restoreFloat32x4(); - } -} - -if (typeof SIMD.float32x4.fromInt32x4Bits === "undefined") { - /** - * @param {int32x4} t An instance of int32x4. - * @return {float32x4} a bit-wise copy of t as a float32x4. - */ - SIMD.float32x4.fromInt32x4Bits = function(t) { - _SIMD_PRIVATE.saveInt32x4(t); - return _SIMD_PRIVATE.restoreFloat32x4(); + * 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.float32x4.fromInt16x8Bits === "undefined") { +if (typeof SIMD.Bool32x4.anyTrue === "undefined") { /** - * @param {int16x8} t An instance of int16x8. - * @return {float32x4} a bit-wise copy of t as a float32x4. - */ - SIMD.float32x4.fromInt16x8Bits = function(t) { - _SIMD_PRIVATE.saveInt16x8(t); - return _SIMD_PRIVATE.restoreFloat32x4(); + * 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.float32x4.fromInt8x16Bits === "undefined") { +if (typeof SIMD.Bool32x4.and === "undefined") { /** - * @param {int8x16} t An instance of int8x16. - * @return {float32x4} a bit-wise copy of t as a float32x4. - */ - SIMD.float32x4.fromInt8x16Bits = function(t) { - _SIMD_PRIVATE.saveInt8x16(t); - return _SIMD_PRIVATE.restoreFloat32x4(); + * @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.float64x2 === "undefined") { +if (typeof SIMD.Bool32x4.or === "undefined") { /** - * Construct a new instance of float64x2 number. - * @param {double} value used for x lane. - * @param {double} value used for y lane. - * @constructor + * @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.float64x2 = function(x, y) { - if (!(this instanceof SIMD.float64x2)) { - return new SIMD.float64x2(x, y); - } - - // Use unary + to force coercion to Number. - this.x_ = +x; - this.y_ = +y; + 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)); } - - Object.defineProperty(SIMD.float64x2.prototype, 'x', { - get: function() { return this.x_; } - }); - - Object.defineProperty(SIMD.float64x2.prototype, 'y', { - get: function() { return this.y_; } - }); - - /** - * Extract the sign bit from each lane return them in the first 2 bits. - */ - Object.defineProperty(SIMD.float64x2.prototype, 'signMask', { - get: function() { - var mx = (this.x < 0.0 || 1/this.x === -Infinity); - var my = (this.y < 0.0 || 1/this.y === -Infinity); - return mx | my << 1; - } - }); } -if (typeof SIMD.float64x2.check === "undefined") { +if (typeof SIMD.Bool32x4.xor === "undefined") { /** - * Check whether the argument is a float64x2. - * @param {float64x2} v An instance of float64x2. - * @return {float64x2} The float64x2 instance. + * @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.float64x2.check = function(v) { - if (!(v instanceof SIMD.float64x2)) { - throw new TypeError("argument is not a float64x2."); - } - return v; + 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.float64x2.splat === "undefined") { +if (typeof SIMD.Bool32x4.not === "undefined") { /** - * Construct a new instance of float64x2 number with the same value - * in all lanes. - * @param {double} value used for all lanes. - * @constructor + * @param {Bool32x4} a An instance of Bool32x4. + * @return {Bool32x4} New instance of Bool32x4 with values of !a */ - SIMD.float64x2.splat = function(s) { - return SIMD.float64x2(s, s); + 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.float64x2.fromFloat32x4 === "undefined") { +if (typeof SIMD.Bool32x4.equal === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float64x2} A float64x2 with .x and .y from t + * @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.float64x2.fromFloat32x4 = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.float64x2(t.x, t.y); + 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.float64x2.fromInt32x4 === "undefined") { +if (typeof SIMD.Bool32x4.notEqual === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @return {float64x2} A float64x2 with .x and .y from t + * @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.float64x2.fromInt32x4 = function(t) { - t = SIMD.int32x4.check(t); - return SIMD.float64x2(t.x, t.y); + 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.float64x2.fromFloat32x4Bits === "undefined") { +if (typeof SIMD.Bool32x4.select === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float64x2} a bit-wise copy of t as a float64x2. - */ - SIMD.float64x2.fromFloat32x4Bits = function(t) { - _SIMD_PRIVATE.saveFloat32x4(t); - return _SIMD_PRIVATE.restoreFloat64x2(); + * @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.float64x2.fromInt32x4Bits === "undefined") { - /** - * @param {int32x4} t An instance of int32x4. - * @return {float64x2} a bit-wise copy of t as a float64x2. - */ - SIMD.float64x2.fromInt32x4Bits = function(t) { - _SIMD_PRIVATE.saveInt32x4(t); - return _SIMD_PRIVATE.restoreFloat64x2(); +if (!Object.hasOwnProperty(SIMD.Bool32x4.prototype, 'valueOf')) { + SIMD.Bool32x4.prototype.valueOf = function() { + throw new TypeError("Bool32x4 cannot be converted to a number"); } } -if (typeof SIMD.float64x2.fromInt16x8Bits === "undefined") { +if (!Object.hasOwnProperty(SIMD.Bool32x4.prototype, 'toString')) { /** - * @param {int16x8} t An instance of int16x8. - * @return {float64x2} a bit-wise copy of t as a float64x2. + * @return {String} a string representing the Bool32x4. */ - SIMD.float64x2.fromInt16x8Bits = function(t) { - _SIMD_PRIVATE.saveInt16x8(t); - return _SIMD_PRIVATE.restoreFloat64x2(); + SIMD.Bool32x4.prototype.toString = function() { + return "SIMD.Bool32x4(" + + this.x_ + ", " + + this.y_ + ", " + + this.z_ + ", " + + this.w_ + ")" } } -if (typeof SIMD.float64x2.fromInt8x16Bits === "undefined") { +if (!Object.hasOwnProperty(SIMD.Bool32x4.prototype, 'toLocaleString')) { /** - * @param {int8x16} t An instance of int8x16. - * @return {float64x2} a bit-wise copy of t as a float64x2. + * @return {String} a locale-sensitive string representing the Bool32x4. */ - SIMD.float64x2.fromInt8x16Bits = function(t) { - _SIMD_PRIVATE.saveInt8x16(t); - return _SIMD_PRIVATE.restoreFloat64x2(); + SIMD.Bool32x4.prototype.toLocaleString = function() { + return "SIMD.Bool32x4(" + + this.x_.toLocaleString() + ", " + + this.y_.toLocaleString() + ", " + + this.z_.toLocaleString() + ", " + + this.w_.toLocaleString() + ")" } } -if (typeof SIMD.int32x4 === "undefined") { +if (typeof SIMD.Bool16x8 === "undefined") { /** - * Construct a new instance of int32x4 number. - * @param {integer} 32-bit value used for x lane. - * @param {integer} 32-bit value used for y lane. - * @param {integer} 32-bit value used for z lane. - * @param {integer} 32-bit value used for w lane. + * Construct a new instance of Bool16x8 number. * @constructor */ - SIMD.int32x4 = function(x, y, z, w) { - if (!(this instanceof SIMD.int32x4)) { - return new SIMD.int32x4(x, y, z, w); + 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.x_ = x|0; - this.y_ = y|0; - this.z_ = z|0; - this.w_ = w|0; + this.s0_ = !!s0; + this.s1_ = !!s1; + this.s2_ = !!s2; + this.s3_ = !!s3; + this.s4_ = !!s4; + this.s5_ = !!s5; + this.s6_ = !!s6; + this.s7_ = !!s7; } - - Object.defineProperty(SIMD.int32x4.prototype, 'x', { - get: function() { return this.x_; } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'y', { - get: function() { return this.y_; } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'z', { - get: function() { return this.z_; } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'w', { - get: function() { return this.w_; } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'flagX', { - get: function() { return _SIMD_PRIVATE.tobool(this.x); } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'flagY', { - get: function() { return _SIMD_PRIVATE.tobool(this.y); } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'flagZ', { - get: function() { return _SIMD_PRIVATE.tobool(this.z); } - }); - - Object.defineProperty(SIMD.int32x4.prototype, 'flagW', { - get: function() { return _SIMD_PRIVATE.tobool(this.w); } - }); - - /** - * Extract the sign bit from each lane return them in the first 4 bits. - */ - Object.defineProperty(SIMD.int32x4.prototype, 'signMask', { - get: function() { - var mx = _SIMD_PRIVATE.tobool(this.x); - var my = _SIMD_PRIVATE.tobool(this.y); - var mz = _SIMD_PRIVATE.tobool(this.z); - var mw = _SIMD_PRIVATE.tobool(this.w); - return mx | my << 1 | mz << 2 | mw << 3; - } - }); } -if (typeof SIMD.int32x4.check === "undefined") { +if (typeof SIMD.Bool16x8.check === "undefined") { /** - * Check whether the argument is a int32x4. - * @param {int32x4} v An instance of int32x4. - * @return {int32x4} The int32x4 instance. + * Check whether the argument is a Bool16x8. + * @param {Bool16x8} v An instance of Bool16x8. + * @return {Bool16x8} The Bool16x8 instance. */ - SIMD.int32x4.check = function(v) { - if (!(v instanceof SIMD.int32x4)) { - throw new TypeError("argument is not a int32x4."); + SIMD.Bool16x8.check = function(v) { + if (!(v instanceof SIMD.Bool16x8)) { + throw new TypeError("argument is not a Bool16x8."); } return v; } } -if (typeof SIMD.int32x4.bool === "undefined") { +if (typeof SIMD.Bool16x8.splat === "undefined") { /** - * Construct a new instance of int32x4 number with either true or false in each - * lane, depending on the truth values in x, y, z, and w. - * @param {boolean} flag used for x lane. - * @param {boolean} flag used for y lane. - * @param {boolean} flag used for z lane. - * @param {boolean} flag used for w lane. - * @constructor - */ - SIMD.int32x4.bool = function(x, y, z, w) { - return SIMD.int32x4(_SIMD_PRIVATE.frombool(x), - _SIMD_PRIVATE.frombool(y), - _SIMD_PRIVATE.frombool(z), - _SIMD_PRIVATE.frombool(w)); - } -} - -if (typeof SIMD.int32x4.splat === "undefined") { - /** - * Construct a new instance of int32x4 number with the same value + * Construct a new instance of Bool16x8 with the same value * in all lanes. - * @param {integer} value used for all lanes. + * @param {double} value used for all lanes. * @constructor */ - SIMD.int32x4.splat = function(s) { - return SIMD.int32x4(s, s, s, s); + SIMD.Bool16x8.splat = function(s) { + return SIMD.Bool16x8(s, s, s, s, s, s, s, s); } } -if (typeof SIMD.int32x4.fromFloat32x4 === "undefined") { +if (typeof SIMD.Bool16x8.extractLane === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {int32x4} with a integer to float conversion of t. + * @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.int32x4.fromFloat32x4 = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.int32x4(_SIMD_PRIVATE.int32FromFloat(t.x), - _SIMD_PRIVATE.int32FromFloat(t.y), - _SIMD_PRIVATE.int32FromFloat(t.z), - _SIMD_PRIVATE.int32FromFloat(t.w)); + 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.int32x4.fromFloat64x2 === "undefined") { +if (typeof SIMD.Bool16x8.replaceLane === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {int32x4} An int32x4 with .x and .y from t + * @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.int32x4.fromFloat64x2 = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.int32x4(_SIMD_PRIVATE.int32FromFloat(t.x), - _SIMD_PRIVATE.int32FromFloat(t.y), - 0, - 0); + SIMD.Bool16x8.replaceLane = function(v, i, s) { + v = SIMD.Bool16x8.check(v); + check8(i); + saveBool16x8(v); + _i16x8[i] = s; + return restoreBool16x8(); } } -if (typeof SIMD.int32x4.fromFloat32x4Bits === "undefined") { +if (typeof SIMD.Bool16x8.allTrue === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {int32x4} a bit-wise copy of t as a int32x4. + * 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.int32x4.fromFloat32x4Bits = function(t) { - _SIMD_PRIVATE.saveFloat32x4(t); - return _SIMD_PRIVATE.restoreInt32x4(); + 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.int32x4.fromFloat64x2Bits === "undefined") { +if (typeof SIMD.Bool16x8.anyTrue === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {int32x4} a bit-wise copy of t as an int32x4. - */ - SIMD.int32x4.fromFloat64x2Bits = function(t) { - _SIMD_PRIVATE.saveFloat64x2(t); - return _SIMD_PRIVATE.restoreInt32x4(); + * 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.int32x4.fromInt16x8Bits === "undefined") { +if (typeof SIMD.Bool16x8.and === "undefined") { /** - * @param {int16x8} t An instance of int16x8. - * @return {int32x4} a bit-wise copy of t as a int32x4. + * @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.int32x4.fromInt16x8Bits = function(t) { - _SIMD_PRIVATE.saveInt16x8(t); - return _SIMD_PRIVATE.restoreInt32x4(); + 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.int32x4.fromInt8x16Bits === "undefined") { +if (typeof SIMD.Bool16x8.or === "undefined") { /** - * @param {int8x16} t An instance of int8x16. - * @return {int32x4} a bit-wise copy of t as a int32x4. + * @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.int32x4.fromInt8x16Bits = function(t) { - _SIMD_PRIVATE.saveInt8x16(t); - return _SIMD_PRIVATE.restoreInt32x4(); + 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.int16x8 === "undefined") { +if (typeof SIMD.Bool16x8.xor === "undefined") { /** - * Construct a new instance of int16x8 number. - * @param {integer} 16-bit value used for s0 lane. - * @param {integer} 16-bit value used for s1 lane. - * @param {integer} 16-bit value used for s2 lane. - * @param {integer} 16-bit value used for s3 lane. - * @param {integer} 16-bit value used for s4 lane. - * @param {integer} 16-bit value used for s5 lane. - * @param {integer} 16-bit value used for s6 lane. - * @param {integer} 16-bit value used for s7 lane. - * @constructor + * @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.int16x8 = function(s0, s1, s2, s3, s4, s5, s6, s7) { - if (!(this instanceof SIMD.int16x8)) { - return new SIMD.int16x8(s0, s1, s2, s3, s4, s5, s6, s7); - } - - this.s0_ = s0 << 16 >> 16; - this.s1_ = s1 << 16 >> 16; - this.s2_ = s2 << 16 >> 16; - this.s3_ = s3 << 16 >> 16; - this.s4_ = s4 << 16 >> 16; - this.s5_ = s5 << 16 >> 16; - this.s6_ = s6 << 16 >> 16; - this.s7_ = s7 << 16 >> 16; + 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)); } - - Object.defineProperty(SIMD.int16x8.prototype, 's0', { - get: function() { return this.s0_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's1', { - get: function() { return this.s1_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's2', { - get: function() { return this.s2_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's3', { - get: function() { return this.s3_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's4', { - get: function() { return this.s4_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's5', { - get: function() { return this.s5_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's6', { - get: function() { return this.s6_; } - }); - - Object.defineProperty(SIMD.int16x8.prototype, 's7', { - get: function() { return this.s7_; } - }); - - /** - * Extract the sign bit from each lane return them in the first 8 bits. - */ - Object.defineProperty(SIMD.int16x8.prototype, 'signMask', { - get: function() { - var ms0 = (this.s0 & 0x8000) >>> 15; - var ms1 = (this.s1 & 0x8000) >>> 15; - var ms2 = (this.s2 & 0x8000) >>> 15; - var ms3 = (this.s3 & 0x8000) >>> 15; - var ms4 = (this.s4 & 0x8000) >>> 15; - var ms5 = (this.s5 & 0x8000) >>> 15; - var ms6 = (this.s6 & 0x8000) >>> 15; - var ms7 = (this.s7 & 0x8000) >>> 15; - return ms0 | ms1 << 1 | ms2 << 2 | ms3 << 3 | - ms4 << 4 | ms5 << 5 | ms6 << 6 | ms7 << 7; - } - }); } -if (typeof SIMD.int16x8.check === "undefined") { +if (typeof SIMD.Bool16x8.not === "undefined") { /** - * Check whether the argument is a int16x8. - * @param {int16x8} v An instance of int16x8. - * @return {int16x8} The int16x8 instance. - */ - SIMD.int16x8.check = function(v) { - if (!(v instanceof SIMD.int16x8)) { - throw new TypeError("argument is not a int16x8."); - } - return v; + * @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.int16x8.bool === "undefined") { +if (typeof SIMD.Bool16x8.equal === "undefined") { /** - * Construct a new instance of int16x8 number with true or false in each - * lane, depending on the truth value in s0, s1, s2, s3, s4, s5, s6, and s7. - * @param {boolean} flag used for s0 lane. - * @param {boolean} flag used for s1 lane. - * @param {boolean} flag used for s2 lane. - * @param {boolean} flag used for s3 lane. - * @param {boolean} flag used for s4 lane. - * @param {boolean} flag used for s5 lane. - * @param {boolean} flag used for s6 lane. - * @param {boolean} flag used for s7 lane. - * @constructor - */ - SIMD.int16x8.bool = function(s0, s1, s2, s3, s4, s5, s6, s7) { - return SIMD.int16x8(s0 ? -1 : 0x0, - s1 ? -1 : 0x0, - s2 ? -1 : 0x0, - s3 ? -1 : 0x0, - s4 ? -1 : 0x0, - s5 ? -1 : 0x0, - s6 ? -1 : 0x0, - s7 ? -1 : 0x0); + * @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.int16x8.splat === "undefined") { - /** - * Construct a new instance of int16x8 number with the same value - * in all lanes. - * @param {integer} value used for all lanes. - * @constructor +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.int16x8.splat = function(s) { - return SIMD.int16x8(s, s, s, s, s, s, s, s); + 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.int16x8.fromFloat32x4Bits === "undefined") { +if (typeof SIMD.Bool16x8.select === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {int16x8} a bit-wise copy of t as a int16x8. + * @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.int16x8.fromFloat32x4Bits = function(t) { - _SIMD_PRIVATE.saveFloat32x4(t); - return _SIMD_PRIVATE.restoreInt16x8(); + 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.int16x8.fromFloat64x2Bits === "undefined") { - /** - * @param {float64x2} t An instance of float64x2. - * @return {int16x8} a bit-wise copy of t as an int16x8. - */ - SIMD.int16x8.fromFloat64x2Bits = function(t) { - _SIMD_PRIVATE.saveFloat64x2(t); - return _SIMD_PRIVATE.restoreInt16x8(); +if (!Object.hasOwnProperty(SIMD.Bool16x8.prototype, 'valueOf')) { + SIMD.Bool16x8.prototype.valueOf = function() { + throw new TypeError("Bool16x8 cannot be converted to a number"); } } -if (typeof SIMD.int16x8.fromInt32x4Bits === "undefined") { +if (!Object.hasOwnProperty(SIMD.Bool16x8.prototype, 'toString')) { /** - * @param {int32x4} t An instance of int32x4. - * @return {int16x8} a bit-wise copy of t as a int16x8. - */ - SIMD.int16x8.fromInt32x4Bits = function(t) { - _SIMD_PRIVATE.saveInt32x4(t); - return _SIMD_PRIVATE.restoreInt16x8(); + * @return {String} a string representing the Bool32x4. + */ + SIMD.Bool16x8.prototype.toString = function() { + return "SIMD.Bool16x8(" + + this.s0_ + ", " + + this.s1_ + ", " + + this.s2_ + ", " + + this.s3_ + ", " + + this.s4_ + ", " + + this.s5_ + ", " + + this.s6_ + ", " + + this.s7_ + ")"; } } -if (typeof SIMD.int16x8.fromInt8x16Bits === "undefined") { +if (!Object.hasOwnProperty(SIMD.Bool16x8.prototype, 'toLocaleString')) { /** - * @param {int8x16} t An instance of int8x16. - * @return {int16x8} a bit-wise copy of t as a int16x8. - */ - SIMD.int16x8.fromInt8x16Bits = function(t) { - _SIMD_PRIVATE.saveInt8x16(t); - return _SIMD_PRIVATE.restoreInt16x8(); + * @return {String} a locale-sensitive string representing the Bool16x8. + */ + SIMD.Bool16x8.prototype.toLocaleString = function() { + return "SIMD.Bool16x8(" + + this.s0_.toLocaleString() + ", " + + this.s1_.toLocaleString() + ", " + + this.s2_.toLocaleString() + ", " + + this.s3_.toLocaleString() + ", " + + this.s4_.toLocaleString() + ", " + + this.s5_.toLocaleString() + ", " + + this.s6_.toLocaleString() + ", " + + this.s7_.toLocaleString() + ")"; } } -if (typeof SIMD.int8x16 === "undefined") { +if (typeof SIMD.Bool8x16 === "undefined") { /** - * Construct a new instance of int8x16 number. - * @param {integer} 8-bit value used for s0 lane. - * @param {integer} 8-bit value used for s1 lane. - * @param {integer} 8-bit value used for s2 lane. - * @param {integer} 8-bit value used for s3 lane. - * @param {integer} 8-bit value used for s4 lane. - * @param {integer} 8-bit value used for s5 lane. - * @param {integer} 8-bit value used for s6 lane. - * @param {integer} 8-bit value used for s7 lane. - * @param {integer} 8-bit value used for s8 lane. - * @param {integer} 8-bit value used for s9 lane. - * @param {integer} 8-bit value used for s10 lane. - * @param {integer} 8-bit value used for s11 lane. - * @param {integer} 8-bit value used for s12 lane. - * @param {integer} 8-bit value used for s13 lane. - * @param {integer} 8-bit value used for s14 lane. - * @param {integer} 8-bit value used for s15 lane. + * Construct a new instance of Bool8x16 number. * @constructor */ - SIMD.int8x16 = function(s0, s1, s2, s3, s4, s5, s6, s7, - s8, s9, s10, s11, s12, s13, s14, s15) { - if (!(this instanceof SIMD.int8x16)) { - return new SIMD.int8x16(s0, s1, s2, s3, s4, s5, s6, s7, - s8, s9, s10, s11, s12, s13, s14, s15); + 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 << 24 >> 24; - this.s1_ = s1 << 24 >> 24; - this.s2_ = s2 << 24 >> 24; - this.s3_ = s3 << 24 >> 24; - this.s4_ = s4 << 24 >> 24; - this.s5_ = s5 << 24 >> 24; - this.s6_ = s6 << 24 >> 24; - this.s7_ = s7 << 24 >> 24; - this.s8_ = s8 << 24 >> 24; - this.s9_ = s9 << 24 >> 24; - this.s10_ = s10 << 24 >> 24; - this.s11_ = s11 << 24 >> 24; - this.s12_ = s12 << 24 >> 24; - this.s13_ = s13 << 24 >> 24; - this.s14_ = s14 << 24 >> 24; - this.s15_ = s15 << 24 >> 24; - } - - Object.defineProperty(SIMD.int8x16.prototype, 's0', { - get: function() { return this.s0_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's1', { - get: function() { return this.s1_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's2', { - get: function() { return this.s2_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's3', { - get: function() { return this.s3_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's4', { - get: function() { return this.s4_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's5', { - get: function() { return this.s5_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's6', { - get: function() { return this.s6_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's7', { - get: function() { return this.s7_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's8', { - get: function() { return this.s8_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's9', { - get: function() { return this.s9_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's10', { - get: function() { return this.s10_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's11', { - get: function() { return this.s11_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's12', { - get: function() { return this.s12_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's13', { - get: function() { return this.s13_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's14', { - get: function() { return this.s14_; } - }); - - Object.defineProperty(SIMD.int8x16.prototype, 's15', { - get: function() { return this.s15_; } - }); - - /** - * Extract the sign bit from each lane return them in the first 16 bits. - */ - Object.defineProperty(SIMD.int8x16.prototype, 'signMask', { - get: function() { - var ms0 = (this.s0 & 0x80) >>> 7; - var ms1 = (this.s1 & 0x80) >>> 7; - var ms2 = (this.s2 & 0x80) >>> 7; - var ms3 = (this.s3 & 0x80) >>> 7; - var ms4 = (this.s4 & 0x80) >>> 7; - var ms5 = (this.s5 & 0x80) >>> 7; - var ms6 = (this.s6 & 0x80) >>> 7; - var ms7 = (this.s7 & 0x80) >>> 7; - var ms8 = (this.s8 & 0x80) >>> 7; - var ms9 = (this.s9 & 0x80) >>> 7; - var ms10 = (this.s10 & 0x80) >>> 7; - var ms11 = (this.s11 & 0x80) >>> 7; - var ms12 = (this.s12 & 0x80) >>> 7; - var ms13 = (this.s13 & 0x80) >>> 7; - var ms14 = (this.s14 & 0x80) >>> 7; - var ms15 = (this.s15 & 0x80) >>> 7; - return ms0 | ms1 << 1 | ms2 << 2 | ms3 << 3 | - ms4 << 4 | ms5 << 5 | ms6 << 6 | ms7 << 7 | - ms8 << 8 | ms9 << 9 | ms10 << 10 | ms11 << 11 | - ms12 << 12 | ms13 << 13 | ms14 << 14 | ms15 << 15; + 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.int8x16.check === "undefined") { +if (typeof SIMD.Bool8x16.splat === "undefined") { /** - * Check whether the argument is a int8x16. - * @param {int8x16} v An instance of int8x16. - * @return {int8x16} The int8x16 instance. + * Construct a new instance of Bool8x16 with the same value + * in all lanes. + * @param {double} value used for all lanes. + * @constructor */ - SIMD.int8x16.check = function(v) { - if (!(v instanceof SIMD.int8x16)) { - throw new TypeError("argument is not a int8x16."); + 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_; } - return v; } } -if (typeof SIMD.int8x16.bool === "undefined") { - /** - * Construct a new instance of int8x16 number with true or false in each - * lane, depending on the truth value in s0, s1, s2, s3, s4, s5, s6, s7, - * s8, s9, s10, s11, s12, s13, s14, and s15. - * @param {boolean} flag used for s0 lane. - * @param {boolean} flag used for s1 lane. - * @param {boolean} flag used for s2 lane. - * @param {boolean} flag used for s3 lane. - * @param {boolean} flag used for s4 lane. - * @param {boolean} flag used for s5 lane. - * @param {boolean} flag used for s6 lane. - * @param {boolean} flag used for s7 lane. - * @param {boolean} flag used for s8 lane. - * @param {boolean} flag used for s9 lane. - * @param {boolean} flag used for s10 lane. - * @param {boolean} flag used for s11 lane. - * @param {boolean} flag used for s12 lane. - * @param {boolean} flag used for s13 lane. - * @param {boolean} flag used for s14 lane. - * @param {boolean} flag used for s15 lane. - * @constructor - */ - SIMD.int8x16.bool = function(s0, s1, s2, s3, s4, s5, s6, s7, - s8, s9, s10, s11, s12, s13, s14, s15) { - return SIMD.int8x16(s0 ? -1 : 0x0, - s1 ? -1 : 0x0, - s2 ? -1 : 0x0, - s3 ? -1 : 0x0, - s4 ? -1 : 0x0, - s5 ? -1 : 0x0, - s6 ? -1 : 0x0, - s7 ? -1 : 0x0, - s8 ? -1 : 0x0, - s9 ? -1 : 0x0, - s10 ? -1 : 0x0, - s11 ? -1 : 0x0, - s12 ? -1 : 0x0, - s13 ? -1 : 0x0, - s14 ? -1 : 0x0, - s15 ? -1 : 0x0); - } -} - -if (typeof SIMD.int8x16.splat === "undefined") { - /** - * Construct a new instance of int8x16 number with the same value - * in all lanes. - * @param {integer} value used for all lanes. - * @constructor +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.int8x16.splat = function(s) { - return SIMD.int8x16(s, s, s, s, s, s, s, s, - s, s, s, s, s, s, s, s); + 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.int8x16.fromFloat32x4Bits === "undefined") { - /** - * @param {float32x4} t An instance of float32x4. - * @return {int8x16} a bit-wise copy of t as a int8x16. - */ - SIMD.int8x16.fromFloat32x4Bits = function(t) { - _SIMD_PRIVATE.saveFloat32x4(t); - return _SIMD_PRIVATE.restoreInt8x16(); +if (!Object.hasOwnProperty(SIMD.Bool8x16.prototype, 'valueOf')) { + SIMD.Bool8x16.prototype.valueOf = function() { + throw new TypeError("Bool8x16 cannot be converted to a number"); } } -if (typeof SIMD.int8x16.fromFloat64x2Bits === "undefined") { +if (!Object.hasOwnProperty(SIMD.Bool8x16.prototype, 'toString')) { /** - * @param {float64x2} t An instance of float64x2. - * @return {int8x16} a bit-wise copy of t as an int8x16. + * @return {String} a string representing the Bool32x4. + */ + SIMD.Bool8x16.prototype.toString = function() { + return "SIMD.Bool8x16(" + + this.s0_ + ", " + + this.s1_ + ", " + + this.s2_ + ", " + + this.s3_ + ", " + + this.s4_ + ", " + + this.s5_ + ", " + + this.s6_ + ", " + + this.s7_ + ", " + + this.s8_ + ", " + + this.s9_ + ", " + + this.s10_ + ", " + + this.s11_ + ", " + + this.s12_ + ", " + + this.s13_ + ", " + + this.s14_ + ", " + + this.s15_ + ")"; + } +} + +if (!Object.hasOwnProperty(SIMD.Bool8x16.prototype, 'toLocaleString')) { + /** + * @return {String} a locale-sensitive string representing the Bool8x16. */ - SIMD.int8x16.fromFloat64x2Bits = function(t) { - _SIMD_PRIVATE.saveFloat64x2(t); - return _SIMD_PRIVATE.restoreInt8x16(); + SIMD.Bool8x16.prototype.toLocaleString = function() { + return "SIMD.Bool8x16(" + + this.s0_.toLocaleString() + ", " + + this.s1_.toLocaleString() + ", " + + this.s2_.toLocaleString() + ", " + + this.s3_.toLocaleString() + ", " + + this.s4_.toLocaleString() + ", " + + this.s5_.toLocaleString() + ", " + + this.s6_.toLocaleString() + ", " + + this.s7_.toLocaleString() + ", " + + this.s8_.toLocaleString() + ", " + + this.s9_.toLocaleString() + ", " + + this.s10_.toLocaleString() + ", " + + this.s11_.toLocaleString() + ", " + + this.s12_.toLocaleString() + ", " + + this.s13_.toLocaleString() + ", " + + this.s14_.toLocaleString() + ", " + + this.s15_.toLocaleString() + ")"; + } +} + + +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); + } + + this.x_ = truncatef32(x); + this.y_ = truncatef32(y); + this.z_ = truncatef32(z); + this.w_ = truncatef32(w); } } -if (typeof SIMD.int8x16.fromInt32x4Bits === "undefined") { +if (typeof SIMD.Float32x4.extractLane === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @return {int8x16} a bit-wise copy of t as a int8x16. + * @param {Float32x4} t An instance of Float32x4. + * @param {integer} i Index in concatenation of t for lane i + * @return {double} The value in lane i of t. */ - SIMD.int8x16.fromInt32x4Bits = function(t) { - _SIMD_PRIVATE.saveInt32x4(t); - return _SIMD_PRIVATE.restoreInt8x16(); + SIMD.Float32x4.extractLane = function(t, i) { + t = SIMD.Float32x4.check(t); + check4(i); + switch(i) { + case 0: return t.x_; + case 1: return t.y_; + case 2: return t.z_; + case 3: return t.w_; + } } } -if (typeof SIMD.int8x16.fromInt16x8Bits === "undefined") { +if (typeof SIMD.Float32x4.replaceLane === "undefined") { /** - * @param {int16x8} t An instance of int16x8. - * @return {int8x16} a bit-wise copy of t as a int8x16. + * @param {Float32x4} t An instance of Float32x4. + * @param {integer} i Index in concatenation of t for lane i + * @param {double} value used for lane i. + * @return {Float32x4} New instance of Float32x4 with the values in t and + * lane i replaced with {v}. */ - SIMD.int8x16.fromInt16x8Bits = function(t) { - _SIMD_PRIVATE.saveInt16x8(t); - return _SIMD_PRIVATE.restoreInt8x16(); + SIMD.Float32x4.replaceLane = function(t, i, v) { + t = SIMD.Float32x4.check(t); + check4(i); + saveFloat32x4(t); + _f32x4[i] = v; + return restoreFloat32x4(); } } -if (typeof SIMD.float32x4.abs === "undefined") { +if (typeof SIMD.Float32x4.check === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float32x4} New instance of float32x4 with absolute values of - * t. - */ - SIMD.float32x4.abs = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(Math.abs(t.x), Math.abs(t.y), Math.abs(t.z), - Math.abs(t.w)); + * Check whether the argument is a Float32x4. + * @param {Float32x4} v An instance of Float32x4. + * @return {Float32x4} The Float32x4 instance. + */ + SIMD.Float32x4.check = function(v) { + if (!(v instanceof SIMD.Float32x4)) { + throw new TypeError("argument is not a Float32x4."); + } + return v; } } -if (typeof SIMD.float32x4.neg === "undefined") { +if (typeof SIMD.Float32x4.splat === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float32x4} New instance of float32x4 with negated values of - * t. + * Construct a new instance of Float32x4 with the same value + * in all lanes. + * @param {double} value used for all lanes. + * @constructor */ - SIMD.float32x4.neg = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(-t.x, -t.y, -t.z, -t.w); + SIMD.Float32x4.splat = function(s) { + return SIMD.Float32x4(s, s, s, s); } } -if (typeof SIMD.float32x4.add === "undefined") { +if (typeof SIMD.Float32x4.fromInt32x4 === "undefined") { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with a + b. + * @param {Int32x4} t An instance of Int32x4. + * @return {Float32x4} An integer to float conversion copy of t. */ - SIMD.float32x4.add = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - return SIMD.float32x4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + SIMD.Float32x4.fromInt32x4 = function(t) { + t = SIMD.Int32x4.check(t); + return SIMD.Float32x4(SIMD.Int32x4.extractLane(t, 0), + SIMD.Int32x4.extractLane(t, 1), + SIMD.Int32x4.extractLane(t, 2), + SIMD.Int32x4.extractLane(t, 3)); } } -if (typeof SIMD.float32x4.sub === "undefined") { +if (typeof SIMD.Float32x4.fromInt32x4Bits === "undefined") { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with a - b. - */ - SIMD.float32x4.sub = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - return SIMD.float32x4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + * @param {Int32x4} t An instance of Int32x4. + * @return {Float32x4} a bit-wise copy of t as a Float32x4. + */ + SIMD.Float32x4.fromInt32x4Bits = function(t) { + saveInt32x4(t); + return restoreFloat32x4(); } } -if (typeof SIMD.float32x4.mul === "undefined") { +if (typeof SIMD.Float32x4.fromInt16x8Bits === "undefined") { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with a * b. - */ - SIMD.float32x4.mul = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - return SIMD.float32x4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + * @param {Int16x8} t An instance of Int16x8. + * @return {Float32x4} a bit-wise copy of t as a Float32x4. + */ + SIMD.Float32x4.fromInt16x8Bits = function(t) { + saveInt16x8(t); + return restoreFloat32x4(); } } -if (typeof SIMD.float32x4.div === "undefined") { +if (typeof SIMD.Float32x4.fromInt8x16Bits === "undefined") { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with a / b. - */ - SIMD.float32x4.div = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - return SIMD.float32x4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); + * @param {Int8x16} t An instance of Int8x16. + * @return {Float32x4} a bit-wise copy of t as a Float32x4. + */ + SIMD.Float32x4.fromInt8x16Bits = function(t) { + saveInt8x16(t); + return restoreFloat32x4(); } } -if (typeof SIMD.float32x4.clamp === "undefined") { +if (!Object.hasOwnProperty(SIMD.Float32x4.prototype, 'toString')) { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} lowerLimit An instance of float32x4. - * @param {float32x4} upperLimit An instance of float32x4. - * @return {float32x4} New instance of float32x4 with t's values clamped - * between lowerLimit and upperLimit. - */ - SIMD.float32x4.clamp = function(t, lowerLimit, upperLimit) { - t = SIMD.float32x4.check(t); - lowerLimit = SIMD.float32x4.check(lowerLimit); - upperLimit = SIMD.float32x4.check(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 SIMD.float32x4(cx, cy, cz, cw); + * @return {String} a string representing the Float32x4. + */ + SIMD.Float32x4.prototype.toString = function() { + return "SIMD.Float32x4(" + + this.x_ + ", " + + this.y_ + ", " + + this.z_ + ", " + + this.w_ + ")" } } -if (typeof SIMD.float32x4.min === "undefined") { +if (!Object.hasOwnProperty(SIMD.Float32x4.prototype, 'toLocaleString')) { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {float32x4} New instance of float32x4 with the minimum value of - * t and other. - */ - SIMD.float32x4.min = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(other); - var cx = Math.min(t.x, other.x); - var cy = Math.min(t.y, other.y); - var cz = Math.min(t.z, other.z); - var cw = Math.min(t.w, other.w); - return SIMD.float32x4(cx, cy, cz, cw); + * @return {String} a locale-sensitive string representing the Float32x4. + */ + SIMD.Float32x4.prototype.toLocaleString = function() { + return "SIMD.Float32x4(" + + this.x_.toLocaleString() + ", " + + this.y_.toLocaleString() + ", " + + this.z_.toLocaleString() + ", " + + this.w_.toLocaleString() + ")" } } -if (typeof SIMD.float32x4.max === "undefined") { - /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {float32x4} New instance of float32x4 with the maximum value of - * t and other. - */ - SIMD.float32x4.max = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(other); - var cx = Math.max(t.x, other.x); - var cy = Math.max(t.y, other.y); - var cz = Math.max(t.z, other.z); - var cw = Math.max(t.w, other.w); - return SIMD.float32x4(cx, cy, cz, cw); +if (!Object.hasOwnProperty(SIMD.Float32x4.prototype, 'valueOf')) { + SIMD.Float32x4.prototype.valueOf = function() { + throw new TypeError("Float32x4 cannot be converted to a number"); } } -if (typeof SIMD.float32x4.minNum === "undefined") { +if (typeof SIMD.Int32x4 === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {float32x4} New instance of float32x4 with the minimum value of - * t and other, preferring numbers over NaNs. + * Construct a new instance of Int32x4 number. + * @param {integer} 32-bit value used for x lane. + * @param {integer} 32-bit value used for y lane. + * @param {integer} 32-bit value used for z lane. + * @param {integer} 32-bit value used for w lane. + * @constructor */ - SIMD.float32x4.minNum = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(other); - var cx = _SIMD_PRIVATE.minNum(t.x, other.x); - var cy = _SIMD_PRIVATE.minNum(t.y, other.y); - var cz = _SIMD_PRIVATE.minNum(t.z, other.z); - var cw = _SIMD_PRIVATE.minNum(t.w, other.w); - return SIMD.float32x4(cx, cy, cz, cw); + SIMD.Int32x4 = function(x, y, z, w) { + if (!(this instanceof SIMD.Int32x4)) { + return new SIMD.Int32x4(x, y, z, w); + } + + this.x_ = x|0; + this.y_ = y|0; + this.z_ = z|0; + this.w_ = w|0; } } -if (typeof SIMD.float32x4.maxNum === "undefined") { +if (typeof SIMD.Int32x4.extractLane === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {float32x4} New instance of float32x4 with the maximum value of - * t and other, preferring numbers over NaNs. + * @param {Int32x4} t An instance of Int32x4. + * @param {integer} i Index in concatenation of t for lane i + * @return {integer} The value in lane i of t. */ - SIMD.float32x4.maxNum = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(other); - var cx = _SIMD_PRIVATE.maxNum(t.x, other.x); - var cy = _SIMD_PRIVATE.maxNum(t.y, other.y); - var cz = _SIMD_PRIVATE.maxNum(t.z, other.z); - var cw = _SIMD_PRIVATE.maxNum(t.w, other.w); - return SIMD.float32x4(cx, cy, cz, cw); + SIMD.Int32x4.extractLane = function(t, i) { + t = SIMD.Int32x4.check(t); + check4(i); + switch(i) { + case 0: return t.x_; + case 1: return t.y_; + case 2: return t.z_; + case 3: return t.w_; + } } } -if (typeof SIMD.float32x4.reciprocalApproximation === "undefined") { +if (typeof SIMD.Int32x4.replaceLane === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float32x4} New instance of float32x4 with an approximation of the - * reciprocal value of t. + * @param {Int32x4} t An instance of Int32x4. + * @param {integer} i Index in concatenation of t for lane i + * @param {integer} value used for lane i. + * @return {Int32x4} New instance of Int32x4 with the values in t and + * lane i replaced with {v}. */ - SIMD.float32x4.reciprocalApproximation = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(1.0 / t.x, 1.0 / t.y, 1.0 / t.z, 1.0 / t.w); + SIMD.Int32x4.replaceLane = function(t, i, v) { + t = SIMD.Int32x4.check(t); + check4(i); + saveInt32x4(t); + _i32x4[i] = v; + return restoreInt32x4(); } } -if (typeof SIMD.float32x4.reciprocalSqrtApproximation === "undefined") { +if (typeof SIMD.Int32x4.check === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float32x4} New instance of float32x4 with an approximation of the - * square root of the reciprocal value of t. + * Check whether the argument is a Int32x4. + * @param {Int32x4} v An instance of Int32x4. + * @return {Int32x4} The Int32x4 instance. */ - SIMD.float32x4.reciprocalSqrtApproximation = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.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)); + SIMD.Int32x4.check = function(v) { + if (!(v instanceof SIMD.Int32x4)) { + throw new TypeError("argument is not a Int32x4."); + } + return v; } } -if (typeof SIMD.float32x4.sqrt === "undefined") { +if (typeof SIMD.Int32x4.splat === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @return {float32x4} New instance of float32x4 with square root of - * values of t. + * Construct a new instance of Int32x4 with the same value + * in all lanes. + * @param {integer} value used for all lanes. + * @constructor */ - SIMD.float32x4.sqrt = function(t) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(Math.sqrt(t.x), Math.sqrt(t.y), - Math.sqrt(t.z), Math.sqrt(t.w)); + SIMD.Int32x4.splat = function(s) { + return SIMD.Int32x4(s, s, s, s); } } -if (typeof SIMD.float32x4.swizzle === "undefined") { +if (typeof SIMD.Int32x4.fromFloat32x4 === "undefined") { /** - * @param {float32x4} t An instance of float32x4 to be swizzled. - * @param {integer} x - Index in t for lane x - * @param {integer} y - Index in t for lane y - * @param {integer} z - Index in t for lane z - * @param {integer} w - Index in t for lane w - * @return {float32x4} New instance of float32x4 with lanes swizzled. + * @param {Float32x4} t An instance of Float32x4. + * @return {Int32x4} with a integer to float conversion of t. */ - SIMD.float32x4.swizzle = function(t, x, y, z, w) { - t = SIMD.float32x4.check(t); - _SIMD_PRIVATE._f32x4[0] = t.x; - _SIMD_PRIVATE._f32x4[1] = t.y; - _SIMD_PRIVATE._f32x4[2] = t.z; - _SIMD_PRIVATE._f32x4[3] = t.w; - var storage = _SIMD_PRIVATE._f32x4; - return SIMD.float32x4(storage[x], storage[y], storage[z], storage[w]); + SIMD.Int32x4.fromFloat32x4 = function(t) { + t = SIMD.Float32x4.check(t); + return SIMD.Int32x4(int32FromFloat(SIMD.Float32x4.extractLane(t, 0)), + int32FromFloat(SIMD.Float32x4.extractLane(t, 1)), + int32FromFloat(SIMD.Float32x4.extractLane(t, 2)), + int32FromFloat(SIMD.Float32x4.extractLane(t, 3))); } } -if (typeof SIMD.float32x4.shuffle === "undefined") { - - _SIMD_PRIVATE._f32x8 = new Float32Array(8); - +if (typeof SIMD.Int32x4.fromFloat32x4Bits === "undefined") { /** - * @param {float32x4} t1 An instance of float32x4 to be shuffled. - * @param {float32x4} t2 An instance of float32x4 to be shuffled. - * @param {integer} x - Index in concatenation of t1 and t2 for lane x - * @param {integer} y - Index in concatenation of t1 and t2 for lane y - * @param {integer} z - Index in concatenation of t1 and t2 for lane z - * @param {integer} w - Index in concatenation of t1 and t2 for lane w - * @return {float32x4} New instance of float32x4 with lanes shuffled. + * @param {Float32x4} t An instance of Float32x4. + * @return {Int32x4} a bit-wise copy of t as a Int32x4. */ - SIMD.float32x4.shuffle = function(t1, t2, x, y, z, w) { - t1 = SIMD.float32x4.check(t1); - t2 = SIMD.float32x4.check(t2); - var storage = _SIMD_PRIVATE._f32x8; - storage[0] = t1.x; - storage[1] = t1.y; - storage[2] = t1.z; - storage[3] = t1.w; - storage[4] = t2.x; - storage[5] = t2.y; - storage[6] = t2.z; - storage[7] = t2.w; - return SIMD.float32x4(storage[x], storage[y], storage[z], storage[w]); + SIMD.Int32x4.fromFloat32x4Bits = function(t) { + saveFloat32x4(t); + return restoreInt32x4(); } } -if (typeof SIMD.float32x4.withX === "undefined") { +if (typeof SIMD.Int32x4.fromInt16x8Bits === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {double} value used for x lane. - * @return {float32x4} New instance of float32x4 with the values in t and - * x replaced with {x}. + * @param {Int16x8} t An instance of Int16x8. + * @return {Int32x4} a bit-wise copy of t as a Int32x4. */ - SIMD.float32x4.withX = function(t, x) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(x, t.y, t.z, t.w); + SIMD.Int32x4.fromInt16x8Bits = function(t) { + saveInt16x8(t); + return restoreInt32x4(); } } -if (typeof SIMD.float32x4.withY === "undefined") { +if (typeof SIMD.Int32x4.fromInt8x16Bits === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {double} value used for y lane. - * @return {float32x4} New instance of float32x4 with the values in t and - * y replaced with {y}. + * @param {Int8x16} t An instance of Int8x16. + * @return {Int32x4} a bit-wise copy of t as a Int32x4. */ - SIMD.float32x4.withY = function(t, y) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(t.x, y, t.z, t.w); + SIMD.Int32x4.fromInt8x16Bits = function(t) { + saveInt8x16(t); + return restoreInt32x4(); } } -if (typeof SIMD.float32x4.withZ === "undefined") { +if (!Object.hasOwnProperty(SIMD.Int32x4.prototype, 'toString')) { /** - * @param {float32x4} t An instance of float32x4. - * @param {double} value used for z lane. - * @return {float32x4} New instance of float32x4 with the values in t and - * z replaced with {z}. - */ - SIMD.float32x4.withZ = function(t, z) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(t.x, t.y, z, t.w); + * @return {String} a string representing the Int32x4. + */ + SIMD.Int32x4.prototype.toString = function() { + return "SIMD.Int32x4(" + + this.x_ + ", " + + this.y_ + ", " + + this.z_ + ", " + + this.w_ + ")"; } } -if (typeof SIMD.float32x4.withW === "undefined") { +if (!Object.hasOwnProperty(SIMD.Int32x4.prototype, 'toLocaleString')) { /** - * @param {float32x4} t An instance of float32x4. - * @param {double} value used for w lane. - * @return {float32x4} New instance of float32x4 with the values in t and - * w replaced with {w}. - */ - SIMD.float32x4.withW = function(t, w) { - t = SIMD.float32x4.check(t); - return SIMD.float32x4(t.x, t.y, t.z, w); + * @return {String} a locale-sensitive string representing the Int32x4. + */ + SIMD.Int32x4.prototype.toLocaleString = function() { + return "SIMD.Int32x4(" + + this.x_.toLocaleString() + ", " + + this.y_.toLocaleString() + ", " + + this.z_.toLocaleString() + ", " + + this.w_.toLocaleString() + ")"; } } -if (typeof SIMD.float32x4.lessThan === "undefined") { - /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {int32x4} true or false in each lane depending on - * the result of t < other. - */ - SIMD.float32x4.lessThan = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); +if (!Object.hasOwnProperty(SIMD.Int32x4.prototype, 'valueOf')) { + SIMD.Int32x4.prototype.valueOf = function() { + throw new TypeError("Int32x4 cannot be converted to a number"); } } -if (typeof SIMD.float32x4.lessThanOrEqual === "undefined") { +if (typeof SIMD.Int16x8 === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {int32x4} true or false in each lane depending on - * the result of t <= other. + * Construct a new instance of Int16x8 number. + * @param {integer} 16-bit value used for s0 lane. + * @param {integer} 16-bit value used for s1 lane. + * @param {integer} 16-bit value used for s2 lane. + * @param {integer} 16-bit value used for s3 lane. + * @param {integer} 16-bit value used for s4 lane. + * @param {integer} 16-bit value used for s5 lane. + * @param {integer} 16-bit value used for s6 lane. + * @param {integer} 16-bit value used for s7 lane. + * @constructor */ - SIMD.float32x4.lessThanOrEqual = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int16x8 = function(s0, s1, s2, s3, s4, s5, s6, s7) { + if (!(this instanceof SIMD.Int16x8)) { + return new SIMD.Int16x8(s0, s1, s2, s3, s4, s5, s6, s7); + } + + this.s0_ = s0 << 16 >> 16; + this.s1_ = s1 << 16 >> 16; + this.s2_ = s2 << 16 >> 16; + this.s3_ = s3 << 16 >> 16; + this.s4_ = s4 << 16 >> 16; + this.s5_ = s5 << 16 >> 16; + this.s6_ = s6 << 16 >> 16; + this.s7_ = s7 << 16 >> 16; } } -if (typeof SIMD.float32x4.equal === "undefined") { +if (typeof SIMD.Int16x8.extractLane === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {int32x4} true or false in each lane depending on - * the result of t == other. + * @param {Int16x8} t An instance of Int16x8. + * @param {integer} i Index in concatenation of t for lane i + * @return {integer} The value in lane i of t. */ - SIMD.float32x4.equal = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int16x8.extractLane = function(t, i) { + t = SIMD.Int16x8.check(t); + check8(i); + switch(i) { + case 0: return t.s0_; + case 1: return t.s1_; + case 2: return t.s2_; + case 3: return t.s3_; + case 4: return t.s4_; + case 5: return t.s5_; + case 6: return t.s6_; + case 7: return t.s7_; + } } } -if (typeof SIMD.float32x4.notEqual === "undefined") { +if (typeof SIMD.Int16x8.unsignedExtractLane === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {int32x4} true or false in each lane depending on - * the result of t != other. + * @param {Int16x8} t An instance of Int16x8. + * @param {integer} i Index in concatenation of t for lane i + * @return {integer} The value in lane i of t extracted as an unsigned value. */ - SIMD.float32x4.notEqual = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int16x8.unsignedExtractLane = function(t, i) { + t = SIMD.Int16x8.check(t); + check8(i); + switch(i) { + case 0: return t.s0_ & 0xffff; + case 1: return t.s1_ & 0xffff; + case 2: return t.s2_ & 0xffff; + case 3: return t.s3_ & 0xffff; + case 4: return t.s4_ & 0xffff; + case 5: return t.s5_ & 0xffff; + case 6: return t.s6_ & 0xffff; + case 7: return t.s7_ & 0xffff; + } } } -if (typeof SIMD.float32x4.greaterThanOrEqual === "undefined") { +if (typeof SIMD.Int16x8.replaceLane === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {int32x4} true or false in each lane depending on - * the result of t >= other. + * @param {Int16x8} t An instance of Int16x8. + * @param {integer} i Index in concatenation of t for lane i + * @param {integer} value used for lane i. + * @return {Int16x8} New instance of Int16x8 with the values in t and + * lane i replaced with {v}. */ - SIMD.float32x4.greaterThanOrEqual = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int16x8.replaceLane = function(t, i, v) { + t = SIMD.Int16x8.check(t); + check8(i); + saveInt16x8(t); + _i16x8[i] = v; + return restoreInt16x8(); } } -if (typeof SIMD.float32x4.greaterThan === "undefined") { +if (typeof SIMD.Int16x8.check === "undefined") { /** - * @param {float32x4} t An instance of float32x4. - * @param {float32x4} other An instance of float32x4. - * @return {int32x4} true or false in each lane depending on - * the result of t > other. + * Check whether the argument is a Int16x8. + * @param {Int16x8} v An instance of Int16x8. + * @return {Int16x8} The Int16x8 instance. */ - SIMD.float32x4.greaterThan = function(t, other) { - t = SIMD.float32x4.check(t); - other = SIMD.float32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int16x8.check = function(v) { + if (!(v instanceof SIMD.Int16x8)) { + throw new TypeError("argument is not a Int16x8."); + } + return v; } } -if (typeof SIMD.float32x4.select === "undefined") { +if (typeof SIMD.Int16x8.splat === "undefined") { /** - * @param {int32x4} t Selector mask. An instance of int32x4 - * @param {float32x4} trueValue Pick lane from here if corresponding - * selector lane is true - * @param {float32x4} falseValue Pick lane from here if corresponding - * selector lane is false - * @return {float32x4} Mix of lanes from trueValue or falseValue as - * indicated + * Construct a new instance of Int16x8 with the same value + * in all lanes. + * @param {integer} value used for all lanes. + * @constructor */ - SIMD.float32x4.select = function(t, trueValue, falseValue) { - t = SIMD.int32x4.check(t); - trueValue = SIMD.float32x4.check(trueValue); - falseValue = SIMD.float32x4.check(falseValue); - return SIMD.float32x4(_SIMD_PRIVATE.tobool(t.x) ? trueValue.x : falseValue.x, - _SIMD_PRIVATE.tobool(t.y) ? trueValue.y : falseValue.y, - _SIMD_PRIVATE.tobool(t.z) ? trueValue.z : falseValue.z, - _SIMD_PRIVATE.tobool(t.w) ? trueValue.w : falseValue.w); + SIMD.Int16x8.splat = function(s) { + return SIMD.Int16x8(s, s, s, s, s, s, s, s); } } -if (typeof SIMD.float32x4.bitselect === "undefined") { +if (typeof SIMD.Int16x8.fromFloat32x4Bits === "undefined") { /** - * @param {int32x4} t Selector mask. An instance of int32x4 - * @param {float32x4} trueValue Pick bit from here if corresponding - * selector bit is 1 - * @param {float32x4} falseValue Pick bit from here if corresponding - * selector bit is 0 - * @return {float32x4} Mix of bits from trueValue or falseValue as - * indicated + * @param {Float32x4} t An instance of Float32x4. + * @return {Int16x8} a bit-wise copy of t as a Int16x8. */ - SIMD.float32x4.bitselect = function(t, trueValue, falseValue) { - t = SIMD.int32x4.check(t); - trueValue = SIMD.float32x4.check(trueValue); - falseValue = SIMD.float32x4.check(falseValue); - var tv = SIMD.int32x4.fromFloat32x4Bits(trueValue); - var fv = SIMD.int32x4.fromFloat32x4Bits(falseValue); - var tr = SIMD.int32x4.and(t, tv); - var fr = SIMD.int32x4.and(SIMD.int32x4.not(t), fv); - return SIMD.float32x4.fromInt32x4Bits(SIMD.int32x4.or(tr, fr)); + SIMD.Int16x8.fromFloat32x4Bits = function(t) { + saveFloat32x4(t); + return restoreInt16x8(); } } -if (typeof SIMD.float32x4.and === "undefined") { +if (typeof SIMD.Int16x8.fromInt32x4Bits === "undefined") { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with values of a & b. + * @param {Int32x4} t An instance of Int32x4. + * @return {Int16x8} a bit-wise copy of t as a Int16x8. */ - SIMD.float32x4.and = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - var aInt = SIMD.int32x4.fromFloat32x4Bits(a); - var bInt = SIMD.int32x4.fromFloat32x4Bits(b); - return SIMD.float32x4.fromInt32x4Bits(SIMD.int32x4.and(aInt, bInt)); + SIMD.Int16x8.fromInt32x4Bits = function(t) { + saveInt32x4(t); + return restoreInt16x8(); } } -if (typeof SIMD.float32x4.or === "undefined") { +if (typeof SIMD.Int16x8.fromInt8x16Bits === "undefined") { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with values of a | b. + * @param {Int8x16} t An instance of Int8x16. + * @return {Int16x8} a bit-wise copy of t as a Int16x8. */ - SIMD.float32x4.or = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - var aInt = SIMD.int32x4.fromFloat32x4Bits(a); - var bInt = SIMD.int32x4.fromFloat32x4Bits(b); - return SIMD.float32x4.fromInt32x4Bits(SIMD.int32x4.or(aInt, bInt)); + SIMD.Int16x8.fromInt8x16Bits = function(t) { + saveInt8x16(t); + return restoreInt16x8(); } } -if (typeof SIMD.float32x4.xor === "undefined") { +if (!Object.hasOwnProperty(SIMD.Int16x8.prototype, 'toString')) { /** - * @param {float32x4} a An instance of float32x4. - * @param {float32x4} b An instance of float32x4. - * @return {float32x4} New instance of float32x4 with values of a ^ b. - */ - SIMD.float32x4.xor = function(a, b) { - a = SIMD.float32x4.check(a); - b = SIMD.float32x4.check(b); - var aInt = SIMD.int32x4.fromFloat32x4Bits(a); - var bInt = SIMD.int32x4.fromFloat32x4Bits(b); - return SIMD.float32x4.fromInt32x4Bits(SIMD.int32x4.xor(aInt, bInt)); + * @return {String} a string representing the Int16x8. + */ + SIMD.Int16x8.prototype.toString = function() { + return "SIMD.Int16x8(" + + this.s0_ + ", " + + this.s1_ + ", " + + this.s2_ + ", " + + this.s3_ + ", " + + this.s4_ + ", " + + this.s5_ + ", " + + this.s6_ + ", " + + this.s7_ + ")"; } } -if (typeof SIMD.float32x4.not === "undefined") { +if (!Object.hasOwnProperty(SIMD.Int16x8.prototype, 'toLocaleString')) { /** - * @param {float32x4} a An instance of float32x4. - * @return {float32x4} New instance of float32x4 with values of ~a. - */ - SIMD.float32x4.not = function(a) { - a = SIMD.float32x4.check(a); - var aInt = SIMD.int32x4.fromFloat32x4Bits(a); - return SIMD.float32x4.fromInt32x4Bits(SIMD.int32x4.not(aInt)); + * @return {String} a locale-sensitive string representing the Int16x8. + */ + SIMD.Int16x8.prototype.toLocaleString = function() { + return "SIMD.Int16x8(" + + this.s0_.toLocaleString() + ", " + + this.s1_.toLocaleString() + ", " + + this.s2_.toLocaleString() + ", " + + this.s3_.toLocaleString() + ", " + + this.s4_.toLocaleString() + ", " + + this.s5_.toLocaleString() + ", " + + this.s6_.toLocaleString() + ", " + + this.s7_.toLocaleString() + ")"; } } -if (typeof SIMD.float32x4.load === "undefined") { - /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @return {float32x4} New instance of float32x4. - */ - SIMD.float32x4.load = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 16) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - var f32temp = _SIMD_PRIVATE._f32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; - var n = 16 / bpe; - for (var i = 0; i < n; ++i) - array[i] = tarray[index + i]; - return SIMD.float32x4(f32temp[0], f32temp[1], f32temp[2], f32temp[3]); +if (!Object.hasOwnProperty(SIMD.Int16x8.prototype, 'valueOf')) { + SIMD.Int16x8.prototype.valueOf = function() { + throw new TypeError("Int16x8 cannot be converted to a number"); } } -if (typeof SIMD.float32x4.loadX === "undefined") { +if (typeof SIMD.Int8x16 === "undefined") { /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @return {float32x4} New instance of float32x4. + * Construct a new instance of Int8x16 number. + * @param {integer} 8-bit value used for s0 lane. + * @param {integer} 8-bit value used for s1 lane. + * @param {integer} 8-bit value used for s2 lane. + * @param {integer} 8-bit value used for s3 lane. + * @param {integer} 8-bit value used for s4 lane. + * @param {integer} 8-bit value used for s5 lane. + * @param {integer} 8-bit value used for s6 lane. + * @param {integer} 8-bit value used for s7 lane. + * @param {integer} 8-bit value used for s8 lane. + * @param {integer} 8-bit value used for s9 lane. + * @param {integer} 8-bit value used for s10 lane. + * @param {integer} 8-bit value used for s11 lane. + * @param {integer} 8-bit value used for s12 lane. + * @param {integer} 8-bit value used for s13 lane. + * @param {integer} 8-bit value used for s14 lane. + * @param {integer} 8-bit value used for s15 lane. + * @constructor */ - SIMD.float32x4.loadX = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 4) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - var f32temp = _SIMD_PRIVATE._f32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; - var n = 4 / bpe; - for (var i = 0; i < n; ++i) - array[i] = tarray[index + i]; - return SIMD.float32x4(f32temp[0], 0.0, 0.0, 0.0); + SIMD.Int8x16 = function(s0, s1, s2, s3, s4, s5, s6, s7, + s8, s9, s10, s11, s12, s13, s14, s15) { + if (!(this instanceof SIMD.Int8x16)) { + return new SIMD.Int8x16(s0, s1, s2, s3, s4, s5, s6, s7, + s8, s9, s10, s11, s12, s13, s14, s15); + } + + this.s0_ = s0 << 24 >> 24; + this.s1_ = s1 << 24 >> 24; + this.s2_ = s2 << 24 >> 24; + this.s3_ = s3 << 24 >> 24; + this.s4_ = s4 << 24 >> 24; + this.s5_ = s5 << 24 >> 24; + this.s6_ = s6 << 24 >> 24; + this.s7_ = s7 << 24 >> 24; + this.s8_ = s8 << 24 >> 24; + this.s9_ = s9 << 24 >> 24; + this.s10_ = s10 << 24 >> 24; + this.s11_ = s11 << 24 >> 24; + this.s12_ = s12 << 24 >> 24; + this.s13_ = s13 << 24 >> 24; + this.s14_ = s14 << 24 >> 24; + this.s15_ = s15 << 24 >> 24; } } -if (typeof SIMD.float32x4.loadXY === "undefined") { - /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @return {float32x4} New instance of float32x4. - */ - SIMD.float32x4.loadXY = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 8) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - var f32temp = _SIMD_PRIVATE._f32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; - var n = 8 / bpe; - for (var i = 0; i < n; ++i) - array[i] = tarray[index + i]; - return SIMD.float32x4(f32temp[0], f32temp[1], 0.0, 0.0); +if (typeof SIMD.Int8x16.extractLane === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {integer} i Index in concatenation of t for lane i + * @return {integer} The value in lane i of t. + */ + SIMD.Int8x16.extractLane = function(t, i) { + t = SIMD.Int8x16.check(t); + check16(i); + switch(i) { + case 0: return t.s0_; + case 1: return t.s1_; + case 2: return t.s2_; + case 3: return t.s3_; + case 4: return t.s4_; + case 5: return t.s5_; + case 6: return t.s6_; + case 7: return t.s7_; + case 8: return t.s8_; + case 9: return t.s9_; + case 10: return t.s10_; + case 11: return t.s11_; + case 12: return t.s12_; + case 13: return t.s13_; + case 14: return t.s14_; + case 15: return t.s15_; + } } } -if (typeof SIMD.float32x4.loadXYZ === "undefined") { +if (typeof SIMD.Int8x16.unsignedExtractLane === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {integer} i Index in concatenation of t for lane i + * @return {integer} The value in lane i of t extracted as an unsigned value. + */ + SIMD.Int8x16.unsignedExtractLane = function(t, i) { + t = SIMD.Int8x16.check(t); + check16(i); + switch(i) { + case 0: return t.s0_ & 0xff; + case 1: return t.s1_ & 0xff; + case 2: return t.s2_ & 0xff; + case 3: return t.s3_ & 0xff; + case 4: return t.s4_ & 0xff; + case 5: return t.s5_ & 0xff; + case 6: return t.s6_ & 0xff; + case 7: return t.s7_ & 0xff; + case 8: return t.s8_ & 0xff; + case 9: return t.s9_ & 0xff; + case 10: return t.s10_ & 0xff; + case 11: return t.s11_ & 0xff; + case 12: return t.s12_ & 0xff; + case 13: return t.s13_ & 0xff; + case 14: return t.s14_ & 0xff; + case 15: return t.s15_ & 0xff; + } + } +} + +if (typeof SIMD.Int8x16.replaceLane === "undefined") { /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @return {float32x4} New instance of float32x4. + * @param {Int8x16} t An instance of Int8x16. + * @param {integer} i Index in concatenation of t for lane i + * @param {integer} value used for lane i. + * @return {Int8x16} New instance of Int8x16 with the values in t and + * lane i replaced with {v}. */ - SIMD.float32x4.loadXYZ = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 12) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - var f32temp = _SIMD_PRIVATE._f32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; - var n = 12 / bpe; - for (var i = 0; i < n; ++i) - array[i] = tarray[index + i]; - return SIMD.float32x4(f32temp[0], f32temp[1], f32temp[2], 0.0); + SIMD.Int8x16.replaceLane = function(t, i, v) { + t = SIMD.Int8x16.check(t); + check16(i); + saveInt8x16(t); + _i8x16[i] = v; + return restoreInt8x16(); } } -if (typeof SIMD.float32x4.store === "undefined") { +if (typeof SIMD.Int8x16.check === "undefined") { /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @param {float32x4} value An instance of float32x4. - * @return {void} + * Check whether the argument is a Int8x16. + * @param {Int8x16} v An instance of Int8x16. + * @return {Int8x16} The Int8x16 instance. */ - SIMD.float32x4.store = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 16) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - value = SIMD.float32x4.check(value); - _SIMD_PRIVATE._f32x4[0] = value.x; - _SIMD_PRIVATE._f32x4[1] = value.y; - _SIMD_PRIVATE._f32x4[2] = value.z; - _SIMD_PRIVATE._f32x4[3] = value.w; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; - var n = 16 / bpe; - for (var i = 0; i < n; ++i) - tarray[index + i] = array[i]; + SIMD.Int8x16.check = function(v) { + if (!(v instanceof SIMD.Int8x16)) { + throw new TypeError("argument is not a Int8x16."); + } + return v; } } -if (typeof SIMD.float32x4.storeX === "undefined") { +if (typeof SIMD.Int8x16.splat === "undefined") { /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @param {float32x4} value An instance of float32x4. - * @return {void} + * Construct a new instance of Int8x16 with the same value + * in all lanes. + * @param {integer} value used for all lanes. + * @constructor */ - SIMD.float32x4.storeX = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 4) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - value = SIMD.float32x4.check(value); - if (bpe == 8) { - // tarray's elements are too wide. Just create a new view; this is rare. - var view = new Float32Array(tarray.buffer, tarray.byteOffset + index * 8, 1); - view[0] = value.x; - } else { - _SIMD_PRIVATE._f32x4[0] = value.x; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4); - var n = 4 / bpe; - for (var i = 0; i < n; ++i) - tarray[index + i] = array[i]; - } + SIMD.Int8x16.splat = function(s) { + return SIMD.Int8x16(s, s, s, s, s, s, s, s, + s, s, s, s, s, s, s, s); } } -if (typeof SIMD.float32x4.storeXY === "undefined") { +if (typeof SIMD.Int8x16.fromFloat32x4Bits === "undefined") { /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @param {float32x4} value An instance of float32x4. - * @return {void} + * @param {Float32x4} t An instance of Float32x4. + * @return {Int8x16} a bit-wise copy of t as a Int8x16. */ - SIMD.float32x4.storeXY = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 8) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - value = SIMD.float32x4.check(value); - _SIMD_PRIVATE._f32x4[0] = value.x; - _SIMD_PRIVATE._f32x4[1] = value.y; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; - var n = 8 / bpe; - for (var i = 0; i < n; ++i) - tarray[index + i] = array[i]; + SIMD.Int8x16.fromFloat32x4Bits = function(t) { + saveFloat32x4(t); + return restoreInt8x16(); } } -if (typeof SIMD.float32x4.storeXYZ === "undefined") { +if (typeof SIMD.Int8x16.fromInt32x4Bits === "undefined") { /** - * @param {Typed array} tarray An instance of a typed array. - * @param {Number} index An instance of Number. - * @param {float32x4} value An instance of float32x4. - * @return {void} + * @param {Int32x4} t An instance of Int32x4. + * @return {Int8x16} a bit-wise copy of t as a Int8x16. */ - SIMD.float32x4.storeXYZ = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) - throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); - var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 12) > tarray.byteLength) - throw new RangeError("The value of index is invalid."); - value = SIMD.float32x4.check(value); - if (bpe == 8) { - // tarray's elements are too wide. Just create a new view; this is rare. - var view = new Float32Array(tarray.buffer, tarray.byteOffset + index * 8, 3); - view[0] = value.x; - view[1] = value.y; - view[2] = value.z; - } else { - _SIMD_PRIVATE._f32x4[0] = value.x; - _SIMD_PRIVATE._f32x4[1] = value.y; - _SIMD_PRIVATE._f32x4[2] = value.z; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4); - var n = 12 / bpe; - for (var i = 0; i < n; ++i) - tarray[index + i] = array[i]; - } + SIMD.Int8x16.fromInt32x4Bits = function(t) { + saveInt32x4(t); + return restoreInt8x16(); + } +} + +if (typeof SIMD.Int8x16.fromInt16x8Bits === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @return {Int8x16} a bit-wise copy of t as a Int8x16. + */ + SIMD.Int8x16.fromInt16x8Bits = function(t) { + saveInt16x8(t); + return restoreInt8x16(); } } -if (typeof SIMD.float64x2.abs === "undefined") { +if (!Object.hasOwnProperty(SIMD.Int8x16.prototype, 'toString')) { /** - * @param {float64x2} t An instance of float64x2. - * @return {float64x2} New instance of float64x2 with absolute values of - * t. + * @return {String} a string representing the Int8x16. */ - SIMD.float64x2.abs = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(Math.abs(t.x), Math.abs(t.y)); + SIMD.Int8x16.prototype.toString = function() { + return "SIMD.Int8x16(" + + this.s0_ + ", " + + this.s1_ + ", " + + this.s2_ + ", " + + this.s3_ + ", " + + this.s4_ + ", " + + this.s5_ + ", " + + this.s6_ + ", " + + this.s7_ + ", " + + this.s8_ + ", " + + this.s9_ + ", " + + this.s10_ + ", " + + this.s11_ + ", " + + this.s12_ + ", " + + this.s13_ + ", " + + this.s14_ + ", " + + this.s15_ + ")"; + } +} + +if (!Object.hasOwnProperty(SIMD.Int8x16.prototype, 'toLocaleString')) { + /** + * @return {String} a locale-sensitive string representing the Int8x16. + */ + SIMD.Int8x16.prototype.toLocaleString = function() { + return "SIMD.Int8x16(" + + this.s0_.toLocaleString() + ", " + + this.s1_.toLocaleString() + ", " + + this.s2_.toLocaleString() + ", " + + this.s3_.toLocaleString() + ", " + + this.s4_.toLocaleString() + ", " + + this.s5_.toLocaleString() + ", " + + this.s6_.toLocaleString() + ", " + + this.s7_.toLocaleString() + ", " + + this.s8_.toLocaleString() + ", " + + this.s9_.toLocaleString() + ", " + + this.s10_.toLocaleString() + ", " + + this.s11_.toLocaleString() + ", " + + this.s12_.toLocaleString() + ", " + + this.s13_.toLocaleString() + ", " + + this.s14_.toLocaleString() + ", " + + this.s15_.toLocaleString() + ")"; + } +} + +if (!Object.hasOwnProperty(SIMD.Int8x16.prototype, 'valueOf')) { + SIMD.Int8x16.prototype.valueOf = function() { + throw new TypeError("Int8x16 cannot be converted to a number"); } } -if (typeof SIMD.float64x2.neg === "undefined") { +if (typeof SIMD.Float32x4.abs === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {float64x2} New instance of float64x2 with negated values of - * t. - */ - SIMD.float64x2.neg = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(-t.x, -t.y); + * @param {Float32x4} t An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with absolute values of + * t. + */ + SIMD.Float32x4.abs = function(t) { + t = SIMD.Float32x4.check(t); + return SIMD.Float32x4(Math.abs(SIMD.Float32x4.extractLane(t, 0)), + Math.abs(SIMD.Float32x4.extractLane(t, 1)), + Math.abs(SIMD.Float32x4.extractLane(t, 2)), + Math.abs(SIMD.Float32x4.extractLane(t, 3))); } } -if (typeof SIMD.float64x2.add === "undefined") { +if (typeof SIMD.Float32x4.neg === "undefined") { /** - * @param {float64x2} a An instance of float64x2. - * @param {float64x2} b An instance of float64x2. - * @return {float64x2} New instance of float64x2 with a + b. + * @param {Float32x4} t An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with negated values of + * t. */ - SIMD.float64x2.add = function(a, b) { - a = SIMD.float64x2.check(a); - b = SIMD.float64x2.check(b); - return SIMD.float64x2(a.x + b.x, a.y + b.y); + SIMD.Float32x4.neg = function(t) { + t = SIMD.Float32x4.check(t); + return SIMD.Float32x4(-SIMD.Float32x4.extractLane(t, 0), + -SIMD.Float32x4.extractLane(t, 1), + -SIMD.Float32x4.extractLane(t, 2), + -SIMD.Float32x4.extractLane(t, 3)); } } -if (typeof SIMD.float64x2.sub === "undefined") { +if (typeof SIMD.Float32x4.add === "undefined") { /** - * @param {float64x2} a An instance of float64x2. - * @param {float64x2} b An instance of float64x2. - * @return {float64x2} New instance of float64x2 with a - b. + * @param {Float32x4} a An instance of Float32x4. + * @param {Float32x4} b An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with a + b. */ - SIMD.float64x2.sub = function(a, b) { - a = SIMD.float64x2.check(a); - b = SIMD.float64x2.check(b); - return SIMD.float64x2(a.x - b.x, a.y - b.y); + SIMD.Float32x4.add = function(a, b) { + a = SIMD.Float32x4.check(a); + b = SIMD.Float32x4.check(b); + return SIMD.Float32x4( + SIMD.Float32x4.extractLane(a, 0) + SIMD.Float32x4.extractLane(b, 0), + SIMD.Float32x4.extractLane(a, 1) + SIMD.Float32x4.extractLane(b, 1), + SIMD.Float32x4.extractLane(a, 2) + SIMD.Float32x4.extractLane(b, 2), + SIMD.Float32x4.extractLane(a, 3) + SIMD.Float32x4.extractLane(b, 3)); } } -if (typeof SIMD.float64x2.mul === "undefined") { +if (typeof SIMD.Float32x4.sub === "undefined") { /** - * @param {float64x2} a An instance of float64x2. - * @param {float64x2} b An instance of float64x2. - * @return {float64x2} New instance of float64x2 with a * b. + * @param {Float32x4} a An instance of Float32x4. + * @param {Float32x4} b An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with a - b. */ - SIMD.float64x2.mul = function(a, b) { - a = SIMD.float64x2.check(a); - b = SIMD.float64x2.check(b); - return SIMD.float64x2(a.x * b.x, a.y * b.y); + SIMD.Float32x4.sub = function(a, b) { + a = SIMD.Float32x4.check(a); + b = SIMD.Float32x4.check(b); + return SIMD.Float32x4( + SIMD.Float32x4.extractLane(a, 0) - SIMD.Float32x4.extractLane(b, 0), + SIMD.Float32x4.extractLane(a, 1) - SIMD.Float32x4.extractLane(b, 1), + SIMD.Float32x4.extractLane(a, 2) - SIMD.Float32x4.extractLane(b, 2), + SIMD.Float32x4.extractLane(a, 3) - SIMD.Float32x4.extractLane(b, 3)); } } -if (typeof SIMD.float64x2.div === "undefined") { +if (typeof SIMD.Float32x4.mul === "undefined") { /** - * @param {float64x2} a An instance of float64x2. - * @param {float64x2} b An instance of float64x2. - * @return {float64x2} New instance of float64x2 with a / b. + * @param {Float32x4} a An instance of Float32x4. + * @param {Float32x4} b An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with a * b. */ - SIMD.float64x2.div = function(a, b) { - a = SIMD.float64x2.check(a); - b = SIMD.float64x2.check(b); - return SIMD.float64x2(a.x / b.x, a.y / b.y); + SIMD.Float32x4.mul = function(a, b) { + a = SIMD.Float32x4.check(a); + b = SIMD.Float32x4.check(b); + return SIMD.Float32x4( + SIMD.Float32x4.extractLane(a, 0) * SIMD.Float32x4.extractLane(b, 0), + SIMD.Float32x4.extractLane(a, 1) * SIMD.Float32x4.extractLane(b, 1), + SIMD.Float32x4.extractLane(a, 2) * SIMD.Float32x4.extractLane(b, 2), + SIMD.Float32x4.extractLane(a, 3) * SIMD.Float32x4.extractLane(b, 3)); } } -if (typeof SIMD.float64x2.clamp === "undefined") { +if (typeof SIMD.Float32x4.div === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} lowerLimit An instance of float64x2. - * @param {float64x2} upperLimit An instance of float64x2. - * @return {float64x2} New instance of float64x2 with t's values clamped - * between lowerLimit and upperLimit. + * @param {Float32x4} a An instance of Float32x4. + * @param {Float32x4} b An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with a / b. */ - SIMD.float64x2.clamp = function(t, lowerLimit, upperLimit) { - t = SIMD.float64x2.check(t); - lowerLimit = SIMD.float64x2.check(lowerLimit); - upperLimit = SIMD.float64x2.check(upperLimit); - var cx = t.x < lowerLimit.x ? lowerLimit.x : t.x; - var cy = t.y < lowerLimit.y ? lowerLimit.y : t.y; - cx = cx > upperLimit.x ? upperLimit.x : cx; - cy = cy > upperLimit.y ? upperLimit.y : cy; - return SIMD.float64x2(cx, cy); + SIMD.Float32x4.div = function(a, b) { + a = SIMD.Float32x4.check(a); + b = SIMD.Float32x4.check(b); + return SIMD.Float32x4( + SIMD.Float32x4.extractLane(a, 0) / SIMD.Float32x4.extractLane(b, 0), + SIMD.Float32x4.extractLane(a, 1) / SIMD.Float32x4.extractLane(b, 1), + SIMD.Float32x4.extractLane(a, 2) / SIMD.Float32x4.extractLane(b, 2), + SIMD.Float32x4.extractLane(a, 3) / SIMD.Float32x4.extractLane(b, 3)); } } -if (typeof SIMD.float64x2.min === "undefined") { +if (typeof SIMD.Float32x4.min === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {float64x2} New instance of float64x2 with the minimum value of + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with the minimum value of * t and other. */ - SIMD.float64x2.min = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = Math.min(t.x, other.x); - var cy = Math.min(t.y, other.y); - return SIMD.float64x2(cx, cy); + SIMD.Float32x4.min = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = Math.min(SIMD.Float32x4.extractLane(t, 0), + SIMD.Float32x4.extractLane(other, 0)); + var cy = Math.min(SIMD.Float32x4.extractLane(t, 1), + SIMD.Float32x4.extractLane(other, 1)); + var cz = Math.min(SIMD.Float32x4.extractLane(t, 2), + SIMD.Float32x4.extractLane(other, 2)); + var cw = Math.min(SIMD.Float32x4.extractLane(t, 3), + SIMD.Float32x4.extractLane(other, 3)); + return SIMD.Float32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.max === "undefined") { +if (typeof SIMD.Float32x4.max === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {float64x2} New instance of float64x2 with the maximum value of + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with the maximum value of * t and other. */ - SIMD.float64x2.max = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = Math.max(t.x, other.x); - var cy = Math.max(t.y, other.y); - return SIMD.float64x2(cx, cy); + SIMD.Float32x4.max = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = Math.max(SIMD.Float32x4.extractLane(t, 0), + SIMD.Float32x4.extractLane(other, 0)); + var cy = Math.max(SIMD.Float32x4.extractLane(t, 1), + SIMD.Float32x4.extractLane(other, 1)); + var cz = Math.max(SIMD.Float32x4.extractLane(t, 2), + SIMD.Float32x4.extractLane(other, 2)); + var cw = Math.max(SIMD.Float32x4.extractLane(t, 3), + SIMD.Float32x4.extractLane(other, 3)); + return SIMD.Float32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.minNum === "undefined") { +if (typeof SIMD.Float32x4.minNum === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {float64x2} New instance of float64x2 with the minimum value of + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with the minimum value of * t and other, preferring numbers over NaNs. */ - SIMD.float64x2.minNum = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = _SIMD_PRIVATE.minNum(t.x, other.x); - var cy = _SIMD_PRIVATE.minNum(t.y, other.y); - return SIMD.float64x2(cx, cy); + SIMD.Float32x4.minNum = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = minNum(SIMD.Float32x4.extractLane(t, 0), + SIMD.Float32x4.extractLane(other, 0)); + var cy = minNum(SIMD.Float32x4.extractLane(t, 1), + SIMD.Float32x4.extractLane(other, 1)); + var cz = minNum(SIMD.Float32x4.extractLane(t, 2), + SIMD.Float32x4.extractLane(other, 2)); + var cw = minNum(SIMD.Float32x4.extractLane(t, 3), + SIMD.Float32x4.extractLane(other, 3)); + return SIMD.Float32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.maxNum === "undefined") { +if (typeof SIMD.Float32x4.maxNum === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {float64x2} New instance of float64x2 with the maximum value of + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with the maximum value of * t and other, preferring numbers over NaNs. */ - SIMD.float64x2.maxNum = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = _SIMD_PRIVATE.maxNum(t.x, other.x); - var cy = _SIMD_PRIVATE.maxNum(t.y, other.y); - return SIMD.float64x2(cx, cy); + SIMD.Float32x4.maxNum = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = maxNum(SIMD.Float32x4.extractLane(t, 0), + SIMD.Float32x4.extractLane(other, 0)); + var cy = maxNum(SIMD.Float32x4.extractLane(t, 1), + SIMD.Float32x4.extractLane(other, 1)); + var cz = maxNum(SIMD.Float32x4.extractLane(t, 2), + SIMD.Float32x4.extractLane(other, 2)); + var cw = maxNum(SIMD.Float32x4.extractLane(t, 3), + SIMD.Float32x4.extractLane(other, 3)); + return SIMD.Float32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.reciprocalApproximation === "undefined") { +if (typeof SIMD.Float32x4.reciprocalApproximation === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {float64x2} New instance of float64x2 with an approximation of the + * @param {Float32x4} t An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with an approximation of the * reciprocal value of t. */ - SIMD.float64x2.reciprocalApproximation = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(1.0 / t.x, 1.0 / t.y); + SIMD.Float32x4.reciprocalApproximation = function(t) { + t = SIMD.Float32x4.check(t); + return SIMD.Float32x4.div(SIMD.Float32x4.splat(1.0), t); } } -if (typeof SIMD.float64x2.reciprocalSqrtApproximation === "undefined") { +if (typeof SIMD.Float32x4.reciprocalSqrtApproximation === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {float64x2} New instance of float64x2 with an approximation of the - * square root of the reciprocal value of t. + * @param {Float32x4} t An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with an approximation of the + * reciprocal value of the square root of t. */ - SIMD.float64x2.reciprocalSqrtApproximation = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(Math.sqrt(1.0 / t.x), Math.sqrt(1.0 / t.y)); + SIMD.Float32x4.reciprocalSqrtApproximation = function(t) { + t = SIMD.Float32x4.check(t); + return SIMD.Float32x4.reciprocalApproximation(SIMD.Float32x4.sqrt(t)); } } -if (typeof SIMD.float64x2.sqrt === "undefined") { +if (typeof SIMD.Float32x4.sqrt === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @return {float64x2} New instance of float64x2 with square root of + * @param {Float32x4} t An instance of Float32x4. + * @return {Float32x4} New instance of Float32x4 with square root of * values of t. */ - SIMD.float64x2.sqrt = function(t) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(Math.sqrt(t.x), Math.sqrt(t.y)); + SIMD.Float32x4.sqrt = function(t) { + t = SIMD.Float32x4.check(t); + return SIMD.Float32x4(Math.sqrt(SIMD.Float32x4.extractLane(t, 0)), + Math.sqrt(SIMD.Float32x4.extractLane(t, 1)), + Math.sqrt(SIMD.Float32x4.extractLane(t, 2)), + Math.sqrt(SIMD.Float32x4.extractLane(t, 3))); } } -if (typeof SIMD.float64x2.swizzle === "undefined") { +if (typeof SIMD.Float32x4.swizzle === "undefined") { /** - * @param {float64x2} t An instance of float64x2 to be swizzled. + * @param {Float32x4} t An instance of Float32x4 to be swizzled. * @param {integer} x - Index in t for lane x * @param {integer} y - Index in t for lane y - * @return {float64x2} New instance of float64x2 with lanes swizzled. + * @param {integer} z - Index in t for lane z + * @param {integer} w - Index in t for lane w + * @return {Float32x4} New instance of Float32x4 with lanes swizzled. */ - SIMD.float64x2.swizzle = function(t, x, y) { - t = SIMD.float64x2.check(t); - var storage = _SIMD_PRIVATE._f64x2; - storage[0] = t.x; - storage[1] = t.y; - return SIMD.float64x2(storage[x], storage[y]); + SIMD.Float32x4.swizzle = function(t, x, y, z, w) { + t = SIMD.Float32x4.check(t); + check4(x); + check4(y); + check4(z); + check4(w); + _f32x4[0] = SIMD.Float32x4.extractLane(t, 0); + _f32x4[1] = SIMD.Float32x4.extractLane(t, 1); + _f32x4[2] = SIMD.Float32x4.extractLane(t, 2); + _f32x4[3] = SIMD.Float32x4.extractLane(t, 3); + var storage = _f32x4; + return SIMD.Float32x4(storage[x], storage[y], storage[z], storage[w]); } } -if (typeof SIMD.float64x2.shuffle === "undefined") { +if (typeof SIMD.Float32x4.shuffle === "undefined") { - _SIMD_PRIVATE._f64x4 = new Float64Array(4); + var _f32x8 = new Float32Array(8); /** - * @param {float64x2} t1 An instance of float64x2 to be shuffled. - * @param {float64x2} t2 An instance of float64x2 to be shuffled. + * @param {Float32x4} t1 An instance of Float32x4 to be shuffled. + * @param {Float32x4} t2 An instance of Float32x4 to be shuffled. * @param {integer} x - Index in concatenation of t1 and t2 for lane x * @param {integer} y - Index in concatenation of t1 and t2 for lane y - * @return {float64x2} New instance of float64x2 with lanes shuffled. - */ - SIMD.float64x2.shuffle = function(t1, t2, x, y) { - t1 = SIMD.float64x2.check(t1); - t2 = SIMD.float64x2.check(t2); - var storage = _SIMD_PRIVATE._f64x4; - storage[0] = t1.x; - storage[1] = t1.y; - storage[2] = t2.x; - storage[3] = t2.y; - return SIMD.float64x2(storage[x], storage[y]); - } -} - -if (typeof SIMD.float64x2.withX === "undefined") { - /** - * @param {float64x2} t An instance of float64x2. - * @param {double} value used for x lane. - * @return {float64x2} New instance of float64x2 with the values in t and - * x replaced with {x}. - */ - SIMD.float64x2.withX = function(t, x) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(x, t.y); - } -} - -if (typeof SIMD.float64x2.withY === "undefined") { - /** - * @param {float64x2} t An instance of float64x2. - * @param {double} value used for y lane. - * @return {float64x2} New instance of float64x2 with the values in t and - * y replaced with {y}. - */ - SIMD.float64x2.withY = function(t, y) { - t = SIMD.float64x2.check(t); - return SIMD.float64x2(t.x, y); - } -} - -if (typeof SIMD.float64x2.lessThan === "undefined") { - /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {int32x4} true or false in each lane depending on + * @param {integer} z - Index in concatenation of t1 and t2 for lane z + * @param {integer} w - Index in concatenation of t1 and t2 for lane w + * @return {Float32x4} New instance of Float32x4 with lanes shuffled. + */ + SIMD.Float32x4.shuffle = function(t1, t2, x, y, z, w) { + t1 = SIMD.Float32x4.check(t1); + t2 = SIMD.Float32x4.check(t2); + check8(x); + check8(y); + check8(z); + check8(w); + var storage = _f32x8; + storage[0] = SIMD.Float32x4.extractLane(t1, 0); + storage[1] = SIMD.Float32x4.extractLane(t1, 1); + storage[2] = SIMD.Float32x4.extractLane(t1, 2); + storage[3] = SIMD.Float32x4.extractLane(t1, 3); + storage[4] = SIMD.Float32x4.extractLane(t2, 0); + storage[5] = SIMD.Float32x4.extractLane(t2, 1); + storage[6] = SIMD.Float32x4.extractLane(t2, 2); + storage[7] = SIMD.Float32x4.extractLane(t2, 3); + return SIMD.Float32x4(storage[x], storage[y], storage[z], storage[w]); + } +} + +if (typeof SIMD.Float32x4.lessThan === "undefined") { + /** + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t < other. */ - SIMD.float64x2.lessThan = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = t.x < other.x; - var cy = t.y < other.y; - return SIMD.int32x4.bool(cx, cx, cy, cy); + SIMD.Float32x4.lessThan = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = + SIMD.Float32x4.extractLane(t, 0) < SIMD.Float32x4.extractLane(other, 0); + var cy = + SIMD.Float32x4.extractLane(t, 1) < SIMD.Float32x4.extractLane(other, 1); + var cz = + SIMD.Float32x4.extractLane(t, 2) < SIMD.Float32x4.extractLane(other, 2); + var cw = + SIMD.Float32x4.extractLane(t, 3) < SIMD.Float32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.lessThanOrEqual === "undefined") { +if (typeof SIMD.Float32x4.lessThanOrEqual === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {int32x4} true or false in each lane depending on + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t <= other. */ - SIMD.float64x2.lessThanOrEqual = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = t.x <= other.x; - var cy = t.y <= other.y; - return SIMD.int32x4.bool(cx, cx, cy, cy); + SIMD.Float32x4.lessThanOrEqual = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = SIMD.Float32x4.extractLane(t, 0) <= + SIMD.Float32x4.extractLane(other, 0); + var cy = SIMD.Float32x4.extractLane(t, 1) <= + SIMD.Float32x4.extractLane(other, 1); + var cz = SIMD.Float32x4.extractLane(t, 2) <= + SIMD.Float32x4.extractLane(other, 2); + var cw = SIMD.Float32x4.extractLane(t, 3) <= + SIMD.Float32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.equal === "undefined") { +if (typeof SIMD.Float32x4.equal === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {int32x4} true or false in each lane depending on + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t == other. */ - SIMD.float64x2.equal = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = t.x == other.x; - var cy = t.y == other.y; - return SIMD.int32x4.bool(cx, cx, cy, cy); + SIMD.Float32x4.equal = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = SIMD.Float32x4.extractLane(t, 0) == + SIMD.Float32x4.extractLane(other, 0); + var cy = SIMD.Float32x4.extractLane(t, 1) == + SIMD.Float32x4.extractLane(other, 1); + var cz = SIMD.Float32x4.extractLane(t, 2) == + SIMD.Float32x4.extractLane(other, 2); + var cw = SIMD.Float32x4.extractLane(t, 3) == + SIMD.Float32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.notEqual === "undefined") { +if (typeof SIMD.Float32x4.notEqual === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {int32x4} true or false in each lane depending on + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t != other. */ - SIMD.float64x2.notEqual = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = t.x != other.x; - var cy = t.y != other.y; - return SIMD.int32x4.bool(cx, cx, cy, cy); + SIMD.Float32x4.notEqual = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = SIMD.Float32x4.extractLane(t, 0) != + SIMD.Float32x4.extractLane(other, 0); + var cy = SIMD.Float32x4.extractLane(t, 1) != + SIMD.Float32x4.extractLane(other, 1); + var cz = SIMD.Float32x4.extractLane(t, 2) != + SIMD.Float32x4.extractLane(other, 2); + var cw = SIMD.Float32x4.extractLane(t, 3) != + SIMD.Float32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.greaterThanOrEqual === "undefined") { +if (typeof SIMD.Float32x4.greaterThanOrEqual === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {int32x4} true or false in each lane depending on + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t >= other. */ - SIMD.float64x2.greaterThanOrEqual = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = t.x >= other.x; - var cy = t.y >= other.y; - return SIMD.int32x4.bool(cx, cx, cy, cy); + SIMD.Float32x4.greaterThanOrEqual = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = SIMD.Float32x4.extractLane(t, 0) >= + SIMD.Float32x4.extractLane(other, 0); + var cy = SIMD.Float32x4.extractLane(t, 1) >= + SIMD.Float32x4.extractLane(other, 1); + var cz = SIMD.Float32x4.extractLane(t, 2) >= + SIMD.Float32x4.extractLane(other, 2); + var cw = SIMD.Float32x4.extractLane(t, 3) >= + SIMD.Float32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.greaterThan === "undefined") { +if (typeof SIMD.Float32x4.greaterThan === "undefined") { /** - * @param {float64x2} t An instance of float64x2. - * @param {float64x2} other An instance of float64x2. - * @return {int32x4} true or false in each lane depending on + * @param {Float32x4} t An instance of Float32x4. + * @param {Float32x4} other An instance of Float32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t > other. */ - SIMD.float64x2.greaterThan = function(t, other) { - t = SIMD.float64x2.check(t); - other = SIMD.float64x2.check(other); - var cx = t.x > other.x; - var cy = t.y > other.y; - return SIMD.int32x4.bool(cx, cx, cy, cy); + SIMD.Float32x4.greaterThan = function(t, other) { + t = SIMD.Float32x4.check(t); + other = SIMD.Float32x4.check(other); + var cx = + SIMD.Float32x4.extractLane(t, 0) > SIMD.Float32x4.extractLane(other, 0); + var cy = + SIMD.Float32x4.extractLane(t, 1) > SIMD.Float32x4.extractLane(other, 1); + var cz = + SIMD.Float32x4.extractLane(t, 2) > SIMD.Float32x4.extractLane(other, 2); + var cw = + SIMD.Float32x4.extractLane(t, 3) > SIMD.Float32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.float64x2.select === "undefined") { +if (typeof SIMD.Float32x4.select === "undefined") { /** - * @param {int32x4} t Selector mask. An instance of int32x4 - * @param {float64x2} trueValue Pick lane from here if corresponding + * @param {Bool32x4} t Selector mask. An instance of Bool32x4 + * @param {Float32x4} trueValue Pick lane from here if corresponding * selector lane is true - * @param {float64x2} falseValue Pick lane from here if corresponding + * @param {Float32x4} falseValue Pick lane from here if corresponding * selector lane is false - * @return {float64x2} Mix of lanes from trueValue or falseValue as + * @return {Float32x4} Mix of lanes from trueValue or falseValue as * indicated */ - SIMD.float64x2.select = function(t, trueValue, falseValue) { - t = SIMD.int32x4.check(t); - trueValue = SIMD.float64x2.check(trueValue); - falseValue = SIMD.float64x2.check(falseValue); - // We use t.z for the second element because t is an int32x4, because - // int64x2 isn't available. - return SIMD.float64x2(_SIMD_PRIVATE.tobool(t.x) ? trueValue.x : falseValue.x, - _SIMD_PRIVATE.tobool(t.z) ? trueValue.y : falseValue.y); + SIMD.Float32x4.select = function(t, trueValue, falseValue) { + t = SIMD.Bool32x4.check(t); + trueValue = SIMD.Float32x4.check(trueValue); + falseValue = SIMD.Float32x4.check(falseValue); + return SIMD.Float32x4( + SIMD.Bool32x4.extractLane(t, 0) ? + SIMD.Float32x4.extractLane(trueValue, 0) : + SIMD.Float32x4.extractLane(falseValue, 0), + SIMD.Bool32x4.extractLane(t, 1) ? + SIMD.Float32x4.extractLane(trueValue, 1) : + SIMD.Float32x4.extractLane(falseValue, 1), + SIMD.Bool32x4.extractLane(t, 2) ? + SIMD.Float32x4.extractLane(trueValue, 2) : + SIMD.Float32x4.extractLane(falseValue, 2), + SIMD.Bool32x4.extractLane(t, 3) ? + SIMD.Float32x4.extractLane(trueValue, 3) : + SIMD.Float32x4.extractLane(falseValue, 3)); } } -if (typeof SIMD.float64x2.bitselect === "undefined") { +if (typeof SIMD.Float32x4.load === "undefined") { /** - * @param {int32x4} t Selector mask. An instance of int32x4 - * @param {float64x2} trueValue Pick bit from here if corresponding - * selector bit is 1 - * @param {float64x2} falseValue Pick bit from here if corresponding - * selector bit is 0 - * @return {float64x2} Mix of bits from trueValue or falseValue as - * indicated + * @param {Typed array} tarray An instance of a typed array. + * @param {Number} index An instance of Number. + * @return {Float32x4} New instance of Float32x4. */ - SIMD.float64x2.bitselect = function(t, trueValue, falseValue) { - t = SIMD.int32x4.check(t); - trueValue = SIMD.float64x2.check(trueValue); - falseValue = SIMD.float64x2.check(falseValue); - var tv = SIMD.int32x4.fromFloat64x2Bits(trueValue); - var fv = SIMD.int32x4.fromFloat64x2Bits(falseValue); - var tr = SIMD.int32x4.and(t, tv); - var fr = SIMD.int32x4.and(SIMD.int32x4.not(t), fv); - return SIMD.float64x2.fromInt32x4Bits(SIMD.int32x4.or(tr, fr)); + SIMD.Float32x4.load = function(tarray, index) { + if (!isTypedArray(tarray)) + throw new TypeError("The 1st argument must be a typed array."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); + var bpe = tarray.BYTES_PER_ELEMENT; + if (index < 0 || (index * bpe + 16) > tarray.byteLength) + throw new RangeError("The value of index is invalid."); + var f32temp = _f32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _i32x4) : + _f64x2; + var n = 16 / bpe; + for (var i = 0; i < n; ++i) + array[i] = tarray[index + i]; + return SIMD.Float32x4(f32temp[0], f32temp[1], f32temp[2], f32temp[3]); } } -if (typeof SIMD.float64x2.load === "undefined") { +if (typeof SIMD.Float32x4.load1 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {float64x2} New instance of float64x2. + * @return {Float32x4} New instance of Float32x4. */ - SIMD.float64x2.load = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Float32x4.load1 = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; - if (index < 0 || (index * bpe + 16) > tarray.byteLength) + if (index < 0 || (index * bpe + 4) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var f64temp = _SIMD_PRIVATE._f64x2; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - f64temp; - var n = 16 / bpe; + var f32temp = _f32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _i32x4) : + _f64x2; + var n = 4 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.float64x2(f64temp[0], f64temp[1]); + return SIMD.Float32x4(f32temp[0], 0.0, 0.0, 0.0); } } -if (typeof SIMD.float64x2.loadX === "undefined") { +if (typeof SIMD.Float32x4.load2 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {float64x2} New instance of float64x2. + * @return {Float32x4} New instance of Float32x4. */ - SIMD.float64x2.loadX = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Float32x4.load2 = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 8) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var f64temp = _SIMD_PRIVATE._f64x2; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - f64temp; + var f32temp = _f32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _i32x4) : + _f64x2; var n = 8 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.float64x2(f64temp[0], 0.0); + return SIMD.Float32x4(f32temp[0], f32temp[1], 0.0, 0.0); + } +} + +if (typeof SIMD.Float32x4.load3 === "undefined") { + /** + * @param {Typed array} tarray An instance of a typed array. + * @param {Number} index An instance of Number. + * @return {Float32x4} New instance of Float32x4. + */ + SIMD.Float32x4.load3 = function(tarray, index) { + if (!isTypedArray(tarray)) + throw new TypeError("The 1st argument must be a typed array."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); + var bpe = tarray.BYTES_PER_ELEMENT; + if (index < 0 || (index * bpe + 12) > tarray.byteLength) + throw new RangeError("The value of index is invalid."); + var f32temp = _f32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? f32temp : _i32x4) : + _f64x2; + var n = 12 / bpe; + for (var i = 0; i < n; ++i) + array[i] = tarray[index + i]; + return SIMD.Float32x4(f32temp[0], f32temp[1], f32temp[2], 0.0); } } -if (typeof SIMD.float64x2.store === "undefined") { +if (typeof SIMD.Float32x4.store === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {float64x2} value An instance of float64x2. - * @return {void} + * @param {Float32x4} value An instance of Float32x4. + * @return {Float32x4} value */ - SIMD.float64x2.store = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Float32x4.store = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.float64x2.check(value); - _SIMD_PRIVATE._f64x2[0] = value.x; - _SIMD_PRIVATE._f64x2[1] = value.y; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + value = SIMD.Float32x4.check(value); + _f32x4[0] = SIMD.Float32x4.extractLane(value, 0); + _f32x4[1] = SIMD.Float32x4.extractLane(value, 1); + _f32x4[2] = SIMD.Float32x4.extractLane(value, 2); + _f32x4[3] = SIMD.Float32x4.extractLane(value, 3); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; } } -if (typeof SIMD.float64x2.storeX === "undefined") { +if (typeof SIMD.Float32x4.store1 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {float64x2} value An instance of float64x2. - * @return {void} + * @param {Float32x4} value An instance of Float32x4. + * @return {Float32x4} value */ - SIMD.float64x2.storeX = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Float32x4.store1 = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); + var bpe = tarray.BYTES_PER_ELEMENT; + if (index < 0 || (index * bpe + 4) > tarray.byteLength) + throw new RangeError("The value of index is invalid."); + value = SIMD.Float32x4.check(value); + if (bpe == 8) { + // tarray's elements are too wide. Just create a new view; this is rare. + var view = new Float32Array(tarray.buffer, + tarray.byteOffset + index * 8, 1); + view[0] = SIMD.Float32x4.extractLane(value, 0); + } else { + _f32x4[0] = SIMD.Float32x4.extractLane(value, 0); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + (tarray instanceof Float32Array ? _f32x4 : _i32x4); + var n = 4 / bpe; + for (var i = 0; i < n; ++i) + tarray[index + i] = array[i]; + return value; + } + } +} + +if (typeof SIMD.Float32x4.store2 === "undefined") { + /** + * @param {Typed array} tarray An instance of a typed array. + * @param {Number} index An instance of Number. + * @param {Float32x4} value An instance of Float32x4. + * @return {Float32x4} value + */ + SIMD.Float32x4.store2 = function(tarray, index, value) { + if (!isTypedArray(tarray)) + throw new TypeError("The 1st argument must be a typed array."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 8) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.float64x2.check(value); - _SIMD_PRIVATE._f64x2[0] = value.x; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + value = SIMD.Float32x4.check(value); + _f32x4[0] = SIMD.Float32x4.extractLane(value, 0); + _f32x4[1] = SIMD.Float32x4.extractLane(value, 1); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 8 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; + } +} + +if (typeof SIMD.Float32x4.store3 === "undefined") { + /** + * @param {Typed array} tarray An instance of a typed array. + * @param {Number} index An instance of Number. + * @param {Float32x4} value An instance of Float32x4. + * @return {Float32x4} value + */ + SIMD.Float32x4.store3 = function(tarray, index, value) { + if (!isTypedArray(tarray)) + throw new TypeError("The 1st argument must be a typed array."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); + var bpe = tarray.BYTES_PER_ELEMENT; + if (index < 0 || (index * bpe + 12) > tarray.byteLength) + throw new RangeError("The value of index is invalid."); + value = SIMD.Float32x4.check(value); + if (bpe == 8) { + // tarray's elements are too wide. Just create a new view; this is rare. + var view = new Float32Array(tarray.buffer, + tarray.byteOffset + index * 8, 3); + view[0] = SIMD.Float32x4.extractLane(value, 0); + view[1] = SIMD.Float32x4.extractLane(value, 1); + view[2] = SIMD.Float32x4.extractLane(value, 2); + } else { + _f32x4[0] = SIMD.Float32x4.extractLane(value, 0); + _f32x4[1] = SIMD.Float32x4.extractLane(value, 1); + _f32x4[2] = SIMD.Float32x4.extractLane(value, 2); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + (tarray instanceof Float32Array ? _f32x4 : _i32x4); + var n = 12 / bpe; + for (var i = 0; i < n; ++i) + tarray[index + i] = array[i]; + return value; + } } } -if (typeof SIMD.int32x4.and === "undefined") { + +if (typeof SIMD.Int32x4.and === "undefined") { /** - * @param {int32x4} a An instance of int32x4. - * @param {int32x4} b An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of a & b. + * @param {Int32x4} a An instance of Int32x4. + * @param {Int32x4} b An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of a & b. */ - SIMD.int32x4.and = function(a, b) { - a = SIMD.int32x4.check(a); - b = SIMD.int32x4.check(b); - return SIMD.int32x4(a.x & b.x, a.y & b.y, a.z & b.z, a.w & b.w); + SIMD.Int32x4.and = function(a, b) { + a = SIMD.Int32x4.check(a); + b = SIMD.Int32x4.check(b); + return SIMD.Int32x4( + SIMD.Int32x4.extractLane(a, 0) & SIMD.Int32x4.extractLane(b, 0), + SIMD.Int32x4.extractLane(a, 1) & SIMD.Int32x4.extractLane(b, 1), + SIMD.Int32x4.extractLane(a, 2) & SIMD.Int32x4.extractLane(b, 2), + SIMD.Int32x4.extractLane(a, 3) & SIMD.Int32x4.extractLane(b, 3)); } } -if (typeof SIMD.int32x4.or === "undefined") { +if (typeof SIMD.Int32x4.or === "undefined") { /** - * @param {int32x4} a An instance of int32x4. - * @param {int32x4} b An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of a | b. + * @param {Int32x4} a An instance of Int32x4. + * @param {Int32x4} b An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of a | b. */ - SIMD.int32x4.or = function(a, b) { - a = SIMD.int32x4.check(a); - b = SIMD.int32x4.check(b); - return SIMD.int32x4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w); + SIMD.Int32x4.or = function(a, b) { + a = SIMD.Int32x4.check(a); + b = SIMD.Int32x4.check(b); + return SIMD.Int32x4( + SIMD.Int32x4.extractLane(a, 0) | SIMD.Int32x4.extractLane(b, 0), + SIMD.Int32x4.extractLane(a, 1) | SIMD.Int32x4.extractLane(b, 1), + SIMD.Int32x4.extractLane(a, 2) | SIMD.Int32x4.extractLane(b, 2), + SIMD.Int32x4.extractLane(a, 3) | SIMD.Int32x4.extractLane(b, 3)); } } -if (typeof SIMD.int32x4.xor === "undefined") { +if (typeof SIMD.Int32x4.xor === "undefined") { /** - * @param {int32x4} a An instance of int32x4. - * @param {int32x4} b An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of a ^ b. + * @param {Int32x4} a An instance of Int32x4. + * @param {Int32x4} b An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of a ^ b. */ - SIMD.int32x4.xor = function(a, b) { - a = SIMD.int32x4.check(a); - b = SIMD.int32x4.check(b); - return SIMD.int32x4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); + SIMD.Int32x4.xor = function(a, b) { + a = SIMD.Int32x4.check(a); + b = SIMD.Int32x4.check(b); + return SIMD.Int32x4( + SIMD.Int32x4.extractLane(a, 0) ^ SIMD.Int32x4.extractLane(b, 0), + SIMD.Int32x4.extractLane(a, 1) ^ SIMD.Int32x4.extractLane(b, 1), + SIMD.Int32x4.extractLane(a, 2) ^ SIMD.Int32x4.extractLane(b, 2), + SIMD.Int32x4.extractLane(a, 3) ^ SIMD.Int32x4.extractLane(b, 3)); } } -if (typeof SIMD.int32x4.not === "undefined") { +if (typeof SIMD.Int32x4.not === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of ~t + * @param {Int32x4} t An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of ~t */ - SIMD.int32x4.not = function(t) { - t = SIMD.int32x4.check(t); - return SIMD.int32x4(~t.x, ~t.y, ~t.z, ~t.w); + SIMD.Int32x4.not = function(t) { + t = SIMD.Int32x4.check(t); + return SIMD.Int32x4(~SIMD.Int32x4.extractLane(t, 0), + ~SIMD.Int32x4.extractLane(t, 1), + ~SIMD.Int32x4.extractLane(t, 2), + ~SIMD.Int32x4.extractLane(t, 3)); } } -if (typeof SIMD.int32x4.neg === "undefined") { +if (typeof SIMD.Int32x4.neg === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of -t + * @param {Int32x4} t An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of -t */ - SIMD.int32x4.neg = function(t) { - t = SIMD.int32x4.check(t); - return SIMD.int32x4(-t.x, -t.y, -t.z, -t.w); + SIMD.Int32x4.neg = function(t) { + t = SIMD.Int32x4.check(t); + return SIMD.Int32x4(-SIMD.Int32x4.extractLane(t, 0), + -SIMD.Int32x4.extractLane(t, 1), + -SIMD.Int32x4.extractLane(t, 2), + -SIMD.Int32x4.extractLane(t, 3)); } } -if (typeof SIMD.int32x4.add === "undefined") { +if (typeof SIMD.Int32x4.add === "undefined") { /** - * @param {int32x4} a An instance of int32x4. - * @param {int32x4} b An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of a + b. + * @param {Int32x4} a An instance of Int32x4. + * @param {Int32x4} b An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of a + b. */ - SIMD.int32x4.add = function(a, b) { - a = SIMD.int32x4.check(a); - b = SIMD.int32x4.check(b); - return SIMD.int32x4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + SIMD.Int32x4.add = function(a, b) { + a = SIMD.Int32x4.check(a); + b = SIMD.Int32x4.check(b); + return SIMD.Int32x4( + SIMD.Int32x4.extractLane(a, 0) + SIMD.Int32x4.extractLane(b, 0), + SIMD.Int32x4.extractLane(a, 1) + SIMD.Int32x4.extractLane(b, 1), + SIMD.Int32x4.extractLane(a, 2) + SIMD.Int32x4.extractLane(b, 2), + SIMD.Int32x4.extractLane(a, 3) + SIMD.Int32x4.extractLane(b, 3)); } } -if (typeof SIMD.int32x4.sub === "undefined") { +if (typeof SIMD.Int32x4.sub === "undefined") { /** - * @param {int32x4} a An instance of int32x4. - * @param {int32x4} b An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of a - b. + * @param {Int32x4} a An instance of Int32x4. + * @param {Int32x4} b An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of a - b. */ - SIMD.int32x4.sub = function(a, b) { - a = SIMD.int32x4.check(a); - b = SIMD.int32x4.check(b); - return SIMD.int32x4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + SIMD.Int32x4.sub = function(a, b) { + a = SIMD.Int32x4.check(a); + b = SIMD.Int32x4.check(b); + return SIMD.Int32x4( + SIMD.Int32x4.extractLane(a, 0) - SIMD.Int32x4.extractLane(b, 0), + SIMD.Int32x4.extractLane(a, 1) - SIMD.Int32x4.extractLane(b, 1), + SIMD.Int32x4.extractLane(a, 2) - SIMD.Int32x4.extractLane(b, 2), + SIMD.Int32x4.extractLane(a, 3) - SIMD.Int32x4.extractLane(b, 3)); } } -if (typeof SIMD.int32x4.mul === "undefined") { +if (typeof SIMD.Int32x4.mul === "undefined") { /** - * @param {int32x4} a An instance of int32x4. - * @param {int32x4} b An instance of int32x4. - * @return {int32x4} New instance of int32x4 with values of a * b. + * @param {Int32x4} a An instance of Int32x4. + * @param {Int32x4} b An instance of Int32x4. + * @return {Int32x4} New instance of Int32x4 with values of a * b. */ - SIMD.int32x4.mul = function(a, b) { - a = SIMD.int32x4.check(a); - b = SIMD.int32x4.check(b); - return SIMD.int32x4(Math.imul(a.x, b.x), Math.imul(a.y, b.y), - Math.imul(a.z, b.z), Math.imul(a.w, b.w)); + SIMD.Int32x4.mul = function(a, b) { + a = SIMD.Int32x4.check(a); + b = SIMD.Int32x4.check(b); + return SIMD.Int32x4( + Math.imul(SIMD.Int32x4.extractLane(a, 0), + SIMD.Int32x4.extractLane(b, 0)), + Math.imul(SIMD.Int32x4.extractLane(a, 1), + SIMD.Int32x4.extractLane(b, 1)), + Math.imul(SIMD.Int32x4.extractLane(a, 2), + SIMD.Int32x4.extractLane(b, 2)), + Math.imul(SIMD.Int32x4.extractLane(a, 3), + SIMD.Int32x4.extractLane(b, 3))); } } -if (typeof SIMD.int32x4.swizzle === "undefined") { +if (typeof SIMD.Int32x4.swizzle === "undefined") { /** - * @param {int32x4} t An instance of int32x4 to be swizzled. + * @param {Int32x4} t An instance of Int32x4 to be swizzled. * @param {integer} x - Index in t for lane x * @param {integer} y - Index in t for lane y * @param {integer} z - Index in t for lane z * @param {integer} w - Index in t for lane w - * @return {int32x4} New instance of int32x4 with lanes swizzled. + * @return {Int32x4} New instance of Int32x4 with lanes swizzled. */ - SIMD.int32x4.swizzle = function(t, x, y, z, w) { - t = SIMD.int32x4.check(t); - var storage = _SIMD_PRIVATE._i32x4; - storage[0] = t.x; - storage[1] = t.y; - storage[2] = t.z; - storage[3] = t.w; - return SIMD.int32x4(storage[x], storage[y], storage[z], storage[w]); + SIMD.Int32x4.swizzle = function(t, x, y, z, w) { + t = SIMD.Int32x4.check(t); + check4(x); + check4(y); + check4(z); + check4(w); + var storage = _i32x4; + storage[0] = SIMD.Int32x4.extractLane(t, 0); + storage[1] = SIMD.Int32x4.extractLane(t, 1); + storage[2] = SIMD.Int32x4.extractLane(t, 2); + storage[3] = SIMD.Int32x4.extractLane(t, 3); + return SIMD.Int32x4(storage[x], storage[y], storage[z], storage[w]); } } -if (typeof SIMD.int32x4.shuffle === "undefined") { +if (typeof SIMD.Int32x4.shuffle === "undefined") { - _SIMD_PRIVATE._i32x8 = new Int32Array(8); + _i32x8 = new Int32Array(8); /** - * @param {int32x4} t1 An instance of int32x4 to be shuffled. - * @param {int32x4} t2 An instance of int32x4 to be shuffled. + * @param {Int32x4} t1 An instance of Int32x4 to be shuffled. + * @param {Int32x4} t2 An instance of Int32x4 to be shuffled. * @param {integer} x - Index in concatenation of t1 and t2 for lane x * @param {integer} y - Index in concatenation of t1 and t2 for lane y * @param {integer} z - Index in concatenation of t1 and t2 for lane z * @param {integer} w - Index in concatenation of t1 and t2 for lane w - * @return {int32x4} New instance of int32x4 with lanes shuffled. + * @return {Int32x4} New instance of Int32x4 with lanes shuffled. */ - SIMD.int32x4.shuffle = function(t1, t2, x, y, z, w) { - t1 = SIMD.int32x4.check(t1); - t2 = SIMD.int32x4.check(t2); - var storage = _SIMD_PRIVATE._i32x8; - storage[0] = t1.x; - storage[1] = t1.y; - storage[2] = t1.z; - storage[3] = t1.w; - storage[4] = t2.x; - storage[5] = t2.y; - storage[6] = t2.z; - storage[7] = t2.w; - return SIMD.int32x4(storage[x], storage[y], storage[z], storage[w]); + SIMD.Int32x4.shuffle = function(t1, t2, x, y, z, w) { + t1 = SIMD.Int32x4.check(t1); + t2 = SIMD.Int32x4.check(t2); + check8(x); + check8(y); + check8(z); + check8(w); + var storage = _i32x8; + storage[0] = SIMD.Int32x4.extractLane(t1, 0); + storage[1] = SIMD.Int32x4.extractLane(t1, 1); + storage[2] = SIMD.Int32x4.extractLane(t1, 2); + storage[3] = SIMD.Int32x4.extractLane(t1, 3); + storage[4] = SIMD.Int32x4.extractLane(t2, 0); + storage[5] = SIMD.Int32x4.extractLane(t2, 1); + storage[6] = SIMD.Int32x4.extractLane(t2, 2); + storage[7] = SIMD.Int32x4.extractLane(t2, 3); + return SIMD.Int32x4(storage[x], storage[y], storage[z], storage[w]); } } -if (typeof SIMD.int32x4.select === "undefined") { +if (typeof SIMD.Int32x4.unsignedHorizontalSum === "undefined") { /** - * @param {int32x4} t Selector mask. An instance of int32x4 - * @param {int32x4} trueValue Pick lane from here if corresponding - * selector lane is true - * @param {int32x4} falseValue Pick lane from here if corresponding - * selector lane is false - * @return {int32x4} Mix of lanes from trueValue or falseValue as - * indicated + * @param {Int32x4} a An instance of 32x4. + * @return {Number} The sum of all the lanes in a, extracted as unsigned values. */ - SIMD.int32x4.select = function(t, trueValue, falseValue) { - t = SIMD.int32x4.check(t); - trueValue = SIMD.int32x4.check(trueValue); - falseValue = SIMD.int32x4.check(falseValue); - return SIMD.int32x4(_SIMD_PRIVATE.tobool(t.x) ? trueValue.x : falseValue.x, - _SIMD_PRIVATE.tobool(t.y) ? trueValue.y : falseValue.y, - _SIMD_PRIVATE.tobool(t.z) ? trueValue.z : falseValue.z, - _SIMD_PRIVATE.tobool(t.w) ? trueValue.w : falseValue.w); + SIMD.Int32x4.unsignedHorizontalSum = function(a) { + a = SIMD.Int32x4.check(a); + return (SIMD.Int32x4.extractLane(a, 0)>>>0) + + (SIMD.Int32x4.extractLane(a, 1)>>>0) + + (SIMD.Int32x4.extractLane(a, 2)>>>0) + + (SIMD.Int32x4.extractLane(a, 3)>>>0); } } -if (typeof SIMD.int32x4.bitselect === "undefined") { +if (typeof SIMD.Int32x4.select === "undefined") { /** - * @param {int32x4} t Selector mask. An instance of int32x4 - * @param {int32x4} trueValue Pick bit from here if corresponding + * @param {Bool32x4} t Selector mask. An instance of Bool32x4 + * @param {Int32x4} trueValue Pick lane from here if corresponding + * selector lane is true + * @param {Int32x4} falseValue Pick lane from here if corresponding + * selector lane is false + * @return {Int32x4} Mix of lanes from trueValue or falseValue as + * indicated + */ + SIMD.Int32x4.select = function(t, trueValue, falseValue) { + t = SIMD.Bool32x4.check(t); + trueValue = SIMD.Int32x4.check(trueValue); + falseValue = SIMD.Int32x4.check(falseValue); + return SIMD.Int32x4( + SIMD.Bool32x4.extractLane(t, 0) ? + SIMD.Int32x4.extractLane(trueValue, 0) : + SIMD.Int32x4.extractLane(falseValue, 0), + SIMD.Bool32x4.extractLane(t, 1) ? + SIMD.Int32x4.extractLane(trueValue, 1) : + SIMD.Int32x4.extractLane(falseValue, 1), + SIMD.Bool32x4.extractLane(t, 2) ? + SIMD.Int32x4.extractLane(trueValue, 2) : + SIMD.Int32x4.extractLane(falseValue, 2), + SIMD.Bool32x4.extractLane(t, 3) ? + SIMD.Int32x4.extractLane(trueValue, 3) : + SIMD.Int32x4.extractLane(falseValue, 3)); + } +} + +if (typeof SIMD.Int32x4.selectBits === "undefined") { + /** + * @param {Int32x4} t Selector mask. An instance of Int32x4 + * @param {Int32x4} trueValue Pick bit from here if corresponding * selector bit is 1 - * @param {int32x4} falseValue Pick bit from here if corresponding + * @param {Int32x4} falseValue Pick bit from here if corresponding * selector bit is 0 - * @return {int32x4} Mix of bits from trueValue or falseValue as + * @return {Int32x4} Mix of bits from trueValue or falseValue as * indicated */ - SIMD.int32x4.bitselect = function(t, trueValue, falseValue) { - t = SIMD.int32x4.check(t); - trueValue = SIMD.int32x4.check(trueValue); - falseValue = SIMD.int32x4.check(falseValue); - var tr = SIMD.int32x4.and(t, trueValue); - var fr = SIMD.int32x4.and(SIMD.int32x4.not(t), falseValue); - return SIMD.int32x4.or(tr, fr); - } -} - -if (typeof SIMD.int32x4.withX === "undefined") { - /** - * @param {int32x4} t An instance of int32x4. - * @param {integer} 32-bit value used for x lane. - * @return {int32x4} New instance of int32x4 with the values in t and - * x lane replaced with {x}. - */ - SIMD.int32x4.withX = function(t, x) { - t = SIMD.int32x4.check(t); - return SIMD.int32x4(x, t.y, t.z, t.w); - } -} - -if (typeof SIMD.int32x4.withY === "undefined") { - /** - * @param {int32x4} t An instance of int32x4. - * @param {integer} 32-bit value used for y lane. - * @return {int32x4} New instance of int32x4 with the values in t and - * y lane replaced with {y}. - */ - SIMD.int32x4.withY = function(t, y) { - t = SIMD.int32x4.check(t); - return SIMD.int32x4(t.x, y, t.z, t.w); - } -} - -if (typeof SIMD.int32x4.withZ === "undefined") { - /** - * @param {int32x4} t An instance of int32x4. - * @param {integer} 32-bit value used for z lane. - * @return {int32x4} New instance of int32x4 with the values in t and - * z lane replaced with {z}. - */ - SIMD.int32x4.withZ = function(t, z) { - t = SIMD.int32x4.check(t); - return SIMD.int32x4(t.x, t.y, z, t.w); - } -} - -if (typeof SIMD.int32x4.withW === "undefined") { - /** - * @param {int32x4} t An instance of int32x4. - * @param {integer} 32-bit value used for w lane. - * @return {int32x4} New instance of int32x4 with the values in t and - * w lane replaced with {w}. - */ - SIMD.int32x4.withW = function(t, w) { - t = SIMD.int32x4.check(t); - return SIMD.int32x4(t.x, t.y, t.z, w); + SIMD.Int32x4.selectBits = function(t, trueValue, falseValue) { + t = SIMD.Int32x4.check(t); + trueValue = SIMD.Int32x4.check(trueValue); + falseValue = SIMD.Int32x4.check(falseValue); + var tr = SIMD.Int32x4.and(t, trueValue); + var fr = SIMD.Int32x4.and(SIMD.Int32x4.not(t), falseValue); + return SIMD.Int32x4.or(tr, fr); } } -if (typeof SIMD.int32x4.equal === "undefined") { +if (typeof SIMD.Int32x4.equal === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @param {int32x4} other An instance of int32x4. - * @return {int32x4} true or false in each lane depending on + * @param {Int32x4} t An instance of Int32x4. + * @param {Int32x4} other An instance of Int32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t == other. */ - SIMD.int32x4.equal = function(t, other) { - t = SIMD.int32x4.check(t); - other = SIMD.int32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int32x4.equal = function(t, other) { + t = SIMD.Int32x4.check(t); + other = SIMD.Int32x4.check(other); + var cx = + SIMD.Int32x4.extractLane(t, 0) == SIMD.Int32x4.extractLane(other, 0); + var cy = + SIMD.Int32x4.extractLane(t, 1) == SIMD.Int32x4.extractLane(other, 1); + var cz = + SIMD.Int32x4.extractLane(t, 2) == SIMD.Int32x4.extractLane(other, 2); + var cw = + SIMD.Int32x4.extractLane(t, 3) == SIMD.Int32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.int32x4.notEqual === "undefined") { +if (typeof SIMD.Int32x4.notEqual === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @param {int32x4} other An instance of int32x4. - * @return {int32x4} true or false in each lane depending on + * @param {Int32x4} t An instance of Int32x4. + * @param {Int32x4} other An instance of Int32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t != other. */ - SIMD.int32x4.notEqual = function(t, other) { - t = SIMD.int32x4.check(t); - other = SIMD.int32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int32x4.notEqual = function(t, other) { + t = SIMD.Int32x4.check(t); + other = SIMD.Int32x4.check(other); + var cx = + SIMD.Int32x4.extractLane(t, 0) != SIMD.Int32x4.extractLane(other, 0); + var cy = + SIMD.Int32x4.extractLane(t, 1) != SIMD.Int32x4.extractLane(other, 1); + var cz = + SIMD.Int32x4.extractLane(t, 2) != SIMD.Int32x4.extractLane(other, 2); + var cw = + SIMD.Int32x4.extractLane(t, 3) != SIMD.Int32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.int32x4.greaterThan === "undefined") { +if (typeof SIMD.Int32x4.greaterThan === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @param {int32x4} other An instance of int32x4. - * @return {int32x4} true or false in each lane depending on + * @param {Int32x4} t An instance of Int32x4. + * @param {Int32x4} other An instance of Int32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t > other. */ - SIMD.int32x4.greaterThan = function(t, other) { - t = SIMD.int32x4.check(t); - other = SIMD.int32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int32x4.greaterThan = function(t, other) { + t = SIMD.Int32x4.check(t); + other = SIMD.Int32x4.check(other); + var cx = + SIMD.Int32x4.extractLane(t, 0) > SIMD.Int32x4.extractLane(other, 0); + var cy = + SIMD.Int32x4.extractLane(t, 1) > SIMD.Int32x4.extractLane(other, 1); + var cz = + SIMD.Int32x4.extractLane(t, 2) > SIMD.Int32x4.extractLane(other, 2); + var cw = + SIMD.Int32x4.extractLane(t, 3) > SIMD.Int32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.int32x4.greaterThanOrEqual === "undefined") { +if (typeof SIMD.Int32x4.greaterThanOrEqual === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @param {int32x4} other An instance of int32x4. - * @return {int32x4} true or false in each lane depending on + * @param {Int32x4} t An instance of Int32x4. + * @param {Int32x4} other An instance of Int32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t >= other. */ - SIMD.int32x4.greaterThanOrEqual = function(t, other) { - t = SIMD.int32x4.check(t); - other = SIMD.int32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int32x4.greaterThanOrEqual = function(t, other) { + t = SIMD.Int32x4.check(t); + other = SIMD.Int32x4.check(other); + var cx = + SIMD.Int32x4.extractLane(t, 0) >= SIMD.Int32x4.extractLane(other, 0); + var cy = + SIMD.Int32x4.extractLane(t, 1) >= SIMD.Int32x4.extractLane(other, 1); + var cz = + SIMD.Int32x4.extractLane(t, 2) >= SIMD.Int32x4.extractLane(other, 2); + var cw = + SIMD.Int32x4.extractLane(t, 3) >= SIMD.Int32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.int32x4.lessThan === "undefined") { +if (typeof SIMD.Int32x4.lessThan === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @param {int32x4} other An instance of int32x4. - * @return {int32x4} true or false in each lane depending on + * @param {Int32x4} t An instance of Int32x4. + * @param {Int32x4} other An instance of Int32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t < other. */ - SIMD.int32x4.lessThan = function(t, other) { - t = SIMD.int32x4.check(t); - other = SIMD.int32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int32x4.lessThan = function(t, other) { + t = SIMD.Int32x4.check(t); + other = SIMD.Int32x4.check(other); + var cx = + SIMD.Int32x4.extractLane(t, 0) < SIMD.Int32x4.extractLane(other, 0); + var cy = + SIMD.Int32x4.extractLane(t, 1) < SIMD.Int32x4.extractLane(other, 1); + var cz = + SIMD.Int32x4.extractLane(t, 2) < SIMD.Int32x4.extractLane(other, 2); + var cw = + SIMD.Int32x4.extractLane(t, 3) < SIMD.Int32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.int32x4.lessThanOrEqual === "undefined") { +if (typeof SIMD.Int32x4.lessThanOrEqual === "undefined") { /** - * @param {int32x4} t An instance of int32x4. - * @param {int32x4} other An instance of int32x4. - * @return {int32x4} true or false in each lane depending on + * @param {Int32x4} t An instance of Int32x4. + * @param {Int32x4} other An instance of Int32x4. + * @return {Bool32x4} true or false in each lane depending on * the result of t <= other. */ - SIMD.int32x4.lessThanOrEqual = function(t, other) { - t = SIMD.int32x4.check(t); - other = SIMD.int32x4.check(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 SIMD.int32x4.bool(cx, cy, cz, cw); + SIMD.Int32x4.lessThanOrEqual = function(t, other) { + t = SIMD.Int32x4.check(t); + other = SIMD.Int32x4.check(other); + var cx = + SIMD.Int32x4.extractLane(t, 0) <= SIMD.Int32x4.extractLane(other, 0); + var cy = + SIMD.Int32x4.extractLane(t, 1) <= SIMD.Int32x4.extractLane(other, 1); + var cz = + SIMD.Int32x4.extractLane(t, 2) <= SIMD.Int32x4.extractLane(other, 2); + var cw = + SIMD.Int32x4.extractLane(t, 3) <= SIMD.Int32x4.extractLane(other, 3); + return SIMD.Bool32x4(cx, cy, cz, cw); } } -if (typeof SIMD.int32x4.shiftLeftByScalar === "undefined") { +if (typeof SIMD.Int32x4.shiftLeftByScalar === "undefined") { /** - * @param {int32x4} a An instance of int32x4. + * @param {Int32x4} a An instance of Int32x4. * @param {integer} bits Bit count to shift by. - * @return {int32x4} lanes in a shifted by bits. + * @return {Int32x4} lanes in a shifted by bits. */ - SIMD.int32x4.shiftLeftByScalar = function(a, bits) { - a = SIMD.int32x4.check(a); + SIMD.Int32x4.shiftLeftByScalar = function(a, bits) { + a = SIMD.Int32x4.check(a); if (bits>>>0 >= 32) - return SIMD.int32x4.splat(0.0); - var x = a.x << bits; - var y = a.y << bits; - var z = a.z << bits; - var w = a.w << bits; - return SIMD.int32x4(x, y, z, w); + return SIMD.Int32x4.splat(0.0); + var x = SIMD.Int32x4.extractLane(a, 0) << bits; + var y = SIMD.Int32x4.extractLane(a, 1) << bits; + var z = SIMD.Int32x4.extractLane(a, 2) << bits; + var w = SIMD.Int32x4.extractLane(a, 3) << bits; + return SIMD.Int32x4(x, y, z, w); } } -if (typeof SIMD.int32x4.shiftRightLogicalByScalar === "undefined") { +if (typeof SIMD.Int32x4.shiftRightLogicalByScalar === "undefined") { /** - * @param {int32x4} a An instance of int32x4. + * @param {Int32x4} a An instance of Int32x4. * @param {integer} bits Bit count to shift by. - * @return {int32x4} lanes in a shifted by bits. + * @return {Int32x4} lanes in a shifted by bits. */ - SIMD.int32x4.shiftRightLogicalByScalar = function(a, bits) { - a = SIMD.int32x4.check(a); + SIMD.Int32x4.shiftRightLogicalByScalar = function(a, bits) { + a = SIMD.Int32x4.check(a); if (bits>>>0 >= 32) - return SIMD.int32x4.splat(0.0); - var x = a.x >>> bits; - var y = a.y >>> bits; - var z = a.z >>> bits; - var w = a.w >>> bits; - return SIMD.int32x4(x, y, z, w); + return SIMD.Int32x4.splat(0.0); + var x = SIMD.Int32x4.extractLane(a, 0) >>> bits; + var y = SIMD.Int32x4.extractLane(a, 1) >>> bits; + var z = SIMD.Int32x4.extractLane(a, 2) >>> bits; + var w = SIMD.Int32x4.extractLane(a, 3) >>> bits; + return SIMD.Int32x4(x, y, z, w); } } -if (typeof SIMD.int32x4.shiftRightArithmeticByScalar === "undefined") { +if (typeof SIMD.Int32x4.shiftRightArithmeticByScalar === "undefined") { /** - * @param {int32x4} a An instance of int32x4. + * @param {Int32x4} a An instance of Int32x4. * @param {integer} bits Bit count to shift by. - * @return {int32x4} lanes in a shifted by bits. + * @return {Int32x4} lanes in a shifted by bits. */ - SIMD.int32x4.shiftRightArithmeticByScalar = function(a, bits) { - a = SIMD.int32x4.check(a); + SIMD.Int32x4.shiftRightArithmeticByScalar = function(a, bits) { + a = SIMD.Int32x4.check(a); if (bits>>>0 >= 32) bits = 31; - var x = a.x >> bits; - var y = a.y >> bits; - var z = a.z >> bits; - var w = a.w >> bits; - return SIMD.int32x4(x, y, z, w); + var x = SIMD.Int32x4.extractLane(a, 0) >> bits; + var y = SIMD.Int32x4.extractLane(a, 1) >> bits; + var z = SIMD.Int32x4.extractLane(a, 2) >> bits; + var w = SIMD.Int32x4.extractLane(a, 3) >> bits; + return SIMD.Int32x4(x, y, z, w); } } -if (typeof SIMD.int32x4.load === "undefined") { +if (typeof SIMD.Int32x4.load === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {int32x4} New instance of int32x4. + * @return {Int32x4} New instance of Int32x4. */ - SIMD.int32x4.load = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.load = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var i32temp = _SIMD_PRIVATE._i32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : i32temp) : - _SIMD_PRIVATE._f64x2; + var i32temp = _i32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : i32temp) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.int32x4(i32temp[0], i32temp[1], i32temp[2], i32temp[3]); + return SIMD.Int32x4(i32temp[0], i32temp[1], i32temp[2], i32temp[3]); } } -if (typeof SIMD.int32x4.loadX === "undefined") { +if (typeof SIMD.Int32x4.load1 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {int32x4} New instance of int32x4. + * @return {Int32x4} New instance of Int32x4. */ - SIMD.int32x4.loadX = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.load1 = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 4) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var i32temp = _SIMD_PRIVATE._i32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : i32temp) : - _SIMD_PRIVATE._f64x2; + var i32temp = _i32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : i32temp) : + _f64x2; var n = 4 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.int32x4(i32temp[0], 0, 0, 0); + return SIMD.Int32x4(i32temp[0], 0, 0, 0); } } -if (typeof SIMD.int32x4.loadXY === "undefined") { +if (typeof SIMD.Int32x4.load2 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {int32x4} New instance of int32x4. + * @return {Int32x4} New instance of Int32x4. */ - SIMD.int32x4.loadXY = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.load2 = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 8) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var i32temp = _SIMD_PRIVATE._i32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : i32temp) : - _SIMD_PRIVATE._f64x2; + var i32temp = _i32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : i32temp) : + _f64x2; var n = 8 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.int32x4(i32temp[0], i32temp[1], 0, 0); + return SIMD.Int32x4(i32temp[0], i32temp[1], 0, 0); } } -if (typeof SIMD.int32x4.loadXYZ === "undefined") { +if (typeof SIMD.Int32x4.load3 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {int32x4} New instance of int32x4. + * @return {Int32x4} New instance of Int32x4. */ - SIMD.int32x4.loadXYZ = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.load3 = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 12) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var i32temp = _SIMD_PRIVATE._i32x4; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : i32temp) : - _SIMD_PRIVATE._f64x2; + var i32temp = _i32x4; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : i32temp) : + _f64x2; var n = 12 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.int32x4(i32temp[0], i32temp[1], i32temp[2], 0); + return SIMD.Int32x4(i32temp[0], i32temp[1], i32temp[2], 0); } } -if (typeof SIMD.int32x4.store === "undefined") { +if (typeof SIMD.Int32x4.store === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {int32x4} value An instance of int32x4. - * @return {void} + * @param {Int32x4} value An instance of Int32x4. + * @return {Int32x4} value */ - SIMD.int32x4.store = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.store = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.int32x4.check(value); - _SIMD_PRIVATE._i32x4[0] = value.x; - _SIMD_PRIVATE._i32x4[1] = value.y; - _SIMD_PRIVATE._i32x4[2] = value.z; - _SIMD_PRIVATE._i32x4[3] = value.w; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + value = SIMD.Int32x4.check(value); + _i32x4[0] = SIMD.Int32x4.extractLane(value, 0); + _i32x4[1] = SIMD.Int32x4.extractLane(value, 1); + _i32x4[2] = SIMD.Int32x4.extractLane(value, 2); + _i32x4[3] = SIMD.Int32x4.extractLane(value, 3); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; } } -if (typeof SIMD.int32x4.storeX === "undefined") { +if (typeof SIMD.Int32x4.store1 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {int32x4} value An instance of int32x4. - * @return {void} + * @param {Int32x4} value An instance of Int32x4. + * @return {Int32x4} value */ - SIMD.int32x4.storeX = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.store1 = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 4) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.int32x4.check(value); + value = SIMD.Int32x4.check(value); if (bpe == 8) { // tarray's elements are too wide. Just create a new view; this is rare. - var view = new Int32Array(tarray.buffer, tarray.byteOffset + index * 8, 1); - view[0] = value.x; + var view = new Int32Array(tarray.buffer, + tarray.byteOffset + index * 8, 1); + view[0] = SIMD.Int32x4.extractLane(value, 0); } else { - _SIMD_PRIVATE._i32x4[0] = value.x; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4); + _i32x4[0] = SIMD.Int32x4.extractLane(value, 0); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + (tarray instanceof Float32Array ? _f32x4 : _i32x4); var n = 4 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; } } } -if (typeof SIMD.int32x4.storeXY === "undefined") { +if (typeof SIMD.Int32x4.store2 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {int32x4} value An instance of int32x4. - * @return {void} + * @param {Int32x4} value An instance of Int32x4. + * @return {Int32x4} value */ - SIMD.int32x4.storeXY = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.store2 = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 8) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.int32x4.check(value); - _SIMD_PRIVATE._i32x4[0] = value.x; - _SIMD_PRIVATE._i32x4[1] = value.y; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + value = SIMD.Int32x4.check(value); + _i32x4[0] = SIMD.Int32x4.extractLane(value, 0); + _i32x4[1] = SIMD.Int32x4.extractLane(value, 1); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 8 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; } } -if (typeof SIMD.int32x4.storeXYZ === "undefined") { +if (typeof SIMD.Int32x4.store3 === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {int32x4} value An instance of int32x4. - * @return {void} + * @param {Int32x4} value An instance of Int32x4. + * @return {Int32x4} value */ - SIMD.int32x4.storeXYZ = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int32x4.store3 = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 12) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.int32x4.check(value); + value = SIMD.Int32x4.check(value); if (bpe == 8) { // tarray's elements are too wide. Just create a new view; this is rare. - var view = new Int32Array(tarray.buffer, tarray.byteOffset + index * 8, 3); - view[0] = value.x; - view[1] = value.y; - view[2] = value.z; + var view = new Int32Array(tarray.buffer, + tarray.byteOffset + index * 8, 3); + view[0] = SIMD.Int32x4.extractLane(value, 0); + view[1] = SIMD.Int32x4.extractLane(value, 1); + view[2] = SIMD.Int32x4.extractLane(value, 2); } else { - _SIMD_PRIVATE._i32x4[0] = value.x; - _SIMD_PRIVATE._i32x4[1] = value.y; - _SIMD_PRIVATE._i32x4[2] = value.z; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4); + _i32x4[0] = SIMD.Int32x4.extractLane(value, 0); + _i32x4[1] = SIMD.Int32x4.extractLane(value, 1); + _i32x4[2] = SIMD.Int32x4.extractLane(value, 2); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + (tarray instanceof Float32Array ? _f32x4 : _i32x4); var n = 12 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; } } } -if (typeof SIMD.int16x8.and === "undefined") { - /** - * @param {int16x8} a An instance of int16x8. - * @param {int16x8} b An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of a & b. - */ - SIMD.int16x8.and = function(a, b) { - a = SIMD.int16x8.check(a); - b = SIMD.int16x8.check(b); - return SIMD.int16x8(a.s0 & b.s0, a.s1 & b.s1, a.s2 & b.s2, a.s3 & b.s3, - a.s4 & b.s4, a.s5 & b.s5, a.s6 & b.s6, a.s7 & b.s7); - } -} - -if (typeof SIMD.int16x8.or === "undefined") { +if (typeof SIMD.Int16x8.and === "undefined") { /** - * @param {int16x8} a An instance of int16x8. - * @param {int16x8} b An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of a | b. + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a & b. */ - SIMD.int16x8.or = function(a, b) { - a = SIMD.int16x8.check(a); - b = SIMD.int16x8.check(b); - return SIMD.int16x8(a.s0 | b.s0, a.s1 | b.s1, a.s2 | b.s2, a.s3 | b.s3, - a.s4 | b.s4, a.s5 | b.s5, a.s6 | b.s6, a.s7 | b.s7); + SIMD.Int16x8.and = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int16x8( + SIMD.Int16x8.extractLane(a, 0) & SIMD.Int16x8.extractLane(b, 0), + SIMD.Int16x8.extractLane(a, 1) & SIMD.Int16x8.extractLane(b, 1), + SIMD.Int16x8.extractLane(a, 2) & SIMD.Int16x8.extractLane(b, 2), + SIMD.Int16x8.extractLane(a, 3) & SIMD.Int16x8.extractLane(b, 3), + SIMD.Int16x8.extractLane(a, 4) & SIMD.Int16x8.extractLane(b, 4), + SIMD.Int16x8.extractLane(a, 5) & SIMD.Int16x8.extractLane(b, 5), + SIMD.Int16x8.extractLane(a, 6) & SIMD.Int16x8.extractLane(b, 6), + SIMD.Int16x8.extractLane(a, 7) & SIMD.Int16x8.extractLane(b, 7)); } } -if (typeof SIMD.int16x8.xor === "undefined") { +if (typeof SIMD.Int16x8.or === "undefined") { /** - * @param {int16x8} a An instance of int16x8. - * @param {int16x8} b An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of a ^ b. + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a | b. */ - SIMD.int16x8.xor = function(a, b) { - a = SIMD.int16x8.check(a); - b = SIMD.int16x8.check(b); - return SIMD.int16x8(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, - a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7); + SIMD.Int16x8.or = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int16x8( + SIMD.Int16x8.extractLane(a, 0) | SIMD.Int16x8.extractLane(b, 0), + SIMD.Int16x8.extractLane(a, 1) | SIMD.Int16x8.extractLane(b, 1), + SIMD.Int16x8.extractLane(a, 2) | SIMD.Int16x8.extractLane(b, 2), + SIMD.Int16x8.extractLane(a, 3) | SIMD.Int16x8.extractLane(b, 3), + SIMD.Int16x8.extractLane(a, 4) | SIMD.Int16x8.extractLane(b, 4), + SIMD.Int16x8.extractLane(a, 5) | SIMD.Int16x8.extractLane(b, 5), + SIMD.Int16x8.extractLane(a, 6) | SIMD.Int16x8.extractLane(b, 6), + SIMD.Int16x8.extractLane(a, 7) | SIMD.Int16x8.extractLane(b, 7)); } } -if (typeof SIMD.int16x8.not === "undefined") { +if (typeof SIMD.Int16x8.xor === "undefined") { /** - * @param {int16x8} t An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of ~t + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a ^ b. */ - SIMD.int16x8.not = function(t) { - t = SIMD.int16x8.check(t); - return SIMD.int16x8(~t.s0, ~t.s1, ~t.s2, ~t.s3, - ~t.s4, ~t.s5, ~t.s6, ~t.s7); - } -} - -if (typeof SIMD.int16x8.neg === "undefined") { - /** - * @param {int16x8} t An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of -t + SIMD.Int16x8.xor = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int16x8( + SIMD.Int16x8.extractLane(a, 0) ^ SIMD.Int16x8.extractLane(b, 0), + SIMD.Int16x8.extractLane(a, 1) ^ SIMD.Int16x8.extractLane(b, 1), + SIMD.Int16x8.extractLane(a, 2) ^ SIMD.Int16x8.extractLane(b, 2), + SIMD.Int16x8.extractLane(a, 3) ^ SIMD.Int16x8.extractLane(b, 3), + SIMD.Int16x8.extractLane(a, 4) ^ SIMD.Int16x8.extractLane(b, 4), + SIMD.Int16x8.extractLane(a, 5) ^ SIMD.Int16x8.extractLane(b, 5), + SIMD.Int16x8.extractLane(a, 6) ^ SIMD.Int16x8.extractLane(b, 6), + SIMD.Int16x8.extractLane(a, 7) ^ SIMD.Int16x8.extractLane(b, 7)); + } +} + +if (typeof SIMD.Int16x8.not === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of ~t */ - SIMD.int16x8.neg = function(t) { - t = SIMD.int16x8.check(t); - return SIMD.int16x8(-t.s0, -t.s1, -t.s2, -t.s3, - -t.s4, -t.s5, -t.s6, -t.s7); + SIMD.Int16x8.not = function(t) { + t = SIMD.Int16x8.check(t); + return SIMD.Int16x8(~SIMD.Int16x8.extractLane(t, 0), + ~SIMD.Int16x8.extractLane(t, 1), + ~SIMD.Int16x8.extractLane(t, 2), + ~SIMD.Int16x8.extractLane(t, 3), + ~SIMD.Int16x8.extractLane(t, 4), + ~SIMD.Int16x8.extractLane(t, 5), + ~SIMD.Int16x8.extractLane(t, 6), + ~SIMD.Int16x8.extractLane(t, 7)); } } -if (typeof SIMD.int16x8.add === "undefined") { +if (typeof SIMD.Int16x8.neg === "undefined") { /** - * @param {int16x8} a An instance of int16x8. - * @param {int16x8} b An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of a + b. + * @param {Int16x8} t An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of -t */ - SIMD.int16x8.add = function(a, b) { - a = SIMD.int16x8.check(a); - b = SIMD.int16x8.check(b); - return SIMD.int16x8(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, - a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7); + SIMD.Int16x8.neg = function(t) { + t = SIMD.Int16x8.check(t); + return SIMD.Int16x8(-SIMD.Int16x8.extractLane(t, 0), + -SIMD.Int16x8.extractLane(t, 1), + -SIMD.Int16x8.extractLane(t, 2), + -SIMD.Int16x8.extractLane(t, 3), + -SIMD.Int16x8.extractLane(t, 4), + -SIMD.Int16x8.extractLane(t, 5), + -SIMD.Int16x8.extractLane(t, 6), + -SIMD.Int16x8.extractLane(t, 7)); } } -if (typeof SIMD.int16x8.sub === "undefined") { - /** - * @param {int16x8} a An instance of int16x8. - * @param {int16x8} b An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of a - b. - */ - SIMD.int16x8.sub = function(a, b) { - a = SIMD.int16x8.check(a); - b = SIMD.int16x8.check(b); - return SIMD.int16x8(a.s0 - b.s0, a.s1 - b.s1, a.s2 - b.s2, a.s3 - b.s3, - a.s4 - b.s4, a.s5 - b.s5, a.s6 - b.s6, a.s7 - b.s7); +if (typeof SIMD.Int16x8.add === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a + b. + */ + SIMD.Int16x8.add = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int16x8( + SIMD.Int16x8.extractLane(a, 0) + SIMD.Int16x8.extractLane(b, 0), + SIMD.Int16x8.extractLane(a, 1) + SIMD.Int16x8.extractLane(b, 1), + SIMD.Int16x8.extractLane(a, 2) + SIMD.Int16x8.extractLane(b, 2), + SIMD.Int16x8.extractLane(a, 3) + SIMD.Int16x8.extractLane(b, 3), + SIMD.Int16x8.extractLane(a, 4) + SIMD.Int16x8.extractLane(b, 4), + SIMD.Int16x8.extractLane(a, 5) + SIMD.Int16x8.extractLane(b, 5), + SIMD.Int16x8.extractLane(a, 6) + SIMD.Int16x8.extractLane(b, 6), + SIMD.Int16x8.extractLane(a, 7) + SIMD.Int16x8.extractLane(b, 7)); } } -if (typeof SIMD.int16x8.mul === "undefined") { - /** - * @param {int16x8} a An instance of int16x8. - * @param {int16x8} b An instance of int16x8. - * @return {int16x8} New instance of int16x8 with values of a * b. - */ - SIMD.int16x8.mul = function(a, b) { - a = SIMD.int16x8.check(a); - b = SIMD.int16x8.check(b); - return SIMD.int16x8(Math.imul(a.s0, b.s0), Math.imul(a.s1, b.s1), - Math.imul(a.s2, b.s2), Math.imul(a.s3, b.s3), - Math.imul(a.s4, b.s4), Math.imul(a.s5, b.s5), - Math.imul(a.s6, b.s6), Math.imul(a.s7, b.s7)); +if (typeof SIMD.Int16x8.sub === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a - b. + */ + SIMD.Int16x8.sub = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int16x8( + SIMD.Int16x8.extractLane(a, 0) - SIMD.Int16x8.extractLane(b, 0), + SIMD.Int16x8.extractLane(a, 1) - SIMD.Int16x8.extractLane(b, 1), + SIMD.Int16x8.extractLane(a, 2) - SIMD.Int16x8.extractLane(b, 2), + SIMD.Int16x8.extractLane(a, 3) - SIMD.Int16x8.extractLane(b, 3), + SIMD.Int16x8.extractLane(a, 4) - SIMD.Int16x8.extractLane(b, 4), + SIMD.Int16x8.extractLane(a, 5) - SIMD.Int16x8.extractLane(b, 5), + SIMD.Int16x8.extractLane(a, 6) - SIMD.Int16x8.extractLane(b, 6), + SIMD.Int16x8.extractLane(a, 7) - SIMD.Int16x8.extractLane(b, 7)); } } -if (typeof SIMD.int16x8.swizzle === "undefined") { - /** - * @param {int16x8} t An instance of int16x8 to be swizzled. +if (typeof SIMD.Int16x8.mul === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a * b. + */ + SIMD.Int16x8.mul = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int16x8(Math.imul(SIMD.Int16x8.extractLane(a, 0), + SIMD.Int16x8.extractLane(b, 0)), + Math.imul(SIMD.Int16x8.extractLane(a, 1), + SIMD.Int16x8.extractLane(b, 1)), + Math.imul(SIMD.Int16x8.extractLane(a, 2), + SIMD.Int16x8.extractLane(b, 2)), + Math.imul(SIMD.Int16x8.extractLane(a, 3), + SIMD.Int16x8.extractLane(b, 3)), + Math.imul(SIMD.Int16x8.extractLane(a, 4), + SIMD.Int16x8.extractLane(b, 4)), + Math.imul(SIMD.Int16x8.extractLane(a, 5), + SIMD.Int16x8.extractLane(b, 5)), + Math.imul(SIMD.Int16x8.extractLane(a, 6), + SIMD.Int16x8.extractLane(b, 6)), + Math.imul(SIMD.Int16x8.extractLane(a, 7), + SIMD.Int16x8.extractLane(b, 7))); + } +} + +if (typeof SIMD.Int16x8.swizzle === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8 to be swizzled. * @param {integer} s0 - Index in t for lane s0 * @param {integer} s1 - Index in t for lane s1 * @param {integer} s2 - Index in t for lane s2 @@ -3089,31 +3503,39 @@ if (typeof SIMD.int16x8.swizzle === "undefined") { * @param {integer} s5 - Index in t for lane s5 * @param {integer} s6 - Index in t for lane s6 * @param {integer} s7 - Index in t for lane s7 - * @return {int16x8} New instance of int16x8 with lanes swizzled. - */ - SIMD.int16x8.swizzle = function(t, s0, s1, s2, s3, s4, s5, s6, s7) { - t = SIMD.int16x8.check(t); - var storage = _SIMD_PRIVATE._i16x8; - storage[0] = t.s0; - storage[1] = t.s1; - storage[2] = t.s2; - storage[3] = t.s3; - storage[4] = t.s4; - storage[5] = t.s5; - storage[6] = t.s6; - storage[7] = t.s7; - return SIMD.int16x8(storage[s0], storage[s1], storage[s2], storage[s3], + * @return {Int16x8} New instance of Int16x8 with lanes swizzled. + */ + SIMD.Int16x8.swizzle = function(t, s0, s1, s2, s3, s4, s5, s6, s7) { + t = SIMD.Int16x8.check(t); + check8(s0); + check8(s1); + check8(s2); + check8(s3); + check8(s4); + check8(s5); + check8(s6); + check8(s7); + var storage = _i16x8; + storage[0] = SIMD.Int16x8.extractLane(t, 0); + storage[1] = SIMD.Int16x8.extractLane(t, 1); + storage[2] = SIMD.Int16x8.extractLane(t, 2); + storage[3] = SIMD.Int16x8.extractLane(t, 3); + storage[4] = SIMD.Int16x8.extractLane(t, 4); + storage[5] = SIMD.Int16x8.extractLane(t, 5); + storage[6] = SIMD.Int16x8.extractLane(t, 6); + storage[7] = SIMD.Int16x8.extractLane(t, 7); + return SIMD.Int16x8(storage[s0], storage[s1], storage[s2], storage[s3], storage[s4], storage[s5], storage[s6], storage[s7]); } } -if (typeof SIMD.int16x8.shuffle === "undefined") { +if (typeof SIMD.Int16x8.shuffle === "undefined") { - _SIMD_PRIVATE._i16x16 = new Int16Array(16); + _i16x16 = new Int16Array(16); /** - * @param {int16x8} t0 An instance of int16x8 to be shuffled. - * @param {int16x8} t1 An instance of int16x8 to be shuffled. + * @param {Int16x8} t0 An instance of Int16x8 to be shuffled. + * @param {Int16x8} t1 An instance of Int16x8 to be shuffled. * @param {integer} s0 - Index in concatenation of t0 and t1 for lane s0 * @param {integer} s1 - Index in concatenation of t0 and t1 for lane s1 * @param {integer} s2 - Index in concatenation of t0 and t1 for lane s2 @@ -3122,468 +3544,932 @@ if (typeof SIMD.int16x8.shuffle === "undefined") { * @param {integer} s5 - Index in concatenation of t0 and t1 for lane s5 * @param {integer} s6 - Index in concatenation of t0 and t1 for lane s6 * @param {integer} s7 - Index in concatenation of t0 and t1 for lane s7 - * @return {int16x8} New instance of int16x8 with lanes shuffled. - */ - SIMD.int16x8.shuffle = function(t0, t1, s0, s1, s2, s3, s4, s5, s6, s7) { - t0 = SIMD.int16x8.check(t0); - t1 = SIMD.int16x8.check(t1); - var storage = _SIMD_PRIVATE._i16x16; - storage[0] = t0.s0; - storage[1] = t0.s1; - storage[2] = t0.s2; - storage[3] = t0.s3; - storage[4] = t0.s4; - storage[5] = t0.s5; - storage[6] = t0.s6; - storage[7] = t0.s7; - storage[8] = t1.s0; - storage[9] = t1.s1; - storage[10] = t1.s2; - storage[11] = t1.s3; - storage[12] = t1.s4; - storage[13] = t1.s5; - storage[14] = t1.s6; - storage[15] = t1.s7; - return SIMD.int16x8(storage[s0], storage[s1], storage[s2], storage[s3], + * @return {Int16x8} New instance of Int16x8 with lanes shuffled. + */ + SIMD.Int16x8.shuffle = function(t0, t1, s0, s1, s2, s3, s4, s5, s6, s7) { + t0 = SIMD.Int16x8.check(t0); + t1 = SIMD.Int16x8.check(t1); + check16(s0); + check16(s1); + check16(s2); + check16(s3); + check16(s4); + check16(s5); + check16(s6); + check16(s7); + var storage = _i16x16; + storage[0] = SIMD.Int16x8.extractLane(t0, 0); + storage[1] = SIMD.Int16x8.extractLane(t0, 1); + storage[2] = SIMD.Int16x8.extractLane(t0, 2); + storage[3] = SIMD.Int16x8.extractLane(t0, 3); + storage[4] = SIMD.Int16x8.extractLane(t0, 4); + storage[5] = SIMD.Int16x8.extractLane(t0, 5); + storage[6] = SIMD.Int16x8.extractLane(t0, 6); + storage[7] = SIMD.Int16x8.extractLane(t0, 7); + storage[8] = SIMD.Int16x8.extractLane(t1, 0); + storage[9] = SIMD.Int16x8.extractLane(t1, 1); + storage[10] = SIMD.Int16x8.extractLane(t1, 2); + storage[11] = SIMD.Int16x8.extractLane(t1, 3); + storage[12] = SIMD.Int16x8.extractLane(t1, 4); + storage[13] = SIMD.Int16x8.extractLane(t1, 5); + storage[14] = SIMD.Int16x8.extractLane(t1, 6); + storage[15] = SIMD.Int16x8.extractLane(t1, 7); + return SIMD.Int16x8(storage[s0], storage[s1], storage[s2], storage[s3], storage[s4], storage[s5], storage[s6], storage[s7]); } } -if (typeof SIMD.int16x8.select === "undefined") { - /** - * @param {int16x8} t Selector mask. An instance of int16x8 - * @param {int16x8} trueValue Pick lane from here if corresponding +if (typeof SIMD.Int16x8.addSaturate === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a + b with + * signed saturating behavior on overflow. + */ + SIMD.Int16x8.addSaturate = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + var c = SIMD.Int16x8.add(a, b); + var max = SIMD.Int16x8.splat(0x7fff); + var min = SIMD.Int16x8.splat(0x8000); + var mask = SIMD.Int16x8.lessThan(c, a); + var bneg = SIMD.Int16x8.lessThan(b, SIMD.Int16x8.splat(0)); + return SIMD.Int16x8.select(SIMD.Bool16x8.and(mask, SIMD.Bool16x8.not(bneg)), max, + SIMD.Int16x8.select(SIMD.Bool16x8.and(SIMD.Bool16x8.not(mask), bneg), min, + c)); + } +} + +if (typeof SIMD.Int16x8.unsignedAddSaturate === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a + b with + * unsigned saturating behavior on overflow. + */ + SIMD.Int16x8.unsignedAddSaturate = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + var c = SIMD.Int16x8.add(a, b); + var max = SIMD.Int16x8.splat(0xffff); + var min = SIMD.Int16x8.splat(0x0000); + var mask = SIMD.Int16x8.unsignedLessThan(c, a); + var bneg = SIMD.Int16x8.unsignedLessThan(b, SIMD.Int16x8.splat(0)); + return SIMD.Int16x8.select(SIMD.Bool16x8.and(mask, SIMD.Bool16x8.not(bneg)), max, + SIMD.Int16x8.select(SIMD.Bool16x8.and(SIMD.Bool16x8.not(mask), bneg), min, + c)); + } +} + +if (typeof SIMD.Int16x8.subSaturate === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a - b with + * signed saturating behavior on overflow. + */ + SIMD.Int16x8.subSaturate = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + var c = SIMD.Int16x8.sub(a, b); + var max = SIMD.Int16x8.splat(0x7fff); + var min = SIMD.Int16x8.splat(0x8000); + var mask = SIMD.Int16x8.greaterThan(c, a); + var bneg = SIMD.Int16x8.lessThan(b, SIMD.Int16x8.splat(0)); + return SIMD.Int16x8.select(SIMD.Bool16x8.and(mask, SIMD.Bool16x8.not(bneg)), min, + SIMD.Int16x8.select(SIMD.Bool16x8.and(SIMD.Bool16x8.not(mask), bneg), max, + c)); + } +} + +if (typeof SIMD.Int16x8.unsignedSubSaturate === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int16x8} New instance of Int16x8 with values of a - b with + * unsigned saturating behavior on overflow. + */ + SIMD.Int16x8.unsignedSubSaturate = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + var c = SIMD.Int16x8.sub(a, b); + var max = SIMD.Int16x8.splat(0xffff); + var min = SIMD.Int16x8.splat(0x0000); + var mask = SIMD.Int16x8.unsignedGreaterThan(c, a); + var bneg = SIMD.Int16x8.unsignedLessThan(b, SIMD.Int16x8.splat(0)); + return SIMD.Int16x8.select(SIMD.Bool16x8.and(mask, SIMD.Bool16x8.not(bneg)), min, + SIMD.Int16x8.select(SIMD.Bool16x8.and(SIMD.Bool16x8.not(mask), bneg), max, + c)); + } +} + +if (typeof SIMD.Int16x8.unsignedAbsoluteDifference === "undefined") { + /** + * @param {Int16x8} a An instance of Int8x16. + * @param {Int16x8} b An instance of Int8x16. + * @return {Int16x8} The absolute differences (abs(x - y)) of the + * corresponding elements of a and b. x and y are interpreted as unsigned + * integers. + */ + SIMD.Int16x8.unsignedAbsoluteDifference = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + var x = SIMD.Int16x8( + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 0) - SIMD.Int16x8.unsignedExtractLane(b, 0)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 1) - SIMD.Int16x8.unsignedExtractLane(b, 1)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 2) - SIMD.Int16x8.unsignedExtractLane(b, 2)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 3) - SIMD.Int16x8.unsignedExtractLane(b, 3)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 4) - SIMD.Int16x8.unsignedExtractLane(b, 4)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 5) - SIMD.Int16x8.unsignedExtractLane(b, 5)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 6) - SIMD.Int16x8.unsignedExtractLane(b, 6)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 7) - SIMD.Int16x8.unsignedExtractLane(b, 7))); + return x; + } +} + +if (typeof SIMD.Int16x8.widenedUnsignedAbsoluteDifference === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @param {Int16x8} b An instance of Int16x8. + * @return {Int32x4} The absolute differences (abs(x - y)) of the + * first 4 corresponding elements of a and b, returning 32-bit results. + * x and y are interpreted as unsigned integers. + */ + SIMD.Int16x8.widenedUnsignedAbsoluteDifference = function(a, b) { + a = SIMD.Int16x8.check(a); + b = SIMD.Int16x8.check(b); + return SIMD.Int32x4( + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 0) - SIMD.Int16x8.unsignedExtractLane(b, 0)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 1) - SIMD.Int16x8.unsignedExtractLane(b, 1)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 2) - SIMD.Int16x8.unsignedExtractLane(b, 2)), + Math.abs( + SIMD.Int16x8.unsignedExtractLane(a, 3) - SIMD.Int16x8.unsignedExtractLane(b, 3))); + } +} + +if (typeof SIMD.Int16x8.unsignedHorizontalSum === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. + * @return {Number} The sum of all the lanes in a, extracted as unsigned values. + */ + SIMD.Int16x8.unsignedHorizontalSum = function(a) { + a = SIMD.Int16x8.check(a); + return SIMD.Int16x8.unsignedExtractLane(a, 0) + + SIMD.Int16x8.unsignedExtractLane(a, 1) + + SIMD.Int16x8.unsignedExtractLane(a, 2) + + SIMD.Int16x8.unsignedExtractLane(a, 3) + + SIMD.Int16x8.unsignedExtractLane(a, 4) + + SIMD.Int16x8.unsignedExtractLane(a, 5) + + SIMD.Int16x8.unsignedExtractLane(a, 6) + + SIMD.Int16x8.unsignedExtractLane(a, 7); + } +} + +if (typeof SIMD.Int16x8.select === "undefined") { + /** + * @param {Bool16x8} t Selector mask. An instance of Bool16x8 + * @param {Int16x8} trueValue Pick lane from here if corresponding * selector lane is true - * @param {int16x8} falseValue Pick lane from here if corresponding + * @param {Int16x8} falseValue Pick lane from here if corresponding * selector lane is false - * @return {int16x8} Mix of lanes from trueValue or falseValue as + * @return {Int16x8} Mix of lanes from trueValue or falseValue as * indicated */ - SIMD.int16x8.select = function(t, trueValue, falseValue) { - t = SIMD.int16x8.check(t); - trueValue = SIMD.int16x8.check(trueValue); - falseValue = SIMD.int16x8.check(falseValue); - return SIMD.int16x8(_SIMD_PRIVATE.tobool(t.s0) ? trueValue.s0 : falseValue.s0, - _SIMD_PRIVATE.tobool(t.s1) ? trueValue.s1 : falseValue.s1, - _SIMD_PRIVATE.tobool(t.s2) ? trueValue.s2 : falseValue.s2, - _SIMD_PRIVATE.tobool(t.s3) ? trueValue.s3 : falseValue.s3, - _SIMD_PRIVATE.tobool(t.s4) ? trueValue.s4 : falseValue.s4, - _SIMD_PRIVATE.tobool(t.s5) ? trueValue.s5 : falseValue.s5, - _SIMD_PRIVATE.tobool(t.s6) ? trueValue.s6 : falseValue.s6, - _SIMD_PRIVATE.tobool(t.s7) ? trueValue.s7 : falseValue.s7); - } -} - -if (typeof SIMD.int16x8.bitselect === "undefined") { - /** - * @param {int16x8} t Selector mask. An instance of int16x8 - * @param {int16x8} trueValue Pick lane from here if corresponding + SIMD.Int16x8.select = function(t, trueValue, falseValue) { + t = SIMD.Bool16x8.check(t); + trueValue = SIMD.Int16x8.check(trueValue); + falseValue = SIMD.Int16x8.check(falseValue); + return SIMD.Int16x8( + SIMD.Bool16x8.extractLane(t, 0) ? + SIMD.Int16x8.extractLane(trueValue, 0) : + SIMD.Int16x8.extractLane(falseValue, 0), + SIMD.Bool16x8.extractLane(t, 1) ? + SIMD.Int16x8.extractLane(trueValue, 1) : + SIMD.Int16x8.extractLane(falseValue, 1), + SIMD.Bool16x8.extractLane(t, 2) ? + SIMD.Int16x8.extractLane(trueValue, 2) : + SIMD.Int16x8.extractLane(falseValue, 2), + SIMD.Bool16x8.extractLane(t, 3) ? + SIMD.Int16x8.extractLane(trueValue, 3) : + SIMD.Int16x8.extractLane(falseValue, 3), + SIMD.Bool16x8.extractLane(t, 4) ? + SIMD.Int16x8.extractLane(trueValue, 4) : + SIMD.Int16x8.extractLane(falseValue, 4), + SIMD.Bool16x8.extractLane(t, 5) ? + SIMD.Int16x8.extractLane(trueValue, 5) : + SIMD.Int16x8.extractLane(falseValue, 5), + SIMD.Bool16x8.extractLane(t, 6) ? + SIMD.Int16x8.extractLane(trueValue, 6) : + SIMD.Int16x8.extractLane(falseValue, 6), + SIMD.Bool16x8.extractLane(t, 7) ? + SIMD.Int16x8.extractLane(trueValue, 7) : + SIMD.Int16x8.extractLane(falseValue, 7)); + } +} + +if (typeof SIMD.Int16x8.selectBits === "undefined") { + /** + * @param {Int16x8} t Selector mask. An instance of Int16x8 + * @param {Int16x8} trueValue Pick bit from here if corresponding * selector bit is 1 - * @param {int16x8} falseValue Pick lane from here if corresponding + * @param {Int16x8} falseValue Pick bit from here if corresponding * selector bit is 0 - * @return {int16x8} Mix of lanes from trueValue or falseValue as + * @return {Int16x8} Mix of bits from trueValue or falseValue as * indicated */ - SIMD.int16x8.bitselect = function(t, trueValue, falseValue) { - t = SIMD.int16x8.check(t); - trueValue = SIMD.int16x8.check(trueValue); - falseValue = SIMD.int16x8.check(falseValue); - var tr = SIMD.int16x8.and(t, trueValue); - var fr = SIMD.int16x8.and(SIMD.int16x8.not(t), falseValue); - return SIMD.int16x8.or(tr, fr); + SIMD.Int16x8.selectBits = function(t, trueValue, falseValue) { + t = SIMD.Int16x8.check(t); + trueValue = SIMD.Int16x8.check(trueValue); + falseValue = SIMD.Int16x8.check(falseValue); + var tr = SIMD.Int16x8.and(t, trueValue); + var fr = SIMD.Int16x8.and(SIMD.Int16x8.not(t), falseValue); + return SIMD.Int16x8.or(tr, fr); } } -if (typeof SIMD.int16x8.equal === "undefined") { +if (typeof SIMD.Int16x8.equal === "undefined") { /** - * @param {int16x8} t An instance of int16x8. - * @param {int16x8} other An instance of int16x8. - * @return {int16x8} true or false in each lane depending on + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on * the result of t == other. */ - SIMD.int16x8.equal = function(t, other) { - t = SIMD.int16x8.check(t); - other = SIMD.int16x8.check(other); - var cs0 = t.s0 == other.s0; - var cs1 = t.s1 == other.s1; - var cs2 = t.s2 == other.s2; - var cs3 = t.s3 == other.s3; - var cs4 = t.s4 == other.s4; - var cs5 = t.s5 == other.s5; - var cs6 = t.s6 == other.s6; - var cs7 = t.s7 == other.s7; - return SIMD.int16x8.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); - } -} - -if (typeof SIMD.int16x8.notEqual === "undefined") { - /** - * @param {int16x8} t An instance of int16x8. - * @param {int16x8} other An instance of int16x8. - * @return {int16x8} true or false in each lane depending on + SIMD.Int16x8.equal = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.extractLane(t, 0) == SIMD.Int16x8.extractLane(other, 0); + var cs1 = + SIMD.Int16x8.extractLane(t, 1) == SIMD.Int16x8.extractLane(other, 1); + var cs2 = + SIMD.Int16x8.extractLane(t, 2) == SIMD.Int16x8.extractLane(other, 2); + var cs3 = + SIMD.Int16x8.extractLane(t, 3) == SIMD.Int16x8.extractLane(other, 3); + var cs4 = + SIMD.Int16x8.extractLane(t, 4) == SIMD.Int16x8.extractLane(other, 4); + var cs5 = + SIMD.Int16x8.extractLane(t, 5) == SIMD.Int16x8.extractLane(other, 5); + var cs6 = + SIMD.Int16x8.extractLane(t, 6) == SIMD.Int16x8.extractLane(other, 6); + var cs7 = + SIMD.Int16x8.extractLane(t, 7) == SIMD.Int16x8.extractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.notEqual === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on * the result of t != other. */ - SIMD.int16x8.notEqual = function(t, other) { - t = SIMD.int16x8.check(t); - other = SIMD.int16x8.check(other); - var cs0 = t.s0 != other.s0; - var cs1 = t.s1 != other.s1; - var cs2 = t.s2 != other.s2; - var cs3 = t.s3 != other.s3; - var cs4 = t.s4 != other.s4; - var cs5 = t.s5 != other.s5; - var cs6 = t.s6 != other.s6; - var cs7 = t.s7 != other.s7; - return SIMD.int16x8.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); - } -} - -if (typeof SIMD.int16x8.greaterThan === "undefined") { - /** - * @param {int16x8} t An instance of int16x8. - * @param {int16x8} other An instance of int16x8. - * @return {int16x8} true or false in each lane depending on + SIMD.Int16x8.notEqual = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.extractLane(t, 0) != SIMD.Int16x8.extractLane(other, 0); + var cs1 = + SIMD.Int16x8.extractLane(t, 1) != SIMD.Int16x8.extractLane(other, 1); + var cs2 = + SIMD.Int16x8.extractLane(t, 2) != SIMD.Int16x8.extractLane(other, 2); + var cs3 = + SIMD.Int16x8.extractLane(t, 3) != SIMD.Int16x8.extractLane(other, 3); + var cs4 = + SIMD.Int16x8.extractLane(t, 4) != SIMD.Int16x8.extractLane(other, 4); + var cs5 = + SIMD.Int16x8.extractLane(t, 5) != SIMD.Int16x8.extractLane(other, 5); + var cs6 = + SIMD.Int16x8.extractLane(t, 6) != SIMD.Int16x8.extractLane(other, 6); + var cs7 = + SIMD.Int16x8.extractLane(t, 7) != SIMD.Int16x8.extractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.greaterThan === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on * the result of t > other. */ - SIMD.int16x8.greaterThan = function(t, other) { - t = SIMD.int16x8.check(t); - other = SIMD.int16x8.check(other); - var cs0 = t.s0 > other.s0; - var cs1 = t.s1 > other.s1; - var cs2 = t.s2 > other.s2; - var cs3 = t.s3 > other.s3; - var cs4 = t.s4 > other.s4; - var cs5 = t.s5 > other.s5; - var cs6 = t.s6 > other.s6; - var cs7 = t.s7 > other.s7; - return SIMD.int16x8.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); - } -} - -if (typeof SIMD.int16x8.greaterThanOrEqual === "undefined") { - /** - * @param {int16x8} t An instance of int16x8. - * @param {int16x8} other An instance of int16x8. - * @return {int16x8} true or false in each lane depending on + SIMD.Int16x8.greaterThan = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.extractLane(t, 0) > SIMD.Int16x8.extractLane(other, 0); + var cs1 = + SIMD.Int16x8.extractLane(t, 1) > SIMD.Int16x8.extractLane(other, 1); + var cs2 = + SIMD.Int16x8.extractLane(t, 2) > SIMD.Int16x8.extractLane(other, 2); + var cs3 = + SIMD.Int16x8.extractLane(t, 3) > SIMD.Int16x8.extractLane(other, 3); + var cs4 = + SIMD.Int16x8.extractLane(t, 4) > SIMD.Int16x8.extractLane(other, 4); + var cs5 = + SIMD.Int16x8.extractLane(t, 5) > SIMD.Int16x8.extractLane(other, 5); + var cs6 = + SIMD.Int16x8.extractLane(t, 6) > SIMD.Int16x8.extractLane(other, 6); + var cs7 = + SIMD.Int16x8.extractLane(t, 7) > SIMD.Int16x8.extractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.unsignedGreaterThan === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on + * the result of t > other as unsigned values. + */ + SIMD.Int16x8.unsignedGreaterThan = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.unsignedExtractLane(t, 0) > SIMD.Int16x8.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int16x8.unsignedExtractLane(t, 1) > SIMD.Int16x8.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int16x8.unsignedExtractLane(t, 2) > SIMD.Int16x8.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int16x8.unsignedExtractLane(t, 3) > SIMD.Int16x8.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int16x8.unsignedExtractLane(t, 4) > SIMD.Int16x8.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int16x8.unsignedExtractLane(t, 5) > SIMD.Int16x8.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int16x8.unsignedExtractLane(t, 6) > SIMD.Int16x8.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int16x8.unsignedExtractLane(t, 7) > SIMD.Int16x8.unsignedExtractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.greaterThanOrEqual === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on * the result of t >= other. */ - SIMD.int16x8.greaterThanOrEqual = function(t, other) { - t = SIMD.int16x8.check(t); - other = SIMD.int16x8.check(other); - var cs0 = t.s0 >= other.s0; - var cs1 = t.s1 >= other.s1; - var cs2 = t.s2 >= other.s2; - var cs3 = t.s3 >= other.s3; - var cs4 = t.s4 >= other.s4; - var cs5 = t.s5 >= other.s5; - var cs6 = t.s6 >= other.s6; - var cs7 = t.s7 >= other.s7; - return SIMD.int16x8.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); - } -} - -if (typeof SIMD.int16x8.lessThan === "undefined") { - /** - * @param {int16x8} t An instance of int16x8. - * @param {int16x8} other An instance of int16x8. - * @return {int16x8} true or false in each lane depending on + SIMD.Int16x8.greaterThanOrEqual = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.extractLane(t, 0) >= SIMD.Int16x8.extractLane(other, 0); + var cs1 = + SIMD.Int16x8.extractLane(t, 1) >= SIMD.Int16x8.extractLane(other, 1); + var cs2 = + SIMD.Int16x8.extractLane(t, 2) >= SIMD.Int16x8.extractLane(other, 2); + var cs3 = + SIMD.Int16x8.extractLane(t, 3) >= SIMD.Int16x8.extractLane(other, 3); + var cs4 = + SIMD.Int16x8.extractLane(t, 4) >= SIMD.Int16x8.extractLane(other, 4); + var cs5 = + SIMD.Int16x8.extractLane(t, 5) >= SIMD.Int16x8.extractLane(other, 5); + var cs6 = + SIMD.Int16x8.extractLane(t, 6) >= SIMD.Int16x8.extractLane(other, 6); + var cs7 = + SIMD.Int16x8.extractLane(t, 7) >= SIMD.Int16x8.extractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.unsignedGreaterThanOrEqual === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on + * the result of t >= other as unsigned values. + */ + SIMD.Int16x8.unsignedGreaterThanOrEqual = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.unsignedExtractLane(t, 0) >= SIMD.Int16x8.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int16x8.unsignedExtractLane(t, 1) >= SIMD.Int16x8.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int16x8.unsignedExtractLane(t, 2) >= SIMD.Int16x8.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int16x8.unsignedExtractLane(t, 3) >= SIMD.Int16x8.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int16x8.unsignedExtractLane(t, 4) >= SIMD.Int16x8.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int16x8.unsignedExtractLane(t, 5) >= SIMD.Int16x8.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int16x8.unsignedExtractLane(t, 6) >= SIMD.Int16x8.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int16x8.unsignedExtractLane(t, 7) >= SIMD.Int16x8.unsignedExtractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.lessThan === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on * the result of t < other. */ - SIMD.int16x8.lessThan = function(t, other) { - t = SIMD.int16x8.check(t); - other = SIMD.int16x8.check(other); - var cs0 = t.s0 < other.s0; - var cs1 = t.s1 < other.s1; - var cs2 = t.s2 < other.s2; - var cs3 = t.s3 < other.s3; - var cs4 = t.s4 < other.s4; - var cs5 = t.s5 < other.s5; - var cs6 = t.s6 < other.s6; - var cs7 = t.s7 < other.s7; - return SIMD.int16x8.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); - } -} - -if (typeof SIMD.int16x8.lessThanOrEqual === "undefined") { - /** - * @param {int16x8} t An instance of int16x8. - * @param {int16x8} other An instance of int16x8. - * @return {int16x8} true or false in each lane depending on + SIMD.Int16x8.lessThan = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.extractLane(t, 0) < SIMD.Int16x8.extractLane(other, 0); + var cs1 = + SIMD.Int16x8.extractLane(t, 1) < SIMD.Int16x8.extractLane(other, 1); + var cs2 = + SIMD.Int16x8.extractLane(t, 2) < SIMD.Int16x8.extractLane(other, 2); + var cs3 = + SIMD.Int16x8.extractLane(t, 3) < SIMD.Int16x8.extractLane(other, 3); + var cs4 = + SIMD.Int16x8.extractLane(t, 4) < SIMD.Int16x8.extractLane(other, 4); + var cs5 = + SIMD.Int16x8.extractLane(t, 5) < SIMD.Int16x8.extractLane(other, 5); + var cs6 = + SIMD.Int16x8.extractLane(t, 6) < SIMD.Int16x8.extractLane(other, 6); + var cs7 = + SIMD.Int16x8.extractLane(t, 7) < SIMD.Int16x8.extractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.unsignedLessThan === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on + * the result of t < other as unsigned values. + */ + SIMD.Int16x8.unsignedLessThan = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.unsignedExtractLane(t, 0) < SIMD.Int16x8.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int16x8.unsignedExtractLane(t, 1) < SIMD.Int16x8.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int16x8.unsignedExtractLane(t, 2) < SIMD.Int16x8.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int16x8.unsignedExtractLane(t, 3) < SIMD.Int16x8.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int16x8.unsignedExtractLane(t, 4) < SIMD.Int16x8.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int16x8.unsignedExtractLane(t, 5) < SIMD.Int16x8.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int16x8.unsignedExtractLane(t, 6) < SIMD.Int16x8.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int16x8.unsignedExtractLane(t, 7) < SIMD.Int16x8.unsignedExtractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.lessThanOrEqual === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on * the result of t <= other. */ - SIMD.int16x8.lessThanOrEqual = function(t, other) { - t = SIMD.int16x8.check(t); - other = SIMD.int16x8.check(other); - var cs0 = t.s0 <= other.s0; - var cs1 = t.s1 <= other.s1; - var cs2 = t.s2 <= other.s2; - var cs3 = t.s3 <= other.s3; - var cs4 = t.s4 <= other.s4; - var cs5 = t.s5 <= other.s5; - var cs6 = t.s6 <= other.s6; - var cs7 = t.s7 <= other.s7; - return SIMD.int16x8.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); - } -} - -if (typeof SIMD.int16x8.shiftLeftByScalar === "undefined") { - /** - * @param {int16x8} a An instance of int16x8. + SIMD.Int16x8.lessThanOrEqual = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.extractLane(t, 0) <= SIMD.Int16x8.extractLane(other, 0); + var cs1 = + SIMD.Int16x8.extractLane(t, 1) <= SIMD.Int16x8.extractLane(other, 1); + var cs2 = + SIMD.Int16x8.extractLane(t, 2) <= SIMD.Int16x8.extractLane(other, 2); + var cs3 = + SIMD.Int16x8.extractLane(t, 3) <= SIMD.Int16x8.extractLane(other, 3); + var cs4 = + SIMD.Int16x8.extractLane(t, 4) <= SIMD.Int16x8.extractLane(other, 4); + var cs5 = + SIMD.Int16x8.extractLane(t, 5) <= SIMD.Int16x8.extractLane(other, 5); + var cs6 = + SIMD.Int16x8.extractLane(t, 6) <= SIMD.Int16x8.extractLane(other, 6); + var cs7 = + SIMD.Int16x8.extractLane(t, 7) <= SIMD.Int16x8.extractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.unsignedLessThanOrEqual === "undefined") { + /** + * @param {Int16x8} t An instance of Int16x8. + * @param {Int16x8} other An instance of Int16x8. + * @return {Bool16x8} true or false in each lane depending on + * the result of t <= other as unsigned values. + */ + SIMD.Int16x8.unsignedLessThanOrEqual = function(t, other) { + t = SIMD.Int16x8.check(t); + other = SIMD.Int16x8.check(other); + var cs0 = + SIMD.Int16x8.unsignedExtractLane(t, 0) <= SIMD.Int16x8.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int16x8.unsignedExtractLane(t, 1) <= SIMD.Int16x8.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int16x8.unsignedExtractLane(t, 2) <= SIMD.Int16x8.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int16x8.unsignedExtractLane(t, 3) <= SIMD.Int16x8.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int16x8.unsignedExtractLane(t, 4) <= SIMD.Int16x8.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int16x8.unsignedExtractLane(t, 5) <= SIMD.Int16x8.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int16x8.unsignedExtractLane(t, 6) <= SIMD.Int16x8.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int16x8.unsignedExtractLane(t, 7) <= SIMD.Int16x8.unsignedExtractLane(other, 7); + return SIMD.Bool16x8(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7); + } +} + +if (typeof SIMD.Int16x8.shiftLeftByScalar === "undefined") { + /** + * @param {Int16x8} a An instance of Int16x8. * @param {integer} bits Bit count to shift by. - * @return {int16x8} lanes in a shifted by bits. + * @return {Int16x8} lanes in a shifted by bits. */ - SIMD.int16x8.shiftLeftByScalar = function(a, bits) { - a = SIMD.int16x8.check(a); + SIMD.Int16x8.shiftLeftByScalar = function(a, bits) { + a = SIMD.Int16x8.check(a); if (bits>>>0 > 16) bits = 16; - var s0 = a.s0 << bits; - var s1 = a.s1 << bits; - var s2 = a.s2 << bits; - var s3 = a.s3 << bits; - var s4 = a.s4 << bits; - var s5 = a.s5 << bits; - var s6 = a.s6 << bits; - var s7 = a.s7 << bits; - return SIMD.int16x8(s0, s1, s2, s3, s4, s5, s6, s7); + var s0 = SIMD.Int16x8.extractLane(a, 0) << bits; + var s1 = SIMD.Int16x8.extractLane(a, 1) << bits; + var s2 = SIMD.Int16x8.extractLane(a, 2) << bits; + var s3 = SIMD.Int16x8.extractLane(a, 3) << bits; + var s4 = SIMD.Int16x8.extractLane(a, 4) << bits; + var s5 = SIMD.Int16x8.extractLane(a, 5) << bits; + var s6 = SIMD.Int16x8.extractLane(a, 6) << bits; + var s7 = SIMD.Int16x8.extractLane(a, 7) << bits; + return SIMD.Int16x8(s0, s1, s2, s3, s4, s5, s6, s7); } } -if (typeof SIMD.int16x8.shiftRightLogicalByScalar === "undefined") { +if (typeof SIMD.Int16x8.shiftRightLogicalByScalar === "undefined") { /** - * @param {int16x8} a An instance of int16x8. + * @param {Int16x8} a An instance of Int16x8. * @param {integer} bits Bit count to shift by. - * @return {int16x8} lanes in a shifted by bits. + * @return {Int16x8} lanes in a shifted by bits. */ - SIMD.int16x8.shiftRightLogicalByScalar = function(a, bits) { - a = SIMD.int16x8.check(a); + SIMD.Int16x8.shiftRightLogicalByScalar = function(a, bits) { + a = SIMD.Int16x8.check(a); if (bits>>>0 > 16) bits = 16; - var s0 = (a.s0 & 0xffff) >>> bits; - var s1 = (a.s1 & 0xffff) >>> bits; - var s2 = (a.s2 & 0xffff) >>> bits; - var s3 = (a.s3 & 0xffff) >>> bits; - var s4 = (a.s4 & 0xffff) >>> bits; - var s5 = (a.s5 & 0xffff) >>> bits; - var s6 = (a.s6 & 0xffff) >>> bits; - var s7 = (a.s7 & 0xffff) >>> bits; - return SIMD.int16x8(s0, s1, s2, s3, s4, s5, s6, s7); + var s0 = (SIMD.Int16x8.extractLane(a, 0) & 0xffff) >>> bits; + var s1 = (SIMD.Int16x8.extractLane(a, 1) & 0xffff) >>> bits; + var s2 = (SIMD.Int16x8.extractLane(a, 2) & 0xffff) >>> bits; + var s3 = (SIMD.Int16x8.extractLane(a, 3) & 0xffff) >>> bits; + var s4 = (SIMD.Int16x8.extractLane(a, 4) & 0xffff) >>> bits; + var s5 = (SIMD.Int16x8.extractLane(a, 5) & 0xffff) >>> bits; + var s6 = (SIMD.Int16x8.extractLane(a, 6) & 0xffff) >>> bits; + var s7 = (SIMD.Int16x8.extractLane(a, 7) & 0xffff) >>> bits; + return SIMD.Int16x8(s0, s1, s2, s3, s4, s5, s6, s7); } } -if (typeof SIMD.int16x8.shiftRightArithmeticByScalar === "undefined") { +if (typeof SIMD.Int16x8.shiftRightArithmeticByScalar === "undefined") { /** - * @param {int16x8} a An instance of int16x8. + * @param {Int16x8} a An instance of Int16x8. * @param {integer} bits Bit count to shift by. - * @return {int16x8} lanes in a shifted by bits. + * @return {Int16x8} lanes in a shifted by bits. */ - SIMD.int16x8.shiftRightArithmeticByScalar = function(a, bits) { - a = SIMD.int16x8.check(a); + SIMD.Int16x8.shiftRightArithmeticByScalar = function(a, bits) { + a = SIMD.Int16x8.check(a); if (bits>>>0 > 16) bits = 16; - var s0 = a.s0 >> bits; - var s1 = a.s1 >> bits; - var s2 = a.s2 >> bits; - var s3 = a.s3 >> bits; - var s4 = a.s4 >> bits; - var s5 = a.s5 >> bits; - var s6 = a.s6 >> bits; - var s7 = a.s7 >> bits; - return SIMD.int16x8(s0, s1, s2, s3, s4, s5, s6, s7); + var s0 = SIMD.Int16x8.extractLane(a, 0) >> bits; + var s1 = SIMD.Int16x8.extractLane(a, 1) >> bits; + var s2 = SIMD.Int16x8.extractLane(a, 2) >> bits; + var s3 = SIMD.Int16x8.extractLane(a, 3) >> bits; + var s4 = SIMD.Int16x8.extractLane(a, 4) >> bits; + var s5 = SIMD.Int16x8.extractLane(a, 5) >> bits; + var s6 = SIMD.Int16x8.extractLane(a, 6) >> bits; + var s7 = SIMD.Int16x8.extractLane(a, 7) >> bits; + return SIMD.Int16x8(s0, s1, s2, s3, s4, s5, s6, s7); } } -if (typeof SIMD.int16x8.load === "undefined") { +if (typeof SIMD.Int16x8.load === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {int16x8} New instance of int16x8. + * @return {Int16x8} New instance of Int16x8. */ - SIMD.int16x8.load = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int16x8.load = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var i16temp = _SIMD_PRIVATE._i16x8; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : + var i16temp = _i16x8; + var array = bpe == 1 ? _i8x16 : bpe == 2 ? i16temp : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.int16x8(i16temp[0], i16temp[1], i16temp[2], i16temp[3], + return SIMD.Int16x8(i16temp[0], i16temp[1], i16temp[2], i16temp[3], i16temp[4], i16temp[5], i16temp[6], i16temp[7]); } } -if (typeof SIMD.int16x8.store === "undefined") { +if (typeof SIMD.Int16x8.store === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {int16x8} value An instance of int16x8. - * @return {void} + * @param {Int16x8} value An instance of Int16x8. + * @return {Int16x8} value */ - SIMD.int16x8.store = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int16x8.store = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.int16x8.check(value); - _SIMD_PRIVATE._i16x8[0] = value.s0; - _SIMD_PRIVATE._i16x8[1] = value.s1; - _SIMD_PRIVATE._i16x8[2] = value.s2; - _SIMD_PRIVATE._i16x8[3] = value.s3; - _SIMD_PRIVATE._i16x8[4] = value.s4; - _SIMD_PRIVATE._i16x8[5] = value.s5; - _SIMD_PRIVATE._i16x8[6] = value.s6; - _SIMD_PRIVATE._i16x8[7] = value.s7; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + value = SIMD.Int16x8.check(value); + _i16x8[0] = SIMD.Int16x8.extractLane(value, 0); + _i16x8[1] = SIMD.Int16x8.extractLane(value, 1); + _i16x8[2] = SIMD.Int16x8.extractLane(value, 2); + _i16x8[3] = SIMD.Int16x8.extractLane(value, 3); + _i16x8[4] = SIMD.Int16x8.extractLane(value, 4); + _i16x8[5] = SIMD.Int16x8.extractLane(value, 5); + _i16x8[6] = SIMD.Int16x8.extractLane(value, 6); + _i16x8[7] = SIMD.Int16x8.extractLane(value, 7); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; - } -} - -if (typeof SIMD.int8x16.and === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. - * @param {int8x16} b An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of a & b. - */ - SIMD.int8x16.and = function(a, b) { - a = SIMD.int8x16.check(a); - b = SIMD.int8x16.check(b); - return SIMD.int8x16(a.s0 & b.s0, a.s1 & b.s1, a.s2 & b.s2, a.s3 & b.s3, - a.s4 & b.s4, a.s5 & b.s5, a.s6 & b.s6, a.s7 & b.s7, - a.s8 & b.s8, a.s9 & b.s9, a.s10 & b.s10, a.s11 & b.s11, - a.s12 & b.s12, a.s13 & b.s13, a.s14 & b.s14, a.s15 & b.s15); - } -} - -if (typeof SIMD.int8x16.or === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. - * @param {int8x16} b An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of a | b. - */ - SIMD.int8x16.or = function(a, b) { - a = SIMD.int8x16.check(a); - b = SIMD.int8x16.check(b); - return SIMD.int8x16(a.s0 | b.s0, a.s1 | b.s1, a.s2 | b.s2, a.s3 | b.s3, - a.s4 | b.s4, a.s5 | b.s5, a.s6 | b.s6, a.s7 | b.s7, - a.s8 | b.s8, a.s9 | b.s9, a.s10 | b.s10, a.s11 | b.s11, - a.s12 | b.s12, a.s13 | b.s13, a.s14 | b.s14, a.s15 | b.s15); - } -} - -if (typeof SIMD.int8x16.xor === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. - * @param {int8x16} b An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of a ^ b. - */ - SIMD.int8x16.xor = function(a, b) { - a = SIMD.int8x16.check(a); - b = SIMD.int8x16.check(b); - return SIMD.int8x16(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, - a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7, - a.s8 ^ b.s8, a.s9 ^ b.s9, a.s10 ^ b.s10, a.s11 ^ b.s11, - a.s12 ^ b.s12, a.s13 ^ b.s13, a.s14 ^ b.s14, a.s15 ^ b.s15); - } -} - -if (typeof SIMD.int8x16.not === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of ~t - */ - SIMD.int8x16.not = function(t) { - t = SIMD.int8x16.check(t); - return SIMD.int8x16(~t.s0, ~t.s1, ~t.s2, ~t.s3, - ~t.s4, ~t.s5, ~t.s6, ~t.s7, - ~t.s8, ~t.s9, ~t.s10, ~t.s11, - ~t.s12, ~t.s13, ~t.s14, ~t.s15); - } -} - -if (typeof SIMD.int8x16.neg === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of -t - */ - SIMD.int8x16.neg = function(t) { - t = SIMD.int8x16.check(t); - return SIMD.int8x16(-t.s0, -t.s1, -t.s2, -t.s3, - -t.s4, -t.s5, -t.s6, -t.s7, - -t.s8, -t.s9, -t.s10, -t.s11, - -t.s12, -t.s13, -t.s14, -t.s15); - } -} - -if (typeof SIMD.int8x16.add === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. - * @param {int8x16} b An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of a + b. - */ - SIMD.int8x16.add = function(a, b) { - a = SIMD.int8x16.check(a); - b = SIMD.int8x16.check(b); - return SIMD.int8x16(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, - a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7, - a.s8 + b.s8, a.s9 + b.s9, a.s10 + b.s10, a.s11 + b.s11, - a.s12 + b.s12, a.s13 + b.s13, a.s14 + b.s14, a.s15 + b.s15); - } -} - -if (typeof SIMD.int8x16.sub === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. - * @param {int8x16} b An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of a - b. - */ - SIMD.int8x16.sub = function(a, b) { - a = SIMD.int8x16.check(a); - b = SIMD.int8x16.check(b); - return SIMD.int8x16(a.s0 - b.s0, a.s1 - b.s1, a.s2 - b.s2, a.s3 - b.s3, - a.s4 - b.s4, a.s5 - b.s5, a.s6 - b.s6, a.s7 - b.s7, - a.s8 - b.s8, a.s9 - b.s9, a.s10 - b.s10, a.s11 - b.s11, - a.s12 - b.s12, a.s13 - b.s13, a.s14 - b.s14, a.s15 - b.s15); - } -} - -if (typeof SIMD.int8x16.mul === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. - * @param {int8x16} b An instance of int8x16. - * @return {int8x16} New instance of int8x16 with values of a * b. - */ - SIMD.int8x16.mul = function(a, b) { - a = SIMD.int8x16.check(a); - b = SIMD.int8x16.check(b); - return SIMD.int8x16(Math.imul(a.s0, b.s0), Math.imul(a.s1, b.s1), - Math.imul(a.s2, b.s2), Math.imul(a.s3, b.s3), - Math.imul(a.s4, b.s4), Math.imul(a.s5, b.s5), - Math.imul(a.s6, b.s6), Math.imul(a.s7, b.s7), - Math.imul(a.s8, b.s8), Math.imul(a.s9, b.s9), - Math.imul(a.s10, b.s10), Math.imul(a.s11, b.s11), - Math.imul(a.s12, b.s12), Math.imul(a.s13, b.s13), - Math.imul(a.s14, b.s14), Math.imul(a.s15, b.s15)); - } -} - -if (typeof SIMD.int8x16.swizzle === "undefined") { - /** - * @param {int8x16} t An instance of int8x16 to be swizzled. + return value; + } +} + +if (typeof SIMD.Int8x16.and === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a & b. + */ + SIMD.Int8x16.and = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int8x16( + SIMD.Int8x16.extractLane(a, 0) & SIMD.Int8x16.extractLane(b, 0), + SIMD.Int8x16.extractLane(a, 1) & SIMD.Int8x16.extractLane(b, 1), + SIMD.Int8x16.extractLane(a, 2) & SIMD.Int8x16.extractLane(b, 2), + SIMD.Int8x16.extractLane(a, 3) & SIMD.Int8x16.extractLane(b, 3), + SIMD.Int8x16.extractLane(a, 4) & SIMD.Int8x16.extractLane(b, 4), + SIMD.Int8x16.extractLane(a, 5) & SIMD.Int8x16.extractLane(b, 5), + SIMD.Int8x16.extractLane(a, 6) & SIMD.Int8x16.extractLane(b, 6), + SIMD.Int8x16.extractLane(a, 7) & SIMD.Int8x16.extractLane(b, 7), + SIMD.Int8x16.extractLane(a, 8) & SIMD.Int8x16.extractLane(b, 8), + SIMD.Int8x16.extractLane(a, 9) & SIMD.Int8x16.extractLane(b, 9), + SIMD.Int8x16.extractLane(a, 10) & SIMD.Int8x16.extractLane(b, 10), + SIMD.Int8x16.extractLane(a, 11) & SIMD.Int8x16.extractLane(b, 11), + SIMD.Int8x16.extractLane(a, 12) & SIMD.Int8x16.extractLane(b, 12), + SIMD.Int8x16.extractLane(a, 13) & SIMD.Int8x16.extractLane(b, 13), + SIMD.Int8x16.extractLane(a, 14) & SIMD.Int8x16.extractLane(b, 14), + SIMD.Int8x16.extractLane(a, 15) & SIMD.Int8x16.extractLane(b, 15)); + } +} + +if (typeof SIMD.Int8x16.or === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a | b. + */ + SIMD.Int8x16.or = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int8x16( + SIMD.Int8x16.extractLane(a, 0) | SIMD.Int8x16.extractLane(b, 0), + SIMD.Int8x16.extractLane(a, 1) | SIMD.Int8x16.extractLane(b, 1), + SIMD.Int8x16.extractLane(a, 2) | SIMD.Int8x16.extractLane(b, 2), + SIMD.Int8x16.extractLane(a, 3) | SIMD.Int8x16.extractLane(b, 3), + SIMD.Int8x16.extractLane(a, 4) | SIMD.Int8x16.extractLane(b, 4), + SIMD.Int8x16.extractLane(a, 5) | SIMD.Int8x16.extractLane(b, 5), + SIMD.Int8x16.extractLane(a, 6) | SIMD.Int8x16.extractLane(b, 6), + SIMD.Int8x16.extractLane(a, 7) | SIMD.Int8x16.extractLane(b, 7), + SIMD.Int8x16.extractLane(a, 8) | SIMD.Int8x16.extractLane(b, 8), + SIMD.Int8x16.extractLane(a, 9) | SIMD.Int8x16.extractLane(b, 9), + SIMD.Int8x16.extractLane(a, 10) | SIMD.Int8x16.extractLane(b, 10), + SIMD.Int8x16.extractLane(a, 11) | SIMD.Int8x16.extractLane(b, 11), + SIMD.Int8x16.extractLane(a, 12) | SIMD.Int8x16.extractLane(b, 12), + SIMD.Int8x16.extractLane(a, 13) | SIMD.Int8x16.extractLane(b, 13), + SIMD.Int8x16.extractLane(a, 14) | SIMD.Int8x16.extractLane(b, 14), + SIMD.Int8x16.extractLane(a, 15) | SIMD.Int8x16.extractLane(b, 15)); + } +} + +if (typeof SIMD.Int8x16.xor === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a ^ b. + */ + SIMD.Int8x16.xor = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int8x16( + SIMD.Int8x16.extractLane(a, 0) ^ SIMD.Int8x16.extractLane(b, 0), + SIMD.Int8x16.extractLane(a, 1) ^ SIMD.Int8x16.extractLane(b, 1), + SIMD.Int8x16.extractLane(a, 2) ^ SIMD.Int8x16.extractLane(b, 2), + SIMD.Int8x16.extractLane(a, 3) ^ SIMD.Int8x16.extractLane(b, 3), + SIMD.Int8x16.extractLane(a, 4) ^ SIMD.Int8x16.extractLane(b, 4), + SIMD.Int8x16.extractLane(a, 5) ^ SIMD.Int8x16.extractLane(b, 5), + SIMD.Int8x16.extractLane(a, 6) ^ SIMD.Int8x16.extractLane(b, 6), + SIMD.Int8x16.extractLane(a, 7) ^ SIMD.Int8x16.extractLane(b, 7), + SIMD.Int8x16.extractLane(a, 8) ^ SIMD.Int8x16.extractLane(b, 8), + SIMD.Int8x16.extractLane(a, 9) ^ SIMD.Int8x16.extractLane(b, 9), + SIMD.Int8x16.extractLane(a, 10) ^ SIMD.Int8x16.extractLane(b, 10), + SIMD.Int8x16.extractLane(a, 11) ^ SIMD.Int8x16.extractLane(b, 11), + SIMD.Int8x16.extractLane(a, 12) ^ SIMD.Int8x16.extractLane(b, 12), + SIMD.Int8x16.extractLane(a, 13) ^ SIMD.Int8x16.extractLane(b, 13), + SIMD.Int8x16.extractLane(a, 14) ^ SIMD.Int8x16.extractLane(b, 14), + SIMD.Int8x16.extractLane(a, 15) ^ SIMD.Int8x16.extractLane(b, 15)); + } +} + +if (typeof SIMD.Int8x16.not === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of ~t + */ + SIMD.Int8x16.not = function(t) { + t = SIMD.Int8x16.check(t); + return SIMD.Int8x16(~SIMD.Int8x16.extractLane(t, 0), + ~SIMD.Int8x16.extractLane(t, 1), + ~SIMD.Int8x16.extractLane(t, 2), + ~SIMD.Int8x16.extractLane(t, 3), + ~SIMD.Int8x16.extractLane(t, 4), + ~SIMD.Int8x16.extractLane(t, 5), + ~SIMD.Int8x16.extractLane(t, 6), + ~SIMD.Int8x16.extractLane(t, 7), + ~SIMD.Int8x16.extractLane(t, 8), + ~SIMD.Int8x16.extractLane(t, 9), + ~SIMD.Int8x16.extractLane(t, 10), + ~SIMD.Int8x16.extractLane(t, 11), + ~SIMD.Int8x16.extractLane(t, 12), + ~SIMD.Int8x16.extractLane(t, 13), + ~SIMD.Int8x16.extractLane(t, 14), + ~SIMD.Int8x16.extractLane(t, 15)); + } +} + +if (typeof SIMD.Int8x16.neg === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of -t + */ + SIMD.Int8x16.neg = function(t) { + t = SIMD.Int8x16.check(t); + return SIMD.Int8x16(-SIMD.Int8x16.extractLane(t, 0), + -SIMD.Int8x16.extractLane(t, 1), + -SIMD.Int8x16.extractLane(t, 2), + -SIMD.Int8x16.extractLane(t, 3), + -SIMD.Int8x16.extractLane(t, 4), + -SIMD.Int8x16.extractLane(t, 5), + -SIMD.Int8x16.extractLane(t, 6), + -SIMD.Int8x16.extractLane(t, 7), + -SIMD.Int8x16.extractLane(t, 8), + -SIMD.Int8x16.extractLane(t, 9), + -SIMD.Int8x16.extractLane(t, 10), + -SIMD.Int8x16.extractLane(t, 11), + -SIMD.Int8x16.extractLane(t, 12), + -SIMD.Int8x16.extractLane(t, 13), + -SIMD.Int8x16.extractLane(t, 14), + -SIMD.Int8x16.extractLane(t, 15)); + } +} + +if (typeof SIMD.Int8x16.add === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a + b. + */ + SIMD.Int8x16.add = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int8x16( + SIMD.Int8x16.extractLane(a, 0) + SIMD.Int8x16.extractLane(b, 0), + SIMD.Int8x16.extractLane(a, 1) + SIMD.Int8x16.extractLane(b, 1), + SIMD.Int8x16.extractLane(a, 2) + SIMD.Int8x16.extractLane(b, 2), + SIMD.Int8x16.extractLane(a, 3) + SIMD.Int8x16.extractLane(b, 3), + SIMD.Int8x16.extractLane(a, 4) + SIMD.Int8x16.extractLane(b, 4), + SIMD.Int8x16.extractLane(a, 5) + SIMD.Int8x16.extractLane(b, 5), + SIMD.Int8x16.extractLane(a, 6) + SIMD.Int8x16.extractLane(b, 6), + SIMD.Int8x16.extractLane(a, 7) + SIMD.Int8x16.extractLane(b, 7), + SIMD.Int8x16.extractLane(a, 8) + SIMD.Int8x16.extractLane(b, 8), + SIMD.Int8x16.extractLane(a, 9) + SIMD.Int8x16.extractLane(b, 9), + SIMD.Int8x16.extractLane(a, 10) + SIMD.Int8x16.extractLane(b, 10), + SIMD.Int8x16.extractLane(a, 11) + SIMD.Int8x16.extractLane(b, 11), + SIMD.Int8x16.extractLane(a, 12) + SIMD.Int8x16.extractLane(b, 12), + SIMD.Int8x16.extractLane(a, 13) + SIMD.Int8x16.extractLane(b, 13), + SIMD.Int8x16.extractLane(a, 14) + SIMD.Int8x16.extractLane(b, 14), + SIMD.Int8x16.extractLane(a, 15) + SIMD.Int8x16.extractLane(b, 15)); + } +} + +if (typeof SIMD.Int8x16.sub === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a - b. + */ + SIMD.Int8x16.sub = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int8x16( + SIMD.Int8x16.extractLane(a, 0) - SIMD.Int8x16.extractLane(b, 0), + SIMD.Int8x16.extractLane(a, 1) - SIMD.Int8x16.extractLane(b, 1), + SIMD.Int8x16.extractLane(a, 2) - SIMD.Int8x16.extractLane(b, 2), + SIMD.Int8x16.extractLane(a, 3) - SIMD.Int8x16.extractLane(b, 3), + SIMD.Int8x16.extractLane(a, 4) - SIMD.Int8x16.extractLane(b, 4), + SIMD.Int8x16.extractLane(a, 5) - SIMD.Int8x16.extractLane(b, 5), + SIMD.Int8x16.extractLane(a, 6) - SIMD.Int8x16.extractLane(b, 6), + SIMD.Int8x16.extractLane(a, 7) - SIMD.Int8x16.extractLane(b, 7), + SIMD.Int8x16.extractLane(a, 8) - SIMD.Int8x16.extractLane(b, 8), + SIMD.Int8x16.extractLane(a, 9) - SIMD.Int8x16.extractLane(b, 9), + SIMD.Int8x16.extractLane(a, 10) - SIMD.Int8x16.extractLane(b, 10), + SIMD.Int8x16.extractLane(a, 11) - SIMD.Int8x16.extractLane(b, 11), + SIMD.Int8x16.extractLane(a, 12) - SIMD.Int8x16.extractLane(b, 12), + SIMD.Int8x16.extractLane(a, 13) - SIMD.Int8x16.extractLane(b, 13), + SIMD.Int8x16.extractLane(a, 14) - SIMD.Int8x16.extractLane(b, 14), + SIMD.Int8x16.extractLane(a, 15) - SIMD.Int8x16.extractLane(b, 15)); + } +} + +if (typeof SIMD.Int8x16.mul === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a * b. + */ + SIMD.Int8x16.mul = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int8x16(Math.imul(SIMD.Int8x16.extractLane(a, 0), + SIMD.Int8x16.extractLane(b, 0)), + Math.imul(SIMD.Int8x16.extractLane(a, 1), + SIMD.Int8x16.extractLane(b, 1)), + Math.imul(SIMD.Int8x16.extractLane(a, 2), + SIMD.Int8x16.extractLane(b, 2)), + Math.imul(SIMD.Int8x16.extractLane(a, 3), + SIMD.Int8x16.extractLane(b, 3)), + Math.imul(SIMD.Int8x16.extractLane(a, 4), + SIMD.Int8x16.extractLane(b, 4)), + Math.imul(SIMD.Int8x16.extractLane(a, 5), + SIMD.Int8x16.extractLane(b, 5)), + Math.imul(SIMD.Int8x16.extractLane(a, 6), + SIMD.Int8x16.extractLane(b, 6)), + Math.imul(SIMD.Int8x16.extractLane(a, 7), + SIMD.Int8x16.extractLane(b, 7)), + Math.imul(SIMD.Int8x16.extractLane(a, 8), + SIMD.Int8x16.extractLane(b, 8)), + Math.imul(SIMD.Int8x16.extractLane(a, 9), + SIMD.Int8x16.extractLane(b, 9)), + Math.imul(SIMD.Int8x16.extractLane(a, 10), + SIMD.Int8x16.extractLane(b, 10)), + Math.imul(SIMD.Int8x16.extractLane(a, 11), + SIMD.Int8x16.extractLane(b, 11)), + Math.imul(SIMD.Int8x16.extractLane(a, 12), + SIMD.Int8x16.extractLane(b, 12)), + Math.imul(SIMD.Int8x16.extractLane(a, 13), + SIMD.Int8x16.extractLane(b, 13)), + Math.imul(SIMD.Int8x16.extractLane(a, 14), + SIMD.Int8x16.extractLane(b, 14)), + Math.imul(SIMD.Int8x16.extractLane(a, 15), + SIMD.Int8x16.extractLane(b, 15))); + } +} + +if (typeof SIMD.Int8x16.swizzle === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16 to be swizzled. * @param {integer} s0 - Index in t for lane s0 * @param {integer} s1 - Index in t for lane s1 * @param {integer} s2 - Index in t for lane s2 @@ -3600,42 +4486,58 @@ if (typeof SIMD.int8x16.swizzle === "undefined") { * @param {integer} s13 - Index in t for lane s13 * @param {integer} s14 - Index in t for lane s14 * @param {integer} s15 - Index in t for lane s15 - * @return {int8x16} New instance of int8x16 with lanes swizzled. + * @return {Int8x16} New instance of Int8x16 with lanes swizzled. */ - SIMD.int8x16.swizzle = function(t, s0, s1, s2, s3, s4, s5, s6, s7, + SIMD.Int8x16.swizzle = function(t, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15) { - t = SIMD.int8x16.check(t); - var storage = _SIMD_PRIVATE._i8x16; - storage[0] = t.s0; - storage[1] = t.s1; - storage[2] = t.s2; - storage[3] = t.s3; - storage[4] = t.s4; - storage[5] = t.s5; - storage[6] = t.s6; - storage[7] = t.s7; - storage[8] = t.s8; - storage[9] = t.s9; - storage[10] = t.s10; - storage[11] = t.s11; - storage[12] = t.s12; - storage[13] = t.s13; - storage[14] = t.s14; - storage[15] = t.s15; - return SIMD.int8x16(storage[s0], storage[s1], storage[s2], storage[s3], + t = SIMD.Int8x16.check(t); + check16(s0); + check16(s1); + check16(s2); + check16(s3); + check16(s4); + check16(s5); + check16(s6); + check16(s7); + check16(s8); + check16(s9); + check16(s10); + check16(s11); + check16(s12); + check16(s13); + check16(s14); + check16(s15); + var storage = _i8x16; + storage[0] = SIMD.Int8x16.extractLane(t, 0); + storage[1] = SIMD.Int8x16.extractLane(t, 1); + storage[2] = SIMD.Int8x16.extractLane(t, 2); + storage[3] = SIMD.Int8x16.extractLane(t, 3); + storage[4] = SIMD.Int8x16.extractLane(t, 4); + storage[5] = SIMD.Int8x16.extractLane(t, 5); + storage[6] = SIMD.Int8x16.extractLane(t, 6); + storage[7] = SIMD.Int8x16.extractLane(t, 7); + storage[8] = SIMD.Int8x16.extractLane(t, 8); + storage[9] = SIMD.Int8x16.extractLane(t, 9); + storage[10] = SIMD.Int8x16.extractLane(t, 10); + storage[11] = SIMD.Int8x16.extractLane(t, 11); + storage[12] = SIMD.Int8x16.extractLane(t, 12); + storage[13] = SIMD.Int8x16.extractLane(t, 13); + storage[14] = SIMD.Int8x16.extractLane(t, 14); + storage[15] = SIMD.Int8x16.extractLane(t, 15); + return SIMD.Int8x16(storage[s0], storage[s1], storage[s2], storage[s3], storage[s4], storage[s5], storage[s6], storage[s7], storage[s8], storage[s9], storage[s10], storage[s11], storage[s12], storage[s13], storage[s14], storage[s15]); } } -if (typeof SIMD.int8x16.shuffle === "undefined") { +if (typeof SIMD.Int8x16.shuffle === "undefined") { - _SIMD_PRIVATE._i8x32 = new Int8Array(32); + _i8x32 = new Int8Array(32); /** - * @param {int8x16} t0 An instance of int8x16 to be shuffled. - * @param {int8x16} t1 An instance of int8x16 to be shuffled. + * @param {Int8x16} t0 An instance of Int8x16 to be shuffled. + * @param {Int8x16} t1 An instance of Int8x16 to be shuffled. * @param {integer} s0 - Index in concatenation of t0 and t1 for lane s0 * @param {integer} s1 - Index in concatenation of t0 and t1 for lane s1 * @param {integer} s2 - Index in concatenation of t0 and t1 for lane s2 @@ -3652,802 +4554,984 @@ if (typeof SIMD.int8x16.shuffle === "undefined") { * @param {integer} s13 - Index in concatenation of t0 and t1 for lane s13 * @param {integer} s14 - Index in concatenation of t0 and t1 for lane s14 * @param {integer} s15 - Index in concatenation of t0 and t1 for lane s15 - * @return {int8x16} New instance of int8x16 with lanes shuffled. + * @return {Int8x16} New instance of Int8x16 with lanes shuffled. */ - SIMD.int8x16.shuffle = function(t0, t1, s0, s1, s2, s3, s4, s5, s6, s7, + SIMD.Int8x16.shuffle = function(t0, t1, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15) { - t0 = SIMD.int8x16.check(t0); - t1 = SIMD.int8x16.check(t1); - var storage = _SIMD_PRIVATE._i8x32; - storage[0] = t0.s0; - storage[1] = t0.s1; - storage[2] = t0.s2; - storage[3] = t0.s3; - storage[4] = t0.s4; - storage[5] = t0.s5; - storage[6] = t0.s6; - storage[7] = t0.s7; - storage[8] = t0.s8; - storage[9] = t0.s9; - storage[10] = t0.s10; - storage[11] = t0.s11; - storage[12] = t0.s12; - storage[13] = t0.s13; - storage[14] = t0.s14; - storage[15] = t0.s15; - storage[16] = t1.s0; - storage[17] = t1.s1; - storage[18] = t1.s2; - storage[19] = t1.s3; - storage[20] = t1.s4; - storage[21] = t1.s5; - storage[22] = t1.s6; - storage[23] = t1.s7; - storage[24] = t1.s8; - storage[25] = t1.s9; - storage[26] = t1.s10; - storage[27] = t1.s11; - storage[28] = t1.s12; - storage[29] = t1.s13; - storage[30] = t1.s14; - storage[31] = t1.s15; - return SIMD.int8x16(storage[s0], storage[s1], storage[s2], storage[s3], + t0 = SIMD.Int8x16.check(t0); + t1 = SIMD.Int8x16.check(t1); + check32(s0); + check32(s1); + check32(s2); + check32(s3); + check32(s4); + check32(s5); + check32(s6); + check32(s7); + check32(s8); + check32(s9); + check32(s10); + check32(s11); + check32(s12); + check32(s13); + check32(s14); + check32(s15); + var storage = _i8x32; + storage[0] = SIMD.Int8x16.extractLane(t0, 0); + storage[1] = SIMD.Int8x16.extractLane(t0, 1); + storage[2] = SIMD.Int8x16.extractLane(t0, 2); + storage[3] = SIMD.Int8x16.extractLane(t0, 3); + storage[4] = SIMD.Int8x16.extractLane(t0, 4); + storage[5] = SIMD.Int8x16.extractLane(t0, 5); + storage[6] = SIMD.Int8x16.extractLane(t0, 6); + storage[7] = SIMD.Int8x16.extractLane(t0, 7); + storage[8] = SIMD.Int8x16.extractLane(t0, 8); + storage[9] = SIMD.Int8x16.extractLane(t0, 9); + storage[10] = SIMD.Int8x16.extractLane(t0, 10); + storage[11] = SIMD.Int8x16.extractLane(t0, 11); + storage[12] = SIMD.Int8x16.extractLane(t0, 12); + storage[13] = SIMD.Int8x16.extractLane(t0, 13); + storage[14] = SIMD.Int8x16.extractLane(t0, 14); + storage[15] = SIMD.Int8x16.extractLane(t0, 15); + storage[16] = SIMD.Int8x16.extractLane(t1, 0); + storage[17] = SIMD.Int8x16.extractLane(t1, 1); + storage[18] = SIMD.Int8x16.extractLane(t1, 2); + storage[19] = SIMD.Int8x16.extractLane(t1, 3); + storage[20] = SIMD.Int8x16.extractLane(t1, 4); + storage[21] = SIMD.Int8x16.extractLane(t1, 5); + storage[22] = SIMD.Int8x16.extractLane(t1, 6); + storage[23] = SIMD.Int8x16.extractLane(t1, 7); + storage[24] = SIMD.Int8x16.extractLane(t1, 8); + storage[25] = SIMD.Int8x16.extractLane(t1, 9); + storage[26] = SIMD.Int8x16.extractLane(t1, 10); + storage[27] = SIMD.Int8x16.extractLane(t1, 11); + storage[28] = SIMD.Int8x16.extractLane(t1, 12); + storage[29] = SIMD.Int8x16.extractLane(t1, 13); + storage[30] = SIMD.Int8x16.extractLane(t1, 14); + storage[31] = SIMD.Int8x16.extractLane(t1, 15); + return SIMD.Int8x16(storage[s0], storage[s1], storage[s2], storage[s3], storage[s4], storage[s5], storage[s6], storage[s7], storage[s8], storage[s9], storage[s10], storage[s11], storage[s12], storage[s13], storage[s14], storage[s15]); } } -if (typeof SIMD.int8x16.select === "undefined") { - /** - * @param {int8x16} t Selector mask. An instance of int8x16 - * @param {int8x16} trueValue Pick lane from here if corresponding +if (typeof SIMD.Int8x16.addSaturate === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a + b with + * signed saturating behavior on overflow. + */ + SIMD.Int8x16.addSaturate = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + var c = SIMD.Int8x16.add(a, b); + var max = SIMD.Int8x16.splat(0x7f); + var min = SIMD.Int8x16.splat(0x80); + var mask = SIMD.Int8x16.lessThan(c, a); + var bneg = SIMD.Int8x16.lessThan(b, SIMD.Int8x16.splat(0)); + return SIMD.Int8x16.select(SIMD.Bool8x16.and(mask, SIMD.Bool8x16.not(bneg)), max, + SIMD.Int8x16.select(SIMD.Bool8x16.and(SIMD.Bool8x16.not(mask), bneg), min, + c)); + } +} + +if (typeof SIMD.Int8x16.unsignedAddSaturate === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a + b with + * unsigned saturating behavior on overflow. + */ + SIMD.Int8x16.unsignedAddSaturate = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + var c = SIMD.Int8x16.add(a, b); + var max = SIMD.Int8x16.splat(0xff); + var min = SIMD.Int8x16.splat(0x00); + var mask = SIMD.Int8x16.unsignedLessThan(c, a); + var bneg = SIMD.Int8x16.unsignedLessThan(b, SIMD.Int8x16.splat(0)); + return SIMD.Int8x16.select(SIMD.Bool8x16.and(mask, SIMD.Bool8x16.not(bneg)), max, + SIMD.Int8x16.select(SIMD.Bool8x16.and(SIMD.Bool8x16.not(mask), bneg), min, + c)); + } +} + +if (typeof SIMD.Int8x16.subSaturate === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a - b with + * signed saturating behavior on overflow. + */ + SIMD.Int8x16.subSaturate = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + var c = SIMD.Int8x16.sub(a, b); + var max = SIMD.Int8x16.splat(0x7f); + var min = SIMD.Int8x16.splat(0x80); + var mask = SIMD.Int8x16.greaterThan(c, a); + var bneg = SIMD.Int8x16.lessThan(b, SIMD.Int8x16.splat(0)); + return SIMD.Int8x16.select(SIMD.Bool8x16.and(mask, SIMD.Bool8x16.not(bneg)), min, + SIMD.Int8x16.select(SIMD.Bool8x16.and(SIMD.Bool8x16.not(mask), bneg), max, + c)); + } +} + +if (typeof SIMD.Int8x16.unsignedSubSaturate === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} New instance of Int8x16 with values of a - b with + * unsigned saturating behavior on overflow. + */ + SIMD.Int8x16.unsignedSubSaturate = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + var c = SIMD.Int8x16.sub(a, b); + var max = SIMD.Int8x16.splat(0xff); + var min = SIMD.Int8x16.splat(0x00); + var mask = SIMD.Int8x16.unsignedGreaterThan(c, a); + var bneg = SIMD.Int8x16.unsignedLessThan(b, SIMD.Int8x16.splat(0)); + return SIMD.Int8x16.select(SIMD.Bool8x16.and(mask, SIMD.Bool8x16.not(bneg)), min, + SIMD.Int8x16.select(SIMD.Bool8x16.and(SIMD.Bool8x16.not(mask), bneg), max, + c)); + } +} + +if (typeof SIMD.Int8x16.unsignedAbsoluteDifference === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int8x16} The absolute differences (abs(x - y)) of the + * corresponding elements of a and b. x and y are interpreted as unsigned + * integers. + */ + SIMD.Int8x16.unsignedAbsoluteDifference = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + var x = SIMD.Int8x16( + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 0) - SIMD.Int8x16.unsignedExtractLane(b, 0)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 1) - SIMD.Int8x16.unsignedExtractLane(b, 1)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 2) - SIMD.Int8x16.unsignedExtractLane(b, 2)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 3) - SIMD.Int8x16.unsignedExtractLane(b, 3)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 4) - SIMD.Int8x16.unsignedExtractLane(b, 4)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 5) - SIMD.Int8x16.unsignedExtractLane(b, 5)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 6) - SIMD.Int8x16.unsignedExtractLane(b, 6)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 7) - SIMD.Int8x16.unsignedExtractLane(b, 7)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 8) - SIMD.Int8x16.unsignedExtractLane(b, 8)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 9) - SIMD.Int8x16.unsignedExtractLane(b, 9)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 10) - SIMD.Int8x16.unsignedExtractLane(b, 10)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 11) - SIMD.Int8x16.unsignedExtractLane(b, 11)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 12) - SIMD.Int8x16.unsignedExtractLane(b, 12)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 13) - SIMD.Int8x16.unsignedExtractLane(b, 13)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 14) - SIMD.Int8x16.unsignedExtractLane(b, 14)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 15) - SIMD.Int8x16.unsignedExtractLane(b, 15))); + return x; + } +} + +if (typeof SIMD.Int8x16.widenedUnsignedAbsoluteDifference === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @param {Int8x16} b An instance of Int8x16. + * @return {Int16x8} The absolute differences (abs(x - y)) of the + * first 8 corresponding elements of a and b, returning 16-bit results. + * x and y are interpreted as unsigned integers. + */ + SIMD.Int8x16.widenedUnsignedAbsoluteDifference = function(a, b) { + a = SIMD.Int8x16.check(a); + b = SIMD.Int8x16.check(b); + return SIMD.Int16x8( + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 0) - SIMD.Int8x16.unsignedExtractLane(b, 0)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 1) - SIMD.Int8x16.unsignedExtractLane(b, 1)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 2) - SIMD.Int8x16.unsignedExtractLane(b, 2)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 3) - SIMD.Int8x16.unsignedExtractLane(b, 3)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 4) - SIMD.Int8x16.unsignedExtractLane(b, 4)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 5) - SIMD.Int8x16.unsignedExtractLane(b, 5)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 6) - SIMD.Int8x16.unsignedExtractLane(b, 6)), + Math.abs( + SIMD.Int8x16.unsignedExtractLane(a, 7) - SIMD.Int8x16.unsignedExtractLane(b, 7))); + } +} + +if (typeof SIMD.Int8x16.unsignedHorizontalSum === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. + * @return {Number} The sum of all the lanes in a, extracted as unsigned values. + */ + SIMD.Int8x16.unsignedHorizontalSum = function(a) { + a = SIMD.Int8x16.check(a); + return SIMD.Int8x16.unsignedExtractLane(a, 0) + + SIMD.Int8x16.unsignedExtractLane(a, 1) + + SIMD.Int8x16.unsignedExtractLane(a, 2) + + SIMD.Int8x16.unsignedExtractLane(a, 3) + + SIMD.Int8x16.unsignedExtractLane(a, 4) + + SIMD.Int8x16.unsignedExtractLane(a, 5) + + SIMD.Int8x16.unsignedExtractLane(a, 6) + + SIMD.Int8x16.unsignedExtractLane(a, 7) + + SIMD.Int8x16.unsignedExtractLane(a, 8) + + SIMD.Int8x16.unsignedExtractLane(a, 9) + + SIMD.Int8x16.unsignedExtractLane(a, 10) + + SIMD.Int8x16.unsignedExtractLane(a, 11) + + SIMD.Int8x16.unsignedExtractLane(a, 12) + + SIMD.Int8x16.unsignedExtractLane(a, 13) + + SIMD.Int8x16.unsignedExtractLane(a, 14) + + SIMD.Int8x16.unsignedExtractLane(a, 15); + } +} + +if (typeof SIMD.Int8x16.select === "undefined") { + /** + * @param {Bool8x16} t Selector mask. An instance of Bool8x16 + * @param {Int8x16} trueValue Pick lane from here if corresponding * selector lane is true - * @param {int8x16} falseValue Pick lane from here if corresponding + * @param {Int8x16} falseValue Pick lane from here if corresponding * selector lane is false - * @return {int8x16} Mix of lanes from trueValue or falseValue as + * @return {Int8x16} Mix of lanes from trueValue or falseValue as * indicated */ - SIMD.int8x16.select = function(t, trueValue, falseValue) { - t = SIMD.int8x16.check(t); - trueValue = SIMD.int8x16.check(trueValue); - falseValue = SIMD.int8x16.check(falseValue); - return SIMD.int8x16(_SIMD_PRIVATE.tobool(t.s0) ? trueValue.s0 : falseValue.s0, - _SIMD_PRIVATE.tobool(t.s1) ? trueValue.s1 : falseValue.s1, - _SIMD_PRIVATE.tobool(t.s2) ? trueValue.s2 : falseValue.s2, - _SIMD_PRIVATE.tobool(t.s3) ? trueValue.s3 : falseValue.s3, - _SIMD_PRIVATE.tobool(t.s4) ? trueValue.s4 : falseValue.s4, - _SIMD_PRIVATE.tobool(t.s5) ? trueValue.s5 : falseValue.s5, - _SIMD_PRIVATE.tobool(t.s6) ? trueValue.s6 : falseValue.s6, - _SIMD_PRIVATE.tobool(t.s7) ? trueValue.s7 : falseValue.s7, - _SIMD_PRIVATE.tobool(t.s8) ? trueValue.s8 : falseValue.s8, - _SIMD_PRIVATE.tobool(t.s9) ? trueValue.s9 : falseValue.s9, - _SIMD_PRIVATE.tobool(t.s10) ? trueValue.s10 : falseValue.s10, - _SIMD_PRIVATE.tobool(t.s11) ? trueValue.s11 : falseValue.s11, - _SIMD_PRIVATE.tobool(t.s12) ? trueValue.s12 : falseValue.s12, - _SIMD_PRIVATE.tobool(t.s13) ? trueValue.s13 : falseValue.s13, - _SIMD_PRIVATE.tobool(t.s14) ? trueValue.s14 : falseValue.s14, - _SIMD_PRIVATE.tobool(t.s15) ? trueValue.s15 : falseValue.s15); - } -} - -if (typeof SIMD.int8x16.bitselect === "undefined") { - /** - * @param {int8x16} t Selector mask. An instance of int8x16 - * @param {int8x16} trueValue Pick lane from here if corresponding + SIMD.Int8x16.select = function(t, trueValue, falseValue) { + t = SIMD.Bool8x16.check(t); + trueValue = SIMD.Int8x16.check(trueValue); + falseValue = SIMD.Int8x16.check(falseValue); + return SIMD.Int8x16( + SIMD.Bool8x16.extractLane(t, 0) ? + SIMD.Int8x16.extractLane(trueValue, 0) : + SIMD.Int8x16.extractLane(falseValue, 0), + SIMD.Bool8x16.extractLane(t, 1) ? + SIMD.Int8x16.extractLane(trueValue, 1) : + SIMD.Int8x16.extractLane(falseValue, 1), + SIMD.Bool8x16.extractLane(t, 2) ? + SIMD.Int8x16.extractLane(trueValue, 2) : + SIMD.Int8x16.extractLane(falseValue, 2), + SIMD.Bool8x16.extractLane(t, 3) ? + SIMD.Int8x16.extractLane(trueValue, 3) : + SIMD.Int8x16.extractLane(falseValue, 3), + SIMD.Bool8x16.extractLane(t, 4) ? + SIMD.Int8x16.extractLane(trueValue, 4) : + SIMD.Int8x16.extractLane(falseValue, 4), + SIMD.Bool8x16.extractLane(t, 5) ? + SIMD.Int8x16.extractLane(trueValue, 5) : + SIMD.Int8x16.extractLane(falseValue, 5), + SIMD.Bool8x16.extractLane(t, 6) ? + SIMD.Int8x16.extractLane(trueValue, 6) : + SIMD.Int8x16.extractLane(falseValue, 6), + SIMD.Bool8x16.extractLane(t, 7) ? + SIMD.Int8x16.extractLane(trueValue, 7) : + SIMD.Int8x16.extractLane(falseValue, 7), + SIMD.Bool8x16.extractLane(t, 8) ? + SIMD.Int8x16.extractLane(trueValue, 8) : + SIMD.Int8x16.extractLane(falseValue, 8), + SIMD.Bool8x16.extractLane(t, 9) ? + SIMD.Int8x16.extractLane(trueValue, 9) : + SIMD.Int8x16.extractLane(falseValue, 9), + SIMD.Bool8x16.extractLane(t, 10) ? + SIMD.Int8x16.extractLane(trueValue, 10) : + SIMD.Int8x16.extractLane(falseValue, 10), + SIMD.Bool8x16.extractLane(t, 11) ? + SIMD.Int8x16.extractLane(trueValue, 11) : + SIMD.Int8x16.extractLane(falseValue, 11), + SIMD.Bool8x16.extractLane(t, 12) ? + SIMD.Int8x16.extractLane(trueValue, 12) : + SIMD.Int8x16.extractLane(falseValue, 12), + SIMD.Bool8x16.extractLane(t, 13) ? + SIMD.Int8x16.extractLane(trueValue, 13) : + SIMD.Int8x16.extractLane(falseValue, 13), + SIMD.Bool8x16.extractLane(t, 14) ? + SIMD.Int8x16.extractLane(trueValue, 14) : + SIMD.Int8x16.extractLane(falseValue, 14), + SIMD.Bool8x16.extractLane(t, 15) ? + SIMD.Int8x16.extractLane(trueValue, 15) : + SIMD.Int8x16.extractLane(falseValue, 15)); + } +} + +if (typeof SIMD.Int8x16.selectBits === "undefined") { + /** + * @param {Int8x16} t Selector mask. An instance of Int8x16 + * @param {Int8x16} trueValue Pick bit from here if corresponding * selector bit is 1 - * @param {int8x16} falseValue Pick lane from here if corresponding + * @param {Int8x16} falseValue Pick bit from here if corresponding * selector bit is 0 - * @return {int8x16} Mix of lanes from trueValue or falseValue as + * @return {Int8x16} Mix of bits from trueValue or falseValue as * indicated */ - SIMD.int8x16.bitselect = function(t, trueValue, falseValue) { - t = SIMD.int8x16.check(t); - trueValue = SIMD.int8x16.check(trueValue); - falseValue = SIMD.int8x16.check(falseValue); - var tr = SIMD.int8x16.and(t, trueValue); - var fr = SIMD.int8x16.and(SIMD.int8x16.not(t), falseValue); - return SIMD.int8x16.or(tr, fr); + SIMD.Int8x16.selectBits = function(t, trueValue, falseValue) { + t = SIMD.Int8x16.check(t); + trueValue = SIMD.Int8x16.check(trueValue); + falseValue = SIMD.Int8x16.check(falseValue); + var tr = SIMD.Int8x16.and(t, trueValue); + var fr = SIMD.Int8x16.and(SIMD.Int8x16.not(t), falseValue); + return SIMD.Int8x16.or(tr, fr); } } -if (typeof SIMD.int8x16.equal === "undefined") { +if (typeof SIMD.Int8x16.equal === "undefined") { /** - * @param {int8x16} t An instance of int8x16. - * @param {int8x16} other An instance of int8x16. - * @return {int8x16} true or false in each lane depending on + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on * the result of t == other. */ - SIMD.int8x16.equal = function(t, other) { - t = SIMD.int8x16.check(t); - other = SIMD.int8x16.check(other); - var cs0 = t.s0 == other.s0; - var cs1 = t.s1 == other.s1; - var cs2 = t.s2 == other.s2; - var cs3 = t.s3 == other.s3; - var cs4 = t.s4 == other.s4; - var cs5 = t.s5 == other.s5; - var cs6 = t.s6 == other.s6; - var cs7 = t.s7 == other.s7; - var cs8 = t.s8 == other.s8; - var cs9 = t.s9 == other.s9; - var cs10 = t.s10 == other.s10; - var cs11 = t.s11 == other.s11; - var cs12 = t.s12 == other.s12; - var cs13 = t.s13 == other.s13; - var cs14 = t.s14 == other.s14; - var cs15 = t.s15 == other.s15; - return SIMD.int8x16.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, - cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); - } -} - -if (typeof SIMD.int8x16.notEqual === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @param {int8x16} other An instance of int8x16. - * @return {int8x16} true or false in each lane depending on + SIMD.Int8x16.equal = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.extractLane(t, 0) == SIMD.Int8x16.extractLane(other, 0); + var cs1 = + SIMD.Int8x16.extractLane(t, 1) == SIMD.Int8x16.extractLane(other, 1); + var cs2 = + SIMD.Int8x16.extractLane(t, 2) == SIMD.Int8x16.extractLane(other, 2); + var cs3 = + SIMD.Int8x16.extractLane(t, 3) == SIMD.Int8x16.extractLane(other, 3); + var cs4 = + SIMD.Int8x16.extractLane(t, 4) == SIMD.Int8x16.extractLane(other, 4); + var cs5 = + SIMD.Int8x16.extractLane(t, 5) == SIMD.Int8x16.extractLane(other, 5); + var cs6 = + SIMD.Int8x16.extractLane(t, 6) == SIMD.Int8x16.extractLane(other, 6); + var cs7 = + SIMD.Int8x16.extractLane(t, 7) == SIMD.Int8x16.extractLane(other, 7); + var cs8 = + SIMD.Int8x16.extractLane(t, 8) == SIMD.Int8x16.extractLane(other, 8); + var cs9 = + SIMD.Int8x16.extractLane(t, 9) == SIMD.Int8x16.extractLane(other, 9); + var cs10 = + SIMD.Int8x16.extractLane(t, 10) == SIMD.Int8x16.extractLane(other, 10); + var cs11 = + SIMD.Int8x16.extractLane(t, 11) == SIMD.Int8x16.extractLane(other, 11); + var cs12 = + SIMD.Int8x16.extractLane(t, 12) == SIMD.Int8x16.extractLane(other, 12); + var cs13 = + SIMD.Int8x16.extractLane(t, 13) == SIMD.Int8x16.extractLane(other, 13); + var cs14 = + SIMD.Int8x16.extractLane(t, 14) == SIMD.Int8x16.extractLane(other, 14); + var cs15 = + SIMD.Int8x16.extractLane(t, 15) == SIMD.Int8x16.extractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.notEqual === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on * the result of t != other. */ - SIMD.int8x16.notEqual = function(t, other) { - t = SIMD.int8x16.check(t); - other = SIMD.int8x16.check(other); - var cs0 = t.s0 != other.s0; - var cs1 = t.s1 != other.s1; - var cs2 = t.s2 != other.s2; - var cs3 = t.s3 != other.s3; - var cs4 = t.s4 != other.s4; - var cs5 = t.s5 != other.s5; - var cs6 = t.s6 != other.s6; - var cs7 = t.s7 != other.s7; - var cs8 = t.s8 != other.s8; - var cs9 = t.s9 != other.s9; - var cs10 = t.s10 != other.s10; - var cs11 = t.s11 != other.s11; - var cs12 = t.s12 != other.s12; - var cs13 = t.s13 != other.s13; - var cs14 = t.s14 != other.s14; - var cs15 = t.s15 != other.s15; - return SIMD.int8x16.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, - cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); - } -} - -if (typeof SIMD.int8x16.greaterThan === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @param {int8x16} other An instance of int8x16. - * @return {int8x16} true or false in each lane depending on + SIMD.Int8x16.notEqual = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.extractLane(t, 0) != SIMD.Int8x16.extractLane(other, 0); + var cs1 = + SIMD.Int8x16.extractLane(t, 1) != SIMD.Int8x16.extractLane(other, 1); + var cs2 = + SIMD.Int8x16.extractLane(t, 2) != SIMD.Int8x16.extractLane(other, 2); + var cs3 = + SIMD.Int8x16.extractLane(t, 3) != SIMD.Int8x16.extractLane(other, 3); + var cs4 = + SIMD.Int8x16.extractLane(t, 4) != SIMD.Int8x16.extractLane(other, 4); + var cs5 = + SIMD.Int8x16.extractLane(t, 5) != SIMD.Int8x16.extractLane(other, 5); + var cs6 = + SIMD.Int8x16.extractLane(t, 6) != SIMD.Int8x16.extractLane(other, 6); + var cs7 = + SIMD.Int8x16.extractLane(t, 7) != SIMD.Int8x16.extractLane(other, 7); + var cs8 = + SIMD.Int8x16.extractLane(t, 8) != SIMD.Int8x16.extractLane(other, 8); + var cs9 = + SIMD.Int8x16.extractLane(t, 9) != SIMD.Int8x16.extractLane(other, 9); + var cs10 = + SIMD.Int8x16.extractLane(t, 10) != SIMD.Int8x16.extractLane(other, 10); + var cs11 = + SIMD.Int8x16.extractLane(t, 11) != SIMD.Int8x16.extractLane(other, 11); + var cs12 = + SIMD.Int8x16.extractLane(t, 12) != SIMD.Int8x16.extractLane(other, 12); + var cs13 = + SIMD.Int8x16.extractLane(t, 13) != SIMD.Int8x16.extractLane(other, 13); + var cs14 = + SIMD.Int8x16.extractLane(t, 14) != SIMD.Int8x16.extractLane(other, 14); + var cs15 = + SIMD.Int8x16.extractLane(t, 15) != SIMD.Int8x16.extractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.greaterThan === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on * the result of t > other. */ - SIMD.int8x16.greaterThan = function(t, other) { - t = SIMD.int8x16.check(t); - other = SIMD.int8x16.check(other); - var cs0 = t.s0 > other.s0; - var cs1 = t.s1 > other.s1; - var cs2 = t.s2 > other.s2; - var cs3 = t.s3 > other.s3; - var cs4 = t.s4 > other.s4; - var cs5 = t.s5 > other.s5; - var cs6 = t.s6 > other.s6; - var cs7 = t.s7 > other.s7; - var cs8 = t.s8 > other.s8; - var cs9 = t.s9 > other.s9; - var cs10 = t.s10 > other.s10; - var cs11 = t.s11 > other.s11; - var cs12 = t.s12 > other.s12; - var cs13 = t.s13 > other.s13; - var cs14 = t.s14 > other.s14; - var cs15 = t.s15 > other.s15; - return SIMD.int8x16.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, - cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); - } -} - -if (typeof SIMD.int8x16.greaterThanOrEqual === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @param {int8x16} other An instance of int8x16. - * @return {int8x16} true or false in each lane depending on + SIMD.Int8x16.greaterThan = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.extractLane(t, 0) > SIMD.Int8x16.extractLane(other, 0); + var cs1 = + SIMD.Int8x16.extractLane(t, 1) > SIMD.Int8x16.extractLane(other, 1); + var cs2 = + SIMD.Int8x16.extractLane(t, 2) > SIMD.Int8x16.extractLane(other, 2); + var cs3 = + SIMD.Int8x16.extractLane(t, 3) > SIMD.Int8x16.extractLane(other, 3); + var cs4 = + SIMD.Int8x16.extractLane(t, 4) > SIMD.Int8x16.extractLane(other, 4); + var cs5 = + SIMD.Int8x16.extractLane(t, 5) > SIMD.Int8x16.extractLane(other, 5); + var cs6 = + SIMD.Int8x16.extractLane(t, 6) > SIMD.Int8x16.extractLane(other, 6); + var cs7 = + SIMD.Int8x16.extractLane(t, 7) > SIMD.Int8x16.extractLane(other, 7); + var cs8 = + SIMD.Int8x16.extractLane(t, 8) > SIMD.Int8x16.extractLane(other, 8); + var cs9 = + SIMD.Int8x16.extractLane(t, 9) > SIMD.Int8x16.extractLane(other, 9); + var cs10 = + SIMD.Int8x16.extractLane(t, 10) > SIMD.Int8x16.extractLane(other, 10); + var cs11 = + SIMD.Int8x16.extractLane(t, 11) > SIMD.Int8x16.extractLane(other, 11); + var cs12 = + SIMD.Int8x16.extractLane(t, 12) > SIMD.Int8x16.extractLane(other, 12); + var cs13 = + SIMD.Int8x16.extractLane(t, 13) > SIMD.Int8x16.extractLane(other, 13); + var cs14 = + SIMD.Int8x16.extractLane(t, 14) > SIMD.Int8x16.extractLane(other, 14); + var cs15 = + SIMD.Int8x16.extractLane(t, 15) > SIMD.Int8x16.extractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.unsignedGreaterThan === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on + * the result of t > other as unsigned values. + */ + SIMD.Int8x16.unsignedGreaterThan = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.unsignedExtractLane(t, 0) > SIMD.Int8x16.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int8x16.unsignedExtractLane(t, 1) > SIMD.Int8x16.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int8x16.unsignedExtractLane(t, 2) > SIMD.Int8x16.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int8x16.unsignedExtractLane(t, 3) > SIMD.Int8x16.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int8x16.unsignedExtractLane(t, 4) > SIMD.Int8x16.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int8x16.unsignedExtractLane(t, 5) > SIMD.Int8x16.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int8x16.unsignedExtractLane(t, 6) > SIMD.Int8x16.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int8x16.unsignedExtractLane(t, 7) > SIMD.Int8x16.unsignedExtractLane(other, 7); + var cs8 = + SIMD.Int8x16.unsignedExtractLane(t, 8) > SIMD.Int8x16.unsignedExtractLane(other, 8); + var cs9 = + SIMD.Int8x16.unsignedExtractLane(t, 9) > SIMD.Int8x16.unsignedExtractLane(other, 9); + var cs10 = + SIMD.Int8x16.unsignedExtractLane(t, 10) > SIMD.Int8x16.unsignedExtractLane(other, 10); + var cs11 = + SIMD.Int8x16.unsignedExtractLane(t, 11) > SIMD.Int8x16.unsignedExtractLane(other, 11); + var cs12 = + SIMD.Int8x16.unsignedExtractLane(t, 12) > SIMD.Int8x16.unsignedExtractLane(other, 12); + var cs13 = + SIMD.Int8x16.unsignedExtractLane(t, 13) > SIMD.Int8x16.unsignedExtractLane(other, 13); + var cs14 = + SIMD.Int8x16.unsignedExtractLane(t, 14) > SIMD.Int8x16.unsignedExtractLane(other, 14); + var cs15 = + SIMD.Int8x16.unsignedExtractLane(t, 15) > SIMD.Int8x16.unsignedExtractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.greaterThanOrEqual === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on * the result of t >= other. */ - SIMD.int8x16.greaterThanOrEqual = function(t, other) { - t = SIMD.int8x16.check(t); - other = SIMD.int8x16.check(other); - var cs0 = t.s0 >= other.s0; - var cs1 = t.s1 >= other.s1; - var cs2 = t.s2 >= other.s2; - var cs3 = t.s3 >= other.s3; - var cs4 = t.s4 >= other.s4; - var cs5 = t.s5 >= other.s5; - var cs6 = t.s6 >= other.s6; - var cs7 = t.s7 >= other.s7; - var cs8 = t.s8 >= other.s8; - var cs9 = t.s9 >= other.s9; - var cs10 = t.s10 >= other.s10; - var cs11 = t.s11 >= other.s11; - var cs12 = t.s12 >= other.s12; - var cs13 = t.s13 >= other.s13; - var cs14 = t.s14 >= other.s14; - var cs15 = t.s15 >= other.s15; - return SIMD.int8x16.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, - cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); - } -} - -if (typeof SIMD.int8x16.lessThan === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @param {int8x16} other An instance of int8x16. - * @return {int8x16} true or false in each lane depending on + SIMD.Int8x16.greaterThanOrEqual = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.extractLane(t, 0) >= SIMD.Int8x16.extractLane(other, 0); + var cs1 = + SIMD.Int8x16.extractLane(t, 1) >= SIMD.Int8x16.extractLane(other, 1); + var cs2 = + SIMD.Int8x16.extractLane(t, 2) >= SIMD.Int8x16.extractLane(other, 2); + var cs3 = + SIMD.Int8x16.extractLane(t, 3) >= SIMD.Int8x16.extractLane(other, 3); + var cs4 = + SIMD.Int8x16.extractLane(t, 4) >= SIMD.Int8x16.extractLane(other, 4); + var cs5 = + SIMD.Int8x16.extractLane(t, 5) >= SIMD.Int8x16.extractLane(other, 5); + var cs6 = + SIMD.Int8x16.extractLane(t, 6) >= SIMD.Int8x16.extractLane(other, 6); + var cs7 = + SIMD.Int8x16.extractLane(t, 7) >= SIMD.Int8x16.extractLane(other, 7); + var cs8 = + SIMD.Int8x16.extractLane(t, 8) >= SIMD.Int8x16.extractLane(other, 8); + var cs9 = + SIMD.Int8x16.extractLane(t, 9) >= SIMD.Int8x16.extractLane(other, 9); + var cs10 = + SIMD.Int8x16.extractLane(t, 10) >= SIMD.Int8x16.extractLane(other, 10); + var cs11 = + SIMD.Int8x16.extractLane(t, 11) >= SIMD.Int8x16.extractLane(other, 11); + var cs12 = + SIMD.Int8x16.extractLane(t, 12) >= SIMD.Int8x16.extractLane(other, 12); + var cs13 = + SIMD.Int8x16.extractLane(t, 13) >= SIMD.Int8x16.extractLane(other, 13); + var cs14 = + SIMD.Int8x16.extractLane(t, 14) >= SIMD.Int8x16.extractLane(other, 14); + var cs15 = + SIMD.Int8x16.extractLane(t, 15) >= SIMD.Int8x16.extractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.unsignedGreaterThanOrEqual === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on + * the result of t >= other as unsigned values. + */ + SIMD.Int8x16.unsignedGreaterThanOrEqual = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.unsignedExtractLane(t, 0) >= SIMD.Int8x16.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int8x16.unsignedExtractLane(t, 1) >= SIMD.Int8x16.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int8x16.unsignedExtractLane(t, 2) >= SIMD.Int8x16.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int8x16.unsignedExtractLane(t, 3) >= SIMD.Int8x16.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int8x16.unsignedExtractLane(t, 4) >= SIMD.Int8x16.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int8x16.unsignedExtractLane(t, 5) >= SIMD.Int8x16.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int8x16.unsignedExtractLane(t, 6) >= SIMD.Int8x16.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int8x16.unsignedExtractLane(t, 7) >= SIMD.Int8x16.unsignedExtractLane(other, 7); + var cs8 = + SIMD.Int8x16.unsignedExtractLane(t, 8) >= SIMD.Int8x16.unsignedExtractLane(other, 8); + var cs9 = + SIMD.Int8x16.unsignedExtractLane(t, 9) >= SIMD.Int8x16.unsignedExtractLane(other, 9); + var cs10 = + SIMD.Int8x16.unsignedExtractLane(t, 10) >= SIMD.Int8x16.unsignedExtractLane(other, 10); + var cs11 = + SIMD.Int8x16.unsignedExtractLane(t, 11) >= SIMD.Int8x16.unsignedExtractLane(other, 11); + var cs12 = + SIMD.Int8x16.unsignedExtractLane(t, 12) >= SIMD.Int8x16.unsignedExtractLane(other, 12); + var cs13 = + SIMD.Int8x16.unsignedExtractLane(t, 13) >= SIMD.Int8x16.unsignedExtractLane(other, 13); + var cs14 = + SIMD.Int8x16.unsignedExtractLane(t, 14) >= SIMD.Int8x16.unsignedExtractLane(other, 14); + var cs15 = + SIMD.Int8x16.unsignedExtractLane(t, 15) >= SIMD.Int8x16.unsignedExtractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.lessThan === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on * the result of t < other. */ - SIMD.int8x16.lessThan = function(t, other) { - t = SIMD.int8x16.check(t); - other = SIMD.int8x16.check(other); - var cs0 = t.s0 < other.s0; - var cs1 = t.s1 < other.s1; - var cs2 = t.s2 < other.s2; - var cs3 = t.s3 < other.s3; - var cs4 = t.s4 < other.s4; - var cs5 = t.s5 < other.s5; - var cs6 = t.s6 < other.s6; - var cs7 = t.s7 < other.s7; - var cs8 = t.s8 < other.s8; - var cs9 = t.s9 < other.s9; - var cs10 = t.s10 < other.s10; - var cs11 = t.s11 < other.s11; - var cs12 = t.s12 < other.s12; - var cs13 = t.s13 < other.s13; - var cs14 = t.s14 < other.s14; - var cs15 = t.s15 < other.s15; - return SIMD.int8x16.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, - cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); - } -} - -if (typeof SIMD.int8x16.lessThanOrEqual === "undefined") { - /** - * @param {int8x16} t An instance of int8x16. - * @param {int8x16} other An instance of int8x16. - * @return {int8x16} true or false in each lane depending on + SIMD.Int8x16.lessThan = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.extractLane(t, 0) < SIMD.Int8x16.extractLane(other, 0); + var cs1 = + SIMD.Int8x16.extractLane(t, 1) < SIMD.Int8x16.extractLane(other, 1); + var cs2 = + SIMD.Int8x16.extractLane(t, 2) < SIMD.Int8x16.extractLane(other, 2); + var cs3 = + SIMD.Int8x16.extractLane(t, 3) < SIMD.Int8x16.extractLane(other, 3); + var cs4 = + SIMD.Int8x16.extractLane(t, 4) < SIMD.Int8x16.extractLane(other, 4); + var cs5 = + SIMD.Int8x16.extractLane(t, 5) < SIMD.Int8x16.extractLane(other, 5); + var cs6 = + SIMD.Int8x16.extractLane(t, 6) < SIMD.Int8x16.extractLane(other, 6); + var cs7 = + SIMD.Int8x16.extractLane(t, 7) < SIMD.Int8x16.extractLane(other, 7); + var cs8 = + SIMD.Int8x16.extractLane(t, 8) < SIMD.Int8x16.extractLane(other, 8); + var cs9 = + SIMD.Int8x16.extractLane(t, 9) < SIMD.Int8x16.extractLane(other, 9); + var cs10 = + SIMD.Int8x16.extractLane(t, 10) < SIMD.Int8x16.extractLane(other, 10); + var cs11 = + SIMD.Int8x16.extractLane(t, 11) < SIMD.Int8x16.extractLane(other, 11); + var cs12 = + SIMD.Int8x16.extractLane(t, 12) < SIMD.Int8x16.extractLane(other, 12); + var cs13 = + SIMD.Int8x16.extractLane(t, 13) < SIMD.Int8x16.extractLane(other, 13); + var cs14 = + SIMD.Int8x16.extractLane(t, 14) < SIMD.Int8x16.extractLane(other, 14); + var cs15 = + SIMD.Int8x16.extractLane(t, 15) < SIMD.Int8x16.extractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.unsignedLessThan === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on + * the result of t < other as unsigned values. + */ + SIMD.Int8x16.unsignedLessThan = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.unsignedExtractLane(t, 0) < SIMD.Int8x16.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int8x16.unsignedExtractLane(t, 1) < SIMD.Int8x16.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int8x16.unsignedExtractLane(t, 2) < SIMD.Int8x16.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int8x16.unsignedExtractLane(t, 3) < SIMD.Int8x16.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int8x16.unsignedExtractLane(t, 4) < SIMD.Int8x16.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int8x16.unsignedExtractLane(t, 5) < SIMD.Int8x16.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int8x16.unsignedExtractLane(t, 6) < SIMD.Int8x16.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int8x16.unsignedExtractLane(t, 7) < SIMD.Int8x16.unsignedExtractLane(other, 7); + var cs8 = + SIMD.Int8x16.unsignedExtractLane(t, 8) < SIMD.Int8x16.unsignedExtractLane(other, 8); + var cs9 = + SIMD.Int8x16.unsignedExtractLane(t, 9) < SIMD.Int8x16.unsignedExtractLane(other, 9); + var cs10 = + SIMD.Int8x16.unsignedExtractLane(t, 10) < SIMD.Int8x16.unsignedExtractLane(other, 10); + var cs11 = + SIMD.Int8x16.unsignedExtractLane(t, 11) < SIMD.Int8x16.unsignedExtractLane(other, 11); + var cs12 = + SIMD.Int8x16.unsignedExtractLane(t, 12) < SIMD.Int8x16.unsignedExtractLane(other, 12); + var cs13 = + SIMD.Int8x16.unsignedExtractLane(t, 13) < SIMD.Int8x16.unsignedExtractLane(other, 13); + var cs14 = + SIMD.Int8x16.unsignedExtractLane(t, 14) < SIMD.Int8x16.unsignedExtractLane(other, 14); + var cs15 = + SIMD.Int8x16.unsignedExtractLane(t, 15) < SIMD.Int8x16.unsignedExtractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.lessThanOrEqual === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on * the result of t <= other. */ - SIMD.int8x16.lessThanOrEqual = function(t, other) { - t = SIMD.int8x16.check(t); - other = SIMD.int8x16.check(other); - var cs0 = t.s0 <= other.s0; - var cs1 = t.s1 <= other.s1; - var cs2 = t.s2 <= other.s2; - var cs3 = t.s3 <= other.s3; - var cs4 = t.s4 <= other.s4; - var cs5 = t.s5 <= other.s5; - var cs6 = t.s6 <= other.s6; - var cs7 = t.s7 <= other.s7; - var cs8 = t.s8 <= other.s8; - var cs9 = t.s9 <= other.s9; - var cs10 = t.s10 <= other.s10; - var cs11 = t.s11 <= other.s11; - var cs12 = t.s12 <= other.s12; - var cs13 = t.s13 <= other.s13; - var cs14 = t.s14 <= other.s14; - var cs15 = t.s15 <= other.s15; - return SIMD.int8x16.bool(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, - cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); - } -} - -if (typeof SIMD.int8x16.shiftLeftByScalar === "undefined") { - /** - * @param {int8x16} a An instance of int8x16. + SIMD.Int8x16.lessThanOrEqual = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.extractLane(t, 0) <= SIMD.Int8x16.extractLane(other, 0); + var cs1 = + SIMD.Int8x16.extractLane(t, 1) <= SIMD.Int8x16.extractLane(other, 1); + var cs2 = + SIMD.Int8x16.extractLane(t, 2) <= SIMD.Int8x16.extractLane(other, 2); + var cs3 = + SIMD.Int8x16.extractLane(t, 3) <= SIMD.Int8x16.extractLane(other, 3); + var cs4 = + SIMD.Int8x16.extractLane(t, 4) <= SIMD.Int8x16.extractLane(other, 4); + var cs5 = + SIMD.Int8x16.extractLane(t, 5) <= SIMD.Int8x16.extractLane(other, 5); + var cs6 = + SIMD.Int8x16.extractLane(t, 6) <= SIMD.Int8x16.extractLane(other, 6); + var cs7 = + SIMD.Int8x16.extractLane(t, 7) <= SIMD.Int8x16.extractLane(other, 7); + var cs8 = + SIMD.Int8x16.extractLane(t, 8) <= SIMD.Int8x16.extractLane(other, 8); + var cs9 = + SIMD.Int8x16.extractLane(t, 9) <= SIMD.Int8x16.extractLane(other, 9); + var cs10 = + SIMD.Int8x16.extractLane(t, 10) <= SIMD.Int8x16.extractLane(other, 10); + var cs11 = + SIMD.Int8x16.extractLane(t, 11) <= SIMD.Int8x16.extractLane(other, 11); + var cs12 = + SIMD.Int8x16.extractLane(t, 12) <= SIMD.Int8x16.extractLane(other, 12); + var cs13 = + SIMD.Int8x16.extractLane(t, 13) <= SIMD.Int8x16.extractLane(other, 13); + var cs14 = + SIMD.Int8x16.extractLane(t, 14) <= SIMD.Int8x16.extractLane(other, 14); + var cs15 = + SIMD.Int8x16.extractLane(t, 15) <= SIMD.Int8x16.extractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.unsignedLessThanOrEqual === "undefined") { + /** + * @param {Int8x16} t An instance of Int8x16. + * @param {Int8x16} other An instance of Int8x16. + * @return {Bool8x16} true or false in each lane depending on + * the result of t <= other as unsigned values. + */ + SIMD.Int8x16.unsignedLessThanOrEqual = function(t, other) { + t = SIMD.Int8x16.check(t); + other = SIMD.Int8x16.check(other); + var cs0 = + SIMD.Int8x16.unsignedExtractLane(t, 0) <= SIMD.Int8x16.unsignedExtractLane(other, 0); + var cs1 = + SIMD.Int8x16.unsignedExtractLane(t, 1) <= SIMD.Int8x16.unsignedExtractLane(other, 1); + var cs2 = + SIMD.Int8x16.unsignedExtractLane(t, 2) <= SIMD.Int8x16.unsignedExtractLane(other, 2); + var cs3 = + SIMD.Int8x16.unsignedExtractLane(t, 3) <= SIMD.Int8x16.unsignedExtractLane(other, 3); + var cs4 = + SIMD.Int8x16.unsignedExtractLane(t, 4) <= SIMD.Int8x16.unsignedExtractLane(other, 4); + var cs5 = + SIMD.Int8x16.unsignedExtractLane(t, 5) <= SIMD.Int8x16.unsignedExtractLane(other, 5); + var cs6 = + SIMD.Int8x16.unsignedExtractLane(t, 6) <= SIMD.Int8x16.unsignedExtractLane(other, 6); + var cs7 = + SIMD.Int8x16.unsignedExtractLane(t, 7) <= SIMD.Int8x16.unsignedExtractLane(other, 7); + var cs8 = + SIMD.Int8x16.unsignedExtractLane(t, 8) <= SIMD.Int8x16.unsignedExtractLane(other, 8); + var cs9 = + SIMD.Int8x16.unsignedExtractLane(t, 9) <= SIMD.Int8x16.unsignedExtractLane(other, 9); + var cs10 = + SIMD.Int8x16.unsignedExtractLane(t, 10) <= SIMD.Int8x16.unsignedExtractLane(other, 10); + var cs11 = + SIMD.Int8x16.unsignedExtractLane(t, 11) <= SIMD.Int8x16.unsignedExtractLane(other, 11); + var cs12 = + SIMD.Int8x16.unsignedExtractLane(t, 12) <= SIMD.Int8x16.unsignedExtractLane(other, 12); + var cs13 = + SIMD.Int8x16.unsignedExtractLane(t, 13) <= SIMD.Int8x16.unsignedExtractLane(other, 13); + var cs14 = + SIMD.Int8x16.unsignedExtractLane(t, 14) <= SIMD.Int8x16.unsignedExtractLane(other, 14); + var cs15 = + SIMD.Int8x16.unsignedExtractLane(t, 15) <= SIMD.Int8x16.unsignedExtractLane(other, 15); + return SIMD.Bool8x16(cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, + cs8, cs9, cs10, cs11, cs12, cs13, cs14, cs15); + } +} + +if (typeof SIMD.Int8x16.shiftLeftByScalar === "undefined") { + /** + * @param {Int8x16} a An instance of Int8x16. * @param {integer} bits Bit count to shift by. - * @return {int8x16} lanes in a shifted by bits. + * @return {Int8x16} lanes in a shifted by bits. */ - SIMD.int8x16.shiftLeftByScalar = function(a, bits) { - a = SIMD.int8x16.check(a); + SIMD.Int8x16.shiftLeftByScalar = function(a, bits) { + a = SIMD.Int8x16.check(a); if (bits>>>0 > 8) bits = 8; - var s0 = a.s0 << bits; - var s1 = a.s1 << bits; - var s2 = a.s2 << bits; - var s3 = a.s3 << bits; - var s4 = a.s4 << bits; - var s5 = a.s5 << bits; - var s6 = a.s6 << bits; - var s7 = a.s7 << bits; - var s8 = a.s8 << bits; - var s9 = a.s9 << bits; - var s10 = a.s10 << bits; - var s11 = a.s11 << bits; - var s12 = a.s12 << bits; - var s13 = a.s13 << bits; - var s14 = a.s14 << bits; - var s15 = a.s15 << bits; - return SIMD.int8x16(s0, s1, s2, s3, s4, s5, s6, s7, + var s0 = SIMD.Int8x16.extractLane(a, 0) << bits; + var s1 = SIMD.Int8x16.extractLane(a, 1) << bits; + var s2 = SIMD.Int8x16.extractLane(a, 2) << bits; + var s3 = SIMD.Int8x16.extractLane(a, 3) << bits; + var s4 = SIMD.Int8x16.extractLane(a, 4) << bits; + var s5 = SIMD.Int8x16.extractLane(a, 5) << bits; + var s6 = SIMD.Int8x16.extractLane(a, 6) << bits; + var s7 = SIMD.Int8x16.extractLane(a, 7) << bits; + var s8 = SIMD.Int8x16.extractLane(a, 8) << bits; + var s9 = SIMD.Int8x16.extractLane(a, 9) << bits; + var s10 = SIMD.Int8x16.extractLane(a, 10) << bits; + var s11 = SIMD.Int8x16.extractLane(a, 11) << bits; + var s12 = SIMD.Int8x16.extractLane(a, 12) << bits; + var s13 = SIMD.Int8x16.extractLane(a, 13) << bits; + var s14 = SIMD.Int8x16.extractLane(a, 14) << bits; + var s15 = SIMD.Int8x16.extractLane(a, 15) << bits; + return SIMD.Int8x16(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15); } } -if (typeof SIMD.int8x16.shiftRightLogicalByScalar === "undefined") { +if (typeof SIMD.Int8x16.shiftRightLogicalByScalar === "undefined") { /** - * @param {int8x16} a An instance of int8x16. + * @param {Int8x16} a An instance of Int8x16. * @param {integer} bits Bit count to shift by. - * @return {int8x16} lanes in a shifted by bits. + * @return {Int8x16} lanes in a shifted by bits. */ - SIMD.int8x16.shiftRightLogicalByScalar = function(a, bits) { - a = SIMD.int8x16.check(a); + SIMD.Int8x16.shiftRightLogicalByScalar = function(a, bits) { + a = SIMD.Int8x16.check(a); if (bits>>>0 > 8) bits = 8; - var s0 = (a.s0 & 0xff) >>> bits; - var s1 = (a.s1 & 0xff) >>> bits; - var s2 = (a.s2 & 0xff) >>> bits; - var s3 = (a.s3 & 0xff) >>> bits; - var s4 = (a.s4 & 0xff) >>> bits; - var s5 = (a.s5 & 0xff) >>> bits; - var s6 = (a.s6 & 0xff) >>> bits; - var s7 = (a.s7 & 0xff) >>> bits; - var s8 = (a.s8 & 0xff) >>> bits; - var s9 = (a.s9 & 0xff) >>> bits; - var s10 = (a.s10 & 0xff) >>> bits; - var s11 = (a.s11 & 0xff) >>> bits; - var s12 = (a.s12 & 0xff) >>> bits; - var s13 = (a.s13 & 0xff) >>> bits; - var s14 = (a.s14 & 0xff) >>> bits; - var s15 = (a.s15 & 0xff) >>> bits; - return SIMD.int8x16(s0, s1, s2, s3, s4, s5, s6, s7, + var s0 = (SIMD.Int8x16.extractLane(a, 0) & 0xff) >>> bits; + var s1 = (SIMD.Int8x16.extractLane(a, 1) & 0xff) >>> bits; + var s2 = (SIMD.Int8x16.extractLane(a, 2) & 0xff) >>> bits; + var s3 = (SIMD.Int8x16.extractLane(a, 3) & 0xff) >>> bits; + var s4 = (SIMD.Int8x16.extractLane(a, 4) & 0xff) >>> bits; + var s5 = (SIMD.Int8x16.extractLane(a, 5) & 0xff) >>> bits; + var s6 = (SIMD.Int8x16.extractLane(a, 6) & 0xff) >>> bits; + var s7 = (SIMD.Int8x16.extractLane(a, 7) & 0xff) >>> bits; + var s8 = (SIMD.Int8x16.extractLane(a, 8) & 0xff) >>> bits; + var s9 = (SIMD.Int8x16.extractLane(a, 9) & 0xff) >>> bits; + var s10 = (SIMD.Int8x16.extractLane(a, 10) & 0xff) >>> bits; + var s11 = (SIMD.Int8x16.extractLane(a, 11) & 0xff) >>> bits; + var s12 = (SIMD.Int8x16.extractLane(a, 12) & 0xff) >>> bits; + var s13 = (SIMD.Int8x16.extractLane(a, 13) & 0xff) >>> bits; + var s14 = (SIMD.Int8x16.extractLane(a, 14) & 0xff) >>> bits; + var s15 = (SIMD.Int8x16.extractLane(a, 15) & 0xff) >>> bits; + return SIMD.Int8x16(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15); } } -if (typeof SIMD.int8x16.shiftRightArithmeticByScalar === "undefined") { +if (typeof SIMD.Int8x16.shiftRightArithmeticByScalar === "undefined") { /** - * @param {int8x16} a An instance of int8x16. + * @param {Int8x16} a An instance of Int8x16. * @param {integer} bits Bit count to shift by. - * @return {int8x16} lanes in a shifted by bits. + * @return {Int8x16} lanes in a shifted by bits. */ - SIMD.int8x16.shiftRightArithmeticByScalar = function(a, bits) { - a = SIMD.int8x16.check(a); + SIMD.Int8x16.shiftRightArithmeticByScalar = function(a, bits) { + a = SIMD.Int8x16.check(a); if (bits>>>0 > 8) bits = 8; - var s0 = a.s0 >> bits; - var s1 = a.s1 >> bits; - var s2 = a.s2 >> bits; - var s3 = a.s3 >> bits; - var s4 = a.s4 >> bits; - var s5 = a.s5 >> bits; - var s6 = a.s6 >> bits; - var s7 = a.s7 >> bits; - var s8 = a.s8 >> bits; - var s9 = a.s9 >> bits; - var s10 = a.s10 >> bits; - var s11 = a.s11 >> bits; - var s12 = a.s12 >> bits; - var s13 = a.s13 >> bits; - var s14 = a.s14 >> bits; - var s15 = a.s15 >> bits; - return SIMD.int8x16(s0, s1, s2, s3, s4, s5, s6, s7, + var s0 = SIMD.Int8x16.extractLane(a, 0) >> bits; + var s1 = SIMD.Int8x16.extractLane(a, 1) >> bits; + var s2 = SIMD.Int8x16.extractLane(a, 2) >> bits; + var s3 = SIMD.Int8x16.extractLane(a, 3) >> bits; + var s4 = SIMD.Int8x16.extractLane(a, 4) >> bits; + var s5 = SIMD.Int8x16.extractLane(a, 5) >> bits; + var s6 = SIMD.Int8x16.extractLane(a, 6) >> bits; + var s7 = SIMD.Int8x16.extractLane(a, 7) >> bits; + var s8 = SIMD.Int8x16.extractLane(a, 8) >> bits; + var s9 = SIMD.Int8x16.extractLane(a, 9) >> bits; + var s10 = SIMD.Int8x16.extractLane(a, 10) >> bits; + var s11 = SIMD.Int8x16.extractLane(a, 11) >> bits; + var s12 = SIMD.Int8x16.extractLane(a, 12) >> bits; + var s13 = SIMD.Int8x16.extractLane(a, 13) >> bits; + var s14 = SIMD.Int8x16.extractLane(a, 14) >> bits; + var s15 = SIMD.Int8x16.extractLane(a, 15) >> bits; + return SIMD.Int8x16(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15); } } -if (typeof SIMD.int8x16.load === "undefined") { +if (typeof SIMD.Int8x16.load === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @return {int8x16} New instance of int8x16. + * @return {Int8x16} New instance of Int8x16. */ - SIMD.int8x16.load = function(tarray, index) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int8x16.load = function(tarray, index) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - var i8temp = _SIMD_PRIVATE._i8x16; + var i8temp = _i8x16; var array = bpe == 1 ? i8temp : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) array[i] = tarray[index + i]; - return SIMD.int8x16(i8temp[0], i8temp[1], i8temp[2], i8temp[3], + return SIMD.Int8x16(i8temp[0], i8temp[1], i8temp[2], i8temp[3], i8temp[4], i8temp[5], i8temp[6], i8temp[7], i8temp[8], i8temp[9], i8temp[10], i8temp[11], i8temp[12], i8temp[13], i8temp[14], i8temp[15]); } } -if (typeof SIMD.int8x16.store === "undefined") { +if (typeof SIMD.Int8x16.store === "undefined") { /** * @param {Typed array} tarray An instance of a typed array. * @param {Number} index An instance of Number. - * @param {int8x16} value An instance of int8x16. - * @return {void} + * @param {Int8x16} value An instance of Int8x16. + * @return {Int8x16} value */ - SIMD.int8x16.store = function(tarray, index, value) { - if (!_SIMD_PRIVATE.isTypedArray(tarray)) + SIMD.Int8x16.store = function(tarray, index, value) { + if (!isTypedArray(tarray)) throw new TypeError("The 1st argument must be a typed array."); - if (!_SIMD_PRIVATE.isNumber(index)) - throw new TypeError("The 2nd argument must be a Number."); + if (!isInt32(index)) + throw new TypeError("The 2nd argument must be an Int32."); var bpe = tarray.BYTES_PER_ELEMENT; if (index < 0 || (index * bpe + 16) > tarray.byteLength) throw new RangeError("The value of index is invalid."); - value = SIMD.int8x16.check(value); - _SIMD_PRIVATE._i8x16[0] = value.s0; - _SIMD_PRIVATE._i8x16[1] = value.s1; - _SIMD_PRIVATE._i8x16[2] = value.s2; - _SIMD_PRIVATE._i8x16[3] = value.s3; - _SIMD_PRIVATE._i8x16[4] = value.s4; - _SIMD_PRIVATE._i8x16[5] = value.s5; - _SIMD_PRIVATE._i8x16[6] = value.s6; - _SIMD_PRIVATE._i8x16[7] = value.s7; - _SIMD_PRIVATE._i8x16[8] = value.s8; - _SIMD_PRIVATE._i8x16[9] = value.s9; - _SIMD_PRIVATE._i8x16[10] = value.s10; - _SIMD_PRIVATE._i8x16[11] = value.s11; - _SIMD_PRIVATE._i8x16[12] = value.s12; - _SIMD_PRIVATE._i8x16[13] = value.s13; - _SIMD_PRIVATE._i8x16[14] = value.s14; - _SIMD_PRIVATE._i8x16[15] = value.s15; - var array = bpe == 1 ? _SIMD_PRIVATE._i8x16 : - bpe == 2 ? _SIMD_PRIVATE._i16x8 : - bpe == 4 ? (tarray instanceof Float32Array ? _SIMD_PRIVATE._f32x4 : _SIMD_PRIVATE._i32x4) : - _SIMD_PRIVATE._f64x2; + value = SIMD.Int8x16.check(value); + _i8x16[0] = SIMD.Int8x16.extractLane(value, 0); + _i8x16[1] = SIMD.Int8x16.extractLane(value, 1); + _i8x16[2] = SIMD.Int8x16.extractLane(value, 2); + _i8x16[3] = SIMD.Int8x16.extractLane(value, 3); + _i8x16[4] = SIMD.Int8x16.extractLane(value, 4); + _i8x16[5] = SIMD.Int8x16.extractLane(value, 5); + _i8x16[6] = SIMD.Int8x16.extractLane(value, 6); + _i8x16[7] = SIMD.Int8x16.extractLane(value, 7); + _i8x16[8] = SIMD.Int8x16.extractLane(value, 8); + _i8x16[9] = SIMD.Int8x16.extractLane(value, 9); + _i8x16[10] = SIMD.Int8x16.extractLane(value, 10); + _i8x16[11] = SIMD.Int8x16.extractLane(value, 11); + _i8x16[12] = SIMD.Int8x16.extractLane(value, 12); + _i8x16[13] = SIMD.Int8x16.extractLane(value, 13); + _i8x16[14] = SIMD.Int8x16.extractLane(value, 14); + _i8x16[15] = SIMD.Int8x16.extractLane(value, 15); + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; var n = 16 / bpe; for (var i = 0; i < n; ++i) tarray[index + i] = array[i]; + return value; } } -if (typeof Float32x4Array === "undefined") { - Float32x4Array = function(a, b, c) { - if (_SIMD_PRIVATE.isNumber(a)) { - this.storage_ = new Float32Array(a*4); - this.length_ = a; - this.byteOffset_ = 0; - return; - } else if (_SIMD_PRIVATE.isTypedArray(a)) { - if (!(a instanceof Float32x4Array)) { - throw "Copying typed array of non-Float32x4Array is unimplemented."; - } - this.storage_ = new Float32Array(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 (_SIMD_PRIVATE.isArrayBuffer(a)) { - if ((b != undefined) && (b % Float32x4Array.BYTES_PER_ELEMENT) != 0) { - throw "byteOffset must be a multiple of 16."; - } - if (c != undefined) { - c *= 4; - this.storage_ = new Float32Array(a, b, c); - } - else { - // Note: new Float32Array(a, b) is NOT equivalent to new Float32Array(a, b, undefined) - this.storage_ = new Float32Array(a, b); - } - this.length_ = this.storage_.length / 4; - this.byteOffset_ = b != undefined ? b : 0; - } else { - throw "Unknown type of first argument."; - } - } - - Object.defineProperty(Float32x4Array.prototype, 'length', { - get: function() { return this.length_; } - }); - - Object.defineProperty(Float32x4Array.prototype, 'byteLength', { - get: function() { return this.length_ * Float32x4Array.BYTES_PER_ELEMENT; } - }); - - Object.defineProperty(Float32x4Array, 'BYTES_PER_ELEMENT', { - get: function() { return 16; } - }); - - Object.defineProperty(Float32x4Array.prototype, 'BYTES_PER_ELEMENT', { - get: function() { return 16; } - }); - - Object.defineProperty(Float32x4Array.prototype, 'byteOffset', { - get: function() { return this.byteOffset_; } - }); - - Object.defineProperty(Float32x4Array.prototype, 'buffer', { - get: function() { return this.storage_.buffer; } - }); - - Float32x4Array.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 SIMD.float32x4(x, y, z, w); - } - - Float32x4Array.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 SIMD.float32x4)) { - throw "Value is not a float32x4."; - } - 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; - } -} - -if (typeof Int32x4Array === "undefined") { - Int32x4Array = function(a, b, c) { - if (_SIMD_PRIVATE.isNumber(a)) { - this.storage_ = new Int32Array(a*4); - this.length_ = a; - this.byteOffset_ = 0; - return; - } else if (_SIMD_PRIVATE.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 ints. - for (var i = 0; i < a.length*4; i++) { - this.storage_[i] = a.storage_[i]; - } - } else if (_SIMD_PRIVATE.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 Int32Array(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 SIMD.int32x4(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 SIMD.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; - } - - _SIMD_PRIVATE.isDataView = function(v) { - return v instanceof DataView; - } - - DataView.prototype.getFloat32x4 = function(byteOffset, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - if (typeof littleEndian === 'undefined') - littleEndian = false; - return SIMD.float32x4(this.getFloat32(byteOffset, littleEndian), - this.getFloat32(byteOffset + 4, littleEndian), - this.getFloat32(byteOffset + 8, littleEndian), - this.getFloat32(byteOffset + 12, littleEndian)); - } - - DataView.prototype.getFloat64x2 = function(byteOffset, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - if (typeof littleEndian === 'undefined') - littleEndian = false; - return SIMD.float64x2(this.getFloat64(byteOffset, littleEndian), - this.getFloat64(byteOffset + 8, littleEndian)); - } - - DataView.prototype.getInt32x4 = function(byteOffset, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - if (typeof littleEndian === 'undefined') - littleEndian = false; - return SIMD.int32x4(this.getInt32(byteOffset, littleEndian), - this.getInt32(byteOffset + 4, littleEndian), - this.getInt32(byteOffset + 8, littleEndian), - this.getInt32(byteOffset + 12, littleEndian)); - } - - DataView.prototype.getInt16x8 = function(byteOffset, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - if (typeof littleEndian === 'undefined') - littleEndian = false; - return SIMD.int16x8(this.getInt16(byteOffset, littleEndian), - this.getInt16(byteOffset + 2, littleEndian), - this.getInt16(byteOffset + 4, littleEndian), - this.getInt16(byteOffset + 6, littleEndian), - this.getInt16(byteOffset + 8, littleEndian), - this.getInt16(byteOffset + 10, littleEndian), - this.getInt16(byteOffset + 12, littleEndian), - this.getInt16(byteOffset + 14, littleEndian)); - } - - DataView.prototype.getInt8x16 = function(byteOffset, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - if (typeof littleEndian === 'undefined') - littleEndian = false; - return SIMD.int8x16(this.getInt8(byteOffset, littleEndian), - this.getInt8(byteOffset + 1, littleEndian), - this.getInt8(byteOffset + 2, littleEndian), - this.getInt8(byteOffset + 3, littleEndian), - this.getInt8(byteOffset + 4, littleEndian), - this.getInt8(byteOffset + 5, littleEndian), - this.getInt8(byteOffset + 6, littleEndian), - this.getInt8(byteOffset + 7, littleEndian), - this.getInt8(byteOffset + 8, littleEndian), - this.getInt8(byteOffset + 9, littleEndian), - this.getInt8(byteOffset + 10, littleEndian), - this.getInt8(byteOffset + 11, littleEndian), - this.getInt8(byteOffset + 12, littleEndian), - this.getInt8(byteOffset + 13, littleEndian), - this.getInt8(byteOffset + 14, littleEndian), - this.getInt8(byteOffset + 15, littleEndian)); - } - - DataView.prototype.setFloat32x4 = function(byteOffset, value, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - value = SIMD.float32x4.check(value); - if (typeof littleEndian === 'undefined') - littleEndian = false; - this.setFloat32(byteOffset, value.x, littleEndian); - this.setFloat32(byteOffset + 4, value.y, littleEndian); - this.setFloat32(byteOffset + 8, value.z, littleEndian); - this.setFloat32(byteOffset + 12, value.w, littleEndian); - } - - DataView.prototype.setFloat64x2 = function(byteOffset, value, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - value = SIMD.float64x2.check(value); - if (typeof littleEndian === 'undefined') - littleEndian = false; - this.setFloat64(byteOffset, value.x, littleEndian); - this.setFloat64(byteOffset + 8, value.y, littleEndian); - } - - DataView.prototype.setInt32x4 = function(byteOffset, value, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - value = SIMD.int32x4.check(value); - if (typeof littleEndian === 'undefined') - littleEndian = false; - this.setInt32(byteOffset, value.x, littleEndian); - this.setInt32(byteOffset + 4, value.y, littleEndian); - this.setInt32(byteOffset + 8, value.z, littleEndian); - this.setInt32(byteOffset + 12, value.w, littleEndian); - } - - DataView.prototype.setInt16x8 = function(byteOffset, value, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - value = SIMD.int16x8.check(value); - if (typeof littleEndian === 'undefined') - littleEndian = false; - this.setInt16(byteOffset, value.s0, littleEndian); - this.setInt16(byteOffset + 2, value.s1, littleEndian); - this.setInt16(byteOffset + 4, value.s2, littleEndian); - this.setInt16(byteOffset + 6, value.s3, littleEndian); - this.setInt16(byteOffset + 8, value.s4, littleEndian); - this.setInt16(byteOffset + 10, value.s5, littleEndian); - this.setInt16(byteOffset + 12, value.s6, littleEndian); - this.setInt16(byteOffset + 14, value.s7, littleEndian); - } - - DataView.prototype.setInt8x16 = function(byteOffset, value, littleEndian) { - if (!_SIMD_PRIVATE.isDataView(this)) - throw new TypeError("This is not a DataView."); - if (byteOffset < 0 || (byteOffset + 16) > this.buffer.byteLength) - throw new RangeError("The value of byteOffset is invalid."); - value = SIMD.int8x16.check(value); - if (typeof littleEndian === 'undefined') - littleEndian = false; - this.setInt8(byteOffset, value.s0, littleEndian); - this.setInt8(byteOffset + 1, value.s1, littleEndian); - this.setInt8(byteOffset + 2, value.s2, littleEndian); - this.setInt8(byteOffset + 3, value.s3, littleEndian); - this.setInt8(byteOffset + 4, value.s4, littleEndian); - this.setInt8(byteOffset + 5, value.s5, littleEndian); - this.setInt8(byteOffset + 6, value.s6, littleEndian); - this.setInt8(byteOffset + 7, value.s7, littleEndian); - this.setInt8(byteOffset + 8, value.s8, littleEndian); - this.setInt8(byteOffset + 9, value.s9, littleEndian); - this.setInt8(byteOffset + 10, value.s10, littleEndian); - this.setInt8(byteOffset + 11, value.s11, littleEndian); - this.setInt8(byteOffset + 12, value.s12, littleEndian); - this.setInt8(byteOffset + 13, value.s13, littleEndian); - this.setInt8(byteOffset + 14, value.s14, littleEndian); - this.setInt8(byteOffset + 15, value.s15, littleEndian); - } -} +// If we're in a browser, the global namespace is named 'window'. If we're +// in node, it's named 'global'. If we're in a shell, 'this' might work. +})(typeof window !== "undefined" + ? window + : (typeof process === 'object' && + typeof require === 'function' && + typeof global === 'object') + ? global + : this); diff --git a/system/include/emscripten/vector.h b/system/include/emscripten/vector.h index 3f28599fc63f..ac3a06084898 100644 --- a/system/include/emscripten/vector.h +++ b/system/include/emscripten/vector.h @@ -18,36 +18,36 @@ float32x4 emscripten_float32x4_abs(float32x4 __a) __attribute__((__nothrow__, __ float32x4 emscripten_float32x4_sqrt(float32x4 __a) __attribute__((__nothrow__, __const__)); float32x4 emscripten_float32x4_reciprocalApproximation(float32x4 __a) __attribute__((__nothrow__, __const__)); float32x4 emscripten_float32x4_reciprocalSqrtApproximation(float32x4 __a) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_float32x4_lessThan(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_float32x4_lessThanOrEqual(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_float32x4_equal(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_float32x4_notEqual(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_float32x4_greaterThanOrEqual(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_float32x4_greaterThan(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_and(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_or(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_xor(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_not(float32x4 __a) __attribute__((__nothrow__, __const__)); +inline int32x4 emscripten_float32x4_lessThan(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)) { return __a < __b; } +inline int32x4 emscripten_float32x4_lessThanOrEqual(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)) { return __a <= __b; } +inline int32x4 emscripten_float32x4_equal(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)) { return __a == __b; } +inline int32x4 emscripten_float32x4_notEqual(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)) { return __a != __b; } +inline int32x4 emscripten_float32x4_greaterThanOrEqual(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)) { return __a >= __b; } +inline int32x4 emscripten_float32x4_greaterThan(float32x4 __a, float32x4 __b) __attribute__((__nothrow__, __const__)) { return __a > __b; } float32x4 emscripten_float32x4_select(int32x4 __a, float32x4 __b, float32x4 __c) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_fromFloat32x4Bits(float32x4 __a) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_fromFloat32x4(float32x4 __a) __attribute__((__nothrow__, __const__)); - -int32x4 emscripten_int32x4_lessThan(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_lessThanOrEqual(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_equal(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_notEqual(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_greaterThanOrEqual(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)); -int32x4 emscripten_int32x4_greaterThan(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)); +inline int32x4 emscripten_int32x4_and(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a & __b; } +inline int32x4 emscripten_int32x4_or(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a | __b; } +inline int32x4 emscripten_int32x4_xor(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a ^ __b; } +inline int32x4 emscripten_int32x4_not(int32x4 __a) __attribute__((__nothrow__, __const__)) { return ~__a; } +inline int32x4 emscripten_int32x4_fromFloat32x4Bits(float32x4 __a) __attribute__((__nothrow__, __const__)) { return (int32x4)__a; } +inline int32x4 emscripten_int32x4_fromFloat32x4(float32x4 __a) __attribute__((__nothrow__, __const__)) { return __builtin_convertvector(__a, int32x4); } + +inline int32x4 emscripten_int32x4_lessThan(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a < __b; } +inline int32x4 emscripten_int32x4_lessThanOrEqual(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a <= __b; } +inline int32x4 emscripten_int32x4_equal(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a == __b; } +inline int32x4 emscripten_int32x4_notEqual(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a != __b; } +inline int32x4 emscripten_int32x4_greaterThanOrEqual(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a >= __b; } +inline int32x4 emscripten_int32x4_greaterThan(int32x4 __a, int32x4 __b) __attribute__((__nothrow__, __const__)) { return __a > __b; } int32x4 emscripten_int32x4_select(int32x4 __a, int32x4 __b, int32x4 __c) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_fromInt32x4Bits(int32x4 __a) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_fromInt32x4(int32x4 __a) __attribute__((__nothrow__, __const__)); +inline float32x4 emscripten_float32x4_fromInt32x4Bits(int32x4 __a) __attribute__((__nothrow__, __const__)) { return (float32x4)__a; } +inline float32x4 emscripten_float32x4_fromInt32x4(int32x4 __a) __attribute__((__nothrow__, __const__)) { return __builtin_convertvector(__a, float32x4); } -float32x4 emscripten_float32x4_loadx(const void *__p) __attribute__((__nothrow__, __const__)); -float32x4 emscripten_float32x4_loadxy(const void *__p) __attribute__((__nothrow__, __const__)); -void emscripten_float32x4_storex(const void *__p, float32x4 __a) __attribute__((__nothrow__)); -void emscripten_float32x4_storexy(const void *__p, float32x4 __a) __attribute__((__nothrow__)); +float32x4 emscripten_float32x4_load1(const void *__p) __attribute__((__nothrow__, __const__)); +float32x4 emscripten_float32x4_load2(const void *__p) __attribute__((__nothrow__, __const__)); +void emscripten_float32x4_store1(const void *__p, float32x4 __a) __attribute__((__nothrow__)); +void emscripten_float32x4_store2(const void *__p, float32x4 __a) __attribute__((__nothrow__)); #ifdef __cplusplus } diff --git a/system/include/emscripten/xmmintrin.h b/system/include/emscripten/xmmintrin.h index 9685d2921cb7..11b474ae7541 100644 --- a/system/include/emscripten/xmmintrin.h +++ b/system/include/emscripten/xmmintrin.h @@ -53,13 +53,13 @@ _mm_load_ps(const float *__p) static __inline__ __m128 __attribute__((__always_inline__)) _mm_loadl_pi(__m128 __a, const void /*__m64*/ *__p) { - return __builtin_shufflevector(emscripten_float32x4_loadxy(__p), __a, 0, 1, 6, 7); + return __builtin_shufflevector(emscripten_float32x4_load2(__p), __a, 0, 1, 6, 7); } static __inline__ __m128 __attribute__((__always_inline__)) _mm_loadh_pi(__m128 __a, const void /*__m64*/ *__p) { - return __builtin_shufflevector(__a, emscripten_float32x4_loadxy(__p), 0, 1, 4, 5); + return __builtin_shufflevector(__a, emscripten_float32x4_load2(__p), 0, 1, 4, 5); } static __inline__ __m128 __attribute__((__always_inline__)) @@ -90,19 +90,19 @@ _mm_load_ps1(const float *__p) static __inline__ __m128 __attribute__((__always_inline__)) _mm_load_ss(const float *__p) { - return emscripten_float32x4_loadx(__p); + return emscripten_float32x4_load1(__p); } static __inline__ void __attribute__((__always_inline__)) _mm_storel_pi(void /*__m64*/ *__p, __m128 __a) { - emscripten_float32x4_storexy(__p, __a); + emscripten_float32x4_store2(__p, __a); } static __inline__ void __attribute__((__always_inline__)) _mm_storeh_pi(void /*__m64*/ *__p, __m128 __a) { - emscripten_float32x4_storexy(__p, __builtin_shufflevector(__a, __a, 2, 3, 0, 1)); + emscripten_float32x4_store2(__p, __builtin_shufflevector(__a, __a, 2, 3, 0, 1)); } static __inline__ void __attribute__((__always_inline__)) @@ -140,7 +140,7 @@ _mm_store_ps1(float *__p, __m128 __a) static __inline__ void __attribute__((__always_inline__)) _mm_store_ss(float *__p, __m128 __a) { - emscripten_float32x4_storex(__p, __a); + emscripten_float32x4_store1(__p, __a); } static __inline__ void __attribute__((__always_inline__)) @@ -376,8 +376,8 @@ _mm_cmpgt_ss(__m128 __a, __m128 __b) static __inline__ __m128 __attribute__((__always_inline__)) _mm_cmpord_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_and(emscripten_float32x4_equal(__a, __a), - emscripten_float32x4_equal(__b, __b)); + return emscripten_int32x4_and(emscripten_float32x4_equal(__a, __a), + emscripten_float32x4_equal(__b, __b)); } static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) _mm_cmpord_ss(__m128 __a, __m128 __b) @@ -387,8 +387,8 @@ static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) _mm_cmp static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) _mm_cmpunord_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_or(emscripten_float32x4_notEqual(__a, __a), - emscripten_float32x4_notEqual(__b, __b)); + return emscripten_int32x4_or(emscripten_float32x4_notEqual(__a, __a), + emscripten_float32x4_notEqual(__b, __b)); } static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) _mm_cmpunord_ss(__m128 __a, __m128 __b) @@ -399,25 +399,25 @@ static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) _mm_cmp static __inline__ __m128 __attribute__((__always_inline__)) _mm_and_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_and(__a, __b); + return emscripten_int32x4_and(__a, __b); } static __inline__ __m128 __attribute__((__always_inline__)) _mm_andnot_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_and(emscripten_float32x4_not(__a), __b); + return emscripten_int32x4_and(emscripten_int32x4_not(__a), __b); } static __inline__ __m128 __attribute__((__always_inline__)) _mm_or_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_or(__a, __b); + return emscripten_int32x4_or(__a, __b); } static __inline__ __m128 __attribute__((__always_inline__)) _mm_xor_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_xor(__a, __b); + return emscripten_int32x4_xor(__a, __b); } static __inline__ __m128 __attribute__((__always_inline__)) @@ -435,7 +435,7 @@ _mm_cmpneq_ss(__m128 __a, __m128 __b) static __inline__ __m128 __attribute__((__always_inline__)) _mm_cmpnge_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_not(_mm_cmpge_ps(__a, __b)); + return emscripten_int32x4_not(_mm_cmpge_ps(__a, __b)); } static __inline__ __m128 __attribute__((__always_inline__)) @@ -447,7 +447,7 @@ _mm_cmpnge_ss(__m128 __a, __m128 __b) static __inline__ __m128 __attribute__((__always_inline__)) _mm_cmpngt_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_not(_mm_cmpgt_ps(__a, __b)); + return emscripten_int32x4_not(_mm_cmpgt_ps(__a, __b)); } static __inline__ __m128 __attribute__((__always_inline__)) @@ -459,7 +459,7 @@ _mm_cmpngt_ss(__m128 __a, __m128 __b) static __inline__ __m128 __attribute__((__always_inline__)) _mm_cmpnle_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_not(_mm_cmple_ps(__a, __b)); + return emscripten_int32x4_not(_mm_cmple_ps(__a, __b)); } static __inline__ __m128 __attribute__((__always_inline__)) @@ -471,7 +471,7 @@ _mm_cmpnle_ss(__m128 __a, __m128 __b) static __inline__ __m128 __attribute__((__always_inline__)) _mm_cmpnlt_ps(__m128 __a, __m128 __b) { - return emscripten_float32x4_not(_mm_cmplt_ps(__a, __b)); + return emscripten_int32x4_not(_mm_cmplt_ps(__a, __b)); } static __inline__ __m128 __attribute__((__always_inline__)) diff --git a/tests/optimizer/simd-output.js b/tests/optimizer/simd-output.js index 29b6d8dea7db..1fa597802105 100644 --- a/tests/optimizer/simd-output.js +++ b/tests/optimizer/simd-output.js @@ -1,7 +1,7 @@ function a(x, y) { - x = SIMD_int32x4_check(x); - y = SIMD_float32x4_check(y); - var z = SIMD_float32x4(0, 0, 0, 0); + x = SIMD_Int32x4_check(x); + y = SIMD_Float32x4_check(y); + var z = SIMD_Float32x4(0, 0, 0, 0); work(z); } diff --git a/tests/optimizer/simd.js b/tests/optimizer/simd.js index 0c715a8983d2..1bb6f1b57ef1 100644 --- a/tests/optimizer/simd.js +++ b/tests/optimizer/simd.js @@ -1,7 +1,7 @@ function a(x, y) { - x = SIMD_int32x4_check(x); - y = SIMD_float32x4_check(y); - var z = SIMD_float32x4(0, 0, 0, 0); + x = SIMD_Int32x4_check(x); + y = SIMD_Float32x4_check(y); + var z = SIMD_Float32x4(0, 0, 0, 0); work(z); } // EMSCRIPTEN_GENERATED_FUNCTIONS: ["a"] diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 3afa5027fe85..930e28bda0e8 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -1773,10 +1773,10 @@ function detectType(node, asmInfo, inVarDef) { if (node[1][0] === 'name') { switch (node[1][1]) { case 'Math_fround': return ASM_FLOAT; - case 'SIMD_float32x4': - case 'SIMD_float32x4_check': return ASM_FLOAT32X4; - case 'SIMD_int32x4': - case 'SIMD_int32x4_check': return ASM_INT32X4; + case 'SIMD_Float32x4': + case 'SIMD_Float32x4_check': return ASM_FLOAT32X4; + case 'SIMD_Int32x4': + case 'SIMD_Int32x4_check': return ASM_INT32X4; default: break; } } @@ -1838,8 +1838,8 @@ function makeAsmCoercion(node, type) { case ASM_INT: return ['binary', '|', node, ['num', 0]]; case ASM_DOUBLE: return ['unary-prefix', '+', node]; case ASM_FLOAT: return ['call', ['name', 'Math_fround'], [node]]; - case ASM_FLOAT32X4: return ['call', ['name', 'SIMD_float32x4_check'], [node]]; - case ASM_INT32X4: return ['call', ['name', 'SIMD_int32x4_check'], [node]]; + case ASM_FLOAT32X4: return ['call', ['name', 'SIMD_Float32x4_check'], [node]]; + case ASM_INT32X4: return ['call', ['name', 'SIMD_Int32x4_check'], [node]]; case ASM_NONE: default: return node; // non-validating code, emit nothing XXX this is dangerous, we should only allow this when we know we are not validating } @@ -1863,10 +1863,10 @@ function makeAsmVarDef(v, type) { } } case ASM_FLOAT32X4: { - return [v, ['call', ['name', 'SIMD_float32x4'], [['num', 0], ['num', 0], ['num', 0], ['num', 0]]]]; + return [v, ['call', ['name', 'SIMD_Float32x4'], [['num', 0], ['num', 0], ['num', 0], ['num', 0]]]]; } case ASM_INT32X4: { - return [v, ['call', ['name', 'SIMD_int32x4'], [['num', 0], ['num', 0], ['num', 0], ['num', 0]]]]; + return [v, ['call', ['name', 'SIMD_Int32x4'], [['num', 0], ['num', 0], ['num', 0], ['num', 0]]]]; } default: throw 'wha? ' + JSON.stringify([v, type]) + new Error().stack; } diff --git a/tools/optimizer/optimizer.cpp b/tools/optimizer/optimizer.cpp index 513d3eef6342..e5c761eba839 100644 --- a/tools/optimizer/optimizer.cpp +++ b/tools/optimizer/optimizer.cpp @@ -14,8 +14,8 @@ typedef std::vector StringVec; Ref doc, extraInfo; -IString SIMD_INT32X4_CHECK("SIMD_int32x4_check"), - SIMD_FLOAT32X4_CHECK("SIMD_float32x4_check"); +IString SIMD_INT32X4_CHECK("SIMD_Int32x4_check"), + SIMD_FLOAT32X4_CHECK("SIMD_Float32x4_check"); //================== // Infrastructure diff --git a/tools/optimizer/parser.cpp b/tools/optimizer/parser.cpp index e7f32dbd41c3..cdd2927d0d46 100644 --- a/tools/optimizer/parser.cpp +++ b/tools/optimizer/parser.cpp @@ -36,8 +36,8 @@ IString TOPLEVEL("toplevel"), UNARY_PREFIX("unary-prefix"), UNARY_POSTFIX("unary-postfix"), MATH_FROUND("Math_fround"), - SIMD_FLOAT32X4("SIMD_float32x4"), - SIMD_INT32X4("SIMD_int32x4"), + SIMD_FLOAT32X4("SIMD_Float32x4"), + SIMD_INT32X4("SIMD_Int32x4"), PLUS("+"), MINUS("-"), OR("|"),