داوطلبان ما هنوز مقاله را به فارسی ترجمه نکرده‌اند. عضو بشوید و به ما کمک کنید!
شما همچنین می‌توانید مقاله را به زبان English (US) بخوانید.

SIMD.js has been taken out of active development in TC39 and removed from Stage 3. It is not being pursued by web browsers for implementation anymore. SIMD operations exposed to the web are under active development within WebAssembly, with operations based on the SIMD.js operations.

The SIMD.Float32x4 data type is a 128-bit vector divided into 4 lanes storing single precision floating point values.

SIMD.Float32x4

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
A double specifying the value of the first lane. Defaults to NaN.
y Optional
A double specifying the value of the second lane. Defaults to NaN.
z Optional
A double specifying the value of the third lane. Defaults to NaN.
w Optional
A double specifying the value of the fourth lane. Defaults to 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.

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

SIMD.Float32x4.check()
Returns a new Float32x4 if the parameter is a valid Float32x4 data type. Throws a TypeError otherwise.

Accessing and mutating lanes

SIMD.Float32x4.extractLane()
Returns the value of the given lane.
SIMD.Float32x4.replaceLane()
Returns a new Float32x4 with the given lane value replaced.

Loading from and storing into typed arrays

SIMD.Float32x4.load()
SIMD.Float32x4.load1()
SIMD.Float32x4.load2()
SIMD.Float32x4.load3()
Returns a new Float32x4 with the lane values loaded from a typed array.
SIMD.Float32x4.store()
SIMD.Float32x4.store1()
SIMD.Float32x4.store2()
SIMD.Float32x4.store3()
Stores an Float32x4 into a typed array.

Arithmetic operations

SIMD.Float32x4.abs()
Returns a new Float32x4 with the absolute lane values.
SIMD.Float32x4.add()
Returns a new Float32x4 with the lane values added (a + b).
SIMD.Float32x4.div()
Returns a new Float32x4 with the lane values divided (a / b).
SIMD.Float32x4.mul()
Returns a new Float32x4 with the lane values multiplied (a * b).
SIMD.Float32x4.neg()
Returns a new Float32x4 with the negated lane values.
SIMD.Float32x4.reciprocalApproximation()
Returns a new Float32x4 with an approximation of the reciprocal lane values.
SIMD.Float32x4.reciprocalSqrtApproximation()
Returns a new Float32x4 with an approximation of the reciprocal square root lane values.
SIMD.Float32x4.sub()
Returns a new Float32x4 with the lane values subtracted (a - b).
SIMD.Float32x4.sqrt()
Returns a new Float32x4 with the square root of the lane values.

Shuffling and swizzling

SIMD.Float32x4.shuffle()
Returns a new Float32x4 with the lane values shuffled.
SIMD.Float32x4.swizzle()
Returns a new Float32x4 with the lane values swizzled.

Min and max values

SIMD.Float32x4.max()
Returns a new Float32x4 with the maximum of the lane values.
SIMD.Float32x4.maxNum()
Returns a new Float32x4 with the maximum of the lane values, preferring numbers over NaN.
SIMD.Float32x4.min()
Returns a new Float32x4 with the minimum of the lane values.
SIMD.Float32x4.minNum()
Returns a new Float32x4 with the minimum of the lane values, preferring numbers over NaN.

Selections

SIMD.Float32x4.select()
Returns a new Float32x4 with the lane values being a mix of the lanes depending on the selector mask.

Comparisons

SIMD.Float32x4.equal()
Returns a selection mask depending on a == b.
SIMD.Float32x4.notEqual()
Returns a selection mask depending on a != b.
SIMD.Float32x4.lessThan()
Returns a selection mask depending on a < b.
SIMD.Float32x4.lessThanOrEqual()
Returns a selection mask depending on a <= b.
SIMD.Float32x4.greaterThan()
Returns a selection mask depending on a > b.
SIMD.Float32x4.greaterThanOrEqual()
Returns a selection mask depending on a >= b.

Data conversions

SIMD.Float32x4.fromFloat64x2Bits()
Creates a new Float32x4 data type with a bit-wise copy from a Float64x2.
SIMD.Float32x4.fromInt32x4()
Creates a new Float32x4 data type with a Float conversion from an Int32x4.
SIMD.Float32x4.fromInt32x4Bits()
Creates a new Float32x4 data type with a bit-wise copy from an Int32x4.
SIMD.Float32x4.fromInt16x8Bits()
Creates a new Float32x4 data type with a bit-wise copy from an Int16x8.
SIMD.Float32x4.fromInt8x16Bits()
Creates a new Float32x4 data type with a bit-wise copy from an Int8x16.
SIMD.Float32x4.fromUint32x4()
Creates a new Float32x4 data type with a Float conversion from a Uint32x4.
SIMD.Float32x4.fromUint32x4Bits()
Creates a new Float32x4 data type with a bit-wise copy from a Uint32x4.
SIMD.Float32x4.fromUint16x8Bits()
Creates a new Float32x4 data type with a bit-wise copy from a Uint16x8.
SIMD.Float32x4.fromUint8x16Bits()
Creates a new Float32x4 data type with a bit-wise copy from a Uint8x16.

SIMD prototype

The following methods and properties are installed on the SIMD.Float32x4.prototype.

SIMD.Float32x4.prototype.constructor
Specifies the function that creates a SIMD object's prototype.
SIMD.Float32x4.prototype.toLocaleString()
Returns a localized string representing the SIMD type and its elements. Overrides the Object.prototype.toLocaleString() method.
SIMD.Float32x4.prototype.toString()
Returns a string representing the SIMD type and its elements. Overrides the Object.prototype.toString() method.
SIMD.Float32x4.prototype.valueOf()
Returns the primitive value of a SIMD object.
SIMD.Float32x4.prototype.toSource()
Returns a string representing the source code of the object. Overrides the Object.prototype.toSource() method.

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
SIMD
The definition of 'Float32x4' in that specification.
Obsolete Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support No support Nightly build Nightly build No support No support No support
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support No support Nightly build Nightly build No support No support No support

See also

Document Tags and Contributors

 Contributors to this page: fscholz, jameshkramer, nmve
 Last updated by: fscholz,