Merge branch 'remove_aligned_alloc' into 'master'

Remove AlignedAlloc

See merge request jschoeberl/netgen!198
This commit is contained in:
Joachim Schöberl 2019-08-14 13:25:40 +00:00
commit 21f5e5a894
5 changed files with 52 additions and 41 deletions

View File

@ -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 <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

View File

@ -40,7 +40,7 @@ namespace ngcore
{
// PajeTrace *trace;
class alignas(64) NodeData : public AlignedAlloc<NodeData>
class alignas(64) NodeData
{
public:
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> end;

View File

@ -75,35 +75,6 @@ namespace ngcore
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
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
{
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<double,2> // : public AlignedAlloc<SIMD<double,4>>
class alignas(16) SIMD<double,2>
{
__m128d data;
@ -360,7 +358,7 @@ using std::fabs;
/////////////////////////////////////////////////////////////////////////////
#ifdef __AVX__
template<>
class alignas(32) SIMD<double,4> : public AlignedAlloc<SIMD<double,4>>
class alignas(32) SIMD<double,4>
{
__m256d data;
@ -457,7 +455,7 @@ using std::fabs;
/////////////////////////////////////////////////////////////////////////////
#ifdef __AVX512F__
template<>
class alignas(64) SIMD<double,8> : public AlignedAlloc<SIMD<double,8>>
class alignas(64) SIMD<double,8>
{
__m512d data;
@ -559,7 +557,7 @@ using std::fabs;
// MultiSIMD - Multiple SIMD values in one struct using head-tail implementation
////////////////////////////////////////////////////////////////////////////////
template <int D, typename T>
class MultiSIMD : public AlignedAlloc<MultiSIMD<D,T>>
class MultiSIMD
{
SIMD<T> head;
MultiSIMD<D-1,T> tail;
@ -584,7 +582,7 @@ using std::fabs;
};
template <typename T>
class MultiSIMD<2,T> : public AlignedAlloc<MultiSIMD<2,T>>
class MultiSIMD<2,T>
{
SIMD<T> v0, v1;
public:

View File

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