2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <thrust/random/linear_feedback_shift_engine.h>
25 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
26 linear_feedback_shift_engine<UIntType,w,k,q,s>
27 ::linear_feedback_shift_engine(result_type value)
30 } // end linear_feedback_shift_engine::linear_feedback_shift_engine()
32 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
33 void linear_feedback_shift_engine<UIntType,w,k,q,s>
34 ::seed(result_type value)
37 } // end linear_feedback_shift_engine::seed()
39 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
40 typename linear_feedback_shift_engine<UIntType,w,k,q,s>::result_type
41 linear_feedback_shift_engine<UIntType,w,k,q,s>
44 const UIntType b = (((m_value << q) ^ m_value) & wordmask) >> (k-s);
45 const UIntType mask = ( (~static_cast<UIntType>(0)) << (w-k) ) & wordmask;
46 m_value = ((m_value & mask) << s) ^ b;
48 } // end linear_feedback_shift_engine::operator()()
51 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
52 void linear_feedback_shift_engine<UIntType,w,k,q,s>
53 ::discard(unsigned long long z)
59 } // end linear_feedback_shift_engine::discard()
62 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
63 template<typename CharT, typename Traits>
64 std::basic_ostream<CharT,Traits>& linear_feedback_shift_engine<UIntType,w,k,q,s>
65 ::stream_out(std::basic_ostream<CharT,Traits> &os) const
67 typedef std::basic_ostream<CharT,Traits> ostream_type;
68 typedef typename ostream_type::ios_base ios_base;
70 // save old flags & fill character
71 const typename ios_base::fmtflags flags = os.flags();
72 const CharT fill = os.fill();
74 os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
75 os.fill(os.widen(' '));
77 // output one word of state
80 // restore flags & fill character
88 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
89 template<typename CharT, typename Traits>
90 std::basic_istream<CharT,Traits>& linear_feedback_shift_engine<UIntType,w,k,q,s>
91 ::stream_in(std::basic_istream<CharT,Traits> &is)
93 typedef std::basic_istream<CharT,Traits> istream_type;
94 typedef typename istream_type::ios_base ios_base;
97 const typename ios_base::fmtflags flags = is.flags();
99 is.flags(ios_base::skipws);
101 // input one word of state
111 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
112 bool linear_feedback_shift_engine<UIntType,w,k,q,s>
113 ::equal(const linear_feedback_shift_engine<UIntType,w,k,q,s> &rhs) const
115 return m_value == rhs.m_value;
119 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
120 bool operator==(const linear_feedback_shift_engine<UIntType,w,k,q,s> &lhs,
121 const linear_feedback_shift_engine<UIntType,w,k,q,s> &rhs)
123 return thrust::random::detail::random_core_access::equal(lhs,rhs);
127 template<typename UIntType, size_t w, size_t k, size_t q, size_t s>
128 bool operator!=(const linear_feedback_shift_engine<UIntType,w,k,q,s> &lhs,
129 const linear_feedback_shift_engine<UIntType,w,k,q,s> &rhs)
131 return !(lhs == rhs);
135 template<typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_,
136 typename CharT, typename Traits>
137 std::basic_ostream<CharT,Traits>&
138 operator<<(std::basic_ostream<CharT,Traits> &os,
139 const linear_feedback_shift_engine<UIntType_,w_,k_,q_,s_> &e)
141 return thrust::random::detail::random_core_access::stream_out(os,e);
145 template<typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_,
146 typename CharT, typename Traits>
147 std::basic_istream<CharT,Traits>&
148 operator>>(std::basic_istream<CharT,Traits> &is,
149 linear_feedback_shift_engine<UIntType_,w_,k_,q_,s_> &e)
151 return thrust::random::detail::random_core_access::stream_in(is,e);