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.
SIMD (pronounced "sim-dee") is short for Single Instruction/Multiple Data which is one classification of computer architectures. SIMD operations perform the same computation on multiple data points resulting in data level parallelism and thus performance gains, for example for 3D graphics and video processing, physics simulations or cryptography, and other domains.
This page and sub pages are the SIMD API reference documentation. See also SIMD types for an article that describes SIMD in JavaScript more generally.
The JavaScript SIMD API consists of several new types and operations. Browsers provide highly optimized implementations of this API depending on the underlying hardware of the user. Currently, SIMD is especially modeled for ARMv7 platforms with NEON and x86 platforms with SSE.
The SIMD API types are installed on a SIMD
module. Unlike the other global objects, SIMD
is not a constructor. You can not use it with a new
operator or invoke the SIMD
object as a function. All properties and methods of SIMD
are static (as is the case with the Math
object).
A SIMD value has multiple lanes. For a vector of length 4, the lanes are named x
, y
, z
, and w
. Now, instead of having to perform 4 separate operations on each of these lanes, SIMD allows you to perform the operation on all 4 lanes simultaneously. This requires fewer operations, which leads to performance improvements and better energy efficiency compared to scalar operations (SISD). Note that SIMD operations cannot be used to process multiple data in different ways. In the following figure, there is only a single instruction (addition) and thus it could be operated with SIMD:
Figures 1 and 2: SISD and SIMD compared.
The JavaScript code for a simple SIMD operation like in figure 2 looks like this:
var a = SIMD.Float32x4(1, 2, 3, 4); var b = SIMD.Float32x4(5, 6, 7, 8); var c = SIMD.Float32x4.add(a,b); // Float32x4[6,8,10,12]
All SIMD data types are immutable. You can not alter them directly. Instead, you perform operations that create new immutable SIMD data types.
The following figure shows the different SIMD data types in a 128-bit SIMD register. The current SIMD JavaScript API has 12 different types with lane lengths of either 2, 4, 8 or 16.
Figure 3: Lanes per type in a 128-bit SIMD register.
SIMD.Bool8x16
SIMD.Bool16x8
SIMD.Bool32x4
SIMD.Bool64x2
SIMD.Int8x16
SIMD.Int16x8
SIMD.Int32x4
SIMD.Uint8x16
SIMD.Uint16x8
SIMD.Uint32x4
SIMD.Float32x4
SIMD.Float64x2
In addition to the simple creator functions (e.g. SIMD.Int32x4(1,2,3,4)
), the SIMD API provides the following constructor functions:
SIMD.%type%.splat()
You can also convert from one SIMD data type to another.
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
Instead, you just write:
var v = SIMD.Float32x4(0,1,2,3);
To actually do something with SIMD types, SIMD operations are needed that work on SIMD data types.
Note: Not all SIMD operations are available on all SIMD types, see the individual reference pages for details and availability.
SIMD.%type%.check()
%type%
. Throws a TypeError
otherwise.SIMD.%type%.extractLane()
SIMD.%type%.replaceLane()
SIMD.%type%.load()
SIMD.%type%.load1()
SIMD.%type%.load2()
SIMD.%type%.load3()
SIMD.%type%.store()
SIMD.%type%.store1()
SIMD.%type%.store2()
SIMD.%type%.store3()
SIMD.%FloatType%.abs()
SIMD.%type%.add()
a + b
).SIMD.%type%.addSaturate()
a + b
) and saturating behavior on overflow.SIMD.%FloatType%.div()
a / b
).SIMD.%type%.mul()
a * b
).SIMD.%type%.neg()
SIMD.%FloatType%.reciprocalApproximation()
SIMD.%FloatType%.reciprocalSqrtApproximation()
SIMD.%type%.sub()
a - b
).SIMD.%type%.subSaturate()
a - b
) and saturating behavior on overflow.SIMD.%FloatType%.sqrt()
SIMD.%type%.shuffle()
SIMD.%type%.swizzle()
SIMD.%FloatType%.max()
SIMD.%FloatType%.maxNum()
NaN
.SIMD.%FloatType%.min()
SIMD.%FloatType%.minNum()
NaN
.SIMD.%type%.select()
SIMD.%type%.equal()
a == b
.SIMD.%type%.notEqual()
a != b
.SIMD.%type%.lessThan()
a < b
.SIMD.%type%.lessThanOrEqual()
a <= b
.SIMD.%type%.greaterThan()
a > b
.SIMD.%type%.greaterThanOrEqual()
a >= b
.SIMD.%type%.and()
a & b
).SIMD.%type%.or()
a | b
).SIMD.%type%.xor()
a ^ b
).SIMD.%type%.not()
~a
).SIMD.%IntegerType%.shiftLeftByScalar()
a << bits
).SIMD.%IntegerType%.shiftRightByScalar()
SIMD.%BooleanType%.allTrue()
true
value.SIMD.%BooleanType%.anyTrue()
true
value.SIMD.%type%.fromFloat32x4()
SIMD.%type%.fromFloat32x4Bits()
SIMD.%type%.fromFloat64x2Bits()
SIMD.%type%.fromInt32x4()
SIMD.%type%.fromInt32x4Bits()
SIMD.%type%.fromInt16x8Bits()
SIMD.%type%.fromInt8x16Bits()
SIMD.%type%.fromUint32x4()
SIMD.%type%.fromUint32x4Bits()
SIMD.%type%.fromUint16x8Bits()
SIMD.%type%.fromUint8x16Bits()
The following methods and properties are installed on the SIMD.%type%.prototype
.
SIMD.%type%.prototype.constructor
SIMD.%type%.prototype.toLocaleString()
Object.prototype.toLocaleString()
method.SIMD.%type%.prototype.toString()
Object.prototype.toString()
method.SIMD.%type%.prototype.valueOf()
SIMD.%type%.prototype.toSource()
Object.prototype.toSource()
method.A Polyfill implementation based on typed arrays, is available at the ecmascript_simd GitHub repository.
Specification | Status | Comment |
---|---|---|
SIMD The definition of 'SIMD' in that specification. | Obsolete | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Float32x4 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Float64x2 | No support | Nightly build | No support | No support | No support | No support |
SIMD.Int8x16 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Int16x8 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Int32x4 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Uint8x16 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Uint16x8 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Uint32x4 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool8x16 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool16x8 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool32x4 | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool64x2 | No support | Nightly build | No support | No support | No support | No support |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | Edge | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Float32x4 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Float64x2 | No support | No support | Nightly build | No support | No support | No support | No support |
SIMD.Int8x16 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Int16x8 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Int32x4 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Uint8x16 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Uint16x8 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Uint32x4 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool8x16 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool16x8 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool32x4 | No support | No support | Nightly build | Nightly build | No support | No support | No support |
SIMD.Bool64x2 | No support | No support | Nightly build | No support | No support | No support | No support |
© 2005–2018 Mozilla Developer Network and individual 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