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.129.124]) by sourceware.org (Postfix) with ESMTPS id D27573858C54 for ; Thu, 14 Apr 2022 19:47:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D27573858C54 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-245-9RDB6gAYOMWRYZg35WPt3A-1; Thu, 14 Apr 2022 15:47:21 -0400 X-MC-Unique: 9RDB6gAYOMWRYZg35WPt3A-1 Received: by mail-qk1-f198.google.com with SMTP id g15-20020a05620a40cf00b0069c61283d9fso3408178qko.20 for ; Thu, 14 Apr 2022 12:47:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Lzw9/xlkzS4YP3C3w/5c6sk12xleiPonGbRULt/sF6E=; b=yBCDhPmKmaVvfb1w5zF27g7Abr7VSgUbpVtwbu43cxxke8rJadBhPt7sQjxvjramvx SglgVu1Bwvi0piTzj8r4rCFqhGO2zuxar1VmvUxzu5oMPtsS3xI1ZZvAFdYKEIMpitSb PAsBw69ZqF6Stj87Xb2X7jbmPvZ4gqlLyLX8jCynYpYUfhL4srQUBp65SLJK/24NrDcC 6WkB3c2Mg4t1F4j9GnbB37L8aAai+OcOY214kE5ChQgOE+PEgXTc+IuHY4AoFyeqz/py 5t0LWr5svMQDmY/2oQjFBjoF4jN4uMkZd9O+TdRop6+gP059sy9BMbwucl2SjcOIdNaA EfuA== X-Gm-Message-State: AOAM532aPYLIHSLh0jwbj2VxAuDUPXdGPmjV0MQ55dgFyWPPRbzacJOm zdgNK8mXTGVe0UUq1sph6KLCder34nxA05ILzmpBMMswFS8iIlicNAtv+aAUxELaE44/6ZAcYoJ r2NacrTMdsaTgb1w= X-Received: by 2002:ad4:5cc3:0:b0:441:1959:cb51 with SMTP id iu3-20020ad45cc3000000b004411959cb51mr5003222qvb.112.1649965640875; Thu, 14 Apr 2022 12:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykPN6/tKNKdVABqRWJAxpA7IqTz400UZwB+eoknTUFSXZ5s09Mv6yuACmWmX6yfGCojVf5Jw== X-Received: by 2002:ad4:5cc3:0:b0:441:1959:cb51 with SMTP id iu3-20020ad45cc3000000b004411959cb51mr5003207qvb.112.1649965640574; Thu, 14 Apr 2022 12:47:20 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id n7-20020ac85a07000000b002f1421dac8csm1647698qta.80.2022.04.14.12.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 12:47:19 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Stop defining _GLIBCXX_ASSERTIONS in floating_to_chars.cc Date: Thu, 14 Apr 2022 15:47:16 -0400 Message-Id: <20220414194716.334032-1-ppalka@redhat.com> X-Mailer: git-send-email 2.36.0.rc2.10.g1ac7422e39 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.6 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_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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 19:47:25 -0000 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? 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