Skip to content

SimdQuery

Martin Evans edited this page Aug 1, 2024 · 3 revisions

A SIMD query is a type of ChunkQuery which returns data re-interpreted as a SIMD vector. This is rarely useful, but it is extremely fast when it fits the problem.

A vector query is defined as a type, which takes type parameters indicating what the component will be re-interpreted as. For example, here the component will be re-interpreted as a float and will be passed as a SIMD Vector<float>:

private struct AddFloats
    : IVectorChunkQuery1<float, float>
{
    public readonly void Execute(Span<Vector<int>> t0, Span<Vector<float>> t0, int offset, int padding)
    {
        for (var i = 0; i < t0.Length; i++)
            t0[i] += t0[i];
    }
}

It is not always possible to fit all the data perfectly into a set of SIMD vectors. For example if the components are Vector3 (3 floats) and a SIMD vector contains 8 floats then this doesn't fit perfectly. In this example you will receive:

  1. [ X0, Y0, Z0, X1, Y1, Z1, X2, Y2 ], offset = 0, padding = 0
  2. [ Z2, X3, Y3, Z3, X4, Y4, Z4, X5 ], offset = 2, padding = 0
  3. [ Y5, Z5, 0, 0, 0, 0, 0, 0, ], offset = 1, padding = 6

The final item has 5 padding items at the end, to make up enough items to fill the final SIMD vector.

Clone this wiki locally