cglm icon indicating copy to clipboard operation
cglm copied to clipboard

CGLM compiled with avx leads to segmentation fault when using mat4 multiplication

Open RealSomeGuy opened this issue 6 months ago • 4 comments

Using cglm with avx leads to glm_mat4_mul segfaulting. I am using mingw-w64 to compile my code with the following flags

-mavx

here is a minimally reproducible example

#include <cglm/mat4.h>
#include <cglm/affine.h>
#include <cglm/io.h>

int main(void)
{
    mat4 a = GLM_MAT4_IDENTITY_INIT;
    mat4 b = GLM_MAT4_IDENTITY_INIT;
    mat4 c = GLM_MAT4_IDENTITY_INIT;

    glm_translate(a, (vec3){2.0f, 0.0f, 3.0f});
    glm_rotate(b, glm_rad(40.0f), (vec3){0.0f, 0.0f, 3.0f});

    glm_mat4_mul(b, a, c);

    glm_mat4_print(c, stdout);
}

this works with SSE, but with avx, it leads to a segmentation fault.

Running it through gdb

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ff6a5762e9d in glm_mat4_mul_avx (m1=0x5ff3c0, m2=0x5ff400, dest=0x5ff380)
    at ../../include/cglm/simd/avx/mat4.h:101
101       y0 = glmm256_fmadd(y3, y7, y0);

RealSomeGuy avatar Jul 14 '25 08:07 RealSomeGuy

Hi @RealSomeGuy,

Sorry for the delay, are you using latest version of cglm ? -mavx forked for me on given sample. I did not test on mingw-w64, will check it asap

recp avatar Jul 21 '25 13:07 recp

@recp sorry for the delay too, I am using 0.9.6

RealSomeGuy avatar Jul 27 '25 11:07 RealSomeGuy

There might be aligment issues on mingw-w64, will check it asap 👍

recp avatar Jul 28 '25 14:07 recp

thank you.

RealSomeGuy avatar Aug 01 '25 16:08 RealSomeGuy