From patchwork Thu Jul 27 17:10:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 12711 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1243423vqo; Thu, 27 Jul 2023 10:11:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlEd96RkYdoOG9Wq/a5rWA45OO+bGPmeaDyJoax784UOYbvHq8moDcTkrQHr5IOGgT6jE4qE X-Received: by 2002:aa7:cd5a:0:b0:522:1dce:ca09 with SMTP id v26-20020aa7cd5a000000b005221dceca09mr2320598edw.29.1690477903609; Thu, 27 Jul 2023 10:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690477903; cv=none; d=google.com; s=arc-20160816; b=LK3UC7wNowLUcs1doualk5DAOOKHsEOKQw8rhfSsx6AUM1ya7frI3k/DtY1+30tOPP sM8PM53de+g+NswEt5CqeVoWpj4boe/4pFyXo8sEgr3Ti9Rt0YCbe0jXuPOEKxProxDE O1FzN0mYJfUIrasTt0HTbwNOATizLTQMMM7ZmVf+LvTbrW/EFW9ZnJnyXuG1l2L1rlF7 d5BmxUW2coB3xqM6C5hVqUPTQQ/xTjc3m+my+gykqbm6r02qUyzGTjfzH+SMzir/ovuD uM589mgPq1jXPX2cmePCiSj9Hz76aMFv6JBRBmS24JAnAaU12FQyELd9EBrp7v86RqEV ym4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=x0ycHaQHFmV15OFxfsETqh7IwO5WWXzYiWqXiNRBIQg=; fh=KY+sxu+GDO8REWaCSOfGlt2KdoG6IIVk0/n1blXeCRk=; b=EQIHlh1Tq2xO1sl2iDQYzNyLD9rx1AxG3gLspdGaJ0J2Atbyhx/y5yeNHlj2xqiBdz duplOU9SwFhCwWuPDX/LyMjJRk4meV3B11VbduVLnpzktcptXAc+yl/fbPvSzhl6nyAF h6W2OUsKueuXD4NmjxxSFwI/jYyxtPs+d80OTDFU5/S4+xrf/3ylX5AXnGyAnKxbhI3g uV75Ety3mxaWWnfcfUvJrU1+i4hkylZypAb1hnK67g8mfulJXUOu+KkY0UaWbG5ALspN 3yLshsLIlLkmZVKkI1xBukLVystW3gKxHjvwLcEjKr88h36xekC3D98fsVN6lt7HAfxX y4tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rKzkPQ4V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c20-20020aa7c754000000b0052257d64ad2si1189311eds.269.2023.07.27.10.11.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:11:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rKzkPQ4V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0083D385AFB2 for ; Thu, 27 Jul 2023 17:11:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0083D385AFB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690477898; bh=x0ycHaQHFmV15OFxfsETqh7IwO5WWXzYiWqXiNRBIQg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rKzkPQ4VlSYrFepogVXOABOuF2TQBbmTOH4JyvjLbGhEbMtzR5yBRmFL56X7BExuT pVCk95AyxZJv7UTB+gSq9O4KrrF8PTMr44F+qftmHqbtlwZJAdbeSb/uVkwKBI2kcJ ESwYJpXe1sXNN+b11ITwHNN6zdCOd+8h3ZCC8Ndw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 96B5E3858D39 for ; Thu, 27 Jul 2023 17:10:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96B5E3858D39 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-399-nN4G6kQAOF66dLcrj9xZcg-1; Thu, 27 Jul 2023 13:10:47 -0400 X-MC-Unique: nN4G6kQAOF66dLcrj9xZcg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A8F17185A78F; Thu, 27 Jul 2023 17:10:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A865492B02; Thu, 27 Jul 2023 17:10:46 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 36RHAhiw2823026 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 19:10:43 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 36RHAgPq2823025; Thu, 27 Jul 2023 19:10:42 +0200 Date: Thu, 27 Jul 2023 19:10:41 +0200 To: gcc-patches@gcc.gnu.org Cc: Richard Biener , "Joseph S. Myers" , Uros Bizjak , hjl.tools@gmail.com Subject: [PATCH 0/5] GCC _BitInt support [PR102989] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772594558355018002 X-GMAIL-MSGID: 1772594558355018002 [PATCH 0/5] GCC _BitInt support [PR102989] The following patch series introduces support for C23 bit-precise integer types. In short, they are similar to other integral types in many ways, just aren't subject for integral promotions if smaller than int and they can have even much wider precisions than ordinary integer types. It is enabled only on targets which have agreed on processor specific ABI how to lay those out or pass as function arguments/return values, which currently is just x86-64 I believe, would be nice if target maintainers helped to get agreement on psABI changes and GCC 14 could enable it on far more architectures than just one. C23 says that defines BITINT_MAXWIDTH macro and that is the largest supported precision of the _BitInt types, smallest is precision of unsigned long long (but due to lack of psABI agreement we'll violate that on architectures which don't have the support done yet). The following series uses for the time just WIDE_INT_MAX_PRECISION as that BITINT_MAXWIDTH, with the intent to increase it incrementally later on. WIDE_INT_MAX_PRECISION is 575 bits on x86_64, but will be even smaller on lots of architectures. This is the largest precision we can support without changes of wide_int/widest_int representation (to make those non-POD and allow use of some allocated buffer rather than the included fixed size one). Once that would be overcome, there is another internal enforced limit, INTEGER_CST in current layout allows at most 255 64-bit limbs, which is 16320 bits as another cap. And if that is overcome, then we have limitation of TYPE_PRECISION being 16-bit, so 65535 as maximum precision. Perhaps we could make TYPE_PRECISION dependent on BITINT_TYPE vs. others and use 32-bit precision in that case later. Latest Clang/LLVM I think supports on paper up to 8388608 bits, but is hardly usable even with much shorter precisions. Besides this hopefully temporary cap on supported precision and support only on targets which buy into it, the support has the following limitations: - _BitInt(N) bit-fields aren't supported yet (the patch rejects them); I'd like to enable those incrementally, but don't really see details on how such bit-fields should be laid-out in memory nor passed inside of function arguments; LLVM implements something, but it is a question if that is what the various ABIs want - conversions between large/huge (see later) _BitInt and _Decimal{32,64,128} aren't support and emit a sorry; I'm not familiar enough with DFP stuff to implement that - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs mention how those should be passed/returned; in a limited way they are supported internally because the internal functions into which __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a hack to return 2 values without using references/pointers - vectors of _BitInt(N) aren't supported, both because psABIs don't specify how that works and because I'm not really sure it would be useful given lack of hw support for anything but bit-precise integers with the same bit precision as standard integer types Because the bit-precise types have different behavior both in the C FE (e.g. the lack of promotion) and do or can have different behavior in type layout and function argument passing/returning values, the patch introduces a new integral type, BITINT_TYPE, so various spots which explicitly check for INTEGER_TYPE and not say INTEGRAL_TYPE_P macro need to be adjusted. Also the assumption that all integral types have scalar integer type mode is no longer true, larger BITINT_TYPEs have BLKmode type. The patch makes 4 different categories of _BitInt depending on the target hook decisions and their precision. The x86-64 psABI says that _BitInt which fit into signed/unsigned char, short, int, long and long long are laid out and passed as those types (with padding bits undefined if they don't have mode precision). Such smallest precision bit-precise integer types are categorized as small, the target hook gives for specific precision a scalar integral mode where a single such mode contains all the bits. Such small _BitInt types are generally kept in the IL until expansion into RTL, with minor tweaks during expansion to avoid relying on the padding bit values. All larger precision _BitInt types are supposed to be handled as structure containing an array of limbs or so, where a limb has some integral mode (for libgcc purposes best if it has word-size) and the limbs have either little or big endian ordering in the array. The padding bits in the most significant limb if any are either undefined or should be always sign/zero extended (but support for this isn't in yet, we don't know if any psABI will require it). As mentioned in some psABI proposals, while currently there is just one limb mode, if the limb ordering would follow normal target endianity, there is always a possibility to have two limb modes, one used for ABI purposes (in alignment/size decisions) and another one used during the actual lowering or libgcc helpers. The second _BitInt category is called medium in the series, those are _BitInt precisions which need more than one limb, but the precision is still smaller than TImode precision (or DImode on targets which don't support __int128). Most arithmetics on such types can be lowered simply to casts to the larger/equal precision {,unsigned} {long long,__int128} type and performing the arith on normal integers and then casted back. Larger _BitInt precision typically will have BLKmode and will be lowered in a new bitintlower* pass right after complex lowering (for -O1+ it is shortly after IPA) into series of operations on individual limbs. The series talks about large and huge _BitInts, large ones are up to one bit smaller than 4 limbs and are lowered in most places in straight line code iterating of the limbs and huge ones are those which use some loop to handle most of the limbs and only handle up to 2 limbs before or after the loop. Most operations, like bitwise operations, addition, subtraction, left shift by constant smaller than limb precision, some casts, ==/!= comparisons, loads/stores are handled in a loop with 2 limbs per iteration followed by 0, 1 or 2 limbs handled after, are called in the series mergeable and the loop handles perhaps many different operations with single use in the same bb. >/>=/