28#ifndef VC_COMMON_MALLOC_H_
29#define VC_COMMON_MALLOC_H_
31#ifndef Vc_VECTOR_DECLARED_
32#error "Incorrect inclusion order. This header must be included from Vc/vector.h only."
35#if defined _WIN32 || defined _WIN64
43namespace Vc_VERSIONED_NAMESPACE
48template <
size_t X>
static constexpr size_t nextMultipleOf(
size_t value)
50 return (value % X) > 0 ? value + X - (value % X) : value;
53template <std::
size_t alignment> Vc_INTRINSIC
void *aligned_malloc(std::size_t n)
56 return _mm_malloc(nextMultipleOf<alignment>(n), alignment);
59 return __mingw_aligned_malloc(nextMultipleOf<alignment>(n), alignment);
61 return _aligned_malloc(nextMultipleOf<alignment>(n), alignment);
65 if (0 == posix_memalign(&ptr, alignment <
sizeof(
void *) ?
sizeof(
void *) : alignment,
66 nextMultipleOf<alignment>(n))) {
73template <Vc::MallocAlignment A> Vc_ALWAYS_INLINE
void *malloc(
size_t n)
77 return aligned_malloc<Vc::VectorAlignment>(n);
80 return aligned_malloc<64>(n);
83 return aligned_malloc<4096>(n);
88Vc_ALWAYS_INLINE
void free(
void *p)
94 return __mingw_aligned_free(p);
96 return _aligned_free(p);
135template<
typename T, Vc::MallocAlignment A>
136Vc_ALWAYS_INLINE T *malloc(
size_t n)
138 return static_cast<T *
>(Common::malloc<A>(n *
sizeof(T)));
163Vc_ALWAYS_INLINE
void free(T *p)
@ AlignOnPage
Align on boundary of page sizes (e.g.
@ AlignOnCacheline
Align on boundary of cache line sizes (e.g.
@ AlignOnVector
Align on boundary of vector sizes (e.g.