llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler
https://www.llvm-mos.org
Other
266 stars 53 forks source link

Add C++ struct-of-arrays library and example #197

Closed mysterymath closed 11 months ago

mysterymath commented 11 months ago

This adds two new types to the SDK under soa.h:

The include-eable soa-struct.h specializes soa::Ptr<T> for a struct type, including its members as distinct soa::Ptr<T> instances that point to the members.

Using this library allows global arrays of structs to be accessed using the absolute indexed addressing mode if it's always known at compile-time what portion of the struct is being accessed. This is generally true if there are no pointers into the array; in that common case, using this library can produce a huge speedup.

See the included example for more details; the library is quite expansive in practice, so the examples walk through what you can and can't do with it.

mysterymath commented 11 months ago

@asiekierka , @jroweboy , @johnwbyrd, PTAL!

mysterymath commented 11 months ago

Closes #185

johnwbyrd commented 11 months ago

This is a good and useful library. When convenient, just because I suspect that SoA type transformations will seem alien to the old-school 6502 community and to Joe Programmer, you may wish to put in a readme.md file that describes why it's important and useful for generating fast code on the 6502.

mysterymath commented 11 months ago

This is a good and useful library. When convenient, just because I suspect that SoA type transformations will seem alien to the old-school 6502 community and to Joe Programmer, you may wish to put in a readme.md file that describes why it's important and useful for generating fast code on the 6502.

That's a good idea; I've modified the doc comment for the main class to include a broader introduction to the idea and why one would do this. That helps motivate everything about the library's syntax and semantics, so it's important that it's understood going in.