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 96B5E3858D39 for ; Thu, 27 Jul 2023 17:10:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96B5E3858D39 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=1690477848; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=x0ycHaQHFmV15OFxfsETqh7IwO5WWXzYiWqXiNRBIQg=; b=EPEMplGbQLTYVof39j6IrAuDcvXWQCEWnrnzDyabucGC7MXkyec4M3Uf9F2viYeupleu8A NhjGNxex1uHAOwz5CJP8IuYx2208Xx8IGnaiEndx17HUeTe46CkIMVtKsxNJMTI4OjS3XT j4GDF7/DWDctbNwIexmkgYpoc41/yiU= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: [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. >/>=/