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

Align stack buffer on 32 bytes #56

Merged
merged 2 commits into from
Sep 30, 2019
Merged

Conversation

jcberentsen
Copy link

Include stdint.h for uint32_t portability
Relates to issue #53

@newhoggy
Copy link
Member

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);
Copy link
Member

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));
Copy link
Member

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.

Copy link
Member

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.

@newhoggy
Copy link
Member

I'll merge anyway given that the fix works for you.

@newhoggy newhoggy merged commit 17e1efa into haskell-works:master Sep 30, 2019
@jcberentsen jcberentsen deleted the sp-align branch September 30, 2019 12:12
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.

3 participants