]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Improve operator-(weekday x, weekday y)
authorCassio Neri <cassio.neri@gmail.com>
Tue, 14 Nov 2023 00:27:39 +0000 (00:27 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 13 Mar 2024 09:49:54 +0000 (09:49 +0000)
commita491dd0eac360758dd20b29bef78b27d005547a1
tree361d06026973c027fe79114ff6f816829246c188
parenta7c37987a57f551794294518c6f6670690e1aad2
libstdc++: Improve operator-(weekday x, weekday y)

The current implementation calls __detail::__modulo which is relatively
expensive.

A better implementation is possible if we assume that x.ok() && y.ok() == true,
so that n = x.c_encoding() - y.c_encoding() is in [-6, 6]. In this case, it
suffices to return n >= 0 ? n : n + 7.

The above is allowed by [time.cal.wd.nonmembers]/5: the returned value is
unspecified when x.ok() || y.ok() == false.

The assembly emitted for x86-64 and ARM can be seen in:
https://godbolt.org/z/nMdc5vv9n.

libstdc++-v3/ChangeLog:

* include/std/chrono (operator-(const weekday&, const weekday&)):
Optimize.

(cherry picked from commit f71352c71d78ac977ea0e71a6900699a8cf09219)
libstdc++-v3/include/std/chrono
This page took 0.053266 seconds and 6 git commands to generate.