On Wed, 17 Dec 2025 at 20:22, Tomasz Kaminski <[email protected]> wrote: > > > > On Wed, Dec 17, 2025 at 8:51 PM Jonathan Wakely <[email protected]> wrote: >> >> This moves the __detail::_Select_uint_least_t<N>::type class to >> namespace scope and extends it with more 128-bit arithmetic operations, >> implemented in terms of uint64_t. >> >> Now std::philox_engine can use _Select_uint_least_t<w*2>::type instead >> of __uint128_t, so that it works on targets without 128-bit integers. >> This also means that targets that do support __uint128_t only use it >> when actually necessary, so that we use uint64_t when generating a >> 32-bit result (e.g. with std::philox4x32). >> >> libstdc++-v3/ChangeLog: >> >> * include/bits/random.h [!__SIZEOF_INT128__] (__rand_uint128): >> Refactor and rename _Select_uint_least_t<128>::type to a new >> class. Make all members constexpr. Add new member functions for >> additional arithmetic and bitwise operations, and comparisons. >> (__detail::_Select_uint_least_t<>::type): Define as an alias of >> __rand_uint128. >> * include/bits/random.tcc (philox_engine::_M_mulhi): Use >> _Select_uint_least_t<w*2>::type instead of __uint128_t. >> (philox_engine::_M_transition): Likewise. >> * include/bits/version.def (philox_engine): Remove extra_cond. >> * include/bits/version.h: Regenerate. >> * testsuite/26_numerics/random/philox4x32.cc: Remove >> dg-require-cpp-feature-test directive. >> * testsuite/26_numerics/random/philox4x64.cc: Likewise. >> * testsuite/26_numerics/random/philox_engine/cons/copy.cc: >> Likewise. >> * testsuite/26_numerics/random/philox_engine/cons/default.cc: >> Likewise. >> * testsuite/26_numerics/random/philox_engine/cons/seed.cc: >> Likewise. >> * testsuite/26_numerics/random/philox_engine/operators/equal.cc: >> Likewise. >> * testsuite/26_numerics/random/philox_engine/operators/serialize.cc: >> Likewise. >> * >> testsuite/26_numerics/random/philox_engine/requirements/constants.cc: >> Likewise. >> * >> testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc: >> Likewise. >> >> Co-authored-by: Jakub Jelinek <[email protected]> >> --- >> >> Tested x86_64-linux >> Also checked -m32 and -D_GLIBCXX_USE_OLD_GENERATE_CANONICAL > > LGTM. > I haven't fully verified the algorithms part of __int128, but they look ok in > general. > Checked, if additional operations are matching ones that were removed.
Thanks for checking it. One reason for hoisting this class out of the _Select_uint_least_t template was that it should be easier to add proper tests for the operators now. I didn't do that as part of this fix, because the priority was just to fix the failing tests, and because the tests for std::uniform_real_distribution and std::linear_congruential_engine contain checks that the results are as expected, which confirms that the arithmetic is giving the expected answers for the current uses of the class.
