# Can this function be auto vectorized with NEON?

Edgar Mobile heideggm@hotmail.com
Fri Jul 22 07:51:03 GMT 2022

Greetings,

I currently try to have this matrix-vector multiplication function auto-vectorized to Aaarch64 armv8 NEON instructions and a 9.3.0 gcc without success:

https://github.com/g-truc/glm/blob/b3f87720261d623986f164b2a7f6a0a938430271/glm/detail/type_mat4x4.inl#L536
[https://opengraph.githubassets.com/8c183f4120fbe851c5fc8496ce4638436329666708589299a2cdae3043ba4284/g-truc/glm]<https://github.com/g-truc/glm/blob/b3f87720261d623986f164b2a7f6a0a938430271/glm/detail/type_mat4x4.inl#L536>
glm/type_mat4x4.inl at b3f87720261d623986f164b2a7f6a0a938430271 · g-truc/glm<https://github.com/g-truc/glm/blob/b3f87720261d623986f164b2a7f6a0a938430271/glm/detail/type_mat4x4.inl#L536>
OpenGL Mathematics (GLM). Contribute to g-truc/glm development by creating an account on GitHub.
github.com
I also tried replacing it with the explicit version commented out:

return typename mat<4, 4, T, Q>::col_type(
m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0] * v[3],
m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1] * v[3],
m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2] * v[3],
m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3] * v[3]);

I tried -O3 and -ftree-vectorize but it only produces the usual fmadd etc. instructions, no NEON.

Can someone tell me which parameters g++ needs to even consider NEON?

Regards