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

Support aligned globals #225

Open
ahomescu opened this issue Jan 7, 2020 · 1 comment
Open

Support aligned globals #225

ahomescu opened this issue Jan 7, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@ahomescu
Copy link
Contributor

ahomescu commented Jan 7, 2020

Submitted by @Lokathor via email:

Your need for aligned globals has come up before and the best way to get some aligned static data without making a new struct every single time is to generalize what you did with the SSEMask type:

#[repr(align(16))]

pub struct Align16<T>(pub T);

 

static ssemask: &[u8; 16] = &Align16([7_u8; 16]).0;

 

#[test]

fn aligned() {

    assert_eq!(ssemask as *const _ as usize % 16, 0);

}

I like this approach, we could implement it for a few common aligment values: 16 (common for SSE values), 32, 64 (common for cache-aligned data) and maybe 128.

@Lokathor
Copy link

Lokathor commented Jan 7, 2020

Align4 is also popular to make include_bytes! be "word aligned" so you can safely cast it to &[u32] without fail.

The drawback of is this that it doesn't work on static mut, but you really shouldn't be using static mut in the first place if it's in any way possible to avoid it, and usually you can avoid it.

@ahomescu ahomescu added the bug Something isn't working label Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants