From 6c5143313e7c7dbae821a59421e62eb33ac61073 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 15 Sep 2016 17:54:37 +0300 Subject: [PATCH] matrix scale --- include/cglm-mat-simd.h | 10 ++++++++++ include/cglm-mat.h | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/cglm-mat-simd.h b/include/cglm-mat-simd.h index 3ca9cc6..a2535a7 100644 --- a/include/cglm-mat-simd.h +++ b/include/cglm-mat-simd.h @@ -48,4 +48,14 @@ _mm_store_ps(D[3], r3); \ } while (0) +#define CGLM_MAT_SCALE_SSE_4x4f(M, S) \ + do { \ + __m128 xmm0; \ + xmm0 = _mm_set1_ps(S); \ + _mm_store_ps(M[0], _mm_mul_ps(_mm_load_ps(M[0]), xmm0)); \ + _mm_store_ps(M[1], _mm_mul_ps(_mm_load_ps(M[1]), xmm0)); \ + _mm_store_ps(M[2], _mm_mul_ps(_mm_load_ps(M[2]), xmm0)); \ + _mm_store_ps(M[3], _mm_mul_ps(_mm_load_ps(M[3]), xmm0)); \ + } while (0) + #endif /* cglm_mat_sse_h */ diff --git a/include/cglm-mat.h b/include/cglm-mat.h index d6d890a..4ac2fe2 100644 --- a/include/cglm-mat.h +++ b/include/cglm-mat.h @@ -124,6 +124,19 @@ glm_mat_transpose_self(mat4 m) { #endif } +CGLM_INLINE +void +glm_mat4_scale(mat4 m, float s) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + CGLM_MAT_SCALE_SSE_4x4f(m, s); +#else + m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; m[0][3] *= s; + m[1][0] *= s; m[1][1] *= s; m[1][2] *= s; m[1][3] *= s; + m[2][0] *= s; m[2][1] *= s; m[2][2] *= s; m[2][3] *= s; + m[3][0] *= s; m[3][1] *= s; m[3][2] *= s; m[3][3] *= s; +#endif +} + CGLM_INLINE float glm_mat4_det(mat4 mat) {