]> git.ipfire.org Git - thirdparty/gcc.git/commit - libstdc++-v3/include/std/chrono
libstdc++: Simplify year::is_leap()
authorCassio Neri <cassio.neri@gmail.com>
Sat, 11 Nov 2023 22:59:50 +0000 (22:59 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 14 Nov 2023 22:32:08 +0000 (22:32 +0000)
commit86a0df1a6c7fe4a835620b868e76ea78d42d6620
treeaa03c7925bbe6429e24ed974d5b6e949ef3c4d1e
parentb011535456396a6846ff24fb5b1baea8fe0a33b1
libstdc++: Simplify year::is_leap()

The current implementation returns
    (_M_y & (__is_multiple_of_100 ? 15 : 3)) == 0;
where __is_multiple_of_100 is calculated using an obfuscated algorithm which
saves one ror instruction when compared to _M_y % 100 == 0 [1].

In leap years calculation, it's correct to replace the divisibility check by
100 with the one by 25. It turns out that _M_y % 25 == 0 also saves the ror
instruction [2]. Therefore, the obfuscation is not required.

[1] https://godbolt.org/z/5PaEv6a6b
[2] https://godbolt.org/z/55G8rn77e

libstdc++-v3/ChangeLog:

* include/std/chrono (year::is_leap): Clear code.
libstdc++-v3/include/std/chrono