From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id DB98D3989033 for ; Wed, 23 Jun 2021 17:52:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB98D3989033 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-D3eZHOWiNy2u_4ex8zv9Mw-1; Wed, 23 Jun 2021 13:52:39 -0400 X-MC-Unique: D3eZHOWiNy2u_4ex8zv9Mw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11886800D55; Wed, 23 Jun 2021 17:52:38 +0000 (UTC) Received: from localhost (unknown [10.33.36.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id B343F5C1A1; Wed, 23 Jun 2021 17:52:37 +0000 (UTC) Date: Wed, 23 Jun 2021 18:52:36 +0100 From: Jonathan Wakely To: cassio.neri@gmail.com Cc: "Koning, Paul" , libstdc++ , Gcc-patches Subject: Re: [PATCH] libstdc++: More efficient std::chrono::year::leap. Message-ID: References: <34C4F25A-6333-4C08-BBFF-8E86A5A9B764@dell.com> MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="H5ls60iywOF7HDYa" Content-Disposition: inline X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jun 2021 17:52:44 -0000 --H5ls60iywOF7HDYa Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline 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 >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 > Co-authored-by: Ulrich Drepper > > 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! --H5ls60iywOF7HDYa Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 4a404f66b09d661bdc60e7e0d5d08f00c4e194db Author: Jonathan Wakely 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 --H5ls60iywOF7HDYa--