-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
packed struct produces byte stores instead of word stores #4056
Comments
packed structs have alignment 1. You need to change it to |
Thank you - will try. |
@daurnimator I tried
but I get the same results. @andrewrk this comment #1834 (comment) points to a gist https://gist.github.com/nic-donaldson/21abc0f0b9a83d3f4e96a5bbb55c9290 that exhibits the same store-byte sequence. My case includes exactly one u32 which I think is different from and simpler than any of the other reports that are trying to use small bit fields that are not multiples of bytes. |
@daurnimator are you sure that align(4) will make it work? I just tried 0.5.0+83f6f730c and have the same results. |
How does this look to you? https://zig.godbolt.org/z/AsAfSh This was the example you referenced in the comment but updated. If there is a bug here it is that if you try to declare the const value inline with the write instead of on its own line, it produces byte stores instead of a word store. Does Zig plan to make guarantees as to how structs are copied though? Even packed structs? Oh wait, I see that your struct only has one field that is a u32, so why is it producing byte stores of that one field if the align attribute is added. I'll investigate some more. |
This example works in every mode except debug: |
Good question.
Ok, I'll have to consider the implications. Thanks! |
This should be well supported now that #5049 is implemented and packed structs use the same semantics as their backing integer type. |
See https://github.com/markfirmware/zig-bare-metal-microbit/blob/7d7b6d23f49c454a36cf23ff7fa8806fd113ac1b/lib00_basics.zig#L384
Good - not a packed struct, does a 32-bit word store
Bad - changing that struct to packed struct, it does a sequence of (4) byte stores. Does not work because mmio needs a word write.
The text was updated successfully, but these errors were encountered: