-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Align stack buffer on 32 bytes #56
Conversation
Include stdint.h for uint32_t portability
Nice! |
// align stack buffer on 32 bytes | ||
uint8_t unaligned_buffer[W8_BUFFER_SIZE + 32]; | ||
uint8_t * buffer = unaligned_buffer + ((uintptr_t)unaligned_buffer & (uintptr_t)0x10); | ||
fprintf(stderr, "Buffer is at address %p of size %zu\n", buffer, (size_t) W8_BUFFER_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's better to declare a stack allocated array for alignment and get the compiler to handle it:
uint64_t aligned_buffer[W8_BUFFER_SIZE / 8];
uint8_t * buffer = (uint8_t *)aligned_buffer;
Unless we need alignment at 32
bytes, in which case we'll have to use your solution.
uint32_t phi_buffer[W8_BUFFER_SIZE]; | ||
|
||
uint32_t unaligned_phi_buffer[W8_BUFFER_SIZE + 32]; | ||
uint32_t * phi_buffer = (uint32_t*) ((void*)unaligned_phi_buffer + ((uintptr_t)unaligned_phi_buffer & (uintptr_t)0x10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is possibly overkill since + 32
for uint32_t
is actually an extra 32 * 4 = 128
bytes.
I'll merge anyway given that the fix works for you. |
Include stdint.h for uint32_t portability
Relates to issue #53