Low-level SIMD primitives
Hardware vector arithmetic (SIMD)

Prev:SIMD data in struct classes


The words in the math.vectors.simd.intrinsics vocabulary are used to implement SIMD support. These words have three disadvantages compared to the higher-level Vector operations words:
They operate on raw byte arrays, with a separate “representation” parameter passed in to determine the type of the operands and result.
They are unsafe; passing values which are not byte arrays, or byte arrays with the wrong size, will dereference invalid memory and possibly crash Factor.

The compiler converts Vector operations into SIMD primitives automatically in cases where it is safe; this means that the input types are known to be SIMD vectors, and the CPU supports SIMD.

It is best to avoid calling SIMD primitives directly. To write efficient high-level code that compiles down to primitives and avoids memory allocation, see Writing efficient SIMD code.

There are two primitives which are used to implement accessing SIMD vector fields of Struct classes:
alien-vector ( c-ptr n rep -- value )

set-alien-vector ( value c-ptr n rep -- )


For the most part, the above primitives correspond directly to vector arithmetic words. They take a representation parameter, which is one of the singleton members of the vector-rep union in the cpu.architecture vocabulary.