SIMD.Float32x4

공헌자 숫자: 1명
아직 자원 봉사자들이 한국어로 현재 문서를 번역하지 않았습니다. 가입해서 이 문서가 번역되는 일에 함께 해 주세요!

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 SIMD.Float32x4 data type is a 128-bit vector divided into 4 lanes storing single precision floating point values.

SIMD.Float32x4

Figure 1: SIMD.Float32x4 in a 128-bit SIMD register.

Syntax

SIMD.Float32x4(x, y, z, w);

Parameters

The input values are specified in double precision floating and are converted to single precision floating point values before being stored.

x Optional
An double specifying the value of the first lane. Defaults to NaN.
y Optional
An double specifying the value of the second lane. Defaults to NaN.
z Optional
An double specifying the value of the third lane. Defaults to NaN.
w Optional
An double specifying the value of the fourth lane. Defaults to NaN.

Constructor functions

In addition to the simple creator functions, the SIMD API provides the following constructor function. Note that you can also convert from another SIMD data type to Float32x4.

SIMD.Float32x4.splat()
Creates an Float32x4 with all lanes set to a given value.

Note: SIMD types don't work with new, as SIMD values are no "boxed" objects (comparable to String(s) vs. new String(s), which creates a String object).

var v = new SIMD.Float32x4(0,1,2,3); 
// TypeError: SIMD.Float32x4 is not a constructor

Instead, you just write:

var v = SIMD.Float32x4(0,1,2,3);

Operations

To actually do something with SIMD types, SIMD operations are needed that work on SIMD data types.

Checking SIMD types

SIMD.Float32x4.check()
Returns a new Float32x4 if the parameter is a valid Float32x4 data type. Throws a TypeError otherwise.

Accessing and mutating lanes

SIMD.Float32x4.extractLane()
Returns the value of the given lane.
SIMD.Float32x4.replaceLane()
Returns a new Float32x4 with the given lane value replaced.

Loading from and storing into typed arrays

SIMD.Float32x4.load()
Returns a new Float32x4 with the lane values loaded from a typed array.
SIMD.Float32x4.store()
Stores an Float32x4 into a typed array.

Arithmetic operations

SIMD.Float32x4.abs()
Returns a new Float32x4 with the absolute lane values.
SIMD.Float32x4.add()
Returns a new Float32x4 with the lane values added (a + b).
SIMD.Float32x4.div()
Returns a new Float32x4 with the lane values divided (a / b).
SIMD.Float32x4.mul()
Returns a new Float32x4 with the lane values multiplied (a * b).
SIMD.Float32x4.neg()
Returns a new Float32x4 with the negated lane values.
SIMD.Float32x4.reciprocalApproximation()
Returns a new Float32x4 with an approximation of the reciprocal lane values.
SIMD.Float32x4.reciprocalSqrtApproximation()
Returns a new Float32x4 with an approximation of the reciprocal square root lane values.
SIMD.Float32x4.sub()
Returns a new Float32x4 with the lane values subtracted (a - b).
SIMD.Float32x4.sqrt()
Returns a new Float32x4 with the square root of the lane values.

Shuffling and swizzling

SIMD.Float32x4.shuffle()
Returns a new Float32x4 with the lane values shuffled.
SIMD.Float32x4.swizzle()
Returns a new Float32x4 with the lane values swizzled.

Min and max values

SIMD.Float32x4.max()
Returns a new Float32x4 with the maximum of the lane values.
SIMD.Float32x4.maxNum()
Returns a new Float32x4 with the maximum of the lane values, preferring numbers over NaN.
SIMD.Float32x4.min()
Returns a new Float32x4 with the minimum of the lane values.
SIMD.Float32x4.minNum()
Returns a new Float32x4 with the minimum of the lane values, preferring numbers over NaN.

Selections

SIMD.Float32x4.select()
Returns a new Float32x4 with the lane values being a mix of the lanes depending on the selector mask.

Comparisons

SIMD.Float32x4.equal()
Returns a selection mask depending on a == b.
SIMD.Float32x4.notEqual()
Returns a selection mask depending on a != b.
SIMD.Float32x4.lessThan()
Returns a selection mask depending on a < b.
SIMD.Float32x4.lessThanOrEqual()
Returns a selection mask depending on a <= b.
SIMD.Float32x4.greaterThan()
Returns a selection mask depending on a > b.
SIMD.Float32x4.greaterThanOrEqual()
Returns a selection mask depending on a >= b.

Bitwise logical operations

SIMD.Float32x4.and()
Returns a new Float32x4 with the logical AND of the lane values (a & b).
SIMD.Float32x4.or()
Returns a new Float32x4 with the logical OR of the lane values (a | b).
SIMD.Float32x4.xor()
Returns a new Float32x4 with the logical XOR of the lane values (a ^ b).
SIMD.Float32x4.not()
Returns a new Float32x4 with lane with the logical NOT of the lane values (~a).

Data conversions

SIMD.Float32x4.fromInt32x4()
Creates a new Float32x4 data type with a Float conversion from an Int32x4.
SIMD.Float32x4.fromInt32x4Bits()
Creates a new Float32x4 data type with a bit-wise copy from an Int32x4.
SIMD.Float32x4.fromFloat64x2()
Creates a new Float32x4 data type with a Float conversion from a Float64x2.
SIMD.Float32x4.fromFloat64x2Bits()
Creates a new Float32x4 data type with a bit-wise copy from a Float64x2.
SIMD.Float32x4.fromInt16x8Bits()
Creates a new Float32x4 data type with a bit-wise copy from an Int16x8.
SIMD.Float32x4.fromInt8x16Bits()
Creates a new Float32x4 data type with a bit-wise copy from an Int8x16.

Examples

SIMD.Float32x4(1, 2, 3, 4); // Float32x4[1, 2, 3, 4]
SIMD.Float32x4(1, 2);       // Float32x4[1, 2, NaN, NaN]
SIMD.Float32x4();           // Float32x4[NaN, NaN, NaN, NaN]

Specifications

Specification Status Comment
SIMD
The definition of 'Float32x4' 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

문서 태그 및 공헌자

Contributors to this page: fscholz
최종 변경: fscholz,
사이드바 숨기기