MCKL
Monte Carlo Kernel Library
increment_avx512_64_2.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/internal/increment_avx512_64_4.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_2_HPP
33 #define MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_2_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, 16, 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, 2> &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  }
59 }; // class IncrementBlockSI512
60 
61 template <typename T>
62 class IncrementBlockSI512<T, 2, 8, 64>
63 {
64  static constexpr std::size_t K_ = 2;
65 
66  public:
67  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 2> &s)
68  {
69  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<1>(ctr)),
70  static_cast<MCKL_INT64>(std::get<0>(ctr)),
71  static_cast<MCKL_INT64>(std::get<1>(ctr)),
72  static_cast<MCKL_INT64>(std::get<0>(ctr)),
73  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 
78  std::get<0>(s) = _mm512_add_epi64(
79  c, _mm512_set_epi64(0, 0x04, 0, 0x03, 0, 0x02, 0, 0x01));
80  std::get<1>(s) = _mm512_add_epi64(
81  c, _mm512_set_epi64(0, 0x08, 0, 0x07, 0, 0x06, 0, 0x05));
82  }
83 }; // class IncrementBlockSI512
84 
85 template <typename T>
86 class IncrementBlockSI512<T, 4, 4, 64>
87 {
88  static constexpr std::size_t K_ = 4;
89 
90  public:
91  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 2> &s)
92  {
93  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<3>(ctr)),
94  static_cast<MCKL_INT64>(std::get<2>(ctr)),
95  static_cast<MCKL_INT64>(std::get<1>(ctr)),
96  static_cast<MCKL_INT64>(std::get<0>(ctr)),
97  static_cast<MCKL_INT64>(std::get<3>(ctr)),
98  static_cast<MCKL_INT64>(std::get<2>(ctr)),
99  static_cast<MCKL_INT64>(std::get<1>(ctr)),
100  static_cast<MCKL_INT64>(std::get<0>(ctr)));
101 
102  std::get<0>(s) =
103  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 2, 0, 0, 0, 1));
104  std::get<1>(s) =
105  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 4, 0, 0, 0, 3));
106  }
107 }; // class IncrementBlockSI512
108 
109 template <typename T>
110 class IncrementBlockSI512<T, 8, 2, 64>
111 {
112  static constexpr std::size_t K_ = 8;
113 
114  public:
115  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 2> &s)
116  {
117  __m512i c = _mm512_set_epi64(static_cast<MCKL_INT64>(std::get<7>(ctr)),
118  static_cast<MCKL_INT64>(std::get<6>(ctr)),
119  static_cast<MCKL_INT64>(std::get<5>(ctr)),
120  static_cast<MCKL_INT64>(std::get<4>(ctr)),
121  static_cast<MCKL_INT64>(std::get<3>(ctr)),
122  static_cast<MCKL_INT64>(std::get<2>(ctr)),
123  static_cast<MCKL_INT64>(std::get<1>(ctr)),
124  static_cast<MCKL_INT64>(std::get<0>(ctr)));
125 
126  std::get<0>(s) =
127  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
128  std::get<1>(s) =
129  _mm512_add_epi64(c, _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 2));
130  }
131 }; // class IncrementBlockSI512
132 
133 template <typename T>
134 class IncrementBlockSI512<T, 16, 1, 64>
135 {
136  static constexpr std::size_t K_ = 16;
137 
138  public:
139  static void eval(const std::array<T, K_> &ctr, std::array<__m512i, 2> &s)
140  {
141  std::memcpy(s.data(), ctr.data(), 128);
142  std::get<0>(s) = _mm512_add_epi64(
143  std::get<0>(s), _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 1));
144  }
145 }; // class IncrementBlockSI512
146 
147 } // namespace internal
148 
149 } // namespace mckl
150 
152 
153 #endif // MCKL_RANDOM_INTERNAL_INCREMENT_AVX512_64_2_HPP
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 2 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 2 > &s)
#define MCKL_PUSH_GCC_WARNING(warning)
Definition: compiler.h:78
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 2 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 2 > &s)
Definition: mcmc.hpp:40
static void eval(const std::array< T, K_ > &ctr, std::array< __m512i, 2 > &s)
#define MCKL_POP_GCC_WARNING
Definition: compiler.h:79