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 4EB4E3858C5F for ; Wed, 13 Sep 2023 22:52:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EB4E3858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694645535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=54wlTTE59NOF2rTIZGmJXPKWMcaFndsOam+QdZPcCDg=; b=INUjw12t/Jl8NFpCCoL7EAHqZYchqxL6DpHQErKbC+8pzBfAXWMClwfQZiZOQBD3Fx3Lh9 MvoxHSAfSi9YZ+5Ul/XwZX3Jwfzpg6VAJnfMeJyFfYKXwrAMzxamb0j43xb8tkRkO+GLw5 U7TPCwB8AsvryhnwprBGWbv0gfgb+aU= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-OHwJlsmDOAmlLXnF_lwCRA-1; Wed, 13 Sep 2023 18:52:12 -0400 X-MC-Unique: OHwJlsmDOAmlLXnF_lwCRA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-41362ffd32aso3121001cf.3 for ; Wed, 13 Sep 2023 15:52:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694645531; x=1695250331; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=54wlTTE59NOF2rTIZGmJXPKWMcaFndsOam+QdZPcCDg=; b=Y6bSBg9PrLokcLwwwT7/CmZmJFUxZpqQqjos65F8A3yJsjQaVR/IN9smT1Y1W5iKsH 7Vv9rERypyfibM3KEuz12rrnUuro//Jz1KRktrb/agvNCQe2TI3Izg2h1OPPmz90Nsq3 0xEGxtem6yYe9C7pctQEBHIqTDTx7bCMEboE3T73Nhmc66KOzaYr4bSOPmnSgYGCEFv1 U9a2r0bW1whOGlr4lP9QVbZ18c/rootYQksOltPe38my9GBmbSQLBuRCo2o7BhF+pe5S FeMHTra5wGbhcGGUi/TIZKokQ/2+cOwuYDsvRCe5j6S/+hoKUkuob8+a+wY1Ngs/hDLT LxZw== X-Gm-Message-State: AOJu0YzZDAxyIRLeNhJgx1HiaGGWAFs23gelcIOqa5D5H7WOMH3qPr3o MCwuLzGr4z8bAbuBU29TsiC3m8WRnUwvNFeRmHI/DMROUUzp+P1zON9ZjJPJplWhFP7TH/1kVFG 9T8Thm0L+xhvWz+HmsASY3kM= X-Received: by 2002:ac8:7dc8:0:b0:410:60a4:ffc7 with SMTP id c8-20020ac87dc8000000b0041060a4ffc7mr4131494qte.10.1694645531046; Wed, 13 Sep 2023 15:52:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/ujL2x3reQpzGzNO+rv1Rqim3sq6uWdFveUKgixXPjDa0tsikn8SxffW4v6cbI5Zb2kpGvQ== X-Received: by 2002:ac8:7dc8:0:b0:410:60a4:ffc7 with SMTP id c8-20020ac87dc8000000b0041060a4ffc7mr4131470qte.10.1694645530752; Wed, 13 Sep 2023 15:52:10 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id j6-20020ac84c86000000b0040ff1b4b400sm85151qtv.73.2023.09.13.15.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:52:10 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Reduce integer std::to/from_chars symbol sizes Date: Wed, 13 Sep 2023 18:52:06 -0400 Message-ID: <20230913225206.4188935-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.158.g94e83dcf5b 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=-13.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- For std::to_chars: The constrained alias __integer_to_chars_result_type seems unnecessary ever since r10-3080-g28f0075742ed58 got rid of the only public overload which used it. Now only non-public overloads are constrained by it (through their return type) and these non-public overloads aren't used in a SFINAE context, so the constraints have no observable effect. So this patch gets rid of this alias, which greatly reduces the symbol sizes of the affected functions (since the expanded alias is quite large). For std::from_chars: We can't get rid of the corresponding alias because it's constrains the public integer std::from_chars overload. But we can avoid having the constraint bloat the mangled name by instead encoding it as a defaulted template parameter. We use the non-type parameter form enable_if_t<..., int> = 0 instead of the type parameter form typename = enable_if_t<...> because the type form can be circumvented by providing an explicit template argument to type parameter, e.g. 'std::from_chars(...)', so the non-type form seems like the more robust choice. In passing, use __is_standard_integer in the constraint. libstdc++-v3/ChangeLog: * include/std/charconv (__detail::__integer_to_chars_result_type): Remove. (__detail::__to_chars_16): Use to_chars_result as return type. (__detail::__to_chars_10): Likewise. (__detail::__to_chars_8): Likewise. (__detail::__to_chars_2): Likewise. (__detail::__to_chars_i): Likewise. (__detail::__integer_from_chars_result_type): Pull out enable_if_t condition into and replace with ... (__detail::__integer_from_chars_enabled): ... this. Use __is_standard_integer instead of __is_signed_integer and __is_unsigned_integer. (from_chars): Encode constraint as a defaulted non-type template parameter instead of within the return type. --- libstdc++-v3/include/std/charconv | 33 ++++++++++--------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 01711d38576..ec25ae139ba 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -79,17 +79,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION namespace __detail { - template - using __integer_to_chars_result_type - = enable_if_t<__or_<__is_signed_integer<_Tp>, - __is_unsigned_integer<_Tp>, -#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ - is_same<_Tp, signed __int128>, - is_same<_Tp, unsigned __int128>, -#endif - is_same>>::value, - to_chars_result>; - // Pick an unsigned type of suitable size. This is used to reduce the // number of specializations of __to_chars_len, __to_chars etc. that // get instantiated. For example, to_chars and to_chars @@ -162,7 +151,7 @@ namespace __detail } template - constexpr __integer_to_chars_result_type<_Tp> + constexpr to_chars_result __to_chars_16(char* __first, char* __last, _Tp __val) noexcept { static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); @@ -208,7 +197,7 @@ namespace __detail } template - constexpr __integer_to_chars_result_type<_Tp> + constexpr to_chars_result __to_chars_10(char* __first, char* __last, _Tp __val) noexcept { static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); @@ -231,7 +220,7 @@ namespace __detail } template - constexpr __integer_to_chars_result_type<_Tp> + constexpr to_chars_result __to_chars_8(char* __first, char* __last, _Tp __val) noexcept { static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); @@ -284,7 +273,7 @@ namespace __detail } template - constexpr __integer_to_chars_result_type<_Tp> + constexpr to_chars_result __to_chars_2(char* __first, char* __last, _Tp __val) noexcept { static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); @@ -320,7 +309,7 @@ namespace __detail } // namespace __detail template - constexpr __detail::__integer_to_chars_result_type<_Tp> + constexpr to_chars_result __to_chars_i(char* __first, char* __last, _Tp __value, int __base = 10) { __glibcxx_assert(2 <= __base && __base <= 36); @@ -548,17 +537,15 @@ namespace __detail } template - using __integer_from_chars_result_type - = enable_if_t<__or_<__is_signed_integer<_Tp>, - __is_unsigned_integer<_Tp>, - is_same>>::value, - from_chars_result>; + constexpr bool __integer_from_chars_enabled + = __or_<__is_standard_integer<_Tp>, is_same>>::value; } // namespace __detail /// std::from_chars for integral types. - template - _GLIBCXX23_CONSTEXPR __detail::__integer_from_chars_result_type<_Tp> + template, int> = 0> + _GLIBCXX23_CONSTEXPR from_chars_result from_chars(const char* __first, const char* __last, _Tp& __value, int __base = 10) { -- 2.42.0.158.g94e83dcf5b