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 11:56:09 +0000 [thread overview]
Message-ID: <20210225115609.GE3008@redhat.com> (raw)
In-Reply-To: <20210224172826.GZ3008@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1722 bytes --]
On 24/02/21 17:28 +0000, Jonathan Wakely wrote:
>On 23/02/21 13:24 +0000, Cassio Neri via Libstdc++ wrote:
>>This patch reimplements std::chrono::year_month_day::_S_from_days() which
>>retrieves a date from the number of elapsed days since 1970/01/01. The new
>>implementation is based on Proposition 6.3 of Neri and Schneider, "Euclidean
>>Affine Functions and Applications to Calendar Algorithms" available at
>>https://arxiv.org/abs/2102.06959.
>>
>>The aforementioned paper benchmarks the implementation against several
>>counterparts, including libc++'s (which is identical to the current
>>implementation). The results, shown in Figure 4, indicate the new algorithm is
>>2.2 times faster than the current one.
>>
>>The patch adds a test which loops through all integers in [-12687428, 11248737],
>>and for each of them, gets the corresponding date and compares the result
>>against its expected value. The latter is calculated using a much simpler and
>>easy to understand algorithm but which is also much slower.
>>
>>The interval used in the test covers the full range of values for which a
>>roundtrip must work [time.cal.ymd.members]. Despite its completeness the test
>>runs in a matter of seconds.
>>
>>libstdc++-v3/ChangeLog:
>>
>> * include/std/chrono:
>> * testsuite/std/time/year_month_day/3.cc: New test.
>
>Thanks! I'm committing this to trunk (it only changes new C++20
>material so OK during stage 4 ... and anyway it's both faster and
>better tested than the old code).
>
>I've tweaked it slightly to keep some lines below 80 columns, but no
>changes except whitespace.
I've made the attached tweak, to avoid a narrowing conversion from
long to int. Tested x86_64-linux, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 974 bytes --]
commit 75c74a83acee3f51e6753b8159fa600fe2d86810
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Feb 25 11:48:18 2021
libstdc++: Fix narrowing conversion in year_month_day [PR 99265]
libstdc++-v3/ChangeLog:
PR libstdc++/99265
* include/std/chrono (year_month_day::_S_from_days): Cast long
to int explicitly.
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index feb2c2a1fad..eef503af274 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2481,8 +2481,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const auto __m1 = __j ? __m0 - 12 : __m0;
const auto __d1 = __d0 + 1;
- return year_month_day{chrono::year{__y1 + __z2}, chrono::month{__m1},
- chrono::day{__d1}};
+ return year_month_day{chrono::year{static_cast<int>(__y1 + __z2)},
+ chrono::month{__m1}, chrono::day{__d1}};
}
// Days since 1970/01/01.
next prev parent reply other threads:[~2021-02-25 11:56 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 [this message]
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
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=20210225115609.GE3008@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).