The SIMD.Float32x4
data type is a 128-bit vector divided into 4 lanes storing single precision floating point values.
Figure 1: SIMD.Float32x4 in a 128-bit SIMD register.
Syntax
SIMD.Float32x4(x, y, z, w);
Parameters
The input values are specified in double precision floating and are converted to single precision floating point values before being stored.
x
{{optional_inline}}- An double specifying the value of the first lane. Defaults to {{jsxref("NaN")}}.
y
{{optional_inline}}- An double specifying the value of the second lane. Defaults to {{jsxref("NaN")}}.
z
{{optional_inline}}- An double specifying the value of the third lane. Defaults to {{jsxref("NaN")}}.
w
{{optional_inline}}- An double specifying the value of the fourth lane. Defaults to {{jsxref("NaN")}}.
Constructor functions
In addition to the simple creator functions, the SIMD API provides the following constructor function. Note that you can also convert from another SIMD data type to Float32x4.
- {{jsxref("SIMD.splat", "SIMD.Float32x4.splat()")}}
- Creates an Float32x4 with all lanes set to a given value.
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.Float32x4(0,1,2,3); // TypeError: SIMD.Float32x4 is not a constructor var w = new SIMD.Float32x4.splat(3); // TypeError: SIMD.Float32x4.splat is not a constructor
Instead, you just write:
var v = SIMD.Float32x4(0,1,2,3); var w = SIMD.Float32x4.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.Float32x4.check()")}}
- Returns a new Float32x4 if the parameter is a valid Float32x4 data type. Throws a {{jsxref("TypeError")}} otherwise.
Accessing and mutating lanes
- {{jsxref("SIMD.extractLane", "SIMD.Float32x4.extractLane()")}}
- Returns the value of the given lane.
- {{jsxref("SIMD.replaceLane", "SIMD.Float32x4.replaceLane()")}}
- Returns a new Float32x4 with the given lane value replaced.
Loading from and storing into typed arrays
- {{jsxref("SIMD.load", "SIMD.Float32x4.load()")}}
- Returns a new Float32x4 with the lane values loaded from a typed array.
- {{jsxref("SIMD.store", "SIMD.Float32x4.store()")}}
- Stores an Float32x4 into a typed array.
Arithmetic operations
- {{jsxref("SIMD.abs", "SIMD.Float32x4.abs()")}}
- Returns a new Float32x4 with the absolute lane values.
- {{jsxref("SIMD.add", "SIMD.Float32x4.add()")}}
- Returns a new Float32x4 with the lane values added (
a + b
). - {{jsxref("SIMD.div", "SIMD.Float32x4.div()")}}
- Returns a new Float32x4 with the lane values divided (
a / b
). - {{jsxref("SIMD.mul", "SIMD.Float32x4.mul()")}}
- Returns a new Float32x4 with the lane values multiplied (
a * b
). - {{jsxref("SIMD.neg", "SIMD.Float32x4.neg()")}}
- Returns a new Float32x4 with the negated lane values.
- {{jsxref("SIMD.reciprocalApproximation", "SIMD.Float32x4.reciprocalApproximation()")}}
- Returns a new Float32x4 with an approximation of the reciprocal lane values.
- {{jsxref("SIMD.reciprocalSqrtApproximation", "SIMD.Float32x4.reciprocalSqrtApproximation()")}}
- Returns a new Float32x4 with an approximation of the reciprocal square root lane values.
- {{jsxref("SIMD.sub", "SIMD.Float32x4.sub()")}}
- Returns a new Float32x4 with the lane values subtracted (
a - b
). - {{jsxref("SIMD.sqrt", "SIMD.Float32x4.sqrt()")}}
- Returns a new Float32x4 with the square root of the lane values.
Shuffling and swizzling
- {{jsxref("SIMD.shuffle", "SIMD.Float32x4.shuffle()")}}
- Returns a new Float32x4 with the lane values shuffled.
- {{jsxref("SIMD.swizzle", "SIMD.Float32x4.swizzle()")}}
- Returns a new Float32x4 with the lane values swizzled.
Min and max values
- {{jsxref("SIMD.max", "SIMD.Float32x4.max()")}}
- Returns a new Float32x4 with the maximum of the lane values.
- {{jsxref("SIMD.maxNum", "SIMD.Float32x4.maxNum()")}}
- Returns a new Float32x4 with the maximum of the lane values, preferring numbers over {{jsxref("NaN")}}.
- {{jsxref("SIMD.min", "SIMD.Float32x4.min()")}}
- Returns a new Float32x4 with the minimum of the lane values.
- {{jsxref("SIMD.minNum", "SIMD.Float32x4.minNum()")}}
- Returns a new Float32x4 with the minimum of the lane values, preferring numbers over {{jsxref("NaN")}}.
Selections
- {{jsxref("SIMD.select", "SIMD.Float32x4.select()")}}
- Returns a new Float32x4 with the lane values being a mix of the lanes depending on the selector mask.
Comparisons
- {{jsxref("SIMD.equal", "SIMD.Float32x4.equal()")}}
- Returns a selection mask depending on
a == b
. - {{jsxref("SIMD.notEqual", "SIMD.Float32x4.notEqual()")}}
- Returns a selection mask depending on
a != b
. - {{jsxref("SIMD.lessThan", "SIMD.Float32x4.lessThan()")}}
- Returns a selection mask depending on
a < b
. - {{jsxref("SIMD.lessThanOrEqual", "SIMD.Float32x4.lessThanOrEqual()")}}
- Returns a selection mask depending on
a <= b
. - {{jsxref("SIMD.greaterThan", "SIMD.Float32x4.greaterThan()")}}
- Returns a selection mask depending on
a > b
. - {{jsxref("SIMD.greaterThanOrEqual", "SIMD.Float32x4.greaterThanOrEqual()")}}
- Returns a selection mask depending on
a >= b
.
Bitwise logical operations
- {{jsxref("SIMD.and", "SIMD.Float32x4.and()")}}
- Returns a new Float32x4 with the logical AND of the lane values (
a & b
). - {{jsxref("SIMD.or", "SIMD.Float32x4.or()")}}
- Returns a new Float32x4 with the logical OR of the lane values (
a | b
). - {{jsxref("SIMD.xor", "SIMD.Float32x4.xor()")}}
- Returns a new Float32x4 with the logical XOR of the lane values (
a ^ b
). - {{jsxref("SIMD.not", "SIMD.Float32x4.not()")}}
- Returns a new Float32x4 with lane with the logical NOT of the lane values (
~a
).
Data conversions
- {{jsxref("SIMD.fromInt32x4", "SIMD.Float32x4.fromInt32x4()")}}
- Creates a new Float32x4 data type with a Float conversion from an Int32x4.
- {{jsxref("SIMD.fromInt32x4Bits", "SIMD.Float32x4.fromInt32x4Bits()")}}
- Creates a new Float32x4 data type with a bit-wise copy from an Int32x4.
- {{jsxref("SIMD.fromFloat64x2", "SIMD.Float32x4.fromFloat64x2()")}}
- Creates a new Float32x4 data type with a Float conversion from a Float64x2.
- {{jsxref("SIMD.fromFloat64x2Bits", "SIMD.Float32x4.fromFloat64x2Bits()")}}
- Creates a new Float32x4 data type with a bit-wise copy from a Float64x2.
- {{jsxref("SIMD.fromInt16x8Bits", "SIMD.Float32x4.fromInt16x8Bits()")}}
- Creates a new Float32x4 data type with a bit-wise copy from an Int16x8.
- {{jsxref("SIMD.fromInt8x16Bits", "SIMD.Float32x4.fromInt8x16Bits()")}}
- Creates a new Float32x4 data type with a bit-wise copy from an Int8x16.
Examples
SIMD.Float32x4(1, 2, 3, 4); // Float32x4[1, 2, 3, 4] SIMD.Float32x4(1, 2); // Float32x4[1, 2, NaN, NaN] SIMD.Float32x4(); // Float32x4[NaN, NaN, NaN, NaN]
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('SIMD', '#float32x4', 'Float32x4')}} | {{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")}}