1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-14 01:35:36 +00:00
Grid/lib/Grid_aligned_allocator.h

65 lines
1.8 KiB
C
Raw Normal View History

2015-03-04 05:31:44 +00:00
#ifndef GRID_ALIGNED_ALLOCATOR_H
#define GRID_ALIGNED_ALLOCATOR_H
#include <immintrin.h>
2015-04-03 05:29:54 +01:00
namespace Grid {
2015-03-04 05:31:44 +00:00
////////////////////////////////////////////////////////////////////
// A lattice of something, but assume the something is SIMDized.
////////////////////////////////////////////////////////////////////
template<typename _Tp>
class alignedAllocator {
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template<typename _Tp1> struct rebind { typedef alignedAllocator<_Tp1> other; };
2015-03-04 05:31:44 +00:00
alignedAllocator() throw() { }
2015-03-04 05:31:44 +00:00
alignedAllocator(const alignedAllocator&) throw() { }
2015-03-04 05:31:44 +00:00
template<typename _Tp1> alignedAllocator(const alignedAllocator<_Tp1>&) throw() { }
2015-03-04 05:31:44 +00:00
~alignedAllocator() throw() { }
pointer address(reference __x) const { return &__x; }
2015-03-04 05:31:44 +00:00
const_pointer address(const_reference __x) const { return &__x; }
2015-03-04 05:31:44 +00:00
size_type max_size() const throw() { return size_t(-1) / sizeof(_Tp); }
2015-03-04 05:31:44 +00:00
pointer allocate(size_type __n, const void* = 0)
{
#ifdef AVX512
_Tp * ptr = (_Tp *) memalign(128,__n*sizeof(_Tp));
#else
_Tp * ptr = (_Tp *) _mm_malloc(__n*sizeof(_Tp),128);
#endif
return ptr;
}
2015-03-04 05:31:44 +00:00
void deallocate(pointer __p, size_type) {
free(__p);
}
void construct(pointer __p, const _Tp& __val) { };
void construct(pointer __p) { };
2015-03-04 05:31:44 +00:00
void destroy(pointer __p) { };
};
template<typename _Tp> inline bool
operator==(const alignedAllocator<_Tp>&, const alignedAllocator<_Tp>&){ return true; }
template<typename _Tp> inline bool
operator!=(const alignedAllocator<_Tp>&, const alignedAllocator<_Tp>&){ return false; }
2015-04-03 05:29:54 +01:00
}; // namespace Grid
2015-03-04 05:31:44 +00:00
#endif