ROOT  6.06/09
Reference Guide
memory.h
Go to the documentation of this file.
1 /* This file is part of the Vc library.
2 
3  Copyright (C) 2009-2012 Matthias Kretz <kretz@kde.org>
4 
5  Vc is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as
7  published by the Free Software Foundation, either version 3 of
8  the License, or (at your option) any later version.
9 
10  Vc is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with Vc. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef VC_COMMON_MEMORY_H
21 #define VC_COMMON_MEMORY_H
22 
23 #include "memorybase.h"
24 #include <assert.h>
25 #include <algorithm>
26 #include <cstring>
27 #include <cstddef>
28 #include "memoryfwd.h"
29 #include "macros.h"
30 
31 namespace ROOT {
32 namespace Vc
33 {
34 
35 /**
36  * Allocates memory on the Heap with alignment and padding suitable for vectorized access.
37  *
38  * Memory that was allocated with this function must be released with Vc::free! Other methods might
39  * work but are not portable.
40  *
41  * \param n Specifies the number of objects the allocated memory must be able to store.
42  * \tparam T The type of the allocated memory. Note, that the constructor is not called.
43  * \tparam A Determines the alignment of the memory. See \ref Vc::MallocAlignment.
44  *
45  * \return Pointer to memory of the requested type, or 0 on error. The allocated memory is padded at
46  * the end to be a multiple of the requested alignment \p A. Thus if you request memory for 21
47  * int objects, aligned via Vc::AlignOnCacheline, you can safely read a full cacheline until the
48  * end of the array, without generating an out-of-bounds access. For a cacheline size of 64 Bytes
49  * and an int size of 4 Bytes you would thus get an array of 128 Bytes to work with.
50  *
51  * \warning
52  * \li The standard malloc function specifies the number of Bytes to allocate whereas this
53  * function specifies the number of values, thus differing in a factor of sizeof(T).
54  * \li This function is mainly meant for use with builtin types. If you use a custom
55  * type with a sizeof that is not a multiple of 2 the results might not be what you expect.
56  * \li The constructor of T is not called. You can make up for this:
57  * \code
58  * SomeType *array = new(Vc::malloc<SomeType, Vc::AlignOnCacheline>(N)) SomeType[N];
59  * \endcode
60  *
61  * \see Vc::free
62  *
63  * \ingroup Utilities
64  * \headerfile memory.h <Vc/Memory>
65  */
66 template<typename T, Vc::MallocAlignment A>
68 {
69  return static_cast<T *>(Internal::Helper::malloc<A>(n * sizeof(T)));
70 }
71 
72 /**
73  * Frees memory that was allocated with Vc::malloc.
74  *
75  * \param p The pointer to the memory to be freed.
76  *
77  * \tparam T The type of the allocated memory.
78  *
79  * \warning The destructor of T is not called. If needed, you can call the destructor before calling
80  * free:
81  * \code
82  * for (int i = 0; i < N; ++i) {
83  * p[i].~T();
84  * }
85  * Vc::free(p);
86  * \endcode
87  *
88  * \ingroup Utilities
89  * \headerfile memory.h <Vc/Memory>
90  *
91  * \see Vc::malloc
92  */
93 template<typename T>
95 {
97 }
98 
99 template<typename V, size_t Size> struct _MemorySizeCalculation
100 {
106  PaddedSize = MaskedSize == 0 ? Size : Size + Padding
107  };
108 };
109 
110 /**
111  * \ingroup Utilities
112  * \headerfile memory.h <Vc/Memory>
113  *
114  * A helper class for fixed-size two-dimensional arrays.
115  *
116  * \param V The vector type you want to operate on. (e.g. float_v or uint_v)
117  * \param Size1 Number of rows
118  * \param Size2 Number of columns
119  */
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> >
121 {
122  public:
123  typedef typename V::EntryType EntryType;
124  private:
125  typedef MemoryBase<V, Memory<V, Size1, Size2>, 2, Memory<V, Size2> > Base;
126  friend class MemoryBase<V, Memory<V, Size1, Size2>, 2, Memory<V, Size2> >;
127  friend class MemoryDimensionBase<V, Memory<V, Size1, Size2>, 2, Memory<V, Size2> >;
130  };
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;
137  // __declspec(align(#)) accepts only numbers not __alignof nor just VectorAlignment
138  // by putting VectorAlignedBaseT<V> here _force_alignment is aligned correctly.
139  // the downside is that there's a lot of padding before m_mem (32 Bytes with SSE) :(
140 #endif
141  EntryType m_mem[Size1][PaddedSize2];
142  public:
143  using Base::vector;
144  enum Constants {
145  RowCount = Size1,
147  };
148 
149  /**
150  * \return the number of rows in the array.
151  *
152  * \note This function can be eliminated by an optimizing compiler.
153  */
154  _VC_CONSTEXPR size_t rowsCount() const { return RowCount; }
155  /**
156  * \return the number of scalar entries in the whole array.
157  *
158  * \warning Do not use this function for scalar iteration over the array since there will be
159  * padding between rows if \c Size2 is not divisible by \c V::Size.
160  *
161  * \note This function can be optimized into a compile-time constant.
162  */
163  _VC_CONSTEXPR size_t entriesCount() const { return Size1 * Size2; }
164  /**
165  * \return the number of vectors in the whole array.
166  *
167  * \note This function can be optimized into a compile-time constant.
168  */
169  _VC_CONSTEXPR size_t vectorsCount() const { return VectorsCount * Size1; }
170 
171  /**
172  * Copies the data from a different object.
173  *
174  * \param rhs The object to copy the data from.
175  *
176  * \return reference to the modified Memory object.
177  *
178  * \note Both objects must have the exact same vectorsCount().
179  */
180  template<typename Parent, typename RM>
182  assert(vectorsCount() == rhs.vectorsCount());
183  Internal::copyVectors(*this, rhs);
184  return *this;
185  }
186 
188  Internal::copyVectors(*this, rhs);
189  return *this;
190  }
191 
192  /**
193  * Initialize all data with the given vector.
194  *
195  * \param v This vector will be used to initialize the memory.
196  *
197  * \return reference to the modified Memory object.
198  */
199  inline Memory &operator=(const V &v) {
200  for (size_t i = 0; i < vectorsCount(); ++i) {
201  vector(i) = v;
202  }
203  return *this;
204  }
205  }
206 #if defined(VC_ICC) && VC_ICC < 20120212 && !defined(_WIN32)
207  __attribute__((__aligned__(__alignof(VectorAlignedBaseT<V>))))
208 #endif
209  ;
210 
211  /**
212  * A helper class to simplify usage of correctly aligned and padded memory, allowing both vector and
213  * scalar access.
214  *
215  * Example:
216  * \code
217  Vc::Memory<int_v, 11> array;
218 
219  // scalar access:
220  for (size_t i = 0; i < array.entriesCount(); ++i) {
221  int x = array[i]; // read
222  array[i] = x; // write
223  }
224  // more explicit alternative:
225  for (size_t i = 0; i < array.entriesCount(); ++i) {
226  int x = array.scalar(i); // read
227  array.scalar(i) = x; // write
228  }
229 
230  // vector access:
231  for (size_t i = 0; i < array.vectorsCount(); ++i) {
232  int_v x = array.vector(i); // read
233  array.vector(i) = x; // write
234  }
235  * \endcode
236  * This code allocates a small array and implements three equivalent loops (that do nothing useful).
237  * The loops show how scalar and vector read/write access is best implemented.
238  *
239  * Since the size of 11 is not a multiple of int_v::Size (unless you use the
240  * scalar Vc implementation) the last write access of the vector loop would normally be out of
241  * bounds. But the Memory class automatically pads the memory such that the whole array can be
242  * accessed with correctly aligned memory addresses.
243  *
244  * \param V The vector type you want to operate on. (e.g. float_v or uint_v)
245  * \param Size The number of entries of the scalar base type the memory should hold. This
246  * is thus the same number as you would use for a normal C array (e.g. float mem[11] becomes
247  * Memory<float_v, 11> mem).
248  *
249  * \see Memory<V, 0u>
250  *
251  * \ingroup Utilities
252  * \headerfile memory.h <Vc/Memory>
253  */
254  template<typename V, size_t Size> class Memory<V, Size, 0u> : public VectorAlignedBaseT<V>, public MemoryBase<V, Memory<V, Size, 0u>, 1, void>
255  {
256  public:
257  typedef typename V::EntryType EntryType;
258  private:
259  typedef MemoryBase<V, Memory<V, Size, 0u>, 1, void> Base;
260  friend class MemoryBase<V, Memory<V, Size, 0u>, 1, void>;
261  friend class MemoryDimensionBase<V, Memory<V, Size, 0u>, 1, void>;
263  Alignment = V::Size,
264  AlignmentMask = Alignment - 1,
265  MaskedSize = Size & AlignmentMask,
266  Padding = Alignment - MaskedSize,
267  PaddedSize = MaskedSize == 0 ? Size : Size + Padding
268  };
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;
275  // __declspec(align(#)) accepts only numbers not __alignof nor just VectorAlignment
276  // by putting VectorAlignedBaseT<V> here _force_alignment is aligned correctly.
277  // the downside is that there's a lot of padding before m_mem (32 Bytes with SSE) :(
278 #endif
279  EntryType m_mem[PaddedSize];
280  public:
281  using Base::vector;
282  enum Constants {
283  EntriesCount = Size,
284  VectorsCount = PaddedSize / V::Size
285  };
286 
287  /**
288  * Wrap existing data with the Memory convenience class.
289  *
290  * This function returns a \em reference to a Memory<V, Size, 0> object that you must
291  * capture to avoid a copy of the whole data:
292  * \code
293  * Memory<float_v, 16> &m = Memory<float_v, 16>::fromRawData(someAlignedPointerToFloat)
294  * \endcode
295  *
296  * \param ptr An aligned pointer to memory of type \p V::EntryType (e.g. \c float for
297  * Vc::float_v).
298  * \return A Memory object placed at the given location in memory.
299  *
300  * \warning The pointer \p ptr passed to this function must be aligned according to the
301  * alignment restrictions of \p V.
302  * \warning The size of the accessible memory must match \p Size. This includes the
303  * required padding at the end to allow the last entries to be accessed via vectors. If
304  * you know what you are doing you might violate this constraint.
305  * \warning It is your responsibility to ensure that the memory is released correctly
306  * (not too early/not leaked). This function simply adds convenience functions to \em
307  * access the memory.
308  */
310  {
311  // DANGER! This placement new has to use the right address. If the compiler decides
312  // RowMemory requires padding before the actual data then the address has to be adjusted
313  // accordingly
314  char *addr = reinterpret_cast<char *>(ptr);
315  typedef Memory<V, Size, 0u> MM;
316  addr -= VC_OFFSETOF(MM, m_mem);
317  return *new(addr) MM;
318  }
319 
320  /**
321  * \return the number of scalar entries in the whole array.
322  *
323  * \note This function can be optimized into a compile-time constant.
324  */
325  _VC_CONSTEXPR size_t entriesCount() const { return EntriesCount; }
326 
327  /**
328  * \return the number of vectors in the whole array.
329  *
330  * \note This function can be optimized into a compile-time constant.
331  */
332  _VC_CONSTEXPR size_t vectorsCount() const { return VectorsCount; }
333 
334 #ifdef VC_CXX11
335  Vc_ALWAYS_INLINE Memory() = default;
336 #else
338 #endif
339 
340  inline Memory(const Memory &rhs)
341  {
342  Internal::copyVectors(*this, rhs);
343  }
344 
345  template <size_t S> inline Memory(const Memory<V, S> &rhs)
346  {
347  assert(vectorsCount() == rhs.vectorsCount());
348  Internal::copyVectors(*this, rhs);
349  }
350 
351  inline Memory &operator=(const Memory &rhs)
352  {
353  Internal::copyVectors(*this, rhs);
354  return *this;
355  }
356 
357  template <size_t S> inline Memory &operator=(const Memory<V, S> &rhs)
358  {
359  assert(vectorsCount() == rhs.vectorsCount());
360  Internal::copyVectors(*this, rhs);
361  return *this;
362  }
363 
364  Vc_ALWAYS_INLINE Memory &operator=(const EntryType *rhs) {
365  std::memcpy(m_mem, rhs, entriesCount() * sizeof(EntryType));
366  return *this;
367  }
368  inline Memory &operator=(const V &v) {
369  for (size_t i = 0; i < vectorsCount(); ++i) {
370  vector(i) = v;
371  }
372  return *this;
373  }
374  }
375 #if defined(VC_ICC) && VC_ICC < 20120212 && !defined(_WIN32)
376  __attribute__((__aligned__(__alignof(VectorAlignedBaseT<V>)) ))
377 #endif
378  ;
379 
380  /**
381  * A helper class that is very similar to Memory<V, Size> but with dynamically allocated memory and
382  * thus dynamic size.
383  *
384  * Example:
385  * \code
386  size_t size = 11;
387  Vc::Memory<int_v> array(size);
388 
389  // scalar access:
390  for (size_t i = 0; i < array.entriesCount(); ++i) {
391  array[i] = i;
392  }
393 
394  // vector access:
395  for (size_t i = 0; i < array.vectorsCount(); ++i) {
396  array.vector(i) = int_v::IndexesFromZero() + i * int_v::Size;
397  }
398  * \endcode
399  * This code allocates a small array with 11 scalar entries
400  * and implements two equivalent loops that initialize the memory.
401  * The scalar loop writes each individual int. The vectorized loop writes int_v::Size values to
402  * memory per iteration. Since the size of 11 is not a multiple of int_v::Size (unless you use the
403  * scalar Vc implementation) the last write access of the vector loop would normally be out of
404  * bounds. But the Memory class automatically pads the memory such that the whole array can be
405  * accessed with correctly aligned memory addresses.
406  * (Note: the scalar loop can be auto-vectorized, except for the last three assignments.)
407  *
408  * \note The internal data pointer is not declared with the \c __restrict__ keyword. Therefore
409  * modifying memory of V::EntryType will require the compiler to assume aliasing. If you want to use
410  * the \c __restrict__ keyword you need to use a standard pointer to memory and do the vector
411  * address calculation and loads and stores manually.
412  *
413  * \param V The vector type you want to operate on. (e.g. float_v or uint_v)
414  *
415  * \see Memory<V, Size>
416  *
417  * \ingroup Utilities
418  * \headerfile memory.h <Vc/Memory>
419  */
420  template<typename V> class Memory<V, 0u, 0u> : public MemoryBase<V, Memory<V, 0u, 0u>, 1, void>
421  {
422  public:
423  typedef typename V::EntryType EntryType;
424  private:
425  typedef MemoryBase<V, Memory<V>, 1, void> Base;
426  friend class MemoryBase<V, Memory<V>, 1, void>;
427  friend class MemoryDimensionBase<V, Memory<V>, 1, void>;
429  Alignment = V::Size,
430  AlignmentMask = Alignment - 1
431  };
434  EntryType *m_mem;
435  size_t calcPaddedEntriesCount(size_t x)
436  {
437  size_t masked = x & AlignmentMask;
438  return (masked == 0 ? x : x + (Alignment - masked));
439  }
440  public:
441  using Base::vector;
442 
443  /**
444  * Allocate enough memory to access \p size values of type \p V::EntryType.
445  *
446  * The allocated memory is aligned and padded correctly for fully vectorized access.
447  *
448  * \param size Determines how many scalar values will fit into the allocated memory.
449  */
451  : m_entriesCount(size),
452  m_vectorsCount(calcPaddedEntriesCount(m_entriesCount)),
453  m_mem(Vc::malloc<EntryType, Vc::AlignOnVector>(m_vectorsCount))
454  {
455  m_vectorsCount /= V::Size;
456  }
457 
458  /**
459  * Copy the memory into a new memory area.
460  *
461  * The allocated memory is aligned and padded correctly for fully vectorized access.
462  *
463  * \param rhs The Memory object to copy from.
464  */
465  template<typename Parent, typename RM>
467  : m_entriesCount(rhs.entriesCount()),
468  m_vectorsCount(rhs.vectorsCount()),
469  m_mem(Vc::malloc<EntryType, Vc::AlignOnVector>(m_vectorsCount * V::Size))
470  {
471  Internal::copyVectors(*this, rhs);
472  }
473 
474  /**
475  * Overload of the above function.
476  *
477  * (Because C++ would otherwise not use the templated cctor and use a default-constructed cctor instead.)
478  *
479  * \param rhs The Memory object to copy from.
480  */
482  : m_entriesCount(rhs.entriesCount()),
483  m_vectorsCount(rhs.vectorsCount()),
484  m_mem(Vc::malloc<EntryType, Vc::AlignOnVector>(m_vectorsCount * V::Size))
485  {
486  Internal::copyVectors(*this, rhs);
487  }
488 
489  /**
490  * Frees the memory which was allocated in the constructor.
491  */
493  {
494  Vc::free(m_mem);
495  }
496 
497  /**
498  * Swap the contents and size information of two Memory objects.
499  *
500  * \param rhs The other Memory object to swap.
501  */
502  inline void swap(Memory &rhs) {
503  std::swap(m_mem, rhs.m_mem);
504  std::swap(m_entriesCount, rhs.m_entriesCount);
505  std::swap(m_vectorsCount, rhs.m_vectorsCount);
506  }
507 
508  /**
509  * \return the number of scalar entries in the whole array.
510  */
511  Vc_ALWAYS_INLINE Vc_PURE size_t entriesCount() const { return m_entriesCount; }
512 
513  /**
514  * \return the number of vectors in the whole array.
515  */
516  Vc_ALWAYS_INLINE Vc_PURE size_t vectorsCount() const { return m_vectorsCount; }
517 
518  /**
519  * Overwrite all entries with the values stored in \p rhs.
520  *
521  * \param rhs The object to copy the data from.
522  *
523  * \return reference to the modified Memory object.
524  *
525  * \note this function requires the vectorsCount() of both Memory objects to be equal.
526  */
527  template<typename Parent, typename RM>
529  assert(vectorsCount() == rhs.vectorsCount());
530  Internal::copyVectors(*this, rhs);
531  return *this;
532  }
533 
535  assert(vectorsCount() == rhs.vectorsCount());
536  Internal::copyVectors(*this, rhs);
537  return *this;
538  }
539 
540  /**
541  * Overwrite all entries with the values stored in the memory at \p rhs.
542  *
543  * \param rhs The array to copy the data from.
544  *
545  * \return reference to the modified Memory object.
546  *
547  * \note this function requires that there are entriesCount() many values accessible from \p rhs.
548  */
549  Vc_ALWAYS_INLINE Memory &operator=(const EntryType *rhs) {
550  std::memcpy(m_mem, rhs, entriesCount() * sizeof(EntryType));
551  return *this;
552  }
553 };
554 
555 /**
556  * Prefetch the cacheline containing \p addr for a single read access.
557  *
558  * This prefetch completely bypasses the cache, not evicting any other data.
559  *
560  * \param addr The cacheline containing \p addr will be prefetched.
561  *
562  * \ingroup Utilities
563  * \headerfile memory.h <Vc/Memory>
564  */
565 Vc_ALWAYS_INLINE void prefetchForOneRead(const void *addr)
566 {
568 }
569 
570 /**
571  * Prefetch the cacheline containing \p addr for modification.
572  *
573  * This prefetch evicts data from the cache. So use it only for data you really will use. When the
574  * target system supports it the cacheline will be marked as modified while prefetching, saving work
575  * later on.
576  *
577  * \param addr The cacheline containing \p addr will be prefetched.
578  *
579  * \ingroup Utilities
580  * \headerfile memory.h <Vc/Memory>
581  */
582 Vc_ALWAYS_INLINE void prefetchForModify(const void *addr)
583 {
585 }
586 
587 /**
588  * Prefetch the cacheline containing \p addr to L1 cache.
589  *
590  * This prefetch evicts data from the cache. So use it only for data you really will use.
591  *
592  * \param addr The cacheline containing \p addr will be prefetched.
593  *
594  * \ingroup Utilities
595  * \headerfile memory.h <Vc/Memory>
596  */
597 Vc_ALWAYS_INLINE void prefetchClose(const void *addr)
598 {
600 }
601 
602 /**
603  * Prefetch the cacheline containing \p addr to L2 cache.
604  *
605  * This prefetch evicts data from the cache. So use it only for data you really will use.
606  *
607  * \param addr The cacheline containing \p addr will be prefetched.
608  *
609  * \ingroup Utilities
610  * \headerfile memory.h <Vc/Memory>
611  */
612 Vc_ALWAYS_INLINE void prefetchMid(const void *addr)
613 {
615 }
616 
617 /**
618  * Prefetch the cacheline containing \p addr to L3 cache.
619  *
620  * This prefetch evicts data from the cache. So use it only for data you really will use.
621  *
622  * \param addr The cacheline containing \p addr will be prefetched.
623  *
624  * \ingroup Utilities
625  * \headerfile memory.h <Vc/Memory>
626  */
627 Vc_ALWAYS_INLINE void prefetchFar(const void *addr)
628 {
630 }
631 
632 } // namespace Vc
633 } // namespace ROOT
634 
635 namespace std
636 {
637  template<typename V> Vc_ALWAYS_INLINE void swap(Vc::Memory<V> &a, Vc::Memory<V> &b) { a.swap(b); }
638 } // namespace std
639 
640 #include "undomacros.h"
641 
642 #endif // VC_COMMON_MEMORY_H
V::EntryType EntryType
Definition: memory.h:123
Memory & operator=(const Memory< V, S > &rhs)
Definition: memory.h:357
Vc_ALWAYS_INLINE Memory & operator=(const EntryType *rhs)
Definition: memory.h:364
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Vc_ALWAYS_INLINE Vc_PURE size_t vectorsCount() const
Definition: memory.h:516
Vc_ALWAYS_INLINE Vc_PURE size_t entriesCount() const
Definition: memory.h:511
EntryType m_mem[Size1][PaddedSize2]
Definition: memory.h:141
Memory(const Memory &rhs)
Definition: memory.h:340
const char * Size
Definition: TXMLSetup.cxx:56
double T(double x)
Definition: ChebyshevPol.h:34
#define assert(cond)
Definition: unittest.h:542
_VC_CONSTEXPR size_t entriesCount() const
Definition: memory.h:325
Memory & operator=(const Memory &rhs)
Definition: memory.h:351
void swap(ROOT::THist< DIMENSIONS, PRECISION > &a, ROOT::THist< DIMENSIONS, PRECISION > &b) noexcept
Swap two histograms.
Definition: THist.h:196
_VC_CONSTEXPR size_t vectorsCount() const
Definition: memory.h:169
TArc * a
Definition: textangle.C:12
STL namespace.
Memory & operator=(const V &v)
Initialize all data with the given vector.
Definition: memory.h:199
Vc_ALWAYS_INLINE Memory & operator=(const EntryType *rhs)
Overwrite all entries with the values stored in the memory at rhs.
Definition: memory.h:549
#define VC_OFFSETOF(Type, member)
Definition: macros.h:380
Vc_ALWAYS_INLINE void prefetchForModify(const void *addr)
Prefetch the cacheline containing addr for modification.
Definition: memory.h:582
_VC_CONSTEXPR size_t entriesCount() const
Definition: memory.h:163
Double_t x[n]
Definition: legend1.C:17
void swap(Memory &rhs)
Swap the contents and size information of two Memory objects.
Definition: memory.h:502
Vc_ALWAYS_INLINE Memory & operator=(const MemoryBase< V, Parent, 1, RM > &rhs)
Overwrite all entries with the values stored in rhs.
Definition: memory.h:528
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: memory.h:94
Vc_ALWAYS_INLINE Vc_PURE size_t vectorsCount() const
Definition: memorybase.h:285
Vc_ALWAYS_INLINE Memory(const MemoryBase< V, Parent, 1, RM > &rhs)
Copy the memory into a new memory area.
Definition: memory.h:466
Vc_ALWAYS_INLINE Memory(const Memory &rhs)
Overload of the above function.
Definition: memory.h:481
Memory(const Memory< V, S > &rhs)
Definition: memory.h:345
Vc_ALWAYS_INLINE void prefetchForOneRead(const void *addr)
Prefetch the cacheline containing addr for a single read access.
Definition: memory.h:565
Vc_ALWAYS_INLINE void prefetchClose(const void *addr)
Prefetch the cacheline containing addr to L1 cache.
Definition: memory.h:597
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlag > vector(size_t i)
Definition: memorybase.h:310
#define Vc_PURE
Definition: macros.h:136
#define Vc_ALWAYS_INLINE_R
Definition: macros.h:132
Vc_ALWAYS_INLINE void prefetchMid(const void *addr)
Prefetch the cacheline containing addr to L2 cache.
Definition: memory.h:612
Vc_ALWAYS_INLINE Memory & operator=(const Memory &rhs)
Definition: memory.h:534
Vc_ALWAYS_INLINE void prefetchFar(const void *addr)
Prefetch the cacheline containing addr to L3 cache.
Definition: memory.h:627
Vc_ALWAYS_INLINE ~Memory()
Frees the memory which was allocated in the constructor.
Definition: memory.h:492
size_t calcPaddedEntriesCount(size_t x)
Definition: memory.h:435
SVector< double, 2 > v
Definition: Dict.h:5
_VC_CONSTEXPR size_t vectorsCount() const
Definition: memory.h:332
Align on boundary of vector sizes (e.g.
Definition: global.h:334
#define Vc_CONST
Definition: macros.h:133
Vc_ALWAYS_INLINE Memory(size_t size)
Allocate enough memory to access size values of type V::EntryType.
Definition: memory.h:450
MemoryBase< V, Memory< V, Size1, Size2 >, 2, Memory< V, Size2 > > Base
Definition: memory.h:125
Vc_ALWAYS_INLINE Memory()
Definition: memory.h:337
A helper class for fixed-size two-dimensional arrays.
Definition: memory.h:120
#define Vc_ALWAYS_INLINE
Definition: macros.h:130
Vc_ALWAYS_INLINE Memory & operator=(const MemoryBase< V, Parent, 2, RM > &rhs)
Copies the data from a different object.
Definition: memory.h:181
#define Vc_ALWAYS_INLINE_L
Definition: macros.h:131
_VC_CONSTEXPR size_t rowsCount() const
Definition: memory.h:154
#define _VC_CONSTEXPR
Definition: macros.h:154
A helper class to simplify usage of correctly aligned and padded memory, allowing both vector and sca...
Definition: memory.h:254
typedef void((*Func_t)())
MemoryBase< V, Memory< V, Size, 0u >, 1, void > Base
Definition: memory.h:259
Common interface to all Memory classes, independent of allocation on the stack or heap...
Definition: memorybase.h:265
MemoryBase< V, Memory< V >, 1, void > Base
Definition: memory.h:425
Definition: casts.h:28
static Vc_ALWAYS_INLINE Vc_CONST Memory< V, Size, 0u > & fromRawData(EntryType *ptr)
Wrap existing data with the Memory convenience class.
Definition: memory.h:309
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.
Definition: memory.h:67
const Int_t n
Definition: legend1.C:16
Vc_ALWAYS_INLINE Memory & operator=(const Memory &rhs)
Definition: memory.h:187
Memory & operator=(const V &v)
Definition: memory.h:368
void copyVectors(MemoryBase< V, ParentL, Dimension, RowMemoryL > &dst, const MemoryBase< V, ParentR, Dimension, RowMemoryR > &src)
Definition: memorybase.h:577