rework(mat4f): add static inline to all no _r functions

This commit is contained in:
2025-08-13 09:18:31 +02:00
parent 4fbd3dcdc8
commit 9d7e47045e
2 changed files with 75 additions and 84 deletions

View File

@@ -18,13 +18,6 @@ Mat4f_t* mat4f_from_array_r(Mat4f_t *__restrict m, const float arr[16])
return m;
}
Mat4f_t mat4f_from_array(const float arr[16])
{
Mat4f_t mat;
mat4f_from_array_r(&mat, arr);
return mat;
}
Mat4f_t* mat4f_scalar_r(Mat4f_t *__restrict m, float f)
{
for(int i = 0; i<MAT_SIZE; i+=MAT_DIM) {
@@ -45,12 +38,6 @@ Mat4f_t* mat4f_scalar_r(Mat4f_t *__restrict m, float f)
return m;
}
Mat4f_t mat4f_scalar(float f)
{
Mat4f_t mat;
mat4f_scalar_r(&mat, f);
return mat;
}
Mat4f_t* mat4f_zero_r(Mat4f_t *__restrict m)
{
@@ -66,13 +53,6 @@ Mat4f_t* mat4f_zero_r(Mat4f_t *__restrict m)
#endif
}
Mat4f_t mat4f_zero()
{
Mat4f_t mat;
mat4f_zero_r(&mat);
return mat;
}
Mat4f_t* mat4f_identity_r(Mat4f_t *__restrict m)
{
mat4f_zero_r(m);
@@ -83,13 +63,6 @@ Mat4f_t* mat4f_identity_r(Mat4f_t *__restrict m)
return m;
}
Mat4f_t mat4f_identity()
{
Mat4f_t mat;
mat4f_identity_r(&mat);
return mat;
}
Mat4f_t* mat4f_add_r(Mat4f_t *out, const Mat4f_t *m2)
{
for(int i = 0; i<MAT_SIZE; i+=MAT_DIM) {
@@ -117,13 +90,6 @@ Mat4f_t* mat4f_add_r(Mat4f_t *out, const Mat4f_t *m2)
return out;
}
Mat4f_t mat4_add(const Mat4f_t* m1, const Mat4f_t* m2)
{
Mat4f_t mout = mat4f_clone(m1);
mat4f_add_r(&mout, m2);
return mout;
}
Mat4f_t* mat4f_sub_r(Mat4f_t *out, const Mat4f_t *m2)
{
for(int i = 0; i<MAT_SIZE; i+=MAT_DIM) {
@@ -151,13 +117,6 @@ Mat4f_t* mat4f_sub_r(Mat4f_t *out, const Mat4f_t *m2)
return out;
}
Mat4f_t mat4_sub(const Mat4f_t* m1, const Mat4f_t* m2)
{
Mat4f_t mout = mat4f_clone(m1);
mat4f_sub_r(&mout, m2);
return mout;
}
Mat4f_t* mat4f_scale_r(Mat4f_t *__restrict out, float scalar)
{
for(int i = 0; i<MAT_SIZE; i+=MAT_DIM) {
@@ -181,13 +140,6 @@ Mat4f_t* mat4f_scale_r(Mat4f_t *__restrict out, float scalar)
return out;
}
Mat4f_t mat4f_scale(const Mat4f_t *__restrict m, float scalar)
{
Mat4f_t mout = mat4f_clone(m);
mat4f_scale_r(&mout, scalar);
return mout;
}
Mat4f_t* mat4f_mul_r(Mat4f_t* out, const Mat4f_t* m2)
{
Mat4f_t clone = mat4f_clone(out);
@@ -245,13 +197,6 @@ Mat4f_t* mat4f_mul_r(Mat4f_t* out, const Mat4f_t* m2)
return out;
}
Mat4f_t mat4f_mul(const Mat4f_t* m1, const Mat4f_t* m2)
{
Mat4f_t mout = mat4f_clone(m1);
mat4f_mul_r(&mout, m2);
return mout;
}
Mat4f_t* mat4f_tpo_r(Mat4f_t *__restrict out)
{
Mat4f_t clone = mat4f_clone(out);
@@ -320,13 +265,6 @@ Mat4f_t* mat4f_tpo_r(Mat4f_t *__restrict out)
return out;
}
Mat4f_t mat4f_tpo(const Mat4f_t *restrict m)
{
Mat4f_t res = mat4f_clone(m);
mat4f_tpo_r(&res);
return res;
}
float mat4f_det(const Mat4f_t* m)
{
const float* const a = m->m;
@@ -377,10 +315,3 @@ Mat4f_t* mat4f_inv_r(Mat4f_t* __restrict m)
return m;
}
Mat4f_t mat4f_inv(const Mat4f_t* m)
{
Mat4f_t mout = mat4f_clone(m);
mat4f_inv_r(&mout);
return mout;
}

View File

@@ -4,6 +4,9 @@
#include <math.h>
#include <float.h>
#define MAT_SIZE 16
#define MAT_DIM 4
#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
#define SIMD_X86
#include <xmmintrin.h>
@@ -16,55 +19,112 @@
#endif
#ifdef _MSC_VER
#define ALIGN16 __declspec(align(16))
#define ALIGN16 __declspec(align(MAT_SIZE))
#else
#define ALIGN16 __attribute__((aligned(16)))
#define ALIGN16 __attribute__((aligned(MAT_SIZE)))
#endif
#define MAT_SIZE 16
#define MAT_DIM 4
typedef struct
{
float m[MAT_SIZE];
} ALIGN16 Mat4f_t;
Mat4f_t* mat4f_from_array_r(Mat4f_t *__restrict m, const float arr[16]);
Mat4f_t mat4f_from_array(const float arr[16]);
Mat4f_t* mat4f_from_array_r(Mat4f_t *__restrict m, const float arr[MAT_SIZE]);
static inline Mat4f_t mat4f_from_array(const float arr[MAT_SIZE])
{
Mat4f_t mat;
mat4f_from_array_r(&mat, arr);
return mat;
}
Mat4f_t* mat4f_scalar_r(Mat4f_t *__restrict m, float f);
Mat4f_t mat4f_scalar(float f);
static inline Mat4f_t mat4f_scalar(float f)
{
Mat4f_t mat;
mat4f_scalar_r(&mat, f);
return mat;
}
Mat4f_t* mat4f_zero_r(Mat4f_t *__restrict m);
Mat4f_t mat4f_zero(void);
static inline Mat4f_t mat4f_zero(void)
{
Mat4f_t mat;
mat4f_zero_r(&mat);
return mat;
}
Mat4f_t* mat4f_identity_r(Mat4f_t *__restrict m);
Mat4f_t mat4f_identity(void);
static inline Mat4f_t mat4f_identity(void)
{
Mat4f_t mat;
mat4f_identity_r(&mat);
return mat;
}
inline static Mat4f_t mat4f_clone(const Mat4f_t *__restrict out)
{
return *out;
}
Mat4f_t mat4f_add(const Mat4f_t* m1, const Mat4f_t* m2);
Mat4f_t* mat4f_add_r(Mat4f_t* out, const Mat4f_t* m2);
Mat4f_t mat4f_sub(const Mat4f_t* m1, const Mat4f_t* m2);
static inline Mat4f_t mat4f_add(const Mat4f_t* m1, const Mat4f_t* m2)
{
Mat4f_t mout = mat4f_clone(m1);
mat4f_add_r(&mout, m2);
return mout;
}
Mat4f_t* mat4f_sub_r(Mat4f_t* out, const Mat4f_t* m2);
Mat4f_t mat4f_scale(const Mat4f_t *__restrict m, float scalar);
static inline Mat4f_t mat4f_sub(const Mat4f_t* m1, const Mat4f_t* m2)
{
Mat4f_t mout = mat4f_clone(m1);
mat4f_sub_r(&mout, m2);
return mout;
}
Mat4f_t* mat4f_scale_r(Mat4f_t *out, float scalar);
static inline Mat4f_t mat4f_scale(const Mat4f_t *__restrict m, float scalar)
{
Mat4f_t mout = mat4f_clone(m);
mat4f_scale_r(&mout, scalar);
return mout;
}
// row * col
Mat4f_t mat4f_mul(const Mat4f_t* m1, const Mat4f_t* m2);
Mat4f_t* mat4f_mul_r(Mat4f_t* out, const Mat4f_t* m2);
static inline Mat4f_t mat4f_mul(const Mat4f_t* m1, const Mat4f_t* m2)
{
Mat4f_t mout = mat4f_clone(m1);
mat4f_mul_r(&mout, m2);
return mout;
}
Mat4f_t mat4f_tpo(const Mat4f_t *__restrict m);
Mat4f_t* mat4f_tpo_r(Mat4f_t *__restrict m);
static inline Mat4f_t mat4f_tpo(const Mat4f_t *__restrict m)
{
Mat4f_t res = mat4f_clone(m);
mat4f_tpo_r(&res);
return res;
}
float mat4f_det(const Mat4f_t* m);
Mat4f_t mat4f_inv(const Mat4f_t* m);
Mat4f_t* mat4f_inv_r(Mat4f_t* __restrict m);
static inline Mat4f_t mat4f_inv(const Mat4f_t* m)
{
Mat4f_t mout = mat4f_clone(m);
mat4f_inv_r(&mout);
return mout;
}
#endif // MATRIX4_H