replace vectors with SMID vectors.

This commit is contained in:
2025-07-03 11:44:59 +02:00
parent 9de6e7f92e
commit 271773a28c
5 changed files with 18 additions and 243 deletions

18
src/util/vec.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include "types.h"
#if defined(__has_attribute) && __has_attribute(vector_size)
typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float`
typedef float fvec4 __attribute__((vector_size(sizeof(float) * 4))); // SMID vector for 4 `float`
typedef u8 u8vec2 __attribute__((vector_size(sizeof(u8) * 2))); // SMID vector for 2 `u8`
typedef u8 u8vec4 __attribute__((vector_size(sizeof(u8) * 4))); // SMID vector for 4 `u8`
#else
#error the platform is unsupported, attribute vector_size must be available (and so does __has_attribute)
#endif
#define VX 0
#define VY 1
#define VZ 2
#define VW 3

View File

@@ -1,69 +0,0 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
#include <math.h>
#include "../atrb.h"
// stores a 2D point using a floating-point number
struct float2 {
float x;
float y;
};
typedef struct float2 float2;
// adds one float2 to another
atrb_const static inline float2 float2_add(float2 v1, float2 v2) {
return (float2){v1.x + v2.x, v1.y + v2.y};
}
// subtracts one float2 from another
atrb_const static inline float2 float2_sub(float2 v1, float2 v2) {
return (float2){v1.x - v2.x, v1.y - v2.y};
}
// multiplies one float2 by another
atrb_const static inline float2 float2_mul(float2 v1, float2 v2) {
return (float2){v1.x * v2.x, v1.y * v2.y};
}
// divides one float2 by another
atrb_const static inline float2 float2_div(float2 v1, float2 v2) {
return (float2){v1.x / v2.x, v1.y / v2.y};
}
// preforms a scalar multiplication upon the float2 (multiplies the float2 by some value)
atrb_const static inline float2 float2_mul_s(float2 v, float n) {
return (float2){v.x * n, v.y * n};
}
// preforms a scalar division upon the float2 (divides the float2 by some value)
atrb_const static inline float2 float2_div_s(float2 v, float n) {
return (float2){v.x / n, v.y / n};
}
atrb_const static inline float2 float2_neg(float2 v) {
return (float2){-v.x, -v.y};
}
// gets the squared magnitude/length of float2
atrb_const static inline float float2_mag2(float2 v) {
return (v.x * v.x) + (v.y * v.y);
}
// gets the length of float2 (length)
atrb_const static inline float float2_mag(float2 v) {
return sqrtf(float2_mag2(v));
}
// normalizes the float2
atrb_const static inline float2 float2_norm(float2 v) {
float s = 1.0F / float2_mag(v); // get the scaling factor
return float2_mul_s(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
}
// gets the dot product of two float2s
atrb_const static inline float float2_dot(float2 v1, float2 v2) {
return v1.x * v2.x + v1.y * v2.y;
}

View File

@@ -1,70 +0,0 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
#include <math.h>
#include "../atrb.h"
// stores a 3D point using a floating-point number
struct float3 {
float x;
float y;
float z;
};
typedef struct float3 float3;
// adds one float3 to another
atrb_const static inline float3 float3_add(float3 v1, float3 v2) {
return (float3){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
}
// subtracts one float3 from another
atrb_const static inline float3 float3_sub(float3 v1, float3 v2) {
return (float3){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z};
}
// multiplies one float3 by another
atrb_const static inline float3 float3_mul(float3 v1, float3 v2) {
return (float3){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z};
}
// divides one float3 by another
atrb_const static inline float3 float3_div(float3 v1, float3 v2) {
return (float3){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z};
}
// preforms a scalar multiplication upon the float3 (multiplies the float3 by some value)
atrb_const static inline float3 float3_mul_s(float3 v, float n) {
return (float3){v.x * n, v.y * n, v.z * n};
}
// preforms a scalar division upon the float3 (divides the float3 by some value)
atrb_const static inline float3 float3_div_s(float3 v, float n) {
return (float3){v.x / n, v.y / n, v.z / n};
}
atrb_const static inline float3 float3_neg(float3 v) {
return (float3){-v.x, -v.y, -v.z};
}
// gets the squared magnitude/length of float3
atrb_const static inline float float3_mag2(float3 v) {
return (v.x * v.x) + (v.y * v.y) + (v.z * v.z);
}
// gets the length of float3 (length)
atrb_const static inline float float3_mag(float3 v) {
return sqrtf(float3_mag2(v));
}
// normalizes the float3
atrb_const static inline float3 float3_norm(float3 v) {
float s = 1.0F / float3_mag(v); // get the scaling factor
return float3_mul_s(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
}
// gets the dot product of two float3s
atrb_const static inline float float3_dot(float3 v1, float3 v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}

View File

@@ -1,51 +0,0 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
#include "../atrb.h"
// stores a 2D point using a floating-point number
struct int2 {
int x;
int y;
};
typedef struct int2 int2;
// adds one int2 to another
atrb_const static inline int2 int2_add(int2 v1, int2 v2) {
return (int2){v1.x + v2.x, v1.y + v2.y};
}
// subtracts one int2 from another
atrb_const static inline int2 int2_sub(int2 v1, int2 v2) {
return (int2){v1.x - v2.x, v1.y - v2.y};
}
// multiplies one int2 by another
atrb_const static inline int2 int2_mul(int2 v1, int2 v2) {
return (int2){v1.x * v2.x, v1.y * v2.y};
}
// divides one int2 by another
atrb_const static inline int2 int2_div(int2 v1, int2 v2) {
return (int2){v1.x / v2.x, v1.y / v2.y};
}
// preforms a scalar multiplication upon the int2 (multiplies the int2 by some value)
atrb_const static inline int2 int2_mul_s(int2 v, float n) {
return (int2){v.x * n, v.y * n};
}
// preforms a scalar division upon the int2 (divides the int2 by some value)
atrb_const static inline int2 int2_div_s(int2 v, float n) {
return (int2){v.x / n, v.y / n};
}
atrb_const static inline int2 int2_neg(int2 v) {
return (int2){-v.x, -v.y};
}
// gets the dot product of two int2s
atrb_const static inline int int2_dot(int2 v1, int2 v2) {
return v1.x * v2.x + v1.y * v2.y;
}

View File

@@ -1,53 +0,0 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
#include "../atrb.h"
// stores a 2D point using a floating-point number
struct int4 {
int x;
int y;
int z;
int w;
};
typedef struct int4 int4;
// adds one int4 to another
atrb_const static inline int4 int4_add(int4 v1, int4 v2) {
return (int4){v1.x + v2.x, v1.y + v2.y, v1.z - v2.z, v1.w - v2.w};
}
// subtracts one int4 from another
atrb_const static inline int4 int4_sub(int4 v1, int4 v2) {
return (int4){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w};
}
// multiplies one int4 by another
atrb_const static inline int4 int4_mul(int4 v1, int4 v2) {
return (int4){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w};
}
// divides one int4 by another
atrb_const static inline int4 int4_div(int4 v1, int4 v2) {
return (int4){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w};
}
// preforms a scalar multiplication upon the int4 (multiplies the int4 by some value)
atrb_const static inline int4 int4_mul_s(int4 v, float n) {
return (int4){v.x * n, v.y * n, v.z * n, v.w * n};
}
// preforms a scalar division upon the int4 (divides the int4 by some value)
atrb_const static inline int4 int4_div_s(int4 v, float n) {
return (int4){v.x / n, v.y / n, v.z / n, v.w / n};
}
atrb_const static inline int4 int4_neg(int4 v) {
return (int4){-v.x, -v.y, -v.z, v.w};
}
// gets the dot product of two int2s
atrb_const static inline int int4_dot(int4 v1, int4 v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
}