gcc/libstdc++-v3/include
Antony Polukhin 7259a9d577 Optimize std::to_chars
Bunch of micro optimizations for std::to_chars:
* For base == 8 replacing the lookup in __digits table with arithmetic
computations leads to a same CPU cycles for a loop (exchanges two movzx
with 3 bit ops). However this saves 129 bytes of data and totally avoids
a chance of cache misses on __digits.
* For base == 16 replacing the lookup in __digits table with
arithmetic computations leads to a few additional instructions, but
totally avoids a chance of cache misses on __digits (- ~9 cache misses
for worst case) and saves 513 bytes of const data.
* Replacing __first[pos] and __first[pos - 1] with __first[1] and
__first[0] on final iterations saves ~2% of code size.
* Removing trailing '\0' from arrays of digits allows the linker to
merge the symbols (so that "0123456789abcdefghijklmnopqrstuvwxyz" and
"0123456789abcdef" could share the same address). This improves data
locality and reduces binary sizes.
* Using __detail::__to_chars_len_2 instead of a generic
__detail::__to_chars_len makes the operation O(1) instead of O(N). It
also makes the code two times shorter.

In sum: this significantly reduces the size of a binary (for about 4KBs
only for base-8 conversion), deals with latency (CPU cache misses)
without changing the iterations count and without adding costly
instructions into the loops.

2019-08-30  Antony Polukhin  <antoshkka@gmail.com>

	* include/std/charconv (__detail::__to_chars_8)
	__detail::__to_chars_16): Replace array of precomputed digits with
	arithmetic operations to avoid CPU cache misses. Remove zero
	termination from array of digits to allow symbol merge with generic
	implementation of __detail::__to_chars. Replace final offsets with
	constants. Use __detail::__to_chars_len_2 instead of a generic
	__detail::__to_chars_len.
	(__detail::__to_chars): Remove zero termination from array of digits.
	(__detail::__to_chars_2): Leading digit is always '1'.

From-SVN: r275205
2019-08-30 17:25:24 +01:00
..
backward Remove using-declarations that add std names to __gnu_cxx 2019-05-31 11:35:07 +01:00
bits PR libstdc++/89164 enforce constraints for uninitialized algos 2019-08-30 14:54:49 +01:00
c Update copyright years. 2019-01-01 13:31:55 +01:00
c_compatibility In C++17 <math.h> should not put special functions in global namespace 2019-03-21 14:03:56 +00:00
c_global Avoid undefined behaviour in std::byte operators (LWG 2950) 2019-06-18 12:39:43 +01:00
c_std Update copyright years. 2019-01-01 13:31:55 +01:00
debug PR libstdc++/87431 re-adjust never-valueless optimizations 2019-04-05 17:56:09 +01:00
decimal Update copyright years. 2019-01-01 13:31:55 +01:00
experimental P0325R4 to_array from LFTS with updates 2019-08-08 11:18:53 +01:00
ext skip Cholesky decomposition in is>>n_mv_dist 2019-08-09 09:20:58 +00:00
parallel Fix markup for Parallel Mode docs 2019-05-02 16:44:51 +01:00
precompiled Implement "P0631R4 Math Constants" for C++20 2019-07-31 17:40:39 +01:00
pstl pstl_config.h (_PSTL_PRAGMA_SIMD_SCAN, [...]): Define to OpenMP 5.0 pragmas even for GCC 10.0+. 2019-06-25 08:59:12 +02:00
std Optimize std::to_chars 2019-08-30 17:25:24 +01:00
tr1 Improve API docs for mathematical special functions 2019-05-02 16:44:59 +01:00
tr2 Fix after P0600. 2019-01-21 11:47:30 +00:00
Makefile.am Implement "P0631R4 Math Constants" for C++20 2019-07-31 17:40:39 +01:00
Makefile.in Implement "P0631R4 Math Constants" for C++20 2019-07-31 17:40:39 +01:00