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

SIMD.%type%.bool()

by 1 contributor:

In the latest specification draft, the bool() method is replaced by SIMD Boolean types. Current implementations (e.g. Firefox Nightly) will be updated soon.

The static SIMD.%type%.bool() method creates a new integer SIMD data type with -1 as a lane value where the Boolean parameter is true and 0x0 where the Boolean parameter is false. This allows you to create an explicit selection mask, for example.

Syntax

SIMD.Int8x16.bool(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15)
SIMD.Int16x8.bool(s0,s1,s2,s3,s4,s5,s6,s7,s8)
SIMD.Int32x4.bool(s0,s1,s2,s3,s4)

Parameters

s[0-15] Optional
Boolean flag for each lane. Defaults to false.

Description

The SIMD.%type%.bool() constructor is used to create a custom selection mask. Masking (or "branching") the 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 particular 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 example).

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]

You can imagine the selection visually like this:

Selection mask logic

Specifications

SIMD is not yet part of an official standards document or draft. In the latest specification draft, the bool() method is replaced by SIMD Boolean type. Current implementations (e.g. Firefox Nightly) will be updated soon and this method will be removed.

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