SIMD.%type%.shiftRightByScalar()

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.

The static SIMD.%type%.shiftRightByScalar() method returns a new instance with the lane values shifted right. Depending on the type, these operations are used:

  • For signed integers, values are shifted arithmetic by a given bit count (a >> bits, signed right shift operator).
  • For unsigned integers, values are shifted logical by a given bit count (a >>> bits, unsigned right shift operator).

Syntax

SIMD.Int8x16.shiftRightByScalar(a, bits)
SIMD.Int16x8.shiftRightByScalar(a, bits)
SIMD.Int32x4.shiftRightByScalar(a, bits)

SIMD.Uint8x16.shiftRightByScalar(a, bits)
SIMD.Uint16x8.shiftRightByScalar(a, bits) 
SIMD.Uint32x4.shiftRightByScalar(a, bits)

Parameters

a
An instance of a SIMD type.
bits
Bit count to shift by.

Return value

A new corresponding SIMD data type with the lane values shifted right by a given bit count.

Description

Signed shift

The bitwise arithmetic right shift operation shifts the specified number of bits to the right. Excess bits shifted off to the right are discarded. Copies of the leftmost bit are shifted in from the left. Since the new leftmost bit has the same value as the previous leftmost bit, the sign bit (the leftmost bit) does not change. Hence the name "sign-propagating" or "arithmetic".

For non-negative numbers, the arithmetic right shift and the logical right shift yield the same result.

For example, a bitwise right arithmetic shift of 5 >> 1 results in 0010 which is 2 in decimal.

5 0101
  ----
2 0010

Unsigned shift

The bitwise logical right shift operation shifts the specified number of bits to the right. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left. The sign bit becomes 0, so the result is always non-negative.

For non-negative numbers, the arithmetic right shift and the logical right shift yield the same result.

For example, a bitwise right logical shift of -8 >>> 1 results in 01111111111111111111111111111100 which is 2147483644 in decimal.

-8            11111111111111111111111111111000
              --------------------------------
2147483644    01111111111111111111111111111100

Examples

Bitwise right arithmetic shift of an Int32x4

var a = SIMD.Int32x4(1, 2, 4, -8);
SIMD.Int32x4.shiftRightByScalar(a, 1);
// Int32x4[0, 1, 2, -4]

Bitwise right logical shift of a Uint32x4

var a = SIMD.Uint32x4(1, 2, 4, -8);
SIMD.Uint32x4.shiftRightByScalar(a, 1);
// Uint32x4[0, 1, 2, 2147483644]

Specifications

Specification Status Comment
SIMD
The definition of 'SIMDConstructor.shiftRightByScalar' in that specification.
Obsolete Initial definition.

Browser compatibility

Experimental SIMD.js has been removed from browsers. It's still available in Firefox Nightly, but will be removed in favor of a SIMD implementation in WebAssembly. See also bug 1416723.

See also

Document Tags and Contributors

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