Open ghost opened 8 years ago
Hi acterhd,
Thank you for your interest in using the SIMD operations.
The SIMD operations are added to make it possible to extract performance from architectures that support SIMD instructions. So the set of operations have been carefully selected to match the typical operations that are available in modern CPUs. The load and store operations are designed to map to the instructions that will load and store individual 128-bit SIMD values and will therefore need to know the memory layout of the data to be loaded or stored. For typed arrays this layout is known, but for regular JS arrays it is not. That's why we only support typed arrays for these operations. If you know that all elements in your array are Numbers you could potentially move the data from the regular array into a typed array, like this:
var ta = new Float32Array(your_regular_array)
As for the missing 'mod' operator. The 'mod' operator only makes sense for integers, and today's CPUs doesn't support a SIMD mod instruction on integer vectors. We've intentionally only included the minimal set of operations that would enable use of SIMD capabilities in modern CPUs. Higher level operations, like integer mod and div operations, can be built using these low level operations. In the case of mod, you would need to first convert to floating point, use the FP 'div' operation, convert back to integers, and do multiplication and subtraction to get the modulus. Be aware of complications with negative values though.
Are you trying to use SIMD for the .map operations in your utils functions?
I want replace map operations to SIMD. In theory possible any size of array, but in practice count of elements three and no more (in my use case). Would be good optimize for SIMD. Also would be good AVX2 SIMD's. Intel Skylake and Nvidia Pascal have support for 64-bit float. Also, when I use conversion between hsx and rgb, I automatically meaning floating point, 32 or 64-bit. But SIMD restricted by 32-bit float. :(
For me "mod" very need, I use floating point (in theory). Color converter using this operator for floats.
And... you have no even "floor" operation. :(
Hello. Why in SIMD no load/store with non-typed array (i.e. Array with Number)? Where operation like "max component" and "min component"? Why just no make SIMD without type definition?
Also why no "mod" function?
I from this project. I want optimize with SIMD, but have some problems. https://github.com/acterhd/death-color