libstdc++: Micro-optimize __from_chars_pow2_base
authorPatrick Palka <ppalka@redhat.com>
Mon, 18 Apr 2022 21:22:55 +0000 (17:22 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 18 Apr 2022 21:22:55 +0000 (17:22 -0400)
commitd210653f3907ac1829fd275d067b2855ea53da24
tree6e394b80ee6b02b74647c5a1a7220d4a2477c6d6
parent021b51814d67bedd8f41ac07edfd05654140c6e5
libstdc++: Micro-optimize __from_chars_pow2_base

In the first iteration of __from_chars_pow2_base's main loop, we need
to remember the value of the leading significant digit for sake of the
overflow check at the end (for base > 2).

This patch manually unrolls this first iteration so as to not encumber
the entire loop with logic that only the first iteration needs.  This
seems to significantly improve performance:

Base  Before  After (seconds, lower is better)
   2    9.36   9.37
   8    3.66   2.93
  16    2.93   1.91
  32    2.39   2.24

libstdc++-v3/ChangeLog:

* include/std/charconv (__from_chars_pow2_base): Manually
unroll the first iteration of the main loop and simplify
accordingly.
libstdc++-v3/include/std/charconv