/*
Copyright (C) 2013
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
https://github.com/johnmccutchan/ecmascript_simd/blob/master/src/ecmascript_simd.js
*/
"use strict";
/**
* 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
*/
function float32x4(x, y, z, w) {
if (!(this instanceof float32x4)) {
return new float32x4(x, y, z, w);
}
this.storage_ = new Float32Array(4);
this.storage_[0] = x;
this.storage_[1] = y;
this.storage_[2] = z;
this.storage_[3] = w;
}
/**
* Construct a new instance of float32x4 number with 0.0 in all lanes.
* @constructor
*/
float32x4.zero = function() {
return float32x4(0.0, 0.0, 0.0, 0.0);
}
/**
* Construct a new instance of float32x4 number with the same value
* in all lanes.
* @param {double} value used for all lanes.
* @constructor
*/
float32x4.splat = function(s) {
return float32x4(s, s, s, s);
}
Object.defineProperty(float32x4.prototype, 'x', {
get: function() { return this.storage_[0]; }
});
Object.defineProperty(float32x4.prototype, 'y', {
get: function() { return this.storage_[1]; }
});
Object.defineProperty(float32x4.prototype, 'z', {
get: function() { return this.storage_[2]; }
});
Object.defineProperty(float32x4.prototype, 'w',
{ get: function() { return this.storage_[3]; }
});
/**
* Extract the sign bit from each lane return them in the first 4 bits.
*/
Object.defineProperty(float32x4.prototype, 'signMask', {
get: function() {
var mx = this.x < 0.0 ? 1 : 0;
var my = this.y < 0.0 ? 1 : 0;
var mz = this.z < 0.0 ? 1 : 0;
var mw = this.w < 0.0 ? 1 : 0;
return mx | my << 1 | mz << 2 | mw << 3;
}
});
/**
* Construct a new instance of int32x4 number.
* @param {integer} 32-bit unsigned value used for x lane.
* @param {integer} 32-bit unsigned value used for y lane.
* @param {integer} 32-bit unsigned value used for z lane.
* @param {integer} 32-bit unsigned value used for w lane.
* @constructor
*/
function int32x4(x, y, z, w) {
if (!(this instanceof int32x4)) {
return new int32x4(x, y, z, w);
}
this.storage_ = new Int32Array(4);
this.storage_[0] = x;
this.storage_[1] = y;
this.storage_[2] = z;
this.storage_[3] = w;
}
/**
* Construct a new instance of int32x4 number with 0xFFFFFFFF or 0x0 in each
* lane, depending on the truth value in x, y, z, and w.
* @param {boolean} flag used for x lane.
* @param {boolean} flag used for y lane.
* @param {boolean} flag used for z lane.
* @param {boolean} flag used for w lane.
* @constructor
*/
int32x4.bool = function(x, y, z, w) {
return int32x4(x ? -1 : 0x0,
y ? -1 : 0x0,
z