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 ESMTPS id E93AA3857809 for ; Tue, 19 Apr 2022 10:42:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E93AA3857809 Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-AIM7cchxN2iaWPMqS5CsOw-1; Tue, 19 Apr 2022 06:42:46 -0400 X-MC-Unique: AIM7cchxN2iaWPMqS5CsOw-1 Received: by mail-yb1-f198.google.com with SMTP id i5-20020a258b05000000b006347131d40bso14371491ybl.17 for ; Tue, 19 Apr 2022 03:42:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=es7ppFMCVFr4wXgUD3I+x5EjKBvHDctO0nnqvR55Qi4=; b=Ygv3rQIybw2KOgtLKaKyJ6LSSgrSDse4V002+ZUnFQbDa/xE65ylLMvF4B1BPgRG8c 5jwpfByHKGiw9d1CMSlLRfxExcKeynfpPAD8g0XXMhhCUEW03TVx9M4Uelm7vmuqSt41 FzolsE3TsHiou26CdUZjxfdXZAhwzM10tH1k8L+7meekljwYRHbkuVkMJYhgz9ezHL1v Wx+KNeptDQHxFy+ySnazR46y2uGqVYI9+/CNVcoG0t0hiyFVwgeHD3wJK22GpwZzOMjO v8ITU1ov09Qo7tpUPj6vWQlBTU3ZCcXtmsm178flpHMRHAZr0peRGh7sFLfmC/XojZSg 53aQ== X-Gm-Message-State: AOAM53328eSFqctwDvMghEC7oC7pwbs4VbJBmVZ7eJjqCzkfLS1Ysz/J hn5Oq0L+0pZGGDt/EMXDLFkKn1yjl9XGjFr38hh4+d50tJW4xV0/LB4Oi3DH8pYEfFGZ7Slr8Kg 8FLODU2o1dJUFogN6vw+HB6TLgFnvkO/6RA== X-Received: by 2002:a25:3a02:0:b0:641:68ce:1fe9 with SMTP id h2-20020a253a02000000b0064168ce1fe9mr14463450yba.320.1650364966371; Tue, 19 Apr 2022 03:42:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUgYLIi4TfZR/tfJpSrfnoExO0220oH2KVLZR0ncPJDfRUDLCz2kekC3Tr7ddJlsy0j03EQV+rMGREfFfwKwA= X-Received: by 2002:a25:3a02:0:b0:641:68ce:1fe9 with SMTP id h2-20020a253a02000000b0064168ce1fe9mr14463444yba.320.1650364966203; Tue, 19 Apr 2022 03:42:46 -0700 (PDT) MIME-Version: 1.0 References: <20220414194716.334032-1-ppalka@redhat.com> In-Reply-To: <20220414194716.334032-1-ppalka@redhat.com> From: Jonathan Wakely Date: Tue, 19 Apr 2022 11:42:35 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Stop defining _GLIBCXX_ASSERTIONS in floating_to_chars.cc To: Patrick Palka Cc: gcc Patches , "libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.9 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 19 Apr 2022 10:42:49 -0000 On Thu, 14 Apr 2022 at 20:48, Patrick Palka via Libstdc++ wrote: > > Assertions were originally enabled in the compiled-in floating-point > std::to_chars implementation to help shake out any bugs, but they > apparently impose a significant performance penalty, in particular for > the hex formatting which is around 25% slower with assertions enabled. > This seems too high of a cost for unconditionally enabling them. > > The newly added calls to __builtin_unreachable work around the compiler > no longer knowing that the set of valid values of 'fmt' is limited (which > was previously upheld by an assert). > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? OK, thanks. > > libstdc++-v3/ChangeLog: > > * src/c++17/floating_to_chars.cc: Don't define > _GLIBCXX_ASSERTIONS. > (__floating_to_chars_shortest): Add __builtin_unreachable calls to > squelch false-positive -Wmaybe-uninitialized and -Wreturn-type > warnings. > (__floating_to_chars_precision): Likewise. > --- > libstdc++-v3/src/c++17/floating_to_chars.cc | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc > index 66bd457cbe2..4599d68a39c 100644 > --- a/libstdc++-v3/src/c++17/floating_to_chars.cc > +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc > @@ -22,9 +22,6 @@ > // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see > // . > > -// Activate __glibcxx_assert within this file to shake out any bugs. > -#define _GLIBCXX_ASSERTIONS 1 > - > #include > > #include > @@ -1114,6 +1111,7 @@ template > } > > __glibcxx_assert(false); > + __builtin_unreachable(); > } > > template > @@ -1202,6 +1200,8 @@ template > effective_precision = min(precision, max_eff_scientific_precision); > output_specifier = "%.*Lg"; > } > + else > + __builtin_unreachable(); > const int excess_precision = (fmt != chars_format::general > ? precision - effective_precision : 0); > > @@ -1234,6 +1234,8 @@ template > output_length_upper_bound = sign + strlen("0"); > output_length_upper_bound += sizeof(radix) + effective_precision; > } > + else > + __builtin_unreachable(); > > // Do the sprintf into the local buffer. > char buffer[output_length_upper_bound+1]; > @@ -1570,6 +1572,7 @@ template > } > > __glibcxx_assert(false); > + __builtin_unreachable(); > } > > // Define the overloads for float. > -- > 2.36.0.rc2.10.g1ac7422e39 >