{{JSRef}} {{SeeCompatTable}}
The SIMD.Int32x4
data type is a 128-bit vector divided into 4 lanes storing 32-bit signed integer values.
Figure 1: SIMD.Int32x4 in a 128-bit SIMD register.
Syntax
SIMD.Int32x4(x, y, z, w);
Parameters
x
{{optional_inline}}- An integer specifying the value of the first lane. Defaults to 0.
y
{{optional_inline}}- An integer specifying the value of the second lane. Defaults to 0.
z
{{optional_inline}}- An integer specifying the value of the third lane. Defaults to 0.
w
{{optional_inline}}- An integer specifying the value of the fourth lane. Defaults to 0.
Constructor functions
In addition to the simple creator functions, the SIMD API provides the following constructor functions.
- {{jsxref("SIMD.splat", "SIMD.Int32x4.splat()")}}
- Creates an Int32x4 with all lanes set to a given value.
You can also convert from another SIMD data type to Int32x4.
Note: SIMD types don't work with new
, as SIMD values are no "boxed" objects (comparable to String(s)
vs. new String(s)
, which creates a String object).
var v = new SIMD.Int32x4(1,2,3,4); // TypeError: SIMD.Int32x4 is not a constructor var w = new SIMD.Int32x4.splat(3); // TypeError: SIMD.Int32x4.splat is not a constructor
Instead, you just write:
var v = SIMD.Int32x4(1,2,3,4); var w = SIMD.Int32x4.splat(3);
Operations
To actually do something with SIMD types, SIMD operations are needed that work on SIMD data types.
Checking SIMD types
- {{jsxref("SIMD.check", "SIMD.Int32x4.check()")}}
- Returns a new Int32x4 if the parameter is a valid Int32x4 data type. Throws a {{jsxref("TypeError")}} otherwise.
Accessing and mutating lanes
- {{jsxref("SIMD.extractLane", "SIMD.Int32x4.extractLane()")}}
- Returns the value of the given lane.
- {{jsxref("SIMD.replaceLane", "SIMD.Int32x4.replaceLane()")}}
- Returns a new Int32x4 with the given lane value replaced.
Loading from and storing into typed arrays
- {{jsxref("SIMD.load", "SIMD.Int32x4.load()")}}
- {{jsxref("SIMD.load", "SIMD.Int32x4.load1()")}}
- {{jsxref("SIMD.load", "SIMD.Int32x4.load2()")}}
- {{jsxref("SIMD.load", "SIMD.Int32x4.load3()")}}
- Returns a new Int32x4 with the lane values loaded from a typed array.
- {{jsxref("SIMD.store", "SIMD.Int32x4.store()")}}
{{jsxref("SIMD.store", "SIMD.Int32x4.store1()")}}
{{jsxref("SIMD.store", "SIMD.Int32x4.store2()")}}
{{jsxref("SIMD.store", "SIMD.Int32x4.store3()")}} - Stores an Int32x4 into a typed array.
Arithmetic operations
- {{jsxref("SIMD.add", "SIMD.Int32x4.add()")}}
- Returns a new Int32x4 with the lane values added (
a + b
). - {{jsxref("SIMD.mul", "SIMD.Int32x4.mul()")}}
- Returns a new Int32x4 with the lane values multiplied (
a * b
). - {{jsxref("SIMD.neg", "SIMD.Int32x4.neg()")}}
- Returns a new Int32x4 with the negated lane values.
- {{jsxref("SIMD.sub", "SIMD.Int32x4.sub()")}}
- Returns a new Int32x4 with the lane values subtracted (
a - b
). -
Shuffling and swizzling
- {{jsxref("SIMD.shuffle", "SIMD.Int32x4.shuffle()")}}
- Returns a new Int32x4 with the lane values shuffled.
- {{jsxref("SIMD.swizzle", "SIMD.Int32x4.swizzle()")}}
- Returns a new Int32x4 with the lane values swizzled.
Selections
- {{jsxref("SIMD.select", "SIMD.Int32x4.select()")}}
- Returns a new Int32x4 with the lane values being a mix of the lanes depending on the selector mask.
Comparisons
- {{jsxref("SIMD.equal", "SIMD.Int32x4.equal()")}}
- Returns a selection mask depending on
a == b
. - {{jsxref("SIMD.notEqual", "SIMD.Int32x4.notEqual()")}}
- Returns a selection mask depending on
a != b
. - {{jsxref("SIMD.lessThan", "SIMD.Int32x4.lessThan()")}}
- Returns a selection mask depending on
a < b
. - {{jsxref("SIMD.lessThanOrEqual", "SIMD.Int32x4.lessThanOrEqual()")}}
- Returns a selection mask depending on
a <= b
. - {{jsxref("SIMD.greaterThan", "SIMD.Int32x4.greaterThan()")}}
- Returns a selection mask depending on
a > b
. - {{jsxref("SIMD.greaterThanOrEqual", "SIMD.Int32x4.greaterThanOrEqual()")}}
- Returns a selection mask depending on
a >= b
.
Bitwise logical operations
- {{jsxref("SIMD.and", "SIMD.Int32x4.and()")}}
- Returns a new Int32x4 with the logical AND of the lane values (
a & b
). - {{jsxref("SIMD.or", "SIMD.Int32x4.or()")}}
- Returns a new Int32x4 with the logical OR of the lane values (
a | b
). - {{jsxref("SIMD.xor", "SIMD.Int32x4.xor()")}}
- Returns a new Int32x4 with the logical XOR of the lane values (
a ^ b
). - {{jsxref("SIMD.not", "SIMD.Int32x4.not()")}}
- Returns a new Int32x4 with lane with the logical NOT of the lane values (
~a
).
Bitwise shift operations
- {{jsxref("SIMD.shiftLeftByScalar", "SIMD.Int32x4.shiftLeftByScalar()")}}
- Returns a new Int32x4 with the lane values shifted left by a given bit count (
a << bits
). - {{jsxref("SIMD.shiftRightByScalar", "SIMD.Int32x4.shiftRightByScalar()")}}
- Returns a new Int32x4 with the lane values shifted right.
- {{jsxref("SIMD.shiftRightArithmeticByScalar", "SIMD.Int32x4.shiftRightArithmeticByScalar()")}}
- Returns a new Int32x4 with the lane values shifted right (arithmetic) by a given bit count (
a >> bits
). - {{jsxref("SIMD.shiftRightLogicalByScalar", "SIMD.Int32x4.shiftRightLogicalByScalar()")}}
- Returns a new Int32x4 with the lane values shifted right (logical) by a given bit count (
a >>> bits
).
Data conversions
- {{jsxref("SIMD.fromFloat32x4", "SIMD.Int32x4.fromFloat32x4()")}}
- Creates a new Int32x4 data type with a float conversion from a float32x4.
- {{jsxref("SIMD.fromFloat32x4Bits", "SIMD.Int32x4.fromFloat32x4Bits()")}}
- Creates a new Int32x4 data type with a bit-wise copy from a float32x4.
- {{jsxref("SIMD.fromFloat64x2Bits", "SIMD.Int32x4.fromFloat64x2Bits()")}}
- Creates a new Int32x4 data type with a bit-wise copy from a float64x2.
- {{jsxref("SIMD.fromInt16x8Bits", "SIMD.Int32x4.fromInt16x8Bits()")}}
- Creates a new Int32x4 data type with a bit-wise copy from an Int16x8.
- {{jsxref("SIMD.fromInt8x16Bits", "SIMD.Int32x4.fromInt8x16Bits()")}}
- Creates a new Int32x4 data type with a bit-wise copy from an Int8x16.
SIMD prototype
The following methods and properties are installed on the SIMD.Int32x4.prototype
.
SIMD.Int32x4.prototype.constructor
- Specifies the function that creates a SIMD object's prototype.
- {{jsxref("SIMD.toLocaleString", "SIMD.Int32x4.prototype.toLocaleString()")}}
- Returns a localized string representing the SIMD type and its elements. Overrides the {{jsxref("Object.prototype.toLocaleString()")}} method.
- {{jsxref("SIMD.toString", "SIMD.Int32x4.prototype.toString()")}}
- Returns a string representing the SIMD type and its elements. Overrides the {{jsxref("Object.prototype.toString()")}} method.
- {{jsxref("SIMD.valueOf", "SIMD.Int32x4.prototype.valueOf()")}}
- Returns the primitive value of a SIMD object.
- {{jsxref("SIMD.toSource", "SIMD.Int32x4.prototype.toSource()")}} {{non-standard_inline}}
- Returns a string representing the source code of the object. Overrides the {{jsxref("Object.prototype.toSource()")}} method.
Examples
Constructing an Int32x4
SIMD.Int32x4(1, 2, 3, 4); // Int32x4[1,2,3,4] SIMD.Int32x4(1, 2); // Int32x4[1,2,0,0] SIMD.Int32x4(); // Int32x4[0,0,0,0]
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('SIMD', '#int32x4', 'Int32x4')}} | {{Spec2('SIMD')}} | Initial definition. |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNightly("firefox")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNightly("firefox")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
See also
- {{jsxref("SIMD")}}