Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

mysterymath
Copy link
Member

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

  • soa::Array<T, s> is an array of T of size s, but where the k'th byte of each T are stored contiguously.
  • soa::Ptr<T> is a pointer to an element of soa::Array.

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.

This adds two new types to the SDK under soa.h:
  - soa::Array<T, s> is an array of T of size s, but where the
    k'th byte of each T are stored contiguously.
  - soa::Ptr<T> is a pointer to an element of soa::Array.

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
Copy link
Member Author

mysterymath commented Sep 12, 2023

@asiekierka , @jroweboy , @johnwbyrd, PTAL!

@mysterymath
Copy link
Member Author

Closes #185

@johnwbyrd
Copy link
Member

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
Copy link
Member Author

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.

@mysterymath mysterymath merged commit eb67420 into llvm-mos:main Sep 14, 2023
@mysterymath mysterymath deleted the soa branch September 14, 2023 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants