diff --git a/libsrc/core/ngcore_api.hpp b/libsrc/core/ngcore_api.hpp index a84a1381..dfdee659 100644 --- a/libsrc/core/ngcore_api.hpp +++ b/libsrc/core/ngcore_api.hpp @@ -34,4 +34,46 @@ #endif #endif +#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101400 +// The c++ standard library on MacOS 10.13 and earlier has no aligned new operator, +// thus implement it here globally +#include +#ifdef __clang__ +#pragma clang diagnostic ignored "-Winline-new-delete" +#endif +inline void * operator new (size_t s, std::align_val_t al) +{ + if (int(al) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + return _mm_malloc(s, int(al)); + else + return new char[s]; +} + +inline void * operator new[] (size_t s, std::align_val_t al) +{ + if (int(al) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + return _mm_malloc(s, int(al)); + else + return new char[s]; +} + +inline void operator delete ( void* ptr, std::align_val_t al ) noexcept +{ + if (int(al) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + _mm_free(ptr); + else + delete (char*)ptr; +} + +inline void operator delete[]( void* ptr, std::align_val_t al ) noexcept +{ + if (int(al) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + _mm_free(ptr); + else + delete[] (char*)ptr; +} +#endif // __MAC_OS_X_VERSION_MIN_REQUIRED +#endif // __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 + #endif // NETGEN_CORE_NGCORE_API_HPP diff --git a/libsrc/core/taskmanager.hpp b/libsrc/core/taskmanager.hpp index c8373627..f0b67746 100644 --- a/libsrc/core/taskmanager.hpp +++ b/libsrc/core/taskmanager.hpp @@ -40,7 +40,7 @@ namespace ngcore { // PajeTrace *trace; - class alignas(64) NodeData : public AlignedAlloc + class alignas(64) NodeData { public: atomic start_cnt{0}; @@ -392,7 +392,7 @@ public: - class alignas(4096) AtomicRange : public AlignedAlloc + class alignas(4096) AtomicRange { atomic begin; atomic end; diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index e1da760c..1eb6d7bd 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -75,35 +75,6 @@ namespace ngcore b = std::move(temp); } - template - class AlignedAlloc - { - protected: - static void * aligned_malloc(size_t s) - { - // Assume 16 byte alignment of standard library - if(alignof(T)<=16) - return malloc(s); - else - return _mm_malloc(s, alignof(T)); - } - - static void aligned_free(void *p) - { - if(alignof(T)<=16) - free(p); - else - _mm_free(p); - } - - public: - void * operator new (size_t s, void *p) { return p; } - void * operator new (size_t s) { return aligned_malloc(s); } - void * operator new[] (size_t s) { return aligned_malloc(s); } - void operator delete (void * p) { aligned_free(p); } - void operator delete[] (void * p) { aligned_free(p); } - }; - // checks if string starts with sequence inline bool StartsWith(const std::string& str, const std::string& start) { diff --git a/libsrc/general/ngsimd.hpp b/libsrc/general/ngsimd.hpp index feba2523..9170e402 100644 --- a/libsrc/general/ngsimd.hpp +++ b/libsrc/general/ngsimd.hpp @@ -50,8 +50,6 @@ NG_INLINE __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; } namespace ngsimd { - using ngcore::AlignedAlloc; - // MSVC does not define SSE. It's always present on 64bit cpus #if (defined(_M_AMD64) || defined(_M_X64) || defined(__AVX__)) #ifndef __SSE__ @@ -260,7 +258,7 @@ using std::fabs; ///////////////////////////////////////////////////////////////////////////// #ifdef __SSE__ template<> - class alignas(16) SIMD // : public AlignedAlloc> + class alignas(16) SIMD { __m128d data; @@ -360,7 +358,7 @@ using std::fabs; ///////////////////////////////////////////////////////////////////////////// #ifdef __AVX__ template<> - class alignas(32) SIMD : public AlignedAlloc> + class alignas(32) SIMD { __m256d data; @@ -457,7 +455,7 @@ using std::fabs; ///////////////////////////////////////////////////////////////////////////// #ifdef __AVX512F__ template<> - class alignas(64) SIMD : public AlignedAlloc> + class alignas(64) SIMD { __m512d data; @@ -559,7 +557,7 @@ using std::fabs; // MultiSIMD - Multiple SIMD values in one struct using head-tail implementation //////////////////////////////////////////////////////////////////////////////// template - class MultiSIMD : public AlignedAlloc> + class MultiSIMD { SIMD head; MultiSIMD tail; @@ -584,7 +582,7 @@ using std::fabs; }; template - class MultiSIMD<2,T> : public AlignedAlloc> + class MultiSIMD<2,T> { SIMD v0, v1; public: diff --git a/libsrc/gprim/geomobjects.hpp b/libsrc/gprim/geomobjects.hpp index 5b028c99..280cb523 100644 --- a/libsrc/gprim/geomobjects.hpp +++ b/libsrc/gprim/geomobjects.hpp @@ -17,7 +17,7 @@ namespace netgen template - class Point : public ngsimd::AlignedAlloc> + class Point { protected: @@ -73,7 +73,7 @@ namespace netgen }; template - class Vec : public ngsimd::AlignedAlloc> + class Vec { protected: @@ -162,7 +162,7 @@ namespace netgen template - class Mat : public ngsimd::AlignedAlloc> + class Mat { protected: