Remove AlignedAlloc

Instead, use a global new (size_t, align_t) operator for MacOS versions
(pre 10.14 is lacking full C++17 support in the standard library).

On all other platforms/versions we expect full C++17 support.
This commit is contained in:
Matthias Hochsteger 2019-08-14 13:09:57 +02:00
parent 15e68020ba
commit 3ce00d1a0c
5 changed files with 52 additions and 41 deletions

View File

@ -34,4 +34,46 @@
#endif #endif
#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 <mm_malloc.h>
#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 #endif // NETGEN_CORE_NGCORE_API_HPP

View File

@ -40,7 +40,7 @@ namespace ngcore
{ {
// PajeTrace *trace; // PajeTrace *trace;
class alignas(64) NodeData : public AlignedAlloc<NodeData> class alignas(64) NodeData
{ {
public: public:
atomic<int> start_cnt{0}; atomic<int> start_cnt{0};
@ -392,7 +392,7 @@ public:
class alignas(4096) AtomicRange : public AlignedAlloc<AtomicRange> class alignas(4096) AtomicRange
{ {
atomic<size_t> begin; atomic<size_t> begin;
atomic<size_t> end; atomic<size_t> end;

View File

@ -75,35 +75,6 @@ namespace ngcore
b = std::move(temp); b = std::move(temp);
} }
template <typename T>
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 // checks if string starts with sequence
inline bool StartsWith(const std::string& str, const std::string& start) inline bool StartsWith(const std::string& str, const std::string& start)
{ {

View File

@ -50,8 +50,6 @@ NG_INLINE __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; }
namespace ngsimd namespace ngsimd
{ {
using ngcore::AlignedAlloc;
// MSVC does not define SSE. It's always present on 64bit cpus // MSVC does not define SSE. It's always present on 64bit cpus
#if (defined(_M_AMD64) || defined(_M_X64) || defined(__AVX__)) #if (defined(_M_AMD64) || defined(_M_X64) || defined(__AVX__))
#ifndef __SSE__ #ifndef __SSE__
@ -260,7 +258,7 @@ using std::fabs;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __SSE__ #ifdef __SSE__
template<> template<>
class alignas(16) SIMD<double,2> // : public AlignedAlloc<SIMD<double,4>> class alignas(16) SIMD<double,2>
{ {
__m128d data; __m128d data;
@ -360,7 +358,7 @@ using std::fabs;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __AVX__ #ifdef __AVX__
template<> template<>
class alignas(32) SIMD<double,4> : public AlignedAlloc<SIMD<double,4>> class alignas(32) SIMD<double,4>
{ {
__m256d data; __m256d data;
@ -457,7 +455,7 @@ using std::fabs;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __AVX512F__ #ifdef __AVX512F__
template<> template<>
class alignas(64) SIMD<double,8> : public AlignedAlloc<SIMD<double,8>> class alignas(64) SIMD<double,8>
{ {
__m512d data; __m512d data;
@ -559,7 +557,7 @@ using std::fabs;
// MultiSIMD - Multiple SIMD values in one struct using head-tail implementation // MultiSIMD - Multiple SIMD values in one struct using head-tail implementation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <int D, typename T> template <int D, typename T>
class MultiSIMD : public AlignedAlloc<MultiSIMD<D,T>> class MultiSIMD
{ {
SIMD<T> head; SIMD<T> head;
MultiSIMD<D-1,T> tail; MultiSIMD<D-1,T> tail;
@ -584,7 +582,7 @@ using std::fabs;
}; };
template <typename T> template <typename T>
class MultiSIMD<2,T> : public AlignedAlloc<MultiSIMD<2,T>> class MultiSIMD<2,T>
{ {
SIMD<T> v0, v1; SIMD<T> v0, v1;
public: public:

View File

@ -17,7 +17,7 @@ namespace netgen
template <int D, typename T> template <int D, typename T>
class Point : public ngsimd::AlignedAlloc<Point<D,T>> class Point
{ {
protected: protected:
@ -73,7 +73,7 @@ namespace netgen
}; };
template <int D, typename T> template <int D, typename T>
class Vec : public ngsimd::AlignedAlloc<Vec<D,T>> class Vec
{ {
protected: protected:
@ -162,7 +162,7 @@ namespace netgen
template <int H, int W=H, typename T = double> template <int H, int W=H, typename T = double>
class Mat : public ngsimd::AlignedAlloc<Mat<H,W,T>> class Mat
{ {
protected: protected: