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

Use alignment hints #65

Open
Heath123 opened this issue Mar 29, 2023 · 1 comment · May be fixed by #67
Open

Use alignment hints #65

Heath123 opened this issue Mar 29, 2023 · 1 comment · May be fixed by #67
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Heath123
Copy link
Contributor

(you might already know all this but I'll explain it just in case:

I did a fancy expandable box (click)

Currently loads and stores use memcpy, which on most platforms can be optimised into a normal memory access. However on platforms that don't support unaligned access like SuperH4 the compiler can't do this as it would cause the CPU to raise an exception if an unaligned access is performed. This means that there is a memcpy call for every memory access.

An option that would be faster in most situations would be to access the memory directly by type punning but use an exception handler to emulate unaligned access. This means you only pay a performance penalty when unaligned access actually happens, but that penalty will be much worse.

WebAssembly has a solution for this; alignment hints! This means you can tell the runtime when a memory is likely to be unaligned so it can emulate the access without causing a CPU exception, for example through a memcpy like w2c2 does now.

So, I'd like a way to have to have alignment hints passed through to the load and store functions so I can use them in a custom version of the header. I imagine this use case is too niche for it to be worth having a default implementation of this in w2c2_base.h but having it exposed would let me implement this myself.

I might do a PR for this like I did for #59 if you want it (should it be behind a flag to not bloat code size when it's not used?)

@turbolent
Copy link
Owner

That makes sense and a PR is very welcome!

@turbolent turbolent added enhancement New feature or request good first issue Good for newcomers labels Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants