我们的志愿者还没有将这篇文章翻译为 中文 (简体)。加入我们帮助完成翻译!
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%.load()
methods create a new SIMD data type with the lane values loaded from a typed array.
Syntax
SIMD.Float64x2.load(tarray, index) SIMD.Float64x2.load1(tarray, index) SIMD.Float32x4.load(tarray, index) SIMD.Float32x4.load1(tarray, index) SIMD.Float32x4.load2(tarray, index) SIMD.Float32x4.load3(tarray, index) SIMD.Int32x4.load(tarray, index) SIMD.Int32x4.load1(tarray, index) SIMD.Int32x4.load2(tarray, index) SIMD.Int32x4.load3(tarray, index) SIMD.Uint32x4.load(tarray, index) SIMD.Uint32x4.load1(tarray, index) SIMD.Uint32x4.load2(tarray, index) SIMD.Uint32x4.load3(tarray, index) SIMD.Int8x16.load(tarray, index) SIMD.Int16x8.load(tarray, index) SIMD.Uint8x16.load(tarray, index) SIMD.Uint16x8.load(tarray, index)
Parameters
tarray
- An instance of a typed array. This can be one of:
index
- A number for the index from where to start loading in the typed array.
Return value
A new SIMD data type.
Exceptions
- If
index
is out of range, for exampleSIMD.Int32x4.load(tarray, -1)
or bigger than the size oftarray
, aRangeError
is thrown. - If
tarray
is not one of the typed array types, for exampleSIMD.Int32x4.load(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 load all lane values using load()
, or only load one, two or three lane values with the methods load1()
, load2()
or load3()
.
Examples
The following examples use an Int32Array
loaded into a SIMD.Int32x4
data type.
Loading all values
var a = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load(a, 0); // Int32x4[1,2,3,4] var b = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load(a, 2); // Int32x4[3,4,5,6]
Loading a single value
var a = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load1(a, 0); // Int32x4[1,0,0,0] var b = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load1(a, 2); // Int32x4[3,0,0,0]
Loading two values
var a = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load2(a, 0); // Int32x4[1,2,0,0] var b = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load2(a, 2); // Int32x4[3,4,0,0]
Loading three values
var a = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load3(a, 0); // Int32x4[1,2,3,0] var b = new Int32Array([1,2,3,4,5,6,7,8]); SIMD.Int32x4.load3(a, 2); // Int32x4[3,4,5,0]
Specifications
Specification | Status | Comment |
---|---|---|
SIMD The definition of 'SIMDConstructor.load' 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 |