MCKL
Monte Carlo Kernel Library
increment_avx512_64_8.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/internal/increment_avx512_64_f.hpp
3 //----------------------------------------------------------------------------
4 // MCKL: Monte Carlo Kernel Library
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2018, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_8_HPP
33 #define MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_8_HPP
34 
36 
37 MCKL_PUSH_GCC_WARNING("-Wignored-attributes")
38 
39 namespace mckl {
40 
41 namespace internal {
42 
43 template <typename T>
44 class IncrementBlockSI512<T, 1, 64, 64>
45 {
46  static constexpr std::size_t K_ = 1;
47 
48  public:
49  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
50  {
51  __m512i c =
52  _mm512_set1_epi64(static_cast<MCKL_INT64>(std::get<0>(ctr)));
53 
54  std::get<0x0>(s) = _mm512_add_epi64(c,
55  _mm512_set_epi64(0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01));
56  std::get<0x1>(s) = _mm512_add_epi64(c,
57  _mm512_set_epi64(0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09));
58  std::get<0x2>(s) = _mm512_add_epi64(c,
59  _mm512_set_epi64(0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11));
60  std::get<0x3>(s) = _mm512_add_epi64(c,
61  _mm512_set_epi64(0x20, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19));
62 
63  __m512i d = _mm512_set1_epi64(0x20);
64  std::get<0x4>(s) = _mm512_add_epi64(std::get<0x0>(s), d);
65  std::get<0x5>(s) = _mm512_add_epi64(std::get<0x1>(s), d);
66  std::get<0x6>(s) = _mm512_add_epi64(std::get<0x2>(s), d);
67  std::get<0x7>(s) = _mm512_add_epi64(std::get<0x3>(s), d);
68  }
69 }; // class IncrementBlockSI512
70 
71 template <typename T>
72 class IncrementBlockSI512<T, 2, 32, 64>
73 {
74  static constexpr std::size_t K_ = 2;
75 
76  public:
77  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
78  {
79  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<1>(ctr)),
80  static_cast<MCKL_INT64>(std::get<0>(ctr)),
81  static_cast<MCKL_INT64>(std::get<1>(ctr)),
82  static_cast<MCKL_INT64>(std::get<0>(ctr)),
83  static_cast<MCKL_INT64>(std::get<1>(ctr)),
84  static_cast<MCKL_INT64>(std::get<0>(ctr)),
85  static_cast<MCKL_INT64>(std::get<1>(ctr)),
86  static_cast<MCKL_INT64>(std::get<0>(ctr)));
87 
88  std::get<0x0>(s) = _mm512_add_epi64(
89  c, _mm512_set_epi64(0, 0x04, 0, 0x03, 0, 0x02, 0, 0x01));
90  std::get<0x1>(s) = _mm512_add_epi64(
91  c, _mm512_set_epi64(0, 0x08, 0, 0x07, 0, 0x06, 0, 0x05));
92  std::get<0x2>(s) = _mm512_add_epi64(
93  c, _mm512_set_epi64(0, 0x0C, 0, 0x0B, 0, 0x0A, 0, 0x09));
94  std::get<0x3>(s) = _mm512_add_epi64(
95  c, _mm512_set_epi64(0, 0x10, 0, 0x0F, 0, 0x0E, 0, 0x0D));
96 
97  __m512i d = _mm512_set_epi64(0, 0x10, 0, 0x10, 0, 0x10, 0, 0x10);
98  std::get<0x4>(s) = _mm512_add_epi64(std::get<0x0>(s), d);
99  std::get<0x5>(s) = _mm512_add_epi64(std::get<0x1>(s), d);
100  std::get<0x6>(s) = _mm512_add_epi64(std::get<0x2>(s), d);
101  std::get<0x7>(s) = _mm512_add_epi64(std::get<0x3>(s), d);
102  }
103 }; // class IncrementBlockSI512
104 
105 template <typename T>
106 class IncrementBlockSI512<T, 4, 16, 64>
107 {
108  static constexpr std::size_t K_ = 4;
109 
110  public:
111  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
112  {
113  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<3>(ctr)),
114  static_cast<MCKL_INT64>(std::get<2>(ctr)),
115  static_cast<MCKL_INT64>(std::get<1>(ctr)),
116  static_cast<MCKL_INT64>(std::get<0>(ctr)),
117  static_cast<MCKL_INT64>(std::get<3>(ctr)),
118  static_cast<MCKL_INT64>(std::get<2>(ctr)),
119  static_cast<MCKL_INT64>(std::get<1>(ctr)),
120  static_cast<MCKL_INT64>(std::get<0>(ctr)));
121 
122  std::get<0>(s) = _mm512_add_epi64(
123  c, _mm512_set_epi64(0, 0, 0, 0x02, 0, 0, 0, 0x01));
124  std::get<1>(s) = _mm512_add_epi64(
125  c, _mm512_set_epi64(0, 0, 0, 0x04, 0, 0, 0, 0x03));
126  std::get<2>(s) = _mm512_add_epi64(
127  c, _mm512_set_epi64(0, 0, 0, 0x06, 0, 0, 0, 0x05));
128  std::get<3>(s) = _mm512_add_epi64(
129  c, _mm512_set_epi64(0, 0, 0, 0x08, 0, 0, 0, 0x07));
130  std::get<4>(s) = _mm512_add_epi64(
131  c, _mm512_set_epi64(0, 0, 0, 0x0A, 0, 0, 0, 0x09));
132  std::get<5>(s) = _mm512_add_epi64(
133  c, _mm512_set_epi64(0, 0, 0, 0x0C, 0, 0, 0, 0x0B));
134  std::get<6>(s) = _mm512_add_epi64(
135  c, _mm512_set_epi64(0, 0, 0, 0x0E, 0, 0, 0, 0x0D));
136  std::get<7>(s) = _mm512_add_epi64(
137  c, _mm512_set_epi64(0, 0, 0, 0x10, 0, 0, 0, 0x0F));
138  }
139 }; // class IncrementBlockSI512
140 
141 template <typename T>
142 class IncrementBlockSI512<T, 8, 8, 64>
143 {
144  static constexpr std::size_t K_ = 8;
145 
146  public:
147  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
148  {
149  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<7>(ctr)),
150  static_cast<MCKL_INT64>(std::get<6>(ctr)),
151  static_cast<MCKL_INT64>(std::get<5>(ctr)),
152  static_cast<MCKL_INT64>(std::get<4>(ctr)),
153  static_cast<MCKL_INT64>(std::get<3>(ctr)),
154  static_cast<MCKL_INT64>(std::get<2>(ctr)),
155  static_cast<MCKL_INT64>(std::get<1>(ctr)),
156  static_cast<MCKL_INT64>(std::get<0>(ctr)));
157 
158  std::get<0>(s) =
159  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
160  std::get<1>(s) =
161  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 2));
162  std::get<2>(s) =
163  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 3));
164  std::get<3>(s) =
165  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 4));
166  std::get<4>(s) =
167  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 5));
168  std::get<5>(s) =
169  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 6));
170  std::get<6>(s) =
171  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 7));
172  std::get<7>(s) =
173  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 8));
174  }
175 }; // class IncrementBlockSI512
176 
177 template <typename T>
178 class IncrementBlockSI512<T, 16, 4, 64>
179 {
180  static constexpr std::size_t K_ = 16;
181 
182  public:
183  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
184  {
185  __m512i c =
186  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0x7>(ctr)),
187  static_cast<MCKL_INT64>(std::get<0x6>(ctr)),
188  static_cast<MCKL_INT64>(std::get<0x5>(ctr)),
189  static_cast<MCKL_INT64>(std::get<0x4>(ctr)),
190  static_cast<MCKL_INT64>(std::get<0x3>(ctr)),
191  static_cast<MCKL_INT64>(std::get<0x2>(ctr)),
192  static_cast<MCKL_INT64>(std::get<0x1>(ctr)),
193  static_cast<MCKL_INT64>(std::get<0x0>(ctr)));
194 
195  std::get<0>(s) =
196  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
197  std::get<1>(s) =
198  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0xF>(ctr)),
199  static_cast<MCKL_INT64>(std::get<0xE>(ctr)),
200  static_cast<MCKL_INT64>(std::get<0xD>(ctr)),
201  static_cast<MCKL_INT64>(std::get<0xC>(ctr)),
202  static_cast<MCKL_INT64>(std::get<0xB>(ctr)),
203  static_cast<MCKL_INT64>(std::get<0xA>(ctr)),
204  static_cast<MCKL_INT64>(std::get<0x9>(ctr)),
205  static_cast<MCKL_INT64>(std::get<0x8>(ctr)));
206  std::get<2>(s) =
207  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 2));
208  std::get<3>(s) = std::get<1>(s);
209  std::get<4>(s) =
210  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 3));
211  std::get<5>(s) = std::get<1>(s);
212  std::get<6>(s) =
213  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 4));
214  std::get<7>(s) = std::get<1>(s);
215  }
216 }; // class IncrementBlockSI512
217 
218 template <typename T>
219 class IncrementBlockSI512<T, 32, 2, 64>
220 {
221  static constexpr std::size_t K_ = 32;
222 
223  public:
224  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
225  {
226  __m512i c =
227  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0x07>(ctr)),
228  static_cast<MCKL_INT64>(std::get<0x06>(ctr)),
229  static_cast<MCKL_INT64>(std::get<0x05>(ctr)),
230  static_cast<MCKL_INT64>(std::get<0x04>(ctr)),
231  static_cast<MCKL_INT64>(std::get<0x03>(ctr)),
232  static_cast<MCKL_INT64>(std::get<0x02>(ctr)),
233  static_cast<MCKL_INT64>(std::get<0x01>(ctr)),
234  static_cast<MCKL_INT64>(std::get<0x00>(ctr)));
235 
236  std::get<0>(s) =
237  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
238  std::get<1>(s) =
239  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0x0F>(ctr)),
240  static_cast<MCKL_INT64>(std::get<0x0E>(ctr)),
241  static_cast<MCKL_INT64>(std::get<0x0D>(ctr)),
242  static_cast<MCKL_INT64>(std::get<0x0C>(ctr)),
243  static_cast<MCKL_INT64>(std::get<0x0B>(ctr)),
244  static_cast<MCKL_INT64>(std::get<0x0A>(ctr)),
245  static_cast<MCKL_INT64>(std::get<0x09>(ctr)),
246  static_cast<MCKL_INT64>(std::get<0x08>(ctr)));
247  std::get<2>(s) =
248  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0x17>(ctr)),
249  static_cast<MCKL_INT64>(std::get<0x16>(ctr)),
250  static_cast<MCKL_INT64>(std::get<0x15>(ctr)),
251  static_cast<MCKL_INT64>(std::get<0x14>(ctr)),
252  static_cast<MCKL_INT64>(std::get<0x13>(ctr)),
253  static_cast<MCKL_INT64>(std::get<0x12>(ctr)),
254  static_cast<MCKL_INT64>(std::get<0x11>(ctr)),
255  static_cast<MCKL_INT64>(std::get<0x10>(ctr)));
256  std::get<3>(s) =
257  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0x1F>(ctr)),
258  static_cast<MCKL_INT64>(std::get<0x1E>(ctr)),
259  static_cast<MCKL_INT64>(std::get<0x1D>(ctr)),
260  static_cast<MCKL_INT64>(std::get<0x1C>(ctr)),
261  static_cast<MCKL_INT64>(std::get<0x1B>(ctr)),
262  static_cast<MCKL_INT64>(std::get<0x1A>(ctr)),
263  static_cast<MCKL_INT64>(std::get<0x19>(ctr)),
264  static_cast<MCKL_INT64>(std::get<0x18>(ctr)));
265  std::get<4>(s) =
266  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 2));
267  std::get<5>(s) = std::get<0x1>(s);
268  std::get<6>(s) = std::get<0x2>(s);
269  std::get<7>(s) = std::get<0x3>(s);
270  }
271 }; // class IncrementBlockSI512
272 
273 template <typename T>
274 class IncrementBlockSI512<T, 64, 1, 64>
275 {
276  static constexpr std::size_t K_ = 64;
277 
278  public:
279  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 8> &s)
280  {
281  std::memcpy(s.data(), ctr.data(), 512);
282  std::get<0>(s) = _mm512_add_epi64(
283  std::get<0>(s), _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
284  }
285 }; // class IncrementBlockSI512
286 
287 } // namespace internal
288 
289 } // namespace mckl
290 
292 
293 #endif // MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_8_HPP
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
#define MCKL_PUSH_GCC_WARNING(warning)
Definition: compiler.h:78
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
#define MCKL_INT64
Definition: clang.h:134
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 8 > &s)
Definition: mcmc.hpp:40
#define MCKL_POP_GCC_WARNING
Definition: compiler.h:79