From 406326b37876aaedcc9cdfb05d41b758b774cc40 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 24 Jan 2019 05:14:17 +0100 Subject: [PATCH] util-math: Add 16-byte aligned version of vec2 --- source/util-math.cpp | 20 ++++++++++++++++++ source/util-math.hpp | 48 ++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/source/util-math.cpp b/source/util-math.cpp index b2462dae..e45f6c17 100644 --- a/source/util-math.cpp +++ b/source/util-math.cpp @@ -22,6 +22,26 @@ #include #include "util-memory.hpp" +void* util::vec2a::operator new(size_t count) +{ + return aligned_alloc(count, 16); +} + +void* util::vec2a::operator new[](size_t count) +{ + return aligned_alloc(count, 16); +} + +void util::vec2a::operator delete(void* p) +{ + aligned_free(p); +} + +void util::vec2a::operator delete[](void* p) +{ + aligned_free(p); +} + void* util::vec3a::operator new(size_t count) { return aligned_alloc(count, 16); diff --git a/source/util-math.hpp b/source/util-math.hpp index 8dc11380..661187c9 100644 --- a/source/util-math.hpp +++ b/source/util-math.hpp @@ -67,24 +67,37 @@ inline size_t GetNearestPowerOfTwoBelow(size_t v) } namespace util { - #ifdef _MSC_VER +#ifdef _MSC_VER __declspec(align(16)) - #endif - struct vec3a : public vec3 { +#endif + struct vec2a : public vec2 { + // 16-byte Aligned version of vec2 static void* operator new(size_t count); static void* operator new[](size_t count); - static void operator delete(void* p); - static void operator delete[](void* p); + static void operator delete(void* p); + static void operator delete[](void* p); }; - #ifdef _MSC_VER +#ifdef _MSC_VER __declspec(align(16)) - #endif - struct vec4a : public vec4 { +#endif + struct vec3a : public vec3 { + // 16-byte Aligned version of vec3 static void* operator new(size_t count); static void* operator new[](size_t count); - static void operator delete(void* p); - static void operator delete[](void* p); + static void operator delete(void* p); + static void operator delete[](void* p); + }; + +#ifdef _MSC_VER + __declspec(align(16)) +#endif + struct vec4a : public vec4 { + // 16-byte Aligned version of vec4 + static void* operator new(size_t count); + static void* operator new[](size_t count); + static void operator delete(void* p); + static void operator delete[](void* p); }; std::pair SizeFromString(std::string text, bool allowSquare = true); @@ -122,19 +135,14 @@ namespace util { { \ return is_power_of_two_loop(v); \ } - is_power_of_two_as_loop(int8_t) - is_power_of_two_as_loop(uint8_t) - is_power_of_two_as_loop(int16_t) - is_power_of_two_as_loop(uint16_t) - is_power_of_two_as_loop(int32_t) - is_power_of_two_as_loop(uint32_t) - is_power_of_two_as_loop(int64_t) - is_power_of_two_as_loop(uint64_t) + is_power_of_two_as_loop(int8_t) is_power_of_two_as_loop(uint8_t) is_power_of_two_as_loop(int16_t) + is_power_of_two_as_loop(uint16_t) is_power_of_two_as_loop(int32_t) is_power_of_two_as_loop(uint32_t) + is_power_of_two_as_loop(int64_t) is_power_of_two_as_loop(uint64_t) #undef is_power_of_two_as_loop #pragma pop_macro("is_power_of_two_as_loop") - template - inline uint64_t get_power_of_two_exponent_floor(T v) + template + inline uint64_t get_power_of_two_exponent_floor(T v) { return uint64_t(floor(log10(T(v)) / log10(2.0))); }