mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
The philox counter increment that happens in
philox_engine::_M_transition(), applies +1 to _M_x[0] before the bitwise
OR with (_M_x[1] << __w), so the carry from _M_x[0] is merged into the
_M_x[1] portion rather than being added to it. This causes the counter
to cycle prematurely and never advance past {0, 0, 1, 2^w - 1}.
Fix by changing operations order, which results in forming the
full-width value from _M_x[1]:_M_x[0] and then adding 1 on both the n ==
4 and n == 2 paths.
libstdc++-v3/ChangeLog:
* include/bits/random.tcc (philox_engine::_M_transtiion): Fix
counter increment to propagate carry correctly.
* testsuite/26_numerics/random/philox_engine/operators/counter_carry.cc:
New test.
Signed-off-by: Elena Tyuleneva <elena.tyuleneva@intel.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>