Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

SIMD.%type%.shiftRightByScalar()

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

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%.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.
Draft Initial definition.

Browser compatibility

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

See also

ドキュメントのタグと貢献者

 このページの貢献者: fscholz
 最終更新者: fscholz,