From: Jonathan Wakely <jwakely@redhat.com>
To: cassio.neri@gmail.com
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/4] libstdc++: More efficient date from days.
Date: Thu, 25 Feb 2021 16:57:59 +0000 [thread overview]
Message-ID: <20210225165759.GH3008@redhat.com> (raw)
In-Reply-To: <20210225141913.GG3008@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 830 bytes --]
On 25/02/21 14:19 +0000, Jonathan Wakely wrote:
>On 25/02/21 14:02 +0000, Jonathan Wakely wrote:
>>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.
>
>We still need to cast to int for the return value though, because
>converting from uint32_t to int is still narrowing.
I've committed this now.
Tested powerpc64le-linux, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 947 bytes --]
commit a47cec4ca7302e65f63490ad7f251c5a469bc0e0
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Feb 25 16:57:20 2021
libstdc++: Use uint32_t for all year_month_day::_S_from_days arithmetic
libstdc++-v3/ChangeLog:
* include/std/chrono (year_month_day::_S_from_days): Perform
all calculations with type uint32_t.
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index eef503af274..fcdaee7328e 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2455,7 +2455,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr auto __z2 = static_cast<uint32_t>(-1468000);
constexpr auto __r2_e3 = static_cast<uint32_t>(536895458);
- const auto __r0 = __dp.count() + __r2_e3;
+ const auto __r0 = static_cast<uint32_t>(__dp.count()) + __r2_e3;
const auto __n1 = 4 * __r0 + 3;
const auto __q1 = __n1 / 146097;
prev parent reply other threads:[~2021-02-25 16:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-23 13:24 Cassio Neri
2021-02-24 17:28 ` Jonathan Wakely
2021-02-25 11:56 ` Jonathan Wakely
2021-02-25 13:46 ` Cassio Neri
2021-02-25 14:02 ` Jonathan Wakely
2021-02-25 14:19 ` Jonathan Wakely
2021-02-25 16:57 ` Jonathan Wakely [this message]
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=20210225165759.GH3008@redhat.com \
--to=jwakely@redhat.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).