BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
std_alloc.h
Go to the documentation of this file.
1
#ifndef STD_ALLOC_H
2
#define STD_ALLOC_H
3
// ---------------------- Allocator for using STL ------------------------
4
5
#include "xmmintrin.h"
6
7
#include <limits>
8
#include <vector>
9
10
namespace
nsL1
11
{
12
13
// #define DEBUG_nsL1
14
15
template
<
class
T>
16
class
SimdAlloc
17
{
18
public
:
19
// type definitions
20
typedef
T
value_type
;
21
typedef
T*
pointer
;
22
typedef
const
T*
const_pointer
;
23
typedef
T&
reference
;
24
typedef
const
T&
const_reference
;
25
typedef
std::size_t
size_type
;
26
typedef
std::ptrdiff_t
difference_type
;
27
28
// rebind allocator to type U
29
template
<
class
U>
30
struct
rebind
31
{
32
typedef
SimdAlloc<U>
other
;
33
};
34
35
// return address of values
36
pointer
address
(
reference
value)
const
{
return
&value; }
37
const_pointer
address
(
const_reference
value)
const
{
return
&value; }
38
39
/* constructors and destructor
40
* - nothing to do because the allocator has no state
41
*/
42
SimdAlloc
() throw() {}
43
SimdAlloc
(
const
SimdAlloc
&)
throw
() {}
44
template
<
class
U>
45
SimdAlloc
(
const
SimdAlloc<U>
&)
throw
()
46
{}
47
~SimdAlloc
() throw() {}
48
49
// return maximum number of elements that can be allocated
50
size_type
max_size
()
const
throw() {
return
std::numeric_limits<std::size_t>::max() /
sizeof
(T); }
51
52
// allocate but don't initialize num elements of type T
53
pointer
allocate
(
size_type
num,
const
void
* = 0)
54
{
55
// print message and allocate memory with global new
56
#ifdef DEBUG_nsL1
57
std::cerr <<
"Allocator: allocate "
<< num <<
" element(s)"
58
<<
" of size "
<<
sizeof
(T) << std::endl;
59
#endif
// DEBUG_nsL1
60
pointer
ret =
reinterpret_cast<
pointer
>
(
/*T::*/
operator
new
(num *
sizeof
(T)));
61
#ifdef DEBUG_nsL1
62
std::cerr <<
" allocated at: "
<< (
void
*)ret << std::endl;
63
#endif
// DEBUG_nsL1
64
return
ret;
65
}
66
67
// initialize elements of allocated storage p with value value
68
void
construct
(
pointer
p,
const
T& value)
69
{
70
// initialize memory with placement new
71
#ifdef DEBUG_nsL1
72
std::cerr <<
"Allocator: construct "
<< p
/*<< " " << value*/
<< std::endl;
73
#endif
// DEBUG_nsL1
74
new
(p) T(value);
75
// p = reinterpret_cast<pointer>( operator new(sizeof(T), p) );
76
// *p = value;
77
#ifdef DEBUG_nsL1
78
std::cerr <<
"done."
<< std::endl;
79
#endif
// DEBUG_nsL1
80
}
81
82
// destroy elements of initialized storage p
83
void
destroy
(
pointer
p)
84
{
85
// destroy objects by calling their destructor
86
#ifdef DEBUG_nsL1
87
std::cerr <<
"Allocator: destroy "
<< p << std::endl;
88
#endif
// DEBUG_nsL1
89
p->~T();
90
#ifdef DEBUG_nsL1
91
std::cerr <<
"done."
<< std::endl;
92
#endif
// DEBUG_nsL1
93
}
94
95
// deallocate storage p of deleted elements
96
void
deallocate
(
pointer
p,
size_type
num)
97
{
98
// print message and deallocate memory with global delete
99
#ifdef DEBUG_nsL1
100
std::cerr <<
"Allocator: deallocate "
<< num <<
" element(s)"
101
<<
" of size "
<<
sizeof
(T) <<
" at: "
<<
static_cast<
void
*
>
(p) << std::endl;
102
#endif
// DEBUG_nsL1
103
/*T::*/
operator
delete
(
static_cast<
void
*
>
(p), num *
sizeof
(T));
104
#ifdef DEBUG_nsL1
105
std::cerr <<
"done."
<< std::endl;
106
#endif
// DEBUG_nsL1
107
}
108
109
void
*
operator
new
(
size_t
size,
void
* ptr) { return ::operator
new
(size, ptr); }
110
void
*
operator
new
[](
size_t
size,
void
* ptr) { return ::operator
new
(size, ptr); }
111
void
*
operator
new
(
size_t
size) {
return
_mm_malloc(size, 16); }
112
void
*
operator
new
[](
size_t
size) {
return
_mm_malloc(size, 16); }
113
void
operator
delete
(
void
* ptr, size_t) { _mm_free(ptr); }
114
void
operator
delete
[](
void
* ptr, size_t) { _mm_free(ptr); }
115
};
// SimdAlloc
116
117
// return that all specializations of this allocator are interchangeable
118
template
<
class
T1,
class
T2>
119
bool
operator==
(
const
SimdAlloc<T1>
&,
const
SimdAlloc<T2>
&)
throw
()
120
{
121
return
true
;
122
};
123
template
<
class
T1,
class
T2>
124
bool
operator!=
(
const
SimdAlloc<T1>
&,
const
SimdAlloc<T2>
&)
throw
()
125
{
126
return
false
;
127
};
128
129
template
<
typename
T>
130
struct
vector
131
{
132
vector
() {};
133
virtual
~vector
() {};
134
135
typedef
std::vector<T>
TStd
;
136
// typedef std::vector<T > TSimd;
137
typedef
std::vector<T, SimdAlloc<T>>
TSimd
;
138
};
139
140
typedef
nsL1::vector<fvec>::TSimd
vector_fvec
;
141
};
// namespace nsL1
142
143
template
<
typename
T>
144
struct
nsL1vector
:
public
nsL1::vector
<T>
// just for use std::vector simultaniosly
145
{};
146
147
#endif
nsL1::SimdAlloc
Definition
std_alloc.h:17
nsL1::SimdAlloc::allocate
pointer allocate(size_type num, const void *=0)
Definition
std_alloc.h:53
nsL1::SimdAlloc::const_reference
const T & const_reference
Definition
std_alloc.h:24
nsL1::SimdAlloc::const_pointer
const T * const_pointer
Definition
std_alloc.h:22
nsL1::SimdAlloc::pointer
T * pointer
Definition
std_alloc.h:21
nsL1::SimdAlloc::deallocate
void deallocate(pointer p, size_type num)
Definition
std_alloc.h:96
nsL1::SimdAlloc::~SimdAlloc
~SimdAlloc()
Definition
std_alloc.h:47
nsL1::SimdAlloc::size_type
std::size_t size_type
Definition
std_alloc.h:25
nsL1::SimdAlloc::destroy
void destroy(pointer p)
Definition
std_alloc.h:83
nsL1::SimdAlloc::construct
void construct(pointer p, const T &value)
Definition
std_alloc.h:68
nsL1::SimdAlloc::SimdAlloc
SimdAlloc()
Definition
std_alloc.h:42
nsL1::SimdAlloc::value_type
T value_type
Definition
std_alloc.h:20
nsL1::SimdAlloc::address
pointer address(reference value) const
Definition
std_alloc.h:36
nsL1::SimdAlloc::max_size
size_type max_size() const
Definition
std_alloc.h:50
nsL1::SimdAlloc::address
const_pointer address(const_reference value) const
Definition
std_alloc.h:37
nsL1::SimdAlloc::difference_type
std::ptrdiff_t difference_type
Definition
std_alloc.h:26
nsL1::SimdAlloc::SimdAlloc
SimdAlloc(const SimdAlloc &)
Definition
std_alloc.h:43
nsL1::SimdAlloc::reference
T & reference
Definition
std_alloc.h:23
nsL1::SimdAlloc::SimdAlloc
SimdAlloc(const SimdAlloc< U > &)
Definition
std_alloc.h:45
nsL1
Definition
PSEUDO_F32vec1.h:143
nsL1::vector_fvec
nsL1::vector< fvec >::TSimd vector_fvec
Definition
PSEUDO_F32vec1.h:151
nsL1::operator==
bool operator==(const SimdAlloc< T1 > &, const SimdAlloc< T2 > &)
Definition
std_alloc.h:119
nsL1::operator!=
bool operator!=(const SimdAlloc< T1 > &, const SimdAlloc< T2 > &)
Definition
std_alloc.h:124
nsL1::SimdAlloc::rebind
Definition
std_alloc.h:31
nsL1::SimdAlloc::rebind::other
SimdAlloc< U > other
Definition
std_alloc.h:32
nsL1::vector
Definition
PSEUDO_F32vec1.h:146
nsL1::vector::~vector
virtual ~vector()
Definition
std_alloc.h:133
nsL1::vector::vector
vector()
Definition
std_alloc.h:132
nsL1::TSimd::TStd
std::vector< T > TStd
Definition
PSEUDO_F32vec1.h:147
nsL1::TSimd::TSimd
std::vector< T > TSimd
Definition
PSEUDO_F32vec1.h:148
nsL1vector
Definition
PSEUDO_F32vec1.h:156
reconstruction
cat
vectors
std_alloc.h
Generated on
for BmnRoot by
1.17.0