From cfa52e9795486b49ab1d3d1ced760c2ea7de56c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Sat, 21 Jun 2025 14:07:24 +0200 Subject: [PATCH] fix: ensure code to compile correctly with MSVC --- src/math/vec3.c | 16 ++++++++-------- src/math/vec3.h | 18 ++++++++++++------ src/math/vec4.c | 8 ++++---- src/math/vec4.h | 19 +++++++++++++------ 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/math/vec3.c b/src/math/vec3.c index 045c30f..83fd09a 100644 --- a/src/math/vec3.c +++ b/src/math/vec3.c @@ -15,11 +15,11 @@ Vec3f_t vec3f(float x, float y, float z) return (Vec3f_t){.x = x, .y = y, .z = z}; } -Vec3f_t vec3f_from_array(const float *__restrict val) +Vec3f_t vec3f_from_array(const float *restrict val) { Vec3f_t vec; #if defined (SIMD_X86) - __m128 arr = _mm_loadu_ps(val); + __m128 arr = _mm_load_ps(val); _mm_store_ps(vec.data, arr); #elif defined (SIMD_ARCH) float32x4_t arr = vld1q_f32(val); @@ -54,7 +54,7 @@ Vec3f_t vec3f_zero(void) return vec3f_scalar(0.f); } -Vec3f_t vec3f_add_r(Vec3f_t *__restrict out, Vec3f_t a) +Vec3f_t vec3f_add_r(Vec3f_t *restrict out, Vec3f_t a) { #if defined (SIMD_X86) __m128 va = _mm_load_ps(a.data); @@ -79,7 +79,7 @@ Vec3f_t vec3f_add(Vec3f_t a, Vec3f_t b) return vec3f_add_r(&a, b); } -Vec3f_t vec3f_sub_r(Vec3f_t *__restrict out, Vec3f_t a) +Vec3f_t vec3f_sub_r(Vec3f_t *restrict out, Vec3f_t a) { #if defined (SIMD_X86) __m128 va = _mm_load_ps(out->data); @@ -104,7 +104,7 @@ Vec3f_t vec3f_sub(Vec3f_t a, Vec3f_t b) return vec3f_sub_r(&a, b); } -Vec3f_t vec3f_scale_r(Vec3f_t *__restrict out, float scalar) +Vec3f_t vec3f_scale_r(Vec3f_t *restrict out, float scalar) { #if defined (SIMD_X86) __m128 va = _mm_load_ps(out->data); @@ -130,11 +130,11 @@ Vec3f_t vec3f_scale(Vec3f_t a, float scalar) } -//Vec3f_t vec3f_add_r(Vec3f_t *__restrict out, Vec3f_t a); +//Vec3f_t vec3f_add_r(Vec3f_t *restrict out, Vec3f_t a); //Vec3f_t vec3f_add(Vec3f_t a, Vec3f_t b); // -//Vec3f_t vec3f_sub_r(Vec3f_t *__restrict out, Vec3f_t a); +//Vec3f_t vec3f_sub_r(Vec3f_t *restrict out, Vec3f_t a); //Vec3f_t vec3f_sub(Vec3f_t a, Vec3f_t b); // -//Vec3f_t vec3f_scale_r(Vec3f_t *__restrict out, float scale); +//Vec3f_t vec3f_scale_r(Vec3f_t *restrict out, float scale); //Vec3f_t vec3f_scale(Vec3f_t a, float scale); diff --git a/src/math/vec3.h b/src/math/vec3.h index 41f56e5..df03e46 100644 --- a/src/math/vec3.h +++ b/src/math/vec3.h @@ -8,31 +8,37 @@ #ifndef vec3_h #define vec3_h +#ifdef _MSC_VER +#define ALIGN16 __declspec(align(16)) +#else +#define ALIGN16 __attribute__((aligned(16))) +#endif + typedef union { struct {float x, y, z; }; float data[4]; -} __attribute__((aligned(16))) Vec3f_t; +} ALIGN16 Vec3f_t; -Vec3f_t vec3f_from_array(const float *__restrict val); +Vec3f_t vec3f_from_array(const float *restrict val); Vec3f_t vec3f(float x, float y, float z); // (f, f, f) Vec3f_t vec3f_scalar(float f); // (0, 0, 0) Vec3f_t vec3f_zero(void); -inline static Vec3f_t vec3f_clone(const Vec3f_t *__restrict v) +inline static Vec3f_t vec3f_clone(const Vec3f_t *restrict v) { return *v; } -Vec3f_t vec3f_add_r(Vec3f_t *__restrict out, Vec3f_t a); +Vec3f_t vec3f_add_r(Vec3f_t *restrict out, Vec3f_t a); Vec3f_t vec3f_add(Vec3f_t a, Vec3f_t b); -Vec3f_t vec3f_sub_r(Vec3f_t *__restrict out, Vec3f_t a); +Vec3f_t vec3f_sub_r(Vec3f_t *restrict out, Vec3f_t a); Vec3f_t vec3f_sub(Vec3f_t a, Vec3f_t b); -Vec3f_t vec3f_scale_r(Vec3f_t *__restrict out, float scale); +Vec3f_t vec3f_scale_r(Vec3f_t *restrict out, float scale); Vec3f_t vec3f_scale(Vec3f_t a, float scale); #endif /* vec3_h */ diff --git a/src/math/vec4.c b/src/math/vec4.c index 126d754..a254132 100644 --- a/src/math/vec4.c +++ b/src/math/vec4.c @@ -8,7 +8,7 @@ Vec4f_t vec4f(float x, float y, float z, float w) return (Vec4f_t){.x = x, .y = y, .z = z, .w = w}; } -Vec4f_t vec4f_from_array(const float *__restrict val) +Vec4f_t vec4f_from_array(const float *restrict val) { Vec4f_t vec; #if defined (SIMD_X86) @@ -53,7 +53,7 @@ Vec4f_t vec4f_zero(void) return vec4f_scalar(0.f); } -Vec4f_t vec4f_add_r(Vec4f_t *__restrict out, Vec4f_t a) +Vec4f_t vec4f_add_r(Vec4f_t *restrict out, Vec4f_t a) { #if defined (SIMD_X86) __m128 va = _mm_load_ps(a.data); @@ -80,7 +80,7 @@ Vec4f_t vec4f_add(Vec4f_t a, Vec4f_t b) return a; } -Vec4f_t vec4f_sub_r(Vec4f_t *__restrict out, Vec4f_t a) +Vec4f_t vec4f_sub_r(Vec4f_t *restrict out, Vec4f_t a) { #if defined (SIMD_X86) __m128 va = _mm_load_ps(out->data); @@ -108,7 +108,7 @@ Vec4f_t vec4f_sub(Vec4f_t a, Vec4f_t b) return a; } -Vec4f_t vec4f_scale_r(Vec4f_t *__restrict out, float scalar) +Vec4f_t vec4f_scale_r(Vec4f_t *restrict out, float scalar) { #if defined (SIMD_X86) __m128 va = _mm_load_ps(out->data); diff --git a/src/math/vec4.h b/src/math/vec4.h index 4052179..db94d78 100644 --- a/src/math/vec4.h +++ b/src/math/vec4.h @@ -1,31 +1,38 @@ #ifndef VECTOR4_H #define VECTOR4_H +#include "vec3.h" +#ifdef _MSC_VER +#define ALIGN16 __declspec(align(16)) +#else +#define ALIGN16 __attribute__((aligned(16))) +#endif + // must be aligned by 16 Bytes (less instruction executed for SSE) typedef union { struct { float x, y, z, w; }; float data[4]; -}__attribute__((aligned(16))) Vec4f_t; +} ALIGN16 Vec4f_t; -Vec4f_t vec4f_from_array(const float *__restrict val); +Vec4f_t vec4f_from_array(const float *restrict val); Vec4f_t vec4f(float x, float y, float z, float w); // (f, f, f, f) Vec4f_t vec4f_scalar(float f); // (0, 0, 0, 0) Vec4f_t vec4f_zero(void); -inline static Vec4f_t vec4f_clone(const Vec4f_t *__restrict v) +inline static Vec4f_t vec4f_clone(const Vec4f_t *restrict v) { return *v; } -Vec4f_t vec4f_add_r(Vec4f_t *__restrict out, Vec4f_t a); +Vec4f_t vec4f_add_r(Vec4f_t *restrict out, Vec4f_t a); Vec4f_t vec4f_add(Vec4f_t a, Vec4f_t b); -Vec4f_t vec4f_sub_r(Vec4f_t *__restrict out, Vec4f_t a); +Vec4f_t vec4f_sub_r(Vec4f_t *restrict out, Vec4f_t a); Vec4f_t vec4f_sub(Vec4f_t a, Vec4f_t b); -Vec4f_t vec4f_scale_r(Vec4f_t *__restrict out, float scale); +Vec4f_t vec4f_scale_r(Vec4f_t *restrict out, float scale); Vec4f_t vec4f_scale(Vec4f_t a, float scale); float vec4_dot(Vec4f_t a, Vec4f_t b);