SIMD.%type%.load()

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

JavaScript
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 example SIMD.Int32x4.load(tarray, -1) or bigger than the size of tarray, a RangeError is thrown.
  • If tarray is not one of the typed array types, for example SIMD.Int32x4.load(tarray.buffer, 0) (an array buffer is not valid), a TypeError 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

JavaScript
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

JavaScript
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

JavaScript
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

JavaScript
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

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/simd/load

Experimental JavaScript Method SIMD