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%.select()
method creates a new integer SIMD data type with the lane values being a selection match from a selector mask.
SIMD.Float32x4.select(mask, trueValue, falseValue) SIMD.Float64x2.select(mask, trueValue, falseValue) SIMD.Int8x16.select(mask, trueValue, falseValue) SIMD.Int16x8.select(mask, trueValue, falseValue) SIMD.Int32x4.select(mask, trueValue, falseValue) SIMD.Uint8x16.select(mask, trueValue, falseValue) SIMD.Uint16x8.select(mask, trueValue, falseValue) SIMD.Uint32x4.select(mask, trueValue, falseValue)
int32x4
, int16x8
or int8x16
that is used as the selector mask.trueValue
true
, pick the corresponding lane value from here.falseValue
false
, pick the corresponding lane value from here.A new SIMD data type.
The SIMD.%type%.select()
method selects lanes from a selection mask. Masking (or "branching") lanes is useful as you can't operate on a fraction of data in SIMD data types. However, with masks and the select
function, you can branch and merge vectors to assemble the result vector you need.
This example uses the SIMD.Bool32x4
type to create a custom selection mask. With this mask, you are able to select the first and the last lane from the first Float32x4
data type. Thus, the select
function selects the first and last lane from vector a
and the second and third lane from vector b
(or the sum
vector in the second select
).
var a = SIMD.Float32x4(1, 2, 3, 4); var b = SIMD.Float32x4(5, 6, 7, 8); var mask = SIMD.Bool32x4(true, false, false, true); SIMD.Float32x4.select(mask, a, b); // Float32x4[1, 6, 7, 4] var sum = SIMD.Float32x4.add(a, b); SIMD.Float32x4.select(mask, a, sum); // Float32x4[1, 8, 10, 4]
All SIMD comparison operations return a selection mask from which you have to select to actually get the result of the comparison:
var a = SIMD.Float32x4(0, 12, 3, 4); var b = SIMD.Float32x4(0, 6, 7, 50); var mask = SIMD.Float32x4.lessThan(a, b); // Bool32x4[false, false, true, true] var result = SIMD.Float32x4.select(mask, a, b); // Float32x4[0, 6, 3, 4]
Specification | Status | Comment |
---|---|---|
SIMD The definition of 'SIMDConstructor.select' in that specification. | Draft | Initial definition. |
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 |
© 2005–2017 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/select