MCKL
Monte Carlo Kernel Library
increment_avx2_64_4.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/internal/increment_avx2_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_AVX2_64_4_HPP
33 #define MCKL_RANDOM_INTERNAL_INCREMENT_AVX2_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 IncrementBlockSI256<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<__m256i, 4> &s)
50  {
51  __m256i c =
52  _mm256_set1_epi64x(static_cast<MCKL_INT64>(std::get<0>(ctr)));
53 
54  std::get<0>(s) =
55  _mm256_add_epi64(c, _mm256_set_epi64x(0x04, 0x03, 0x02, 0x01));
56  std::get<1>(s) =
57  _mm256_add_epi64(c, _mm256_set_epi64x(0x08, 0x07, 0x06, 0x05));
58  std::get<2>(s) =
59  _mm256_add_epi64(c, _mm256_set_epi64x(0x0C, 0x0B, 0x0A, 0x09));
60  std::get<3>(s) =
61  _mm256_add_epi64(c, _mm256_set_epi64x(0x10, 0x0F, 0x0E, 0x0D));
62  }
63 }; // class IncrementBlockSI256
64 
65 template <typename T>
66 class IncrementBlockSI256<T, 2, 8, 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<__m256i, 4> &s)
72  {
73  __m256i c =
74  _mm256_set_epi64x(static_cast<MCKL_INT64>(std::get<1>(ctr)),
75  static_cast<MCKL_INT64>(std::get<0>(ctr)),
76  static_cast<MCKL_INT64>(std::get<1>(ctr)),
77  static_cast<MCKL_INT64>(std::get<0>(ctr)));
78 
79  std::get<0>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 2, 0, 1));
80  std::get<1>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 4, 0, 3));
81  std::get<2>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 6, 0, 5));
82  std::get<3>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 8, 0, 7));
83  }
84 }; // class IncrementBlockSI256
85 
86 template <typename T>
87 class IncrementBlockSI256<T, 4, 4, 64>
88 {
89  static constexpr std::size_t K_ = 4;
90 
91  public:
92  static void eval(const std::array<T, K_> &ctr, std::array<__m256i, 4> &s)
93  {
94  __m256i c =
95  _mm256_set_epi64x(static_cast<MCKL_INT64>(std::get<3>(ctr)),
96  static_cast<MCKL_INT64>(std::get<2>(ctr)),
97  static_cast<MCKL_INT64>(std::get<1>(ctr)),
98  static_cast<MCKL_INT64>(std::get<0>(ctr)));
99 
100  std::get<0>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 0, 0, 1));
101  std::get<1>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 0, 0, 2));
102  std::get<2>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 0, 0, 3));
103  std::get<3>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 0, 0, 4));
104  }
105 }; // class IncrementBlockSI256
106 
107 template <typename T>
108 class IncrementBlockSI256<T, 8, 2, 64>
109 {
110  static constexpr std::size_t K_ = 8;
111 
112  public:
113  static void eval(const std::array<T, K_> &ctr, std::array<__m256i, 4> &s)
114  {
115  __m256i c =
116  _mm256_set_epi64x(static_cast<MCKL_INT64>(std::get<3>(ctr)),
117  static_cast<MCKL_INT64>(std::get<2>(ctr)),
118  static_cast<MCKL_INT64>(std::get<1>(ctr)),
119  static_cast<MCKL_INT64>(std::get<0>(ctr)));
120 
121  std::get<0>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 0, 0, 1));
122  std::get<1>(s) =
123  _mm256_set_epi64x(static_cast<MCKL_INT64>(std::get<7>(ctr)),
124  static_cast<MCKL_INT64>(std::get<6>(ctr)),
125  static_cast<MCKL_INT64>(std::get<5>(ctr)),
126  static_cast<MCKL_INT64>(std::get<4>(ctr)));
127  std::get<2>(s) = _mm256_add_epi64(c, _mm256_set_epi64x(0, 0, 0, 2));
128  std::get<3>(s) = std::get<1>(s);
129  }
130 }; // class IncrementBlockSI256
131 
132 template <typename T>
133 class IncrementBlockSI256<T, 16, 1, 64>
134 {
135  static constexpr std::size_t K_ = 16;
136 
137  public:
138  static void eval(const std::array<T, K_> &ctr, std::array<__m256i, 4> &s)
139  {
140  std::memcpy(s.data(), ctr.data(), 128);
141  std::get<0>(s) =
142  _mm256_add_epi64(std::get<0>(s), _mm256_set_epi64x(0, 0, 0, 1));
143  }
144 }; // class IncrementBlockSI256
145 
146 } // namespace internal
147 
148 } // namespace mckl
149 
151 
152 #endif // MCKL_RANDOM_INTERNAL_INCREMENT_AVX2_64_4_HPP
static void eval(const std::array< T, K_ > &ctr, std::array< __m256i, 4 > &s)
#define MCKL_PUSH_GCC_WARNING(warning)
Definition: compiler.h:78
static void eval(const std::array< T, K_ > &ctr, std::array< __m256i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m256i, 4 > &s)
Definition: mcmc.hpp:40
static void eval(const std::array< T, K_ > &ctr, std::array< __m256i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m256i, 4 > &s)
#define MCKL_POP_GCC_WARNING
Definition: compiler.h:79