From patchwork Sat Sep 19 10:37:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 1367549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Bep7oEfx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BtnGd4Xqbz9sT6 for ; Sat, 19 Sep 2020 20:37:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEDA63987917; Sat, 19 Sep 2020 10:37:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEDA63987917 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600511875; bh=T1vJkXMD9sF1rUHcdzN4JHzdRQotCaI7QXUWntlF39E=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Bep7oEfx+DcAGpBDKVbeukCHyLCFv9Du/QqYwrfUakHjhgGFisiqws4Jm2Bdb/agR nNqk62/TAjNcB8YUprhq1kRuXHrmlTwi1kl3bAzL1y0VLxl3856sbwUBFSakgGjpq/ KUEJg+LU2r5PO0eq32TkfJS80Ejo571vskUQc7U0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from avasout04.plus.net (avasout04.plus.net [212.159.14.19]) by sourceware.org (Postfix) with ESMTPS id 2DB9A3986427 for ; Sat, 19 Sep 2020 10:37:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2DB9A3986427 Received: from deneb ([80.229.24.9]) by smtp with ESMTP id JaFZkEBgFrXCcJaFak5Zos; Sat, 19 Sep 2020 11:37:51 +0100 X-Clacks-Overhead: "GNU Terry Pratchett" X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=Q+xJH7+a c=1 sm=1 tr=0 a=E/9URZZQ5L3bK/voZ0g0HQ==:117 a=E/9URZZQ5L3bK/voZ0g0HQ==:17 a=reM5J-MqmosA:10 a=20KFwNOVAAAA:8 a=fXM4FEJ6vOjzBBum0QkA:9 a=CjuIK1q_8ugA:10 a=-An2I_7KAAAA:8 a=mDV3o1hIAAAA:8 a=Wd7Erw1rZoCISAI73doA:9 a=Sq34B_EcNBM9_nrAYB9S:22 a=_FVE-zBwftR9WsbkzFJk:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 Received: from mac by deneb with local (Exim 4.92) (envelope-from ) id 1kJaFZ-0002PR-1q; Sat, 19 Sep 2020 11:37:49 +0100 Date: Sat, 19 Sep 2020 11:37:49 +0100 To: Jonathan Wakely Subject: libstdc++: Fix chrono::__detail::ceil to work with C++11 (was Re: [PATCH v5 6/8] libstdc++ atomic_futex: Avoid rounding errors in std::future::wait_* [PR91486]) Message-ID: <20200919103749.GA7523@mcrowe.com> References: <20200911144059.GU6061@redhat.com> <20200911172204.GV6061@redhat.com> <20200911185936.GW6061@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200911185936.GW6061@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CMAE-Envelope: MS4wfAJIV+DPKIv+J+8QMfo5ISL02CTkUsH2MfYWrokih8zbeBqAEyCqiprXbrE68I4woScL7y8famEquZfXIGGdFXvVcPFkcVJAxV8XLaYQ+orHOHU5ov09 7CHND8TyMRgyRE7jyyev5OktYFWLbxGBAMQ= X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=unavailable 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-Patchwork-Original-From: Mike Crowe via Gcc-patches From: Mike Crowe Reply-To: Mike Crowe Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" On Friday 11 September 2020 at 19:59:36 +0100, Jonathan Wakely wrote: > commit 53ad6b1979f4bd7121e977c4a44151b14d8a0147 > Author: Jonathan Wakely > Date: Fri Sep 11 19:59:11 2020 > > libstdc++: Fix chrono::__detail::ceil to work with C++11 > > In C++11 constexpr functions can only have a return statement, so we > need to fix __detail::ceil to make it valid in C++11. This can be done > by moving the comparison and increment into a new function, __ceil_impl, > and calling that with the result of the duration_cast. > > This would mean the standard C++17 std::chrono::ceil function would make > two further calls, which would add too much overhead when not inlined. > For C++17 and later use a using-declaration to add chrono::ceil to > namespace __detail. For C++11 and C++14 define chrono::__detail::__ceil > as a C++11-compatible constexpr function template. > > > libstdc++-v3/ChangeLog: > > * include/std/chrono [C++17] (chrono::__detail::ceil): Add > using declaration to make chrono::ceil available for internal > use with a consistent name. > (chrono::__detail::__ceil_impl): New function template. > (chrono::__detail::ceil): Use __ceil_impl to compare and > increment the value. Remove SFINAE constraint. This change introduces a new implementation of ceil that, as far as I can tell, has no tests. A patch is attached to add the equivalent of the existing chrono::ceil tests for chrono::__detail::ceil. The tests fail to compile if I run them without 53ad6b1979f4bd7121e977c4a44151b14d8a0147 as expected due to the previous non-C++11-compliant implementation. Mike. From b9dffbf4f1bc05a887269ea95a3b86d5a611e720 Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Wed, 16 Sep 2020 15:31:28 +0100 Subject: [PATCH 1/2] libstdc++: Test C++11 implementation of std::chrono::__detail::ceil Commit 53ad6b1979f4bd7121e977c4a44151b14d8a0147 split the implementation of std::chrono::__detail::ceil so that when compiling for C++17 and later std::chrono::ceil is used but when compiling for earlier versions a separate implementation is used to comply with C++11's limited constexpr rules. Let's run the equivalent of the existing std::chrono::ceil test cases on std::chrono::__detail::ceil too to make sure that it doesn't get broken. libstdc++-v3/ChangeLog: * testsuite/20_util/duration_cast/rounding_c++11.cc: Copy rounding.cc and alter to support compilation for C++11 and to test std::chrono::__detail::ceil. --- .../20_util/duration_cast/rounding_c++11.cc | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc diff --git a/libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc b/libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc new file mode 100644 index 00000000000..f10d27fd082 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2016-2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile { target c++11 } } + +#include + +using std::chrono::seconds; +using std::chrono::milliseconds; + +using fp_seconds = std::chrono::duration; + +static_assert( std::chrono::__detail::ceil(milliseconds(1000)) + == seconds(1) ); +static_assert( std::chrono::__detail::ceil(milliseconds(1001)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(1500)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(1999)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(2000)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(2001)) + == seconds(3) ); +static_assert( std::chrono::__detail::ceil(milliseconds(2500)) + == seconds(3) ); +static_assert( std::chrono::__detail::ceil(milliseconds(500)) + == fp_seconds{0.5f} ); -- 2.28.0