This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The static SIMD.%type%.store()
methods store a SIMD data type into a typed array.
Syntax
SIMD.Float32x4.store(tarray, index, value) SIMD.Float32x4.store1(tarray, index, value) SIMD.Float32x4.store2(tarray, index, value) SIMD.Float32x4.store3(tarray, index, value) SIMD.Float64x2.store(tarray, index, value) SIMD.Float64x2.store1(tarray, index, value) SIMD.Int32x4.store(tarray, index, value) SIMD.Int32x4.store1(tarray, index, value) SIMD.Int32x4.store2(tarray, index, value) SIMD.Int32x4.store3(tarray, index, value) SIMD.Int8x16.store(tarray, index, value) SIMD.Int16x8.store(tarray, index, value) SIMD.Uint32x4.store(tarray, index, value) SIMD.Uint32x4.store1(tarray, index, value) SIMD.Uint32x4.store2(tarray, index, value) SIMD.Uint32x4.store3(tarray, index, value) SIMD.Uint8x16.store(tarray, index, value) SIMD.Uint16x8.store(tarray, index, value)
Parameters
tarray
- An instance of a typed array. This can be one of:
index
- A number for the index from where to start storing in the typed array.
value
- An instance of a SIMD data type to store into the typed array.
Return value
The value
that has been stored (a SIMD data type).
Exceptions
- If
index
is out of range, for exampleSIMD.Int32x4.store(tarray, -1, value)
or bigger than the size oftarray
, aRangeError
is thrown. - If
tarray
is not one of the typed array types, for exampleSIMD.Int32x4.store(tarray.buffer, 0)
(an array buffer is not valid), aTypeError
is thrown.
Description
The SIMD load
and store
methods intermix with typed arrays. With load
, you can pass in typed arrays into SIMD types and with store,
SIMD data can be stored into typed arrays.
You can either store all lane values using store()
, or only store one, two or three lane values with the methods store1()
, store2()
or store3()
.
Examples
The following examples use SIMD.Int32x4
data type stored into an Int32Array
.
Storing all values
var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store(tarray, 0, value); // tarray = Int32Array[1, 2, 3, 4, 0, 0, 0, 0] var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store(tarray, 2, value); // tarray = Int32Array[0, 0, 1, 2, 3, 4, 0, 0]
Storing one value
var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store1(tarray, 0, value); // tarray = Int32Array[1, 0, 0, 0, 0, 0, 0, 0] var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store1(tarray, 2, value); // tarray = Int32Array[0, 0, 1, 0, 0, 0, 0, 0]
Storing two values
var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store2(tarray, 0, value); // tarray = Int32Array[1, 2, 0, 0, 0, 0, 0, 0] var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store2(tarray, 2, value); // tarray = Int32Array[0, 0, 1, 2, 0, 0, 0, 0]
Storing three values
var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store3(tarray, 0, value); // tarray = Int32Array[1, 2, 3, 0, 0, 0, 0, 0] var tarray = new Int32Array(8); var value = SIMD.Int32x4(1, 2, 3, 4); SIMD.Int32x4.store3(tarray, 2, value); // tarray = Int32Array[0, 0, 1, 2, 3, 0, 0, 0]
Specifications
Specification | Status | Comment |
---|---|---|
SIMD The definition of 'SIMDConstructor.store' in that specification. |
Draft | Initial definition. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | No support | Nightly build | No support | No support | No support |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | Nightly build | No support | No support | No support |