MCKL
Monte Carlo Kernel Library
increment_sse2_64_4.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/internal/increment_sse2_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_SSE2_64_4_HPP
33 #define MCKL_RANDOM_INTERNAL_INCREMENT_SSE2_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 IncrementBlockSI128<T, 1, 8, 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<__m128i, 4> &s)
50  {
51  __m128i c = _mm_set1_epi64x(static_cast<MCKL_INT64>(std::get<0>(ctr)));
52 
53  std::get<0>(s) = _mm_add_epi64(c, _mm_set_epi64x(2, 1));
54  std::get<1>(s) = _mm_add_epi64(c, _mm_set_epi64x(4, 3));
55  std::get<2>(s) = _mm_add_epi64(c, _mm_set_epi64x(6, 5));
56  std::get<3>(s) = _mm_add_epi64(c, _mm_set_epi64x(8, 7));
57  }
58 }; // class IncrementBlockSI128
59 
60 template <typename T>
61 class IncrementBlockSI128<T, 2, 4, 64>
62 {
63  static constexpr std::size_t K_ = 2;
64 
65  public:
66  static void eval(const std::array<T, K_> &ctr, std::array<__m128i, 4> &s)
67  {
68  __m128i c = _mm_set_epi64x(static_cast<MCKL_INT64>(std::get<1>(ctr)),
69  static_cast<MCKL_INT64>(std::get<0>(ctr)));
70 
71  std::get<0>(s) = _mm_add_epi64(c, _mm_set_epi64x(0, 1));
72  std::get<1>(s) = _mm_add_epi64(c, _mm_set_epi64x(0, 2));
73  std::get<2>(s) = _mm_add_epi64(c, _mm_set_epi64x(0, 3));
74  std::get<3>(s) = _mm_add_epi64(c, _mm_set_epi64x(0, 4));
75  }
76 }; // class IncrementBlockSI128
77 
78 template <typename T>
79 class IncrementBlockSI128<T, 4, 2, 64>
80 {
81  static constexpr std::size_t K_ = 4;
82 
83  public:
84  static void eval(const std::array<T, K_> &ctr, std::array<__m128i, 4> &s)
85  {
86  __m128i c = _mm_set_epi64x(static_cast<MCKL_INT64>(std::get<1>(ctr)),
87  static_cast<MCKL_INT64>(std::get<0>(ctr)));
88 
89  std::get<0>(s) = _mm_add_epi64(c, _mm_set_epi64x(0, 1));
90  std::get<1>(s) =
91  _mm_set_epi64x(static_cast<MCKL_INT64>(std::get<3>(ctr)),
92  static_cast<MCKL_INT64>(std::get<2>(ctr)));
93  std::get<2>(s) = _mm_add_epi64(c, _mm_set_epi64x(0, 2));
94  std::get<3>(s) = std::get<1>(s);
95  }
96 }; // class IncrementBlockSI128
97 
98 template <typename T>
99 class IncrementBlockSI128<T, 8, 1, 64>
100 {
101  static constexpr std::size_t K_ = 8;
102 
103  public:
104  static void eval(const std::array<T, K_> &ctr, std::array<__m128i, 4> &s)
105  {
106  std::memcpy(s.data(), ctr.data(), 64);
107  std::get<0>(s) = _mm_add_epi64(std::get<0>(s), _mm_set_epi64x(0, 1));
108  }
109 }; // class IncrementBlockSI128
110 
111 } // namespace internal
112 
113 } // namespace mckl
114 
116 
117 #endif // MCKL_RANDOM_INTERNAL_INCREMENT_SSE2_64_4_HPP
static void eval(const std::array< T, K_ > &ctr, std::array< __m128i, 4 > &s)
#define MCKL_PUSH_GCC_WARNING(warning)
Definition: compiler.h:78
static void eval(const std::array< T, K_ > &ctr, std::array< __m128i, 4 > &s)
static void eval(const std::array< T, K_ > &ctr, std::array< __m128i, 4 > &s)
Definition: mcmc.hpp:40
static void eval(const std::array< T, K_ > &ctr, std::array< __m128i, 4 > &s)
#define MCKL_POP_GCC_WARNING
Definition: compiler.h:79