MCKL
Monte Carlo Kernel Library
increment_avx512_64_4.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/internal/increment_avx512_64_8.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_4_HPP
33 #define MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_4_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, 32, 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, 4> &s)
50  {
51  __m512i c =
52  _mm512_set1_epi64(static_cast<MCKL_INT64>(std::get<0>(ctr)));
53 
54  std::get<0>(s) = _mm512_add_epi64(c,
55  _mm512_set_epi64(0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01));
56  std::get<1>(s) = _mm512_add_epi64(c,
57  _mm512_set_epi64(0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09));
58  std::get<2>(s) = _mm512_add_epi64(c,
59  _mm512_set_epi64(0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11));
60  std::get<3>(s) = _mm512_add_epi64(c,
61  _mm512_set_epi64(0x20, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19));
62  }
63 }; // class IncrementBlockSI512
64 
65 template <typename T>
66 class IncrementBlockSI512<T, 2, 16, 64>
67 {
68  static constexpr std::size_t K_ = 2;
69 
70  public:
71  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 4> &s)
72  {
73  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<1>(ctr)),
74  static_cast<MCKL_INT64>(std::get<0>(ctr)),
75  static_cast<MCKL_INT64>(std::get<1>(ctr)),
76  static_cast<MCKL_INT64>(std::get<0>(ctr)),
77  static_cast<MCKL_INT64>(std::get<1>(ctr)),
78  static_cast<MCKL_INT64>(std::get<0>(ctr)),
79  static_cast<MCKL_INT64>(std::get<1>(ctr)),
80  static_cast<MCKL_INT64>(std::get<0>(ctr)));
81 
82  std::get<0>(s) = _mm512_add_epi64(
83  c, _mm512_set_epi64(0, 0x04, 0, 0x03, 0, 0x02, 0, 0x01));
84  std::get<1>(s) = _mm512_add_epi64(
85  c, _mm512_set_epi64(0, 0x08, 0, 0x07, 0, 0x06, 0, 0x05));
86  std::get<2>(s) = _mm512_add_epi64(
87  c, _mm512_set_epi64(0, 0x0C, 0, 0x0B, 0, 0x0A, 0, 0x09));
88  std::get<3>(s) = _mm512_add_epi64(
89  c, _mm512_set_epi64(0, 0x10, 0, 0x0F, 0, 0x0E, 0, 0x0D));
90  }
91 }; // class IncrementBlockSI512
92 
93 template <typename T>
94 class IncrementBlockSI512<T, 4, 8, 64>
95 {
96  static constexpr std::size_t K_ = 4;
97 
98  public:
99  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 4> &s)
100  {
101  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<3>(ctr)),
102  static_cast<MCKL_INT64>(std::get<2>(ctr)),
103  static_cast<MCKL_INT64>(std::get<1>(ctr)),
104  static_cast<MCKL_INT64>(std::get<0>(ctr)),
105  static_cast<MCKL_INT64>(std::get<3>(ctr)),
106  static_cast<MCKL_INT64>(std::get<2>(ctr)),
107  static_cast<MCKL_INT64>(std::get<1>(ctr)),
108  static_cast<MCKL_INT64>(std::get<0>(ctr)));
109 
110  std::get<0>(s) =
111  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 2, 0, 0, 0, 1));
112  std::get<1>(s) =
113  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 4, 0, 0, 0, 3));
114  std::get<2>(s) =
115  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 6, 0, 0, 0, 5));
116  std::get<3>(s) =
117  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 8, 0, 0, 0, 7));
118  }
119 }; // class IncrementBlockSI512
120 
121 template <typename T>
122 class IncrementBlockSI512<T, 8, 4, 64>
123 {
124  static constexpr std::size_t K_ = 8;
125 
126  public:
127  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 4> &s)
128  {
129  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<7>(ctr)),
130  static_cast<MCKL_INT64>(std::get<6>(ctr)),
131  static_cast<MCKL_INT64>(std::get<5>(ctr)),
132  static_cast<MCKL_INT64>(std::get<4>(ctr)),
133  static_cast<MCKL_INT64>(std::get<3>(ctr)),
134  static_cast<MCKL_INT64>(std::get<2>(ctr)),
135  static_cast<MCKL_INT64>(std::get<1>(ctr)),
136  static_cast<MCKL_INT64>(std::get<0>(ctr)));
137 
138  std::get<0>(s) =
139  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
140  std::get<1>(s) =
141  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 2));
142  std::get<2>(s) =
143  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 3));
144  std::get<3>(s) =
145  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 4));
146  }
147 }; // class IncrementBlockSI512
148 
149 template <typename T>
150 class IncrementBlockSI512<T, 16, 2, 64>
151 {
152  static constexpr std::size_t K_ = 16;
153 
154  public:
155  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 4> &s)
156  {
157  __m512i c =
158  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0x7>(ctr)),
159  static_cast<MCKL_INT64>(std::get<0x5>(ctr)),
160  static_cast<MCKL_INT64>(std::get<0x5>(ctr)),
161  static_cast<MCKL_INT64>(std::get<0x4>(ctr)),
162  static_cast<MCKL_INT64>(std::get<0x3>(ctr)),
163  static_cast<MCKL_INT64>(std::get<0x2>(ctr)),
164  static_cast<MCKL_INT64>(std::get<0x1>(ctr)),
165  static_cast<MCKL_INT64>(std::get<0x0>(ctr)));
166 
167  std::get<0>(s) =
168  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
169  std::get<1>(s) =
170  _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<0xF>(ctr)),
171  static_cast<MCKL_INT64>(std::get<0xE>(ctr)),
172  static_cast<MCKL_INT64>(std::get<0xD>(ctr)),
173  static_cast<MCKL_INT64>(std::get<0xC>(ctr)),
174  static_cast<MCKL_INT64>(std::get<0xB>(ctr)),
175  static_cast<MCKL_INT64>(std::get<0xA>(ctr)),
176  static_cast<MCKL_INT64>(std::get<0x9>(ctr)),
177  static_cast<MCKL_INT64>(std::get<0x8>(ctr)));
178  std::get<2>(s) =
179  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 2));
180  std::get<3>(s) = std::get<1>(s);
181  }
182 }; // class IncrementBlockSI512
183 
184 template <typename T>
185 class IncrementBlockSI512<T, 32, 1, 64>
186 {
187  static constexpr std::size_t K_ = 32;
188 
189  public:
190  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 4> &s)
191  {
192  std::memcpy(s.data(), ctr.data(), 512);
193  std::get<0>(s) = _mm512_add_epi64(
194  std::get<0>(s), _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
195  }
196 }; // class IncrementBlockSI512
197 
198 } // namespace internal
199 
200 } // namespace mckl
201 
203 
204 #endif // MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_4_HPP
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 4 > &s)
#define MCKL_PUSH_GCC_WARNING(warning)
Definition: compiler.h:78
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 4 > &s)
Definition: mcmc.hpp:40
#define MCKL_POP_GCC_WARNING
Definition: compiler.h:79