20 #ifndef VC_COMMON_MEMORY_H
21 #define VC_COMMON_MEMORY_H
66 template<
typename T, Vc::MallocAlignment A>
69 return static_cast<T *
>(Internal::Helper::malloc<A>(n *
sizeof(
T)));
120 template<
typename V,
size_t Size1,
size_t Size2>
class Memory :
public VectorAlignedBaseT<V>,
public MemoryBase<V, Memory<V, Size1, Size2>, 2, Memory<V, Size2> >
131 #if defined(VC_ICC) && defined(_WIN32)
132 __declspec(align(__alignof(VectorAlignedBaseT<V>)))
133 #elif defined(VC_CLANG)
134 __attribute__((aligned(__alignof(VectorAlignedBaseT<V>))))
135 #elif defined(VC_MSVC)
136 VectorAlignedBaseT<V> _force_alignment;
180 template<
typename Parent,
typename RM>
206 #if defined(VC_ICC) && VC_ICC < 20120212 && !defined(_WIN32)
207 __attribute__((__aligned__(__alignof(VectorAlignedBaseT<V>))))
254 template<
typename V,
size_t Size>
class Memory<V,
Size, 0u> :
public VectorAlignedBaseT<V>,
public MemoryBase<V, Memory<V, Size, 0u>, 1, void>
259 typedef MemoryBase<V, Memory<V, Size, 0u>, 1,
void>
Base;
264 AlignmentMask = Alignment - 1,
265 MaskedSize =
Size & AlignmentMask,
266 Padding = Alignment - MaskedSize,
267 PaddedSize = MaskedSize == 0 ?
Size :
Size + Padding
269 #if defined(VC_ICC) && defined(_WIN32)
270 __declspec(align(__alignof(VectorAlignedBaseT<V>)))
271 #elif defined(VC_CLANG)
272 __attribute__((aligned(__alignof(VectorAlignedBaseT<V>))))
273 #elif defined(VC_MSVC)
274 VectorAlignedBaseT<V> _force_alignment;
314 char *addr =
reinterpret_cast<char *
>(ptr);
317 return *
new(addr) MM;
365 std::memcpy(m_mem, rhs,
entriesCount() *
sizeof(EntryType));
375 #if defined(VC_ICC) && VC_ICC < 20120212 && !defined(_WIN32)
376 __attribute__((__aligned__(__alignof(VectorAlignedBaseT<V>)) ))
420 template<
typename V>
class Memory<V, 0u, 0u> :
public MemoryBase<V, Memory<V, 0u, 0u>, 1, void>
430 AlignmentMask = Alignment - 1
437 size_t masked = x & AlignmentMask;
438 return (masked == 0 ? x : x + (Alignment - masked));
451 : m_entriesCount(size),
452 m_vectorsCount(calcPaddedEntriesCount(m_entriesCount)),
465 template<
typename Parent,
typename RM>
503 std::swap(m_mem, rhs.
m_mem);
504 std::swap(m_entriesCount, rhs.m_entriesCount);
505 std::swap(m_vectorsCount, rhs.m_vectorsCount);
527 template<
typename Parent,
typename RM>
550 std::memcpy(m_mem, rhs,
entriesCount() *
sizeof(EntryType));
642 #endif // VC_COMMON_MEMORY_H
Memory & operator=(const Memory< V, S > &rhs)
Vc_ALWAYS_INLINE Memory & operator=(const EntryType *rhs)
Namespace for new ROOT classes and functions.
Vc_ALWAYS_INLINE Vc_PURE size_t vectorsCount() const
Vc_ALWAYS_INLINE Vc_PURE size_t entriesCount() const
EntryType m_mem[Size1][PaddedSize2]
Memory(const Memory &rhs)
_VC_CONSTEXPR size_t entriesCount() const
Memory & operator=(const Memory &rhs)
void swap(ROOT::THist< DIMENSIONS, PRECISION > &a, ROOT::THist< DIMENSIONS, PRECISION > &b) noexcept
Swap two histograms.
_VC_CONSTEXPR size_t vectorsCount() const
Memory & operator=(const V &v)
Initialize all data with the given vector.
Vc_ALWAYS_INLINE Memory & operator=(const EntryType *rhs)
Overwrite all entries with the values stored in the memory at rhs.
#define VC_OFFSETOF(Type, member)
Vc_ALWAYS_INLINE void prefetchForModify(const void *addr)
Prefetch the cacheline containing addr for modification.
_VC_CONSTEXPR size_t entriesCount() const
void swap(Memory &rhs)
Swap the contents and size information of two Memory objects.
Vc_ALWAYS_INLINE Memory & operator=(const MemoryBase< V, Parent, 1, RM > &rhs)
Overwrite all entries with the values stored in rhs.
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Vc_ALWAYS_INLINE Vc_PURE size_t vectorsCount() const
Vc_ALWAYS_INLINE Memory(const MemoryBase< V, Parent, 1, RM > &rhs)
Copy the memory into a new memory area.
Vc_ALWAYS_INLINE Memory(const Memory &rhs)
Overload of the above function.
Memory(const Memory< V, S > &rhs)
Vc_ALWAYS_INLINE void prefetchForOneRead(const void *addr)
Prefetch the cacheline containing addr for a single read access.
Vc_ALWAYS_INLINE void prefetchClose(const void *addr)
Prefetch the cacheline containing addr to L1 cache.
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlag > vector(size_t i)
#define Vc_ALWAYS_INLINE_R
Vc_ALWAYS_INLINE void prefetchMid(const void *addr)
Prefetch the cacheline containing addr to L2 cache.
Vc_ALWAYS_INLINE Memory & operator=(const Memory &rhs)
Vc_ALWAYS_INLINE void prefetchFar(const void *addr)
Prefetch the cacheline containing addr to L3 cache.
Vc_ALWAYS_INLINE ~Memory()
Frees the memory which was allocated in the constructor.
size_t calcPaddedEntriesCount(size_t x)
_VC_CONSTEXPR size_t vectorsCount() const
Align on boundary of vector sizes (e.g.
Vc_ALWAYS_INLINE Memory(size_t size)
Allocate enough memory to access size values of type V::EntryType.
MemoryBase< V, Memory< V, Size1, Size2 >, 2, Memory< V, Size2 > > Base
Vc_ALWAYS_INLINE Memory()
A helper class for fixed-size two-dimensional arrays.
Vc_ALWAYS_INLINE Memory & operator=(const MemoryBase< V, Parent, 2, RM > &rhs)
Copies the data from a different object.
#define Vc_ALWAYS_INLINE_L
_VC_CONSTEXPR size_t rowsCount() const
A helper class to simplify usage of correctly aligned and padded memory, allowing both vector and sca...
typedef void((*Func_t)())
MemoryBase< V, Memory< V, Size, 0u >, 1, void > Base
Common interface to all Memory classes, independent of allocation on the stack or heap...
MemoryBase< V, Memory< V >, 1, void > Base
static Vc_ALWAYS_INLINE Vc_CONST Memory< V, Size, 0u > & fromRawData(EntryType *ptr)
Wrap existing data with the Memory convenience class.
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
Vc_ALWAYS_INLINE Memory & operator=(const Memory &rhs)
Memory & operator=(const V &v)
void copyVectors(MemoryBase< V, ParentL, Dimension, RowMemoryL > &dst, const MemoryBase< V, ParentR, Dimension, RowMemoryR > &src)