From: Antony Polukhin Date: Mon, 9 Sep 2019 11:12:44 +0000 (+0000) Subject: Minor std::to_chars optimisation for base 10 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d0e086ae4f9ac2138a5fa6c6405c61b1f7ae032d;p=gcc.git Minor std::to_chars optimisation for base 10 __to_chars_10_impl is quite fast. According to the IACA the main loop takes only 6.0 cycles, the whole function with one iteration takes 10.0 cycles. Replacing the __first[pos] and __first[pos - 1] with __first[0] and __first[1] drops the function time to 7.53 cycles. 2019-09-09 Antony Polukhin * include/bits/charconv.h (__detail::__to_chars_10_impl): Replace final offsets with constants. From-SVN: r275514 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0aff148effb..6cf1737c7fa 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2019-09-09 Antony Polukhin + + * include/bits/charconv.h (__detail::__to_chars_10_impl): Replace + final offsets with constants. + 2019-09-09 Jonathan Wakely * include/bits/range_access.h (__adl_to_address): Remove. diff --git a/libstdc++-v3/include/bits/charconv.h b/libstdc++-v3/include/bits/charconv.h index 0911660fab6..a5b6be567bc 100644 --- a/libstdc++-v3/include/bits/charconv.h +++ b/libstdc++-v3/include/bits/charconv.h @@ -92,11 +92,11 @@ namespace __detail if (__val >= 10) { auto const __num = __val * 2; - __first[__pos] = __digits[__num + 1]; - __first[__pos - 1] = __digits[__num]; + __first[1] = __digits[__num + 1]; + __first[0] = __digits[__num]; } else - __first[__pos] = '0' + __val; + __first[0] = '0' + __val; } } // namespace __detail