diff options
Diffstat (limited to 'libstdc++-v3')
13 files changed, 1397 insertions, 11 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8a36129..047f444 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,26 @@ +2012-08-29 Ulrich Drepper <drepper@gmail.com> + + Add simd_fast_mersenne_twister_engine class. + * include/ext/random: New file. + * include/ext/random.tcc: New file. + * include/Makefile.am (ext_headers): Add random and random.tcc. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + operators/inequal.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + operators/equal.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + operators/serialize.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + cons/seed2.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + cons/default.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + cons/seed_seq.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + cons/copy.cc: New file. + * testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/ + cons/seed1.cc: New file. + 2012-08-28 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/54102, part 2 diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index e6de256..d3d6f4a 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -518,6 +518,8 @@ ext_headers = \ ${ext_srcdir}/pointer.h \ ${ext_srcdir}/pool_allocator.h \ ${ext_srcdir}/rb_tree \ + ${ext_srcdir}/random \ + ${ext_srcdir}/random.tcc \ ${ext_srcdir}/rope \ ${ext_srcdir}/ropeimpl.h \ ${ext_srcdir}/slist \ @@ -1099,7 +1101,7 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \ visibility=`cat stamp-visibility` ;\ externtemplate=`cat stamp-extern-template` ;\ ldbl_compat='s,g,g,' ;\ - grep "^[ ]*#[ ]*define[ ][ ]*_GLIBCXX_LONG_DOUBLE_COMPAT[ ][ ]*1[ ]*$$" \ + grep "^[ ]*#[ ]*define[ ][ ]*_GLIBCXX_LONG_DOUBLE_COMPAT[ ][ ]*1[ ]*$$" \ ${CONFIG_HEADER} > /dev/null 2>&1 \ && ldbl_compat='s,^#undef _GLIBCXX_LONG_DOUBLE_COMPAT$$,#define _GLIBCXX_LONG_DOUBLE_COMPAT 1,' ;\ sed -e "s,define __GLIBCXX__,define __GLIBCXX__ $$date," \ @@ -1113,7 +1115,7 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \ -e 's/VERSION/_GLIBCXX_VERSION/g' \ -e 's/WORDS_/_GLIBCXX_WORDS_/g' \ -e 's/ICONV_CONST/_GLIBCXX_ICONV_CONST/g' \ - -e '/[ ]_GLIBCXX_LONG_DOUBLE_COMPAT[ ]/d' \ + -e '/[ ]_GLIBCXX_LONG_DOUBLE_COMPAT[ ]/d' \ < ${CONFIG_HEADER} >> $@ ;\ echo "" >> $@ ;\ echo "#endif // _GLIBCXX_CXX_CONFIG_H" >> $@ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 9344d46..34fcf78 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, -# Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -769,6 +769,8 @@ ext_headers = \ ${ext_srcdir}/pointer.h \ ${ext_srcdir}/pool_allocator.h \ ${ext_srcdir}/rb_tree \ + ${ext_srcdir}/random \ + ${ext_srcdir}/random.tcc \ ${ext_srcdir}/rope \ ${ext_srcdir}/ropeimpl.h \ ${ext_srcdir}/slist \ @@ -1175,6 +1177,7 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; +$(top_srcdir)/fragment.am: $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh @@ -1210,10 +1213,15 @@ install-am: all-am installcheck: installcheck-am install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi mostlyclean-generic: clean-generic: @@ -1491,7 +1499,7 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \ visibility=`cat stamp-visibility` ;\ externtemplate=`cat stamp-extern-template` ;\ ldbl_compat='s,g,g,' ;\ - grep "^[ ]*#[ ]*define[ ][ ]*_GLIBCXX_LONG_DOUBLE_COMPAT[ ][ ]*1[ ]*$$" \ + grep "^[ ]*#[ ]*define[ ][ ]*_GLIBCXX_LONG_DOUBLE_COMPAT[ ][ ]*1[ ]*$$" \ ${CONFIG_HEADER} > /dev/null 2>&1 \ && ldbl_compat='s,^#undef _GLIBCXX_LONG_DOUBLE_COMPAT$$,#define _GLIBCXX_LONG_DOUBLE_COMPAT 1,' ;\ sed -e "s,define __GLIBCXX__,define __GLIBCXX__ $$date," \ @@ -1505,7 +1513,7 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \ -e 's/VERSION/_GLIBCXX_VERSION/g' \ -e 's/WORDS_/_GLIBCXX_WORDS_/g' \ -e 's/ICONV_CONST/_GLIBCXX_ICONV_CONST/g' \ - -e '/[ ]_GLIBCXX_LONG_DOUBLE_COMPAT[ ]/d' \ + -e '/[ ]_GLIBCXX_LONG_DOUBLE_COMPAT[ ]/d' \ < ${CONFIG_HEADER} >> $@ ;\ echo "" >> $@ ;\ echo "#endif // _GLIBCXX_CXX_CONFIG_H" >> $@ diff --git a/libstdc++-v3/include/ext/random b/libstdc++-v3/include/ext/random new file mode 100644 index 0000000..05cbc8f --- /dev/null +++ b/libstdc++-v3/include/ext/random @@ -0,0 +1,382 @@ +// Random number extensions -*- C++ -*- + +// Copyright (C) 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/random + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_RANDOM +#define _EXT_RANDOM 1 + +#pragma GCC system_header + +#include <random> +#ifdef __SSE2__ +# include <x86intrin.h> +#endif + + +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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<typename _Sseq, typename = typename + std::enable_if<!std::is_same<_Sseq, simd_fast_mersenne_twister_engine>::value> + ::type> + explicit + simd_fast_mersenne_twister_engine(_Sseq& __q) + { seed(__q); } + + void + seed(result_type __sd = default_seed); + + template<typename _Sseq> + typename std::enable_if<std::is_class<_Sseq>::value>::type + seed(_Sseq& __q); + + static constexpr result_type + min() + { return 0; }; + + static constexpr result_type + max() + { return std::numeric_limits<result_type>::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<typename _UIntType_2, size_t __m_2, + size_t __pos1_2, size_t __sl1_2, size_t __sl2_2, + size_t __sr1_2, size_t __sr2_2, + uint32_t __msk1_2, uint32_t __msk2_2, + uint32_t __msk3_2, uint32_t __msk4_2, + uint32_t __parity1_2, uint32_t __parity2_2, + uint32_t __parity3_2, uint32_t __parity4_2, + typename _CharT, typename _Traits> + 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<typename _UIntType_2, size_t __m_2, + size_t __pos1_2, size_t __sl1_2, size_t __sl2_2, + size_t __sr1_2, size_t __sr2_2, + uint32_t __msk1_2, uint32_t __msk2_2, + uint32_t __msk3_2, uint32_t __msk4_2, + uint32_t __parity1_2, uint32_t __parity2_2, + uint32_t __parity3_2, uint32_t __parity4_2, + typename _CharT, typename _Traits> + 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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<uint32_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> + sfmt607; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> + sfmt607_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 1279, 7, + 14, 3, 5, 1, + 0xf7fefffdU, 0x7fefcfffU, + 0xaff3ef3fU, 0xb5ffff7fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x20000000U> + sfmt1279; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 1279, 7, + 14, 3, 5, 1, + 0xf7fefffdU, 0x7fefcfffU, + 0xaff3ef3fU, 0xb5ffff7fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x20000000U> + sfmt1279_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 2281, 12, + 19, 1, 5, 1, + 0xbff7ffbfU, 0xfdfffffeU, + 0xf7ffef7fU, 0xf2f7cbbfU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x41dfa600U> + sfmt2281; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 2281, 12, + 19, 1, 5, 1, + 0xbff7ffbfU, 0xfdfffffeU, + 0xf7ffef7fU, 0xf2f7cbbfU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x41dfa600U> + sfmt2281_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 4253, 17, + 20, 1, 7, 1, + 0x9f7bffffU, 0x9fffff5fU, + 0x3efffffbU, 0xfffff7bbU, + 0xa8000001U, 0xaf5390a3U, + 0xb740b3f8U, 0x6c11486dU> + sfmt4253; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 4253, 17, + 20, 1, 7, 1, + 0x9f7bffffU, 0x9fffff5fU, + 0x3efffffbU, 0xfffff7bbU, + 0xa8000001U, 0xaf5390a3U, + 0xb740b3f8U, 0x6c11486dU> + sfmt4253_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 11213, 68, + 14, 3, 7, 3, + 0xeffff7fbU, 0xffffffefU, + 0xdfdfbfffU, 0x7fffdbfdU, + 0x00000001U, 0x00000000U, + 0xe8148000U, 0xd0c7afa3U> + sfmt11213; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 11213, 68, + 14, 3, 7, 3, + 0xeffff7fbU, 0xffffffefU, + 0xdfdfbfffU, 0x7fffdbfdU, + 0x00000001U, 0x00000000U, + 0xe8148000U, 0xd0c7afa3U> + sfmt11213_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 19937, 122, + 18, 1, 11, 1, + 0xdfffffefU, 0xddfecb7fU, + 0xbffaffffU, 0xbffffff6U, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x13c9e684U> + sfmt19937; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 19937, 122, + 18, 1, 11, 1, + 0xdfffffefU, 0xddfecb7fU, + 0xbffaffffU, 0xbffffff6U, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x13c9e684U> + sfmt19937_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 44497, 330, + 5, 3, 9, 3, + 0xeffffffbU, 0xdfbebfffU, + 0xbfbf7befU, 0x9ffd7bffU, + 0x00000001U, 0x00000000U, + 0xa3ac4000U, 0xecc1327aU> + sfmt44497; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 44497, 330, + 5, 3, 9, 3, + 0xeffffffbU, 0xdfbebfffU, + 0xbfbf7befU, 0x9ffd7bffU, + 0x00000001U, 0x00000000U, + 0xa3ac4000U, 0xecc1327aU> + sfmt44497_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 86243, 366, + 6, 7, 19, 1, + 0xfdbffbffU, 0xbff7ff3fU, + 0xfd77efffU, 0xbf9ff3ffU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0xe9528d85U> + sfmt86243; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 86243, 366, + 6, 7, 19, 1, + 0xfdbffbffU, 0xbff7ff3fU, + 0xfd77efffU, 0xbf9ff3ffU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0xe9528d85U> + sfmt86243_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 132049, 110, + 19, 1, 21, 1, + 0xffffbb5fU, 0xfb6ebf95U, + 0xfffefffaU, 0xcff77fffU, + 0x00000001U, 0x00000000U, + 0xcb520000U, 0xc7e91c7dU> + sfmt132049; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 132049, 110, + 19, 1, 21, 1, + 0xffffbb5fU, 0xfb6ebf95U, + 0xfffefffaU, 0xcff77fffU, + 0x00000001U, 0x00000000U, + 0xcb520000U, 0xc7e91c7dU> + sfmt132049_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 216091, 627, + 11, 3, 10, 1, + 0xbff7bff7U, 0xbfffffffU, + 0xbffffa7fU, 0xffddfbfbU, + 0xf8000001U, 0x89e80709U, + 0x3bd2b64bU, 0x0c64b1e4U> + sfmt216091; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 216091, 627, + 11, 3, 10, 1, + 0xbff7bff7U, 0xbfffffffU, + 0xbffffa7fU, 0xffddfbfbU, + 0xf8000001U, 0x89e80709U, + 0x3bd2b64bU, 0x0c64b1e4U> + sfmt216091_64; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std + +#include "random.tcc" + +#endif /* _EXT_RANDOM */ diff --git a/libstdc++-v3/include/ext/random.tcc b/libstdc++-v3/include/ext/random.tcc new file mode 100644 index 0000000..2a6fde0 --- /dev/null +++ b/libstdc++-v3/include/ext/random.tcc @@ -0,0 +1,445 @@ +// Random number extensions -*- C++ -*- + +// Copyright (C) 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/random.tcc + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/random} + */ + +#ifndef _EXT_RANDOM_TCC +#define _EXT_RANDOM_TCC 1 + +#pragma GCC system_header + + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<uint32_t>(__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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + template<typename _Sseq> + typename std::enable_if<std::is_class<_Sseq>::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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<size_t __sl1, size_t __sl2, size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, uint32_t __msk3, uint32_t __msk4> + 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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<size_t __shift> + inline void __rshift(uint32_t *__out, const uint32_t *__in) + { + uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32) + | static_cast<uint64_t>(__in[2])); + uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32) + | static_cast<uint64_t>(__in[0])); + + uint64_t __oh = __th >> (__shift * 8); + uint64_t __ol = __tl >> (__shift * 8); + __ol |= __th << (64 - __shift * 8); + __out[1] = static_cast<uint32_t>(__ol >> 32); + __out[0] = static_cast<uint32_t>(__ol); + __out[3] = static_cast<uint32_t>(__oh >> 32); + __out[2] = static_cast<uint32_t>(__oh); + } + + + template<size_t __shift> + inline void __lshift(uint32_t *__out, const uint32_t *__in) + { + uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32) + | static_cast<uint64_t>(__in[2])); + uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32) + | static_cast<uint64_t>(__in[0])); + + uint64_t __oh = __th << (__shift * 8); + uint64_t __ol = __tl << (__shift * 8); + __oh |= __tl >> (64 - __shift * 8); + __out[1] = static_cast<uint32_t>(__ol >> 32); + __out[0] = static_cast<uint32_t>(__ol); + __out[3] = static_cast<uint32_t>(__oh >> 32); + __out[2] = static_cast<uint32_t>(__oh); + } + + + template<size_t __sl1, size_t __sl2, size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, uint32_t __msk3, uint32_t __msk4> + 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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + 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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4, + typename _CharT, typename _Traits> + 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<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4, + typename _CharT, typename _Traits> + 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 + + +#endif // _EXT_RANDOM_TCC diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/copy.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/copy.cc new file mode 100644 index 0000000..8371f46 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/copy.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-02-16 Paolo Carlini <paolo.carlini@oracle.com> +// 2012-08-28 Ulrich Drepper <drepper@gmail.com>, 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 +// <http://www.gnu.org/licenses/>. + +#include <ext/random> + +void +test01() +{ + typedef uint32_t value_type; + + __gnu_cxx::simd_fast_mersenne_twister_engine<value_type, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> e(1); + + const auto f(e); + auto g(f); + g = g; // Suppress unused warning. +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/default.cc new file mode 100644 index 0000000..5b6489a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/default.cc @@ -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 <drepper@gmail.com>, 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 +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <ext/random> +#include <testsuite_hooks.h> + + +template<class SFMT> +void run_test(std::initializer_list<typename SFMT::result_type> 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<uint32_t>::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; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed1.cc new file mode 100644 index 0000000..1926958 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed1.cc @@ -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 <drepper@gmail.com>, 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 +// <http://www.gnu.org/licenses/>. + +#include <ext/random> + +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; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed2.cc new file mode 100644 index 0000000..464512c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed2.cc @@ -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 <drepper@gmail.com>, 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 +// <http://www.gnu.org/licenses/>. + +#include <ext/random> + +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; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc new file mode 100644 index 0000000..4820fa4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com> +// 2012-08-28 Ulrich Drepper <drepper@gmail.com>, 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 +// <http://www.gnu.org/licenses/>. + +#include <ext/random> + +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; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/equal.cc new file mode 100644 index 0000000..80022a6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/equal.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// 2012-08-28 Ulrich Drepper <drepper@gmail.com>, adapted for SFMT +// +// Copyright (C) 2008, 2009, 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 +// <http://www.gnu.org/licenses/>. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <ext/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::sfmt19937 u, v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/inequal.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/inequal.cc new file mode 100644 index 0000000..15aaf12 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/inequal.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-03-16 Paolo Carlini <paolo.carlini@oracle.com> +// 2012-08-28 Ulrich Drepper <drepper@gmail.com>, 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 +// <http://www.gnu.org/licenses/>. + +// 26.5.3.2 Class template mersenne_twister_engine [rand.eng.mers] + +#include <ext/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::sfmt19937 u, v; + + VERIFY( !(u != v) ); + + u.discard(100); + v.discard(100); + + VERIFY( !(u != v) ); + + v.discard(1); + + VERIFY( u != v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/serialize.cc new file mode 100644 index 0000000..ddc62b5 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/simd_fast_mersenne_twister_engine/operators/serialize.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// 2012-08-28 Ulrich Drepper <drepper@gmail.com>, adapted for SFMT +// +// Copyright (C) 2008, 2009, 2010, 2011, 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 +// <http://www.gnu.org/licenses/>. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <sstream> +#include <ext/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + __gnu_cxx::sfmt19937 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; +} |