[PATCH 1/4] libstdc++: More efficient date from days.

Jonathan Wakely jwakely@redhat.com
Thu Feb 25 14:02:56 GMT 2021


On 25/02/21 13:46 +0000, Cassio Neri via Libstdc++ wrote:
>Hi Jonathan,
>
>The issue is that I didn't cast __dp.count() to uint32_t:
>
>-      const auto __r0 = __dp.count() + __r2_e3;
>+      const auto __r0 = static_cast<uint32_t>(__dp.count()) + __r2_e3;
>
>The above would be a better fix. Indeed, __r0 belongs to [0, 2^32[ which allows
>all arithmetics that follow to be performed on uint32_t values. For performance
>this is better than using signed integers.

OK, I'll make that change shortly, thanks.

>I wrongly assumed __dp.count() was int32_t which would make __r0 also uint32_t.
>It turns out, it is int64_t so are __r0 and other expressions including
>__y1 + __z2. Hence, we're losing a bit of performance. I'm glad the compiler
>warned us. (Although I don't understand why I didn't get the warning.)

You won't see it without -Wsystem-headers because warnings are
suppressed by default in libstdc++ headers.

There are a few annoyances in <chrono> due to the unnecessary use of
64-bit integers, which then causes narrowing conversions because some
constructors take int parameters.
e.g. https://github.com/cplusplus/draft/pull/4184




More information about the Gcc-patches mailing list