From 2c74626e66e5fd88683348f37f4b30ab397bf55b Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 9 Jul 2025 12:20:10 +0200 Subject: Core/Random: Use standard aligned operator new and remove RandomEngine singleton instance (it is trivially constructible) --- src/common/Utilities/SFMTRand.cpp | 77 ++------------------------------------- 1 file changed, 3 insertions(+), 74 deletions(-) (limited to 'src/common/Utilities/SFMTRand.cpp') diff --git a/src/common/Utilities/SFMTRand.cpp b/src/common/Utilities/SFMTRand.cpp index 63918fce710..e39cfa1bc46 100644 --- a/src/common/Utilities/SFMTRand.cpp +++ b/src/common/Utilities/SFMTRand.cpp @@ -22,44 +22,13 @@ #include #include -#if __has_include() -#include -#elif __has_include() && TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT -#include -#else -static __inline__ void *__attribute__((__always_inline__, __nodebug__, __malloc__)) -_mm_malloc(size_t __size, size_t __align) -{ - if (__align == 1) - { - return malloc(__size); - } - - if (!(__align & (__align - 1)) && __align < sizeof(void *)) - __align = sizeof(void *); - - void *__mallocedMemory; - - if (posix_memalign(&__mallocedMemory, __align, __size)) - return NULL; - - return __mallocedMemory; -} - -static __inline__ void __attribute__((__always_inline__, __nodebug__)) -_mm_free(void *__p) -{ - free(__p); -} -#endif - -SFMTRand::SFMTRand() +SFMTRand::SFMTRand() noexcept { std::random_device dev; if (dev.entropy() > 0) { std::array seed; - std::generate(seed.begin(), seed.end(), std::ref(dev)); + std::ranges::generate(seed, std::ref(dev)); sfmt_init_by_array(&_state, seed.data(), seed.size()); } @@ -67,47 +36,7 @@ SFMTRand::SFMTRand() sfmt_init_gen_rand(&_state, uint32(time(nullptr))); } -uint32 SFMTRand::RandomUInt32() // Output random bits +uint32 SFMTRand::RandomUInt32() noexcept // Output random bits { return sfmt_genrand_uint32(&_state); } - -void* SFMTRand::operator new(size_t size, std::nothrow_t const&) -{ - return _mm_malloc(size, 16); -} - -void SFMTRand::operator delete(void* ptr, std::nothrow_t const&) -{ - _mm_free(ptr); -} - -void* SFMTRand::operator new(size_t size) -{ - return _mm_malloc(size, 16); -} - -void SFMTRand::operator delete(void* ptr) -{ - _mm_free(ptr); -} - -void* SFMTRand::operator new[](size_t size, std::nothrow_t const&) -{ - return _mm_malloc(size, 16); -} - -void SFMTRand::operator delete[](void* ptr, std::nothrow_t const&) -{ - _mm_free(ptr); -} - -void* SFMTRand::operator new[](size_t size) -{ - return _mm_malloc(size, 16); -} - -void SFMTRand::operator delete[](void* ptr) -{ - _mm_free(ptr); -} -- cgit v1.2.3