-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
global is misaligned #4502
Labels
Comments
It doesn't crash for me (Win 10 Pro, AMD Ryzen 9 5950X). But the last line does print "random" output every time you run it.
etc. |
I did find a code gen bug by slightly changing the code: package main
import "core:fmt"
import "core:math/rand"
Globals :: struct #align(128) {
padding04: f32,
padding08: f32,
padding12: f32,
padding16: f32,
// padding20: f32,
// padding24: f32,
// padding28: f32,
// padding32: f32,
mat: matrix[4, 4]f32,
}
g := Globals{} // <- struct is misaligned (seems to be stuck on 16 byte alignment)
// compiled with core-avx2
main :: proc() {
g.mat = {
2, -1.0, -1.0, -1.0,
-1.0, 2, -1.0, -1.0,
-1.0, -1.0, 2, -1.0,
-1.0, -1.0, -1.0, 2,
}
mat: matrix[4, 4]f32
for i in 0..<4 {
for j in 0..<4 {
g.mat[i, j] = rand.float32_uniform(1.0, 10.0) // fails to compile
// mat[i, j] = 1 // rand.float32_uniform(1.0, 10.0)
}
}
fmt.println(size_of(matrix[4, 4]f32))
fmt.println(align_of(matrix[4, 4]f32))
fmt.println(size_of(Globals))
fmt.println(align_of(Globals))
struct_memory_as_floats := cast([^]f32)&g
fmt.println("struct address =", rawptr(struct_memory_as_floats))
fmt.println(struct_memory_as_floats[:size_of(Globals) / size_of(f32)])
fmt.println(g.mat * mat) // CRASH: vmovaps ymm, m256 <- not 32 byte aligned
} Which results in:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
I started using Odin about a year ago, and I love it! I can't stop using it, it's so much better than C/C++. I use it whenever I can.
So far, I haven’t had many issues, but today my luck ran out when I tried to compile my code with AVX instructions. After a bit of debugging, I found that some of my global data was misaligned.
I’ve reduced the code to a small example to reproduce the problem.
Expected Behavior
For the global data to be correctly aligned.
Current Behavior
The global data is misaligned, and the AVX builds are blowing up in my face. :(
Steps to Reproduce
Run the code. add/remove padding to make the struct misaligned.
The text was updated successfully, but these errors were encountered: