Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

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.Int32x4 data type is a 128-bit vector divided into 4 lanes storing 32-bit signed integer values.

SIMD.Int32x4

Figure 1: SIMD.Int32x4 in a 128-bit SIMD register.

Syntax

SIMD.Int32x4(x, y, z, w);

Parameters

x Optional
An integer specifying the value of the first lane. Defaults to 0.
y Optional
An integer specifying the value of the second lane. Defaults to 0.
z Optional
An integer specifying the value of the third lane. Defaults to 0.
w Optional
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.

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

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

Accessing and mutating lanes

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

Loading from and storing into typed arrays

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

Arithmetic operations

SIMD.Int32x4.add()
Returns a new Int32x4 with the lane values added (a + b).
SIMD.Int32x4.mul()
Returns a new Int32x4 with the lane values multiplied (a * b).
SIMD.Int32x4.neg()
Returns a new Int32x4 with the negated lane values.
SIMD.Int32x4.sub()
Returns a new Int32x4 with the lane values subtracted (a - b).

Shuffling and swizzling

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

Selections

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

Comparisons

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

Bitwise logical operations

SIMD.Int32x4.and()
Returns a new Int32x4 with the logical AND of the lane values (a & b).
SIMD.Int32x4.or()
Returns a new Int32x4 with the logical OR of the lane values (a | b).
SIMD.Int32x4.xor()
Returns a new Int32x4 with the logical XOR of the lane values (a ^ b).
SIMD.Int32x4.not()
Returns a new Int32x4 with lane with the logical NOT of the lane values (~a).

Bitwise shift operations

SIMD.Int32x4.shiftLeftByScalar()
Returns a new Int32x4 with the lane values shifted left by a given bit count (a << bits).
SIMD.Int32x4.shiftRightByScalar()
Returns a new Int32x4 with the lane values shifted right.

Data conversions

SIMD.Int32x4.fromFloat32x4()
Creates a new Int32x4 data type with a float conversion from a float32x4.
SIMD.Int32x4.fromFloat32x4Bits()
Creates a new Int32x4 data type with a bit-wise copy from a float32x4.
SIMD.Int32x4.fromFloat64x2Bits()
Creates a new Int32x4 data type with a bit-wise copy from a float64x2.
SIMD.Int32x4.fromInt16x8Bits()
Creates a new Int32x4 data type with a bit-wise copy from an Int16x8.
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.
SIMD.Int32x4.prototype.toLocaleString()
Returns a localized string representing the SIMD type and its elements. Overrides the Object.prototype.toLocaleString() method.
SIMD.Int32x4.prototype.toString()
Returns a string representing the SIMD type and its elements. Overrides the Object.prototype.toString() method.
SIMD.Int32x4.prototype.valueOf()
Returns the primitive value of a SIMD object.
SIMD.Int32x4.prototype.toSource()
Returns a string representing the source code of the object. Overrides the 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
SIMD
The definition of 'Int32x4' in that specification.
Draft 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

Schlagwörter des Dokuments und Mitwirkende

Schlagwörter: 
 Mitwirkende an dieser Seite: fscholz, jameshkramer, nmve
 Zuletzt aktualisiert von: fscholz,