gcc/libstdc++-v3/testsuite/26_numerics
Jonathan Wakely 3c21913415 libstdc++: Optimise GCD algorithms
The current std::gcd and std::chrono::duration::_S_gcd algorithms are
both recursive. This is potentially expensive to evaluate in constant
expressions, because each level of recursion makes a new copy of the
function to evaluate. The maximum number of steps is bounded
(proportional to the number of decimal digits in the smaller value) and
so unlikely to exceed the limit for constexpr nesting, but the memory
usage is still suboptimal. By using an iterative algorithm we avoid
that compile-time cost. Because looping in constexpr functions is not
allowed until C++14, we need to keep the recursive implementation in
duration::_S_gcd for C++11 mode.

For std::gcd we can also optimise runtime performance by using the
binary GCD algorithm.

libstdc++-v3/ChangeLog:

	* include/std/chrono (duration::_S_gcd): Use iterative algorithm
	for C++14 and later.
	* include/std/numeric (__detail::__gcd): Replace recursive
	Euclidean algorithm with iterative version of binary GCD algorithm.
	* testsuite/26_numerics/gcd/1.cc: Test additional inputs.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Adjust dg-error lines.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
	* testsuite/experimental/numeric/gcd.cc: Test additional inputs.
	* testsuite/26_numerics/gcd/2.cc: New test.
2020-09-03 12:46:13 +01:00
..
accumulate libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
adjacent_difference libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
bit libstdc++ P1956R1 On the names of low-level bit manipulation functions 2020-02-17 17:09:18 +00:00
complex
endian
exclusive_scan libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
gcd libstdc++: Optimise GCD algorithms 2020-09-03 12:46:13 +01:00
headers libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
inclusive_scan libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
inner_product libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
iota libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
lcm libstdc++: Optimise GCD algorithms 2020-09-03 12:46:13 +01:00
midpoint libstdc++: midpoint should not constrain T is complete (LWG 3200) 2020-02-19 15:28:45 +00:00
numbers libstdc++: Avoid using __float128 in strict modes 2020-07-31 19:58:03 +01:00
partial_sum libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
pstl/numeric_ops
random libstdc++: Use RDRAND as fallback if RDSEED keeps failing (PR 94087) 2020-05-19 23:04:45 +01:00
reduce libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
slice libstdc++: Add comparison operators to types from Numerics clause 2020-04-08 16:51:59 +01:00
slice_array
transform_exclusive_scan libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
transform_inclusive_scan libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
transform_reduce libstdc++: P1645R1 constexpr for <numeric> algorithms 2020-02-26 10:23:17 -05:00
valarray libstdc++: Use c++NN_only effective target to tests 2020-07-31 19:58:02 +01:00
lerp.cc