What is this structure called? Simply SoA?

2019-08-10 14:07发布

问题:

I've seen common comparisons made between the AoS (Array of Structures):

struct xyz
{
    ALIGNED float x, y, z, ignored;
};
ALIGNED struct xyz AoS[n];

And the SoA (Structure of Arrays):

struct SoA
{
    ALIGNED_AND_PADDED float x[n];
    ALIGNED_AND_PADDED float y[n];
    ALIGNED_AND_PADDED float z[n];
};

So what would this kind of data representation be called?

struct xyz4
{
    ALIGNED float x[4];
    ALIGNED float y[4];
    ALIGNED float z[4];
};
ALIGNED struct xyz4[n/4] ???;

A "cache-efficient SoA"? An AoSoA? An SoAoS? A "PITA to code"? It seems like the most efficient solution generally speaking, providing SoA-type SIMD with a lot of cache hits.

回答1:

That data structure has multiple names such as a Hybrid Structure of Arrays (see Extending a C-like Language for Portable SIMD Programming) or an array of struct of arrays (AoSoA).

AoS is not suitable for SIMD. SoA is an improvement but in some cases is still not sufficient. The solution is a Hybrid Structure of Arrays. It may be a PITA as you say but that's what you have to use sometimes if you want the highest efficient from SIMD (unless gather and scatter instructions become efficient).



标签: c simd