1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #if (defined(__ICL) || defined(_MSC_VER) || defined(__ICC))
#include <fvec.h>
inline void *aligned_malloc (size_t size, size_t align=16) { return _mm_malloc(size,align); }
inline void aligned_free (void *p) { return _mm_free(p); }
#elif defined (__CYGWIN__)
#include <xmmintrin.h>
inline void *aligned_malloc (size_t size, size_t align=16) { return _mm_malloc(size,align); }
inline void aligned_free (void *p) { return _mm_free(p); }
#elif defined(__MINGW64__)
#include <malloc.h>
inline void *aligned_malloc (size_t size, size_t align=16) { return malloc(size+align); }
inline void aligned_free (void *p) { return free(p); }
#elif defined(__MINGW32__)
#include <malloc.h>
inline void *aligned_malloc (size_t size, size_t align=16) { return __mingw_aligned_malloc(size,align); }
inline void aligned_free (void *p) { return __mingw_aligned_free(p); }
#elif defined(__FreeBSD__)
#include <stdlib.h>
inline void* aligned_malloc (size_t size, size_t align=16) { return malloc(size); }
inline void aligned_free (void *p) { return free(p); }
#elif (defined(__MACOSX__) || defined(__APPLE__))
#include <stdlib.h>
inline void* aligned_malloc (size_t size, size_t align=16) { return malloc(size); }
inline void aligned_free (void *p) { return free(p); }
#else
#include <malloc.h>
inline void* aligned_malloc (size_t size, size_t align=16) { return memalign(align,size); }
inline void aligned_free (void *p) { return free(p); }
#endif
template<class T, int N=16> class alignment_allocator
{
public:
typedef T value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
public:
inline alignment_allocator() throw() {}
template <class T2> inline alignment_allocator(const alignment_allocator<T2,N>&) throw() {}
inline ~alignment_allocator() throw() {}
inline pointer address(reference r) { return &r; }
inline const_pointer address(const_reference r) const { return &r; }
inline pointer allocate(size_type n) { return (pointer)aligned_malloc(n*sizeof(value_type),N); }
inline void deallocate(pointer p, size_type) { aligned_free(p); }
inline void construct (pointer p,const value_type& val) { new (p) value_type(val); }
inline void destroy (pointer p ) { p->~value_type(); }
inline size_type max_size() const throw() { return size_type(-1)/sizeof(value_type); }
template<class T2> struct rebind { typedef alignment_allocator<T2,N> other; };
}; |
Partager