Commit b668e41a by Ulrich Drepper Committed by Ulrich Drepper

random.h (mersenne_twister_engine): Don't inline discard here.


	* include/bits/random.h (mersenne_twister_engine): Don't inline
	discard here.  New member function _M_gen_rand.
	* include/bits/random.tcc (mersenne_twister_engine<>::_M_gen_rand):
	New function.  Extracted from operator().
	(mersenne_twister_engine<>::discard): New implementation which
	skips in large steps.
	(mersenne_twister_engine<>::operator()): Use _M_gen_rand.

From-SVN: r190711
parent 6f79f4d1
012-08-22 Ulrich Drepper <drepper@gmail.com>
* include/bits/random.h (mersenne_twister_engine): Don't inline
discard here. New member function _M_gen_rand.
* include/bits/random.tcc (mersenne_twister_engine<>::_M_gen_rand):
New function. Extracted from operator().
(mersenne_twister_engine<>::discard): New implementation which
skips in large steps.
(mersenne_twister_engine<>::operator()): Use _M_gen_rand.
2012-08-26 Marc Glisse <marc.glisse@inria.fr> 2012-08-26 Marc Glisse <marc.glisse@inria.fr>
Paolo Carlini <paolo.carlini@oracle.com> Paolo Carlini <paolo.carlini@oracle.com>
......
...@@ -530,11 +530,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -530,11 +530,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Discard a sequence of random numbers. * @brief Discard a sequence of random numbers.
*/ */
void void
discard(unsigned long long __z) discard(unsigned long long __z);
{
for (; __z != 0ULL; --__z)
(*this)();
}
result_type result_type
operator()(); operator()();
...@@ -610,6 +606,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -610,6 +606,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__l1, __f1>& __x); __l1, __f1>& __x);
private: private:
void _M_gen_rand();
_UIntType _M_x[state_size]; _UIntType _M_x[state_size];
size_t _M_p; size_t _M_p;
}; };
......
...@@ -392,15 +392,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -392,15 +392,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __a, size_t __u, _UIntType __d, size_t __s,
_UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __b, size_t __t, _UIntType __c, size_t __l,
_UIntType __f> _UIntType __f>
typename void
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>::result_type
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>:: __s, __b, __t, __c, __l, __f>::
operator()() _M_gen_rand(void)
{
// Reload the vector - cost is O(n) amortized over n calls.
if (_M_p >= state_size)
{ {
const _UIntType __upper_mask = (~_UIntType()) << __r; const _UIntType __upper_mask = (~_UIntType()) << __r;
const _UIntType __lower_mask = ~__upper_mask; const _UIntType __lower_mask = ~__upper_mask;
...@@ -428,6 +423,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -428,6 +423,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_p = 0; _M_p = 0;
} }
template<typename _UIntType, size_t __w,
size_t __n, size_t __m, size_t __r,
_UIntType __a, size_t __u, _UIntType __d, size_t __s,
_UIntType __b, size_t __t, _UIntType __c, size_t __l,
_UIntType __f>
void
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>::
discard(unsigned long long __z)
{
while (__z > state_size - _M_p)
{
__z -= state_size - _M_p;
_M_gen_rand();
}
_M_p += __z;
}
template<typename _UIntType, size_t __w,
size_t __n, size_t __m, size_t __r,
_UIntType __a, size_t __u, _UIntType __d, size_t __s,
_UIntType __b, size_t __t, _UIntType __c, size_t __l,
_UIntType __f>
typename
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>::result_type
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>::
operator()()
{
// Reload the vector - cost is O(n) amortized over n calls.
if (_M_p >= state_size)
_M_gen_rand();
// Calculate o(x(i)). // Calculate o(x(i)).
result_type __z = _M_x[_M_p++]; result_type __z = _M_x[_M_p++];
__z ^= (__z >> __u) & __d; __z ^= (__z >> __u) & __d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment