From cc5f533fc924d09771a9c315e03bf73dcea2c462 Mon Sep 17 00:00:00 2001 From: Jonathan Platzer Date: Thu, 19 Jul 2018 10:14:30 +0200 Subject: [PATCH] Add macro for automatic alignment of matrices --- include/cglm/affine-mat.h | 2 +- include/cglm/affine.h | 8 ++++---- include/cglm/mat3.h | 4 ++-- include/cglm/mat4.h | 2 +- include/cglm/quat.h | 2 +- include/cglm/types.h | 6 ++++++ 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 62bfce1..1f66776 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -151,7 +151,7 @@ glm_inv_tr(mat4 mat) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_inv_tr_sse2(mat); #else - CGLM_ALIGN(16) mat3 r; + CGLM_ALIGN_MAT mat3 r; CGLM_ALIGN(16) vec3 t; /* rotate */ diff --git a/include/cglm/affine.h b/include/cglm/affine.h index e8f98bb..dd2f619 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -244,7 +244,7 @@ glm_scale_uni(mat4 m, float s) { CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -269,7 +269,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -294,7 +294,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -351,7 +351,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis) { - CGLM_ALIGN(16) mat4 rot; + CGLM_ALIGN_MAT mat4 rot; glm_rotate_make(rot, angle, axis); glm_mul_rot(m, rot, m); } diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index f932bce..d0135a4 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -81,7 +81,7 @@ glm_mat3_copy(mat3 mat, mat3 dest) { CGLM_INLINE void glm_mat3_identity(mat3 mat) { - CGLM_ALIGN(16) mat3 t = GLM_MAT3_IDENTITY_INIT; + CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT; glm_mat3_copy(t, mat); } @@ -155,7 +155,7 @@ glm_mat3_transpose_to(mat3 m, mat3 dest) { CGLM_INLINE void glm_mat3_transpose(mat3 m) { - CGLM_ALIGN(16) mat3 tmp; + CGLM_ALIGN_MAT mat3 tmp; tmp[0][1] = m[1][0]; tmp[0][2] = m[2][0]; diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index a0a50e7..4162cd1 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -139,7 +139,7 @@ glm_mat4_copy(mat4 mat, mat4 dest) { CGLM_INLINE void glm_mat4_identity(mat4 mat) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; glm_mat4_copy(t, mat); } diff --git a/include/cglm/quat.h b/include/cglm/quat.h index aa303ca..e97e922 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -742,7 +742,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { CGLM_INLINE void glm_quat_rotate(mat4 m, versor q, mat4 dest) { - CGLM_ALIGN(16) mat4 rot; + CGLM_ALIGN_MAT mat4 rot; glm_quat_mat4(q, rot); glm_mul_rot(m, rot, dest); } diff --git a/include/cglm/types.h b/include/cglm/types.h index 6fca0fe..76c3646 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -26,6 +26,12 @@ # define CGLM_ALIGN_IF(X) /* no alignment */ #endif +#ifdef __AVX__ +# define CGLM_ALIGN_MAT CGLM_ALIGN(32) +#else +# define CGLM_ALIGN_MAT CGLM_ALIGN(16) +#endif + typedef float vec2[2]; typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef int ivec3[3];