Index: include/bits/random.h =================================================================== --- include/bits/random.h (revision 190753) +++ include/bits/random.h (working copy) @@ -32,6 +32,9 @@ #define _RANDOM_H 1 #include +#ifdef __SSE2__ +# include +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -1560,6 +1563,355 @@ typedef minstd_rand0 default_random_engine; +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std + + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /* Mersenne twister implementation optimized for vector operations. + * + * Reference: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/ + */ + template + class simd_fast_mersenne_twister_engine + { + static_assert(std::is_unsigned<_UIntType>::value, "template argument " + "substituting _UIntType not an unsigned integral type"); + static_assert(__sr1 < 32, "first right shift too large"); + static_assert(__sr2 < 16, "second right shift too large"); + static_assert(__sl1 < 32, "first left shift too large"); + static_assert(__sl2 < 16, "second left shift too large"); + + public: + typedef _UIntType result_type; + + private: + static constexpr size_t m_w = sizeof(result_type) * 8; + static constexpr size_t _M_nstate = __m / 128 + 1; + static constexpr size_t _M_nstate32 = _M_nstate * 4; + + static_assert(std::is_unsigned<_UIntType>::value, "template argument " + "substituting _UIntType not an unsigned integral type"); + static_assert(__pos1 < _M_nstate, "POS1 not smaller than state size"); + static_assert(16 % sizeof(_UIntType) == 0, + "UIntType size must divide 16"); + + public: + static constexpr size_t state_size = _M_nstate * (16 + / sizeof(result_type)); + static constexpr result_type default_seed = 5489u; + + // constructors and member function + explicit + simd_fast_mersenne_twister_engine(result_type __sd = default_seed) + { seed(__sd); } + + template::value> + ::type> + explicit + simd_fast_mersenne_twister_engine(_Sseq& __q) + { seed(__q); } + + void + seed(result_type __sd = default_seed); + + template + typename std::enable_if::value>::type + seed(_Sseq& __q); + + static constexpr result_type + min() + { return 0; }; + + static constexpr result_type + max() + { return std::numeric_limits::max(); } + + void + discard(unsigned long long __z); + + result_type + operator()() + { + if (__builtin_expect(_M_pos >= state_size, 0)) + _M_gen_rand(); + + return _M_stateT[_M_pos++]; + } + +#ifdef __SSE2__ + friend bool + operator==(const simd_fast_mersenne_twister_engine& __lhs, + const simd_fast_mersenne_twister_engine& __rhs) + { __m128i __res = _mm_cmpeq_epi8(__lhs._M_state[0], __rhs._M_state[0]); + for (size_t __i = 1; __i < __lhs._M_nstate; ++__i) + __res = _mm_and_si128(__res, _mm_cmpeq_epi8(__lhs._M_state[__i], + __rhs._M_state[__i])); + return (_mm_movemask_epi8(__res) == 0xffff + && __lhs._M_pos == __rhs._M_pos); } +#else + friend bool + operator==(const simd_fast_mersenne_twister_engine& __lhs, + const simd_fast_mersenne_twister_engine& __rhs) + { return (std::equal(__lhs._M_stateT, __lhs._M_stateT + state_size, + __rhs._M_stateT) + && __lhs._M_pos == __rhs._M_pos); } +#endif + + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType_2, + __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2, + __msk1_2, __msk2_2, __msk3_2, __msk4_2, + __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x); + + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType_2, + __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2, + __msk1_2, __msk2_2, __msk3_2, __msk4_2, + __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x); + + private: + union + { +#ifdef __SSE2__ + __m128i _M_state[_M_nstate]; +#endif + uint32_t _M_state32[_M_nstate32]; + result_type _M_stateT[state_size]; + } __attribute__ ((__aligned__ (16))); + size_t _M_pos; + + void _M_gen_rand(void); + void _M_period_certification(); + }; + + + template + inline bool + operator!=(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3, + __msk4, __parity1, __parity2, __parity3, __parity4>& __lhs, + const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3, + __msk4, __parity1, __parity2, __parity3, __parity4>& __rhs) + { return !(__lhs == __rhs); } + + + /* Definitions for the SIMD-oriented Fast Mersenne Twister as defined + * in the C implementation by Daito and Matsumoto, as both a 32-bit + * and 64-bit version. + */ + typedef simd_fast_mersenne_twister_engine + sfmt607; + + typedef simd_fast_mersenne_twister_engine + sfmt607_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt1279; + + typedef simd_fast_mersenne_twister_engine + sfmt1279_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt2281; + + typedef simd_fast_mersenne_twister_engine + sfmt2281_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt4253; + + typedef simd_fast_mersenne_twister_engine + sfmt4253_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt11213; + + typedef simd_fast_mersenne_twister_engine + sfmt11213_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt19937; + + typedef simd_fast_mersenne_twister_engine + sfmt19937_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt44497; + + typedef simd_fast_mersenne_twister_engine + sfmt44497_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt86243; + + typedef simd_fast_mersenne_twister_engine + sfmt86243_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt132049; + + typedef simd_fast_mersenne_twister_engine + sfmt132049_64; + + + typedef simd_fast_mersenne_twister_engine + sfmt216091; + + typedef simd_fast_mersenne_twister_engine + sfmt216091_64; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std + + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + /** * A standard interface to a platform-specific non-deterministic * random number generator (if any are available). Index: include/bits/random.tcc =================================================================== --- include/bits/random.tcc (revision 190753) +++ include/bits/random.tcc (working copy) @@ -876,7 +876,423 @@ return __is; } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + + template + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + seed(_UIntType __seed) + { + _M_state32[0] = static_cast(__seed); + for (size_t __i = 1; __i < _M_nstate32; ++__i) + _M_state32[__i] = (1812433253UL + * (_M_state32[__i - 1] ^ (_M_state32[__i - 1] >> 30)) + + __i); + _M_pos = state_size; + _M_period_certification(); + } + + + namespace { + + inline uint32_t _Func1(uint32_t __x) + { + return (__x ^ (__x >> 27)) * UINT32_C(1664525); + } + + inline uint32_t _Func2(uint32_t __x) + { + return (__x ^ (__x >> 27)) * UINT32_C(1566083941); + } + + } + + + template + template + typename std::enable_if::value>::type + simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + seed(_Sseq& __q) + { + size_t __lag; + + if (_M_nstate32 >= 623) + __lag = 11; + else if (_M_nstate32 >= 68) + __lag = 7; + else if (_M_nstate32 >= 39) + __lag = 5; + else + __lag = 3; + const size_t __mid = (_M_nstate32 - __lag) / 2; + + std::fill(_M_state32, _M_state32 + _M_nstate32, UINT32_C(0x8b8b8b8b)); + uint32_t __arr[_M_nstate32]; + __q.generate(__arr + 0, __arr + _M_nstate32); + + uint32_t __r = _Func1(_M_state32[0] ^ _M_state32[__mid] + ^ _M_state32[_M_nstate32 - 1]); + _M_state32[__mid] += __r; + __r += _M_nstate32; + _M_state32[__mid + __lag] += __r; + _M_state32[0] = __r; + + for (size_t __i = 1, __j = 0; __j < _M_nstate32; ++__j) + { + __r = _Func1(_M_state32[__i] + ^ _M_state32[(__i + __mid) % _M_nstate32] + ^ _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]); + _M_state32[(__i + __mid) % _M_nstate32] += __r; + __r += __arr[__j] + __i; + _M_state32[(__i + __mid + __lag) % _M_nstate32] += __r; + _M_state32[__i] = __r; + __i = (__i + 1) % _M_nstate32; + } + for (size_t __j = 0; __j < _M_nstate32; ++__j) + { + const size_t __i = (__j + 1) % _M_nstate32; + __r = _Func2(_M_state32[__i] + + _M_state32[(__i + __mid) % _M_nstate32] + + _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]); + _M_state32[(__i + __mid) % _M_nstate32] ^= __r; + __r -= __i; + _M_state32[(__i + __mid + __lag) % _M_nstate32] ^= __r; + _M_state32[__i] = __r; + } + + _M_pos = state_size; + _M_period_certification(); + } + + + template + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + _M_period_certification(void) + { + static const uint32_t __parity[4] = { __parity1, __parity2, + __parity3, __parity4 }; + uint32_t __inner = 0; + for (size_t __i = 0; __i < 4; ++__i) + if (__parity[__i] != 0) + __inner ^= _M_state32[__i] & __parity[__i]; + + if (__builtin_parity(__inner) & 1) + return; + for (size_t __i = 0; __i < 4; ++__i) + if (__parity[__i] != 0) + { + _M_state32[__i] ^= 1 << (__builtin_ffs(__parity[__i]) - 1); + return; + } + __builtin_unreachable(); + } + + + template + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + discard(unsigned long long __z) + { + while (__z > state_size - _M_pos) + { + __z -= state_size - _M_pos; + + _M_gen_rand(); + } + + _M_pos += __z; + } + + +#ifdef __SSE2__ + + namespace { + + template + inline __m128i __sse2_recursion(__m128i __a, __m128i __b, + __m128i __c, __m128i __d) + { + __m128i __y = _mm_srli_epi32(__b, __sr1); + __m128i __z = _mm_srli_si128(__c, __sr2); + __m128i __v = _mm_slli_epi32(__d, __sl1); + __z = _mm_xor_si128(__z, __a); + __z = _mm_xor_si128(__z, __v); + __m128i __x = _mm_slli_si128(__a, __sl2); + __y = _mm_and_si128(__y, _mm_set_epi32(__msk4, __msk3, __msk2, __msk1)); + __z = _mm_xor_si128(__z, __x); + return _mm_xor_si128(__z, __y); + } + + } + + + template + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + _M_gen_rand(void) + { + __m128i __r1 = _mm_load_si128(&_M_state[_M_nstate - 2]); + __m128i __r2 = _mm_load_si128(&_M_state[_M_nstate - 1]); + + size_t __i; + for (__i = 0; __i < _M_nstate - __pos1; ++__i) + { + __m128i __r = __sse2_recursion<__sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4> + (_M_state[__i], _M_state[__i + __pos1], __r1, __r2); + _mm_store_si128(&_M_state[__i], __r); + __r1 = __r2; + __r2 = __r; + } + for (; __i < _M_nstate; ++__i) + { + __m128i __r = __sse2_recursion<__sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4> + (_M_state[__i], _M_state[__i + __pos1 - _M_nstate], __r1, __r2); + _mm_store_si128(&_M_state[__i], __r); + __r1 = __r2; + __r2 = __r; + } + + _M_pos = 0; + } + + +#else + + namespace { + + template + inline void __rshift(uint32_t *__out, const uint32_t *__in) + { + uint64_t __th = ((static_cast(__in[3]) << 32) + | static_cast(__in[2])); + uint64_t __tl = ((static_cast(__in[1]) << 32) + | static_cast(__in[0])); + + uint64_t __oh = __th >> (__shift * 8); + uint64_t __ol = __tl >> (__shift * 8); + __ol |= __th << (64 - __shift * 8); + __out[1] = static_cast(__ol >> 32); + __out[0] = static_cast(__ol); + __out[3] = static_cast(__oh >> 32); + __out[2] = static_cast(__oh); + } + + + template + inline void __lshift(uint32_t *__out, const uint32_t *__in) + { + uint64_t __th = ((static_cast(__in[3]) << 32) + | static_cast(__in[2])); + uint64_t __tl = ((static_cast(__in[1]) << 32) + | static_cast(__in[0])); + + uint64_t __oh = __th << (__shift * 8); + uint64_t __ol = __tl << (__shift * 8); + __oh |= __tl >> (64 - __shift * 8); + __out[1] = static_cast(__ol >> 32); + __out[0] = static_cast(__ol); + __out[3] = static_cast(__oh >> 32); + __out[2] = static_cast(__oh); + } + + + template + inline void __recursion(uint32_t *__r, + const uint32_t *__a, const uint32_t *__b, + const uint32_t *__c, const uint32_t *__d) + { + uint32_t __x[4]; + uint32_t __y[4]; + + __lshift<__sl2>(__x, __a); + __rshift<__sr2>(__y, __c); + __r[0] = (__a[0] ^ __x[0] ^ ((__b[0] >> __sr1) & __msk1) + ^ __y[0] ^ (__d[0] << __sl1)); + __r[1] = (__a[1] ^ __x[1] ^ ((__b[1] >> __sr1) & __msk2) + ^ __y[1] ^ (__d[1] << __sl1)); + __r[2] = (__a[2] ^ __x[2] ^ ((__b[2] >> __sr1) & __msk3) + ^ __y[2] ^ (__d[2] << __sl1)); + __r[3] = (__a[3] ^ __x[3] ^ ((__b[3] >> __sr1) & __msk4) + ^ __y[3] ^ (__d[3] << __sl1)); + } + + } + + + template + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + _M_gen_rand(void) + { + const uint32_t *__r1 = &_M_state32[_M_nstate32 - 8]; + const uint32_t *__r2 = &_M_state32[_M_nstate32 - 4]; + static constexpr size_t __pos1_32 = __pos1 * 4; + + size_t __i; + for (__i = 0; __i < _M_nstate32 - __pos1_32; __i += 4) + { + __recursion<__sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4> + (&_M_state32[__i], &_M_state32[__i], + &_M_state32[__i + __pos1_32], __r1, __r2); + __r1 = __r2; + __r2 = &_M_state32[__i]; + } + + for (; __i < _M_nstate32; __i += 4) + { + __recursion<__sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4> + (&_M_state32[__i], &_M_state32[__i], + &_M_state32[__i + __pos1_32 - _M_nstate32], __r1, __r2); + __r1 = __r2; + __r2 = &_M_state32[__i]; + } + + _M_pos = 0; + } + +#endif + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + for (size_t __i = 0; __i < __x._M_nstate32; ++__i) + __os << __x._M_state32[__i] << __space; + __os << __x._M_pos; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (size_t __i = 0; __i < __x._M_nstate32; ++__i) + __is >> __x._M_state32[__i]; + __is >> __x._M_pos; + + __is.flags(__flags); + return __is; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template template typename uniform_int_distribution<_IntType>::result_type --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc 2012-08-29 07:40:02.244581550 -0400 @@ -0,0 +1,43 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-02-01 Paolo Carlini +// 2012-08-28 Ulrich Drepper , adapted for SFMT +// +// Copyright (C) 2010, 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +void +test01() +{ + std::seed_seq seed; + __gnu_cxx::simd_fast_mersenne_twister_engine< + uint32_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> x(seed); +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed2.cc 2012-08-29 07:39:42.007574256 -0400 @@ -0,0 +1,43 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// 2012-08-28 Ulrich Drepper , adapted for SFMT +// +// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +void +test01() +{ + double seed = 2.0; + __gnu_cxx::simd_fast_mersenne_twister_engine< + uint64_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> x(seed); +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed1.cc 2012-08-29 07:39:17.141565961 -0400 @@ -0,0 +1,43 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// 2012-08-28 Ulrich Drepper , adapted for SFMT +// +// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +void +test01() +{ + unsigned long seed = 2; + __gnu_cxx::simd_fast_mersenne_twister_engine< + uint64_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> x(seed); +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/default.cc 2012-08-29 10:28:00.910376445 -0400 @@ -0,0 +1,183 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// 2012-08-28 Ulrich Drepper , adapted for SFMT +// +// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + + +template +void run_test(std::initializer_list vals) +{ + typedef typename SFMT::result_type result_type; + SFMT e; + + e.seed(sizeof(result_type) == 4 ? 1234 : 4321); + e.discard(990); + bool success = true; + for (auto i : vals) + { + result_type r = e(); + success &= r == i; + std::cout << r << " vs " << i << std::endl; + } + VERIFY( success ); +} + + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::sfmt19937 e; + + VERIFY( e.min() == 0 ); + VERIFY( e.max() == std::numeric_limits::max() ); + + run_test<__gnu_cxx::sfmt607>({ UINT32_C(1318548553), UINT32_C(1985957974), + UINT32_C(1367744196), UINT32_C(3463392791), UINT32_C(2780736231), + UINT32_C(3894488561), UINT32_C(3157036262), UINT32_C(3491812767), + UINT32_C(1724574180), UINT32_C(3645035493) }); + + run_test<__gnu_cxx::sfmt607_64>({UINT64_C(15510024334182072935), + UINT64_C(5793753331747412752), UINT64_C(16198353238554625740), + UINT64_C(2233208824926016498), UINT64_C(3566091399820823780), + UINT64_C(16608268514591292798), UINT64_C(10684941689666043359), + UINT64_C(12463424292910456802), UINT64_C(5902567440240131366), + UINT64_C(7228030834036501150) }); + + run_test<__gnu_cxx::sfmt1279>({ UINT32_C(66657331), UINT32_C(637106837), + UINT32_C(406927341), UINT32_C(3964420203), UINT32_C(2127134160), + UINT32_C(1327235047), UINT32_C(227339400), UINT32_C(97109542), + UINT32_C(1814799261), UINT32_C(340888197) }); + + run_test<__gnu_cxx::sfmt1279_64>({ UINT64_C(16431921382083697129), + UINT64_C(3107599092104940900), UINT64_C(4055245506102959965), + UINT64_C(16096064917153424198), UINT64_C(14429331498726837109), + UINT64_C(9539664361920633782), UINT64_C(1435296568185387099), + UINT64_C(15922567183295047131), UINT64_C(641988285517426228), + UINT64_C(15936274870984512675) }); + + run_test<__gnu_cxx::sfmt2281>({ UINT32_C(2662391944), UINT32_C(1176696104), + UINT32_C(3587947451), UINT32_C(4098993357), UINT32_C(3140998698), + UINT32_C(870759742), UINT32_C(623529127), UINT32_C(3458807285), + UINT32_C(3341615957), UINT32_C(195614711) }); + + run_test<__gnu_cxx::sfmt2281_64>({ UINT64_C(16747191622237074632), + UINT64_C(15804170396401370381), UINT64_C(3395175278324920203), + UINT64_C(1541877340159274442), UINT64_C(14176322102994316687), + UINT64_C(5130618305074712143), UINT64_C(6769693652413407081), + UINT64_C(17733765687477661079), UINT64_C(5189766940360047353), + UINT64_C(1333654688569723389) }); + + run_test<__gnu_cxx::sfmt4253>({ UINT32_C(90342133), UINT32_C(1083987943), + UINT32_C(1785481425), UINT32_C(1921212667), UINT32_C(3164342992), + UINT32_C(1489324569), UINT32_C(603530523), UINT32_C(952851722), + UINT32_C(2380944844), UINT32_C(3335854133) }); + + run_test<__gnu_cxx::sfmt4253_64>({ UINT64_C(11570915401962514263), + UINT64_C(206693220452528225), UINT64_C(16553299974633247759), + UINT64_C(1069562842508952901), UINT64_C(7203975672387749585), + UINT64_C(7552781925224963166), UINT64_C(16865729458807008705), + UINT64_C(7848963629493506078), UINT64_C(9282397173969292817), + UINT64_C(10738488504584559289) }); + + run_test<__gnu_cxx::sfmt11213>({ UINT32_C(2072997009), UINT32_C(1332330347), + UINT32_C(179681555), UINT32_C(2315290438), UINT32_C(2429393974), + UINT32_C(509881964), UINT32_C(3807607878), UINT32_C(3055319970), + UINT32_C(671840881), UINT32_C(3477325874) }); + + run_test<__gnu_cxx::sfmt11213_64>({ UINT64_C(373867573626408653), + UINT64_C(4732829340233638861), UINT64_C(16174630176505735656), + UINT64_C(10063018133994900869), UINT64_C(17308645173308419196), + UINT64_C(11091353816581371951), UINT64_C(15078420471318089727), + UINT64_C(17965717592743818706), UINT64_C(12301543162252389155), + UINT64_C(1724943167823308511) }); + + run_test<__gnu_cxx::sfmt19937>({ UINT32_C(4002809368), UINT32_C(421169044), + UINT32_C(1112642589), UINT32_C(3076213779), UINT32_C(3387033971), + UINT32_C(2499610950), UINT32_C(3057240914), UINT32_C(1662679783), + UINT32_C(461224431), UINT32_C(1168395933) }); + + run_test<__gnu_cxx::sfmt19937_64>({ UINT64_C(8032857516355555296), + UINT64_C(14023605983059313116), UINT64_C(1032336061815461376), + UINT64_C(9840995337876562612), UINT64_C(9869256223029203587), + UINT64_C(12227975697177267636), UINT64_C(12728115115844186033), + UINT64_C(7752058479783205470), UINT64_C(729733219713393087), + UINT64_C(12954017801239007622) }); + + run_test<__gnu_cxx::sfmt44497>({ UINT32_C(1483092082), UINT32_C(1895679637), + UINT32_C(9122740), UINT32_C(635864575), UINT32_C(320732971), + UINT32_C(4253159584), UINT32_C(30097521), UINT32_C(839233316), + UINT32_C(1431693534), UINT32_C(645981752) }); + + run_test<__gnu_cxx::sfmt44497_64>({ UINT64_C(6246103978016445638), + UINT64_C(4198275826138953222), UINT64_C(12473679170573289212), + UINT64_C(14745709982748360209), UINT64_C(3630790792408208113), + UINT64_C(4195294399578350499), UINT64_C(3742595698794327253), + UINT64_C(17388385867517445933), UINT64_C(4261866397667814669), + UINT64_C(17394085161690598095) }); + + run_test<__gnu_cxx::sfmt86243>({ UINT32_C(3910985535), UINT32_C(100094501), + UINT32_C(3120362616), UINT32_C(1854432382), UINT32_C(314688154), + UINT32_C(522122712), UINT32_C(3026095676), UINT32_C(3681962735), + UINT32_C(1851548627), UINT32_C(2153846465) }); + + run_test<__gnu_cxx::sfmt86243_64>({ UINT64_C(250135615696586029), + UINT64_C(4836277875486422184), UINT64_C(12389320296183057446), + UINT64_C(7983028875884559442), UINT64_C(10079555227308335361), + UINT64_C(14829333386540244214), UINT64_C(12159744972103351172), + UINT64_C(4932579842314286356), UINT64_C(5200375244476537050), + UINT64_C(11795681221121010641) }); + + run_test<__gnu_cxx::sfmt132049>({ UINT32_C(1551023420), UINT32_C(1462317554), + UINT32_C(2882528449), UINT32_C(1136299843), UINT32_C(292840589), + UINT32_C(1307775247), UINT32_C(463274356), UINT32_C(1430357686), + UINT32_C(3907607055), UINT32_C(3462509184) }); + + run_test<__gnu_cxx::sfmt132049_64>({ UINT64_C(649482638765113922), + UINT64_C(14205859353699897918), UINT64_C(14077261854908137257), + UINT64_C(9564785861212212042), UINT64_C(7310747921257808846), + UINT64_C(13759009477111470372), UINT64_C(11942123860149328831), + UINT64_C(12868386070200572127), UINT64_C(18348617059674004332), + UINT64_C(4233208019331956061) }); + + run_test<__gnu_cxx::sfmt216091>({ UINT32_C(4171954654), UINT32_C(2938491210), + UINT32_C(1356393891), UINT32_C(3558249995), UINT32_C(3711769979), + UINT32_C(3434953144), UINT32_C(1601628304), UINT32_C(2187495640), + UINT32_C(1762169715), UINT32_C(2141213778) }); + + run_test<__gnu_cxx::sfmt216091_64>({ UINT64_C(11322404276387828766), + UINT64_C(9653391575000195546), UINT64_C(1767839622905368464), + UINT64_C(1690838241348740821), UINT64_C(817628268513271254), + UINT64_C(15111277786569319196), UINT64_C(15817118810543358764), + UINT64_C(5639001693408668083), UINT64_C(9959854003669400568), + UINT64_C(13675983279642398887) }); +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/copy.cc 2012-08-28 21:49:26.084298339 -0400 @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-02-16 Paolo Carlini +// 2012-08-28 Ulrich Drepper , adapted for SFMT +// +// Copyright (C) 2010, 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +void +test01() +{ + typedef uint32_t value_type; + + __gnu_cxx::simd_fast_mersenne_twister_engine e(1); + + const auto f(e); + auto g(f); + g = g; // Suppress unused warning. +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/serialize.cc 2012-08-28 20:46:50.307884127 -0400 @@ -0,0 +1,70 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> u, v; + + u(); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/equal.cc 2012-08-28 20:46:50.307884127 -0400 @@ -0,0 +1,53 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> u, v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} --- /dev/null 2012-08-25 17:45:56.293307003 -0400 +++ testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/inequal.cc 2012-08-28 20:46:50.307884127 -0400 @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-03-16 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 26.5.3.2 Class template mersenne_twister_engine [rand.eng.mers] + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> u, v; + + VERIFY( !(u != v) ); + + u.discard(100); + v.discard(100); + + VERIFY( !(u != v) ); +} + +int main() +{ + test01(); + return 0; +}