/*
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
*/
/**
* Construct a new instance of a 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 a 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 a 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 a uint32x4 number.
* @param {integer} 32-bit unsigned value used for x lane.
* @param {integer} 32-bit unsigned value used for y lane.
* @param {integer} 32-bit unsigned value used for z lane.
* @param {integer} 32-bit unsigned value used for w lane.
* @constructor
*/
function uint32x4(x, y, z, w) {
if (!(this instanceof uint32x4)) {
return new uint32x4(x, y, z, w);
}
this.storage_ = new Uint32Array(4);
this.storage_[0] = x;
this.storage_[1] = y;
this.storage_[2] = z;
this.storage_[3] = w;
}
/**
* Construct a new instance of a uint32x4 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
*/
uint32x4.bool = function(x, y, z, w) {
return uint32x4(x ? 0xFFFFFFFF : 0x0,
y ? 0xFFFFFFFF : 0x0,
z ? 0xFFFFFFFF : 0x0,
w ? 0xFFFFFFFF : 0x0);
}
/**
* Construct a new instance of a uint32x4 number with the same value
* in all lanes.
* @param {integer} value used for all lanes.
* @constructor
*/
uint32x4.splat = function(s) {
return uint32x4(s, s, s, s);
}
Object.defineProperty(uint32x4.prototype, 'x', {
get: function() { return this.storage_[0]; }
});
Object.defineProperty(uint32x4.prototype, 'y', {
get: function() { return this.storage_[1]; }
});
Object.defineProperty(uint32x4.prototype, 'z', {
get: function() { return this.storage_[2]; }
});
Object.defineProperty(uint32x4.prototype, 'w',
{ get: function() { return this.storage_[3]; }
});
Object.defineProperty(uint32x4.prototype, 'flagX', {
get: function() {