From: Jonathan Wakely <jwakely@redhat.com>
To: cassio.neri@gmail.com
Cc: "Koning, Paul" <Paul.Koning@dell.com>,
libstdc++ <libstdc++@gcc.gnu.org>,
Gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: More efficient std::chrono::year::leap.
Date: Wed, 23 Jun 2021 18:52:36 +0100 [thread overview]
Message-ID: <YNN05My95aTkoZw6@redhat.com> (raw)
In-Reply-To: <YNN0lYiTh2C9Uodx@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1562 bytes --]
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 <cassio.neri@gmail.com>
>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 <jwakely@redhat.com>
> Co-authored-by: Ulrich Drepper <drepper@redhat.com>
>
> 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!
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1122 bytes --]
commit 4a404f66b09d661bdc60e7e0d5d08f00c4e194db
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jun 23 18:50:03 2021
libstdc++: Fix comment in chrono::year::is_leap()
libstdc++-v3/ChangeLog:
* include/std/chrono (chrono::year::is_leap()): Fix incorrect
logic in comment.
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index 863b6a27bdf..0b597be1944 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -1606,8 +1606,8 @@ _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
+ // Furthermore, if y%100 == 0, then y%400==0 is equivalent to y%16==0,
+ // so we can simplify it to (!mult_100 && y % 4 == 0) || y % 16 == 0,
// which is equivalent to (y & (mult_100 ? 15 : 3)) == 0.
// See https://gcc.gnu.org/pipermail/libstdc++/2021-June/052815.html
next prev parent reply other threads:[~2021-06-23 17:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-21 17:46 Cassio Neri
2021-05-21 18:05 ` Koning, Paul
2021-05-21 18:44 ` Cassio Neri
2021-06-23 11:45 ` Jonathan Wakely
2021-06-23 13:16 ` Jonathan Wakely
2021-06-23 17:51 ` Jonathan Wakely
2021-06-23 17:52 ` Jonathan Wakely [this message]
2021-06-24 11:42 ` Cassio Neri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YNN05My95aTkoZw6@redhat.com \
--to=jwakely@redhat.com \
--cc=Paul.Koning@dell.com \
--cc=cassio.neri@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).