User:Evilpie/Simd
= SIMD API
"Single instruction, multiple data"
The goal of this is API to enable easier optimizations of JavaScript code that needs to work on TypedArrays repeatedly with the same operation. For example adding or subtracting the contents of two arrays.
This API is currently in the drafting phase, but the main idea is to have different instruction two work on arbitrary sized slices of two arrays. Previous work include for example Mono's SIMD support or Microsoft's .net Vector methods.
The SIMD API is going to expose one new global to the JavaScript environment, called "Simd". This plain object with the Class "Simd", has the following "static method". (These are methods directly defined on the object)
1. Simd.add(arrayA, indexA, arrayB, indexB, count)
1. If not arrayA is an object, throw TypeError 2. Let indexA be ToUint32(indexA) 3. If not arrayB is an object, throw TypeError 4. Let indexB be ToUint32(indexB) 4. Let count be ToUint32(count) 5. Throw TypeError, if arrayA is not a TypeArray (the class is either Float32Array, Float64 etc.) 6. Throw TypeError, if the internal property Class of arrayA is different from internal property Class of arrayB 7. Throw RangeError if indexA + count is larger than the length of the arrayA 8. Throw RangeError if indexB + count is larger than the length of the arrayB 9. Let k be 0 10. Repeat, while k < count a. Let a be arrayA[indexA + k] b. Let b be arrayB[indexB + k] c. Assign a + b to arrayA[indexA + k] c. Increment k by one
Example
var a = new Float64Array(2); var b = new Float64Array(2); a[0] = 0; b[0] = 2; a[1] = 1 b[1] = 2; Simd.add(a, b, 0, 0, 2);
Now a[0] and [1] should be 2, b should not have changed.