Changes

Jump to: navigation, search

SIMD/Operations

1,358 bytes added, 16:59, 2 May 2014
Load and Store
== Load and Store ==
 
To assemble vectors of data that subsequently can be operated upon, SIMD instruction sets include loading instructions, that copy data values from consecutive memory locations into SIMD registers. After completing computation, the contents of SIMD registers can be copied to memory locations using store instructions.
 
In JavaScript, these instructions need to be exposed to programmers in a convenient way to instantiate SIMD data types, such as, e.g., [[SIMD/Types/uint16x8 |uint16x8]]. This can, for instance happen by having a constructor that accepts 8 numeric values (and applying clamping etc. as needed):
 
var myUint16x8 = new uint16x8(1, 2, 3, 4, 5, 6, 8);
 
This has the distinct disadvantage of being slow, as each data value need to be converted to the corresponding scalar data type and written into memory to be accessible for the SIMD load instruction.
 
A more efficient approach may be to load data values from a fittingly typed [https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView], which is backed by a memory region containing data values in a linear fashion, as desired by the SIMD load/store instructions:
 
// myUint16Array is an ArrayBufferView of type Uint16Array
var myUint16x8 = new uint16x8(myUint16Array, 2);
 
This loads eight uint16 values from myUint16Array into myUint16x8, starting at offset 2.
== Arithmetic operations ==
51
edits

Navigation menu