Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFPSimdAllocator.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFPSimdAllocator.h
1 /*
2  * This file is part of KFParticle package
3  * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
4  * 2007-2019 Goethe University of Frankfurt
5  * 2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
6  * 2007-2019 Maksym Zyzak
7  *
8  * KFParticle is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * KFParticle is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef KFPSimdAllocator_H
23 #define KFPSimdAllocator_H
24 
25 #include <Vc/Vc>
26 
34 template <class T>
36  public:
37  // type definitions
38  typedef T value_type;
39  typedef T* pointer;
40  typedef const T* const_pointer;
41  typedef T& reference;
42  typedef const T& const_reference;
43  typedef std::size_t size_type;
44  typedef std::ptrdiff_t difference_type;
45 
52  template <class U>
53  struct rebind {
55  };
56 
59  return &value;
60  }
63  return &value;
64  }
65 
66  /* constructors and destructor
67  * - nothing to do because the allocator has no state
68  */
69  KFPSimdAllocator() throw() { }
70  KFPSimdAllocator(const KFPSimdAllocator&) throw() { }
71  template <class U>
73  ~KFPSimdAllocator() throw() { }
74 
76  size_type max_size () const throw() {
77  return std::numeric_limits<std::size_t>::max() / sizeof(T);
78  }
79 
81  pointer allocate (size_type num, const void* = 0) {
82 // print message and allocate memory with global new
83  pointer ret = reinterpret_cast<pointer>( /*T::*/operator new(num*sizeof(T)) );
84  return ret;
85  }
86 
88  void construct (pointer p) {
89  // initialize memory with placement new
90  new(p) T();
91  }
92 
94  void construct (pointer p, const T& value) {
95  new(p) T(value);
96  }
97 
99  void destroy (pointer p) {
100  // destroy objects by calling their destructor
101  p->~T();
102  }
103 
106  // print message and deallocate memory with global delete
107  /*T::*/operator delete(static_cast<void*>(p), num*sizeof(T));
108 
109  }
110 
111  void *operator new(size_t size, void *ptr) { return ::operator new(size, ptr);}
112  void *operator new[](size_t size, void *ptr) { return ::operator new(size, ptr);}
113  void *operator new(size_t size) { return _mm_malloc(size, sizeof(Vc::float_v)); }
114  void *operator new[](size_t size) { return _mm_malloc(size, sizeof(Vc::float_v)); }
115  void operator delete(void *ptr, size_t) { _mm_free(ptr); }
116  void operator delete[](void *ptr, size_t) { _mm_free(ptr); }
117 }; // KFPSimdAllocator
118 
119 #endif //KFPSimdAllocator