-
-
Notifications
You must be signed in to change notification settings - Fork 670
Add a raw static memory mechanism #1233
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
Conversation
Alright, turned out this conflicts with exported memory if one has |
This is potentially breaking because I had to make the compiler refuse to export builtin functions, so this now also doesn't export |
I would love to start using this. Any status on when this will be ready for nightly? |
Last commit updates all (but one, SPECIALS_UPPER, where .length is read in String#toUpperCase) occasions of There's one subtle difference now, though, in that these memory segments are not guaranteed to start at an offset that is 16 byte aligned, potentially leading to inefficient loads where the data is expected to be aligned in some way that is larger than the natural alignment of their element type. Not sure if that's the case - @MaxGraey ? |
16-byte alignment could be performance sensitive case, so perhaps make sense add alignment for such cases |
Are there specific blobs of data that would benefit from this, or are you suggesting to align all of them to 16 byte boundaries? |
try yo align all data to 16 bytes. It will be zero padding right? In this case binaryen should optimize it and reduce size anyway in memory packing pass |
To give an example of what this means: const PIO2_TABLE = memory.data<u64>([...]); // aligns to 8 bytes
const TAB = memory.data<u8>([...]); // does not align and the change would be const PIO2_TABLE = memory.data<u64>([...], 16); // explicitly align to 16 bytes
const TAB = memory.data<u8>([...], 16); // explicitly align to 16 bytes for either reason of
|
I see. Hmm I guess need benchmark |
Perhaps, what we can do is to look at the algorithms using the data and see if these may do unaligned accesses considering the alignment indicated by the |
According to this, and if I didn't miss something, all of them should do proper aligned accesses. |
I see. Thanks for explanation. In this case everything should be fine. But we should keep alignment in mind when something changes in code relying to bigger than native alignment |
An implementation of the mechanism proposed in #1232.
Usage:
i32
, align?:i32
):usize
Gets a pointer to a zeroed static chunk of memory of the given size. Alignment defaults to
16
. Arguments must be compile-time constants.T
>(values:T[]
, align?:i32
):usize
Gets a pointer to a pre-initialized static chunk of memory. Alignment defaults to the size of
T
. Arguments must be compile-time constants.fixes #1232