On 23/06/21 18:51 +0100, Jonathan Wakely wrote: >Here's what I've committed. Tested x86_64-linux and powerpc64le-linux. >Pushed to trunk. > > > >commit b92d12d3fe3f1aa56d190d960e40c62869a6cfbb >Author: Cassio Neri >Date: Wed Jun 23 15:32:16 2021 > > libstdc++: More efficient std::chrono::year::leap > > Simple change to std::chrono::year::is_leap. If a year is multiple of 100, > then it's divisible by 400 if and only if it's divisible by 16. The latter > allows for better code generation. > > The expression is then either y%16 or y%4 which are both powers of two > and so it can be rearranged to use simple bitmask operations. > > Co-authored-by: Jonathan Wakely > Co-authored-by: Ulrich Drepper > > libstdc++-v3/ChangeLog: > > * include/std/chrono (chrono::year::is_leap()): Optimize. > >diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono >index 4631a727d73..863b6a27bdf 100644 >--- a/libstdc++-v3/include/std/chrono >+++ b/libstdc++-v3/include/std/chrono >@@ -1606,13 +1606,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > // [1] https://github.com/cassioneri/calendar > // [2] https://accu.org/journals/overload/28/155/overload155.pdf#page=16 > >+ // Furthermore, if y%100 != 0, then y%400==0 is equivalent to y%16==0, >+ // so we can rearrange the expression to (mult_100 ? y % 4 : y % 16)==0 But Ulrich pointed out I got my boolean logic all muddled up in the comment. Fixed with the attached patch!