4 ms·
"What if a programming language would provide us with a structure that would act like an array of structs, but internally it would really behave like a struct o
by jeff-davis 5y ago
"What if a programming language would provide us with a structure that would act like an array of structs, but internally it would really behave like a struct of arrays?"
What about SQL when using a columnar data store?
- rualca 5y agoAn array of structs is already a struct of arrays if you're willing to do some offset math.
- incrudible 5y agoThat would make the whole thing moot. The crucial difference between AOS and SOA is that the "physical" memory layout is different: AOS: [xyzw][xyzw][xyzw][xyzw] vs SOA: [xxxx][yyyy][zzzz][wwww] If you have such a layout, a SIMD instruction touching 4 packed words has quite different behavior. Arguably, SIMD is pointless without SOA or AOSOA.
- rualca 5y ago> SOA: [xxxx][yyyy][zzzz][wwww] That difference only occurs if, for some random reason, you came about what's the address of element zero of that array, or if for any even rarer reason you have a hard requirement of when you cease to process x and start to process y, and you find a single memory jump prohibitively expensive. Meanwhile, AOS is already by definition [xxxx] and [yyyy] and [zzzz] and [wwww], given the remaining members of the struct are treated as padding.
- incrudible 5y ago> Meanwhile, AOS is already by definition [xxxx] and [yyyy] and [zzzz] and [wwww] There must be a misunderstanding here. AOS is by definition [xyzw][xyzw](...), the (C/C++) compiler has no leeway in rearranging this. I'm also assuming that there's no padding necessary, in either case. Perhaps my way of notation is confusing, in that case I'm going to refer you to this page, which has code examples: https://software.intel.com/content/www/us/en/develop/articles/memory-layout-transformations.html https://software.intel.com/content/www/us/en/develop/article...