★ wanayoo — archive 1999 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SIMD/selectNouvelle recherche | Portail wanayoo

SIMD.%type%.select()

by 1 contributor:

This is an experimental technology, part of the ECMAScript 2016 (ES7) proposal.
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 version of browsers as the spec 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.

Syntax

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.Bool8x16.select(mask, trueValue, falseValue)
SIMD.Bool16x8.select(mask, trueValue, falseValue)
SIMD.Bool32x4.select(mask, trueValue, falseValue) 

Parameters

mask
An int32x4, int16x8 or int8x16 that is used as the selector mask.
trueValue
If the selector mask lane is true, pick the corresponding lane value from here.
falseValue
If the selector mask lane is false, pick the corresponding lane value from here.

Description

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.

Examples

Custom selection mask

This example uses the Int32x4.bool() function 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.Int32x4.bool(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]

Operations returning a selection mask

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);
// Int32x4[0, 0, -1, -1]

var result = SIMD.Float32x4.select(mask, a, b);
// Float32x4[0, 6, 3, 4]

Specifications

Specification Status Comment
SIMD
The definition of 'SIMDConstructor.select' in that specification.
Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support Not supported Nightly build Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported Not supported Nightly build Not supported Not supported Not supported

See also

Document Tags and Contributors

Contributors to this page: fscholz
Last updated by: fscholz,
Hide Sidebar