From dc514cfe311fe285be7a07f0c2b12265db0682e8 Mon Sep 17 00:00:00 2001 From: Yggdrasil75 Date: Wed, 21 Jan 2026 10:13:39 -0500 Subject: [PATCH] add fp16 with fp32 fallback --- tests/g3test2.cpp | 6 +-- util/vectorlogic/vec3.hpp | 83 ++++----------------------------------- 2 files changed, 10 insertions(+), 79 deletions(-) diff --git a/tests/g3test2.cpp b/tests/g3test2.cpp index f993274..2b25f78 100644 --- a/tests/g3test2.cpp +++ b/tests/g3test2.cpp @@ -23,9 +23,9 @@ struct defaults { int outWidth = 512; int outHeight = 512; - int gridWidth = 128; - int gridHeight = 128; - int gridDepth = 128; + int gridWidth = 512; + int gridHeight = 512; + int gridDepth = 512; float fps = 30.0f; PNoise2 noise = PNoise2(42); }; diff --git a/util/vectorlogic/vec3.hpp b/util/vectorlogic/vec3.hpp index 4b600b5..03fe95e 100644 --- a/util/vectorlogic/vec3.hpp +++ b/util/vectorlogic/vec3.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "vec2.hpp" #ifdef __SSE__ @@ -41,6 +42,7 @@ public: for (size_t i = 0; i < count; ++i) { result[i] = a[i] + b[i]; } + return *this; } template @@ -517,83 +519,12 @@ public: } }; -// #ifdef __SSE__ -// template<> -// class Vec3 { -// union { -// __m128 simd; -// struct { float x, y, z, w; }; -// } -// public: - -// Vec3() noexcept : simd(_mm_setzero_ps()) {} - -// Vec3(float x, float y, float z) noexcept { -// simd = _mm_set_ps(0.0f, z, y, x); -// } - -// Vec3(float scalar) noexcept { -// simd = _mm_set_ps(0.0f, scalar, scalar, scalar); -// } - -// Vec3(const Vec3& other) noexcept : simd(other.simd) {} - -// Vec3& operator=(const Vec3& other) noexcept { -// simd = other.simd; -// return *this; -// } - -// Vec3 operator+(const Vec3& other) const noexcept { -// Vec3 result; -// result.simd = _mm_add_ps(simd, other.simd); -// return result; -// } - -// Vec3 operator-(const Vec3& other) const noexcept { -// Vec3 result; -// result.simd = _mm_sub_ps(simd, other.simd); -// return result; -// } - -// Vec3 operator*(const Vec3& other) const noexcept { -// Vec3 result; -// result.simd = _mm_mul_ps(simd, other.simd); -// return result; -// } - -// Vec3 operator*(float scalar) const noexcept { -// Vec3 result; -// __m128 scalar_vec = _mm_set1_ps(scalar); -// result.simd = _mm_mul_ps(simd, scalar_vec); -// return result; -// } - -// float dot(const Vec3& other) const noexcept { -// __m128 mul = _mm_mul_ps(simd, other.simd); -// __m128 shuf = _mm_movehdup_ps(mul); -// __m128 sums = _mm_add_ps(mul, shuf); -// shuf = _mm_movehl_ps(shuf, sums); -// sums = _mm_add_ss(sums, shuf); -// return _mm_cvtss_f32(sums); -// } - -// // Add other necessary methods for the specialization -// float length() const { -// float len_sq = dot(*this); -// return std::sqrt(len_sq); -// } - -// Vec3 normalized() const { -// float len = length(); -// if (len > 0) { -// return *this * (1.0f / len); -// } -// return *this; -// } -// }; -// #endif - +//use a smaller format first instead of larger format. +#ifdef std::float16_t +using Vec3f = Vec3; +#else using Vec3f = Vec3; +#endif using Vec3d = Vec3; using Vec3i = Vec3; using Vec3i32 = Vec3;