From patchwork Thu Jul 27 17:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 127071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1245172vqo; Thu, 27 Jul 2023 10:14:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHi1CZHipDGYg3Y7RMe+sc3VXMRBRX5IIk6ylAyBIy/9KqclKrSuWTbVlgSV4Ye5rUaau/r X-Received: by 2002:a17:907:7887:b0:99b:4867:5e1a with SMTP id ku7-20020a170907788700b0099b48675e1amr2286815ejc.41.1690478082754; Thu, 27 Jul 2023 10:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690478082; cv=none; d=google.com; s=arc-20160816; b=qqlpc/mOADwg+nXRTRHwURWUIhhCezGW1DoX1dqRO4bkMJ2OEM4ZffiF/2C1eLffzs wR4i4RiNlkKNMUkoXYt2KG07STvL9A+m+XP/+l5ylyBJL/EXAT4cmZyguV4xrcVOI0rO ajMbaGvhm09uNO41pzYeJU6DqbCaTNFXPvSI6laK6RM5UKfdSK178Vfr7obx97HJwhbs A6BJLtXvjFx1jVfwV0ip0kjU53rYP2eGkjKYFhoHPf6V774CmNlgjPXDTJQ/XyGDul7/ BJ3VcuBUqE9tVvlPSQSq8gGtpjsoOMQKkZrvY2K/GYwpLDNZXHR6W58GZ4lugNgd9uCQ woFQ== 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=f62QpLcG0VT0NN2hdkPrReSx1IRX44dDKnRqZaD7Ulk=; fh=KY+sxu+GDO8REWaCSOfGlt2KdoG6IIVk0/n1blXeCRk=; b=MGQd0IEStsO2+7m1ux0llsUihzS8Va8gNy5MAs8E45wCsHHnZuiHnSzMsqKqWwBEJI YKG67EpGfLAF63JPe5WeknUPtJLF8N3UW+yZkMIBUjvAIgWnTxVfd1tk5KI3CW3IJcM8 WbTeihuwCLQ/mLq6mhr8ePs2LJXJ8c9hjxu306WBBo2Jf0cM/d7bK6lhiJNNjeCQJc5g Az1Jb35X31wh2oo77iidhmb14hlBKrkqjUiGxrw65ghwuRx72JP53yamrDE7XVCXN75u 5N88MnGJGdfvsF23WpK1gbQyfaMV44jz3Zdy3241HcRgpSqsPAw6Vv8tfjVreLvFQpWf SP0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MIW6oTEY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id pg15-20020a170907204f00b00992437c5880si1233783ejb.327.2023.07.27.10.14.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:14:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MIW6oTEY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 90041385AFA4 for ; Thu, 27 Jul 2023 17:14:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90041385AFA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690478063; bh=f62QpLcG0VT0NN2hdkPrReSx1IRX44dDKnRqZaD7Ulk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=MIW6oTEYjnKRNSMpmSzFS3yL9RuR0CYvtwfSVEPtUIZueNYWLa5RUGkMVqdTGzaI9 EyZbz+khuCOMP9cu97dfTbLU8dleIeoIA9OYH6REa3IScjGw+I9fsXMAJpmltariej 83egYJociXHN60D4XoMdboz7loraHdgR3z28OrtY= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 7CE9A3858D39 for ; Thu, 27 Jul 2023 17:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CE9A3858D39 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-f7ja1MSTO5qzcl229fCF7Q-1; Thu, 27 Jul 2023 13:12:06 -0400 X-MC-Unique: f7ja1MSTO5qzcl229fCF7Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A46A1C07559; Thu, 27 Jul 2023 17:12:06 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6CED9C57965; Thu, 27 Jul 2023 17:12:05 +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 36RHC2CQ2823040 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 19:12:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 36RHC1n12823039; Thu, 27 Jul 2023 19:12:01 +0200 Date: Thu, 27 Jul 2023 19:12:01 +0200 To: gcc-patches@gcc.gnu.org Cc: Richard Biener , "Joseph S. Myers" , Uros Bizjak , hjl.tools@gmail.com Subject: [PATCH 1/5] Middle-end _BitInt support [PR102989] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.9 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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: 1772594745899115673 X-GMAIL-MSGID: 1772594745899115673 Hi! The following patch introduces the middle-end part of the _BitInt support, a new BITINT_TYPE, handling it where needed and most importantly the new bitintlower lowering pass which lowers most operations on medium _BitInt into operations on corresponding integer types, large _BitInt into straight line code operating on 2 or more limbs and finally huge _BitInt into a loop plus optional straight line code. As the only supported architecture is little-endian, the lowering only supports little-endian for now, because it would be impossible to test it all for big-endian. Rest is written with any endian support in mind, but of course only little-endian has been actually tested. I hope it is ok to add big-endian support to the lowering pass incrementally later when first big-endian target shows with the backend support. There are 2 possibilities of adding such support, one would be minimal one, just tweak limb_access function and perhaps one or two other spots and transform there the indexes from little endian (index 0 is least significant) to big endian for just the memory access. Advantage is I think maintainance costs, disadvantage is that the loops will still iterate from 0 to some number of limbs and we'd rely on IVOPTs or something similar changing it later if needed. Or we could make those indexes endian related everywhere, though I'm afraid that would be several hundreds of changes. For switches indexed by large/huge _BitInt the patch invokes what the switch lowering pass does (but only on those specific switches, not all of them); the switch lowering breaks the switches into clusters and none of the clusters can have a range which doesn't fit into 64-bit UWHI, everything else will be turned into a tree of comparisons. For clusters normally emitted as smaller switches, because we already have a guarantee that the low .. high range is at most 64 bits, the patch forces subtraction of the low and turns it into a 64-bit switch. This is done before the actual pass starts. Similarly, we cancel lowering of certain constructs like ABS_EXPR, ABSU_EXPR, MIN_EXPR, MAX_EXPR and COND_EXPR and turn those back to simpler comparisons etc., so that fewer operations need to be lowered later. There is some -fsanitize=undefined support for _BitInt, but some of the diagnostics is limited by lack of proper support in the library. I've filed https://github.com/llvm/llvm-project/issues/64100 to request proper support, for now some of the diagnostics might have less or more confusing or inaccurate wording but UB should still be diagnosed when it happens. 2023-07-27 Jakub Jelinek PR c/102989 gcc/ * tree.def (BITINT_TYPE): New type. * tree.h (TREE_CHECK6, TREE_NOT_CHECK6): Define. (NUMERICAL_TYPE_CHECK, INTEGRAL_TYPE_P): Include BITINT_TYPE. (BITINT_TYPE_P): Define. (tree_check6, tree_not_check6): New inline functions. (any_integral_type_check): Include BITINT_TYPE. (build_bitint_type): Declare. * tree.cc (tree_code_size, wide_int_to_tree_1, cache_integer_cst, build_zero_cst, type_hash_canon_hash, type_cache_hasher::equal, type_hash_canon): Handle BITINT_TYPE. (bitint_type_cache): New variable. (build_bitint_type): New function. (signed_or_unsigned_type_for, verify_type_variant, verify_type): Handle BITINT_TYPE. (tree_cc_finalize): Free bitint_type_cache. * builtins.cc (type_to_class): Handle BITINT_TYPE. (fold_builtin_unordered_cmp): Handle BITINT_TYPE like INTEGER_TYPE. * calls.cc (store_one_arg): Handle large/huge BITINT_TYPE INTEGER_CSTs as call arguments. * cfgexpand.cc (expand_asm_stmt): Handle large/huge BITINT_TYPE INTEGER_CSTs as inline asm inputs. (expand_debug_expr): Punt on BLKmode BITINT_TYPE INTEGER_CSTs. * config/i386/i386.cc (classify_argument): Handle BITINT_TYPE. (ix86_bitint_type_info): New function. (TARGET_C_BITINT_TYPE_INFO): Redefine. * convert.cc (convert_to_pointer_1, convert_to_real_1, convert_to_complex_1): Handle BITINT_TYPE like INTEGER_TYPE. (convert_to_integer_1): Likewise. For BITINT_TYPE don't check GET_MODE_PRECISION (TYPE_MODE (type)). * doc/tm.texi.in (TARGET_C_BITINT_TYPE_INFO): New. * doc/tm.texi: Regenerated. * dwarf2out.cc (base_type_die, is_base_type, modified_type_die, gen_type_die_with_usage): Handle BITINT_TYPE. (rtl_for_decl_init): Punt on BLKmode BITINT_TYPE INTEGER_CSTs or handle those which fit into shwi. * expr.cc (expand_expr_real_1): Reduce to bitfield precision reads from BITINT_TYPE vars, parameters or memory locations. * fold-const.cc (fold_convert_loc, make_range_step): Handle BITINT_TYPE. (extract_muldiv_1): For BITINT_TYPE use TYPE_PRECISION rather than GET_MODE_SIZE (SCALAR_INT_TYPE_MODE). (native_encode_int, native_interpret_int, native_interpret_expr): Handle BITINT_TYPE. * gimple-expr.cc (useless_type_conversion_p): Make BITINT_TYPE to some other integral type or vice versa conversions non-useless. * gimple-fold.cc (gimple_fold_builtin_memset): Punt for BITINT_TYPE. * gimple-lower-bitint.cc: New file. * gimple-lower-bitint.h: New file. * internal-fn.cc (expand_ubsan_result_store): Add LHS, MODE and DO_ERROR arguments. For non-mode precision BITINT_TYPE results check if all padding bits up to mode precision are zeros or sign bit copies and if not, jump to DO_ERROR. (expand_addsub_overflow, expand_neg_overflow): Adjust expand_ubsan_result_store callers. (expand_mul_overflow): Likewise. For unsigned non-mode precision operands force pos_neg? to 1. (expand_MULBITINT, expand_DIVMODBITINT, expand_FLOATTOBITINT, expand_BITINTTOFLOAT): New functions. * internal-fn.def (MULBITINT, DIVMODBITINT, FLOATTOBITINT, BITINTTOFLOAT): New internal functions. * internal-fn.h (expand_MULBITINT, expand_DIVMODBITINT, expand_FLOATTOBITINT, expand_BITINTTOFLOAT): Declare. * lto-streamer-in.cc (lto_input_tree_1): Assert TYPE_PRECISION is up to WIDE_INT_MAX_PRECISION rather than MAX_BITSIZE_MODE_ANY_INT. * Makefile.in (OBJS): Add gimple-lower-bitint.o. * match.pd (non-equality compare simplifications from fold_binary): Punt if TYPE_MODE (arg1_type) is BLKmode. * passes.def: Add pass_lower_bitint after pass_lower_complex and pass_lower_bitint_O0 after pass_lower_complex_O0. * pretty-print.h (pp_wide_int): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * stor-layout.cc (layout_type): Handle BITINT_TYPE. Handle COMPLEX_TYPE with BLKmode element type and assert it is BITINT_TYPE. * target.def (bitint_type_info): New C target hook. * target.h (struct bitint_info): New type. * targhooks.cc (default_bitint_type_info): New function. * targhooks.h (default_bitint_type_info): Declare. * tree-pass.h (PROP_gimple_lbitint): Define. (make_pass_lower_bitint_O0, make_pass_lower_bitint): Declare. * tree-pretty-print.cc (dump_generic_node): Handle BITINT_TYPE. Handle printing large wide_ints which would buffer overflow digit_buffer. * tree-ssa-coalesce.cc: Include gimple-lower-bitint.h. (build_ssa_conflict_graph): Call build_bitint_stmt_ssa_conflicts if map->bitint. (create_coalesce_list_for_region): For map->bitint ignore SSA_NAMEs not in that bitmap, and allow res without default def. (compute_optimized_partition_bases): In map->bitint mode try hard to coalesce any SSA_NAMEs with the same size. (coalesce_bitint): New function. (coalesce_ssa_name): In map->bitint mode, or map->bitmap into used_in_copies and call coalesce_bitint. * tree-ssa-live.cc (init_var_map): Add BITINT argument, initialize map->bitint and set map->outofssa_p to false if it is non-NULL. * tree-ssa-live.h (struct _var_map): Add bitint member. (init_var_map): Adjust declaration. (region_contains_p): Handle map->bitint like map->outofssa_p. * tree-ssa-sccvn.cc: Include target.h. (eliminate_dom_walker::eliminate_stmt): Punt for large/huge BITINT_TYPE. * tree-switch-conversion.cc (jump_table_cluster::emit): For more than 64-bit BITINT_TYPE subtract low bound from expression and cast to 64-bit integer type both the controlling expression and case labels. * typeclass.h (enum type_class): Add bitint_type_class enumerator. * ubsan.cc: Include target.h and langhooks.h. (ubsan_encode_value): Pass BITINT_TYPE values which fit into pointer size converted to pointer sized integer, pass BITINT_TYPE values which fit into TImode (if supported) or DImode as those integer types or otherwise for now punt (pass 0). (ubsan_type_descriptor): Handle BITINT_TYPE. For pstyle of UBSAN_PRINT_FORCE_INT use TK_Integer (0x0000) mode with a TImode/DImode precision rather than TK_Unknown used otherwise for large/huge BITINT_TYPEs. (instrument_si_overflow): Instrument BITINT_TYPE operations even when they don't have mode precision. * ubsan.h (enum ubsan_print_style): New enumerator. * varasm.cc (output_constant): Handle BITINT_TYPE INTEGER_CSTs. * vr-values.cc (check_for_binary_op_overflow): Use widest2_int rather than widest_int. (simplify_using_ranges::simplify_internal_call_using_ranges): Use unsigned_type_for rather than build_nonstandard_integer_type. Jakub --- gcc/tree.def.jj 2023-07-17 09:07:42.154282849 +0200 +++ gcc/tree.def 2023-07-27 15:03:24.223234605 +0200 @@ -113,7 +113,7 @@ DEFTREECODE (BLOCK, "block", tcc_excepti /* The ordering of the following codes is optimized for the checking macros in tree.h. Changing the order will degrade the speed of the compiler. OFFSET_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, INTEGER_TYPE, - REAL_TYPE, POINTER_TYPE. */ + BITINT_TYPE, REAL_TYPE, POINTER_TYPE. */ /* An offset is a pointer relative to an object. The TREE_TYPE field is the type of the object at the offset. @@ -144,6 +144,9 @@ DEFTREECODE (BOOLEAN_TYPE, "boolean_type and TYPE_PRECISION (number of bits used by this type). */ DEFTREECODE (INTEGER_TYPE, "integer_type", tcc_type, 0) +/* Bit-precise integer type. */ +DEFTREECODE (BITINT_TYPE, "bitint_type", tcc_type, 0) + /* C's float and double. Different floating types are distinguished by machine mode and by the TYPE_SIZE and the TYPE_PRECISION. */ DEFTREECODE (REAL_TYPE, "real_type", tcc_type, 0) --- gcc/tree.h.jj 2023-07-17 09:07:42.155282836 +0200 +++ gcc/tree.h 2023-07-27 15:03:24.256234145 +0200 @@ -363,6 +363,14 @@ code_helper::is_builtin_fn () const (tree_not_check5 ((T), __FILE__, __LINE__, __FUNCTION__, \ (CODE1), (CODE2), (CODE3), (CODE4), (CODE5))) +#define TREE_CHECK6(T, CODE1, CODE2, CODE3, CODE4, CODE5, CODE6) \ +(tree_check6 ((T), __FILE__, __LINE__, __FUNCTION__, \ + (CODE1), (CODE2), (CODE3), (CODE4), (CODE5), (CODE6))) + +#define TREE_NOT_CHECK6(T, CODE1, CODE2, CODE3, CODE4, CODE5, CODE6) \ +(tree_not_check6 ((T), __FILE__, __LINE__, __FUNCTION__, \ + (CODE1), (CODE2), (CODE3), (CODE4), (CODE5), (CODE6))) + #define CONTAINS_STRUCT_CHECK(T, STRUCT) \ (contains_struct_check ((T), (STRUCT), __FILE__, __LINE__, __FUNCTION__)) @@ -485,6 +493,8 @@ extern void omp_clause_range_check_faile #define TREE_NOT_CHECK4(T, CODE1, CODE2, CODE3, CODE4) (T) #define TREE_CHECK5(T, CODE1, CODE2, CODE3, CODE4, CODE5) (T) #define TREE_NOT_CHECK5(T, CODE1, CODE2, CODE3, CODE4, CODE5) (T) +#define TREE_CHECK6(T, CODE1, CODE2, CODE3, CODE4, CODE5, CODE6) (T) +#define TREE_NOT_CHECK6(T, CODE1, CODE2, CODE3, CODE4, CODE5, CODE6) (T) #define TREE_CLASS_CHECK(T, CODE) (T) #define TREE_RANGE_CHECK(T, CODE1, CODE2) (T) #define EXPR_CHECK(T) (T) @@ -528,8 +538,8 @@ extern void omp_clause_range_check_faile TREE_CHECK2 (T, ARRAY_TYPE, INTEGER_TYPE) #define NUMERICAL_TYPE_CHECK(T) \ - TREE_CHECK5 (T, INTEGER_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, REAL_TYPE, \ - FIXED_POINT_TYPE) + TREE_CHECK6 (T, INTEGER_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, REAL_TYPE, \ + FIXED_POINT_TYPE, BITINT_TYPE) /* Here is how primitive or already-canonicalized types' hash codes are made. */ @@ -603,7 +613,8 @@ extern void omp_clause_range_check_faile #define INTEGRAL_TYPE_P(TYPE) \ (TREE_CODE (TYPE) == ENUMERAL_TYPE \ || TREE_CODE (TYPE) == BOOLEAN_TYPE \ - || TREE_CODE (TYPE) == INTEGER_TYPE) + || TREE_CODE (TYPE) == INTEGER_TYPE \ + || TREE_CODE (TYPE) == BITINT_TYPE) /* Nonzero if TYPE represents an integral type, including complex and vector integer types. */ @@ -614,6 +625,10 @@ extern void omp_clause_range_check_faile || VECTOR_TYPE_P (TYPE)) \ && INTEGRAL_TYPE_P (TREE_TYPE (TYPE)))) +/* Nonzero if TYPE is bit-precise integer type. */ + +#define BITINT_TYPE_P(TYPE) (TREE_CODE (TYPE) == BITINT_TYPE) + /* Nonzero if TYPE represents a non-saturating fixed-point type. */ #define NON_SAT_FIXED_POINT_TYPE_P(TYPE) \ @@ -3684,6 +3699,38 @@ tree_not_check5 (tree __t, const char *_ } inline tree +tree_check6 (tree __t, const char *__f, int __l, const char *__g, + enum tree_code __c1, enum tree_code __c2, enum tree_code __c3, + enum tree_code __c4, enum tree_code __c5, enum tree_code __c6) +{ + if (TREE_CODE (__t) != __c1 + && TREE_CODE (__t) != __c2 + && TREE_CODE (__t) != __c3 + && TREE_CODE (__t) != __c4 + && TREE_CODE (__t) != __c5 + && TREE_CODE (__t) != __c6) + tree_check_failed (__t, __f, __l, __g, __c1, __c2, __c3, __c4, __c5, __c6, + 0); + return __t; +} + +inline tree +tree_not_check6 (tree __t, const char *__f, int __l, const char *__g, + enum tree_code __c1, enum tree_code __c2, enum tree_code __c3, + enum tree_code __c4, enum tree_code __c5, enum tree_code __c6) +{ + if (TREE_CODE (__t) == __c1 + || TREE_CODE (__t) == __c2 + || TREE_CODE (__t) == __c3 + || TREE_CODE (__t) == __c4 + || TREE_CODE (__t) == __c5 + || TREE_CODE (__t) == __c6) + tree_not_check_failed (__t, __f, __l, __g, __c1, __c2, __c3, __c4, __c5, + __c6, 0); + return __t; +} + +inline tree contains_struct_check (tree __t, const enum tree_node_structure_enum __s, const char *__f, int __l, const char *__g) { @@ -3821,7 +3868,7 @@ any_integral_type_check (tree __t, const { if (!ANY_INTEGRAL_TYPE_P (__t)) tree_check_failed (__t, __f, __l, __g, BOOLEAN_TYPE, ENUMERAL_TYPE, - INTEGER_TYPE, 0); + INTEGER_TYPE, BITINT_TYPE, 0); return __t; } @@ -3940,6 +3987,38 @@ tree_not_check5 (const_tree __t, const c } inline const_tree +tree_check6 (const_tree __t, const char *__f, int __l, const char *__g, + enum tree_code __c1, enum tree_code __c2, enum tree_code __c3, + enum tree_code __c4, enum tree_code __c5, enum tree_code __c6) +{ + if (TREE_CODE (__t) != __c1 + && TREE_CODE (__t) != __c2 + && TREE_CODE (__t) != __c3 + && TREE_CODE (__t) != __c4 + && TREE_CODE (__t) != __c5 + && TREE_CODE (__t) != __c6) + tree_check_failed (__t, __f, __l, __g, __c1, __c2, __c3, __c4, __c5, __c6, + 0); + return __t; +} + +inline const_tree +tree_not_check6 (const_tree __t, const char *__f, int __l, const char *__g, + enum tree_code __c1, enum tree_code __c2, enum tree_code __c3, + enum tree_code __c4, enum tree_code __c5, enum tree_code __c6) +{ + if (TREE_CODE (__t) == __c1 + || TREE_CODE (__t) == __c2 + || TREE_CODE (__t) == __c3 + || TREE_CODE (__t) == __c4 + || TREE_CODE (__t) == __c5 + || TREE_CODE (__t) == __c6) + tree_not_check_failed (__t, __f, __l, __g, __c1, __c2, __c3, __c4, __c5, + __c6, 0); + return __t; +} + +inline const_tree contains_struct_check (const_tree __t, const enum tree_node_structure_enum __s, const char *__f, int __l, const char *__g) { @@ -4047,7 +4126,7 @@ any_integral_type_check (const_tree __t, { if (!ANY_INTEGRAL_TYPE_P (__t)) tree_check_failed (__t, __f, __l, __g, BOOLEAN_TYPE, ENUMERAL_TYPE, - INTEGER_TYPE, 0); + INTEGER_TYPE, BITINT_TYPE, 0); return __t; } @@ -5579,6 +5658,7 @@ extern void build_common_builtin_nodes ( extern void tree_cc_finalize (void); extern tree build_nonstandard_integer_type (unsigned HOST_WIDE_INT, int); extern tree build_nonstandard_boolean_type (unsigned HOST_WIDE_INT); +extern tree build_bitint_type (unsigned HOST_WIDE_INT, int); extern tree build_range_type (tree, tree, tree); extern tree build_nonshared_range_type (tree, tree, tree); extern bool subrange_type_for_debug_p (const_tree, tree *, tree *); --- gcc/tree.cc.jj 2023-07-17 09:07:42.154282849 +0200 +++ gcc/tree.cc 2023-07-27 15:03:24.217234689 +0200 @@ -991,6 +991,7 @@ tree_code_size (enum tree_code code) case VOID_TYPE: case FUNCTION_TYPE: case METHOD_TYPE: + case BITINT_TYPE: case LANG_TYPE: return sizeof (tree_type_non_common); default: gcc_checking_assert (code >= NUM_TREE_CODES); @@ -1732,6 +1733,7 @@ wide_int_to_tree_1 (tree type, const wid case INTEGER_TYPE: case OFFSET_TYPE: + case BITINT_TYPE: if (TYPE_SIGN (type) == UNSIGNED) { /* Cache [0, N). */ @@ -1915,6 +1917,7 @@ cache_integer_cst (tree t, bool might_du case INTEGER_TYPE: case OFFSET_TYPE: + case BITINT_TYPE: if (TYPE_UNSIGNED (type)) { /* Cache 0..N */ @@ -2637,7 +2640,7 @@ build_zero_cst (tree type) { case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: case POINTER_TYPE: case REFERENCE_TYPE: - case OFFSET_TYPE: case NULLPTR_TYPE: + case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE: return build_int_cst (type, 0); case REAL_TYPE: @@ -6053,7 +6056,16 @@ type_hash_canon_hash (tree type) hstate.add_object (TREE_INT_CST_ELT (t, i)); break; } - + + case BITINT_TYPE: + { + unsigned prec = TYPE_PRECISION (type); + unsigned uns = TYPE_UNSIGNED (type); + hstate.add_object (prec); + hstate.add_int (uns); + break; + } + case REAL_TYPE: case FIXED_POINT_TYPE: { @@ -6136,6 +6148,11 @@ type_cache_hasher::equal (type_hash *a, || tree_int_cst_equal (TYPE_MIN_VALUE (a->type), TYPE_MIN_VALUE (b->type)))); + case BITINT_TYPE: + if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type)) + return false; + return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type); + case FIXED_POINT_TYPE: return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type); @@ -6236,7 +6253,7 @@ type_hash_canon (unsigned int hashcode, /* Free also min/max values and the cache for integer types. This can't be done in free_node, as LTO frees those on its own. */ - if (TREE_CODE (type) == INTEGER_TYPE) + if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE) { if (TYPE_MIN_VALUE (type) && TREE_TYPE (TYPE_MIN_VALUE (type)) == type) @@ -7154,6 +7171,44 @@ build_nonstandard_boolean_type (unsigned return type; } +static GTY(()) vec *bitint_type_cache; + +/* Builds a signed or unsigned _BitInt(PRECISION) type. */ +tree +build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp) +{ + tree itype, ret; + + if (unsignedp) + unsignedp = MAX_INT_CACHED_PREC + 1; + + if (bitint_type_cache == NULL) + vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2); + + if (precision <= MAX_INT_CACHED_PREC) + { + itype = (*bitint_type_cache)[precision + unsignedp]; + if (itype) + return itype; + } + + itype = make_node (BITINT_TYPE); + TYPE_PRECISION (itype) = precision; + + if (unsignedp) + fixup_unsigned_type (itype); + else + fixup_signed_type (itype); + + inchash::hash hstate; + inchash::add_expr (TYPE_MAX_VALUE (itype), hstate); + ret = type_hash_canon (hstate.end (), itype); + if (precision <= MAX_INT_CACHED_PREC) + (*bitint_type_cache)[precision + unsignedp] = ret; + + return ret; +} + /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED is true, reuse such a type that has already been constructed. */ @@ -11041,6 +11096,8 @@ signed_or_unsigned_type_for (int unsigne else return NULL_TREE; + if (TREE_CODE (type) == BITINT_TYPE) + return build_bitint_type (bits, unsignedp); return build_nonstandard_integer_type (bits, unsignedp); } @@ -13462,6 +13519,7 @@ verify_type_variant (const_tree t, tree if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t)) || TREE_CODE (t) == INTEGER_TYPE || TREE_CODE (t) == BOOLEAN_TYPE + || TREE_CODE (t) == BITINT_TYPE || SCALAR_FLOAT_TYPE_P (t) || FIXED_POINT_TYPE_P (t)) { @@ -14201,6 +14259,7 @@ verify_type (const_tree t) } else if (TREE_CODE (t) == INTEGER_TYPE || TREE_CODE (t) == BOOLEAN_TYPE + || TREE_CODE (t) == BITINT_TYPE || TREE_CODE (t) == OFFSET_TYPE || TREE_CODE (t) == REFERENCE_TYPE || TREE_CODE (t) == NULLPTR_TYPE @@ -14260,6 +14319,7 @@ verify_type (const_tree t) } if (TREE_CODE (t) != INTEGER_TYPE && TREE_CODE (t) != BOOLEAN_TYPE + && TREE_CODE (t) != BITINT_TYPE && TREE_CODE (t) != OFFSET_TYPE && TREE_CODE (t) != REFERENCE_TYPE && TREE_CODE (t) != NULLPTR_TYPE @@ -15035,6 +15095,7 @@ void tree_cc_finalize (void) { clear_nonstandard_integer_type_cache (); + vec_free (bitint_type_cache); } #if CHECKING_P --- gcc/builtins.cc.jj 2023-07-24 17:48:26.432041329 +0200 +++ gcc/builtins.cc 2023-07-27 15:03:24.222234619 +0200 @@ -1876,6 +1876,7 @@ type_to_class (tree type) ? string_type_class : array_type_class); case LANG_TYPE: return lang_type_class; case OPAQUE_TYPE: return opaque_type_class; + case BITINT_TYPE: return bitint_type_class; default: return no_type_class; } } @@ -9423,9 +9424,11 @@ fold_builtin_unordered_cmp (location_t l /* Choose the wider of two real types. */ cmp_type = TYPE_PRECISION (type0) >= TYPE_PRECISION (type1) ? type0 : type1; - else if (code0 == REAL_TYPE && code1 == INTEGER_TYPE) + else if (code0 == REAL_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) cmp_type = type0; - else if (code0 == INTEGER_TYPE && code1 == REAL_TYPE) + else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && code1 == REAL_TYPE) cmp_type = type1; arg0 = fold_convert_loc (loc, cmp_type, arg0); --- gcc/calls.cc.jj 2023-06-20 20:17:01.706613302 +0200 +++ gcc/calls.cc 2023-07-27 15:03:24.240234368 +0200 @@ -5016,6 +5016,24 @@ store_one_arg (struct arg_data *arg, rtx if (arg->pass_on_stack) stack_arg_under_construction++; + if (TREE_CODE (pval) == INTEGER_CST + && TREE_CODE (TREE_TYPE (pval)) == BITINT_TYPE) + { + unsigned int prec = TYPE_PRECISION (TREE_TYPE (pval)); + struct bitint_info info; + gcc_assert (targetm.c.bitint_type_info (prec, &info)); + scalar_int_mode limb_mode = as_a (info.limb_mode); + unsigned int limb_prec = GET_MODE_PRECISION (limb_mode); + if (prec > limb_prec) + { + scalar_int_mode arith_mode + = (targetm.scalar_mode_supported_p (TImode) + ? TImode : DImode); + if (prec > GET_MODE_PRECISION (arith_mode)) + pval = tree_output_constant_def (pval); + } + } + arg->value = expand_expr (pval, (partial || TYPE_MODE (TREE_TYPE (pval)) != arg->mode) --- gcc/cfgexpand.cc.jj 2023-06-06 20:02:35.588211832 +0200 +++ gcc/cfgexpand.cc 2023-07-27 15:03:24.262234061 +0200 @@ -3096,6 +3096,15 @@ expand_asm_stmt (gasm *stmt) { tree t = gimple_asm_input_op (stmt, i); input_tvec[i] = TREE_VALUE (t); + if (TREE_CODE (input_tvec[i]) == INTEGER_CST + && TREE_CODE (TREE_TYPE (input_tvec[i])) == BITINT_TYPE) + { + scalar_int_mode arith_mode + = (targetm.scalar_mode_supported_p (TImode) ? TImode : DImode); + if (TYPE_PRECISION (TREE_TYPE (input_tvec[i])) + > GET_MODE_PRECISION (arith_mode)) + input_tvec[i] = tree_output_constant_def (input_tvec[i]); + } constraints[i + noutputs] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); } @@ -4524,6 +4533,10 @@ expand_debug_expr (tree exp) /* Fall through. */ case INTEGER_CST: + if (TREE_CODE (TREE_TYPE (exp)) == BITINT_TYPE + && TYPE_MODE (TREE_TYPE (exp)) == BLKmode) + return NULL; + /* FALLTHRU */ case REAL_CST: case FIXED_CST: op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER); --- gcc/config/i386/i386.cc.jj 2023-07-19 10:01:17.380467993 +0200 +++ gcc/config/i386/i386.cc 2023-07-27 15:03:24.230234508 +0200 @@ -2121,7 +2121,8 @@ classify_argument (machine_mode mode, co return 0; } - if (type && AGGREGATE_TYPE_P (type)) + if (type && (AGGREGATE_TYPE_P (type) + || (TREE_CODE (type) == BITINT_TYPE && words > 1))) { int i; tree field; @@ -2270,6 +2271,14 @@ classify_argument (machine_mode mode, co } break; + case BITINT_TYPE: + /* _BitInt(N) for N > 64 is passed as structure containing + (N + 63) / 64 64-bit elements. */ + if (words > 2) + return 0; + classes[0] = classes[1] = X86_64_INTEGER_CLASS; + return 2; + default: gcc_unreachable (); } @@ -24799,6 +24808,26 @@ ix86_get_excess_precision (enum excess_p return FLT_EVAL_METHOD_UNPREDICTABLE; } +/* Return true if _BitInt(N) is supported and fill details about it into + *INFO. */ +bool +ix86_bitint_type_info (int n, struct bitint_info *info) +{ + if (!TARGET_64BIT) + return false; + if (n <= 8) + info->limb_mode = QImode; + else if (n <= 16) + info->limb_mode = HImode; + else if (n <= 32) + info->limb_mode = SImode; + else + info->limb_mode = DImode; + info->big_endian = false; + info->extended = false; + return true; +} + /* Implement PUSH_ROUNDING. On 386, we have pushw instruction that decrements by exactly 2 no matter what the position was, there is no pushb. @@ -25403,6 +25432,8 @@ ix86_run_selftests (void) #undef TARGET_C_EXCESS_PRECISION #define TARGET_C_EXCESS_PRECISION ix86_get_excess_precision +#undef TARGET_C_BITINT_TYPE_INFO +#define TARGET_C_BITINT_TYPE_INFO ix86_bitint_type_info #undef TARGET_PROMOTE_PROTOTYPES #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true #undef TARGET_PUSH_ARGUMENT --- gcc/convert.cc.jj 2023-01-04 23:12:56.937574700 +0100 +++ gcc/convert.cc 2023-07-27 15:03:24.258234117 +0200 @@ -77,6 +77,7 @@ convert_to_pointer_1 (tree type, tree ex case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: + case BITINT_TYPE: { /* If the input precision differs from the target pointer type precision, first convert the input expression to an integer type of @@ -316,6 +317,7 @@ convert_to_real_1 (tree type, tree expr, case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: + case BITINT_TYPE: return build1 (FLOAT_EXPR, type, expr); case FIXED_POINT_TYPE: @@ -660,6 +662,7 @@ convert_to_integer_1 (tree type, tree ex case ENUMERAL_TYPE: case BOOLEAN_TYPE: case OFFSET_TYPE: + case BITINT_TYPE: /* If this is a logical operation, which just returns 0 or 1, we can change the type of the expression. */ @@ -701,7 +704,9 @@ convert_to_integer_1 (tree type, tree ex type corresponding to its mode, then do a nop conversion to TYPE. */ else if (TREE_CODE (type) == ENUMERAL_TYPE - || maybe_ne (outprec, GET_MODE_PRECISION (TYPE_MODE (type)))) + || (TREE_CODE (type) != BITINT_TYPE + && maybe_ne (outprec, + GET_MODE_PRECISION (TYPE_MODE (type))))) { expr = convert_to_integer_1 (lang_hooks.types.type_for_mode @@ -1000,6 +1005,7 @@ convert_to_complex_1 (tree type, tree ex case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: + case BITINT_TYPE: return build2 (COMPLEX_EXPR, type, convert (subtype, expr), convert (subtype, integer_zero_node)); --- gcc/doc/tm.texi.in.jj 2023-05-30 17:52:34.476857273 +0200 +++ gcc/doc/tm.texi.in 2023-07-27 15:03:24.286233725 +0200 @@ -936,6 +936,8 @@ Return a value, with the same meaning as @code{FLT_EVAL_METHOD} that describes which excess precision should be applied. +@hook TARGET_C_BITINT_TYPE_INFO + @hook TARGET_PROMOTE_FUNCTION_MODE @defmac PARM_BOUNDARY --- gcc/doc/tm.texi.jj 2023-05-30 17:52:34.474857301 +0200 +++ gcc/doc/tm.texi 2023-07-27 15:03:24.284233753 +0200 @@ -1020,6 +1020,11 @@ Return a value, with the same meaning as @code{FLT_EVAL_METHOD} that describes which excess precision should be applied. +@deftypefn {Target Hook} bool TARGET_C_BITINT_TYPE_INFO (int @var{n}, struct bitint_info *@var{info}) +This target hook returns true if _BitInt(N) is supported and provides some +details on it. +@end deftypefn + @deftypefn {Target Hook} machine_mode TARGET_PROMOTE_FUNCTION_MODE (const_tree @var{type}, machine_mode @var{mode}, int *@var{punsignedp}, const_tree @var{funtype}, int @var{for_return}) Like @code{PROMOTE_MODE}, but it is applied to outgoing function arguments or function return values. The target hook should return the new mode --- gcc/dwarf2out.cc.jj 2023-07-19 10:01:17.402467687 +0200 +++ gcc/dwarf2out.cc 2023-07-27 15:04:07.726625658 +0200 @@ -13298,6 +13298,14 @@ base_type_die (tree type, bool reverse) encoding = DW_ATE_boolean; break; + case BITINT_TYPE: + /* C23 _BitInt(N). */ + if (TYPE_UNSIGNED (type)) + encoding = DW_ATE_unsigned; + else + encoding = DW_ATE_signed; + break; + default: /* No other TREE_CODEs are Dwarf fundamental types. */ gcc_unreachable (); @@ -13308,6 +13316,8 @@ base_type_die (tree type, bool reverse) add_AT_unsigned (base_type_result, DW_AT_byte_size, int_size_in_bytes (type)); add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); + if (TREE_CODE (type) == BITINT_TYPE) + add_AT_unsigned (base_type_result, DW_AT_bit_size, TYPE_PRECISION (type)); if (need_endianity_attribute_p (reverse)) add_AT_unsigned (base_type_result, DW_AT_endianity, @@ -13392,6 +13402,7 @@ is_base_type (tree type) case FIXED_POINT_TYPE: case COMPLEX_TYPE: case BOOLEAN_TYPE: + case BITINT_TYPE: return true; case VOID_TYPE: @@ -13990,12 +14001,24 @@ modified_type_die (tree type, int cv_qua name = DECL_NAME (name); add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name)); } - /* This probably indicates a bug. */ else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type) { - name = TYPE_IDENTIFIER (type); - add_name_attribute (mod_type_die, - name ? IDENTIFIER_POINTER (name) : "__unknown__"); + if (TREE_CODE (type) == BITINT_TYPE) + { + char name_buf[sizeof ("unsigned _BitInt(2147483647)")]; + snprintf (name_buf, sizeof (name_buf), + "%s_BitInt(%d)", TYPE_UNSIGNED (type) ? "unsigned " : "", + TYPE_PRECISION (type)); + add_name_attribute (mod_type_die, name_buf); + } + else + { + /* This probably indicates a bug. */ + name = TYPE_IDENTIFIER (type); + add_name_attribute (mod_type_die, + name + ? IDENTIFIER_POINTER (name) : "__unknown__"); + } } if (qualified_type && !reverse_base_type) @@ -20523,6 +20546,22 @@ rtl_for_decl_init (tree init, tree type) return NULL; } + /* RTL can't deal with BLKmode INTEGER_CSTs. */ + if (TREE_CODE (init) == INTEGER_CST + && TREE_CODE (TREE_TYPE (init)) == BITINT_TYPE + && TYPE_MODE (TREE_TYPE (init)) == BLKmode) + { + if (tree_fits_shwi_p (init)) + { + bool uns = TYPE_UNSIGNED (TREE_TYPE (init)); + tree type + = build_nonstandard_integer_type (HOST_BITS_PER_WIDE_INT, uns); + init = fold_convert (type, init); + } + else + return NULL; + } + rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); /* If expand_expr returns a MEM, it wasn't immediate. */ @@ -26361,6 +26400,7 @@ gen_type_die_with_usage (tree type, dw_d case FIXED_POINT_TYPE: case COMPLEX_TYPE: case BOOLEAN_TYPE: + case BITINT_TYPE: /* No DIEs needed for fundamental types. */ break; --- gcc/expr.cc.jj 2023-07-02 12:07:08.455164393 +0200 +++ gcc/expr.cc 2023-07-27 15:03:24.253234187 +0200 @@ -10828,6 +10828,8 @@ expand_expr_real_1 (tree exp, rtx target ssa_name = exp; decl_rtl = get_rtx_for_ssa_name (ssa_name); exp = SSA_NAME_VAR (ssa_name); + if (!exp || VAR_P (exp)) + reduce_bit_field = false; goto expand_decl_rtl; case VAR_DECL: @@ -10961,6 +10963,13 @@ expand_expr_real_1 (tree exp, rtx target temp = expand_misaligned_mem_ref (temp, mode, unsignedp, MEM_ALIGN (temp), NULL_RTX, NULL); + if (TREE_CODE (type) == BITINT_TYPE + && reduce_bit_field + && mode != BLKmode + && modifier != EXPAND_MEMORY + && modifier != EXPAND_WRITE + && modifier != EXPAND_CONST_ADDRESS) + return reduce_to_bit_field_precision (temp, NULL_RTX, type); return temp; } @@ -11007,9 +11016,23 @@ expand_expr_real_1 (tree exp, rtx target temp = gen_lowpart_SUBREG (mode, decl_rtl); SUBREG_PROMOTED_VAR_P (temp) = 1; SUBREG_PROMOTED_SET (temp, unsignedp); + if (TREE_CODE (type) == BITINT_TYPE + && reduce_bit_field + && mode != BLKmode + && modifier != EXPAND_MEMORY + && modifier != EXPAND_WRITE + && modifier != EXPAND_CONST_ADDRESS) + return reduce_to_bit_field_precision (temp, NULL_RTX, type); return temp; } + if (TREE_CODE (type) == BITINT_TYPE + && reduce_bit_field + && mode != BLKmode + && modifier != EXPAND_MEMORY + && modifier != EXPAND_WRITE + && modifier != EXPAND_CONST_ADDRESS) + return reduce_to_bit_field_precision (decl_rtl, NULL_RTX, type); return decl_rtl; case INTEGER_CST: @@ -11192,6 +11215,13 @@ expand_expr_real_1 (tree exp, rtx target && align < GET_MODE_ALIGNMENT (mode)) temp = expand_misaligned_mem_ref (temp, mode, unsignedp, align, NULL_RTX, NULL); + if (TREE_CODE (type) == BITINT_TYPE + && reduce_bit_field + && mode != BLKmode + && modifier != EXPAND_WRITE + && modifier != EXPAND_MEMORY + && modifier != EXPAND_CONST_ADDRESS) + return reduce_to_bit_field_precision (temp, NULL_RTX, type); return temp; } @@ -11253,18 +11283,21 @@ expand_expr_real_1 (tree exp, rtx target set_mem_addr_space (temp, as); if (TREE_THIS_VOLATILE (exp)) MEM_VOLATILE_P (temp) = 1; - if (modifier != EXPAND_WRITE - && modifier != EXPAND_MEMORY - && !inner_reference_p + if (modifier == EXPAND_WRITE || modifier == EXPAND_MEMORY) + return temp; + if (!inner_reference_p && mode != BLKmode && align < GET_MODE_ALIGNMENT (mode)) temp = expand_misaligned_mem_ref (temp, mode, unsignedp, align, modifier == EXPAND_STACK_PARM ? NULL_RTX : target, alt_rtl); - if (reverse - && modifier != EXPAND_MEMORY - && modifier != EXPAND_WRITE) + if (reverse) temp = flip_storage_order (mode, temp); + if (TREE_CODE (type) == BITINT_TYPE + && reduce_bit_field + && mode != BLKmode + && modifier != EXPAND_CONST_ADDRESS) + return reduce_to_bit_field_precision (temp, NULL_RTX, type); return temp; } @@ -11817,6 +11850,14 @@ expand_expr_real_1 (tree exp, rtx target && modifier != EXPAND_WRITE) op0 = flip_storage_order (mode1, op0); + if (TREE_CODE (type) == BITINT_TYPE + && reduce_bit_field + && mode != BLKmode + && modifier != EXPAND_MEMORY + && modifier != EXPAND_WRITE + && modifier != EXPAND_CONST_ADDRESS) + op0 = reduce_to_bit_field_precision (op0, NULL_RTX, type); + if (mode == mode1 || mode1 == BLKmode || mode1 == tmode || modifier == EXPAND_CONST_ADDRESS || modifier == EXPAND_INITIALIZER) --- gcc/fold-const.cc.jj 2023-07-19 10:01:17.404467659 +0200 +++ gcc/fold-const.cc 2023-07-27 15:03:24.294233613 +0200 @@ -2557,7 +2557,7 @@ fold_convert_loc (location_t loc, tree t /* fall through */ case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: - case OFFSET_TYPE: + case OFFSET_TYPE: case BITINT_TYPE: if (TREE_CODE (arg) == INTEGER_CST) { tem = fold_convert_const (NOP_EXPR, type, arg); @@ -2597,7 +2597,7 @@ fold_convert_loc (location_t loc, tree t switch (TREE_CODE (orig)) { - case INTEGER_TYPE: + case INTEGER_TYPE: case BITINT_TYPE: case BOOLEAN_TYPE: case ENUMERAL_TYPE: case POINTER_TYPE: case REFERENCE_TYPE: return fold_build1_loc (loc, FLOAT_EXPR, type, arg); @@ -2632,6 +2632,7 @@ fold_convert_loc (location_t loc, tree t case ENUMERAL_TYPE: case BOOLEAN_TYPE: case REAL_TYPE: + case BITINT_TYPE: return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg); case COMPLEX_TYPE: @@ -2645,7 +2646,7 @@ fold_convert_loc (location_t loc, tree t case COMPLEX_TYPE: switch (TREE_CODE (orig)) { - case INTEGER_TYPE: + case INTEGER_TYPE: case BITINT_TYPE: case BOOLEAN_TYPE: case ENUMERAL_TYPE: case POINTER_TYPE: case REFERENCE_TYPE: case REAL_TYPE: @@ -5324,6 +5325,8 @@ make_range_step (location_t loc, enum tr equiv_type = lang_hooks.types.type_for_mode (TYPE_MODE (arg0_type), TYPE_SATURATING (arg0_type)); + else if (TREE_CODE (arg0_type) == BITINT_TYPE) + equiv_type = arg0_type; else equiv_type = lang_hooks.types.type_for_mode (TYPE_MODE (arg0_type), 1); @@ -6850,10 +6853,19 @@ extract_muldiv_1 (tree t, tree c, enum t { tree type = TREE_TYPE (t); enum tree_code tcode = TREE_CODE (t); - tree ctype = (wide_type != 0 - && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (wide_type)) - > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type))) - ? wide_type : type); + tree ctype = type; + if (wide_type) + { + if (TREE_CODE (type) == BITINT_TYPE + || TREE_CODE (wide_type) == BITINT_TYPE) + { + if (TYPE_PRECISION (wide_type) > TYPE_PRECISION (type)) + ctype = wide_type; + } + else if (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (wide_type)) + > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type))) + ctype = wide_type; + } tree t1, t2; bool same_p = tcode == code; tree op0 = NULL_TREE, op1 = NULL_TREE; @@ -7714,7 +7726,29 @@ static int native_encode_int (const_tree expr, unsigned char *ptr, int len, int off) { tree type = TREE_TYPE (expr); - int total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)); + int total_bytes; + if (TREE_CODE (type) == BITINT_TYPE) + { + struct bitint_info info; + gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), + &info)); + scalar_int_mode limb_mode = as_a (info.limb_mode); + if (TYPE_PRECISION (type) > GET_MODE_PRECISION (limb_mode)) + { + total_bytes = tree_to_uhwi (TYPE_SIZE_UNIT (type)); + /* More work is needed when adding _BitInt support to PDP endian + if limb is smaller than word, or if _BitInt limb ordering doesn't + match target endianity here. */ + gcc_checking_assert (info.big_endian == WORDS_BIG_ENDIAN + && (BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN + || (GET_MODE_SIZE (limb_mode) + >= UNITS_PER_WORD))); + } + else + total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)); + } + else + total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)); int byte, offset, word, words; unsigned char value; @@ -8622,7 +8656,29 @@ native_encode_initializer (tree init, un static tree native_interpret_int (tree type, const unsigned char *ptr, int len) { - int total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)); + int total_bytes; + if (TREE_CODE (type) == BITINT_TYPE) + { + struct bitint_info info; + gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), + &info)); + scalar_int_mode limb_mode = as_a (info.limb_mode); + if (TYPE_PRECISION (type) > GET_MODE_PRECISION (limb_mode)) + { + total_bytes = tree_to_uhwi (TYPE_SIZE_UNIT (type)); + /* More work is needed when adding _BitInt support to PDP endian + if limb is smaller than word, or if _BitInt limb ordering doesn't + match target endianity here. */ + gcc_checking_assert (info.big_endian == WORDS_BIG_ENDIAN + && (BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN + || (GET_MODE_SIZE (limb_mode) + >= UNITS_PER_WORD))); + } + else + total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)); + } + else + total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)); if (total_bytes > len || total_bytes * BITS_PER_UNIT > HOST_BITS_PER_DOUBLE_INT) @@ -8824,6 +8880,7 @@ native_interpret_expr (tree type, const case POINTER_TYPE: case REFERENCE_TYPE: case OFFSET_TYPE: + case BITINT_TYPE: return native_interpret_int (type, ptr, len); case REAL_TYPE: --- gcc/gimple-expr.cc.jj 2023-05-20 15:31:09.197661517 +0200 +++ gcc/gimple-expr.cc 2023-07-27 15:03:24.219234661 +0200 @@ -111,6 +111,15 @@ useless_type_conversion_p (tree outer_ty && TYPE_PRECISION (outer_type) != 1) return false; + /* Preserve conversions to/from BITINT_TYPE. While we don't + need to care that much about such conversions within a function's + body, we need to prevent changing BITINT_TYPE to INTEGER_TYPE + of the same precision or vice versa when passed to functions, + especially for varargs. */ + if ((TREE_CODE (inner_type) == BITINT_TYPE) + != (TREE_CODE (outer_type) == BITINT_TYPE)) + return false; + /* We don't need to preserve changes in the types minimum or maximum value in general as these do not generate code unless the types precisions are different. */ --- gcc/gimple-fold.cc.jj 2023-07-24 17:48:26.491040563 +0200 +++ gcc/gimple-fold.cc 2023-07-27 15:03:24.257234131 +0200 @@ -1475,8 +1475,9 @@ gimple_fold_builtin_memset (gimple_stmt_ if (TREE_CODE (etype) == ARRAY_TYPE) etype = TREE_TYPE (etype); - if (!INTEGRAL_TYPE_P (etype) - && !POINTER_TYPE_P (etype)) + if ((!INTEGRAL_TYPE_P (etype) + && !POINTER_TYPE_P (etype)) + || TREE_CODE (etype) == BITINT_TYPE) return NULL_TREE; if (! var_decl_component_p (var)) --- gcc/gimple-lower-bitint.cc.jj 2023-07-27 15:03:24.299233543 +0200 +++ gcc/gimple-lower-bitint.cc 2023-07-27 15:30:57.839090959 +0200 @@ -0,0 +1,5495 @@ +/* Lower _BitInt(N) operations to scalar operations. + Copyright (C) 2023 Free Software Foundation, Inc. + Contributed by Jakub Jelinek . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "rtl.h" +#include "tree.h" +#include "gimple.h" +#include "cfghooks.h" +#include "tree-pass.h" +#include "ssa.h" +#include "fold-const.h" +#include "gimplify.h" +#include "gimple-iterator.h" +#include "tree-cfg.h" +#include "tree-dfa.h" +#include "cfgloop.h" +#include "cfganal.h" +#include "target.h" +#include "tree-ssa-live.h" +#include "tree-ssa-coalesce.h" +#include "domwalk.h" +#include "memmodel.h" +#include "optabs.h" +#include "varasm.h" +#include "gimple-range.h" +#include "value-range.h" +#include "langhooks.h" +#include "gimplify-me.h" +#include "diagnostic-core.h" +#include "tree-eh.h" +#include "tree-pretty-print.h" +#include "alloc-pool.h" +#include "tree-into-ssa.h" +#include "tree-cfgcleanup.h" +#include "tree-switch-conversion.h" +#include "ubsan.h" +#include "gimple-lower-bitint.h" + +/* Split BITINT_TYPE precisions in 4 categories. Small _BitInt, where + target hook says it is a single limb, middle _BitInt which per ABI + does not, but there is some INTEGER_TYPE in which arithmetics can be + performed (operations on such _BitInt are lowered to casts to that + arithmetic type and cast back; e.g. on x86_64 limb is DImode, but + target supports TImode, so _BitInt(65) to _BitInt(128) are middle + ones), large _BitInt which should by straight line code and + finally huge _BitInt which should be handled by loops over the limbs. */ + +enum bitint_prec_kind { + bitint_prec_small, + bitint_prec_middle, + bitint_prec_large, + bitint_prec_huge +}; + +/* Caches to speed up bitint_precision_kind. */ + +static int small_max_prec, mid_min_prec, large_min_prec, huge_min_prec; +static int limb_prec; + +/* Categorize _BitInt(PREC) as small, middle, large or huge. */ + +static bitint_prec_kind +bitint_precision_kind (int prec) +{ + if (prec <= small_max_prec) + return bitint_prec_small; + if (huge_min_prec && prec >= huge_min_prec) + return bitint_prec_huge; + if (large_min_prec && prec >= large_min_prec) + return bitint_prec_large; + if (mid_min_prec && prec >= mid_min_prec) + return bitint_prec_middle; + + struct bitint_info info; + gcc_assert (targetm.c.bitint_type_info (prec, &info)); + scalar_int_mode limb_mode = as_a (info.limb_mode); + if (prec <= GET_MODE_PRECISION (limb_mode)) + { + small_max_prec = prec; + return bitint_prec_small; + } + scalar_int_mode arith_mode = (targetm.scalar_mode_supported_p (TImode) + ? TImode : DImode); + if (!large_min_prec + && GET_MODE_PRECISION (arith_mode) > GET_MODE_PRECISION (limb_mode)) + large_min_prec = GET_MODE_PRECISION (arith_mode) + 1; + if (!limb_prec) + limb_prec = GET_MODE_PRECISION (limb_mode); + if (!huge_min_prec) + { + if (4 * limb_prec >= GET_MODE_PRECISION (arith_mode)) + huge_min_prec = 4 * limb_prec; + else + huge_min_prec = GET_MODE_PRECISION (arith_mode) + 1; + } + if (prec <= GET_MODE_PRECISION (arith_mode)) + { + if (!mid_min_prec || prec < mid_min_prec) + mid_min_prec = prec; + return bitint_prec_middle; + } + if (large_min_prec && prec <= large_min_prec) + return bitint_prec_large; + return bitint_prec_huge; +} + +/* Same for a TYPE. */ + +static bitint_prec_kind +bitint_precision_kind (tree type) +{ + return bitint_precision_kind (TYPE_PRECISION (type)); +} + +/* Return minimum precision needed to describe INTEGER_CST + CST. All bits above that precision up to precision of + TREE_TYPE (CST) are cleared if EXT is set to 0, or set + if EXT is set to -1. */ + +static unsigned +bitint_min_cst_precision (tree cst, int &ext) +{ + ext = tree_int_cst_sgn (cst) < 0 ? -1 : 0; + wide_int w = wi::to_wide (cst); + unsigned min_prec = wi::min_precision (w, TYPE_SIGN (TREE_TYPE (cst))); + /* For signed values, we don't need to count the sign bit, + we'll use constant 0 or -1 for the upper bits. */ + if (!TYPE_UNSIGNED (TREE_TYPE (cst))) + --min_prec; + else + { + /* For unsigned values, also try signed min_precision + in case the constant has lots of most significant bits set. */ + unsigned min_prec2 = wi::min_precision (w, SIGNED) - 1; + if (min_prec2 < min_prec) + { + ext = -1; + return min_prec2; + } + } + return min_prec; +} + +namespace { + +/* If OP is middle _BitInt, cast it to corresponding INTEGER_TYPE + cached in TYPE and return it. */ + +tree +maybe_cast_middle_bitint (gimple_stmt_iterator *gsi, tree op, tree &type) +{ + if (op == NULL_TREE + || TREE_CODE (TREE_TYPE (op)) != BITINT_TYPE + || bitint_precision_kind (TREE_TYPE (op)) != bitint_prec_middle) + return op; + + int prec = TYPE_PRECISION (TREE_TYPE (op)); + int uns = TYPE_UNSIGNED (TREE_TYPE (op)); + if (type == NULL_TREE + || TYPE_PRECISION (type) != prec + || TYPE_UNSIGNED (type) != uns) + type = build_nonstandard_integer_type (prec, uns); + + if (TREE_CODE (op) != SSA_NAME) + { + tree nop = fold_convert (type, op); + if (is_gimple_val (nop)) + return nop; + } + + tree nop = make_ssa_name (type); + gimple *g = gimple_build_assign (nop, NOP_EXPR, op); + gsi_insert_before (gsi, g, GSI_SAME_STMT); + return nop; +} + +/* Return true if STMT can be handled in a loop from least to most + significant limb together with its dependencies. */ + +bool +mergeable_op (gimple *stmt) +{ + if (!is_gimple_assign (stmt)) + return false; + switch (gimple_assign_rhs_code (stmt)) + { + case PLUS_EXPR: + case MINUS_EXPR: + case NEGATE_EXPR: + case BIT_AND_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + case BIT_NOT_EXPR: + case SSA_NAME: + case INTEGER_CST: + return true; + case LSHIFT_EXPR: + { + tree cnt = gimple_assign_rhs2 (stmt); + if (tree_fits_uhwi_p (cnt) + && tree_to_uhwi (cnt) < (unsigned HOST_WIDE_INT) limb_prec) + return true; + } + break; + CASE_CONVERT: + case VIEW_CONVERT_EXPR: + { + tree lhs_type = TREE_TYPE (gimple_assign_lhs (stmt)); + tree rhs_type = TREE_TYPE (gimple_assign_rhs1 (stmt)); + if (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME + && TREE_CODE (lhs_type) == BITINT_TYPE + && TREE_CODE (rhs_type) == BITINT_TYPE + && bitint_precision_kind (lhs_type) >= bitint_prec_large + && bitint_precision_kind (rhs_type) >= bitint_prec_large + && tree_int_cst_equal (TYPE_SIZE (lhs_type), TYPE_SIZE (rhs_type))) + { + if (TYPE_PRECISION (rhs_type) >= TYPE_PRECISION (lhs_type)) + return true; + if ((unsigned) TYPE_PRECISION (lhs_type) % (2 * limb_prec) != 0) + return true; + if (bitint_precision_kind (lhs_type) == bitint_prec_large) + return true; + } + break; + } + default: + break; + } + return false; +} + +/* Return non-zero if stmt is .{ADD,SUB,MUL}_OVERFLOW call with + _Complex large/huge _BitInt lhs which has at most two immediate uses, + at most one use in REALPART_EXPR stmt in the same bb and exactly one + IMAGPART_EXPR use in the same bb with a single use which casts it to + non-BITINT_TYPE integral type. If there is a REALPART_EXPR use, + return 2. Such cases (most common uses of those builtins) can be + optimized by marking their lhs and lhs of IMAGPART_EXPR and maybe lhs + of REALPART_EXPR as not needed to be backed up by a stack variable. + For .UBSAN_CHECK_{ADD,SUB,MUL} return 3. */ + +int +optimizable_arith_overflow (gimple *stmt) +{ + bool is_ubsan = false; + if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt)) + return false; + switch (gimple_call_internal_fn (stmt)) + { + case IFN_ADD_OVERFLOW: + case IFN_SUB_OVERFLOW: + case IFN_MUL_OVERFLOW: + break; + case IFN_UBSAN_CHECK_ADD: + case IFN_UBSAN_CHECK_SUB: + case IFN_UBSAN_CHECK_MUL: + is_ubsan = true; + break; + default: + return 0; + } + tree lhs = gimple_call_lhs (stmt); + if (!lhs) + return 0; + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs)) + return 0; + tree type = is_ubsan ? TREE_TYPE (lhs) : TREE_TYPE (TREE_TYPE (lhs)); + if (TREE_CODE (type) != BITINT_TYPE + || bitint_precision_kind (type) < bitint_prec_large) + return 0; + + if (is_ubsan) + { + use_operand_p use_p; + gimple *use_stmt; + if (!single_imm_use (lhs, &use_p, &use_stmt) + || gimple_bb (use_stmt) != gimple_bb (stmt) + || !gimple_store_p (use_stmt) + || !is_gimple_assign (use_stmt) + || gimple_has_volatile_ops (use_stmt) + || stmt_ends_bb_p (use_stmt)) + return 0; + return 3; + } + + imm_use_iterator ui; + use_operand_p use_p; + int seen = 0; + FOR_EACH_IMM_USE_FAST (use_p, ui, lhs) + { + gimple *g = USE_STMT (use_p); + if (is_gimple_debug (g)) + continue; + if (!is_gimple_assign (g) || gimple_bb (g) != gimple_bb (stmt)) + return 0; + if (gimple_assign_rhs_code (g) == REALPART_EXPR) + { + if ((seen & 1) != 0) + return 0; + seen |= 1; + } + else if (gimple_assign_rhs_code (g) == IMAGPART_EXPR) + { + if ((seen & 2) != 0) + return 0; + seen |= 2; + + use_operand_p use2_p; + gimple *use_stmt; + tree lhs2 = gimple_assign_lhs (g); + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs2)) + return 0; + if (!single_imm_use (lhs2, &use2_p, &use_stmt) + || gimple_bb (use_stmt) != gimple_bb (stmt) + || !gimple_assign_cast_p (use_stmt)) + return 0; + + lhs2 = gimple_assign_lhs (use_stmt); + if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs2)) + || TREE_CODE (TREE_TYPE (lhs2)) == BITINT_TYPE) + return 0; + } + else + return 0; + } + if ((seen & 2) == 0) + return 0; + return seen == 3 ? 2 : 1; +} + +/* If STMT is some kind of comparison (GIMPLE_COND, comparison + assignment or COND_EXPR) comparing large/huge _BitInt types, + return the comparison code and if non-NULL fill in the comparison + operands to *POP1 and *POP2. */ + +tree_code +comparison_op (gimple *stmt, tree *pop1, tree *pop2) +{ + tree op1 = NULL_TREE, op2 = NULL_TREE; + tree_code code = ERROR_MARK; + if (gimple_code (stmt) == GIMPLE_COND) + { + code = gimple_cond_code (stmt); + op1 = gimple_cond_lhs (stmt); + op2 = gimple_cond_rhs (stmt); + } + else if (is_gimple_assign (stmt)) + { + code = gimple_assign_rhs_code (stmt); + op1 = gimple_assign_rhs1 (stmt); + if (TREE_CODE_CLASS (code) == tcc_comparison + || TREE_CODE_CLASS (code) == tcc_binary) + op2 = gimple_assign_rhs2 (stmt); + switch (code) + { + default: + break; + case COND_EXPR: + tree cond = gimple_assign_rhs1 (stmt); + code = TREE_CODE (cond); + op1 = TREE_OPERAND (cond, 0); + op2 = TREE_OPERAND (cond, 1); + break; + } + } + if (TREE_CODE_CLASS (code) != tcc_comparison) + return ERROR_MARK; + tree type = TREE_TYPE (op1); + if (TREE_CODE (type) != BITINT_TYPE + || bitint_precision_kind (type) < bitint_prec_large) + return ERROR_MARK; + if (pop1) + { + *pop1 = op1; + *pop2 = op2; + } + return code; +} + +/* Class used during large/huge _BitInt lowering containing all the + state for the methods. */ + +struct bitint_large_huge +{ + bitint_large_huge () + : m_names (NULL), m_loads (NULL), m_preserved (NULL), + m_single_use_names (NULL), m_map (NULL), m_vars (NULL), + m_limb_type (NULL_TREE), m_data (vNULL) {} + + ~bitint_large_huge (); + + void insert_before (gimple *); + tree limb_access_type (tree, tree); + tree limb_access (tree, tree, tree, bool); + tree handle_operand (tree, tree); + tree prepare_data_in_out (tree, tree, tree *); + tree add_cast (tree, tree); + tree handle_plus_minus (tree_code, tree, tree, tree); + tree handle_lshift (tree, tree, tree); + tree handle_cast (tree, tree, tree); + tree handle_stmt (gimple *, tree); + tree handle_operand_addr (tree, gimple *, int *, int *); + tree create_loop (tree, tree *); + tree lower_mergeable_stmt (gimple *, tree_code &, tree, tree); + tree lower_comparison_stmt (gimple *, tree_code &, tree, tree); + void lower_shift_stmt (tree, gimple *); + void lower_muldiv_stmt (tree, gimple *); + void lower_float_conv_stmt (tree, gimple *); + tree arith_overflow_extract_bits (unsigned int, unsigned int, tree, + unsigned int, bool); + void finish_arith_overflow (tree, tree, tree, tree, tree, tree, gimple *, + tree_code); + void lower_addsub_overflow (tree, gimple *); + void lower_mul_overflow (tree, gimple *); + void lower_cplxpart_stmt (tree, gimple *); + void lower_complexexpr_stmt (gimple *); + void lower_call (tree, gimple *); + void lower_asm (gimple *); + void lower_stmt (gimple *); + + /* Bitmap of large/huge _BitInt SSA_NAMEs except those can be + merged with their uses. */ + bitmap m_names; + /* Subset of those for lhs of load statements. These will be + cleared in m_names if the loads will be mergeable with all + their uses. */ + bitmap m_loads; + /* Bitmap of large/huge _BitInt SSA_NAMEs that should survive + to later passes (arguments or return values of calls). */ + bitmap m_preserved; + /* Subset of m_names which have a single use. As the lowering + can replace various original statements with their lowered + form even before it is done iterating over all basic blocks, + testing has_single_use for the purpose of emitting clobbers + doesn't work properly. */ + bitmap m_single_use_names; + /* Used for coalescing/partitioning of large/huge _BitInt SSA_NAMEs + set in m_names. */ + var_map m_map; + /* Mapping of the partitions to corresponding decls. */ + tree *m_vars; + /* Unsigned integer type with limb precision. */ + tree m_limb_type; + /* Its TYPE_SIZE_UNIT. */ + unsigned HOST_WIDE_INT m_limb_size; + /* Location of a gimple stmt which is being currently lowered. */ + location_t m_loc; + /* Current stmt iterator where code is being lowered currently. */ + gimple_stmt_iterator m_gsi; + /* Statement after which any clobbers should be added if non-NULL. */ + gimple *m_after_stmt; + /* Set when creating loops to the loop header bb and its preheader. */ + basic_block m_bb, m_preheader_bb; + /* Stmt iterator after which initialization statements should be emitted. */ + gimple_stmt_iterator m_init_gsi; + /* Decl into which a mergeable statement stores result. */ + tree m_lhs; + /* handle_operand/handle_stmt can be invoked in various ways. + + lower_mergeable_stmt for large _BitInt calls those with constant + idx only, expanding to straight line code, for huge _BitInt + emits a loop from least significant limb upwards, where each loop + iteration handles 2 limbs, plus there can be up to one full limb + and one partial limb processed after the loop, where handle_operand + and/or handle_stmt are called with constant idx. m_upwards_2limb + is set for this case, false otherwise. + + Another way is used by lower_comparison_stmt, which walks limbs + from most significant to least significant, partial limb if any + processed first with constant idx and then loop processing a single + limb per iteration with non-constant idx. + + Another way is used in lower_shift_stmt, where for LSHIFT_EXPR + destination limbs are processed from most significant to least + significant or for RSHIFT_EXPR the other way around, in loops or + straight line code, but idx usually is non-constant (so from + handle_operand/handle_stmt POV random access). The LSHIFT_EXPR + handling there can access even partial limbs using non-constant + idx (then m_var_msb should be true, for all the other cases + including lower_mergeable_stmt/lower_comparison_stmt that is + not the case and so m_var_msb should be false. + + m_first should be set the first time handle_operand/handle_stmt + is called and clear when it is called for some other limb with + the same argument. If the lowering of an operand (e.g. INTEGER_CST) + or statement (e.g. +/-/<< with < limb_prec constant) needs some + state between the different calls, when m_first is true it should + push some trees to m_data vector and also make sure m_data_cnt is + incremented by how many trees were pushed, and when m_first is + false, it can use the m_data[m_data_cnt] etc. data or update them, + just needs to bump m_data_cnt by the same amount as when it was + called with m_first set. The toplevel calls to + handle_operand/handle_stmt should set m_data_cnt to 0 and truncate + m_data vector when setting m_first to true. */ + bool m_first; + bool m_var_msb; + unsigned m_upwards_2limb; + vec m_data; + unsigned int m_data_cnt; +}; + +bitint_large_huge::~bitint_large_huge () +{ + BITMAP_FREE (m_names); + BITMAP_FREE (m_loads); + BITMAP_FREE (m_preserved); + BITMAP_FREE (m_single_use_names); + if (m_map) + delete_var_map (m_map); + XDELETEVEC (m_vars); + m_data.release (); +} + +/* Insert gimple statement G before current location + and set its gimple_location. */ + +void +bitint_large_huge::insert_before (gimple *g) +{ + gimple_set_location (g, m_loc); + gsi_insert_before (&m_gsi, g, GSI_SAME_STMT); +} + +/* Return type for accessing limb IDX of BITINT_TYPE TYPE. + This is normally m_limb_type, except for a partial most + significant limb if any. */ + +tree +bitint_large_huge::limb_access_type (tree type, tree idx) +{ + if (type == NULL_TREE) + return m_limb_type; + unsigned HOST_WIDE_INT i = tree_to_uhwi (idx); + unsigned int prec = TYPE_PRECISION (type); + gcc_assert (i * limb_prec < prec); + if ((i + 1) * limb_prec <= prec) + return m_limb_type; + else + return build_nonstandard_integer_type (prec % limb_prec, + TYPE_UNSIGNED (type)); +} + +/* Return a tree how to access limb IDX of VAR corresponding to BITINT_TYPE + TYPE. If WRITE_P is true, it will be a store, otherwise a read. */ + +tree +bitint_large_huge::limb_access (tree type, tree var, tree idx, bool write_p) +{ + tree atype = (tree_fits_uhwi_p (idx) + ? limb_access_type (type, idx) : m_limb_type); + tree ret; + if (DECL_P (var) && tree_fits_uhwi_p (idx)) + { + tree ptype = build_pointer_type (strip_array_types (TREE_TYPE (var))); + unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size; + ret = build2 (MEM_REF, m_limb_type, + build_fold_addr_expr (var), + build_int_cst (ptype, off)); + if (TREE_THIS_VOLATILE (var) || TREE_THIS_VOLATILE (TREE_TYPE (var))) + TREE_THIS_VOLATILE (ret) = 1; + } + else if (TREE_CODE (var) == MEM_REF && tree_fits_uhwi_p (idx)) + { + ret + = build2 (MEM_REF, m_limb_type, TREE_OPERAND (var, 0), + size_binop (PLUS_EXPR, TREE_OPERAND (var, 1), + build_int_cst (TREE_TYPE (TREE_OPERAND (var, 1)), + tree_to_uhwi (idx) + * m_limb_size))); + if (TREE_THIS_VOLATILE (var)) + TREE_THIS_VOLATILE (ret) = 1; + } + else + { + var = unshare_expr (var); + if (TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE + || !useless_type_conversion_p (m_limb_type, + TREE_TYPE (TREE_TYPE (var)))) + { + unsigned HOST_WIDE_INT nelts + = tree_to_uhwi (TYPE_SIZE (type)) / limb_prec; + tree atype = build_array_type_nelts (m_limb_type, nelts); + var = build1 (VIEW_CONVERT_EXPR, atype, var); + } + ret = build4 (ARRAY_REF, m_limb_type, var, idx, NULL_TREE, NULL_TREE); + } + if (!write_p && !useless_type_conversion_p (atype, m_limb_type)) + { + gimple *g = gimple_build_assign (make_ssa_name (m_limb_type), ret); + insert_before (g); + ret = gimple_assign_lhs (g); + ret = build1 (NOP_EXPR, atype, ret); + } + return ret; +} + +/* Emit code to access limb IDX from OP. */ + +tree +bitint_large_huge::handle_operand (tree op, tree idx) +{ + switch (TREE_CODE (op)) + { + case SSA_NAME: + if (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (op))) + { + if (gimple_code (SSA_NAME_DEF_STMT (op)) == GIMPLE_NOP) + { + if (m_first) + { + tree v = create_tmp_var (m_limb_type); + if (SSA_NAME_VAR (op) && VAR_P (SSA_NAME_VAR (op))) + { + DECL_NAME (v) = DECL_NAME (SSA_NAME_VAR (op)); + DECL_SOURCE_LOCATION (v) + = DECL_SOURCE_LOCATION (SSA_NAME_VAR (op)); + } + v = get_or_create_ssa_default_def (cfun, v); + m_data.safe_push (v); + } + tree ret = m_data[m_data_cnt]; + m_data_cnt++; + if (tree_fits_uhwi_p (idx)) + { + tree type = limb_access_type (TREE_TYPE (op), idx); + ret = add_cast (type, ret); + } + return ret; + } + location_t loc_save = m_loc; + m_loc = gimple_location (SSA_NAME_DEF_STMT (op)); + tree ret = handle_stmt (SSA_NAME_DEF_STMT (op), idx); + m_loc = loc_save; + return ret; + } + int p; + gimple *g; + tree t; + p = var_to_partition (m_map, op); + gcc_assert (m_vars[p] != NULL_TREE); + t = limb_access (TREE_TYPE (op), m_vars[p], idx, false); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t); + insert_before (g); + t = gimple_assign_lhs (g); + if (m_first + && m_single_use_names + && m_vars[p] != m_lhs + && m_after_stmt + && bitmap_bit_p (m_single_use_names, SSA_NAME_VERSION (op))) + { + tree clobber = build_clobber (TREE_TYPE (m_vars[p]), CLOBBER_EOL); + g = gimple_build_assign (m_vars[p], clobber); + gimple_stmt_iterator gsi = gsi_for_stmt (m_after_stmt); + gsi_insert_after (&gsi, g, GSI_SAME_STMT); + } + return t; + case INTEGER_CST: + if (tree_fits_uhwi_p (idx)) + { + tree c, type = limb_access_type (TREE_TYPE (op), idx); + unsigned HOST_WIDE_INT i = tree_to_uhwi (idx); + if (m_first) + { + m_data.safe_push (NULL_TREE); + m_data.safe_push (NULL_TREE); + } + if (limb_prec != HOST_BITS_PER_WIDE_INT) + { + wide_int w = wi::rshift (wi::to_wide (op), i * limb_prec, + TYPE_SIGN (TREE_TYPE (op))); + c = wide_int_to_tree (type, + wide_int::from (w, TYPE_PRECISION (type), + UNSIGNED)); + } + else if (i >= TREE_INT_CST_EXT_NUNITS (op)) + c = build_int_cst (type, + tree_int_cst_sgn (op) < 0 ? -1 : 0); + else + c = build_int_cst (type, TREE_INT_CST_ELT (op, i)); + m_data_cnt += 2; + return c; + } + if (m_first + || (m_data[m_data_cnt] == NULL_TREE + && m_data[m_data_cnt + 1] == NULL_TREE)) + { + unsigned int prec = TYPE_PRECISION (TREE_TYPE (op)); + unsigned int rem = prec % (2 * limb_prec); + int ext; + unsigned min_prec = bitint_min_cst_precision (op, ext); + if (m_first) + { + m_data.safe_push (NULL_TREE); + m_data.safe_push (NULL_TREE); + } + if (integer_zerop (op)) + { + tree c = build_zero_cst (m_limb_type); + m_data[m_data_cnt] = c; + m_data[m_data_cnt + 1] = c; + } + else if (integer_all_onesp (op)) + { + tree c = build_all_ones_cst (m_limb_type); + m_data[m_data_cnt] = c; + m_data[m_data_cnt + 1] = c; + } + else if (m_upwards_2limb && min_prec <= (unsigned) limb_prec) + { + /* Single limb constant. Use a phi with that limb from + the preheader edge and 0 or -1 constant from the other edge + and for the second limb in the loop. */ + tree out; + gcc_assert (m_first); + m_data.pop (); + m_data.pop (); + prepare_data_in_out (fold_convert (m_limb_type, op), idx, &out); + g = gimple_build_assign (m_data[m_data_cnt + 1], + build_int_cst (m_limb_type, ext)); + insert_before (g); + m_data[m_data_cnt + 1] = gimple_assign_rhs1 (g); + } + else if (min_prec > prec - rem - 2 * limb_prec) + { + /* Constant which has enough significant bits that it isn't + worth trying to save .rodata space by extending from smaller + number. */ + tree type; + if (m_var_msb) + type = TREE_TYPE (op); + else + /* If we have a guarantee the most significant partial limb + (if any) will be only accessed through handle_operand + with INTEGER_CST idx, we don't need to include the partial + limb in .rodata. */ + type = build_bitint_type (prec - rem, 1); + tree c = tree_output_constant_def (fold_convert (type, op)); + m_data[m_data_cnt] = c; + m_data[m_data_cnt + 1] = NULL_TREE; + } + else if (m_upwards_2limb) + { + /* Constant with smaller number of bits. Trade conditional + code for .rodata space by extending from smaller number. */ + min_prec = CEIL (min_prec, 2 * limb_prec) * (2 * limb_prec); + tree type = build_bitint_type (min_prec, 1); + tree c = tree_output_constant_def (fold_convert (type, op)); + tree idx2 = make_ssa_name (sizetype); + g = gimple_build_assign (idx2, PLUS_EXPR, idx, size_one_node); + insert_before (g); + g = gimple_build_cond (GE_EXPR, idx, + size_int (min_prec / limb_prec), + NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_TRUE_VALUE); + e3->probability = profile_probability::likely (); + if (min_prec >= (prec - rem) / 2) + e3->probability = e3->probability.invert (); + e1->flags = EDGE_FALSE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + tree c1 = limb_access (TREE_TYPE (op), c, idx, false); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (c1)), c1); + insert_before (g); + c1 = gimple_assign_lhs (g); + tree c2 = limb_access (TREE_TYPE (op), c, idx2, false); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (c2)), c2); + insert_before (g); + c2 = gimple_assign_lhs (g); + tree c3 = build_int_cst (m_limb_type, ext); + m_gsi = gsi_after_labels (e2->dest); + m_data[m_data_cnt] = make_ssa_name (m_limb_type); + m_data[m_data_cnt + 1] = make_ssa_name (m_limb_type); + gphi *phi = create_phi_node (m_data[m_data_cnt], e2->dest); + add_phi_arg (phi, c1, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, c3, e3, UNKNOWN_LOCATION); + phi = create_phi_node (m_data[m_data_cnt + 1], e2->dest); + add_phi_arg (phi, c2, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, c3, e3, UNKNOWN_LOCATION); + } + else + { + /* Constant with smaller number of bits. Trade conditional + code for .rodata space by extending from smaller number. + Version for loops with random access to the limbs or + downwards loops. */ + min_prec = CEIL (min_prec, limb_prec) * limb_prec; + tree c; + if (min_prec <= (unsigned) limb_prec) + c = fold_convert (m_limb_type, op); + else + { + tree type = build_bitint_type (min_prec, 1); + c = tree_output_constant_def (fold_convert (type, op)); + } + m_data[m_data_cnt] = c; + m_data[m_data_cnt + 1] = integer_type_node; + } + t = m_data[m_data_cnt]; + if (m_data[m_data_cnt + 1] == NULL_TREE) + { + t = limb_access (TREE_TYPE (op), t, idx, false); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t); + insert_before (g); + t = gimple_assign_lhs (g); + } + } + else if (m_data[m_data_cnt + 1] == NULL_TREE) + { + t = limb_access (TREE_TYPE (op), m_data[m_data_cnt], idx, false); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t); + insert_before (g); + t = gimple_assign_lhs (g); + } + else + t = m_data[m_data_cnt + 1]; + if (m_data[m_data_cnt + 1] == integer_type_node) + { + unsigned int prec = TYPE_PRECISION (TREE_TYPE (op)); + unsigned rem = prec % (2 * limb_prec); + int ext = tree_int_cst_sgn (op) < 0 ? -1 : 0; + tree c = m_data[m_data_cnt]; + unsigned min_prec = TYPE_PRECISION (TREE_TYPE (c)); + g = gimple_build_cond (GE_EXPR, idx, + size_int (min_prec / limb_prec), + NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_TRUE_VALUE); + e3->probability = profile_probability::likely (); + if (min_prec >= (prec - rem) / 2) + e3->probability = e3->probability.invert (); + e1->flags = EDGE_FALSE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + if (min_prec > (unsigned) limb_prec) + { + c = limb_access (TREE_TYPE (op), c, idx, false); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (c)), c); + insert_before (g); + c = gimple_assign_lhs (g); + } + tree c2 = build_int_cst (m_limb_type, ext); + m_gsi = gsi_after_labels (e2->dest); + t = make_ssa_name (m_limb_type); + gphi *phi = create_phi_node (t, e2->dest); + add_phi_arg (phi, c, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, c2, e3, UNKNOWN_LOCATION); + } + m_data_cnt += 2; + return t; + default: + gcc_unreachable (); + } +} + +/* Helper method, add a PHI node with VAL from preheader edge if + inside of a loop and m_first. Keep state in a pair of m_data + elements. */ + +tree +bitint_large_huge::prepare_data_in_out (tree val, tree idx, tree *data_out) +{ + if (!m_first) + { + *data_out = tree_fits_uhwi_p (idx) ? NULL_TREE : m_data[m_data_cnt + 1]; + return m_data[m_data_cnt]; + } + + *data_out = NULL_TREE; + if (tree_fits_uhwi_p (idx)) + { + m_data.safe_push (val); + m_data.safe_push (NULL_TREE); + return val; + } + + tree in = make_ssa_name (TREE_TYPE (val)); + gphi *phi = create_phi_node (in, m_bb); + edge e1 = find_edge (m_preheader_bb, m_bb); + edge e2 = EDGE_PRED (m_bb, 0); + if (e1 == e2) + e2 = EDGE_PRED (m_bb, 1); + add_phi_arg (phi, val, e1, UNKNOWN_LOCATION); + tree out = make_ssa_name (TREE_TYPE (val)); + add_phi_arg (phi, out, e2, UNKNOWN_LOCATION); + m_data.safe_push (in); + m_data.safe_push (out); + return in; +} + +/* Return VAL cast to TYPE. If VAL is INTEGER_CST, just + convert it without emitting any code, otherwise emit + the conversion statement before the current location. */ + +tree +bitint_large_huge::add_cast (tree type, tree val) +{ + if (TREE_CODE (val) == INTEGER_CST) + return fold_convert (type, val); + + tree lhs = make_ssa_name (type); + gimple *g = gimple_build_assign (lhs, NOP_EXPR, val); + insert_before (g); + return lhs; +} + +/* Helper of handle_stmt method, handle PLUS_EXPR or MINUS_EXPR. */ + +tree +bitint_large_huge::handle_plus_minus (tree_code code, tree rhs1, tree rhs2, + tree idx) +{ + tree lhs, data_out, ctype; + tree rhs1_type = TREE_TYPE (rhs1); + gimple *g; + tree data_in = prepare_data_in_out (build_zero_cst (m_limb_type), idx, + &data_out); + + if (optab_handler (code == PLUS_EXPR ? uaddc5_optab : usubc5_optab, + TYPE_MODE (m_limb_type)) != CODE_FOR_nothing) + { + ctype = build_complex_type (m_limb_type); + if (!types_compatible_p (rhs1_type, m_limb_type)) + { + if (!TYPE_UNSIGNED (rhs1_type)) + { + tree type = unsigned_type_for (rhs1_type); + rhs1 = add_cast (type, rhs1); + rhs2 = add_cast (type, rhs2); + } + rhs1 = add_cast (m_limb_type, rhs1); + rhs2 = add_cast (m_limb_type, rhs2); + } + lhs = make_ssa_name (ctype); + g = gimple_build_call_internal (code == PLUS_EXPR + ? IFN_UADDC : IFN_USUBC, + 3, rhs1, rhs2, data_in); + gimple_call_set_lhs (g, lhs); + insert_before (g); + if (data_out == NULL_TREE) + data_out = make_ssa_name (m_limb_type); + g = gimple_build_assign (data_out, IMAGPART_EXPR, + build1 (IMAGPART_EXPR, m_limb_type, lhs)); + insert_before (g); + } + else if (types_compatible_p (rhs1_type, m_limb_type)) + { + ctype = build_complex_type (m_limb_type); + lhs = make_ssa_name (ctype); + g = gimple_build_call_internal (code == PLUS_EXPR + ? IFN_ADD_OVERFLOW : IFN_SUB_OVERFLOW, + 2, rhs1, rhs2); + gimple_call_set_lhs (g, lhs); + insert_before (g); + if (data_out == NULL_TREE) + data_out = make_ssa_name (m_limb_type); + if (!integer_zerop (data_in)) + { + rhs1 = make_ssa_name (m_limb_type); + g = gimple_build_assign (rhs1, REALPART_EXPR, + build1 (REALPART_EXPR, m_limb_type, lhs)); + insert_before (g); + rhs2 = make_ssa_name (m_limb_type); + g = gimple_build_assign (rhs2, IMAGPART_EXPR, + build1 (IMAGPART_EXPR, m_limb_type, lhs)); + insert_before (g); + lhs = make_ssa_name (ctype); + g = gimple_build_call_internal (code == PLUS_EXPR + ? IFN_ADD_OVERFLOW + : IFN_SUB_OVERFLOW, + 2, rhs1, data_in); + gimple_call_set_lhs (g, lhs); + insert_before (g); + data_in = make_ssa_name (m_limb_type); + g = gimple_build_assign (data_in, IMAGPART_EXPR, + build1 (IMAGPART_EXPR, m_limb_type, lhs)); + insert_before (g); + g = gimple_build_assign (data_out, PLUS_EXPR, rhs2, data_in); + insert_before (g); + } + else + { + g = gimple_build_assign (data_out, IMAGPART_EXPR, + build1 (IMAGPART_EXPR, m_limb_type, lhs)); + insert_before (g); + } + } + else + { + tree in = add_cast (rhs1_type, data_in); + lhs = make_ssa_name (rhs1_type); + g = gimple_build_assign (lhs, code, rhs1, rhs2); + insert_before (g); + rhs1 = make_ssa_name (rhs1_type); + g = gimple_build_assign (rhs1, code, lhs, in); + insert_before (g); + m_data[m_data_cnt] = NULL_TREE; + m_data_cnt += 2; + return rhs1; + } + rhs1 = make_ssa_name (m_limb_type); + g = gimple_build_assign (rhs1, REALPART_EXPR, + build1 (REALPART_EXPR, m_limb_type, lhs)); + insert_before (g); + if (!types_compatible_p (rhs1_type, m_limb_type)) + rhs1 = add_cast (rhs1_type, rhs1); + m_data[m_data_cnt] = data_out; + m_data_cnt += 2; + return rhs1; +} + +/* Helper function for handle_stmt method, handle LSHIFT_EXPR by + count in [0, limb_prec - 1] range. */ + +tree +bitint_large_huge::handle_lshift (tree rhs1, tree rhs2, tree idx) +{ + unsigned HOST_WIDE_INT cnt = tree_to_uhwi (rhs2); + gcc_checking_assert (cnt < (unsigned) limb_prec); + if (cnt == 0) + return rhs1; + + tree lhs, data_out, rhs1_type = TREE_TYPE (rhs1); + gimple *g; + tree data_in = prepare_data_in_out (build_zero_cst (m_limb_type), idx, + &data_out); + + if (!integer_zerop (data_in)) + { + lhs = make_ssa_name (m_limb_type); + g = gimple_build_assign (lhs, RSHIFT_EXPR, data_in, + build_int_cst (unsigned_type_node, + limb_prec - cnt)); + insert_before (g); + if (!types_compatible_p (rhs1_type, m_limb_type)) + lhs = add_cast (rhs1_type, lhs); + data_in = lhs; + } + if (types_compatible_p (rhs1_type, m_limb_type)) + { + if (data_out == NULL_TREE) + data_out = make_ssa_name (m_limb_type); + g = gimple_build_assign (data_out, rhs1); + insert_before (g); + } + if (cnt < (unsigned) TYPE_PRECISION (rhs1_type)) + { + lhs = make_ssa_name (rhs1_type); + g = gimple_build_assign (lhs, LSHIFT_EXPR, rhs1, rhs2); + insert_before (g); + if (!integer_zerop (data_in)) + { + rhs1 = lhs; + lhs = make_ssa_name (rhs1_type); + g = gimple_build_assign (lhs, BIT_IOR_EXPR, rhs1, data_in); + insert_before (g); + } + } + else + lhs = data_in; + m_data[m_data_cnt] = data_out; + m_data_cnt += 2; + return lhs; +} + +/* Helper function for handle_stmt method, handle an integral + to integral conversion. */ + +tree +bitint_large_huge::handle_cast (tree lhs_type, tree rhs1, tree idx) +{ + tree rhs_type = TREE_TYPE (rhs1); + gimple *g; + if (TREE_CODE (rhs1) == SSA_NAME + && TREE_CODE (lhs_type) == BITINT_TYPE + && TREE_CODE (rhs_type) == BITINT_TYPE + && bitint_precision_kind (lhs_type) >= bitint_prec_large + && bitint_precision_kind (rhs_type) >= bitint_prec_large) + { + if (TYPE_PRECISION (rhs_type) >= TYPE_PRECISION (lhs_type) + /* If lhs has bigger precision than rhs, we can use + the simple case only if there is a guarantee that + the most significant limb is handled in straight + line code. If m_var_msb (on left shifts) or + if m_upwards_2limb * limb_prec is equal to + lhs precision that is not the case. */ + || (!m_var_msb + && tree_int_cst_equal (TYPE_SIZE (rhs_type), + TYPE_SIZE (lhs_type)) + && (!m_upwards_2limb + || (m_upwards_2limb * limb_prec + < TYPE_PRECISION (lhs_type))))) + { + rhs1 = handle_operand (rhs1, idx); + if (tree_fits_uhwi_p (idx)) + { + tree type = limb_access_type (lhs_type, idx); + if (!types_compatible_p (type, TREE_TYPE (rhs1))) + rhs1 = add_cast (type, rhs1); + } + return rhs1; + } + tree t; + /* Indexes lower than this don't need any special processing. */ + unsigned low = ((unsigned) TYPE_PRECISION (rhs_type) + - !TYPE_UNSIGNED (rhs_type)) / limb_prec; + /* Indexes >= than this always contain an extension. */ + unsigned high = CEIL ((unsigned) TYPE_PRECISION (rhs_type), limb_prec); + bool save_first = m_first; + if (m_first) + { + m_data.safe_push (NULL_TREE); + m_data.safe_push (NULL_TREE); + m_data.safe_push (NULL_TREE); + if (TYPE_UNSIGNED (rhs_type)) + /* No need to keep state between iterations. */ + ; + else if (!m_upwards_2limb) + { + unsigned save_data_cnt = m_data_cnt; + gimple_stmt_iterator save_gsi = m_gsi; + m_gsi = m_init_gsi; + if (gsi_end_p (m_gsi)) + m_gsi = gsi_after_labels (gsi_bb (m_gsi)); + else + gsi_next (&m_gsi); + m_data_cnt = save_data_cnt + 3; + t = handle_operand (rhs1, size_int (low)); + m_first = false; + m_data[save_data_cnt + 2] + = build_int_cst (NULL_TREE, m_data_cnt); + m_data_cnt = save_data_cnt; + t = add_cast (signed_type_for (m_limb_type), t); + tree lpm1 = build_int_cst (unsigned_type_node, limb_prec - 1); + tree n = make_ssa_name (TREE_TYPE (t)); + g = gimple_build_assign (n, RSHIFT_EXPR, t, lpm1); + insert_before (g); + m_data[save_data_cnt + 1] = add_cast (m_limb_type, n); + m_gsi = save_gsi; + } + else if (m_upwards_2limb * limb_prec < TYPE_PRECISION (rhs_type)) + /* We need to keep state between iterations, but + fortunately not within the loop, only afterwards. */ + ; + else + { + tree out; + m_data.truncate (m_data_cnt); + prepare_data_in_out (build_zero_cst (m_limb_type), idx, &out); + m_data.safe_push (NULL_TREE); + } + } + + unsigned save_data_cnt = m_data_cnt; + m_data_cnt += 3; + if (!tree_fits_uhwi_p (idx)) + { + if (m_upwards_2limb + && (m_upwards_2limb * limb_prec + <= ((unsigned) TYPE_PRECISION (rhs_type) + - !TYPE_UNSIGNED (rhs_type)))) + { + rhs1 = handle_operand (rhs1, idx); + if (m_first) + m_data[save_data_cnt + 2] + = build_int_cst (NULL_TREE, m_data_cnt); + m_first = save_first; + return rhs1; + } + bool single_comparison + = low == high || (m_upwards_2limb && (low & 1) == m_first); + g = gimple_build_cond (single_comparison ? LT_EXPR : LE_EXPR, + idx, size_int (low), NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + edge e4 = NULL; + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + if (!single_comparison) + { + m_gsi = gsi_after_labels (e1->dest); + g = gimple_build_cond (EQ_EXPR, idx, size_int (low), + NULL_TREE, NULL_TREE); + insert_before (g); + e2 = split_block (gsi_bb (m_gsi), g); + basic_block bb = create_empty_bb (e2->dest); + add_bb_to_loop (bb, e2->dest->loop_father); + e4 = make_edge (e2->src, bb, EDGE_TRUE_VALUE); + set_immediate_dominator (CDI_DOMINATORS, bb, e2->src); + e4->probability = profile_probability::unlikely (); + e2->flags = EDGE_FALSE_VALUE; + e2->probability = e4->probability.invert (); + e4 = make_edge (bb, e3->dest, EDGE_FALLTHRU); + e2 = find_edge (e2->dest, e3->dest); + } + m_gsi = gsi_after_labels (e2->src); + tree t1 = handle_operand (rhs1, idx), t2 = NULL_TREE; + if (m_first) + m_data[save_data_cnt + 2] + = build_int_cst (NULL_TREE, m_data_cnt); + tree ext = NULL_TREE; + if (!single_comparison) + { + m_gsi = gsi_after_labels (e4->src); + m_first = false; + m_data_cnt = save_data_cnt + 3; + t2 = handle_operand (rhs1, size_int (low)); + if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (t2))) + t2 = add_cast (m_limb_type, t2); + if (!TYPE_UNSIGNED (rhs_type) && m_upwards_2limb) + { + ext = add_cast (signed_type_for (m_limb_type), t2); + tree lpm1 = build_int_cst (unsigned_type_node, + limb_prec - 1); + tree n = make_ssa_name (TREE_TYPE (ext)); + g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1); + insert_before (g); + ext = add_cast (m_limb_type, n); + } + } + tree t3; + if (TYPE_UNSIGNED (rhs_type)) + t3 = build_zero_cst (m_limb_type); + else if (m_upwards_2limb && (save_first || ext != NULL_TREE)) + t3 = m_data[save_data_cnt]; + else + t3 = m_data[save_data_cnt + 1]; + m_gsi = gsi_after_labels (e2->dest); + t = make_ssa_name (m_limb_type); + gphi *phi = create_phi_node (t, e2->dest); + add_phi_arg (phi, t1, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, t3, e3, UNKNOWN_LOCATION); + if (e4) + add_phi_arg (phi, t2, e4, UNKNOWN_LOCATION); + if (ext) + { + tree t4 = make_ssa_name (m_limb_type); + phi = create_phi_node (t4, e2->dest); + add_phi_arg (phi, build_zero_cst (m_limb_type), e2, + UNKNOWN_LOCATION); + add_phi_arg (phi, m_data[save_data_cnt], e3, UNKNOWN_LOCATION); + add_phi_arg (phi, ext, e4, UNKNOWN_LOCATION); + g = gimple_build_assign (m_data[save_data_cnt + 1], t4); + insert_before (g); + } + m_first = save_first; + return t; + } + else + { + if (tree_to_uhwi (idx) < low) + { + t = handle_operand (rhs1, idx); + if (m_first) + m_data[save_data_cnt + 2] + = build_int_cst (NULL_TREE, m_data_cnt); + } + else if (tree_to_uhwi (idx) < high) + { + t = handle_operand (rhs1, size_int (low)); + if (m_first) + m_data[save_data_cnt + 2] + = build_int_cst (NULL_TREE, m_data_cnt); + if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (t))) + t = add_cast (m_limb_type, t); + tree ext = NULL_TREE; + if (!TYPE_UNSIGNED (rhs_type) && m_upwards_2limb) + { + ext = add_cast (signed_type_for (m_limb_type), t); + tree lpm1 = build_int_cst (unsigned_type_node, + limb_prec - 1); + tree n = make_ssa_name (TREE_TYPE (ext)); + g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1); + insert_before (g); + ext = add_cast (m_limb_type, n); + m_data[save_data_cnt + 1] = ext; + } + } + else + { + if (TYPE_UNSIGNED (rhs_type) && m_first) + { + handle_operand (rhs1, size_zero_node); + m_data[save_data_cnt + 2] + = build_int_cst (NULL_TREE, m_data_cnt); + } + else + m_data_cnt = tree_to_uhwi (m_data[save_data_cnt + 2]); + if (TYPE_UNSIGNED (rhs_type)) + t = build_zero_cst (m_limb_type); + else + t = m_data[save_data_cnt + 1]; + } + tree type = limb_access_type (lhs_type, idx); + if (!useless_type_conversion_p (type, m_limb_type)) + t = add_cast (type, t); + m_first = save_first; + return t; + } + } + else if (TREE_CODE (lhs_type) == BITINT_TYPE + && bitint_precision_kind (lhs_type) >= bitint_prec_large + && INTEGRAL_TYPE_P (rhs_type)) + { + /* Add support for 3 or more limbs filled in from normal integral + type if this assert fails. If no target chooses limb mode smaller + than half of largest supported normal integral type, this will not + be needed. */ + gcc_assert (TYPE_PRECISION (rhs_type) <= 2 * limb_prec); + tree r1 = NULL_TREE, r2 = NULL_TREE, rext = NULL_TREE; + if (m_first) + { + gimple_stmt_iterator save_gsi = m_gsi; + m_gsi = m_init_gsi; + if (gsi_end_p (m_gsi)) + m_gsi = gsi_after_labels (gsi_bb (m_gsi)); + else + gsi_next (&m_gsi); + if (TREE_CODE (rhs_type) == BITINT_TYPE + && bitint_precision_kind (rhs_type) == bitint_prec_middle) + { + tree type = NULL_TREE; + rhs1 = maybe_cast_middle_bitint (&m_gsi, rhs1, type); + rhs_type = TREE_TYPE (rhs1); + } + r1 = rhs1; + if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1))) + r1 = add_cast (m_limb_type, rhs1); + if (TYPE_PRECISION (rhs_type) > limb_prec) + { + g = gimple_build_assign (make_ssa_name (rhs_type), + RSHIFT_EXPR, rhs1, + build_int_cst (unsigned_type_node, + limb_prec)); + insert_before (g); + r2 = add_cast (m_limb_type, gimple_assign_lhs (g)); + } + if (TYPE_UNSIGNED (rhs_type)) + rext = build_zero_cst (m_limb_type); + else + { + rext = add_cast (signed_type_for (m_limb_type), r2 ? r2 : r1); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (rext)), + RSHIFT_EXPR, rext, + build_int_cst (unsigned_type_node, + limb_prec - 1)); + insert_before (g); + rext = add_cast (m_limb_type, gimple_assign_lhs (g)); + } + m_gsi = save_gsi; + } + tree t; + if (m_upwards_2limb) + { + if (m_first) + { + tree out1, out2; + prepare_data_in_out (r1, idx, &out1); + g = gimple_build_assign (m_data[m_data_cnt + 1], rext); + insert_before (g); + if (TYPE_PRECISION (rhs_type) > limb_prec) + { + prepare_data_in_out (r2, idx, &out2); + g = gimple_build_assign (m_data[m_data_cnt + 3], rext); + insert_before (g); + m_data.pop (); + t = m_data.pop (); + m_data[m_data_cnt + 1] = t; + } + else + m_data[m_data_cnt + 1] = rext; + m_data.safe_push (rext); + t = m_data[m_data_cnt]; + } + else if (!tree_fits_uhwi_p (idx)) + t = m_data[m_data_cnt + 1]; + else + { + tree type = limb_access_type (lhs_type, idx); + t = m_data[m_data_cnt + 2]; + if (!useless_type_conversion_p (type, m_limb_type)) + t = add_cast (type, t); + } + m_data_cnt += 3; + return t; + } + else if (m_first) + { + m_data.safe_push (r1); + m_data.safe_push (r2); + m_data.safe_push (rext); + } + if (tree_fits_uhwi_p (idx)) + { + tree type = limb_access_type (lhs_type, idx); + if (integer_zerop (idx)) + t = m_data[m_data_cnt]; + else if (TYPE_PRECISION (rhs_type) > limb_prec + && integer_onep (idx)) + t = m_data[m_data_cnt + 1]; + else + t = m_data[m_data_cnt + 2]; + if (!useless_type_conversion_p (type, m_limb_type)) + t = add_cast (type, t); + m_data_cnt += 3; + return t; + } + g = gimple_build_cond (EQ_EXPR, idx, size_zero_node, + NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_TRUE_VALUE); + edge e4 = NULL; + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_FALSE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + if (m_data[m_data_cnt + 1]) + { + m_gsi = gsi_after_labels (e1->dest); + g = gimple_build_cond (EQ_EXPR, idx, size_one_node, + NULL_TREE, NULL_TREE); + insert_before (g); + edge e5 = split_block (gsi_bb (m_gsi), g); + e4 = make_edge (e5->src, e2->dest, EDGE_TRUE_VALUE); + e2 = find_edge (e5->dest, e2->dest); + e4->probability = profile_probability::unlikely (); + e5->flags = EDGE_FALSE_VALUE; + e5->probability = e4->probability.invert (); + } + m_gsi = gsi_after_labels (e2->dest); + t = make_ssa_name (m_limb_type); + gphi *phi = create_phi_node (t, e2->dest); + add_phi_arg (phi, m_data[m_data_cnt + 2], e2, UNKNOWN_LOCATION); + add_phi_arg (phi, m_data[m_data_cnt], e3, UNKNOWN_LOCATION); + if (e4) + add_phi_arg (phi, m_data[m_data_cnt + 1], e4, UNKNOWN_LOCATION); + m_data_cnt += 3; + return t; + } + return NULL_TREE; +} + +/* Return a limb IDX from a mergeable statement STMT. */ + +tree +bitint_large_huge::handle_stmt (gimple *stmt, tree idx) +{ + tree lhs, rhs1, rhs2 = NULL_TREE; + gimple *g; + switch (gimple_code (stmt)) + { + case GIMPLE_ASSIGN: + if (gimple_assign_load_p (stmt)) + { + rhs1 = gimple_assign_rhs1 (stmt); + tree rhs_type = TREE_TYPE (rhs1); + bool eh = stmt_ends_bb_p (stmt); + /* Use write_p = true for loads with EH edges to make + sure limb_access doesn't add a cast as separate + statement after it. */ + rhs1 = limb_access (rhs_type, rhs1, idx, eh); + lhs = make_ssa_name (TREE_TYPE (rhs1)); + g = gimple_build_assign (lhs, rhs1); + insert_before (g); + if (eh) + { + maybe_duplicate_eh_stmt (g, stmt); + edge e1; + edge_iterator ei; + basic_block bb = gimple_bb (stmt); + + FOR_EACH_EDGE (e1, ei, bb->succs) + if (e1->flags & EDGE_EH) + break; + if (e1) + { + edge e2 = split_block (gsi_bb (m_gsi), g); + m_gsi = gsi_after_labels (e2->dest); + make_edge (e2->src, e1->dest, EDGE_EH)->probability + = profile_probability::very_unlikely (); + } + if (tree_fits_uhwi_p (idx)) + { + tree atype = limb_access_type (rhs_type, idx); + if (!useless_type_conversion_p (atype, TREE_TYPE (rhs1))) + lhs = add_cast (atype, lhs); + } + } + return lhs; + } + switch (gimple_assign_rhs_code (stmt)) + { + case BIT_AND_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + rhs2 = handle_operand (gimple_assign_rhs2 (stmt), idx); + /* FALLTHRU */ + case BIT_NOT_EXPR: + rhs1 = handle_operand (gimple_assign_rhs1 (stmt), idx); + lhs = make_ssa_name (TREE_TYPE (rhs1)); + g = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt), + rhs1, rhs2); + insert_before (g); + return lhs; + case PLUS_EXPR: + case MINUS_EXPR: + rhs1 = handle_operand (gimple_assign_rhs1 (stmt), idx); + rhs2 = handle_operand (gimple_assign_rhs2 (stmt), idx); + return handle_plus_minus (gimple_assign_rhs_code (stmt), + rhs1, rhs2, idx); + case NEGATE_EXPR: + rhs2 = handle_operand (gimple_assign_rhs1 (stmt), idx); + rhs1 = build_zero_cst (TREE_TYPE (rhs2)); + return handle_plus_minus (MINUS_EXPR, rhs1, rhs2, idx); + case LSHIFT_EXPR: + return handle_lshift (handle_operand (gimple_assign_rhs1 (stmt), + idx), + gimple_assign_rhs2 (stmt), idx); + case SSA_NAME: + case INTEGER_CST: + return handle_operand (gimple_assign_rhs1 (stmt), idx); + CASE_CONVERT: + case VIEW_CONVERT_EXPR: + return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)), + gimple_assign_rhs1 (stmt), idx); + default: + break; + } + break; + default: + break; + } + gcc_unreachable (); +} + +/* Return minimum precision of OP at STMT. + Positive value is minimum precision above which all bits + are zero, negative means all bits above negation of the + value are copies of the sign bit. */ + +static int +range_to_prec (tree op, gimple *stmt) +{ + int_range_max r; + wide_int w; + tree type = TREE_TYPE (op); + unsigned int prec = TYPE_PRECISION (type); + + if (!optimize + || !get_range_query (cfun)->range_of_expr (r, op, stmt)) + { + if (TYPE_UNSIGNED (type)) + return prec; + else + return -prec; + } + + if (!TYPE_UNSIGNED (TREE_TYPE (op))) + { + w = r.lower_bound (); + if (wi::neg_p (w)) + { + int min_prec1 = wi::min_precision (w, SIGNED); + w = r.upper_bound (); + int min_prec2 = wi::min_precision (w, SIGNED); + int min_prec = MAX (min_prec1, min_prec2); + return MIN (-min_prec, -2); + } + } + + w = r.upper_bound (); + int min_prec = wi::min_precision (w, UNSIGNED); + return MAX (min_prec, 1); +} + +/* Return address of the first limb of OP and write into *PREC + its precision. If positive, the operand is zero extended + from that precision, if it is negative, the operand is sign-extended + from -*PREC. If PREC_STORED is NULL, it is the toplevel call, + otherwise *PREC_STORED is prec from the innermost call without + range optimizations. */ + +tree +bitint_large_huge::handle_operand_addr (tree op, gimple *stmt, + int *prec_stored, int *prec) +{ + wide_int w; + location_t loc_save = m_loc; + if ((TREE_CODE (TREE_TYPE (op)) != BITINT_TYPE + || bitint_precision_kind (TREE_TYPE (op)) < bitint_prec_large) + && TREE_CODE (op) != INTEGER_CST) + { + do_int: + *prec = range_to_prec (op, stmt); + bitint_prec_kind kind = bitint_prec_small; + gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (op))); + if (TREE_CODE (TREE_TYPE (op)) == BITINT_TYPE) + kind = bitint_precision_kind (TREE_TYPE (op)); + if (kind == bitint_prec_middle) + { + tree type = NULL_TREE; + op = maybe_cast_middle_bitint (&m_gsi, op, type); + } + tree op_type = TREE_TYPE (op); + unsigned HOST_WIDE_INT nelts + = CEIL (TYPE_PRECISION (op_type), limb_prec); + /* Add support for 3 or more limbs filled in from normal + integral type if this assert fails. If no target chooses + limb mode smaller than half of largest supported normal + integral type, this will not be needed. */ + gcc_assert (nelts <= 2); + if (prec_stored) + *prec_stored = (TYPE_UNSIGNED (op_type) + ? TYPE_PRECISION (op_type) + : -TYPE_PRECISION (op_type)); + if (*prec <= limb_prec && *prec >= -limb_prec) + { + nelts = 1; + if (prec_stored) + { + if (TYPE_UNSIGNED (op_type)) + { + if (*prec_stored > limb_prec) + *prec_stored = limb_prec; + } + else if (*prec_stored < -limb_prec) + *prec_stored = -limb_prec; + } + } + tree atype = build_array_type_nelts (m_limb_type, nelts); + tree var = create_tmp_var (atype); + tree t1 = op; + if (!useless_type_conversion_p (m_limb_type, op_type)) + t1 = add_cast (m_limb_type, t1); + tree v = build4 (ARRAY_REF, m_limb_type, var, size_zero_node, + NULL_TREE, NULL_TREE); + gimple *g = gimple_build_assign (v, t1); + insert_before (g); + if (nelts > 1) + { + tree lp = build_int_cst (unsigned_type_node, limb_prec); + g = gimple_build_assign (make_ssa_name (op_type), + RSHIFT_EXPR, op, lp); + insert_before (g); + tree t2 = gimple_assign_lhs (g); + t2 = add_cast (m_limb_type, t2); + v = build4 (ARRAY_REF, m_limb_type, var, size_one_node, + NULL_TREE, NULL_TREE); + g = gimple_build_assign (v, t2); + insert_before (g); + } + tree ret = build_fold_addr_expr (var); + if (!stmt_ends_bb_p (gsi_stmt (m_gsi))) + { + tree clobber = build_clobber (atype, CLOBBER_EOL); + g = gimple_build_assign (var, clobber); + gsi_insert_after (&m_gsi, g, GSI_SAME_STMT); + } + m_loc = loc_save; + return ret; + } + switch (TREE_CODE (op)) + { + case SSA_NAME: + if (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (op))) + { + gimple *g = SSA_NAME_DEF_STMT (op); + tree ret; + m_loc = gimple_location (g); + if (gimple_assign_load_p (g)) + { + *prec = range_to_prec (op, NULL); + if (prec_stored) + *prec_stored = (TYPE_UNSIGNED (TREE_TYPE (op)) + ? TYPE_PRECISION (TREE_TYPE (op)) + : -TYPE_PRECISION (TREE_TYPE (op))); + ret = build_fold_addr_expr (gimple_assign_rhs1 (g)); + ret = force_gimple_operand_gsi (&m_gsi, ret, true, + NULL_TREE, true, GSI_SAME_STMT); + } + else if (gimple_code (g) == GIMPLE_NOP) + { + tree var = create_tmp_var (m_limb_type); + TREE_ADDRESSABLE (var) = 1; + ret = build_fold_addr_expr (var); + if (!stmt_ends_bb_p (gsi_stmt (m_gsi))) + { + tree clobber = build_clobber (m_limb_type, CLOBBER_EOL); + g = gimple_build_assign (var, clobber); + gsi_insert_after (&m_gsi, g, GSI_SAME_STMT); + } + } + else + { + gcc_assert (gimple_assign_cast_p (g)); + tree rhs1 = gimple_assign_rhs1 (g); + bitint_prec_kind kind = bitint_prec_small; + gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))); + if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE) + kind = bitint_precision_kind (TREE_TYPE (rhs1)); + if (kind >= bitint_prec_large) + { + tree lhs_type = TREE_TYPE (op); + tree rhs_type = TREE_TYPE (rhs1); + int prec_stored_val = 0; + ret = handle_operand_addr (rhs1, g, &prec_stored_val, prec); + if (TYPE_PRECISION (lhs_type) > TYPE_PRECISION (rhs_type)) + { + if (TYPE_UNSIGNED (lhs_type) + && !TYPE_UNSIGNED (rhs_type)) + gcc_assert (*prec >= 0 || prec_stored == NULL); + } + else + { + if (*prec > 0 && *prec < TYPE_PRECISION (lhs_type)) + ; + else if (TYPE_UNSIGNED (lhs_type)) + { + gcc_assert (*prec > 0 + || prec_stored_val > 0 + || (-prec_stored_val + >= TYPE_PRECISION (lhs_type))); + *prec = TYPE_PRECISION (lhs_type); + } + else if (*prec < 0 && -*prec < TYPE_PRECISION (lhs_type)) + ; + else + *prec = -TYPE_PRECISION (lhs_type); + } + } + else + { + op = rhs1; + stmt = g; + goto do_int; + } + } + m_loc = loc_save; + return ret; + } + else + { + int p = var_to_partition (m_map, op); + gcc_assert (m_vars[p] != NULL_TREE); + *prec = range_to_prec (op, stmt); + if (prec_stored) + *prec_stored = (TYPE_UNSIGNED (TREE_TYPE (op)) + ? TYPE_PRECISION (TREE_TYPE (op)) + : -TYPE_PRECISION (TREE_TYPE (op))); + return build_fold_addr_expr (m_vars[p]); + } + case INTEGER_CST: + unsigned int min_prec, mp; + tree type; + w = wi::to_wide (op); + if (tree_int_cst_sgn (op) >= 0) + { + min_prec = wi::min_precision (w, UNSIGNED); + *prec = MAX (min_prec, 1); + } + else + { + min_prec = wi::min_precision (w, SIGNED); + *prec = MIN ((int) -min_prec, -2); + } + mp = CEIL (min_prec, limb_prec) * limb_prec; + if (mp >= (unsigned) TYPE_PRECISION (TREE_TYPE (op))) + type = TREE_TYPE (op); + else + type = build_bitint_type (mp, 1); + if (TREE_CODE (type) != BITINT_TYPE + || bitint_precision_kind (type) == bitint_prec_small) + { + if (TYPE_PRECISION (type) <= limb_prec) + type = m_limb_type; + else + /* This case is for targets which e.g. have 64-bit + limb but categorize up to 128-bits _BitInts as + small. We could use type of m_limb_type[2] and + similar instead to save space. */ + type = build_bitint_type (mid_min_prec, 1); + } + if (prec_stored) + { + if (tree_int_cst_sgn (op) >= 0) + *prec_stored = MAX (TYPE_PRECISION (type), 1); + else + *prec_stored = MIN ((int) -TYPE_PRECISION (type), -2); + } + op = tree_output_constant_def (fold_convert (type, op)); + return build_fold_addr_expr (op); + default: + gcc_unreachable (); + } +} + +/* Helper function, create a loop before the current location, + start with sizetype INIT value from the preheader edge. Return + a PHI result and set *IDX_NEXT to SSA_NAME it creates and uses + from the latch edge. */ + +tree +bitint_large_huge::create_loop (tree init, tree *idx_next) +{ + if (!gsi_end_p (m_gsi)) + gsi_prev (&m_gsi); + else + m_gsi = gsi_last_bb (gsi_bb (m_gsi)); + edge e1 = split_block (gsi_bb (m_gsi), gsi_stmt (m_gsi)); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->dest, e1->dest, EDGE_TRUE_VALUE); + e3->probability = profile_probability::very_unlikely (); + e2->flags = EDGE_FALSE_VALUE; + e2->probability = e3->probability.invert (); + tree idx = make_ssa_name (sizetype); + gphi *phi = create_phi_node (idx, e1->dest); + add_phi_arg (phi, init, e1, UNKNOWN_LOCATION); + *idx_next = make_ssa_name (sizetype); + add_phi_arg (phi, *idx_next, e3, UNKNOWN_LOCATION); + m_gsi = gsi_after_labels (e1->dest); + m_bb = e1->dest; + m_preheader_bb = e1->src; + class loop *loop = alloc_loop (); + loop->header = e1->dest; + add_loop (loop, e1->src->loop_father); + return idx; +} + +/* Lower large/huge _BitInt statement mergeable or similar STMT which can be + lowered using iteration from the least significant limb up to the most + significant limb. For large _BitInt it is emitted as straight line code + before current location, for huge _BitInt as a loop handling two limbs + at once, followed by handling up to limbs in straight line code (at most + one full and one partial limb). It can also handle EQ_EXPR/NE_EXPR + comparisons, in that case CMP_CODE should be the comparison code and + CMP_OP1/CMP_OP2 the comparison operands. */ + +tree +bitint_large_huge::lower_mergeable_stmt (gimple *stmt, tree_code &cmp_code, + tree cmp_op1, tree cmp_op2) +{ + bool eq_p = cmp_code != ERROR_MARK; + tree type; + if (eq_p) + type = TREE_TYPE (cmp_op1); + else + type = TREE_TYPE (gimple_assign_lhs (stmt)); + gcc_assert (TREE_CODE (type) == BITINT_TYPE); + bitint_prec_kind kind = bitint_precision_kind (type); + gcc_assert (kind >= bitint_prec_large); + gimple *g; + tree lhs = gimple_get_lhs (stmt); + tree rhs1, lhs_type = lhs ? TREE_TYPE (lhs) : NULL_TREE; + if (lhs + && TREE_CODE (lhs) == SSA_NAME + && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large) + { + int p = var_to_partition (m_map, lhs); + gcc_assert (m_vars[p] != NULL_TREE); + m_lhs = lhs = m_vars[p]; + } + unsigned cnt, rem = 0, end = 0, prec = TYPE_PRECISION (type); + bool sext = false; + tree ext = NULL_TREE, store_operand = NULL_TREE; + bool eh = false; + basic_block eh_pad = NULL; + if (gimple_store_p (stmt)) + { + store_operand = gimple_assign_rhs1 (stmt); + eh = stmt_ends_bb_p (stmt); + if (eh) + { + edge e; + edge_iterator ei; + basic_block bb = gimple_bb (stmt); + + FOR_EACH_EDGE (e, ei, bb->succs) + if (e->flags & EDGE_EH) + { + eh_pad = e->dest; + break; + } + } + } + if ((store_operand + && TREE_CODE (store_operand) == SSA_NAME + && (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (store_operand))) + && gimple_assign_cast_p (SSA_NAME_DEF_STMT (store_operand))) + || gimple_assign_cast_p (stmt)) + { + rhs1 = gimple_assign_rhs1 (store_operand + ? SSA_NAME_DEF_STMT (store_operand) + : stmt); + /* Optimize mergeable ops ending with widening cast to _BitInt + (or followed by store). We can lower just the limbs of the + cast operand and widen afterwards. */ + if (TREE_CODE (rhs1) == SSA_NAME + && (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))) + && TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large + && (CEIL ((unsigned) TYPE_PRECISION (TREE_TYPE (rhs1)), + limb_prec) < CEIL (prec, limb_prec) + || (kind == bitint_prec_huge + && TYPE_PRECISION (TREE_TYPE (rhs1)) < prec))) + { + store_operand = rhs1; + prec = TYPE_PRECISION (TREE_TYPE (rhs1)); + kind = bitint_precision_kind (TREE_TYPE (rhs1)); + if (!TYPE_UNSIGNED (TREE_TYPE (rhs1))) + sext = true; + } + } + tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE; + if (kind == bitint_prec_large) + cnt = CEIL (prec, limb_prec); + else + { + rem = (prec % (2 * limb_prec)); + end = (prec - rem) / limb_prec; + cnt = 2 + CEIL (rem, limb_prec); + idx = idx_first = create_loop (size_zero_node, &idx_next); + } + + basic_block edge_bb = NULL; + if (eq_p) + { + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + gsi_prev (&gsi); + edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); + edge_bb = e->src; + if (kind == bitint_prec_large) + { + m_gsi = gsi_last_bb (edge_bb); + if (!gsi_end_p (m_gsi)) + gsi_next (&m_gsi); + } + } + else + m_after_stmt = stmt; + if (kind != bitint_prec_large) + m_upwards_2limb = end; + + for (unsigned i = 0; i < cnt; i++) + { + m_data_cnt = 0; + if (kind == bitint_prec_large) + idx = size_int (i); + else if (i >= 2) + idx = size_int (end + (i > 2)); + if (eq_p) + { + rhs1 = handle_operand (cmp_op1, idx); + tree rhs2 = handle_operand (cmp_op2, idx); + g = gimple_build_cond (NE_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + e1->flags = EDGE_FALSE_VALUE; + edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE); + e1->probability = profile_probability::unlikely (); + e2->probability = e1->probability.invert (); + if (i == 0) + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src); + m_gsi = gsi_after_labels (e1->dest); + } + else + { + if (store_operand) + rhs1 = handle_operand (store_operand, idx); + else + rhs1 = handle_stmt (stmt, idx); + tree l = limb_access (lhs_type, lhs, idx, true); + if (!useless_type_conversion_p (TREE_TYPE (l), TREE_TYPE (rhs1))) + rhs1 = add_cast (TREE_TYPE (l), rhs1); + if (sext && i == cnt - 1) + ext = rhs1; + g = gimple_build_assign (l, rhs1); + insert_before (g); + if (eh) + { + maybe_duplicate_eh_stmt (g, stmt); + if (eh_pad) + { + edge e = split_block (gsi_bb (m_gsi), g); + m_gsi = gsi_after_labels (e->dest); + make_edge (e->src, eh_pad, EDGE_EH)->probability + = profile_probability::very_unlikely (); + } + } + } + m_first = false; + if (kind == bitint_prec_huge && i <= 1) + { + if (i == 0) + { + idx = make_ssa_name (sizetype); + g = gimple_build_assign (idx, PLUS_EXPR, idx_first, + size_one_node); + insert_before (g); + } + else + { + g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first, + size_int (2)); + insert_before (g); + g = gimple_build_cond (NE_EXPR, idx_next, size_int (end), + NULL_TREE, NULL_TREE); + insert_before (g); + if (eq_p) + m_gsi = gsi_after_labels (edge_bb); + else + m_gsi = gsi_for_stmt (stmt); + } + } + } + + if (prec != (unsigned) TYPE_PRECISION (type) + && (CEIL ((unsigned) TYPE_PRECISION (type), limb_prec) + > CEIL (prec, limb_prec))) + { + if (sext) + { + ext = add_cast (signed_type_for (m_limb_type), ext); + tree lpm1 = build_int_cst (unsigned_type_node, + limb_prec - 1); + tree n = make_ssa_name (TREE_TYPE (ext)); + g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1); + insert_before (g); + ext = add_cast (m_limb_type, n); + } + else + ext = build_zero_cst (m_limb_type); + kind = bitint_precision_kind (type); + unsigned start = CEIL (prec, limb_prec); + prec = TYPE_PRECISION (type); + idx = idx_first = idx_next = NULL_TREE; + if (prec <= (start + 2) * limb_prec) + kind = bitint_prec_large; + if (kind == bitint_prec_large) + cnt = CEIL (prec, limb_prec) - start; + else + { + rem = prec % limb_prec; + end = (prec - rem) / limb_prec; + cnt = 1 + (rem != 0); + idx = create_loop (size_int (start), &idx_next); + } + for (unsigned i = 0; i < cnt; i++) + { + if (kind == bitint_prec_large) + idx = size_int (start + i); + else if (i == 1) + idx = size_int (end); + rhs1 = ext; + tree l = limb_access (lhs_type, lhs, idx, true); + if (!useless_type_conversion_p (TREE_TYPE (l), TREE_TYPE (rhs1))) + rhs1 = add_cast (TREE_TYPE (l), rhs1); + g = gimple_build_assign (l, rhs1); + insert_before (g); + if (kind == bitint_prec_huge && i == 0) + { + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, + size_one_node); + insert_before (g); + g = gimple_build_cond (NE_EXPR, idx_next, size_int (end), + NULL_TREE, NULL_TREE); + insert_before (g); + m_gsi = gsi_for_stmt (stmt); + } + } + } + + if (gimple_store_p (stmt)) + { + unlink_stmt_vdef (stmt); + release_ssa_name (gimple_vdef (stmt)); + gsi_remove (&m_gsi, true); + } + if (eq_p) + { + lhs = make_ssa_name (boolean_type_node); + basic_block bb = gimple_bb (stmt); + gphi *phi = create_phi_node (lhs, bb); + edge e = find_edge (gsi_bb (m_gsi), bb); + unsigned int n = EDGE_COUNT (bb->preds); + for (unsigned int i = 0; i < n; i++) + { + edge e2 = EDGE_PRED (bb, i); + add_phi_arg (phi, e == e2 ? boolean_true_node : boolean_false_node, + e2, UNKNOWN_LOCATION); + } + cmp_code = cmp_code == EQ_EXPR ? NE_EXPR : EQ_EXPR; + return lhs; + } + else + return NULL_TREE; +} + +/* Handle a large/huge _BitInt comparison statement STMT other than + EQ_EXPR/NE_EXPR. CMP_CODE, CMP_OP1 and CMP_OP2 meaning is like in + lower_mergeable_stmt. The {GT,GE,LT,LE}_EXPR comparisons are + lowered by iteration from the most significant limb downwards to + the least significant one, for large _BitInt in straight line code, + otherwise with most significant limb handled in + straight line code followed by a loop handling one limb at a time. + Comparisons with unsigned huge _BitInt with precisions which are + multiples of limb precision can use just the loop and don't need to + handle most significant limb before the loop. The loop or straight + line code jumps to final basic block if a particular pair of limbs + is not equal. */ + +tree +bitint_large_huge::lower_comparison_stmt (gimple *stmt, tree_code &cmp_code, + tree cmp_op1, tree cmp_op2) +{ + tree type = TREE_TYPE (cmp_op1); + gcc_assert (TREE_CODE (type) == BITINT_TYPE); + bitint_prec_kind kind = bitint_precision_kind (type); + gcc_assert (kind >= bitint_prec_large); + gimple *g; + if (!TYPE_UNSIGNED (type) + && integer_zerop (cmp_op2) + && (cmp_code == GE_EXPR || cmp_code == LT_EXPR)) + { + unsigned end = CEIL ((unsigned) TYPE_PRECISION (type), limb_prec) - 1; + tree idx = size_int (end); + m_data_cnt = 0; + tree rhs1 = handle_operand (cmp_op1, idx); + if (TYPE_UNSIGNED (TREE_TYPE (rhs1))) + { + tree stype = signed_type_for (TREE_TYPE (rhs1)); + rhs1 = add_cast (stype, rhs1); + } + tree lhs = make_ssa_name (boolean_type_node); + g = gimple_build_assign (lhs, cmp_code, rhs1, + build_zero_cst (TREE_TYPE (rhs1))); + insert_before (g); + cmp_code = NE_EXPR; + return lhs; + } + + unsigned cnt, rem = 0, end = 0; + tree idx = NULL_TREE, idx_next = NULL_TREE; + if (kind == bitint_prec_large) + cnt = CEIL ((unsigned) TYPE_PRECISION (type), limb_prec); + else + { + rem = ((unsigned) TYPE_PRECISION (type) % limb_prec); + if (rem == 0 && !TYPE_UNSIGNED (type)) + rem = limb_prec; + end = ((unsigned) TYPE_PRECISION (type) - rem) / limb_prec; + cnt = 1 + (rem != 0); + } + + basic_block edge_bb = NULL; + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + gsi_prev (&gsi); + edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); + edge_bb = e->src; + m_gsi = gsi_last_bb (edge_bb); + if (!gsi_end_p (m_gsi)) + gsi_next (&m_gsi); + + edge *edges = XALLOCAVEC (edge, cnt * 2); + for (unsigned i = 0; i < cnt; i++) + { + m_data_cnt = 0; + if (kind == bitint_prec_large) + idx = size_int (cnt - i - 1); + else if (i == cnt - 1) + idx = create_loop (size_int (end - 1), &idx_next); + else + idx = size_int (end); + tree rhs1 = handle_operand (cmp_op1, idx); + tree rhs2 = handle_operand (cmp_op2, idx); + if (i == 0 + && !TYPE_UNSIGNED (type) + && TYPE_UNSIGNED (TREE_TYPE (rhs1))) + { + tree stype = signed_type_for (TREE_TYPE (rhs1)); + rhs1 = add_cast (stype, rhs1); + rhs2 = add_cast (stype, rhs2); + } + g = gimple_build_cond (GT_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + e1->flags = EDGE_FALSE_VALUE; + edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE); + e1->probability = profile_probability::likely (); + e2->probability = e1->probability.invert (); + if (i == 0) + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src); + m_gsi = gsi_after_labels (e1->dest); + edges[2 * i] = e2; + g = gimple_build_cond (LT_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE); + insert_before (g); + e1 = split_block (gsi_bb (m_gsi), g); + e1->flags = EDGE_FALSE_VALUE; + e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE); + e1->probability = profile_probability::unlikely (); + e2->probability = e1->probability.invert (); + m_gsi = gsi_after_labels (e1->dest); + edges[2 * i + 1] = e2; + m_first = false; + if (kind == bitint_prec_huge && i == cnt - 1) + { + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1)); + insert_before (g); + g = gimple_build_cond (NE_EXPR, idx, size_zero_node, + NULL_TREE, NULL_TREE); + insert_before (g); + edge true_edge, false_edge; + extract_true_false_edges_from_block (gsi_bb (m_gsi), + &true_edge, &false_edge); + m_gsi = gsi_after_labels (false_edge->dest); + } + } + + tree lhs = make_ssa_name (boolean_type_node); + basic_block bb = gimple_bb (stmt); + gphi *phi = create_phi_node (lhs, bb); + for (unsigned int i = 0; i < cnt * 2; i++) + { + tree val = ((cmp_code == GT_EXPR || cmp_code == GE_EXPR) + ^ (i & 1)) ? boolean_true_node : boolean_false_node; + add_phi_arg (phi, val, edges[i], UNKNOWN_LOCATION); + } + add_phi_arg (phi, (cmp_code == GE_EXPR || cmp_code == LE_EXPR) + ? boolean_true_node : boolean_false_node, + find_edge (gsi_bb (m_gsi), bb), UNKNOWN_LOCATION); + cmp_code = NE_EXPR; + return lhs; +} + +/* Lower large/huge _BitInt left and right shift except for left + shift by < limb_prec constant. */ + +void +bitint_large_huge::lower_shift_stmt (tree obj, gimple *stmt) +{ + tree rhs1 = gimple_assign_rhs1 (stmt); + tree lhs = gimple_assign_lhs (stmt); + tree_code rhs_code = gimple_assign_rhs_code (stmt); + tree type = TREE_TYPE (rhs1); + gimple *final_stmt = gsi_stmt (m_gsi); + gcc_assert (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large); + int prec = TYPE_PRECISION (type); + tree n = gimple_assign_rhs2 (stmt), n1, n2, n3, n4; + gimple *g; + if (obj == NULL_TREE) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + obj = m_vars[part]; + } + /* Preparation code common for both left and right shifts. + unsigned n1 = n % limb_prec; + size_t n2 = n / limb_prec; + size_t n3 = n1 != 0; + unsigned n4 = (limb_prec - n1) % limb_prec; + (for power of 2 limb_prec n4 can be -n1 & (limb_prec)). */ + if (TREE_CODE (n) == INTEGER_CST) + { + tree lp = build_int_cst (TREE_TYPE (n), limb_prec); + n1 = int_const_binop (TRUNC_MOD_EXPR, n, lp); + n2 = fold_convert (sizetype, int_const_binop (TRUNC_DIV_EXPR, n, lp)); + n3 = size_int (!integer_zerop (n1)); + n4 = int_const_binop (TRUNC_MOD_EXPR, + int_const_binop (MINUS_EXPR, lp, n1), lp); + } + else + { + n1 = make_ssa_name (TREE_TYPE (n)); + n2 = make_ssa_name (sizetype); + n3 = make_ssa_name (sizetype); + n4 = make_ssa_name (TREE_TYPE (n)); + if (pow2p_hwi (limb_prec)) + { + tree lpm1 = build_int_cst (TREE_TYPE (n), limb_prec - 1); + g = gimple_build_assign (n1, BIT_AND_EXPR, n, lpm1); + insert_before (g); + g = gimple_build_assign (useless_type_conversion_p (sizetype, + TREE_TYPE (n)) + ? n2 : make_ssa_name (TREE_TYPE (n)), + RSHIFT_EXPR, n, + build_int_cst (TREE_TYPE (n), + exact_log2 (limb_prec))); + insert_before (g); + if (gimple_assign_lhs (g) != n2) + { + g = gimple_build_assign (n2, NOP_EXPR, gimple_assign_lhs (g)); + insert_before (g); + } + g = gimple_build_assign (make_ssa_name (TREE_TYPE (n)), + NEGATE_EXPR, n1); + insert_before (g); + g = gimple_build_assign (n4, BIT_AND_EXPR, gimple_assign_lhs (g), + lpm1); + insert_before (g); + } + else + { + tree lp = build_int_cst (TREE_TYPE (n), limb_prec); + g = gimple_build_assign (n1, TRUNC_MOD_EXPR, n, lp); + insert_before (g); + g = gimple_build_assign (useless_type_conversion_p (sizetype, + TREE_TYPE (n)) + ? n2 : make_ssa_name (TREE_TYPE (n)), + TRUNC_DIV_EXPR, n, lp); + insert_before (g); + if (gimple_assign_lhs (g) != n2) + { + g = gimple_build_assign (n2, NOP_EXPR, gimple_assign_lhs (g)); + insert_before (g); + } + g = gimple_build_assign (make_ssa_name (TREE_TYPE (n)), + MINUS_EXPR, lp, n1); + insert_before (g); + g = gimple_build_assign (n4, TRUNC_MOD_EXPR, gimple_assign_lhs (g), + lp); + insert_before (g); + } + g = gimple_build_assign (make_ssa_name (boolean_type_node), NE_EXPR, n1, + build_zero_cst (TREE_TYPE (n))); + insert_before (g); + g = gimple_build_assign (n3, NOP_EXPR, gimple_assign_lhs (g)); + insert_before (g); + } + tree p = build_int_cst (sizetype, + prec / limb_prec - (prec % limb_prec == 0)); + if (rhs_code == RSHIFT_EXPR) + { + /* Lower + dst = src >> n; + as + unsigned n1 = n % limb_prec; + size_t n2 = n / limb_prec; + size_t n3 = n1 != 0; + unsigned n4 = (limb_prec - n1) % limb_prec; + size_t idx; + size_t p = prec / limb_prec - (prec % limb_prec == 0); + int signed_p = (typeof (src) -1) < 0; + for (idx = n2; idx < ((!signed_p && (prec % limb_prec == 0)) + ? p : p - n3); ++idx) + dst[idx - n2] = (src[idx] >> n1) | (src[idx + n3] << n4); + limb_type ext; + if (prec % limb_prec == 0) + ext = src[p]; + else if (signed_p) + ext = ((signed limb_type) (src[p] << (limb_prec + - (prec % limb_prec)))) + >> (limb_prec - (prec % limb_prec)); + else + ext = src[p] & (((limb_type) 1 << (prec % limb_prec)) - 1); + if (!signed_p && (prec % limb_prec == 0)) + ; + else if (idx < prec / 64) + { + dst[idx - n2] = (src[idx] >> n1) | (ext << n4); + ++idx; + } + idx -= n2; + if (signed_p) + { + dst[idx] = ((signed limb_type) ext) >> n1; + ext = ((signed limb_type) ext) >> (limb_prec - 1); + } + else + { + dst[idx] = ext >> n1; + ext = 0; + } + for (++idx; idx <= p; ++idx) + dst[idx] = ext; */ + tree pmn3; + if (TYPE_UNSIGNED (type) && prec % limb_prec == 0) + pmn3 = p; + else if (TREE_CODE (n3) == INTEGER_CST) + pmn3 = int_const_binop (MINUS_EXPR, p, n3); + else + { + pmn3 = make_ssa_name (sizetype); + g = gimple_build_assign (pmn3, MINUS_EXPR, p, n3); + insert_before (g); + } + g = gimple_build_cond (LT_EXPR, n2, pmn3, NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + tree idx_next; + tree idx = create_loop (n2, &idx_next); + tree idxmn2 = make_ssa_name (sizetype); + tree idxpn3 = make_ssa_name (sizetype); + g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2); + insert_before (g); + g = gimple_build_assign (idxpn3, PLUS_EXPR, idx, n3); + insert_before (g); + m_data_cnt = 0; + tree t1 = handle_operand (rhs1, idx); + m_first = false; + g = gimple_build_assign (make_ssa_name (m_limb_type), + RSHIFT_EXPR, t1, n1); + insert_before (g); + t1 = gimple_assign_lhs (g); + if (!integer_zerop (n3)) + { + m_data_cnt = 0; + tree t2 = handle_operand (rhs1, idxpn3); + g = gimple_build_assign (make_ssa_name (m_limb_type), + LSHIFT_EXPR, t2, n4); + insert_before (g); + t2 = gimple_assign_lhs (g); + g = gimple_build_assign (make_ssa_name (m_limb_type), + BIT_IOR_EXPR, t1, t2); + insert_before (g); + t1 = gimple_assign_lhs (g); + } + tree l = limb_access (TREE_TYPE (lhs), obj, idxmn2, true); + g = gimple_build_assign (l, t1); + insert_before (g); + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node); + insert_before (g); + g = gimple_build_cond (LT_EXPR, idx_next, pmn3, NULL_TREE, NULL_TREE); + insert_before (g); + idx = make_ssa_name (sizetype); + m_gsi = gsi_for_stmt (final_stmt); + gphi *phi = create_phi_node (idx, gsi_bb (m_gsi)); + e1 = find_edge (e1->src, gsi_bb (m_gsi)); + e2 = EDGE_PRED (gsi_bb (m_gsi), EDGE_PRED (gsi_bb (m_gsi), 0) == e1); + add_phi_arg (phi, n2, e1, UNKNOWN_LOCATION); + add_phi_arg (phi, idx_next, e2, UNKNOWN_LOCATION); + m_data_cnt = 0; + tree ms = handle_operand (rhs1, p); + tree ext = ms; + if (!types_compatible_p (TREE_TYPE (ms), m_limb_type)) + ext = add_cast (m_limb_type, ms); + if (!(TYPE_UNSIGNED (type) && prec % limb_prec == 0) + && !integer_zerop (n3)) + { + g = gimple_build_cond (LT_EXPR, idx, p, NULL_TREE, NULL_TREE); + insert_before (g); + e1 = split_block (gsi_bb (m_gsi), g); + e2 = split_block (e1->dest, (gimple *) NULL); + e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + m_data_cnt = 0; + t1 = handle_operand (rhs1, idx); + g = gimple_build_assign (make_ssa_name (m_limb_type), + RSHIFT_EXPR, t1, n1); + insert_before (g); + t1 = gimple_assign_lhs (g); + g = gimple_build_assign (make_ssa_name (m_limb_type), + LSHIFT_EXPR, ext, n4); + insert_before (g); + tree t2 = gimple_assign_lhs (g); + g = gimple_build_assign (make_ssa_name (m_limb_type), + BIT_IOR_EXPR, t1, t2); + insert_before (g); + t1 = gimple_assign_lhs (g); + idxmn2 = make_ssa_name (sizetype); + g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2); + insert_before (g); + l = limb_access (TREE_TYPE (lhs), obj, idxmn2, true); + g = gimple_build_assign (l, t1); + insert_before (g); + idx_next = make_ssa_name (sizetype); + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node); + insert_before (g); + m_gsi = gsi_for_stmt (final_stmt); + tree nidx = make_ssa_name (sizetype); + phi = create_phi_node (nidx, gsi_bb (m_gsi)); + e1 = find_edge (e1->src, gsi_bb (m_gsi)); + e2 = EDGE_PRED (gsi_bb (m_gsi), EDGE_PRED (gsi_bb (m_gsi), 0) == e1); + add_phi_arg (phi, idx, e1, UNKNOWN_LOCATION); + add_phi_arg (phi, idx_next, e2, UNKNOWN_LOCATION); + idx = nidx; + } + g = gimple_build_assign (make_ssa_name (sizetype), MINUS_EXPR, idx, n2); + insert_before (g); + idx = gimple_assign_lhs (g); + tree sext = ext; + if (!TYPE_UNSIGNED (type)) + sext = add_cast (signed_type_for (m_limb_type), ext); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (sext)), + RSHIFT_EXPR, sext, n1); + insert_before (g); + t1 = gimple_assign_lhs (g); + if (!TYPE_UNSIGNED (type)) + { + t1 = add_cast (m_limb_type, t1); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (sext)), + RSHIFT_EXPR, sext, + build_int_cst (TREE_TYPE (n), + limb_prec - 1)); + insert_before (g); + ext = add_cast (m_limb_type, gimple_assign_lhs (g)); + } + else + ext = build_zero_cst (m_limb_type); + l = limb_access (TREE_TYPE (lhs), obj, idx, true); + g = gimple_build_assign (l, t1); + insert_before (g); + g = gimple_build_assign (make_ssa_name (sizetype), PLUS_EXPR, idx, + size_one_node); + insert_before (g); + idx = gimple_assign_lhs (g); + g = gimple_build_cond (LE_EXPR, idx, p, NULL_TREE, NULL_TREE); + insert_before (g); + e1 = split_block (gsi_bb (m_gsi), g); + e2 = split_block (e1->dest, (gimple *) NULL); + e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + idx = create_loop (idx, &idx_next); + l = limb_access (TREE_TYPE (lhs), obj, idx, true); + g = gimple_build_assign (l, ext); + insert_before (g); + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node); + insert_before (g); + g = gimple_build_cond (LE_EXPR, idx_next, p, NULL_TREE, NULL_TREE); + insert_before (g); + } + else + { + /* Lower + dst = src << n; + as + unsigned n1 = n % limb_prec; + size_t n2 = n / limb_prec; + size_t n3 = n1 != 0; + unsigned n4 = (limb_prec - n1) % limb_prec; + size_t idx; + size_t p = prec / limb_prec - (prec % limb_prec == 0); + for (idx = p; (ssize_t) idx >= (ssize_t) (n2 + n3); --idx) + dst[idx] = (src[idx - n2] << n1) | (src[idx - n2 - n3] >> n4); + if (n1) + { + dst[idx] = src[idx - n2] << n1; + --idx; + } + for (; (ssize_t) idx >= 0; --idx) + dst[idx] = 0; */ + tree n2pn3; + if (TREE_CODE (n2) == INTEGER_CST && TREE_CODE (n3) == INTEGER_CST) + n2pn3 = int_const_binop (PLUS_EXPR, n2, n3); + else + { + n2pn3 = make_ssa_name (sizetype); + g = gimple_build_assign (n2pn3, PLUS_EXPR, n2, n3); + insert_before (g); + } + /* For LSHIFT_EXPR, we can use handle_operand with non-INTEGER_CST + idx even to access the most significant partial limb. */ + m_var_msb = true; + if (integer_zerop (n3)) + /* For n3 == 0 p >= n2 + n3 is always true for all valid shift + counts. Emit if (true) condition that can be optimized later. */ + g = gimple_build_cond (NE_EXPR, boolean_true_node, boolean_false_node, + NULL_TREE, NULL_TREE); + else + g = gimple_build_cond (LE_EXPR, n2pn3, p, NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + tree idx_next; + tree idx = create_loop (p, &idx_next); + tree idxmn2 = make_ssa_name (sizetype); + tree idxmn2mn3 = make_ssa_name (sizetype); + g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2); + insert_before (g); + g = gimple_build_assign (idxmn2mn3, MINUS_EXPR, idxmn2, n3); + insert_before (g); + m_data_cnt = 0; + tree t1 = handle_operand (rhs1, idxmn2); + m_first = false; + g = gimple_build_assign (make_ssa_name (m_limb_type), + LSHIFT_EXPR, t1, n1); + insert_before (g); + t1 = gimple_assign_lhs (g); + if (!integer_zerop (n3)) + { + m_data_cnt = 0; + tree t2 = handle_operand (rhs1, idxmn2mn3); + g = gimple_build_assign (make_ssa_name (m_limb_type), + RSHIFT_EXPR, t2, n4); + insert_before (g); + t2 = gimple_assign_lhs (g); + g = gimple_build_assign (make_ssa_name (m_limb_type), + BIT_IOR_EXPR, t1, t2); + insert_before (g); + t1 = gimple_assign_lhs (g); + } + tree l = limb_access (TREE_TYPE (lhs), obj, idx, true); + g = gimple_build_assign (l, t1); + insert_before (g); + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1)); + insert_before (g); + tree sn2pn3 = add_cast (ssizetype, n2pn3); + g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx_next), sn2pn3, + NULL_TREE, NULL_TREE); + insert_before (g); + idx = make_ssa_name (sizetype); + m_gsi = gsi_for_stmt (final_stmt); + gphi *phi = create_phi_node (idx, gsi_bb (m_gsi)); + e1 = find_edge (e1->src, gsi_bb (m_gsi)); + e2 = EDGE_PRED (gsi_bb (m_gsi), EDGE_PRED (gsi_bb (m_gsi), 0) == e1); + add_phi_arg (phi, p, e1, UNKNOWN_LOCATION); + add_phi_arg (phi, idx_next, e2, UNKNOWN_LOCATION); + m_data_cnt = 0; + if (!integer_zerop (n3)) + { + g = gimple_build_cond (NE_EXPR, n3, size_zero_node, + NULL_TREE, NULL_TREE); + insert_before (g); + e1 = split_block (gsi_bb (m_gsi), g); + e2 = split_block (e1->dest, (gimple *) NULL); + e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + idxmn2 = make_ssa_name (sizetype); + g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2); + insert_before (g); + m_data_cnt = 0; + t1 = handle_operand (rhs1, idxmn2); + g = gimple_build_assign (make_ssa_name (m_limb_type), + LSHIFT_EXPR, t1, n1); + insert_before (g); + t1 = gimple_assign_lhs (g); + l = limb_access (TREE_TYPE (lhs), obj, idx, true); + g = gimple_build_assign (l, t1); + insert_before (g); + idx_next = make_ssa_name (sizetype); + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1)); + insert_before (g); + m_gsi = gsi_for_stmt (final_stmt); + tree nidx = make_ssa_name (sizetype); + phi = create_phi_node (nidx, gsi_bb (m_gsi)); + e1 = find_edge (e1->src, gsi_bb (m_gsi)); + e2 = EDGE_PRED (gsi_bb (m_gsi), EDGE_PRED (gsi_bb (m_gsi), 0) == e1); + add_phi_arg (phi, idx, e1, UNKNOWN_LOCATION); + add_phi_arg (phi, idx_next, e2, UNKNOWN_LOCATION); + idx = nidx; + } + g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx), + ssize_int (0), NULL_TREE, NULL_TREE); + insert_before (g); + e1 = split_block (gsi_bb (m_gsi), g); + e2 = split_block (e1->dest, (gimple *) NULL); + e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + idx = create_loop (idx, &idx_next); + l = limb_access (TREE_TYPE (lhs), obj, idx, true); + g = gimple_build_assign (l, build_zero_cst (m_limb_type)); + insert_before (g); + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1)); + insert_before (g); + g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx_next), + ssize_int (0), NULL_TREE, NULL_TREE); + insert_before (g); + } +} + +/* Lower large/huge _BitInt multiplication or division. */ + +void +bitint_large_huge::lower_muldiv_stmt (tree obj, gimple *stmt) +{ + tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs2 (stmt); + tree lhs = gimple_assign_lhs (stmt); + tree_code rhs_code = gimple_assign_rhs_code (stmt); + tree type = TREE_TYPE (rhs1); + gcc_assert (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large); + int prec = TYPE_PRECISION (type), prec1, prec2; + rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec1); + rhs2 = handle_operand_addr (rhs2, stmt, NULL, &prec2); + if (obj == NULL_TREE) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + obj = m_vars[part]; + lhs = build_fold_addr_expr (obj); + } + else + { + lhs = build_fold_addr_expr (obj); + lhs = force_gimple_operand_gsi (&m_gsi, lhs, true, + NULL_TREE, true, GSI_SAME_STMT); + } + tree sitype = lang_hooks.types.type_for_mode (SImode, 0); + gimple *g; + switch (rhs_code) + { + case MULT_EXPR: + g = gimple_build_call_internal (IFN_MULBITINT, 6, + lhs, build_int_cst (sitype, prec), + rhs1, build_int_cst (sitype, prec1), + rhs2, build_int_cst (sitype, prec2)); + insert_before (g); + break; + case TRUNC_DIV_EXPR: + g = gimple_build_call_internal (IFN_DIVMODBITINT, 8, + lhs, build_int_cst (sitype, prec), + null_pointer_node, + build_int_cst (sitype, 0), + rhs1, build_int_cst (sitype, prec1), + rhs2, build_int_cst (sitype, prec2)); + if (!stmt_ends_bb_p (stmt)) + gimple_call_set_nothrow (as_a (g), true); + insert_before (g); + break; + case TRUNC_MOD_EXPR: + g = gimple_build_call_internal (IFN_DIVMODBITINT, 8, null_pointer_node, + build_int_cst (sitype, 0), + lhs, build_int_cst (sitype, prec), + rhs1, build_int_cst (sitype, prec1), + rhs2, build_int_cst (sitype, prec2)); + if (!stmt_ends_bb_p (stmt)) + gimple_call_set_nothrow (as_a (g), true); + insert_before (g); + break; + default: + gcc_unreachable (); + } + if (stmt_ends_bb_p (stmt)) + { + maybe_duplicate_eh_stmt (g, stmt); + edge e1; + edge_iterator ei; + basic_block bb = gimple_bb (stmt); + + FOR_EACH_EDGE (e1, ei, bb->succs) + if (e1->flags & EDGE_EH) + break; + if (e1) + { + edge e2 = split_block (gsi_bb (m_gsi), g); + m_gsi = gsi_after_labels (e2->dest); + make_edge (e2->src, e1->dest, EDGE_EH)->probability + = profile_probability::very_unlikely (); + } + } +} + +/* Lower large/huge _BitInt conversion to/from floating point. */ + +void +bitint_large_huge::lower_float_conv_stmt (tree obj, gimple *stmt) +{ + tree rhs1 = gimple_assign_rhs1 (stmt); + tree lhs = gimple_assign_lhs (stmt); + tree_code rhs_code = gimple_assign_rhs_code (stmt); + if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (rhs1))) + || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (lhs)))) + { + sorry_at (gimple_location (stmt), + "unsupported conversion between %<_BitInt(%d)%> and %qT", + rhs_code == FIX_TRUNC_EXPR + ? TYPE_PRECISION (TREE_TYPE (lhs)) + : TYPE_PRECISION (TREE_TYPE (rhs1)), + rhs_code == FIX_TRUNC_EXPR + ? TREE_TYPE (rhs1) : TREE_TYPE (lhs)); + if (rhs_code == FLOAT_EXPR) + { + gimple *g + = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs))); + gsi_replace (&m_gsi, g, true); + } + return; + } + tree sitype = lang_hooks.types.type_for_mode (SImode, 0); + gimple *g; + if (rhs_code == FIX_TRUNC_EXPR) + { + int prec = TYPE_PRECISION (TREE_TYPE (lhs)); + if (!TYPE_UNSIGNED (TREE_TYPE (lhs))) + prec = -prec; + if (obj == NULL_TREE) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + obj = m_vars[part]; + lhs = build_fold_addr_expr (obj); + } + else + { + lhs = build_fold_addr_expr (obj); + lhs = force_gimple_operand_gsi (&m_gsi, lhs, true, + NULL_TREE, true, GSI_SAME_STMT); + } + scalar_mode from_mode + = as_a (TYPE_MODE (TREE_TYPE (rhs1))); +#ifdef HAVE_SFmode + /* IEEE single is a full superset of both IEEE half and + bfloat formats, convert to float first and then to _BitInt + to avoid the need of another 2 library routines. */ + if ((REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format + || REAL_MODE_FORMAT (from_mode) == &ieee_half_format) + && REAL_MODE_FORMAT (SFmode) == &ieee_single_format) + { + tree type = lang_hooks.types.type_for_mode (SFmode, 0); + if (type) + rhs1 = add_cast (type, rhs1); + } +#endif + g = gimple_build_call_internal (IFN_FLOATTOBITINT, 3, + lhs, build_int_cst (sitype, prec), + rhs1); + insert_before (g); + } + else + { + int prec; + rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec); + g = gimple_build_call_internal (IFN_BITINTTOFLOAT, 2, + rhs1, build_int_cst (sitype, prec)); + gimple_call_set_lhs (g, lhs); + if (!stmt_ends_bb_p (stmt)) + gimple_call_set_nothrow (as_a (g), true); + gsi_replace (&m_gsi, g, true); + } +} + +/* Helper method for lower_addsub_overflow and lower_mul_overflow. + If check_zero is true, caller wants to check if all bits in [start, end) + are zero, otherwise if bits in [start, end) are either all zero or + all ones. L is the limb with index LIMB, START and END are measured + in bits. */ + +tree +bitint_large_huge::arith_overflow_extract_bits (unsigned int start, + unsigned int end, tree l, + unsigned int limb, + bool check_zero) +{ + unsigned startlimb = start / limb_prec; + unsigned endlimb = (end - 1) / limb_prec; + gimple *g; + + if ((start % limb_prec) == 0 && (end % limb_prec) == 0) + return l; + if (startlimb == endlimb && limb == startlimb) + { + if (check_zero) + { + wide_int w = wi::shifted_mask (start % limb_prec, + end - start, false, limb_prec); + g = gimple_build_assign (make_ssa_name (m_limb_type), + BIT_AND_EXPR, l, + wide_int_to_tree (m_limb_type, w)); + insert_before (g); + return gimple_assign_lhs (g); + } + unsigned int shift = start % limb_prec; + if ((end % limb_prec) != 0) + { + unsigned int lshift = (-end) % limb_prec; + shift += lshift; + g = gimple_build_assign (make_ssa_name (m_limb_type), + LSHIFT_EXPR, l, + build_int_cst (unsigned_type_node, + lshift)); + insert_before (g); + l = gimple_assign_lhs (g); + } + l = add_cast (signed_type_for (m_limb_type), l); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (l)), + RSHIFT_EXPR, l, + build_int_cst (unsigned_type_node, shift)); + insert_before (g); + return add_cast (m_limb_type, gimple_assign_lhs (g)); + } + else if (limb == startlimb) + { + if ((start % limb_prec) == 0) + return l; + if (!check_zero) + l = add_cast (signed_type_for (m_limb_type), l); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (l)), + RSHIFT_EXPR, l, + build_int_cst (unsigned_type_node, + start % limb_prec)); + insert_before (g); + l = gimple_assign_lhs (g); + if (!check_zero) + l = add_cast (m_limb_type, l); + return l; + } + else if (limb == endlimb) + { + if ((end % limb_prec) == 0) + return l; + if (check_zero) + { + wide_int w = wi::mask (end % limb_prec, false, limb_prec); + g = gimple_build_assign (make_ssa_name (m_limb_type), + BIT_AND_EXPR, l, + wide_int_to_tree (m_limb_type, w)); + insert_before (g); + return gimple_assign_lhs (g); + } + unsigned int shift = (-end) % limb_prec; + g = gimple_build_assign (make_ssa_name (m_limb_type), + LSHIFT_EXPR, l, + build_int_cst (unsigned_type_node, shift)); + insert_before (g); + l = add_cast (signed_type_for (m_limb_type), gimple_assign_lhs (g)); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (l)), + RSHIFT_EXPR, l, + build_int_cst (unsigned_type_node, shift)); + insert_before (g); + return add_cast (m_limb_type, gimple_assign_lhs (g)); + } + return l; +} + +/* Helper method for lower_addsub_overflow and lower_mul_overflow. Store + result including overflow flag into the right locations. */ + +void +bitint_large_huge::finish_arith_overflow (tree var, tree obj, tree type, + tree ovf, tree lhs, tree orig_obj, + gimple *stmt, tree_code code) +{ + gimple *g; + + if (obj == NULL_TREE + && (TREE_CODE (type) != BITINT_TYPE + || bitint_precision_kind (type) < bitint_prec_large)) + { + /* Add support for 3 or more limbs filled in from normal integral + type if this assert fails. If no target chooses limb mode smaller + than half of largest supported normal integral type, this will not + be needed. */ + gcc_assert (TYPE_PRECISION (type) <= 2 * limb_prec); + tree lhs_type = type; + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) == bitint_prec_middle) + lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (type), + TYPE_UNSIGNED (type)); + tree r1 = limb_access (NULL_TREE, var, size_int (0), true); + g = gimple_build_assign (make_ssa_name (m_limb_type), r1); + insert_before (g); + r1 = gimple_assign_lhs (g); + if (!useless_type_conversion_p (lhs_type, TREE_TYPE (r1))) + r1 = add_cast (lhs_type, r1); + if (TYPE_PRECISION (lhs_type) > limb_prec) + { + tree r2 = limb_access (NULL_TREE, var, size_int (1), true); + g = gimple_build_assign (make_ssa_name (m_limb_type), r2); + insert_before (g); + r2 = gimple_assign_lhs (g); + r2 = add_cast (lhs_type, r2); + g = gimple_build_assign (make_ssa_name (lhs_type), LSHIFT_EXPR, r2, + build_int_cst (unsigned_type_node, + limb_prec)); + insert_before (g); + g = gimple_build_assign (make_ssa_name (lhs_type), BIT_IOR_EXPR, r1, + gimple_assign_lhs (g)); + insert_before (g); + r1 = gimple_assign_lhs (g); + } + if (lhs_type != type) + r1 = add_cast (type, r1); + ovf = add_cast (lhs_type, ovf); + if (lhs_type != type) + ovf = add_cast (type, ovf); + g = gimple_build_assign (lhs, COMPLEX_EXPR, r1, ovf); + m_gsi = gsi_for_stmt (stmt); + gsi_replace (&m_gsi, g, true); + } + else + { + unsigned HOST_WIDE_INT nelts = 0; + tree atype = NULL_TREE; + if (obj) + { + nelts = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec; + if (orig_obj == NULL_TREE) + nelts >>= 1; + atype = build_array_type_nelts (m_limb_type, nelts); + } + if (var && obj) + { + tree v1, v2; + tree zero; + if (orig_obj == NULL_TREE) + { + zero = build_zero_cst (build_pointer_type (TREE_TYPE (obj))); + v1 = build2 (MEM_REF, atype, + build_fold_addr_expr (unshare_expr (obj)), zero); + } + else if (!useless_type_conversion_p (atype, TREE_TYPE (obj))) + v1 = build1 (VIEW_CONVERT_EXPR, atype, unshare_expr (obj)); + else + v1 = unshare_expr (obj); + zero = build_zero_cst (build_pointer_type (TREE_TYPE (var))); + v2 = build2 (MEM_REF, atype, build_fold_addr_expr (var), zero); + g = gimple_build_assign (v1, v2); + insert_before (g); + } + if (orig_obj == NULL_TREE && obj) + { + ovf = add_cast (m_limb_type, ovf); + tree l = limb_access (NULL_TREE, obj, size_int (nelts), true); + g = gimple_build_assign (l, ovf); + insert_before (g); + if (nelts > 1) + { + atype = build_array_type_nelts (m_limb_type, nelts - 1); + tree off = build_int_cst (build_pointer_type (TREE_TYPE (obj)), + (nelts + 1) * m_limb_size); + tree v1 = build2 (MEM_REF, atype, + build_fold_addr_expr (unshare_expr (obj)), + off); + g = gimple_build_assign (v1, build_zero_cst (atype)); + insert_before (g); + } + } + else if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE) + { + imm_use_iterator ui; + use_operand_p use_p; + FOR_EACH_IMM_USE_FAST (use_p, ui, lhs) + { + g = USE_STMT (use_p); + if (!is_gimple_assign (g) + || gimple_assign_rhs_code (g) != IMAGPART_EXPR) + continue; + tree lhs2 = gimple_assign_lhs (g); + gimple *use_stmt; + single_imm_use (lhs2, &use_p, &use_stmt); + lhs2 = gimple_assign_lhs (use_stmt); + gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt); + if (useless_type_conversion_p (TREE_TYPE (lhs2), TREE_TYPE (ovf))) + g = gimple_build_assign (lhs2, ovf); + else + g = gimple_build_assign (lhs2, NOP_EXPR, ovf); + gsi_replace (&gsi, g, true); + break; + } + } + else if (ovf != boolean_false_node) + { + g = gimple_build_cond (NE_EXPR, ovf, boolean_false_node, + NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::very_likely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + m_gsi = gsi_after_labels (e1->dest); + tree zero = build_zero_cst (TREE_TYPE (lhs)); + tree fn = ubsan_build_overflow_builtin (code, m_loc, + TREE_TYPE (lhs), + zero, zero, NULL); + force_gimple_operand_gsi (&m_gsi, fn, true, NULL_TREE, + true, GSI_SAME_STMT); + m_gsi = gsi_after_labels (e2->dest); + } + } + if (var) + { + tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_EOL); + g = gimple_build_assign (var, clobber); + gsi_insert_after (&m_gsi, g, GSI_SAME_STMT); + } +} + +/* Helper function for lower_addsub_overflow and lower_mul_overflow. + Given precisions of result TYPE (PREC), argument 0 precision PREC0, + argument 1 precision PREC1 and minimum precision for the result + PREC2, compute *START, *END, *CHECK_ZERO and return OVF. */ + +static tree +arith_overflow (tree_code code, tree type, int prec, int prec0, int prec1, + int prec2, unsigned *start, unsigned *end, bool *check_zero) +{ + *start = 0; + *end = 0; + *check_zero = true; + /* Ignore this special rule for subtraction, even if both + prec0 >= 0 and prec1 >= 0, their subtraction can be negative + in infinite precision. */ + if (code != MINUS_EXPR && prec0 >= 0 && prec1 >= 0) + { + /* Result in [0, prec2) is unsigned, if prec > prec2, + all bits above it will be zero. */ + if ((prec - !TYPE_UNSIGNED (type)) >= prec2) + return boolean_false_node; + else + { + /* ovf if any of bits in [start, end) is non-zero. */ + *start = prec - !TYPE_UNSIGNED (type); + *end = prec2; + } + } + else if (TYPE_UNSIGNED (type)) + { + /* If result in [0, prec2) is signed and if prec > prec2, + all bits above it will be sign bit copies. */ + if (prec >= prec2) + { + /* ovf if bit prec - 1 is non-zero. */ + *start = prec - 1; + *end = prec; + } + else + { + /* ovf if any of bits in [start, end) is non-zero. */ + *start = prec; + *end = prec2; + } + } + else if (prec >= prec2) + return boolean_false_node; + else + { + /* ovf if [start, end) bits aren't all zeros or all ones. */ + *start = prec - 1; + *end = prec2; + *check_zero = false; + } + return NULL_TREE; +} + +/* Lower a .{ADD,SUB}_OVERFLOW call with at least one large/huge _BitInt + argument or return type _Complex large/huge _BitInt. */ + +void +bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt) +{ + tree arg0 = gimple_call_arg (stmt, 0); + tree arg1 = gimple_call_arg (stmt, 1); + tree lhs = gimple_call_lhs (stmt); + gimple *g; + + if (!lhs) + { + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + gsi_remove (&gsi, true); + return; + } + gimple *final_stmt = gsi_stmt (m_gsi); + tree type = TREE_TYPE (lhs); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + int prec = TYPE_PRECISION (type); + int prec0 = range_to_prec (arg0, stmt); + int prec1 = range_to_prec (arg1, stmt); + int prec2 = ((prec0 < 0) == (prec1 < 0) + ? MAX (prec0 < 0 ? -prec0 : prec0, + prec1 < 0 ? -prec1 : prec1) + 1 + : MAX (prec0 < 0 ? -prec0 : prec0 + 1, + prec1 < 0 ? -prec1 : prec1 + 1) + 1); + int prec3 = MAX (prec0 < 0 ? -prec0 : prec0, + prec1 < 0 ? -prec1 : prec1); + prec3 = MAX (prec3, prec); + tree var = NULL_TREE; + tree orig_obj = obj; + if (obj == NULL_TREE + && TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large + && m_names + && bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs))) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + obj = m_vars[part]; + if (TREE_TYPE (lhs) == type) + orig_obj = obj; + } + if (TREE_CODE (type) != BITINT_TYPE + || bitint_precision_kind (type) < bitint_prec_large) + { + unsigned HOST_WIDE_INT nelts = CEIL (prec, limb_prec); + tree atype = build_array_type_nelts (m_limb_type, nelts); + var = create_tmp_var (atype); + } + + enum tree_code code; + switch (gimple_call_internal_fn (stmt)) + { + case IFN_ADD_OVERFLOW: + case IFN_UBSAN_CHECK_ADD: + code = PLUS_EXPR; + break; + case IFN_SUB_OVERFLOW: + case IFN_UBSAN_CHECK_SUB: + code = MINUS_EXPR; + break; + default: + gcc_unreachable (); + } + unsigned start, end; + bool check_zero; + tree ovf = arith_overflow (code, type, prec, prec0, prec1, prec2, + &start, &end, &check_zero); + + unsigned startlimb, endlimb; + if (ovf) + { + startlimb = ~0U; + endlimb = ~0U; + } + else + { + startlimb = start / limb_prec; + endlimb = (end - 1) / limb_prec; + } + + int prec4 = ovf != NULL_TREE ? prec : prec3; + bitint_prec_kind kind = bitint_precision_kind (prec4); + unsigned cnt, rem = 0, fin = 0; + tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE; + bool last_ovf = (ovf == NULL_TREE + && CEIL (prec2, limb_prec) > CEIL (prec3, limb_prec)); + if (kind != bitint_prec_huge) + cnt = CEIL (prec4, limb_prec) + last_ovf; + else + { + rem = (prec4 % (2 * limb_prec)); + fin = (prec4 - rem) / limb_prec; + cnt = 2 + CEIL (rem, limb_prec) + last_ovf; + idx = idx_first = create_loop (size_zero_node, &idx_next); + } + + if (kind == bitint_prec_huge) + m_upwards_2limb = fin; + + tree type0 = TREE_TYPE (arg0); + tree type1 = TREE_TYPE (arg1); + if (TYPE_PRECISION (type0) < prec3) + { + type0 = build_bitint_type (prec3, TYPE_UNSIGNED (type0)); + if (TREE_CODE (arg0) == INTEGER_CST) + arg0 = fold_convert (type0, arg0); + } + if (TYPE_PRECISION (type1) < prec3) + { + type1 = build_bitint_type (prec3, TYPE_UNSIGNED (type1)); + if (TREE_CODE (arg1) == INTEGER_CST) + arg1 = fold_convert (type1, arg1); + } + unsigned int data_cnt = 0; + tree last_rhs1 = NULL_TREE, last_rhs2 = NULL_TREE; + tree cmp = build_zero_cst (m_limb_type); + unsigned prec_limbs = CEIL ((unsigned) prec, limb_prec); + tree ovf_out = NULL_TREE, cmp_out = NULL_TREE; + for (unsigned i = 0; i < cnt; i++) + { + m_data_cnt = 0; + tree rhs1, rhs2; + if (kind != bitint_prec_huge) + idx = size_int (i); + else if (i >= 2) + idx = size_int (fin + (i > 2)); + if (!last_ovf || i < cnt - 1) + { + if (type0 != TREE_TYPE (arg0)) + rhs1 = handle_cast (type0, arg0, idx); + else + rhs1 = handle_operand (arg0, idx); + if (type1 != TREE_TYPE (arg1)) + rhs2 = handle_cast (type1, arg1, idx); + else + rhs2 = handle_operand (arg1, idx); + if (i == 0) + data_cnt = m_data_cnt; + if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1))) + rhs1 = add_cast (m_limb_type, rhs1); + if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs2))) + rhs2 = add_cast (m_limb_type, rhs2); + last_rhs1 = rhs1; + last_rhs2 = rhs2; + } + else + { + m_data_cnt = data_cnt; + if (TYPE_UNSIGNED (type0)) + rhs1 = build_zero_cst (m_limb_type); + else + { + rhs1 = add_cast (signed_type_for (m_limb_type), last_rhs1); + if (TREE_CODE (rhs1) == INTEGER_CST) + rhs1 = build_int_cst (m_limb_type, + tree_int_cst_sgn (rhs1) < 0 ? -1 : 0); + else + { + tree lpm1 = build_int_cst (unsigned_type_node, + limb_prec - 1); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)), + RSHIFT_EXPR, rhs1, lpm1); + insert_before (g); + rhs1 = add_cast (m_limb_type, gimple_assign_lhs (g)); + } + } + if (TYPE_UNSIGNED (type1)) + rhs2 = build_zero_cst (m_limb_type); + else + { + rhs2 = add_cast (signed_type_for (m_limb_type), last_rhs2); + if (TREE_CODE (rhs2) == INTEGER_CST) + rhs2 = build_int_cst (m_limb_type, + tree_int_cst_sgn (rhs2) < 0 ? -1 : 0); + else + { + tree lpm1 = build_int_cst (unsigned_type_node, + limb_prec - 1); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs2)), + RSHIFT_EXPR, rhs2, lpm1); + insert_before (g); + rhs2 = add_cast (m_limb_type, gimple_assign_lhs (g)); + } + } + } + tree rhs = handle_plus_minus (code, rhs1, rhs2, idx); + if (ovf != boolean_false_node) + { + if (tree_fits_uhwi_p (idx)) + { + unsigned limb = tree_to_uhwi (idx); + if (limb >= startlimb && limb <= endlimb) + { + tree l = arith_overflow_extract_bits (start, end, rhs, + limb, check_zero); + tree this_ovf = make_ssa_name (boolean_type_node); + if (ovf == NULL_TREE && !check_zero) + { + cmp = l; + g = gimple_build_assign (make_ssa_name (m_limb_type), + PLUS_EXPR, l, + build_int_cst (m_limb_type, 1)); + insert_before (g); + g = gimple_build_assign (this_ovf, GT_EXPR, + gimple_assign_lhs (g), + build_int_cst (m_limb_type, 1)); + } + else + g = gimple_build_assign (this_ovf, NE_EXPR, l, cmp); + insert_before (g); + if (ovf == NULL_TREE) + ovf = this_ovf; + else + { + tree b = make_ssa_name (boolean_type_node); + g = gimple_build_assign (b, BIT_IOR_EXPR, ovf, this_ovf); + insert_before (g); + ovf = b; + } + } + } + else if (startlimb < fin) + { + if (m_first && startlimb + 2 < fin) + { + tree data_out; + ovf = prepare_data_in_out (boolean_false_node, idx, &data_out); + ovf_out = m_data.pop (); + m_data.pop (); + if (!check_zero) + { + cmp = prepare_data_in_out (cmp, idx, &data_out); + cmp_out = m_data.pop (); + m_data.pop (); + } + } + if (i != 0 || startlimb != fin - 1) + { + tree_code cmp_code; + bool single_comparison + = (startlimb + 2 >= fin || (startlimb & 1) != (i & 1)); + if (!single_comparison) + { + cmp_code = GE_EXPR; + if (!check_zero && (start % limb_prec) == 0) + single_comparison = true; + } + else if ((startlimb & 1) == (i & 1)) + cmp_code = EQ_EXPR; + else + cmp_code = GT_EXPR; + g = gimple_build_cond (cmp_code, idx, size_int (startlimb), + NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + edge e4 = NULL; + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + if (!single_comparison) + { + m_gsi = gsi_after_labels (e1->dest); + g = gimple_build_cond (EQ_EXPR, idx, + size_int (startlimb), NULL_TREE, + NULL_TREE); + insert_before (g); + e2 = split_block (gsi_bb (m_gsi), g); + basic_block bb = create_empty_bb (e2->dest); + add_bb_to_loop (bb, e2->dest->loop_father); + e4 = make_edge (e2->src, bb, EDGE_TRUE_VALUE); + set_immediate_dominator (CDI_DOMINATORS, bb, e2->src); + e4->probability = profile_probability::unlikely (); + e2->flags = EDGE_FALSE_VALUE; + e2->probability = e4->probability.invert (); + e4 = make_edge (bb, e3->dest, EDGE_FALLTHRU); + e2 = find_edge (e2->dest, e3->dest); + } + m_gsi = gsi_after_labels (e2->src); + unsigned tidx = startlimb + (cmp_code == GT_EXPR); + tree l = arith_overflow_extract_bits (start, end, rhs, tidx, + check_zero); + tree this_ovf = make_ssa_name (boolean_type_node); + if (cmp_code != GT_EXPR && !check_zero) + { + g = gimple_build_assign (make_ssa_name (m_limb_type), + PLUS_EXPR, l, + build_int_cst (m_limb_type, 1)); + insert_before (g); + g = gimple_build_assign (this_ovf, GT_EXPR, + gimple_assign_lhs (g), + build_int_cst (m_limb_type, 1)); + } + else + g = gimple_build_assign (this_ovf, NE_EXPR, l, cmp); + insert_before (g); + if (cmp_code == GT_EXPR) + { + tree t = make_ssa_name (boolean_type_node); + g = gimple_build_assign (t, BIT_IOR_EXPR, ovf, this_ovf); + insert_before (g); + this_ovf = t; + } + tree this_ovf2 = NULL_TREE; + if (!single_comparison) + { + m_gsi = gsi_after_labels (e4->src); + tree t = make_ssa_name (boolean_type_node); + g = gimple_build_assign (t, NE_EXPR, rhs, cmp); + insert_before (g); + this_ovf2 = make_ssa_name (boolean_type_node); + g = gimple_build_assign (this_ovf2, BIT_IOR_EXPR, + ovf, t); + insert_before (g); + } + m_gsi = gsi_after_labels (e2->dest); + tree t; + if (i == 1 && ovf_out) + t = ovf_out; + else + t = make_ssa_name (boolean_type_node); + gphi *phi = create_phi_node (t, e2->dest); + add_phi_arg (phi, this_ovf, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, ovf ? ovf + : boolean_false_node, e3, + UNKNOWN_LOCATION); + if (e4) + add_phi_arg (phi, this_ovf2, e4, UNKNOWN_LOCATION); + ovf = t; + if (!check_zero && cmp_code != GT_EXPR) + { + t = cmp_out ? cmp_out : make_ssa_name (m_limb_type); + phi = create_phi_node (t, e2->dest); + add_phi_arg (phi, l, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, cmp, e3, UNKNOWN_LOCATION); + if (e4) + add_phi_arg (phi, cmp, e4, UNKNOWN_LOCATION); + cmp = t; + } + } + } + } + + if (var || obj) + { + if (tree_fits_uhwi_p (idx) && tree_to_uhwi (idx) >= prec_limbs) + ; + else if (!tree_fits_uhwi_p (idx) + && (unsigned) prec < (fin - (i == 0)) * limb_prec) + { + bool single_comparison + = (((unsigned) prec % limb_prec) == 0 + || prec_limbs + 1 >= fin + || (prec_limbs & 1) == (i & 1)); + g = gimple_build_cond (LE_EXPR, idx, size_int (prec_limbs - 1), + NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + edge e4 = NULL; + e3->probability = profile_probability::unlikely (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + if (!single_comparison) + { + m_gsi = gsi_after_labels (e1->dest); + g = gimple_build_cond (LT_EXPR, idx, + size_int (prec_limbs - 1), + NULL_TREE, NULL_TREE); + insert_before (g); + e2 = split_block (gsi_bb (m_gsi), g); + basic_block bb = create_empty_bb (e2->dest); + add_bb_to_loop (bb, e2->dest->loop_father); + e4 = make_edge (e2->src, bb, EDGE_TRUE_VALUE); + set_immediate_dominator (CDI_DOMINATORS, bb, e2->src); + e4->probability = profile_probability::unlikely (); + e2->flags = EDGE_FALSE_VALUE; + e2->probability = e4->probability.invert (); + e4 = make_edge (bb, e3->dest, EDGE_FALLTHRU); + e2 = find_edge (e2->dest, e3->dest); + } + m_gsi = gsi_after_labels (e2->src); + tree l = limb_access (type, var ? var : obj, idx, true); + g = gimple_build_assign (l, rhs); + insert_before (g); + if (!single_comparison) + { + m_gsi = gsi_after_labels (e4->src); + l = limb_access (type, var ? var : obj, + size_int (prec_limbs - 1), true); + if (!useless_type_conversion_p (TREE_TYPE (l), + TREE_TYPE (rhs))) + rhs = add_cast (TREE_TYPE (l), rhs); + g = gimple_build_assign (l, rhs); + insert_before (g); + } + m_gsi = gsi_after_labels (e2->dest); + } + else + { + tree l = limb_access (type, var ? var : obj, idx, true); + if (!useless_type_conversion_p (TREE_TYPE (l), TREE_TYPE (rhs))) + rhs = add_cast (TREE_TYPE (l), rhs); + g = gimple_build_assign (l, rhs); + insert_before (g); + } + } + m_first = false; + if (kind == bitint_prec_huge && i <= 1) + { + if (i == 0) + { + idx = make_ssa_name (sizetype); + g = gimple_build_assign (idx, PLUS_EXPR, idx_first, + size_one_node); + insert_before (g); + } + else + { + g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first, + size_int (2)); + insert_before (g); + g = gimple_build_cond (NE_EXPR, idx_next, size_int (fin), + NULL_TREE, NULL_TREE); + insert_before (g); + m_gsi = gsi_for_stmt (final_stmt); + } + } + } + + finish_arith_overflow (var, obj, type, ovf, lhs, orig_obj, stmt, code); +} + +/* Lower a .MUL_OVERFLOW call with at least one large/huge _BitInt + argument or return type _Complex large/huge _BitInt. */ + +void +bitint_large_huge::lower_mul_overflow (tree obj, gimple *stmt) +{ + tree arg0 = gimple_call_arg (stmt, 0); + tree arg1 = gimple_call_arg (stmt, 1); + tree lhs = gimple_call_lhs (stmt); + if (!lhs) + { + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + gsi_remove (&gsi, true); + return; + } + gimple *final_stmt = gsi_stmt (m_gsi); + tree type = TREE_TYPE (lhs); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + int prec = TYPE_PRECISION (type), prec0, prec1; + arg0 = handle_operand_addr (arg0, stmt, NULL, &prec0); + arg1 = handle_operand_addr (arg1, stmt, NULL, &prec1); + int prec2 = ((prec0 < 0 ? -prec0 : prec0) + + (prec1 < 0 ? -prec1 : prec1) + + ((prec0 < 0) != (prec1 < 0))); + tree var = NULL_TREE; + tree orig_obj = obj; + bool force_var = false; + if (obj == NULL_TREE + && TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large + && m_names + && bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs))) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + obj = m_vars[part]; + if (TREE_TYPE (lhs) == type) + orig_obj = obj; + } + else if (obj != NULL_TREE && DECL_P (obj)) + { + for (int i = 0; i < 2; ++i) + { + tree arg = i ? arg1 : arg0; + if (TREE_CODE (arg) == ADDR_EXPR) + arg = TREE_OPERAND (arg, 0); + if (get_base_address (arg) == obj) + { + force_var = true; + break; + } + } + } + if (obj == NULL_TREE + || force_var + || TREE_CODE (type) != BITINT_TYPE + || bitint_precision_kind (type) < bitint_prec_large + || prec2 > (CEIL (prec, limb_prec) * limb_prec * (orig_obj ? 1 : 2))) + { + unsigned HOST_WIDE_INT nelts = CEIL (MAX (prec, prec2), limb_prec); + tree atype = build_array_type_nelts (m_limb_type, nelts); + var = create_tmp_var (atype); + } + tree addr = build_fold_addr_expr (var ? var : obj); + addr = force_gimple_operand_gsi (&m_gsi, addr, true, + NULL_TREE, true, GSI_SAME_STMT); + tree sitype = lang_hooks.types.type_for_mode (SImode, 0); + gimple *g + = gimple_build_call_internal (IFN_MULBITINT, 6, + addr, build_int_cst (sitype, + MAX (prec2, prec)), + arg0, build_int_cst (sitype, prec0), + arg1, build_int_cst (sitype, prec1)); + insert_before (g); + + unsigned start, end; + bool check_zero; + tree ovf = arith_overflow (MULT_EXPR, type, prec, prec0, prec1, prec2, + &start, &end, &check_zero); + if (ovf == NULL_TREE) + { + unsigned startlimb = start / limb_prec; + unsigned endlimb = (end - 1) / limb_prec; + unsigned cnt; + bool use_loop = false; + if (startlimb == endlimb) + cnt = 1; + else if (startlimb + 1 == endlimb) + cnt = 2; + else if ((end % limb_prec) == 0) + { + cnt = 2; + use_loop = true; + } + else + { + cnt = 3; + use_loop = startlimb + 2 < endlimb; + } + if (cnt == 1) + { + tree l = limb_access (NULL_TREE, var ? var : obj, + size_int (startlimb), true); + g = gimple_build_assign (make_ssa_name (m_limb_type), l); + insert_before (g); + l = arith_overflow_extract_bits (start, end, gimple_assign_lhs (g), + startlimb, check_zero); + ovf = make_ssa_name (boolean_type_node); + if (check_zero) + g = gimple_build_assign (ovf, NE_EXPR, l, + build_zero_cst (m_limb_type)); + else + { + g = gimple_build_assign (make_ssa_name (m_limb_type), + PLUS_EXPR, l, + build_int_cst (m_limb_type, 1)); + insert_before (g); + g = gimple_build_assign (ovf, GT_EXPR, gimple_assign_lhs (g), + build_int_cst (m_limb_type, 1)); + } + insert_before (g); + } + else + { + basic_block edge_bb = NULL; + gimple_stmt_iterator gsi = m_gsi; + gsi_prev (&gsi); + edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); + edge_bb = e->src; + m_gsi = gsi_last_bb (edge_bb); + if (!gsi_end_p (m_gsi)) + gsi_next (&m_gsi); + + tree cmp = build_zero_cst (m_limb_type); + for (unsigned i = 0; i < cnt; i++) + { + tree idx, idx_next = NULL_TREE; + if (i == 0) + idx = size_int (startlimb); + else if (i == 2) + idx = size_int (endlimb); + else if (use_loop) + idx = create_loop (size_int (startlimb + 1), &idx_next); + else + idx = size_int (startlimb + 1); + tree l = limb_access (NULL_TREE, var ? var : obj, idx, true); + g = gimple_build_assign (make_ssa_name (m_limb_type), l); + insert_before (g); + l = gimple_assign_lhs (g); + if (i == 0 || i == 2) + l = arith_overflow_extract_bits (start, end, l, + tree_to_uhwi (idx), + check_zero); + if (i == 0 && !check_zero) + { + cmp = l; + g = gimple_build_assign (make_ssa_name (m_limb_type), + PLUS_EXPR, l, + build_int_cst (m_limb_type, 1)); + insert_before (g); + g = gimple_build_cond (GT_EXPR, gimple_assign_lhs (g), + build_int_cst (m_limb_type, 1), + NULL_TREE, NULL_TREE); + } + else + g = gimple_build_cond (NE_EXPR, l, cmp, NULL_TREE, NULL_TREE); + insert_before (g); + edge e1 = split_block (gsi_bb (m_gsi), g); + e1->flags = EDGE_FALSE_VALUE; + edge e2 = make_edge (e1->src, gimple_bb (final_stmt), + EDGE_TRUE_VALUE); + e1->probability = profile_probability::likely (); + e2->probability = e1->probability.invert (); + if (i == 0) + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src); + m_gsi = gsi_after_labels (e1->dest); + if (i == 1 && use_loop) + { + g = gimple_build_assign (idx_next, PLUS_EXPR, idx, + size_one_node); + insert_before (g); + g = gimple_build_cond (NE_EXPR, idx_next, + size_int (endlimb + (cnt == 1)), + NULL_TREE, NULL_TREE); + insert_before (g); + edge true_edge, false_edge; + extract_true_false_edges_from_block (gsi_bb (m_gsi), + &true_edge, + &false_edge); + m_gsi = gsi_after_labels (false_edge->dest); + } + } + + ovf = make_ssa_name (boolean_type_node); + basic_block bb = gimple_bb (final_stmt); + gphi *phi = create_phi_node (ovf, bb); + edge e1 = find_edge (gsi_bb (m_gsi), bb); + edge_iterator ei; + FOR_EACH_EDGE (e, ei, bb->preds) + { + tree val = e == e1 ? boolean_false_node : boolean_true_node; + add_phi_arg (phi, val, e, UNKNOWN_LOCATION); + } + m_gsi = gsi_for_stmt (final_stmt); + } + } + + finish_arith_overflow (var, obj, type, ovf, lhs, orig_obj, stmt, MULT_EXPR); +} + +/* Lower REALPART_EXPR or IMAGPART_EXPR stmt extracting part of result from + .{ADD,SUB,MUL}_OVERFLOW call. */ + +void +bitint_large_huge::lower_cplxpart_stmt (tree obj, gimple *stmt) +{ + tree rhs1 = gimple_assign_rhs1 (stmt); + rhs1 = TREE_OPERAND (rhs1, 0); + if (obj == NULL_TREE) + { + int part = var_to_partition (m_map, gimple_assign_lhs (stmt)); + gcc_assert (m_vars[part] != NULL_TREE); + obj = m_vars[part]; + } + if (TREE_CODE (rhs1) == SSA_NAME + && (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))) + { + lower_call (obj, SSA_NAME_DEF_STMT (rhs1)); + return; + } + int part = var_to_partition (m_map, rhs1); + gcc_assert (m_vars[part] != NULL_TREE); + tree var = m_vars[part]; + unsigned HOST_WIDE_INT nelts + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec; + tree atype = build_array_type_nelts (m_limb_type, nelts); + if (!useless_type_conversion_p (atype, TREE_TYPE (obj))) + obj = build1 (VIEW_CONVERT_EXPR, atype, obj); + tree off = build_int_cst (build_pointer_type (TREE_TYPE (var)), + gimple_assign_rhs_code (stmt) == REALPART_EXPR + ? 0 : nelts * m_limb_size); + tree v2 = build2 (MEM_REF, atype, build_fold_addr_expr (var), off); + gimple *g = gimple_build_assign (obj, v2); + insert_before (g); +} + +/* Lower COMPLEX_EXPR stmt. */ + +void +bitint_large_huge::lower_complexexpr_stmt (gimple *stmt) +{ + tree lhs = gimple_assign_lhs (stmt); + tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs2 (stmt); + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + lhs = m_vars[part]; + unsigned HOST_WIDE_INT nelts + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (rhs1))) / limb_prec; + tree atype = build_array_type_nelts (m_limb_type, nelts); + tree zero = build_zero_cst (build_pointer_type (TREE_TYPE (lhs))); + tree v1 = build2 (MEM_REF, atype, build_fold_addr_expr (lhs), zero); + tree v2; + if (TREE_CODE (rhs1) == SSA_NAME) + { + part = var_to_partition (m_map, rhs1); + gcc_assert (m_vars[part] != NULL_TREE); + v2 = m_vars[part]; + } + else if (integer_zerop (rhs1)) + v2 = build_zero_cst (atype); + else + v2 = tree_output_constant_def (rhs1); + if (!useless_type_conversion_p (atype, TREE_TYPE (v2))) + v2 = build1 (VIEW_CONVERT_EXPR, atype, v2); + gimple *g = gimple_build_assign (v1, v2); + insert_before (g); + tree off = fold_convert (build_pointer_type (TREE_TYPE (lhs)), + TYPE_SIZE_UNIT (atype)); + v1 = build2 (MEM_REF, atype, build_fold_addr_expr (lhs), off); + if (TREE_CODE (rhs2) == SSA_NAME) + { + part = var_to_partition (m_map, rhs2); + gcc_assert (m_vars[part] != NULL_TREE); + v2 = m_vars[part]; + } + else if (integer_zerop (rhs2)) + v2 = build_zero_cst (atype); + else + v2 = tree_output_constant_def (rhs2); + if (!useless_type_conversion_p (atype, TREE_TYPE (v2))) + v2 = build1 (VIEW_CONVERT_EXPR, atype, v2); + g = gimple_build_assign (v1, v2); + insert_before (g); +} + +/* Lower a call statement with one or more large/huge _BitInt + arguments or large/huge _BitInt return value. */ + +void +bitint_large_huge::lower_call (tree obj, gimple *stmt) +{ + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + unsigned int nargs = gimple_call_num_args (stmt); + if (gimple_call_internal_p (stmt)) + switch (gimple_call_internal_fn (stmt)) + { + case IFN_ADD_OVERFLOW: + case IFN_SUB_OVERFLOW: + case IFN_UBSAN_CHECK_ADD: + case IFN_UBSAN_CHECK_SUB: + lower_addsub_overflow (obj, stmt); + return; + case IFN_MUL_OVERFLOW: + case IFN_UBSAN_CHECK_MUL: + lower_mul_overflow (obj, stmt); + return; + default: + break; + } + for (unsigned int i = 0; i < nargs; ++i) + { + tree arg = gimple_call_arg (stmt, i); + if (TREE_CODE (arg) != SSA_NAME + || TREE_CODE (TREE_TYPE (arg)) != BITINT_TYPE + || bitint_precision_kind (TREE_TYPE (arg)) <= bitint_prec_middle) + continue; + int p = var_to_partition (m_map, arg); + tree v = m_vars[p]; + gcc_assert (v != NULL_TREE); + if (!types_compatible_p (TREE_TYPE (arg), TREE_TYPE (v))) + v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg), v); + arg = make_ssa_name (TREE_TYPE (arg)); + gimple *g = gimple_build_assign (arg, v); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_call_set_arg (stmt, i, arg); + if (m_preserved == NULL) + m_preserved = BITMAP_ALLOC (NULL); + bitmap_set_bit (m_preserved, SSA_NAME_VERSION (arg)); + } + tree lhs = gimple_call_lhs (stmt); + if (lhs + && TREE_CODE (lhs) == SSA_NAME + && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large) + { + int p = var_to_partition (m_map, lhs); + tree v = m_vars[p]; + gcc_assert (v != NULL_TREE); + if (!types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (v))) + v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), v); + gimple_call_set_lhs (stmt, v); + SSA_NAME_DEF_STMT (lhs) = gimple_build_nop (); + } + update_stmt (stmt); +} + +/* Lower __asm STMT which involves large/huge _BitInt values. */ + +void +bitint_large_huge::lower_asm (gimple *stmt) +{ + gasm *g = as_a (stmt); + unsigned noutputs = gimple_asm_noutputs (g); + unsigned ninputs = gimple_asm_ninputs (g); + + for (unsigned i = 0; i < noutputs; ++i) + { + tree t = gimple_asm_output_op (g, i); + tree s = TREE_VALUE (t); + if (TREE_CODE (s) == SSA_NAME + && TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large) + { + int part = var_to_partition (m_map, s); + gcc_assert (m_vars[part] != NULL_TREE); + TREE_VALUE (t) = m_vars[part]; + } + } + for (unsigned i = 0; i < ninputs; ++i) + { + tree t = gimple_asm_input_op (g, i); + tree s = TREE_VALUE (t); + if (TREE_CODE (s) == SSA_NAME + && TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large) + { + int part = var_to_partition (m_map, s); + gcc_assert (m_vars[part] != NULL_TREE); + TREE_VALUE (t) = m_vars[part]; + } + } + update_stmt (stmt); +} + +/* Lower statement STMT which involves large/huge _BitInt values + into code accessing individual limbs. */ + +void +bitint_large_huge::lower_stmt (gimple *stmt) +{ + m_first = true; + m_lhs = NULL_TREE; + m_data.truncate (0); + m_data_cnt = 0; + m_gsi = gsi_for_stmt (stmt); + m_after_stmt = NULL; + m_bb = NULL; + m_init_gsi = m_gsi; + gsi_prev (&m_init_gsi); + m_preheader_bb = NULL; + m_upwards_2limb = 0; + m_var_msb = false; + m_loc = gimple_location (stmt); + if (is_gimple_call (stmt)) + { + lower_call (NULL_TREE, stmt); + return; + } + if (gimple_code (stmt) == GIMPLE_ASM) + { + lower_asm (stmt); + return; + } + tree lhs = NULL_TREE, cmp_op1 = NULL_TREE, cmp_op2 = NULL_TREE; + tree_code cmp_code = comparison_op (stmt, &cmp_op1, &cmp_op2); + bool eq_p = (cmp_code == EQ_EXPR || cmp_code == NE_EXPR); + bool mergeable_cast_p = false; + bool final_cast_p = false; + if (gimple_assign_cast_p (stmt)) + { + lhs = gimple_assign_lhs (stmt); + tree rhs1 = gimple_assign_rhs1 (stmt); + if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large + && INTEGRAL_TYPE_P (TREE_TYPE (rhs1))) + mergeable_cast_p = true; + else if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large + && INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + { + final_cast_p = true; + if (TREE_CODE (rhs1) == SSA_NAME + && (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))) + { + gimple *g = SSA_NAME_DEF_STMT (rhs1); + if (is_gimple_assign (g) + && gimple_assign_rhs_code (g) == IMAGPART_EXPR) + { + tree rhs2 = TREE_OPERAND (gimple_assign_rhs1 (g), 0); + if (TREE_CODE (rhs2) == SSA_NAME + && (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs2)))) + { + g = SSA_NAME_DEF_STMT (rhs2); + int ovf = optimizable_arith_overflow (g); + if (ovf == 2) + /* If .{ADD,SUB,MUL}_OVERFLOW has both REALPART_EXPR + and IMAGPART_EXPR uses, where the latter is cast to + non-_BitInt, it will be optimized when handling + the REALPART_EXPR. */ + return; + if (ovf == 1) + { + lower_call (NULL_TREE, g); + return; + } + } + } + } + } + } + if (gimple_store_p (stmt)) + { + tree rhs1 = gimple_assign_rhs1 (stmt); + if (TREE_CODE (rhs1) == SSA_NAME + && (m_names == NULL + || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))) + { + gimple *g = SSA_NAME_DEF_STMT (rhs1); + m_loc = gimple_location (g); + lhs = gimple_assign_lhs (stmt); + if (is_gimple_assign (g) && !mergeable_op (g)) + switch (gimple_assign_rhs_code (g)) + { + case LSHIFT_EXPR: + case RSHIFT_EXPR: + lower_shift_stmt (lhs, g); + handled: + m_gsi = gsi_for_stmt (stmt); + unlink_stmt_vdef (stmt); + release_ssa_name (gimple_vdef (stmt)); + gsi_remove (&m_gsi, true); + return; + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + lower_muldiv_stmt (lhs, g); + goto handled; + case FIX_TRUNC_EXPR: + lower_float_conv_stmt (lhs, g); + goto handled; + case REALPART_EXPR: + case IMAGPART_EXPR: + lower_cplxpart_stmt (lhs, g); + goto handled; + default: + break; + } + else if (optimizable_arith_overflow (g) == 3) + { + lower_call (lhs, g); + goto handled; + } + m_loc = gimple_location (stmt); + } + } + if (mergeable_op (stmt) + || gimple_store_p (stmt) + || gimple_assign_load_p (stmt) + || eq_p + || mergeable_cast_p) + { + lhs = lower_mergeable_stmt (stmt, cmp_code, cmp_op1, cmp_op2); + if (!eq_p) + return; + } + else if (cmp_code != ERROR_MARK) + lhs = lower_comparison_stmt (stmt, cmp_code, cmp_op1, cmp_op2); + if (cmp_code != ERROR_MARK) + { + if (gimple_code (stmt) == GIMPLE_COND) + { + gcond *cstmt = as_a (stmt); + gimple_cond_set_lhs (cstmt, lhs); + gimple_cond_set_rhs (cstmt, boolean_false_node); + gimple_cond_set_code (cstmt, cmp_code); + update_stmt (stmt); + return; + } + if (gimple_assign_rhs_code (stmt) == COND_EXPR) + { + tree cond = build2 (cmp_code, boolean_type_node, lhs, + boolean_false_node); + gimple_assign_set_rhs1 (stmt, cond); + lhs = gimple_assign_lhs (stmt); + gcc_assert (TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE + || (bitint_precision_kind (TREE_TYPE (lhs)) + <= bitint_prec_middle)); + update_stmt (stmt); + return; + } + gimple_assign_set_rhs1 (stmt, lhs); + gimple_assign_set_rhs2 (stmt, boolean_false_node); + gimple_assign_set_rhs_code (stmt, cmp_code); + update_stmt (stmt); + return; + } + if (final_cast_p) + { + tree lhs_type = TREE_TYPE (lhs); + /* Add support for 3 or more limbs filled in from normal integral + type if this assert fails. If no target chooses limb mode smaller + than half of largest supported normal integral type, this will not + be needed. */ + gcc_assert (TYPE_PRECISION (lhs_type) <= 2 * limb_prec); + gimple *g; + if (TREE_CODE (lhs_type) == BITINT_TYPE + && bitint_precision_kind (lhs_type) == bitint_prec_middle) + lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (lhs_type), + TYPE_UNSIGNED (lhs_type)); + m_data_cnt = 0; + tree rhs1 = gimple_assign_rhs1 (stmt); + tree r1 = handle_operand (rhs1, size_int (0)); + if (!useless_type_conversion_p (lhs_type, TREE_TYPE (r1))) + r1 = add_cast (lhs_type, r1); + if (TYPE_PRECISION (lhs_type) > limb_prec) + { + m_data_cnt = 0; + m_first = false; + tree r2 = handle_operand (rhs1, size_int (1)); + r2 = add_cast (lhs_type, r2); + g = gimple_build_assign (make_ssa_name (lhs_type), LSHIFT_EXPR, r2, + build_int_cst (unsigned_type_node, + limb_prec)); + insert_before (g); + g = gimple_build_assign (make_ssa_name (lhs_type), BIT_IOR_EXPR, r1, + gimple_assign_lhs (g)); + insert_before (g); + r1 = gimple_assign_lhs (g); + } + if (lhs_type != TREE_TYPE (lhs)) + g = gimple_build_assign (lhs, NOP_EXPR, r1); + else + g = gimple_build_assign (lhs, r1); + gsi_replace (&m_gsi, g, true); + return; + } + if (is_gimple_assign (stmt)) + switch (gimple_assign_rhs_code (stmt)) + { + case LSHIFT_EXPR: + case RSHIFT_EXPR: + lower_shift_stmt (NULL_TREE, stmt); + return; + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + lower_muldiv_stmt (NULL_TREE, stmt); + return; + case FIX_TRUNC_EXPR: + case FLOAT_EXPR: + lower_float_conv_stmt (NULL_TREE, stmt); + return; + case REALPART_EXPR: + case IMAGPART_EXPR: + lower_cplxpart_stmt (NULL_TREE, stmt); + return; + case COMPLEX_EXPR: + lower_complexexpr_stmt (stmt); + return; + default: + break; + } + gcc_unreachable (); +} + +/* Helper for walk_non_aliased_vuses. Determine if we arrived at + the desired memory state. */ + +void * +vuse_eq (ao_ref *, tree vuse1, void *data) +{ + tree vuse2 = (tree) data; + if (vuse1 == vuse2) + return data; + + return NULL; +} + +/* Dominator walker used to discover which large/huge _BitInt + loads could be sunk into all their uses. */ + +class bitint_dom_walker : public dom_walker +{ +public: + bitint_dom_walker (bitmap names, bitmap loads) + : dom_walker (CDI_DOMINATORS), m_names (names), m_loads (loads) {} + + edge before_dom_children (basic_block) final override; + +private: + bitmap m_names, m_loads; +}; + +edge +bitint_dom_walker::before_dom_children (basic_block bb) +{ + gphi *phi = get_virtual_phi (bb); + tree vop; + if (phi) + vop = gimple_phi_result (phi); + else if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)) + vop = NULL_TREE; + else + vop = (tree) get_immediate_dominator (CDI_DOMINATORS, bb)->aux; + + auto_vec worklist; + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); + !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + if (is_gimple_debug (stmt)) + continue; + + if (!vop && gimple_vuse (stmt)) + vop = gimple_vuse (stmt); + + tree cvop = vop; + if (gimple_vdef (stmt)) + vop = gimple_vdef (stmt); + + tree lhs = gimple_get_lhs (stmt); + if (lhs + && TREE_CODE (lhs) == SSA_NAME + && TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large + && !bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs))) + /* If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names, + it means it will be handled in a loop or straight line code + at the location of its (ultimate) immediate use, so for + vop checking purposes check these only at the ultimate + immediate use. */ + continue; + + ssa_op_iter oi; + use_operand_p use_p; + FOR_EACH_SSA_USE_OPERAND (use_p, stmt, oi, SSA_OP_USE) + { + tree s = USE_FROM_PTR (use_p); + if (TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large) + worklist.safe_push (s); + } + + while (worklist.length () > 0) + { + tree s = worklist.pop (); + + if (!bitmap_bit_p (m_names, SSA_NAME_VERSION (s))) + { + FOR_EACH_SSA_USE_OPERAND (use_p, SSA_NAME_DEF_STMT (s), + oi, SSA_OP_USE) + { + tree s2 = USE_FROM_PTR (use_p); + if (TREE_CODE (TREE_TYPE (s2)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (s2)) + >= bitint_prec_large)) + worklist.safe_push (s2); + } + continue; + } + if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s) + && gimple_assign_cast_p (SSA_NAME_DEF_STMT (s))) + { + tree rhs = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)); + if (TREE_CODE (rhs) == SSA_NAME + && bitmap_bit_p (m_loads, SSA_NAME_VERSION (rhs))) + s = rhs; + else + continue; + } + else if (!bitmap_bit_p (m_loads, SSA_NAME_VERSION (s))) + continue; + + ao_ref ref; + ao_ref_init (&ref, gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s))); + tree lvop = gimple_vuse (SSA_NAME_DEF_STMT (s)); + unsigned limit = 64; + tree vuse = cvop; + if (vop != cvop + && is_gimple_assign (stmt) + && gimple_store_p (stmt) + && !operand_equal_p (lhs, + gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)), + 0)) + vuse = vop; + if (vuse != lvop + && walk_non_aliased_vuses (&ref, vuse, false, vuse_eq, + NULL, NULL, limit, lvop) == NULL) + bitmap_clear_bit (m_loads, SSA_NAME_VERSION (s)); + } + } + + bb->aux = (void *) vop; + return NULL; +} + +} + +/* Replacement for normal processing of STMT in tree-ssa-coalesce.cc + build_ssa_conflict_graph. + The differences are: + 1) don't process assignments with large/huge _BitInt lhs not in NAMES + 2) for large/huge _BitInt multiplication/division/modulo process def + only after processing uses rather than before to make uses conflict + with the definition + 3) for large/huge _BitInt uses not in NAMES mark the uses of their + SSA_NAME_DEF_STMT (recursively), because those uses will be sunk into + the final statement. */ + +void +build_bitint_stmt_ssa_conflicts (gimple *stmt, live_track *live, + ssa_conflicts *graph, bitmap names, + void (*def) (live_track *, tree, + ssa_conflicts *), + void (*use) (live_track *, tree)) +{ + bool muldiv_p = false; + tree lhs = NULL_TREE; + if (is_gimple_assign (stmt)) + { + lhs = gimple_assign_lhs (stmt); + if (TREE_CODE (lhs) == SSA_NAME + && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large) + { + if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs))) + return; + switch (gimple_assign_rhs_code (stmt)) + { + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + muldiv_p = true; + default: + break; + } + } + } + + ssa_op_iter iter; + tree var; + if (!muldiv_p) + { + /* For stmts with more than one SSA_NAME definition pretend all the + SSA_NAME outputs but the first one are live at this point, so + that conflicts are added in between all those even when they are + actually not really live after the asm, because expansion might + copy those into pseudos after the asm and if multiple outputs + share the same partition, it might overwrite those that should + be live. E.g. + asm volatile (".." : "=r" (a) : "=r" (b) : "0" (a), "1" (a)); + return a; + See PR70593. */ + bool first = true; + FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) + if (first) + first = false; + else + use (live, var); + + FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) + def (live, var, graph); + } + + auto_vec worklist; + FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE) + if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large) + { + if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) + use (live, var); + else + worklist.safe_push (var); + } + + while (worklist.length () > 0) + { + tree s = worklist.pop (); + FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_USE) + if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large) + { + if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) + use (live, var); + else + worklist.safe_push (var); + } + } + + if (muldiv_p) + def (live, lhs, graph); +} + +/* Entry point for _BitInt(N) operation lowering during optimization. */ + +static unsigned int +gimple_lower_bitint (void) +{ + small_max_prec = mid_min_prec = large_min_prec = huge_min_prec = 0; + limb_prec = 0; + + unsigned int i; + tree vop = gimple_vop (cfun); + for (i = 0; i < num_ssa_names; ++i) + { + tree s = ssa_name (i); + if (s == NULL) + continue; + tree type = TREE_TYPE (s); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) != bitint_prec_small) + break; + /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs + into memory. Such functions could have no large/huge SSA_NAMEs. */ + if (vop && SSA_NAME_VAR (s) == vop) + { + gimple *g = SSA_NAME_DEF_STMT (s); + if (is_gimple_assign (g) && gimple_store_p (g)) + { + tree t = gimple_assign_rhs1 (g); + if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (t)) + >= bitint_prec_large)) + break; + } + } + } + if (i == num_ssa_names) + return 0; + + basic_block bb; + auto_vec switch_statements; + FOR_EACH_BB_FN (bb, cfun) + { + if (gswitch *swtch = safe_dyn_cast (*gsi_last_bb (bb))) + { + tree idx = gimple_switch_index (swtch); + if (TREE_CODE (TREE_TYPE (idx)) != BITINT_TYPE + || bitint_precision_kind (TREE_TYPE (idx)) < bitint_prec_large) + continue; + + if (optimize) + group_case_labels_stmt (swtch); + switch_statements.safe_push (swtch); + } + } + + if (!switch_statements.is_empty ()) + { + bool expanded = false; + gimple *stmt; + unsigned int j; + i = 0; + FOR_EACH_VEC_ELT (switch_statements, j, stmt) + { + gswitch *swtch = as_a (stmt); + tree_switch_conversion::switch_decision_tree dt (swtch); + expanded |= dt.analyze_switch_statement (); + } + + if (expanded) + { + free_dominance_info (CDI_DOMINATORS); + free_dominance_info (CDI_POST_DOMINATORS); + mark_virtual_operands_for_renaming (cfun); + cleanup_tree_cfg (TODO_update_ssa); + } + } + + struct bitint_large_huge large_huge; + bool has_large_huge_parm_result = false; + bool has_large_huge = false; + unsigned int ret = 0, first_large_huge = ~0U; + bool edge_insertions = false; + for (; i < num_ssa_names; ++i) + { + tree s = ssa_name (i); + if (s == NULL) + continue; + tree type = TREE_TYPE (s); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large) + { + if (first_large_huge == ~0U) + first_large_huge = i; + gimple *stmt = SSA_NAME_DEF_STMT (s), *g; + gimple_stmt_iterator gsi; + tree_code rhs_code; + /* Unoptimize certain constructs to simpler alternatives to + avoid having to lower all of them. */ + if (is_gimple_assign (stmt)) + switch (rhs_code = gimple_assign_rhs_code (stmt)) + { + default: + break; + case LROTATE_EXPR: + case RROTATE_EXPR: + { + first_large_huge = 0; + location_t loc = gimple_location (stmt); + gsi = gsi_for_stmt (stmt); + tree rhs1 = gimple_assign_rhs1 (stmt); + tree type = TREE_TYPE (rhs1); + tree n = gimple_assign_rhs2 (stmt), m; + tree p = build_int_cst (TREE_TYPE (n), + TYPE_PRECISION (type)); + if (TREE_CODE (n) == INTEGER_CST) + m = fold_build2 (MINUS_EXPR, TREE_TYPE (n), p, n); + else + { + m = make_ssa_name (TREE_TYPE (n)); + g = gimple_build_assign (m, MINUS_EXPR, p, n); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + } + if (!TYPE_UNSIGNED (type)) + { + tree utype = build_bitint_type (TYPE_PRECISION (type), + 1); + if (TREE_CODE (rhs1) == INTEGER_CST) + rhs1 = fold_convert (utype, rhs1); + else + { + tree t = make_ssa_name (type); + g = gimple_build_assign (t, NOP_EXPR, rhs1); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + } + } + g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)), + rhs_code == LROTATE_EXPR + ? LSHIFT_EXPR : RSHIFT_EXPR, + rhs1, n); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + tree op1 = gimple_assign_lhs (g); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)), + rhs_code == LROTATE_EXPR + ? RSHIFT_EXPR : LSHIFT_EXPR, + rhs1, m); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + tree op2 = gimple_assign_lhs (g); + tree lhs = gimple_assign_lhs (stmt); + if (!TYPE_UNSIGNED (type)) + { + g = gimple_build_assign (make_ssa_name (TREE_TYPE (op1)), + BIT_IOR_EXPR, op1, op2); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + g = gimple_build_assign (lhs, NOP_EXPR, + gimple_assign_lhs (g)); + } + else + g = gimple_build_assign (lhs, BIT_IOR_EXPR, op1, op2); + gsi_replace (&gsi, g, true); + gimple_set_location (g, loc); + } + break; + case ABS_EXPR: + case ABSU_EXPR: + case MIN_EXPR: + case MAX_EXPR: + case COND_EXPR: + first_large_huge = 0; + gsi = gsi_for_stmt (stmt); + tree lhs = gimple_assign_lhs (stmt); + tree rhs1 = gimple_assign_rhs1 (stmt), rhs2 = NULL_TREE; + location_t loc = gimple_location (stmt); + if (rhs_code == ABS_EXPR) + g = gimple_build_cond (LT_EXPR, rhs1, + build_zero_cst (TREE_TYPE (rhs1)), + NULL_TREE, NULL_TREE); + else if (rhs_code == ABSU_EXPR) + { + rhs2 = make_ssa_name (TREE_TYPE (lhs)); + g = gimple_build_assign (rhs2, NOP_EXPR, rhs1); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + g = gimple_build_cond (LT_EXPR, rhs1, + build_zero_cst (TREE_TYPE (rhs1)), + NULL_TREE, NULL_TREE); + rhs1 = rhs2; + } + else if (rhs_code == MIN_EXPR || rhs_code == MAX_EXPR) + { + rhs2 = gimple_assign_rhs2 (stmt); + if (TREE_CODE (rhs1) == INTEGER_CST) + std::swap (rhs1, rhs2); + g = gimple_build_cond (LT_EXPR, rhs1, rhs2, + NULL_TREE, NULL_TREE); + if (rhs_code == MAX_EXPR) + std::swap (rhs1, rhs2); + } + else + { + g = gimple_build_cond (TREE_CODE (rhs1), + TREE_OPERAND (rhs1, 0), + TREE_OPERAND (rhs1, 1), + NULL_TREE, NULL_TREE); + rhs1 = gimple_assign_rhs2 (stmt); + rhs2 = gimple_assign_rhs3 (stmt); + } + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + edge e1 = split_block (gsi_bb (gsi), g); + edge e2 = split_block (e1->dest, (gimple *) NULL); + edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE); + e3->probability = profile_probability::even (); + e1->flags = EDGE_TRUE_VALUE; + e1->probability = e3->probability.invert (); + if (dom_info_available_p (CDI_DOMINATORS)) + set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src); + if (rhs_code == ABS_EXPR || rhs_code == ABSU_EXPR) + { + gsi = gsi_after_labels (e1->dest); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)), + NEGATE_EXPR, rhs1); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + rhs2 = gimple_assign_lhs (g); + std::swap (rhs1, rhs2); + } + gsi = gsi_for_stmt (stmt); + gsi_remove (&gsi, true); + gphi *phi = create_phi_node (lhs, e2->dest); + add_phi_arg (phi, rhs1, e2, UNKNOWN_LOCATION); + add_phi_arg (phi, rhs2, e3, UNKNOWN_LOCATION); + break; + } + } + /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs + into memory. Such functions could have no large/huge SSA_NAMEs. */ + else if (vop && SSA_NAME_VAR (s) == vop) + { + gimple *g = SSA_NAME_DEF_STMT (s); + if (is_gimple_assign (g) && gimple_store_p (g)) + { + tree t = gimple_assign_rhs1 (g); + if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (t)) + >= bitint_prec_large)) + has_large_huge = true; + } + } + } + for (i = first_large_huge; i < num_ssa_names; ++i) + { + tree s = ssa_name (i); + if (s == NULL) + continue; + tree type = TREE_TYPE (s); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large) + { + use_operand_p use_p; + gimple *use_stmt; + has_large_huge = true; + if (optimize + && optimizable_arith_overflow (SSA_NAME_DEF_STMT (s))) + continue; + /* Ignore large/huge _BitInt SSA_NAMEs which have single use in + the same bb and could be handled in the same loop with the + immediate use. */ + if (optimize + && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s) + && single_imm_use (s, &use_p, &use_stmt) + && gimple_bb (SSA_NAME_DEF_STMT (s)) == gimple_bb (use_stmt)) + { + if (mergeable_op (SSA_NAME_DEF_STMT (s))) + { + if (mergeable_op (use_stmt)) + continue; + tree_code cmp_code = comparison_op (use_stmt, NULL, NULL); + if (cmp_code == EQ_EXPR || cmp_code == NE_EXPR) + continue; + if (gimple_assign_cast_p (use_stmt)) + { + tree lhs = gimple_assign_lhs (use_stmt); + if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + continue; + } + else if (gimple_store_p (use_stmt) + && is_gimple_assign (use_stmt) + && !gimple_has_volatile_ops (use_stmt) + && !stmt_ends_bb_p (use_stmt)) + continue; + } + if (gimple_assign_cast_p (SSA_NAME_DEF_STMT (s))) + { + tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)); + if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && ((is_gimple_assign (use_stmt) + && (gimple_assign_rhs_code (use_stmt) + != COMPLEX_EXPR)) + || gimple_code (use_stmt) == GIMPLE_COND) + && (!gimple_store_p (use_stmt) + || (is_gimple_assign (use_stmt) + && !gimple_has_volatile_ops (use_stmt) + && !stmt_ends_bb_p (use_stmt))) + && (TREE_CODE (rhs1) != SSA_NAME + || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))) + { + if (TREE_CODE (TREE_TYPE (rhs1)) != BITINT_TYPE + || (bitint_precision_kind (TREE_TYPE (rhs1)) + < bitint_prec_large) + || (TYPE_PRECISION (TREE_TYPE (rhs1)) + >= TYPE_PRECISION (TREE_TYPE (s))) + || mergeable_op (SSA_NAME_DEF_STMT (s))) + continue; + /* Prevent merging a widening non-mergeable cast + on result of some narrower mergeable op + together with later mergeable operations. E.g. + result of _BitInt(223) addition shouldn't be + sign-extended to _BitInt(513) and have another + _BitInt(513) added to it, as handle_plus_minus + with its PHI node handling inside of handle_cast + will not work correctly. An exception is if + use_stmt is a store, this is handled directly + in lower_mergeable_stmt. */ + if (TREE_CODE (rhs1) != SSA_NAME + || !has_single_use (rhs1) + || (gimple_bb (SSA_NAME_DEF_STMT (rhs1)) + != gimple_bb (SSA_NAME_DEF_STMT (s))) + || !mergeable_op (SSA_NAME_DEF_STMT (rhs1)) + || gimple_store_p (use_stmt)) + continue; + if (gimple_assign_cast_p (SSA_NAME_DEF_STMT (rhs1))) + { + /* Another exception is if the widening cast is + from mergeable same precision cast from something + not mergeable. */ + tree rhs2 + = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (rhs1)); + if (TREE_CODE (TREE_TYPE (rhs2)) == BITINT_TYPE + && (TYPE_PRECISION (TREE_TYPE (rhs1)) + == TYPE_PRECISION (TREE_TYPE (rhs2)))) + { + if (TREE_CODE (rhs2) != SSA_NAME + || !has_single_use (rhs2) + || (gimple_bb (SSA_NAME_DEF_STMT (rhs2)) + != gimple_bb (SSA_NAME_DEF_STMT (s))) + || !mergeable_op (SSA_NAME_DEF_STMT (rhs2))) + continue; + } + } + } + } + if (is_gimple_assign (SSA_NAME_DEF_STMT (s))) + switch (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (s))) + { + case IMAGPART_EXPR: + { + tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)); + rhs1 = TREE_OPERAND (rhs1, 0); + if (TREE_CODE (rhs1) == SSA_NAME) + { + gimple *g = SSA_NAME_DEF_STMT (rhs1); + if (optimizable_arith_overflow (g)) + continue; + } + } + /* FALLTHRU */ + case LSHIFT_EXPR: + case RSHIFT_EXPR: + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + case FIX_TRUNC_EXPR: + case REALPART_EXPR: + if (gimple_store_p (use_stmt) + && is_gimple_assign (use_stmt) + && !gimple_has_volatile_ops (use_stmt) + && !stmt_ends_bb_p (use_stmt)) + continue; + default: + break; + } + } + + /* Also ignore uninitialized uses. */ + if (SSA_NAME_IS_DEFAULT_DEF (s) + && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s)))) + continue; + + if (!large_huge.m_names) + large_huge.m_names = BITMAP_ALLOC (NULL); + bitmap_set_bit (large_huge.m_names, SSA_NAME_VERSION (s)); + if (has_single_use (s)) + { + if (!large_huge.m_single_use_names) + large_huge.m_single_use_names = BITMAP_ALLOC (NULL); + bitmap_set_bit (large_huge.m_single_use_names, + SSA_NAME_VERSION (s)); + } + if (SSA_NAME_VAR (s) + && ((TREE_CODE (SSA_NAME_VAR (s)) == PARM_DECL + && SSA_NAME_IS_DEFAULT_DEF (s)) + || TREE_CODE (SSA_NAME_VAR (s)) == RESULT_DECL)) + has_large_huge_parm_result = true; + if (optimize + && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s) + && gimple_assign_load_p (SSA_NAME_DEF_STMT (s)) + && !gimple_has_volatile_ops (SSA_NAME_DEF_STMT (s)) + && !stmt_ends_bb_p (SSA_NAME_DEF_STMT (s))) + { + use_operand_p use_p; + imm_use_iterator iter; + bool optimizable_load = true; + FOR_EACH_IMM_USE_FAST (use_p, iter, s) + { + gimple *use_stmt = USE_STMT (use_p); + if (is_gimple_debug (use_stmt)) + continue; + if (gimple_code (use_stmt) == GIMPLE_PHI + || is_gimple_call (use_stmt)) + { + optimizable_load = false; + break; + } + } + + ssa_op_iter oi; + FOR_EACH_SSA_USE_OPERAND (use_p, SSA_NAME_DEF_STMT (s), + oi, SSA_OP_USE) + { + tree s2 = USE_FROM_PTR (use_p); + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s2)) + { + optimizable_load = false; + break; + } + } + + if (optimizable_load && !stmt_ends_bb_p (SSA_NAME_DEF_STMT (s))) + { + if (!large_huge.m_loads) + large_huge.m_loads = BITMAP_ALLOC (NULL); + bitmap_set_bit (large_huge.m_loads, SSA_NAME_VERSION (s)); + } + } + } + /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs + into memory. Such functions could have no large/huge SSA_NAMEs. */ + else if (vop && SSA_NAME_VAR (s) == vop) + { + gimple *g = SSA_NAME_DEF_STMT (s); + if (is_gimple_assign (g) && gimple_store_p (g)) + { + tree t = gimple_assign_rhs1 (g); + if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (t)) >= bitint_prec_large) + has_large_huge = true; + } + } + } + + if (large_huge.m_names || has_large_huge) + { + ret = TODO_update_ssa_only_virtuals | TODO_cleanup_cfg; + calculate_dominance_info (CDI_DOMINATORS); + if (optimize) + enable_ranger (cfun); + if (large_huge.m_loads) + { + basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun); + entry->aux = NULL; + bitint_dom_walker (large_huge.m_names, + large_huge.m_loads).walk (entry); + bitmap_and_compl_into (large_huge.m_names, large_huge.m_loads); + clear_aux_for_blocks (); + BITMAP_FREE (large_huge.m_loads); + } + large_huge.m_limb_type = build_nonstandard_integer_type (limb_prec, 1); + large_huge.m_limb_size + = tree_to_uhwi (TYPE_SIZE_UNIT (large_huge.m_limb_type)); + } + if (large_huge.m_names) + { + large_huge.m_map + = init_var_map (num_ssa_names, NULL, large_huge.m_names); + coalesce_ssa_name (large_huge.m_map); + partition_view_normal (large_huge.m_map); + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "After Coalescing:\n"); + dump_var_map (dump_file, large_huge.m_map); + } + large_huge.m_vars + = XCNEWVEC (tree, num_var_partitions (large_huge.m_map)); + bitmap_iterator bi; + if (has_large_huge_parm_result) + EXECUTE_IF_SET_IN_BITMAP (large_huge.m_names, 0, i, bi) + { + tree s = ssa_name (i); + if (SSA_NAME_VAR (s) + && ((TREE_CODE (SSA_NAME_VAR (s)) == PARM_DECL + && SSA_NAME_IS_DEFAULT_DEF (s)) + || TREE_CODE (SSA_NAME_VAR (s)) == RESULT_DECL)) + { + int p = var_to_partition (large_huge.m_map, s); + if (large_huge.m_vars[p] == NULL_TREE) + { + large_huge.m_vars[p] = SSA_NAME_VAR (s); + mark_addressable (SSA_NAME_VAR (s)); + } + } + } + tree atype = NULL_TREE; + EXECUTE_IF_SET_IN_BITMAP (large_huge.m_names, 0, i, bi) + { + tree s = ssa_name (i); + int p = var_to_partition (large_huge.m_map, s); + if (large_huge.m_vars[p] != NULL_TREE) + continue; + if (atype == NULL_TREE + || !tree_int_cst_equal (TYPE_SIZE (atype), + TYPE_SIZE (TREE_TYPE (s)))) + { + unsigned HOST_WIDE_INT nelts + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (s))) / limb_prec; + atype = build_array_type_nelts (large_huge.m_limb_type, nelts); + } + large_huge.m_vars[p] = create_tmp_var (atype, "bitint"); + mark_addressable (large_huge.m_vars[p]); + } + } + + FOR_EACH_BB_REVERSE_FN (bb, cfun) + { + gimple_stmt_iterator prev; + for (gimple_stmt_iterator gsi = gsi_last_bb (bb); !gsi_end_p (gsi); + gsi = prev) + { + prev = gsi; + gsi_prev (&prev); + ssa_op_iter iter; + gimple *stmt = gsi_stmt (gsi); + if (is_gimple_debug (stmt)) + continue; + bitint_prec_kind kind = bitint_prec_small; + tree t; + FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, SSA_OP_ALL_OPERANDS) + if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE) + { + bitint_prec_kind this_kind + = bitint_precision_kind (TREE_TYPE (t)); + if (this_kind > kind) + kind = this_kind; + } + if (is_gimple_assign (stmt) && gimple_store_p (stmt)) + { + t = gimple_assign_rhs1 (stmt); + if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE) + { + bitint_prec_kind this_kind + = bitint_precision_kind (TREE_TYPE (t)); + if (this_kind > kind) + kind = this_kind; + } + } + if (is_gimple_call (stmt)) + { + t = gimple_call_lhs (stmt); + if (t + && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE + && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == BITINT_TYPE) + { + bitint_prec_kind this_kind + = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t))); + if (this_kind > kind) + kind = this_kind; + } + } + if (kind == bitint_prec_small) + continue; + switch (gimple_code (stmt)) + { + case GIMPLE_CALL: + /* For now. We'll need to handle some internal functions and + perhaps some builtins. */ + if (kind == bitint_prec_middle) + continue; + break; + case GIMPLE_ASM: + if (kind == bitint_prec_middle) + continue; + break; + case GIMPLE_RETURN: + continue; + case GIMPLE_ASSIGN: + if (gimple_clobber_p (stmt)) + continue; + if (kind >= bitint_prec_large) + break; + if (gimple_assign_single_p (stmt)) + /* No need to lower copies, loads or stores. */ + continue; + if (gimple_assign_cast_p (stmt)) + { + tree lhs = gimple_assign_lhs (stmt); + tree rhs = gimple_assign_rhs1 (stmt); + if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + && INTEGRAL_TYPE_P (TREE_TYPE (rhs)) + && (TYPE_PRECISION (TREE_TYPE (lhs)) + == TYPE_PRECISION (TREE_TYPE (rhs)))) + /* No need to lower casts to same precision. */ + continue; + } + break; + default: + break; + } + + if (kind == bitint_prec_middle) + { + tree type = NULL_TREE; + /* Middle _BitInt(N) is rewritten to casts to INTEGER_TYPEs + with the same precision and back. */ + if (tree lhs = gimple_get_lhs (stmt)) + if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (lhs)) + == bitint_prec_middle)) + { + int prec = TYPE_PRECISION (TREE_TYPE (lhs)); + int uns = TYPE_UNSIGNED (TREE_TYPE (lhs)); + type = build_nonstandard_integer_type (prec, uns); + tree lhs2 = make_ssa_name (type); + gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2); + gsi_insert_after (&gsi, g, GSI_SAME_STMT); + gimple_set_lhs (stmt, lhs2); + } + unsigned int nops = gimple_num_ops (stmt); + for (unsigned int i = 0; i < nops; ++i) + if (tree op = gimple_op (stmt, i)) + { + tree nop = maybe_cast_middle_bitint (&gsi, op, type); + if (nop != op) + gimple_set_op (stmt, i, nop); + else if (COMPARISON_CLASS_P (op)) + { + TREE_OPERAND (op, 0) + = maybe_cast_middle_bitint (&gsi, + TREE_OPERAND (op, 0), + type); + TREE_OPERAND (op, 1) + = maybe_cast_middle_bitint (&gsi, + TREE_OPERAND (op, 1), + type); + } + else if (TREE_CODE (op) == CASE_LABEL_EXPR) + { + CASE_LOW (op) + = maybe_cast_middle_bitint (&gsi, CASE_LOW (op), + type); + CASE_HIGH (op) + = maybe_cast_middle_bitint (&gsi, CASE_HIGH (op), + type); + } + } + update_stmt (stmt); + continue; + } + + if (tree lhs = gimple_get_lhs (stmt)) + if (TREE_CODE (lhs) == SSA_NAME) + { + tree type = TREE_TYPE (lhs); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large + && (large_huge.m_names == NULL + || !bitmap_bit_p (large_huge.m_names, + SSA_NAME_VERSION (lhs)))) + continue; + } + + large_huge.lower_stmt (stmt); + } + + tree atype = NULL_TREE; + for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); + gsi_next (&gsi)) + { + gphi *phi = gsi.phi (); + tree lhs = gimple_phi_result (phi); + if (TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE + || bitint_precision_kind (TREE_TYPE (lhs)) < bitint_prec_large) + continue; + int p1 = var_to_partition (large_huge.m_map, lhs); + gcc_assert (large_huge.m_vars[p1] != NULL_TREE); + tree v1 = large_huge.m_vars[p1]; + for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) + { + tree arg = gimple_phi_arg_def (phi, i); + edge e = gimple_phi_arg_edge (phi, i); + gimple *g; + switch (TREE_CODE (arg)) + { + case INTEGER_CST: + if (integer_zerop (arg) && VAR_P (v1)) + { + tree zero = build_zero_cst (TREE_TYPE (v1)); + g = gimple_build_assign (v1, zero); + gsi_insert_on_edge (e, g); + edge_insertions = true; + break; + } + int ext; + unsigned int min_prec, prec, rem; + tree c; + prec = TYPE_PRECISION (TREE_TYPE (arg)); + rem = prec % (2 * limb_prec); + min_prec = bitint_min_cst_precision (arg, ext); + if (min_prec > prec - rem - 2 * limb_prec + && min_prec > (unsigned) limb_prec) + /* Constant which has enough significant bits that it + isn't worth trying to save .rodata space by extending + from smaller number. */ + min_prec = prec; + else + min_prec = CEIL (min_prec, limb_prec) * limb_prec; + if (min_prec == 0) + c = NULL_TREE; + else if (min_prec == prec) + c = tree_output_constant_def (arg); + else if (min_prec == (unsigned) limb_prec) + c = fold_convert (large_huge.m_limb_type, arg); + else + { + tree ctype = build_bitint_type (min_prec, 1); + c = tree_output_constant_def (fold_convert (ctype, arg)); + } + if (c) + { + if (VAR_P (v1) && min_prec == prec) + { + tree v2 = build1 (VIEW_CONVERT_EXPR, + TREE_TYPE (v1), c); + g = gimple_build_assign (v1, v2); + gsi_insert_on_edge (e, g); + edge_insertions = true; + break; + } + if (TREE_CODE (TREE_TYPE (c)) == INTEGER_TYPE) + g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR, + TREE_TYPE (c), v1), + c); + else + { + unsigned HOST_WIDE_INT nelts + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (c))) + / limb_prec; + tree vtype + = build_array_type_nelts (large_huge.m_limb_type, + nelts); + g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR, + vtype, v1), + build1 (VIEW_CONVERT_EXPR, + vtype, c)); + } + gsi_insert_on_edge (e, g); + } + if (ext == 0) + { + unsigned HOST_WIDE_INT nelts + = (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (v1))) + - min_prec) / limb_prec; + tree vtype + = build_array_type_nelts (large_huge.m_limb_type, + nelts); + tree ptype = build_pointer_type (TREE_TYPE (v1)); + tree off = fold_convert (ptype, + TYPE_SIZE_UNIT (TREE_TYPE (c))); + tree vd = build2 (MEM_REF, vtype, + build_fold_addr_expr (v1), off); + g = gimple_build_assign (vd, build_zero_cst (vtype)); + } + else + { + tree vd = v1; + if (c) + { + tree ptype = build_pointer_type (TREE_TYPE (v1)); + tree off + = fold_convert (ptype, + TYPE_SIZE_UNIT (TREE_TYPE (c))); + vd = build2 (MEM_REF, large_huge.m_limb_type, + build_fold_addr_expr (v1), off); + } + vd = build_fold_addr_expr (vd); + unsigned HOST_WIDE_INT nbytes + = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (v1))); + if (c) + nbytes + -= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (c))); + tree fn = builtin_decl_implicit (BUILT_IN_MEMSET); + g = gimple_build_call (fn, 3, vd, + integer_minus_one_node, + build_int_cst (sizetype, + nbytes)); + } + gsi_insert_on_edge (e, g); + edge_insertions = true; + break; + default: + gcc_unreachable (); + case SSA_NAME: + if (gimple_code (SSA_NAME_DEF_STMT (arg)) == GIMPLE_NOP) + { + if (large_huge.m_names == NULL + || !bitmap_bit_p (large_huge.m_names, + SSA_NAME_VERSION (arg))) + continue; + } + int p2 = var_to_partition (large_huge.m_map, arg); + if (p1 == p2) + continue; + gcc_assert (large_huge.m_vars[p2] != NULL_TREE); + tree v2 = large_huge.m_vars[p2]; + if (VAR_P (v1) && VAR_P (v2)) + g = gimple_build_assign (v1, v2); + else if (VAR_P (v1)) + g = gimple_build_assign (v1, build1 (VIEW_CONVERT_EXPR, + TREE_TYPE (v1), v2)); + else if (VAR_P (v2)) + g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR, + TREE_TYPE (v2), v1), v2); + else + { + if (atype == NULL_TREE + || !tree_int_cst_equal (TYPE_SIZE (atype), + TYPE_SIZE (TREE_TYPE (lhs)))) + { + unsigned HOST_WIDE_INT nelts + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs))) + / limb_prec; + atype + = build_array_type_nelts (large_huge.m_limb_type, + nelts); + } + g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR, + atype, v1), + build1 (VIEW_CONVERT_EXPR, + atype, v2)); + } + gsi_insert_on_edge (e, g); + edge_insertions = true; + break; + } + } + } + } + + if (large_huge.m_names || has_large_huge) + { + gimple *nop = NULL; + for (i = 0; i < num_ssa_names; ++i) + { + tree s = ssa_name (i); + if (s == NULL_TREE) + continue; + tree type = TREE_TYPE (s); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large) + { + if (large_huge.m_preserved + && bitmap_bit_p (large_huge.m_preserved, + SSA_NAME_VERSION (s))) + continue; + gimple *g = SSA_NAME_DEF_STMT (s); + if (gimple_code (g) == GIMPLE_NOP) + { + if (SSA_NAME_VAR (s)) + set_ssa_default_def (cfun, SSA_NAME_VAR (s), NULL_TREE); + release_ssa_name (s); + continue; + } + if (gimple_code (g) != GIMPLE_ASM) + { + gimple_stmt_iterator gsi = gsi_for_stmt (g); + bool save_vta = flag_var_tracking_assignments; + flag_var_tracking_assignments = false; + gsi_remove (&gsi, true); + flag_var_tracking_assignments = save_vta; + } + if (nop == NULL) + nop = gimple_build_nop (); + SSA_NAME_DEF_STMT (s) = nop; + release_ssa_name (s); + } + } + if (optimize) + disable_ranger (cfun); + } + + if (edge_insertions) + gsi_commit_edge_inserts (); + + return ret; +} + +namespace { + +const pass_data pass_data_lower_bitint = +{ + GIMPLE_PASS, /* type */ + "bitintlower", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + PROP_ssa, /* properties_required */ + PROP_gimple_lbitint, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_lower_bitint : public gimple_opt_pass +{ +public: + pass_lower_bitint (gcc::context *ctxt) + : gimple_opt_pass (pass_data_lower_bitint, ctxt) + {} + + /* opt_pass methods: */ + opt_pass * clone () final override { return new pass_lower_bitint (m_ctxt); } + unsigned int execute (function *) final override + { + return gimple_lower_bitint (); + } + +}; // class pass_lower_bitint + +} // anon namespace + +gimple_opt_pass * +make_pass_lower_bitint (gcc::context *ctxt) +{ + return new pass_lower_bitint (ctxt); +} + + +namespace { + +const pass_data pass_data_lower_bitint_O0 = +{ + GIMPLE_PASS, /* type */ + "bitintlower0", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + PROP_cfg, /* properties_required */ + PROP_gimple_lbitint, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_lower_bitint_O0 : public gimple_opt_pass +{ +public: + pass_lower_bitint_O0 (gcc::context *ctxt) + : gimple_opt_pass (pass_data_lower_bitint_O0, ctxt) + {} + + /* opt_pass methods: */ + bool gate (function *fun) final override + { + /* With errors, normal optimization passes are not run. If we don't + lower bitint operations at all, rtl expansion will abort. */ + return !(fun->curr_properties & PROP_gimple_lbitint); + } + + unsigned int execute (function *) final override + { + return gimple_lower_bitint (); + } + +}; // class pass_lower_bitint_O0 + +} // anon namespace + +gimple_opt_pass * +make_pass_lower_bitint_O0 (gcc::context *ctxt) +{ + return new pass_lower_bitint_O0 (ctxt); +} --- gcc/gimple-lower-bitint.h.jj 2023-07-27 15:03:24.287233711 +0200 +++ gcc/gimple-lower-bitint.h 2023-07-27 15:03:24.287233711 +0200 @@ -0,0 +1,31 @@ +/* Header file for gimple-lower-bitint.cc exports. + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_GIMPLE_LOWER_BITINT_H +#define GCC_GIMPLE_LOWER_BITINT_H + +class live_track; +struct ssa_conflicts; +extern void build_bitint_stmt_ssa_conflicts (gimple *, live_track *, + ssa_conflicts *, bitmap, + void (*) (live_track *, tree, + ssa_conflicts *), + void (*) (live_track *, tree)); + +#endif /* GCC_GIMPLE_LOWER_BITINT_H */ --- gcc/internal-fn.cc.jj 2023-07-24 17:48:26.494040524 +0200 +++ gcc/internal-fn.cc 2023-07-27 15:03:24.288233697 +0200 @@ -981,8 +981,38 @@ expand_arith_overflow_result_store (tree /* Helper for expand_*_overflow. Store RES into TARGET. */ static void -expand_ubsan_result_store (rtx target, rtx res) +expand_ubsan_result_store (tree lhs, rtx target, scalar_int_mode mode, + rtx res, rtx_code_label *do_error) { + if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && TYPE_PRECISION (TREE_TYPE (lhs)) < GET_MODE_PRECISION (mode)) + { + int uns = TYPE_UNSIGNED (TREE_TYPE (lhs)); + int prec = TYPE_PRECISION (TREE_TYPE (lhs)); + int tgtprec = GET_MODE_PRECISION (mode); + rtx resc = gen_reg_rtx (mode), lres; + emit_move_insn (resc, res); + if (uns) + { + rtx mask + = immed_wide_int_const (wi::shifted_mask (0, prec, false, tgtprec), + mode); + lres = expand_simple_binop (mode, AND, res, mask, NULL_RTX, + true, OPTAB_LIB_WIDEN); + } + else + { + lres = expand_shift (LSHIFT_EXPR, mode, res, tgtprec - prec, + NULL_RTX, 1); + lres = expand_shift (RSHIFT_EXPR, mode, lres, tgtprec - prec, + NULL_RTX, 0); + } + if (lres != res) + emit_move_insn (res, lres); + do_compare_rtx_and_jump (res, resc, + NE, true, mode, NULL_RTX, NULL, do_error, + profile_probability::very_unlikely ()); + } if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target)) /* If this is a scalar in a register that is stored in a wider mode than the declared mode, compute the result into its declared mode @@ -1431,7 +1461,7 @@ expand_addsub_overflow (location_t loc, if (lhs) { if (is_ubsan) - expand_ubsan_result_store (target, res); + expand_ubsan_result_store (lhs, target, mode, res, do_error); else { if (do_xor) @@ -1528,7 +1558,7 @@ expand_neg_overflow (location_t loc, tre if (lhs) { if (is_ubsan) - expand_ubsan_result_store (target, res); + expand_ubsan_result_store (lhs, target, mode, res, do_error); else expand_arith_overflow_result_store (lhs, target, mode, res); } @@ -1646,6 +1676,12 @@ expand_mul_overflow (location_t loc, tre int pos_neg0 = get_range_pos_neg (arg0); int pos_neg1 = get_range_pos_neg (arg1); + /* Unsigned types with smaller than mode precision, even if they have most + significant bit set, are still zero-extended. */ + if (uns0_p && TYPE_PRECISION (TREE_TYPE (arg0)) < GET_MODE_PRECISION (mode)) + pos_neg0 = 1; + if (uns1_p && TYPE_PRECISION (TREE_TYPE (arg1)) < GET_MODE_PRECISION (mode)) + pos_neg1 = 1; /* s1 * u2 -> ur */ if (!uns0_p && uns1_p && unsr_p) @@ -2414,7 +2450,7 @@ expand_mul_overflow (location_t loc, tre if (lhs) { if (is_ubsan) - expand_ubsan_result_store (target, res); + expand_ubsan_result_store (lhs, target, mode, res, do_error); else expand_arith_overflow_result_store (lhs, target, mode, res); } @@ -4899,3 +4935,76 @@ expand_MASK_CALL (internal_fn, gcall *) /* This IFN should only exist between ifcvt and vect passes. */ gcc_unreachable (); } + +void +expand_MULBITINT (internal_fn, gcall *stmt) +{ + rtx_mode_t args[6]; + for (int i = 0; i < 6; i++) + args[i] = rtx_mode_t (expand_normal (gimple_call_arg (stmt, i)), + (i & 1) ? SImode : ptr_mode); + rtx fun = init_one_libfunc ("__mulbitint3"); + emit_library_call_value_1 (0, fun, NULL_RTX, LCT_NORMAL, VOIDmode, 6, args); +} + +void +expand_DIVMODBITINT (internal_fn, gcall *stmt) +{ + rtx_mode_t args[8]; + for (int i = 0; i < 8; i++) + args[i] = rtx_mode_t (expand_normal (gimple_call_arg (stmt, i)), + (i & 1) ? SImode : ptr_mode); + rtx fun = init_one_libfunc ("__divmodbitint4"); + emit_library_call_value_1 (0, fun, NULL_RTX, LCT_NORMAL, VOIDmode, 8, args); +} + +void +expand_FLOATTOBITINT (internal_fn, gcall *stmt) +{ + machine_mode mode = TYPE_MODE (TREE_TYPE (gimple_call_arg (stmt, 2))); + rtx arg0 = expand_normal (gimple_call_arg (stmt, 0)); + rtx arg1 = expand_normal (gimple_call_arg (stmt, 1)); + rtx arg2 = expand_normal (gimple_call_arg (stmt, 2)); + const char *mname = GET_MODE_NAME (mode); + unsigned mname_len = strlen (mname); + int len = 12 + mname_len; + char *libfunc_name = XALLOCAVEC (char, len); + char *p = libfunc_name; + const char *q; + memcpy (p, "__fix", 5); + p += 5; + for (q = mname; *q; q++) + *p++ = TOLOWER (*q); + memcpy (p, "bitint", 7); + rtx fun = init_one_libfunc (libfunc_name); + emit_library_call (fun, LCT_NORMAL, VOIDmode, arg0, ptr_mode, arg1, + SImode, arg2, mode); +} + +void +expand_BITINTTOFLOAT (internal_fn, gcall *stmt) +{ + tree lhs = gimple_call_lhs (stmt); + if (!lhs) + return; + machine_mode mode = TYPE_MODE (TREE_TYPE (lhs)); + rtx arg0 = expand_normal (gimple_call_arg (stmt, 0)); + rtx arg1 = expand_normal (gimple_call_arg (stmt, 1)); + const char *mname = GET_MODE_NAME (mode); + unsigned mname_len = strlen (mname); + int len = 14 + mname_len; + char *libfunc_name = XALLOCAVEC (char, len); + char *p = libfunc_name; + const char *q; + memcpy (p, "__floatbitint", 13); + p += 13; + for (q = mname; *q; q++) + *p++ = TOLOWER (*q); + *p = '\0'; + rtx fun = init_one_libfunc (libfunc_name); + rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); + rtx val = emit_library_call_value (fun, target, LCT_PURE, mode, + arg0, ptr_mode, arg1, SImode); + if (val != target) + emit_move_insn (target, val); +} --- gcc/internal-fn.def.jj 2023-07-24 17:48:26.494040524 +0200 +++ gcc/internal-fn.def 2023-07-27 15:03:24.259234103 +0200 @@ -559,6 +559,12 @@ DEF_INTERNAL_FN (ASSUME, ECF_CONST | ECF /* For if-conversion of inbranch SIMD clones. */ DEF_INTERNAL_FN (MASK_CALL, ECF_NOVOPS, NULL) +/* _BitInt support. */ +DEF_INTERNAL_FN (MULBITINT, ECF_LEAF | ECF_NOTHROW, ". O . R . R . ") +DEF_INTERNAL_FN (DIVMODBITINT, ECF_LEAF, ". O . O . R . R . ") +DEF_INTERNAL_FN (FLOATTOBITINT, ECF_LEAF | ECF_NOTHROW, ". O . . ") +DEF_INTERNAL_FN (BITINTTOFLOAT, ECF_PURE | ECF_LEAF, ". R . ") + #undef DEF_INTERNAL_INT_FN #undef DEF_INTERNAL_FLT_FN #undef DEF_INTERNAL_FLT_FLOATN_FN --- gcc/internal-fn.h.jj 2023-07-17 09:07:42.071283977 +0200 +++ gcc/internal-fn.h 2023-07-27 15:03:24.231234494 +0200 @@ -256,6 +256,10 @@ extern void expand_SPACESHIP (internal_f extern void expand_TRAP (internal_fn, gcall *); extern void expand_ASSUME (internal_fn, gcall *); extern void expand_MASK_CALL (internal_fn, gcall *); +extern void expand_MULBITINT (internal_fn, gcall *); +extern void expand_DIVMODBITINT (internal_fn, gcall *); +extern void expand_FLOATTOBITINT (internal_fn, gcall *); +extern void expand_BITINTTOFLOAT (internal_fn, gcall *); extern bool vectorized_internal_fn_supported_p (internal_fn, tree); --- gcc/lto-streamer-in.cc.jj 2023-07-17 09:07:42.078283882 +0200 +++ gcc/lto-streamer-in.cc 2023-07-27 15:03:24.255234159 +0200 @@ -1888,7 +1888,7 @@ lto_input_tree_1 (class lto_input_block for (i = 0; i < len; i++) a[i] = streamer_read_hwi (ib); - gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT); + gcc_assert (TYPE_PRECISION (type) <= WIDE_INT_MAX_PRECISION); result = wide_int_to_tree (type, wide_int::from_array (a, len, TYPE_PRECISION (type))); streamer_tree_cache_append (data_in->reader_cache, result, hash); --- gcc/Makefile.in.jj 2023-07-27 15:02:53.744661238 +0200 +++ gcc/Makefile.in 2023-07-27 15:03:24.281233795 +0200 @@ -1453,6 +1453,7 @@ OBJS = \ gimple-loop-jam.o \ gimple-loop-versioning.o \ gimple-low.o \ + gimple-lower-bitint.o \ gimple-predicate-analysis.o \ gimple-pretty-print.o \ gimple-range.o \ --- gcc/match.pd.jj 2023-07-24 17:49:05.496533445 +0200 +++ gcc/match.pd 2023-07-27 15:03:24.225234577 +0200 @@ -6433,6 +6433,7 @@ (define_operator_list SYNC_FETCH_AND_AND - 1)); })))) (if (wi::to_wide (cst) == signed_max && TYPE_UNSIGNED (arg1_type) + && TYPE_MODE (arg1_type) != BLKmode /* We will flip the signedness of the comparison operator associated with the mode of @1, so the sign bit is specified by this mode. Check that @1 is the signed --- gcc/passes.def.jj 2023-07-17 09:07:42.092283692 +0200 +++ gcc/passes.def 2023-07-27 15:03:24.287233711 +0200 @@ -237,6 +237,7 @@ along with GCC; see the file COPYING3. NEXT_PASS (pass_tail_recursion); NEXT_PASS (pass_ch); NEXT_PASS (pass_lower_complex); + NEXT_PASS (pass_lower_bitint); NEXT_PASS (pass_sra); /* The dom pass will also resolve all __builtin_constant_p calls that are still there to 0. This has to be done after some @@ -386,6 +387,7 @@ along with GCC; see the file COPYING3. NEXT_PASS (pass_strip_predict_hints, false /* early_p */); /* Lower remaining pieces of GIMPLE. */ NEXT_PASS (pass_lower_complex); + NEXT_PASS (pass_lower_bitint); NEXT_PASS (pass_lower_vector_ssa); NEXT_PASS (pass_lower_switch); /* Perform simple scalar cleanup which is constant/copy propagation. */ @@ -429,6 +431,7 @@ along with GCC; see the file COPYING3. NEXT_PASS (pass_lower_vaarg); NEXT_PASS (pass_lower_vector); NEXT_PASS (pass_lower_complex_O0); + NEXT_PASS (pass_lower_bitint_O0); NEXT_PASS (pass_sancov_O0); NEXT_PASS (pass_lower_switch_O0); NEXT_PASS (pass_asan_O0); --- gcc/pretty-print.h.jj 2023-06-26 09:27:04.352366471 +0200 +++ gcc/pretty-print.h 2023-07-27 15:03:24.281233795 +0200 @@ -336,8 +336,23 @@ pp_get_prefix (const pretty_printer *pp) #define pp_wide_int(PP, W, SGN) \ do \ { \ - print_dec (W, pp_buffer (PP)->digit_buffer, SGN); \ - pp_string (PP, pp_buffer (PP)->digit_buffer); \ + const wide_int_ref &pp_wide_int_ref = (W); \ + unsigned int pp_wide_int_prec \ + = pp_wide_int_ref.get_precision (); \ + if ((pp_wide_int_prec + 3) / 4 \ + > sizeof (pp_buffer (PP)->digit_buffer) - 3) \ + { \ + char *pp_wide_int_buf \ + = XALLOCAVEC (char, (pp_wide_int_prec + 3) / 4 + 3);\ + print_dec (pp_wide_int_ref, pp_wide_int_buf, SGN); \ + pp_string (PP, pp_wide_int_buf); \ + } \ + else \ + { \ + print_dec (pp_wide_int_ref, \ + pp_buffer (PP)->digit_buffer, SGN); \ + pp_string (PP, pp_buffer (PP)->digit_buffer); \ + } \ } \ while (0) #define pp_vrange(PP, R) \ --- gcc/stor-layout.cc.jj 2023-05-30 17:52:34.509856813 +0200 +++ gcc/stor-layout.cc 2023-07-27 15:03:24.295233599 +0200 @@ -2393,6 +2393,64 @@ layout_type (tree type) break; } + case BITINT_TYPE: + { + struct bitint_info info; + int cnt; + gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + scalar_int_mode limb_mode = as_a (info.limb_mode); + if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) + { + SET_TYPE_MODE (type, limb_mode); + cnt = 1; + } + else + { + SET_TYPE_MODE (type, BLKmode); + cnt = CEIL (TYPE_PRECISION (type), GET_MODE_PRECISION (limb_mode)); + } + TYPE_SIZE (type) = bitsize_int (cnt * GET_MODE_BITSIZE (limb_mode)); + TYPE_SIZE_UNIT (type) = size_int (cnt * GET_MODE_SIZE (limb_mode)); + SET_TYPE_ALIGN (type, GET_MODE_ALIGNMENT (limb_mode)); + if (cnt > 1) + { + /* Use same mode as compute_record_mode would use for a structure + containing cnt limb_mode elements. */ + machine_mode mode = mode_for_size_tree (TYPE_SIZE (type), + MODE_INT, 1).else_blk (); + if (mode == BLKmode) + break; + finalize_type_size (type); + SET_TYPE_MODE (type, mode); + if (STRICT_ALIGNMENT + && !(TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT + || TYPE_ALIGN (type) >= GET_MODE_ALIGNMENT (mode))) + { + /* If this is the only reason this type is BLKmode, then + don't force containing types to be BLKmode. */ + TYPE_NO_FORCE_BLK (type) = 1; + SET_TYPE_MODE (type, BLKmode); + } + if (TYPE_NEXT_VARIANT (type) || type != TYPE_MAIN_VARIANT (type)) + for (tree variant = TYPE_MAIN_VARIANT (type); + variant != NULL_TREE; + variant = TYPE_NEXT_VARIANT (variant)) + { + SET_TYPE_MODE (variant, mode); + if (STRICT_ALIGNMENT + && !(TYPE_ALIGN (variant) >= BIGGEST_ALIGNMENT + || (TYPE_ALIGN (variant) + >= GET_MODE_ALIGNMENT (mode)))) + { + TYPE_NO_FORCE_BLK (variant) = 1; + SET_TYPE_MODE (variant, BLKmode); + } + } + return; + } + break; + } + case REAL_TYPE: { /* Allow the caller to choose the type mode, which is how decimal @@ -2417,6 +2475,18 @@ layout_type (tree type) case COMPLEX_TYPE: TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TREE_TYPE (type)); + if (TYPE_MODE (TREE_TYPE (type)) == BLKmode) + { + gcc_checking_assert (TREE_CODE (TREE_TYPE (type)) == BITINT_TYPE); + SET_TYPE_MODE (type, BLKmode); + TYPE_SIZE (type) + = int_const_binop (MULT_EXPR, TYPE_SIZE (TREE_TYPE (type)), + bitsize_int (2)); + TYPE_SIZE_UNIT (type) + = int_const_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (type)), + bitsize_int (2)); + break; + } SET_TYPE_MODE (type, GET_MODE_COMPLEX_MODE (TYPE_MODE (TREE_TYPE (type)))); --- gcc/target.def.jj 2023-05-30 17:52:34.510856799 +0200 +++ gcc/target.def 2023-07-27 15:03:24.298233557 +0200 @@ -6241,6 +6241,15 @@ when @var{type} is @code{EXCESS_PRECISIO enum flt_eval_method, (enum excess_precision_type type), default_excess_precision) +/* Return true if _BitInt(N) is supported and fill details about it into + *INFO. */ +DEFHOOK +(bitint_type_info, + "This target hook returns true if _BitInt(N) is supported and provides some\n\ +details on it.", + bool, (int n, struct bitint_info *info), + default_bitint_type_info) + HOOK_VECTOR_END (c) /* Functions specific to the C++ frontend. */ --- gcc/target.h.jj 2023-03-13 23:01:42.078959188 +0100 +++ gcc/target.h 2023-07-27 15:03:24.273233907 +0200 @@ -68,6 +68,20 @@ union cumulative_args_t { void *p; }; #endif /* !CHECKING_P */ +/* Target properties of _BitInt(N) type. _BitInt(N) is to be represented + as series of limb_mode CEIL (N, GET_MODE_PRECISION (limb_mode)) limbs, + ordered from least significant to most significant if !big_endian, + otherwise from most significant to least significant. If extended is + false, the bits above or equal to N are undefined when stored in a register + or memory, otherwise they are zero or sign extended depending on if + it is unsigned _BitInt(N) or _BitInt(N) / signed _BitInt(N). */ + +struct bitint_info { + machine_mode limb_mode; + bool big_endian; + bool extended; +}; + /* Types of memory operation understood by the "by_pieces" infrastructure. Used by the TARGET_USE_BY_PIECES_INFRASTRUCTURE_P target hook and internally by the functions in expr.cc. */ --- gcc/targhooks.cc.jj 2023-05-01 23:07:05.366414623 +0200 +++ gcc/targhooks.cc 2023-07-27 15:03:24.280233809 +0200 @@ -2595,6 +2595,14 @@ default_excess_precision (enum excess_pr return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT; } +/* Return true if _BitInt(N) is supported and fill details about it into + *INFO. */ +bool +default_bitint_type_info (int, struct bitint_info *) +{ + return false; +} + /* Default implementation for TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE. */ HOST_WIDE_INT --- gcc/targhooks.h.jj 2023-05-01 23:07:05.366414623 +0200 +++ gcc/targhooks.h 2023-07-27 15:03:24.258234117 +0200 @@ -284,6 +284,7 @@ extern unsigned int default_min_arithmet extern enum flt_eval_method default_excess_precision (enum excess_precision_type ATTRIBUTE_UNUSED); +extern bool default_bitint_type_info (int, struct bitint_info *); extern HOST_WIDE_INT default_stack_clash_protection_alloca_probe_range (void); extern void default_select_early_remat_modes (sbitmap); extern tree default_preferred_else_value (unsigned, tree, unsigned, tree *); --- gcc/tree-pass.h.jj 2023-07-17 09:07:42.140283040 +0200 +++ gcc/tree-pass.h 2023-07-27 15:03:24.218234675 +0200 @@ -229,6 +229,7 @@ protected: have completed. */ #define PROP_assumptions_done (1 << 19) /* Assume function kept around. */ +#define PROP_gimple_lbitint (1 << 20) /* lowered large _BitInt */ #define PROP_gimple \ (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp) @@ -420,6 +421,8 @@ extern gimple_opt_pass *make_pass_strip_ extern gimple_opt_pass *make_pass_rebuild_frequencies (gcc::context *ctxt); extern gimple_opt_pass *make_pass_lower_complex_O0 (gcc::context *ctxt); extern gimple_opt_pass *make_pass_lower_complex (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_lower_bitint_O0 (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_lower_bitint (gcc::context *ctxt); extern gimple_opt_pass *make_pass_lower_switch (gcc::context *ctxt); extern gimple_opt_pass *make_pass_lower_switch_O0 (gcc::context *ctxt); extern gimple_opt_pass *make_pass_lower_vector (gcc::context *ctxt); --- gcc/tree-pretty-print.cc.jj 2023-06-06 20:02:35.676210599 +0200 +++ gcc/tree-pretty-print.cc 2023-07-27 15:03:24.296233585 +0200 @@ -1924,6 +1924,7 @@ dump_generic_node (pretty_printer *pp, t case VECTOR_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: + case BITINT_TYPE: case OPAQUE_TYPE: { unsigned int quals = TYPE_QUALS (node); @@ -2038,6 +2039,14 @@ dump_generic_node (pretty_printer *pp, t pp_decimal_int (pp, TYPE_PRECISION (node)); pp_greater (pp); } + else if (TREE_CODE (node) == BITINT_TYPE) + { + if (TYPE_UNSIGNED (node)) + pp_string (pp, "unsigned "); + pp_string (pp, "_BitInt("); + pp_decimal_int (pp, TYPE_PRECISION (node)); + pp_right_paren (pp); + } else if (TREE_CODE (node) == VOID_TYPE) pp_string (pp, "void"); else @@ -2234,8 +2243,18 @@ dump_generic_node (pretty_printer *pp, t pp_minus (pp); val = -val; } - print_hex (val, pp_buffer (pp)->digit_buffer); - pp_string (pp, pp_buffer (pp)->digit_buffer); + unsigned int prec = val.get_precision (); + if ((prec + 3) / 4 > sizeof (pp_buffer (pp)->digit_buffer) - 3) + { + char *buf = XALLOCAVEC (char, (prec + 3) / 4 + 3); + print_hex (val, buf); + pp_string (pp, buf); + } + else + { + print_hex (val, pp_buffer (pp)->digit_buffer); + pp_string (pp, pp_buffer (pp)->digit_buffer); + } } if ((flags & TDF_GIMPLE) && ! (POINTER_TYPE_P (TREE_TYPE (node)) --- gcc/tree-ssa-coalesce.cc.jj 2023-05-20 15:31:09.229661068 +0200 +++ gcc/tree-ssa-coalesce.cc 2023-07-27 15:03:24.254234173 +0200 @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. #include "explow.h" #include "tree-dfa.h" #include "stor-layout.h" +#include "gimple-lower-bitint.h" /* This set of routines implements a coalesce_list. This is an object which is used to track pairs of ssa_names which are desirable to coalesce @@ -914,6 +915,14 @@ build_ssa_conflict_graph (tree_live_info else if (is_gimple_debug (stmt)) continue; + if (map->bitint) + { + build_bitint_stmt_ssa_conflicts (stmt, live, graph, map->bitint, + live_track_process_def, + live_track_process_use); + continue; + } + /* For stmts with more than one SSA_NAME definition pretend all the SSA_NAME outputs but the first one are live at this point, so that conflicts are added in between all those even when they are @@ -1058,6 +1067,8 @@ create_coalesce_list_for_region (var_map if (virtual_operand_p (res)) continue; ver = SSA_NAME_VERSION (res); + if (map->bitint && !bitmap_bit_p (map->bitint, ver)) + continue; /* Register ssa_names and coalesces between the args and the result of all PHI. */ @@ -1106,6 +1117,8 @@ create_coalesce_list_for_region (var_map { v1 = SSA_NAME_VERSION (lhs); v2 = SSA_NAME_VERSION (rhs1); + if (map->bitint && !bitmap_bit_p (map->bitint, v1)) + break; cost = coalesce_cost_bb (bb); add_coalesce (cl, v1, v2, cost); bitmap_set_bit (used_in_copy, v1); @@ -1124,12 +1137,16 @@ create_coalesce_list_for_region (var_map if (!rhs1) break; tree lhs = ssa_default_def (cfun, res); + if (map->bitint && !lhs) + break; gcc_assert (lhs); if (TREE_CODE (rhs1) == SSA_NAME && gimple_can_coalesce_p (lhs, rhs1)) { v1 = SSA_NAME_VERSION (lhs); v2 = SSA_NAME_VERSION (rhs1); + if (map->bitint && !bitmap_bit_p (map->bitint, v1)) + break; cost = coalesce_cost_bb (bb); add_coalesce (cl, v1, v2, cost); bitmap_set_bit (used_in_copy, v1); @@ -1177,6 +1194,8 @@ create_coalesce_list_for_region (var_map v1 = SSA_NAME_VERSION (outputs[match]); v2 = SSA_NAME_VERSION (input); + if (map->bitint && !bitmap_bit_p (map->bitint, v1)) + continue; if (gimple_can_coalesce_p (outputs[match], input)) { @@ -1651,6 +1670,33 @@ compute_optimized_partition_bases (var_m } } + if (map->bitint + && flag_tree_coalesce_vars + && (optimize > 1 || parts < 500)) + for (i = 0; i < (unsigned) parts; ++i) + { + tree s1 = partition_to_var (map, i); + int p1 = partition_find (tentative, i); + for (unsigned j = i + 1; j < (unsigned) parts; ++j) + { + tree s2 = partition_to_var (map, j); + if (s1 == s2) + continue; + if (tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (s1)), + TYPE_SIZE (TREE_TYPE (s2)))) + { + int p2 = partition_find (tentative, j); + + if (p1 == p2) + continue; + + partition_union (tentative, p1, p2); + if (partition_find (tentative, i) != p1) + break; + } + } + } + map->partition_to_base_index = XCNEWVEC (int, parts); auto_vec index_map (parts); if (parts) @@ -1692,6 +1738,101 @@ compute_optimized_partition_bases (var_m partition_delete (tentative); } +/* For the bitint lowering pass, try harder. Partitions which contain + SSA_NAME default def of a PARM_DECL or have RESULT_DECL need to have + compatible types because they will use that RESULT_DECL or PARM_DECL. + Other partitions can have even incompatible _BitInt types, as long + as they have the same size - those will use VAR_DECLs which are just + arrays of the limbs. */ + +static void +coalesce_bitint (var_map map, ssa_conflicts *graph) +{ + unsigned n = num_var_partitions (map); + if (optimize <= 1 && n > 500) + return; + + bool try_same_size = false; + FILE *debug_file = (dump_flags & TDF_DETAILS) ? dump_file : NULL; + for (unsigned i = 0; i < n; ++i) + { + tree s1 = partition_to_var (map, i); + if ((unsigned) var_to_partition (map, s1) != i) + continue; + int v1 = SSA_NAME_VERSION (s1); + for (unsigned j = i + 1; j < n; ++j) + { + tree s2 = partition_to_var (map, j); + if (s1 == s2 || (unsigned) var_to_partition (map, s2) != j) + continue; + if (!types_compatible_p (TREE_TYPE (s1), TREE_TYPE (s2))) + { + if (!try_same_size + && tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (s1)), + TYPE_SIZE (TREE_TYPE (s2)))) + try_same_size = true; + continue; + } + int v2 = SSA_NAME_VERSION (s2); + if (attempt_coalesce (map, graph, v1, v2, debug_file) + && partition_to_var (map, i) != s1) + break; + } + } + + if (!try_same_size) + return; + + unsigned i; + bitmap_iterator bi; + bitmap same_type = NULL; + + EXECUTE_IF_SET_IN_BITMAP (map->bitint, 0, i, bi) + { + tree s = ssa_name (i); + if (!SSA_NAME_VAR (s)) + continue; + if (TREE_CODE (SSA_NAME_VAR (s)) != RESULT_DECL + && (TREE_CODE (SSA_NAME_VAR (s)) != PARM_DECL + || !SSA_NAME_IS_DEFAULT_DEF (s))) + continue; + if (same_type == NULL) + same_type = BITMAP_ALLOC (NULL); + int p = var_to_partition (map, s); + bitmap_set_bit (same_type, p); + } + + for (i = 0; i < n; ++i) + { + if (same_type && bitmap_bit_p (same_type, i)) + continue; + tree s1 = partition_to_var (map, i); + if ((unsigned) var_to_partition (map, s1) != i) + continue; + int v1 = SSA_NAME_VERSION (s1); + for (unsigned j = i + 1; j < n; ++j) + { + if (same_type && bitmap_bit_p (same_type, j)) + continue; + + tree s2 = partition_to_var (map, j); + if (s1 == s2 || (unsigned) var_to_partition (map, s2) != j) + continue; + + if (!tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (s1)), + TYPE_SIZE (TREE_TYPE (s2)))) + continue; + + int v2 = SSA_NAME_VERSION (s2); + if (attempt_coalesce (map, graph, v1, v2, debug_file) + && partition_to_var (map, i) != s1) + break; + } + } + + BITMAP_FREE (same_type); +} + /* Given an initial var_map MAP, coalesce variables and return a partition map with the resulting coalesce. Note that this function is called in either live range computation context or out-of-ssa context, indicated by MAP. */ @@ -1709,6 +1850,8 @@ coalesce_ssa_name (var_map map) if (map->outofssa_p) populate_coalesce_list_for_outofssa (cl, used_in_copies); bitmap_list_view (used_in_copies); + if (map->bitint) + bitmap_ior_into (used_in_copies, map->bitint); if (dump_file && (dump_flags & TDF_DETAILS)) dump_var_map (dump_file, map); @@ -1756,6 +1899,9 @@ coalesce_ssa_name (var_map map) ((dump_flags & TDF_DETAILS) ? dump_file : NULL)); delete_coalesce_list (cl); + + if (map->bitint && flag_tree_coalesce_vars) + coalesce_bitint (map, graph); + ssa_conflicts_delete (graph); } - --- gcc/tree-ssa-live.cc.jj 2023-03-16 22:01:02.376089791 +0100 +++ gcc/tree-ssa-live.cc 2023-07-27 15:03:24.289233683 +0200 @@ -76,10 +76,11 @@ var_map_base_fini (var_map map) } /* Create a variable partition map of SIZE for region, initialize and return it. Region is a loop if LOOP is non-NULL, otherwise is the current - function. */ + function. If BITINT is non-NULL, only SSA_NAMEs from that bitmap + will be coalesced. */ var_map -init_var_map (int size, class loop *loop) +init_var_map (int size, class loop *loop, bitmap bitint) { var_map map; @@ -108,7 +109,8 @@ init_var_map (int size, class loop *loop else { map->bmp_bbs = NULL; - map->outofssa_p = true; + map->outofssa_p = bitint == NULL; + map->bitint = bitint; basic_block bb; FOR_EACH_BB_FN (bb, cfun) map->vec_bbs.safe_push (bb); --- gcc/tree-ssa-live.h.jj 2023-02-17 22:20:14.986011041 +0100 +++ gcc/tree-ssa-live.h 2023-07-27 15:03:24.231234494 +0200 @@ -70,6 +70,10 @@ typedef struct _var_map /* Vector of basic block in the region. */ vec vec_bbs; + /* If non-NULL, only coalesce SSA_NAMEs from this bitmap, and try harder + for those (for bitint lowering pass). */ + bitmap bitint; + /* True if this map is for out-of-ssa, otherwise for live range computation. When for out-of-ssa, it also means the var map is computed for whole current function. */ @@ -80,7 +84,7 @@ typedef struct _var_map /* Value used to represent no partition number. */ #define NO_PARTITION -1 -extern var_map init_var_map (int, class loop* = NULL); +extern var_map init_var_map (int, class loop * = NULL, bitmap = NULL); extern void delete_var_map (var_map); extern int var_union (var_map, tree, tree); extern void partition_view_normal (var_map); @@ -100,7 +104,7 @@ inline bool region_contains_p (var_map map, basic_block bb) { /* It's possible that the function is called with ENTRY_BLOCK/EXIT_BLOCK. */ - if (map->outofssa_p) + if (map->outofssa_p || map->bitint) return (bb->index != ENTRY_BLOCK && bb->index != EXIT_BLOCK); return bitmap_bit_p (map->bmp_bbs, bb->index); --- gcc/tree-ssa-sccvn.cc.jj 2023-07-24 17:48:26.536039977 +0200 +++ gcc/tree-ssa-sccvn.cc 2023-07-27 15:03:24.289233683 +0200 @@ -74,6 +74,7 @@ along with GCC; see the file COPYING3. #include "ipa-modref-tree.h" #include "ipa-modref.h" #include "tree-ssa-sccvn.h" +#include "target.h" /* This algorithm is based on the SCC algorithm presented by Keith Cooper and L. Taylor Simpson in "SCC-Based Value numbering" @@ -6969,8 +6970,14 @@ eliminate_dom_walker::eliminate_stmt (ba || !DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1))) && !type_has_mode_precision_p (TREE_TYPE (lhs))) { - if (TREE_CODE (lhs) == COMPONENT_REF - || TREE_CODE (lhs) == MEM_REF) + if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && (TYPE_PRECISION (TREE_TYPE (lhs)) + > (targetm.scalar_mode_supported_p (TImode) + ? GET_MODE_PRECISION (TImode) + : GET_MODE_PRECISION (DImode)))) + lookup_lhs = NULL_TREE; + else if (TREE_CODE (lhs) == COMPONENT_REF + || TREE_CODE (lhs) == MEM_REF) { tree ltype = build_nonstandard_integer_type (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (lhs))), --- gcc/tree-switch-conversion.cc.jj 2023-04-27 11:33:13.477770933 +0200 +++ gcc/tree-switch-conversion.cc 2023-07-27 15:03:24.241234354 +0200 @@ -1143,32 +1143,93 @@ jump_table_cluster::emit (tree index_exp tree default_label_expr, basic_block default_bb, location_t loc) { - unsigned HOST_WIDE_INT range = get_range (get_low (), get_high ()); + tree low = get_low (); + unsigned HOST_WIDE_INT range = get_range (low, get_high ()); unsigned HOST_WIDE_INT nondefault_range = 0; + bool bitint = false; + gimple_stmt_iterator gsi = gsi_start_bb (m_case_bb); + + /* For large/huge _BitInt, subtract low from index_expr, cast to unsigned + DImode type (get_range doesn't support ranges larger than 64-bits) + and subtract low from all case values as well. */ + if (TREE_CODE (TREE_TYPE (index_expr)) == BITINT_TYPE + && TYPE_PRECISION (TREE_TYPE (index_expr)) > GET_MODE_PRECISION (DImode)) + { + bitint = true; + tree this_low = low, type; + gimple *g; + if (!TYPE_OVERFLOW_WRAPS (TREE_TYPE (index_expr))) + { + type = unsigned_type_for (TREE_TYPE (index_expr)); + g = gimple_build_assign (make_ssa_name (type), NOP_EXPR, index_expr); + gimple_set_location (g, loc); + gsi_insert_after (&gsi, g, GSI_NEW_STMT); + index_expr = gimple_assign_lhs (g); + this_low = fold_convert (type, this_low); + } + this_low = const_unop (NEGATE_EXPR, TREE_TYPE (this_low), this_low); + g = gimple_build_assign (make_ssa_name (TREE_TYPE (index_expr)), + PLUS_EXPR, index_expr, this_low); + gimple_set_location (g, loc); + gsi_insert_after (&gsi, g, GSI_NEW_STMT); + index_expr = gimple_assign_lhs (g); + type = build_nonstandard_integer_type (GET_MODE_PRECISION (DImode), 1); + g = gimple_build_cond (GT_EXPR, index_expr, + fold_convert (TREE_TYPE (index_expr), + TYPE_MAX_VALUE (type)), + NULL_TREE, NULL_TREE); + gimple_set_location (g, loc); + gsi_insert_after (&gsi, g, GSI_NEW_STMT); + edge e1 = split_block (m_case_bb, g); + e1->flags = EDGE_FALSE_VALUE; + e1->probability = profile_probability::likely (); + edge e2 = make_edge (e1->src, default_bb, EDGE_TRUE_VALUE); + e2->probability = e1->probability.invert (); + gsi = gsi_start_bb (e1->dest); + g = gimple_build_assign (make_ssa_name (type), NOP_EXPR, index_expr); + gimple_set_location (g, loc); + gsi_insert_after (&gsi, g, GSI_NEW_STMT); + index_expr = gimple_assign_lhs (g); + } /* For jump table we just emit a new gswitch statement that will be latter lowered to jump table. */ auto_vec labels; labels.create (m_cases.length ()); - make_edge (m_case_bb, default_bb, 0); + basic_block case_bb = gsi_bb (gsi); + make_edge (case_bb, default_bb, 0); for (unsigned i = 0; i < m_cases.length (); i++) { - labels.quick_push (unshare_expr (m_cases[i]->m_case_label_expr)); - make_edge (m_case_bb, m_cases[i]->m_case_bb, 0); + tree lab = unshare_expr (m_cases[i]->m_case_label_expr); + if (bitint) + { + CASE_LOW (lab) + = fold_convert (TREE_TYPE (index_expr), + const_binop (MINUS_EXPR, + TREE_TYPE (CASE_LOW (lab)), + CASE_LOW (lab), low)); + if (CASE_HIGH (lab)) + CASE_HIGH (lab) + = fold_convert (TREE_TYPE (index_expr), + const_binop (MINUS_EXPR, + TREE_TYPE (CASE_HIGH (lab)), + CASE_HIGH (lab), low)); + } + labels.quick_push (lab); + make_edge (case_bb, m_cases[i]->m_case_bb, 0); } gswitch *s = gimple_build_switch (index_expr, unshare_expr (default_label_expr), labels); gimple_set_location (s, loc); - gimple_stmt_iterator gsi = gsi_start_bb (m_case_bb); gsi_insert_after (&gsi, s, GSI_NEW_STMT); /* Set up even probabilities for all cases. */ for (unsigned i = 0; i < m_cases.length (); i++) { simple_cluster *sc = static_cast (m_cases[i]); - edge case_edge = find_edge (m_case_bb, sc->m_case_bb); + edge case_edge = find_edge (case_bb, sc->m_case_bb); unsigned HOST_WIDE_INT case_range = sc->get_range (sc->get_low (), sc->get_high ()); nondefault_range += case_range; @@ -1184,7 +1245,7 @@ jump_table_cluster::emit (tree index_exp for (unsigned i = 0; i < m_cases.length (); i++) { simple_cluster *sc = static_cast (m_cases[i]); - edge case_edge = find_edge (m_case_bb, sc->m_case_bb); + edge case_edge = find_edge (case_bb, sc->m_case_bb); case_edge->probability = profile_probability::always ().apply_scale ((intptr_t)case_edge->aux, range); --- gcc/typeclass.h.jj 2023-01-03 00:20:35.218084730 +0100 +++ gcc/typeclass.h 2023-07-27 15:03:24.273233907 +0200 @@ -37,7 +37,8 @@ enum type_class function_type_class, method_type_class, record_type_class, union_type_class, array_type_class, string_type_class, - lang_type_class, opaque_type_class + lang_type_class, opaque_type_class, + bitint_type_class }; #endif /* GCC_TYPECLASS_H */ --- gcc/ubsan.cc.jj 2023-05-20 15:31:09.240660915 +0200 +++ gcc/ubsan.cc 2023-07-27 15:03:24.260234089 +0200 @@ -50,6 +50,8 @@ along with GCC; see the file COPYING3. #include "gimple-fold.h" #include "varasm.h" #include "realmpfr.h" +#include "target.h" +#include "langhooks.h" /* Map from a tree to a VAR_DECL tree. */ @@ -125,6 +127,25 @@ tree ubsan_encode_value (tree t, enum ubsan_encode_value_phase phase) { tree type = TREE_TYPE (t); + if (TREE_CODE (type) == BITINT_TYPE) + { + if (TYPE_PRECISION (type) <= POINTER_SIZE) + { + type = pointer_sized_int_node; + t = fold_build1 (NOP_EXPR, type, t); + } + else + { + scalar_int_mode arith_mode + = (targetm.scalar_mode_supported_p (TImode) ? TImode : DImode); + if (TYPE_PRECISION (type) > GET_MODE_PRECISION (arith_mode)) + return build_zero_cst (pointer_sized_int_node); + type + = build_nonstandard_integer_type (GET_MODE_PRECISION (arith_mode), + TYPE_UNSIGNED (type)); + t = fold_build1 (NOP_EXPR, type, t); + } + } scalar_mode mode = SCALAR_TYPE_MODE (type); const unsigned int bitsize = GET_MODE_BITSIZE (mode); if (bitsize <= POINTER_SIZE) @@ -355,14 +376,32 @@ ubsan_type_descriptor (tree type, enum u { /* See through any typedefs. */ type = TYPE_MAIN_VARIANT (type); + tree type3 = type; + if (pstyle == UBSAN_PRINT_FORCE_INT) + { + /* Temporary hack for -fsanitize=shift with _BitInt(129) and more. + libubsan crashes if it is not TK_Integer type. */ + if (TREE_CODE (type) == BITINT_TYPE) + { + scalar_int_mode arith_mode + = (targetm.scalar_mode_supported_p (TImode) + ? TImode : DImode); + if (TYPE_PRECISION (type) > GET_MODE_PRECISION (arith_mode)) + type3 = build_qualified_type (type, TYPE_QUAL_CONST); + } + if (type3 == type) + pstyle = UBSAN_PRINT_NORMAL; + } - tree decl = decl_for_type_lookup (type); + tree decl = decl_for_type_lookup (type3); /* It is possible that some of the earlier created DECLs were found unused, in that case they weren't emitted and varpool_node::get returns NULL node on them. But now we really need them. Thus, renew them here. */ if (decl != NULL_TREE && varpool_node::get (decl)) - return build_fold_addr_expr (decl); + { + return build_fold_addr_expr (decl); + } tree dtype = ubsan_get_type_descriptor_type (); tree type2 = type; @@ -370,6 +409,7 @@ ubsan_type_descriptor (tree type, enum u pretty_printer pretty_name; unsigned char deref_depth = 0; unsigned short tkind, tinfo; + char tname_bitint[sizeof ("unsigned _BitInt(2147483647)")]; /* Get the name of the type, or the name of the pointer type. */ if (pstyle == UBSAN_PRINT_POINTER) @@ -403,8 +443,18 @@ ubsan_type_descriptor (tree type, enum u } if (tname == NULL) - /* We weren't able to determine the type name. */ - tname = ""; + { + if (TREE_CODE (type2) == BITINT_TYPE) + { + snprintf (tname_bitint, sizeof (tname_bitint), + "%s_BitInt(%d)", TYPE_UNSIGNED (type2) ? "unsigned " : "", + TYPE_PRECISION (type2)); + tname = tname_bitint; + } + else + /* We weren't able to determine the type name. */ + tname = ""; + } pp_quote (&pretty_name); @@ -472,6 +522,18 @@ ubsan_type_descriptor (tree type, enum u case INTEGER_TYPE: tkind = 0x0000; break; + case BITINT_TYPE: + { + /* FIXME: libubsan right now only supports _BitInts which + fit into DImode or TImode. */ + scalar_int_mode arith_mode = (targetm.scalar_mode_supported_p (TImode) + ? TImode : DImode); + if (TYPE_PRECISION (eltype) <= GET_MODE_PRECISION (arith_mode)) + tkind = 0x0000; + else + tkind = 0xffff; + } + break; case REAL_TYPE: /* FIXME: libubsan right now only supports float, double and long double type formats. */ @@ -486,7 +548,17 @@ ubsan_type_descriptor (tree type, enum u tkind = 0xffff; break; } - tinfo = get_ubsan_type_info_for_type (eltype); + tinfo = tkind == 0xffff ? 0 : get_ubsan_type_info_for_type (eltype); + + if (pstyle == UBSAN_PRINT_FORCE_INT) + { + tkind = 0x0000; + scalar_int_mode arith_mode = (targetm.scalar_mode_supported_p (TImode) + ? TImode : DImode); + tree t = lang_hooks.types.type_for_mode (arith_mode, + TYPE_UNSIGNED (eltype)); + tinfo = get_ubsan_type_info_for_type (t); + } /* Create a new VAR_DECL of type descriptor. */ const char *tmp = pp_formatted_text (&pretty_name); @@ -522,7 +594,7 @@ ubsan_type_descriptor (tree type, enum u varpool_node::finalize_decl (decl); /* Save the VAR_DECL into the hash table. */ - decl_for_type_insert (type, decl); + decl_for_type_insert (type3, decl); return build_fold_addr_expr (decl); } @@ -1604,8 +1676,9 @@ instrument_si_overflow (gimple_stmt_iter Also punt on bit-fields. */ if (!INTEGRAL_TYPE_P (lhsinner) || TYPE_OVERFLOW_WRAPS (lhsinner) - || maybe_ne (GET_MODE_BITSIZE (TYPE_MODE (lhsinner)), - TYPE_PRECISION (lhsinner))) + || (TREE_CODE (lhsinner) != BITINT_TYPE + && maybe_ne (GET_MODE_BITSIZE (TYPE_MODE (lhsinner)), + TYPE_PRECISION (lhsinner)))) return; switch (code) --- gcc/ubsan.h.jj 2023-01-03 00:20:35.219084715 +0100 +++ gcc/ubsan.h 2023-07-27 15:03:24.222234619 +0200 @@ -39,7 +39,8 @@ enum ubsan_null_ckind { enum ubsan_print_style { UBSAN_PRINT_NORMAL, UBSAN_PRINT_POINTER, - UBSAN_PRINT_ARRAY + UBSAN_PRINT_ARRAY, + UBSAN_PRINT_FORCE_INT }; /* This controls ubsan_encode_value behavior. */ --- gcc/varasm.cc.jj 2023-07-17 09:07:42.158282795 +0200 +++ gcc/varasm.cc 2023-07-27 15:03:24.291233655 +0200 @@ -5281,6 +5281,61 @@ output_constant (tree exp, unsigned HOST reverse, false); break; + case BITINT_TYPE: + if (TREE_CODE (exp) != INTEGER_CST) + error ("initializer for %<_BitInt(%d)%> value is not an integer " + "constant", TYPE_PRECISION (TREE_TYPE (exp))); + else + { + struct bitint_info info; + tree type = TREE_TYPE (exp); + gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), + &info)); + scalar_int_mode limb_mode = as_a (info.limb_mode); + if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) + { + cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); + if (reverse) + cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst); + if (!assemble_integer (cst, MIN (size, thissize), align, 0)) + error ("initializer for integer/fixed-point value is too " + "complicated"); + break; + } + int prec = GET_MODE_PRECISION (limb_mode); + int cnt = CEIL (TYPE_PRECISION (type), prec); + tree limb_type = build_nonstandard_integer_type (prec, 1); + int elt_size = GET_MODE_SIZE (limb_mode); + unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (limb_mode)); + thissize = 0; + if (prec == HOST_BITS_PER_WIDE_INT) + for (int i = 0; i < cnt; i++) + { + int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i; + tree c; + if (idx >= TREE_INT_CST_EXT_NUNITS (exp)) + c = build_int_cst (limb_type, + tree_int_cst_sgn (exp) < 0 ? -1 : 0); + else + c = build_int_cst (limb_type, + TREE_INT_CST_ELT (exp, idx)); + output_constant (c, elt_size, nalign, reverse, false); + thissize += elt_size; + } + else + for (int i = 0; i < cnt; i++) + { + int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i; + wide_int w = wi::rshift (wi::to_wide (exp), idx * prec, + TYPE_SIGN (TREE_TYPE (exp))); + tree c = wide_int_to_tree (limb_type, + wide_int::from (w, prec, UNSIGNED)); + output_constant (c, elt_size, nalign, reverse, false); + thissize += elt_size; + } + } + break; + case ARRAY_TYPE: case VECTOR_TYPE: switch (TREE_CODE (exp)) --- gcc/vr-values.cc.jj 2023-06-12 18:52:23.237435819 +0200 +++ gcc/vr-values.cc 2023-07-27 15:03:24.274233893 +0200 @@ -111,21 +111,21 @@ check_for_binary_op_overflow (range_quer { /* So far we found that there is an overflow on the boundaries. That doesn't prove that there is an overflow even for all values - in between the boundaries. For that compute widest_int range + in between the boundaries. For that compute widest2_int range of the result and see if it doesn't overlap the range of type. */ - widest_int wmin, wmax; - widest_int w[4]; + widest2_int wmin, wmax; + widest2_int w[4]; int i; signop sign0 = TYPE_SIGN (TREE_TYPE (op0)); signop sign1 = TYPE_SIGN (TREE_TYPE (op1)); - w[0] = widest_int::from (vr0.lower_bound (), sign0); - w[1] = widest_int::from (vr0.upper_bound (), sign0); - w[2] = widest_int::from (vr1.lower_bound (), sign1); - w[3] = widest_int::from (vr1.upper_bound (), sign1); + w[0] = widest2_int::from (vr0.lower_bound (), sign0); + w[1] = widest2_int::from (vr0.upper_bound (), sign0); + w[2] = widest2_int::from (vr1.lower_bound (), sign1); + w[3] = widest2_int::from (vr1.upper_bound (), sign1); for (i = 0; i < 4; i++) { - widest_int wt; + widest2_int wt; switch (subcode) { case PLUS_EXPR: @@ -153,10 +153,10 @@ check_for_binary_op_overflow (range_quer } /* The result of op0 CODE op1 is known to be in range [wmin, wmax]. */ - widest_int wtmin - = widest_int::from (irange_val_min (type), TYPE_SIGN (type)); - widest_int wtmax - = widest_int::from (irange_val_max (type), TYPE_SIGN (type)); + widest2_int wtmin + = widest2_int::from (irange_val_min (type), TYPE_SIGN (type)); + widest2_int wtmax + = widest2_int::from (irange_val_max (type), TYPE_SIGN (type)); /* If all values in [wmin, wmax] are smaller than [wtmin, wtmax] or all are larger than [wtmin, wtmax], the arithmetic operation will always overflow. */ @@ -1717,12 +1717,11 @@ simplify_using_ranges::simplify_internal g = gimple_build_assign (gimple_call_lhs (stmt), subcode, op0, op1); else { - int prec = TYPE_PRECISION (type); tree utype = type; if (ovf || !useless_type_conversion_p (type, TREE_TYPE (op0)) || !useless_type_conversion_p (type, TREE_TYPE (op1))) - utype = build_nonstandard_integer_type (prec, 1); + utype = unsigned_type_for (type); if (TREE_CODE (op0) == INTEGER_CST) op0 = fold_convert (utype, op0); else if (!useless_type_conversion_p (utype, TREE_TYPE (op0))) From patchwork Thu Jul 27 17:13:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 127073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1246573vqo; Thu, 27 Jul 2023 10:16:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlEcqEJFL2DCQBF72YSG6VQeJCXsNBINOoYyCTVqXfo9MA6eYE4xrsRWsH91nzSBMqbfTX4v X-Received: by 2002:adf:ea8f:0:b0:314:3985:b291 with SMTP id s15-20020adfea8f000000b003143985b291mr2728369wrm.15.1690478213776; Thu, 27 Jul 2023 10:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690478213; cv=none; d=google.com; s=arc-20160816; b=BNu5RmglLzI6mLJI7diyHIpMXW/f33HBHKeCj9HAnSz61cQkJJgzTu8+WSS9albBl9 QJcYVvRz1D5T7t4weLeYtUOBiW+IYICN1BvUA4zrZV0pbkwRr4T7l9XZzm+xjzXhmIMR GZaRdoLjj2Wi25A2hVw+YrH2uyQj0WMOicXzjPXqqf3Lg2gJ6ZKRA30GzfPAtajXI8mM qIsrJ2R1vdMY1qNmU9NQQ8HYeYqgaOM96OX2VpnfXkOhvFz5vrMFA2sxbMkJdEZP+4Cs gM/Cc4QSsJQMtaSm4LaQicT0sqLJGEKN/QHuapKmF29OeeoOSnoQwoNlwbhprEOtWHOs MChQ== 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=3LkAcL5WDoisXxMs58ZE/LbLC4KvGrMSeKIVLh2dy9Q=; fh=WLIzpkiNYT+sSgm6PnMRUugV0RZtfwj0ju7DyNqWOiY=; b=NmpySVoevzOQlqwrR8bIYldufrIjm3SrBKIIFQq7L9nq9ZsPLs9I9x1TuYUr6LNBL3 OtyLMCwi2xADyWzucuIPnbqXl6Dp/HnNyIg+P6J2B1w3vJs0AhUEIGMztvO1V5r1YSq5 mAp3sl1U9ahyUTe5kGmiKBg//Ay+AYMNRQuJ/voMVx4pVfF6gePkq3KSzxK2/BMmUOBs ZsVlnogoPTfoxeJ9GSRkYDf0u9WynqKpYxCP4ouXpyBSmEK4Ir3l9vs9vbChlClVPq4r q4QeBRGfwPUeRdwSCIwGIy6GXGoue99DD/T1hjVUB0emLchwLiBi4LOcQ4qNrfJ51TFW zs2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PDqIjjAU; 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 i12-20020a170906a28c00b00997d315d050si1252030ejz.84.2023.07.27.10.16.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:16:53 -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=PDqIjjAU; 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 C7AE13854C58 for ; Thu, 27 Jul 2023 17:16:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7AE13854C58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690478165; bh=3LkAcL5WDoisXxMs58ZE/LbLC4KvGrMSeKIVLh2dy9Q=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=PDqIjjAUjCznjKVA1EXARBNQaGeAqf974NZ5v83KCCtWhsCJxwxIjqv8PethoiHQh uGt0sVvWal+5R2JU3m9sGpMFovzb7Kxz4PGB71ZpsLqikeGsvEIsgQ8gTEcJQoS4Ie EtNAdUC3ZXph9csaxc31gQ7a8ew6cfWPuYK/y4Kc= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 0F8343854822 for ; Thu, 27 Jul 2023 17:13:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F8343854822 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-70-qRvCplv4MWaX6wAQjnf8Ew-1; Thu, 27 Jul 2023 13:13:19 -0400 X-MC-Unique: qRvCplv4MWaX6wAQjnf8Ew-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B49C1805951; Thu, 27 Jul 2023 17:13:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 138942166B27; Thu, 27 Jul 2023 17:13:17 +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 36RHDFO82823055 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 19:13:15 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 36RHDDwW2823054; Thu, 27 Jul 2023 19:13:13 +0200 Date: Thu, 27 Jul 2023 19:13:13 +0200 To: gcc-patches@gcc.gnu.org Cc: "Joseph S. Myers" , Uros Bizjak , Ian Lance Taylor Subject: [PATCH 2/5] libgcc _BitInt support [PR102989] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.9 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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: 1772594883464710519 X-GMAIL-MSGID: 1772594883464710519 Hi! This patch adds the library helpers for multiplication, division + modulo and casts from and to floating point. As described in the intro, the first step is try to reduce further the passed in precision by skipping over most significant limbs with just zeros or sign bit copies. For multiplication and division I've implemented a simple algorithm, using something smarter like Karatsuba or Toom N-Way might be faster for very large _BitInts (which we don't support right now anyway), but could mean more code in libgcc, which maybe isn't what people are willing to accept. For the to/from floating point conversions the patch uses soft-fp, because it already has tons of handy macros which can be used for that. In theory it could be implemented using {,unsigned} long long or {,unsigned} __int128 to/from floating point conversions with some frexp before/after, but at that point we already need to force it into integer registers and analyze it anyway. Plus, for 32-bit arches there is no __int128 that could be used for XF/TF mode stuff. I know that soft-fp is owned by glibc and I think the op-common.h change should be propagated there, but the bitint stuff is really GCC specific and IMHO doesn't belong into the glibc copy. 2023-07-27 Jakub Jelinek PR c/102989 libgcc/ * config/aarch64/t-softfp (softfp_extras): Use += rather than :=. * config/i386/64/t-softfp (softfp_extras): Likewise. * config/i386/libgcc-glibc.ver (GCC_14.0.0): Export _BitInt support routines. * config/i386/t-softfp (softfp_extras): Add fixxfbitint and bf, hf and xf mode floatbitint. (CFLAGS-floatbitintbf.c, CFLAGS-floatbitinthf.c): Add -msse2. * config/riscv/t-softfp32 (softfp_extras): Use += rather than :=. * config/rs6000/t-e500v1-fp (softfp_extras): Likewise. * config/rs6000/t-e500v2-fp (softfp_extras): Likewise. * config/t-softfp (softfp_floatbitint_funcs): New. (softfp_func_list): Add sf and df mode from and to _BitInt libcalls. * config/t-softfp-sfdftf (softfp_extras): Add fixtfbitint and floatbitinttf. * config/t-softfp-tf (softfp_extras): Likewise. * libgcc2.c (bitint_reduce_prec): New inline function. (BITINT_INC, BITINT_END): Define. (bitint_mul_1, bitint_addmul_1): New helper functions. (__mulbitint3): New function. (bitint_negate, bitint_submul_1): New helper functions. (__divmodbitint4): New function. * libgcc2.h (LIBGCC2_UNITS_PER_WORD): When building _BitInt support libcalls, redefine depending on __LIBGCC_BITINT_LIMB_WIDTH__. (__mulbitint3, __divmodbitint4): Declare. * libgcc-std.ver.in (GCC_14.0.0): Export _BitInt support routines. * Makefile.in (lib2funcs): Add _mulbitint3. (LIB2_DIVMOD_FUNCS): Add _divmodbitint4. * soft-fp/bitint.h: New file. * soft-fp/fixdfbitint.c: New file. * soft-fp/fixsfbitint.c: New file. * soft-fp/fixtfbitint.c: New file. * soft-fp/fixxfbitint.c: New file. * soft-fp/floatbitintbf.c: New file. * soft-fp/floatbitintdf.c: New file. * soft-fp/floatbitinthf.c: New file. * soft-fp/floatbitintsf.c: New file. * soft-fp/floatbitinttf.c: New file. * soft-fp/floatbitintxf.c: New file. * soft-fp/op-common.h (_FP_FROM_INT): Add support for rsize up to 4 * _FP_W_TYPE_SIZE rather than just 2 * _FP_W_TYPE_SIZE. Jakub --- libgcc/config/aarch64/t-softfp.jj 2023-03-13 00:11:52.330213322 +0100 +++ libgcc/config/aarch64/t-softfp 2023-07-14 12:38:30.764869473 +0200 @@ -3,7 +3,7 @@ softfp_int_modes := si di ti softfp_extensions := sftf dftf hftf bfsf softfp_truncations := tfsf tfdf tfhf tfbf dfbf sfbf hfbf softfp_exclude_libgcc2 := n -softfp_extras := fixhfti fixunshfti floattihf floatuntihf \ +softfp_extras += fixhfti fixunshfti floattihf floatuntihf \ floatdibf floatundibf floattibf floatuntibf TARGET_LIBGCC2_CFLAGS += -Wno-missing-prototypes --- libgcc/config/i386/64/t-softfp.jj 2023-03-10 20:39:43.849687830 +0100 +++ libgcc/config/i386/64/t-softfp 2023-07-14 12:37:55.422344930 +0200 @@ -1,4 +1,4 @@ -softfp_extras := fixhfti fixunshfti floattihf floatuntihf \ +softfp_extras += fixhfti fixunshfti floattihf floatuntihf \ floattibf floatuntibf CFLAGS-fixhfti.c += -msse2 --- libgcc/config/i386/libgcc-glibc.ver.jj 2023-07-11 13:39:49.760107863 +0200 +++ libgcc/config/i386/libgcc-glibc.ver 2023-07-17 09:45:43.128281615 +0200 @@ -226,3 +226,13 @@ GCC_13.0.0 { __truncxfbf2 __trunchfbf2 } + +%inherit GCC_14.0.0 GCC_13.0.0 +GCC_14.0.0 { + __PFX__fixxfbitint + __PFX__fixtfbitint + __PFX__floatbitintbf + __PFX__floatbitinthf + __PFX__floatbitintxf + __PFX__floatbitinttf +} --- libgcc/config/i386/t-softfp.jj 2022-10-14 09:35:56.268989311 +0200 +++ libgcc/config/i386/t-softfp 2023-07-17 09:38:43.575980078 +0200 @@ -10,7 +10,7 @@ softfp_extensions := hfsf hfdf hftf hfxf softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf \ tfbf xfbf dfbf sfbf hfbf -softfp_extras += eqhf2 +softfp_extras += eqhf2 fixxfbitint $(foreach m,hf bf xf,floatbitint$(m)) CFLAGS-extendhfsf2.c += -msse2 CFLAGS-extendhfdf2.c += -msse2 @@ -28,6 +28,9 @@ CFLAGS-truncxfbf2.c += -msse2 CFLAGS-trunctfbf2.c += -msse2 CFLAGS-trunchfbf2.c += -msse2 +CFLAGS-floatbitintbf.c += -msse2 +CFLAGS-floatbitinthf.c += -msse2 + CFLAGS-eqhf2.c += -msse2 CFLAGS-_divhc3.c += -msse2 CFLAGS-_mulhc3.c += -msse2 --- libgcc/config/riscv/t-softfp32.jj 2022-08-17 16:59:09.291544033 +0200 +++ libgcc/config/riscv/t-softfp32 2023-07-14 12:36:57.895118834 +0200 @@ -13,7 +13,7 @@ softfp_extensions := sftf dftf softfp_truncations := tfsf tfdf # Enable divide routines to make -mno-fdiv work. -softfp_extras := divsf3 divdf3 +softfp_extras += divsf3 divdf3 else # !ABI_DOUBLE @@ -28,7 +28,7 @@ else # ABI_SINGLE # Enable divide routines to make -mno-fdiv work. -softfp_extras := divsf3 +softfp_extras += divsf3 endif @@ -38,7 +38,7 @@ else # ABI_QUAD # Enable divide routines to make -mno-fdiv work. -softfp_extras := divsf3 divdf3 divtf3 +softfp_extras += divsf3 divdf3 divtf3 endif --- libgcc/config/rs6000/t-e500v1-fp.jj 2023-01-16 11:52:16.774723882 +0100 +++ libgcc/config/rs6000/t-e500v1-fp 2023-07-14 12:39:03.906423712 +0200 @@ -29,4 +29,4 @@ softfp_int_modes := si di softfp_extensions := sfdf softfp_truncations := dfsf softfp_exclude_libgcc2 := n -softfp_extras := unordsf2 +softfp_extras += unordsf2 --- libgcc/config/rs6000/t-e500v2-fp.jj 2023-01-16 11:52:16.774723882 +0100 +++ libgcc/config/rs6000/t-e500v2-fp 2023-07-14 12:39:09.924342992 +0200 @@ -23,4 +23,4 @@ softfp_int_modes := softfp_extensions := softfp_truncations := softfp_exclude_libgcc2 := n -softfp_extras := unordsf2 unorddf2 +softfp_extras += unordsf2 unorddf2 --- libgcc/config/t-softfp.jj 2023-01-16 11:52:16.778723823 +0100 +++ libgcc/config/t-softfp 2023-07-17 09:35:07.802912565 +0200 @@ -64,12 +64,14 @@ softfp_float_funcs = add$(m)3 div$(m)3 e neg$(m)2 sub$(m)3 unord$(m)2 softfp_floatint_funcs = fix$(m)$(i) fixuns$(m)$(i) \ float$(i)$(m) floatun$(i)$(m) +softfp_floatbitint_funcs = fix$(m)bitint floatbitint$(m) softfp_func_list := \ $(foreach m,$(softfp_float_modes), \ $(softfp_float_funcs) \ $(foreach i,$(softfp_int_modes), \ $(softfp_floatint_funcs))) \ + $(foreach m,sf df,$(softfp_floatbitint_funcs)) \ $(foreach e,$(softfp_extensions),extend$(e)2) \ $(foreach t,$(softfp_truncations),trunc$(t)2) \ $(softfp_extras) --- libgcc/config/t-softfp-sfdftf.jj 2020-01-12 11:54:38.691379040 +0100 +++ libgcc/config/t-softfp-sfdftf 2023-07-17 09:35:59.283212918 +0200 @@ -2,4 +2,5 @@ softfp_float_modes := sf df tf softfp_int_modes := si di softfp_extensions := sfdf sftf dftf xftf softfp_truncations := dfsf tfsf tfdf tfxf +softfp_extras += fixtfbitint floatbitinttf softfp_exclude_libgcc2 := n --- libgcc/config/t-softfp-tf.jj 2020-01-12 11:54:38.691379040 +0100 +++ libgcc/config/t-softfp-tf 2023-07-17 09:35:18.190771387 +0200 @@ -2,4 +2,5 @@ softfp_float_modes := tf softfp_int_modes := si di ti softfp_extensions := sftf dftf xftf softfp_truncations := tfsf tfdf tfxf +softfp_extras += fixtfbitint floatbitinttf softfp_exclude_libgcc2 := n --- libgcc/libgcc2.c.jj 2023-07-11 13:39:49.777107635 +0200 +++ libgcc/libgcc2.c 2023-07-22 12:18:43.743740024 +0200 @@ -1301,6 +1301,687 @@ __udivdi3 (UDWtype n, UDWtype d) } #endif +#if (defined(__BITINT_MAXWIDTH__) \ + && (defined(L_mulbitint3) || defined(L_divmodbitint4))) +/* _BitInt support. */ + +/* If *P is zero or sign extended (the latter only for PREC < 0) from + some narrower _BitInt value, reduce precision. */ + +static inline __attribute__((__always_inline__)) SItype +bitint_reduce_prec (const UWtype **p, SItype prec) +{ + UWtype mslimb; + SItype i; + if (prec < 0) + { +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + i = 0; +#else + i = ((USItype) -1 - prec) / W_TYPE_SIZE; +#endif + mslimb = (*p)[i]; + if (mslimb & ((UWtype) 1 << (((USItype) -1 - prec) % W_TYPE_SIZE))) + { + SItype n = ((USItype) -prec) % W_TYPE_SIZE; + if (n) + { + mslimb |= ((UWtype) -1 << (((USItype) -1 - prec) % W_TYPE_SIZE)); + if (mslimb == (UWtype) -1) + { + prec += n; + if (prec >= -1) + return -2; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + n = 0; + } + } + while (mslimb == (UWtype) -1) + { + prec += W_TYPE_SIZE; + if (prec >= -1) + return -2; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + } + if (n == 0) + { + if ((Wtype) mslimb >= 0) + { +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + --p; +#endif + return prec - 1; + } + } + return prec; + } + else + prec = -prec; + } + else + { +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + i = 0; +#else + i = ((USItype) prec - 1) / W_TYPE_SIZE; +#endif + mslimb = (*p)[i]; + } + SItype n = ((USItype) prec) % W_TYPE_SIZE; + if (n) + { + mslimb &= ((UWtype) 1 << (((USItype) prec) % W_TYPE_SIZE)) - 1; + if (mslimb == 0) + { + prec -= n; + if (prec == 0) + return 1; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + } + } + while (mslimb == 0) + { + prec -= W_TYPE_SIZE; + if (prec == 0) + return 1; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + } + return prec; +} + +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ +# define BITINT_INC -1 +# define BITINT_END(be, le) (be) +#else +# define BITINT_INC 1 +# define BITINT_END(be, le) (le) +#endif + +#ifdef L_mulbitint3 +/* D = S * L. */ + +static UWtype +bitint_mul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n) +{ + UWtype sv, hi, lo, c = 0; + do + { + sv = *s; + s += BITINT_INC; + umul_ppmm (hi, lo, sv, l); + c = __builtin_add_overflow (lo, c, &lo) + hi; + *d = lo; + d += BITINT_INC; + } + while (--n); + return c; +} + +/* D += S * L. */ + +static UWtype +bitint_addmul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n) +{ + UWtype sv, hi, lo, c = 0; + do + { + sv = *s; + s += BITINT_INC; + umul_ppmm (hi, lo, sv, l); + hi += __builtin_add_overflow (lo, *d, &lo); + c = __builtin_add_overflow (lo, c, &lo) + hi; + *d = lo; + d += BITINT_INC; + } + while (--n); + return c; +} + +/* If XPREC is positive, it is precision in bits + of an unsigned _BitInt operand (which has XPREC/W_TYPE_SIZE + full limbs and if Xprec%W_TYPE_SIZE one partial limb. + If Xprec is negative, -XPREC is precision in bits + of a signed _BitInt operand. RETPREC should be always + positive. */ + +void +__mulbitint3 (UWtype *ret, SItype retprec, + const UWtype *u, SItype uprec, + const UWtype *v, SItype vprec) +{ + uprec = bitint_reduce_prec (&u, uprec); + vprec = bitint_reduce_prec (&v, vprec); + USItype auprec = uprec < 0 ? -uprec : uprec; + USItype avprec = vprec < 0 ? -vprec : vprec; + + /* Prefer non-negative U. + Otherwise make sure V doesn't have higher precision than U. */ + if ((uprec < 0 && vprec >= 0) + || (avprec > auprec && !(uprec >= 0 && vprec < 0))) + { + SItype p; + const UWtype *t; + p = uprec; uprec = vprec; vprec = p; + p = auprec; auprec = avprec; avprec = p; + t = u; u = v; v = t; + } + + USItype un = auprec / W_TYPE_SIZE; + USItype un2 = (auprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype vn = avprec / W_TYPE_SIZE; + USItype vn2 = (avprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype retn = ((USItype) retprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype retidx, uidx, vidx; + UWtype vv; + /* Indexes of least significant limb. */ +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + retidx = retn - 1; + uidx = un2 - 1; + vidx = vn2 - 1; +#else + retidx = 0; + uidx = 0; + vidx = 0; +#endif + if (__builtin_expect (auprec <= W_TYPE_SIZE, 0) && vprec < 0) + { + UWtype uu = u[uidx]; + if (__builtin_expect (auprec < W_TYPE_SIZE, 0)) + uu &= ((UWtype) 1 << (auprec % W_TYPE_SIZE)) - 1; + if (uu == 0) + { + /* 0 * negative would be otherwise mishandled below, so + handle it specially. */ + __builtin_memset (ret, 0, retn * sizeof (UWtype)); + return; + } + } + vv = v[vidx]; + if (__builtin_expect (avprec < W_TYPE_SIZE, 0)) + { + if (vprec > 0) + vv &= ((UWtype) 1 << (avprec % W_TYPE_SIZE)) - 1; + else + vv |= (UWtype) -1 << (avprec % W_TYPE_SIZE); + } + + USItype n = un > retn ? retn : un; + USItype n2 = n; + USItype retidx2 = retidx + n * BITINT_INC; + UWtype c = 0, uv = 0; + if (n) + c = bitint_mul_1 (ret + retidx, u + uidx, vv, n); + if (retn > un && un2 != un) + { + UWtype hi, lo; + uv = u[uidx + n * BITINT_INC]; + if (uprec > 0) + uv &= ((UWtype) 1 << (auprec % W_TYPE_SIZE)) - 1; + else + uv |= (UWtype) -1 << (auprec % W_TYPE_SIZE); + umul_ppmm (hi, lo, uv, vv); + c = __builtin_add_overflow (lo, c, &lo) + hi; + ret[retidx2] = lo; + retidx2 += BITINT_INC; + ++n2; + } + if (retn > un2) + { + if (uprec < 0) + { + while (n2 < retn) + { + if (n2 >= un2 + vn2) + break; + UWtype hi, lo; + umul_ppmm (hi, lo, (UWtype) -1, vv); + c = __builtin_add_overflow (lo, c, &lo) + hi; + ret[retidx2] = lo; + retidx2 += BITINT_INC; + ++n2; + } + } + else + { + ret[retidx2] = c; + retidx2 += BITINT_INC; + ++n2; + } + /* If RET has more limbs than U after precision reduction, + fill in the remaining limbs. */ + while (n2 < retn) + { + if (n2 < un2 + vn2 || (uprec ^ vprec) >= 0) + c = 0; + else + c = (UWtype) -1; + ret[retidx2] = c; + retidx2 += BITINT_INC; + ++n2; + } + } + /* N is now number of possibly non-zero limbs in RET (ignoring + limbs above UN2 + VN2 which if any have been finalized already). */ + USItype end = vprec < 0 ? un2 + vn2 : vn2; + if (retn > un2 + vn2) retn = un2 + vn2; + if (end > retn) end = retn; + for (USItype m = 1; m < end; ++m) + { + retidx += BITINT_INC; + vidx += BITINT_INC; + if (m < vn2) + { + vv = v[vidx]; + if (__builtin_expect (m == vn, 0)) + { + if (vprec > 0) + vv &= ((UWtype) 1 << (avprec % W_TYPE_SIZE)) - 1; + else + vv |= (UWtype) -1 << (avprec % W_TYPE_SIZE); + } + } + else + vv = (UWtype) -1; + if (m + n > retn) + n = retn - m; + c = 0; + if (n) + c = bitint_addmul_1 (ret + retidx, u + uidx, vv, n); + n2 = m + n; + retidx2 = retidx + n * BITINT_INC; + if (n2 < retn && un2 != un) + { + UWtype hi, lo; + umul_ppmm (hi, lo, uv, vv); + hi += __builtin_add_overflow (lo, ret[retidx2], &lo); + c = __builtin_add_overflow (lo, c, &lo) + hi; + ret[retidx2] = lo; + retidx2 += BITINT_INC; + ++n2; + } + if (uprec < 0) + while (n2 < retn) + { + UWtype hi, lo; + umul_ppmm (hi, lo, (UWtype) -1, vv); + hi += __builtin_add_overflow (lo, ret[retidx2], &lo); + c = __builtin_add_overflow (lo, c, &lo) + hi; + ret[retidx2] = lo; + retidx2 += BITINT_INC; + ++n2; + } + else if (n2 < retn) + { + ret[retidx2] = c; + retidx2 += BITINT_INC; + } + } +} +#endif + +#ifdef L_divmodbitint4 +static void +bitint_negate (UWtype *d, const UWtype *s, SItype n) +{ + UWtype c = 1; + do + { + UWtype sv = *s, lo; + s += BITINT_INC; + c = __builtin_add_overflow (~sv, c, &lo); + *d = lo; + d += BITINT_INC; + } + while (--n); +} + +/* D -= S * L. */ + +static UWtype +bitint_submul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n) +{ + UWtype sv, hi, lo, c = 0; + do + { + sv = *s; + s += BITINT_INC; + umul_ppmm (hi, lo, sv, l); + hi += __builtin_sub_overflow (*d, lo, &lo); + c = __builtin_sub_overflow (lo, c, &lo) + hi; + *d = lo; + d += BITINT_INC; + } + while (--n); + return c; +} + +/* If XPREC is positive, it is precision in bits + of an unsigned _BitInt operand (which has XPREC/W_TYPE_SIZE + full limbs and if Xprec%W_TYPE_SIZE one partial limb. + If Xprec is negative, -XPREC is precision in bits + of a signed _BitInt operand. QPREC and RPREC should be + always non-negative. If either Q or R is NULL (at least + one should be non-NULL), then corresponding QPREC or RPREC + should be 0. */ + +void +__divmodbitint4 (UWtype *q, SItype qprec, + UWtype *r, SItype rprec, + const UWtype *u, SItype uprec, + const UWtype *v, SItype vprec) +{ + uprec = bitint_reduce_prec (&u, uprec); + vprec = bitint_reduce_prec (&v, vprec); + USItype auprec = uprec < 0 ? -uprec : uprec; + USItype avprec = vprec < 0 ? -vprec : vprec; + USItype un = (auprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype vn = (avprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype qn = ((USItype) qprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE; + USItype up = auprec % W_TYPE_SIZE; + USItype vp = avprec % W_TYPE_SIZE; + if (__builtin_expect (un < vn, 0)) + { + /* If abs(v) > abs(u), then q is 0 and r is u. */ + if (q) + __builtin_memset (q, 0, qn * sizeof (UWtype)); + if (r == NULL) + return; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + r += rn - 1; + u += un - 1; +#endif + if (up) + --un; + if (rn < un) + un = rn; + for (rn -= un; un; --un) + { + *r = *u; + r += BITINT_INC; + u += BITINT_INC; + } + if (!rn) + return; + if (up) + { + if (uprec > 0) + *r = *u & (((UWtype) 1 << up) - 1); + else + *r = *u | ((UWtype) -1 << up); + r += BITINT_INC; + if (!--rn) + return; + } + UWtype c = uprec < 0 ? (UWtype) -1 : (UWtype) 0; + for (; rn; --rn) + { + *r = c; + r += BITINT_INC; + } + return; + } + USItype qn2 = un - vn + 1; + if (qn >= qn2) + qn2 = 0; + USItype sz = un + 1 + vn + qn2; + UWtype *buf = __builtin_alloca (sz * sizeof (UWtype)); + USItype uidx, vidx; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + uidx = un - 1; + vidx = vn - 1; +#else + uidx = 0; + vidx = 0; +#endif + if (uprec < 0) + bitint_negate (buf + BITINT_END (uidx + 1, 0), u + uidx, un); + else + __builtin_memcpy (buf + BITINT_END (1, 0), u, un * sizeof (UWtype)); + if (up) + buf[BITINT_END (1, un - 1)] &= (((UWtype) 1 << up) - 1); + if (vprec < 0) + bitint_negate (buf + un + 1 + vidx, v + vidx, vn); + else + __builtin_memcpy (buf + un + 1, v, vn * sizeof (UWtype)); + if (vp) + buf[un + 1 + BITINT_END (0, vn - 1)] &= (((UWtype) 1 << vp) - 1); + UWtype *u2 = buf; + UWtype *v2 = u2 + un + 1; + UWtype *q2 = v2 + vn; + if (!qn2) + q2 = q + BITINT_END (qn - (un - vn + 1), 0); + + /* Knuth's algorithm. See also ../gcc/wide-int.cc (divmod_internal_2). */ + +#ifndef UDIV_NEEDS_NORMALIZATION + /* Handle single limb divisor first. */ + if (vn == 1) + { + UWtype vv = v2[0]; + if (vv == 0) + vv = 1 / vv; /* Divide intentionally by zero. */ + UWtype k = 0; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + for (SItype i = 0; i <= un - 1; ++i) +#else + for (SItype i = un - 1; i >= 0; --i) +#endif + udiv_qrnnd (q2[i], k, k, u2[BITINT_END (i + 1, i)], vv); + if (r != NULL) + r[BITINT_END (rn - 1, 0)] = k; + } + else +#endif + { + SItype s; +#ifdef UDIV_NEEDS_NORMALIZATION + if (vn == 1 && v2[0] == 0) + s = 0; + else +#endif + if (sizeof (0U) == sizeof (UWtype)) + s = __builtin_clz (v2[BITINT_END (0, vn - 1)]); + else if (sizeof (0UL) == sizeof (UWtype)) + s = __builtin_clzl (v2[BITINT_END (0, vn - 1)]); + else + s = __builtin_clzll (v2[BITINT_END (0, vn - 1)]); + if (s) + { + /* Normalize by shifting v2 left so that it has msb set. */ + const SItype n = sizeof (UWtype) * __CHAR_BIT__; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + for (SItype i = 0; i < vn - 1; ++i) +#else + for (SItype i = vn - 1; i > 0; --i) +#endif + v2[i] = (v2[i] << s) | (v2[i - BITINT_INC] >> (n - s)); + v2[vidx] = v2[vidx] << s; + /* And shift u2 left by the same amount. */ + u2[BITINT_END (0, un)] = u2[BITINT_END (1, un - 1)] >> (n - s); +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + for (SItype i = 1; i < un; ++i) +#else + for (SItype i = un - 1; i > 0; --i) +#endif + u2[i] = (u2[i] << s) | (u2[i - BITINT_INC] >> (n - s)); + u2[BITINT_END (un, 0)] = u2[BITINT_END (un, 0)] << s; + } + else + u2[BITINT_END (0, un)] = 0; +#ifdef UDIV_NEEDS_NORMALIZATION + /* Handle single limb divisor first. */ + if (vn == 1) + { + UWtype vv = v2[0]; + if (vv == 0) + vv = 1 / vv; /* Divide intentionally by zero. */ + UWtype k = u2[BITINT_END (0, un)]; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + for (SItype i = 0; i <= un - 1; ++i) +#else + for (SItype i = un - 1; i >= 0; --i) +#endif + udiv_qrnnd (q2[i], k, k, u2[BITINT_END (i + 1, i)], vv); + if (r != NULL) + r[BITINT_END (rn - 1, 0)] = k >> s; + } + else +#endif + { + UWtype vv1 = v2[BITINT_END (0, vn - 1)]; + UWtype vv0 = v2[BITINT_END (1, vn - 2)]; + /* Main loop. */ + for (SItype j = un - vn; j >= 0; --j) + { + /* Compute estimate in qhat. */ + UWtype uv1 = u2[BITINT_END (un - j - vn, j + vn)]; + UWtype uv0 = u2[BITINT_END (un - j - vn + 1, j + vn - 1)]; + UWtype qhat, rhat, hi, lo, c; + if (uv1 >= vv1) + { + /* udiv_qrnnd doesn't support quotients which don't + fit into UWtype, so subtract from uv1:uv0 vv1 + first. */ + uv1 -= vv1 + __builtin_sub_overflow (uv0, vv1, &uv0); + udiv_qrnnd (qhat, rhat, uv1, uv0, vv1); + if (!__builtin_add_overflow (rhat, vv1, &rhat)) + goto again; + } + else + { + udiv_qrnnd (qhat, rhat, uv1, uv0, vv1); + again: + umul_ppmm (hi, lo, qhat, vv0); + if (hi > rhat + || (hi == rhat + && lo > u2[BITINT_END (un - j - vn + 2, + j + vn - 2)])) + { + --qhat; + if (!__builtin_add_overflow (rhat, vv1, &rhat)) + goto again; + } + } + + c = bitint_submul_1 (u2 + BITINT_END (un - j, j), + v2 + BITINT_END (vn - 1, 0), qhat, vn); + u2[BITINT_END (un - j - vn, j + vn)] -= c; + /* If we've subtracted too much, decrease qhat and + and add back. */ + if ((Wtype) u2[BITINT_END (un - j - vn, j + vn)] < 0) + { + --qhat; + c = 0; + for (USItype i = 0; i < vn; ++i) + { + UWtype s = v2[BITINT_END (vn - 1 - i, i)]; + UWtype d = u2[BITINT_END (un - i - j, i + j)]; + UWtype c1 = __builtin_add_overflow (d, s, &d); + UWtype c2 = __builtin_add_overflow (d, c, &d); + c = c1 + c2; + u2[BITINT_END (un - i - j, i + j)] = d; + } + u2[BITINT_END (un - j - vn, j + vn)] += c; + } + q2[BITINT_END (un - vn - j, j)] = qhat; + } + if (r != NULL) + { + if (s) + { + const SItype n = sizeof (UWtype) * __CHAR_BIT__; + /* Unnormalize remainder. */ + USItype i; + for (i = 0; i < vn && i < rn; ++i) + r[BITINT_END (rn - 1 - i, i)] + = ((u2[BITINT_END (un - i, i)] >> s) + | (u2[BITINT_END (un - i - 1, i + 1)] << (n - s))); + if (i < rn) + r[BITINT_END (rn - vn, vn - 1)] + = u2[BITINT_END (un - vn + 1, vn - 1)] >> s; + } + else if (rn > vn) + __builtin_memcpy (&r[BITINT_END (rn - vn, 0)], + &u2[BITINT_END (un + 1 - vn, 0)], + vn * sizeof (UWtype)); + else + __builtin_memcpy (&r[0], &u2[BITINT_END (un + 1 - rn, 0)], + rn * sizeof (UWtype)); + } + } + } + if (q != NULL) + { + if ((uprec < 0) ^ (vprec < 0)) + { + /* Negative quotient. */ + USItype n; + if (un - vn + 1 > qn) + n = qn; + else + n = un - vn + 1; + bitint_negate (q + BITINT_END (qn - 1, 0), + q2 + BITINT_END (un - vn, 0), n); + if (qn > n) + __builtin_memset (q + BITINT_END (0, n), -1, + (qn - n) * sizeof (UWtype)); + } + else + { + /* Positive quotient. */ + if (qn2) + __builtin_memcpy (q, q2 + BITINT_END (un - vn + 1 - qn, 0), + qn * sizeof (UWtype)); + else if (qn > un - vn + 1) + __builtin_memset (q + BITINT_END (0, un - vn + 1), 0, + (qn - (un - vn + 1)) * sizeof (UWtype)); + } + } + if (r != NULL) + { + if (uprec < 0) + { + /* Negative remainder. */ + bitint_negate (r + BITINT_END (rn - 1, 0), + r + BITINT_END (rn - 1, 0), + rn > vn ? vn : rn); + if (rn > vn) + __builtin_memset (r + BITINT_END (0, vn), -1, + (rn - vn) * sizeof (UWtype)); + } + else + { + /* Positive remainder. */ + if (rn > vn) + __builtin_memset (r + BITINT_END (0, vn), 0, + (rn - vn) * sizeof (UWtype)); + } + } +} +#endif +#endif + #ifdef L_cmpdi2 cmp_return_type __cmpdi2 (DWtype a, DWtype b) --- libgcc/libgcc2.h.jj 2023-07-11 13:39:49.817107100 +0200 +++ libgcc/libgcc2.h 2023-07-12 14:21:56.996358364 +0200 @@ -181,6 +181,12 @@ typedef int shift_count_type __attribute #define float bogus_type #define double bogus_type +#if (defined(__BITINT_MAXWIDTH__) \ + && (defined(L_mulbitint3) || defined(L_divmodbitint4))) +#undef LIBGCC2_UNITS_PER_WORD +#define LIBGCC2_UNITS_PER_WORD (__LIBGCC_BITINT_LIMB_WIDTH__ / __CHAR_BIT__) +#endif + /* Versions prior to 3.4.4 were not taking into account the word size for the 5 trapping arithmetic functions absv, addv, subv, mulv and negv. As a consequence, the si and di variants were always and the only ones emitted. @@ -390,6 +396,15 @@ extern DWtype __divmoddi4 (DWtype, DWtyp extern UDWtype __udivmoddi4 (UDWtype, UDWtype, UDWtype *); #endif +#if (defined(__BITINT_MAXWIDTH__) \ + && (defined(L_mulbitint3) || defined(L_divmodbitint4))) +/* _BitInt support. */ +extern void __mulbitint3 (UWtype *, SItype, const UWtype *, SItype, + const UWtype *, SItype); +extern void __divmodbitint4 (UWtype *, SItype, UWtype *, SItype, + const UWtype *, SItype, const UWtype *, SItype); +#endif + /* __negdi2 is static inline when building other libgcc2 portions. */ #if !defined(L_divdi3) && !defined(L_moddi3) extern DWtype __negdi2 (DWtype); --- libgcc/libgcc-std.ver.in.jj 2023-07-11 13:39:49.775107662 +0200 +++ libgcc/libgcc-std.ver.in 2023-07-17 09:45:50.463182114 +0200 @@ -1944,3 +1944,13 @@ GCC_7.0.0 { __PFX__divmoddi4 __PFX__divmodti4 } + +%inherit GCC_14.0.0 GCC_7.0.0 +GCC_14.0.0 { + __PFX__mulbitint3 + __PFX__divmodbitint4 + __PFX__fixsfbitint + __PFX__fixdfbitint + __PFX__floatbitintsf + __PFX__floatbitintdf +} --- libgcc/Makefile.in.jj 2023-07-11 13:39:49.722108372 +0200 +++ libgcc/Makefile.in 2023-07-14 12:32:32.134694076 +0200 @@ -446,7 +446,7 @@ lib2funcs = _muldi3 _negdi2 _lshrdi3 _as _paritysi2 _paritydi2 _powisf2 _powidf2 _powixf2 _powitf2 \ _mulhc3 _mulsc3 _muldc3 _mulxc3 _multc3 _divhc3 _divsc3 \ _divdc3 _divxc3 _divtc3 _bswapsi2 _bswapdi2 _clrsbsi2 \ - _clrsbdi2 + _clrsbdi2 _mulbitint3 # The floating-point conversion routines that involve a single-word integer. # XX stands for the integer mode. @@ -466,7 +466,8 @@ endif # These might cause a divide overflow trap and so are compiled with # unwinder info. LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _divmoddi4 \ - _udivdi3 _umoddi3 _udivmoddi4 _udiv_w_sdiv + _udivdi3 _umoddi3 _udivmoddi4 _udiv_w_sdiv \ + _divmodbitint4 # Remove any objects from lib2funcs and LIB2_DIVMOD_FUNCS that are # defined as optimized assembly code in LIB1ASMFUNCS or as C code --- libgcc/soft-fp/bitint.h.jj 2023-07-13 12:45:21.000663607 +0200 +++ libgcc/soft-fp/bitint.h 2023-07-14 23:35:51.539466644 +0200 @@ -0,0 +1,306 @@ +/* Software floating-point emulation. + Definitions for _BitInt implementation details. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#ifndef GCC_SOFT_FP_BITINT_H +#define GCC_SOFT_FP_BITINT_H + +#ifdef __BITINT_MAXWIDTH__ +#define BIL_UNITS_PER_WORD (__LIBGCC_BITINT_LIMB_WIDTH__ / __CHAR_BIT__) + +#if BIL_UNITS_PER_WORD == 8 +#define BIL_TYPE_SIZE (8 * __CHAR_BIT__) +#define BILtype DItype +#define UBILtype UDItype +#elif BIL_UNITS_PER_WORD == 4 +#define BIL_TYPE_SIZE (4 * __CHAR_BIT__) +#define BILtype SItype +#define UBILtype USItype +#elif BIL_UNITS_PER_WORD == 2 +#define BIL_TYPE_SIZE (2 * __CHAR_BIT__) +#define BILtype HItype +#define UBILtype UHItype +#else +#define BIL_TYPE_SIZE __CHAR_BIT__ +#define BILtype QItype +#define UBILtype UQItype +#endif + +/* If *P is zero or sign extended (the latter only for PREC < 0) from + some narrower _BitInt value, reduce precision. */ + +static inline __attribute__((__always_inline__)) SItype +bitint_reduce_prec (const UBILtype **p, SItype prec) +{ + UBILtype mslimb; + SItype i; + if (prec < 0) + { +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + i = 0; +#else + i = ((USItype) -1 - prec) / BIL_TYPE_SIZE; +#endif + mslimb = (*p)[i]; + if (mslimb & ((UBILtype) 1 << (((USItype) -1 - prec) % BIL_TYPE_SIZE))) + { + SItype n = ((USItype) -prec) % BIL_TYPE_SIZE; + if (n) + { + mslimb |= ((UBILtype) -1 << (((USItype) -1 - prec) % BIL_TYPE_SIZE)); + if (mslimb == (UBILtype) -1) + { + prec += n; + if (prec >= -1) + return -2; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + n = 0; + } + } + while (mslimb == (UBILtype) -1) + { + prec += BIL_TYPE_SIZE; + if (prec >= -1) + return -2; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + } + if (n == 0) + { + if ((BILtype) mslimb >= 0) + { +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + --p; +#endif + return prec - 1; + } + } + return prec; + } + else + prec = -prec; + } + else + { +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + i = 0; +#else + i = ((USItype) prec - 1) / BIL_TYPE_SIZE; +#endif + mslimb = (*p)[i]; + } + SItype n = ((USItype) prec) % BIL_TYPE_SIZE; + if (n) + { + mslimb &= ((UBILtype) 1 << (((USItype) prec) % BIL_TYPE_SIZE)) - 1; + if (mslimb == 0) + { + prec -= n; + if (prec == 0) + return 1; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + } + } + while (mslimb == 0) + { + prec -= BIL_TYPE_SIZE; + if (prec == 0) + return 1; +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ + ++p; +#else + --i; +#endif + mslimb = (*p)[i]; + } + return prec; +} + +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ +# define BITINT_INC -1 +# define BITINT_END(be, le) (be) +#else +# define BITINT_INC 1 +# define BITINT_END(be, le) (le) +#endif + +#define FP_TO_BITINT(r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI) \ + if (ovf) \ + { \ + if ((rv & 1) != 0) \ + __builtin_memset (r, -1, rn * sizeof (UBILtype)); \ + else \ + __builtin_memset (r, 0, rn * sizeof (UBILtype)); \ + if (rv & (((U##DI##type) 1) << (rsize - 1))) \ + r[BITINT_END (0, rn - 1)] \ + |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE); \ + else \ + r[BITINT_END (0, rn - 1)] \ + &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE)); \ + } \ + else \ + { \ + USItype shiftl = shift / BIL_TYPE_SIZE; \ + rsize = DI##_BITS; \ + if (rsigned && (DI##type) rv >= 0) \ + rsigned = 0; \ + if (shift + DI##_BITS > arprec) \ + rsize = arprec - shift; \ + USItype shiftr = shift % BIL_TYPE_SIZE; \ + if (shiftl) \ + __builtin_memset (r + BITINT_END (rn - shiftl, 0), 0, \ + shiftl * sizeof (UBILtype)); \ + USItype idx = BITINT_END (rn - shiftl - 1, shiftl); \ + DI##type rvs = rv; \ + if (shiftr) \ + { \ + r[idx] = (rsigned ? (UBILtype) rvs : (UBILtype) rv) << shiftr;\ + idx += BITINT_INC; \ + if (rsize > BIL_TYPE_SIZE - shiftr) \ + { \ + rv >>= BIL_TYPE_SIZE - shiftr; \ + rvs >>= BIL_TYPE_SIZE - shiftr; \ + rsize -= BIL_TYPE_SIZE - shiftr; \ + } \ + else \ + rsize = 0; \ + } \ + while (rsize) \ + { \ + r[idx] = rsigned ? (UBILtype) rvs : (UBILtype) rv; \ + idx += BITINT_INC; \ + if (rsize <= BIL_TYPE_SIZE) \ + break; \ + rv >>= (DI##_BITS > BIL_TYPE_SIZE ? BIL_TYPE_SIZE : 0); \ + rvs >>= (DI##_BITS > BIL_TYPE_SIZE ? BIL_TYPE_SIZE : 0); \ + rsize -= BIL_TYPE_SIZE; \ + } \ + if (idx < rn) \ + __builtin_memset (r + BITINT_END (0, idx), rsigned ? -1 : 0, \ + BITINT_END (idx + 1, rn - idx) \ + * sizeof (UBILtype)); \ + } + +#define FP_FROM_BITINT(i, iprec, iv, shift, DI) \ + do \ + { \ + iprec = bitint_reduce_prec (&i, iprec); \ + USItype aiprec = iprec < 0 ? -iprec : iprec; \ + USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; \ + USItype idx = BITINT_END (0, in - 1); \ + UBILtype msb = i[idx]; \ + SItype n = 0; \ + if (aiprec % BIL_TYPE_SIZE) \ + { \ + if (iprec > 0) \ + msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1; \ + else \ + msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE); \ + } \ + if (iprec < 0) \ + { \ + n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);\ + if (BIL_TYPE_SIZE > DI##_BITS && n > DI##_BITS) \ + { \ + iv = msb >> (n - DI##_BITS); \ + shift = n - DI##_BITS; \ + n = 0; \ + } \ + else \ + { \ + iv = (BILtype) msb; \ + n = DI##_BITS - n; \ + } \ + } \ + /* bitint_reduce_prec guarantees that if msb is 0, then whole \ + i must be zero, otherwise it would have reduced the \ + precision. */ \ + else if (msb == 0) \ + iv = 0; \ + else \ + { \ + n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb); \ + if (BIL_TYPE_SIZE >= DI##_BITS && n >= DI##_BITS) \ + { \ + iv = msb >> (n - DI##_BITS + 1); \ + shift = n - DI##_BITS + 1; \ + n = 0; \ + } \ + else \ + { \ + iv = msb; \ + n = DI##_BITS - 1 - n; \ + } \ + } \ + while (n && BITINT_END (idx < in - 1, idx)) \ + { \ + idx -= BITINT_INC; \ + msb = i[idx]; \ + if (BIL_TYPE_SIZE < DI##_BITS && n >= BIL_TYPE_SIZE) \ + { \ + iv = (U##DI##type) iv << (BIL_TYPE_SIZE < DI##_BITS \ + ? BIL_TYPE_SIZE : 0); \ + iv |= msb; \ + n -= BIL_TYPE_SIZE; \ + } \ + else \ + { \ + iv = (U##DI##type) iv << n; \ + iv |= msb >> (BIL_TYPE_SIZE - n); \ + shift = BIL_TYPE_SIZE - n; \ + break; \ + } \ + } \ + \ + UBILtype low_bits = 0; \ + if (shift) \ + low_bits = msb & (((UBILtype) 1 << shift) - 1); \ + shift += BITINT_END (in - 1 - idx, idx) * BIL_TYPE_SIZE; \ + while (!low_bits && BITINT_END (idx < in - 1, idx)) \ + { \ + idx -= BITINT_INC; \ + low_bits |= i[idx]; \ + } \ + iv |= (low_bits != 0); \ + } \ + while (0) + +#endif /* __BITINT_MAXWIDTH__ */ + +#endif /* GCC_SOFT_FP_BITINT_H */ --- libgcc/soft-fp/fixdfbitint.c.jj 2023-07-13 12:50:52.639175463 +0200 +++ libgcc/soft-fp/fixdfbitint.c 2023-07-14 09:11:13.705084773 +0200 @@ -0,0 +1,71 @@ +/* Software floating-point emulation. + Convert IEEE double to signed or unsigned _BitInt. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "double.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +void +__fixdfbitint (UBILtype *r, SItype rprec, DFtype a) +{ + FP_DECL_EX; + FP_DECL_D (A); + USItype arprec = rprec < 0 ? -rprec : rprec; + USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; + UDItype rv; + USItype rsize = arprec > DI_BITS ? DI_BITS : arprec; + USItype rsigned = rprec < 0; + USItype ovf = 0; + USItype shift = 0; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_D (A, a); + if (arprec > DI_BITS) + { + if (A_e < _FP_EXPBIAS_D || (A_s && !rsigned)) + ovf = 1; + else if (A_e >= (_FP_EXPMAX_D < _FP_EXPBIAS_D + arprec + ? _FP_EXPMAX_D + : _FP_EXPBIAS_D + arprec - rsigned)) + { + ovf = 1; + if (A_s + && A_e == _FP_EXPBIAS_D + arprec - 1 + && A_e < _FP_EXPMAX_D) + A_e -= arprec - DI_BITS; + } + else if (A_e >= _FP_EXPBIAS_D + DI_BITS - rsigned) + { + shift = A_e - (_FP_EXPBIAS_D + DI_BITS - rsigned - 1); + A_e -= shift; + } + } + FP_TO_INT_D (rv, A, rsize, rsigned); + FP_HANDLE_EXCEPTIONS; + FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI); +} +#endif --- libgcc/soft-fp/fixsfbitint.c.jj 2023-07-14 09:17:15.812063032 +0200 +++ libgcc/soft-fp/fixsfbitint.c 2023-07-14 09:22:00.174119081 +0200 @@ -0,0 +1,71 @@ +/* Software floating-point emulation. + Convert IEEE single to signed or unsigned _BitInt. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "single.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +void +__fixsfbitint (UBILtype *r, SItype rprec, SFtype a) +{ + FP_DECL_EX; + FP_DECL_S (A); + USItype arprec = rprec < 0 ? -rprec : rprec; + USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; + USItype rv; + USItype rsize = arprec > SI_BITS ? SI_BITS : arprec; + USItype rsigned = rprec < 0; + USItype ovf = 0; + USItype shift = 0; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_S (A, a); + if (arprec > SI_BITS) + { + if (A_e < _FP_EXPBIAS_S || (A_s && !rsigned)) + ovf = 1; + else if (A_e >= (_FP_EXPMAX_S < _FP_EXPBIAS_S + arprec + ? _FP_EXPMAX_S + : _FP_EXPBIAS_S + arprec - rsigned)) + { + ovf = 1; + if (A_s + && A_e == _FP_EXPBIAS_S + arprec - 1 + && A_e < _FP_EXPMAX_S) + A_e -= arprec - SI_BITS; + } + else if (A_e >= _FP_EXPBIAS_S + SI_BITS - rsigned) + { + shift = A_e - (_FP_EXPBIAS_S + SI_BITS - rsigned - 1); + A_e -= shift; + } + } + FP_TO_INT_S (rv, A, rsize, rsigned); + FP_HANDLE_EXCEPTIONS; + FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI); +} +#endif --- libgcc/soft-fp/fixtfbitint.c.jj 2023-07-14 12:24:54.024856956 +0200 +++ libgcc/soft-fp/fixtfbitint.c 2023-07-14 09:34:17.091902919 +0200 @@ -0,0 +1,81 @@ +/* Software floating-point emulation. + Convert IEEE quad to signed or unsigned _BitInt. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "quad.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ + +#ifndef TI_BITS +/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit + type, but on most 32-bit architectures TImode isn't supported. + Use _BitInt(128) instead. */ +typedef _BitInt(128) TItype; +typedef unsigned _BitInt(128) UTItype; +#define TI_BITS 128 +#endif + +void +__fixtfbitint (UBILtype *r, SItype rprec, TFtype a) +{ + FP_DECL_EX; + FP_DECL_Q (A); + USItype arprec = rprec < 0 ? -rprec : rprec; + USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; + UTItype rv; + USItype rsize = arprec > TI_BITS ? TI_BITS : arprec; + USItype rsigned = rprec < 0; + USItype ovf = 0; + USItype shift = 0; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_Q (A, a); + if (arprec > TI_BITS) + { + if (A_e < _FP_EXPBIAS_Q || (A_s && !rsigned)) + ovf = 1; + else if (A_e >= (_FP_EXPMAX_Q < _FP_EXPBIAS_Q + arprec + ? _FP_EXPMAX_Q + : _FP_EXPBIAS_Q + arprec - rsigned)) + { + ovf = 1; + if (A_s + && A_e == _FP_EXPBIAS_Q + arprec - 1 + && A_e < _FP_EXPMAX_Q) + A_e -= arprec - TI_BITS; + } + else if (A_e >= _FP_EXPBIAS_Q + TI_BITS - rsigned) + { + shift = A_e - (_FP_EXPBIAS_Q + TI_BITS - rsigned - 1); + A_e -= shift; + } + } + FP_TO_INT_Q (rv, A, rsize, rsigned); + FP_HANDLE_EXCEPTIONS; + FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI); +} +#endif --- libgcc/soft-fp/fixxfbitint.c.jj 2023-07-14 09:19:04.908549924 +0200 +++ libgcc/soft-fp/fixxfbitint.c 2023-07-14 10:10:22.936886921 +0200 @@ -0,0 +1,82 @@ +/* Software floating-point emulation. + Convert IEEE extended to signed or unsigned _BitInt. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "extended.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ + +#ifndef TI_BITS +/* While mantissa is 64 bits including 1 explicit bit, extended.h uses + op-2.h for W_TYPE_SIZE 64 and op-4.h for W_TYPE_SIZE 32, so we have + to use 128-bit type here. On most 32-bit architectures TImode isn't + supported, so use _BitInt(128) instead. */ +typedef _BitInt(128) TItype; +typedef unsigned _BitInt(128) UTItype; +#define TI_BITS 128 +#endif + +void +__fixxfbitint (UBILtype *r, SItype rprec, XFtype a) +{ + FP_DECL_EX; + FP_DECL_E (A); + USItype arprec = rprec < 0 ? -rprec : rprec; + USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; + UTItype rv; + USItype rsize = arprec > TI_BITS ? TI_BITS : arprec; + USItype rsigned = rprec < 0; + USItype ovf = 0; + USItype shift = 0; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_E (A, a); + if (arprec > TI_BITS) + { + if (A_e < _FP_EXPBIAS_E || (A_s && !rsigned)) + ovf = 1; + else if (A_e >= (_FP_EXPMAX_E < _FP_EXPBIAS_E + arprec + ? _FP_EXPMAX_E + : _FP_EXPBIAS_E + arprec - rsigned)) + { + ovf = 1; + if (A_s + && A_e == _FP_EXPBIAS_E + arprec - 1 + && A_e < _FP_EXPMAX_E) + A_e -= arprec - TI_BITS; + } + else if (A_e >= _FP_EXPBIAS_E + TI_BITS - rsigned) + { + shift = A_e - (_FP_EXPBIAS_E + TI_BITS - rsigned - 1); + A_e -= shift; + } + } + FP_TO_INT_E (rv, A, rsize, rsigned); + FP_HANDLE_EXCEPTIONS; + FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI); +} +#endif --- libgcc/soft-fp/floatbitintbf.c.jj 2023-07-14 23:42:07.422424792 +0200 +++ libgcc/soft-fp/floatbitintbf.c 2023-07-17 09:48:02.380392453 +0200 @@ -0,0 +1,59 @@ +/* Software floating-point emulation. + Convert a _BitInt to bfloat16. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "brain.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +BFtype +__floatbitintbf (const UBILtype *i, SItype iprec) +{ + SItype iv; + USItype shift = 0; + FP_DECL_EX; + FP_DECL_B (A); + BFtype a; + + FP_FROM_BITINT (i, iprec, iv, shift, SI); + FP_INIT_ROUNDMODE; + FP_FROM_INT_B (A, iv, SI_BITS, USItype); + if (shift) + { + A_e += shift; + if (A_e >= _FP_EXPMAX_B) + { + /* Exponent too big; overflow to infinity. */ + _FP_OVERFLOW_SEMIRAW (B, 1, A); + _FP_PACK_SEMIRAW (B, 1, A); + } + } + FP_PACK_RAW_B (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} +#endif --- libgcc/soft-fp/floatbitintdf.c.jj 2023-07-14 13:47:58.082710779 +0200 +++ libgcc/soft-fp/floatbitintdf.c 2023-07-17 09:48:02.380392453 +0200 @@ -0,0 +1,64 @@ +/* Software floating-point emulation. + Convert a _BitInt to IEEE double. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "double.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +DFtype +__floatbitintdf (const UBILtype *i, SItype iprec) +{ + DItype iv; + USItype shift = 0; + FP_DECL_EX; + FP_DECL_D (A); + DFtype a; + + FP_FROM_BITINT (i, iprec, iv, shift, DI); + FP_INIT_ROUNDMODE; + FP_FROM_INT_D (A, iv, DI_BITS, UDItype); + if (shift) + { + A_e += shift; + if (A_e >= _FP_EXPMAX_D) + { + /* Exponent too big; overflow to infinity. */ +#if _FP_W_TYPE_SIZE < 64 + _FP_OVERFLOW_SEMIRAW (D, 2, A); + _FP_PACK_SEMIRAW (D, 2, A); +#else + _FP_OVERFLOW_SEMIRAW (D, 1, A); + _FP_PACK_SEMIRAW (D, 1, A); +#endif + } + } + FP_PACK_RAW_D (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} +#endif --- libgcc/soft-fp/floatbitinthf.c.jj 2023-07-14 23:39:20.033670033 +0200 +++ libgcc/soft-fp/floatbitinthf.c 2023-07-17 09:48:02.380392453 +0200 @@ -0,0 +1,59 @@ +/* Software floating-point emulation. + Convert a _BitInt to IEEE half. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "half.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +HFtype +__floatbitinthf (const UBILtype *i, SItype iprec) +{ + SItype iv; + USItype shift = 0; + FP_DECL_EX; + FP_DECL_H (A); + HFtype a; + + FP_FROM_BITINT (i, iprec, iv, shift, SI); + FP_INIT_ROUNDMODE; + FP_FROM_INT_H (A, iv, SI_BITS, USItype); + if (shift) + { + A_e += shift; + if (A_e >= _FP_EXPMAX_H) + { + /* Exponent too big; overflow to infinity. */ + _FP_OVERFLOW_SEMIRAW (H, 1, A); + _FP_PACK_SEMIRAW (H, 1, A); + } + } + FP_PACK_RAW_H (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} +#endif --- libgcc/soft-fp/floatbitintsf.c.jj 2023-07-14 23:37:18.464300690 +0200 +++ libgcc/soft-fp/floatbitintsf.c 2023-07-17 09:48:02.380392453 +0200 @@ -0,0 +1,59 @@ +/* Software floating-point emulation. + Convert a _BitInt to IEEE single. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "single.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +SFtype +__floatbitintsf (const UBILtype *i, SItype iprec) +{ + SItype iv; + USItype shift = 0; + FP_DECL_EX; + FP_DECL_S (A); + SFtype a; + + FP_FROM_BITINT (i, iprec, iv, shift, SI); + FP_INIT_ROUNDMODE; + FP_FROM_INT_S (A, iv, SI_BITS, USItype); + if (shift) + { + A_e += shift; + if (A_e >= _FP_EXPMAX_S) + { + /* Exponent too big; overflow to infinity. */ + _FP_OVERFLOW_SEMIRAW (S, 1, A); + _FP_PACK_SEMIRAW (S, 1, A); + } + } + FP_PACK_RAW_S (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} +#endif --- libgcc/soft-fp/floatbitinttf.c.jj 2023-07-17 09:32:55.202714681 +0200 +++ libgcc/soft-fp/floatbitinttf.c 2023-07-17 09:49:00.734600781 +0200 @@ -0,0 +1,73 @@ +/* Software floating-point emulation. + Convert a _BitInt to IEEE quad. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "quad.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +#ifndef TI_BITS +/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit + type, but on most 32-bit architectures TImode isn't supported. + Use _BitInt(128) instead. */ +typedef _BitInt(128) TItype; +typedef unsigned _BitInt(128) UTItype; +#define TI_BITS 128 +#endif + +TFtype +__floatbitinttf (const UBILtype *i, SItype iprec) +{ + TItype iv; + USItype shift = 0; + FP_DECL_EX; + FP_DECL_Q (A); + TFtype a; + + FP_FROM_BITINT (i, iprec, iv, shift, TI); + FP_INIT_ROUNDMODE; + FP_FROM_INT_Q (A, iv, TI_BITS, UTItype); + if (shift) + { + A_e += shift; + if (A_e >= _FP_EXPMAX_Q) + { + /* Exponent too big; overflow to infinity. */ +#if _FP_W_TYPE_SIZE < 64 + _FP_OVERFLOW_SEMIRAW (Q, 4, A); + _FP_PACK_SEMIRAW (Q, 4, A); +#else + _FP_OVERFLOW_SEMIRAW (Q, 2, A); + _FP_PACK_SEMIRAW (Q, 2, A); +#endif + } + } + FP_PACK_RAW_Q (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} +#endif --- libgcc/soft-fp/floatbitintxf.c.jj 2023-07-17 09:28:59.311920588 +0200 +++ libgcc/soft-fp/floatbitintxf.c 2023-07-17 09:48:02.381392439 +0200 @@ -0,0 +1,74 @@ +/* Software floating-point emulation. + Convert a _BitInt to IEEE extended. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "soft-fp.h" +#include "extended.h" +#include "bitint.h" + +#ifdef __BITINT_MAXWIDTH__ +#ifndef TI_BITS +/* While mantissa is 64 bits including 1 explicit bit, extended.h uses + op-2.h for W_TYPE_SIZE 64 and op-4.h for W_TYPE_SIZE 32, so we have + to use 128-bit type here. On most 32-bit architectures TImode isn't + supported, so use _BitInt(128) instead. */ +typedef _BitInt(128) TItype; +typedef unsigned _BitInt(128) UTItype; +#define TI_BITS 128 +#endif + +XFtype +__floatbitintxf (const UBILtype *i, SItype iprec) +{ + TItype iv; + USItype shift = 0; + FP_DECL_EX; + FP_DECL_E (A); + XFtype a; + + FP_FROM_BITINT (i, iprec, iv, shift, TI); + FP_INIT_ROUNDMODE; + FP_FROM_INT_E (A, iv, TI_BITS, UTItype); + if (shift) + { + A_e += shift; + if (A_e >= _FP_EXPMAX_E) + { + /* Exponent too big; overflow to infinity. */ +#if _FP_W_TYPE_SIZE < 64 + _FP_OVERFLOW_SEMIRAW (E, 4, A); + _FP_PACK_SEMIRAW (E, 4, A); +#else + _FP_OVERFLOW_SEMIRAW (E, 2, A); + _FP_PACK_SEMIRAW (E, 2, A); +#endif + } + } + FP_PACK_RAW_E (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} +#endif --- libgcc/soft-fp/op-common.h.jj 2022-08-17 16:59:09.303543880 +0200 +++ libgcc/soft-fp/op-common.h 2023-07-17 12:02:29.369681164 +0200 @@ -1800,7 +1800,7 @@ if ((X##_s = ((r) < 0))) \ _FP_FROM_INT_ur = -_FP_FROM_INT_ur; \ \ - _FP_STATIC_ASSERT ((rsize) <= 2 * _FP_W_TYPE_SIZE, \ + _FP_STATIC_ASSERT ((rsize) <= 4 * _FP_W_TYPE_SIZE, \ "rsize too large"); \ (void) (((rsize) <= _FP_W_TYPE_SIZE) \ ? ({ \ @@ -1810,13 +1810,38 @@ X##_e = (_FP_EXPBIAS_##fs + _FP_W_TYPE_SIZE - 1 \ - _FP_FROM_INT_lz); \ }) \ - : ({ \ + : ((rsize) <= 2 * _FP_W_TYPE_SIZE) \ + ? ({ \ int _FP_FROM_INT_lz; \ __FP_CLZ_2 (_FP_FROM_INT_lz, \ (_FP_W_TYPE) (_FP_FROM_INT_ur \ >> _FP_W_TYPE_SIZE), \ (_FP_W_TYPE) _FP_FROM_INT_ur); \ - X##_e = (_FP_EXPBIAS_##fs + 2 * _FP_W_TYPE_SIZE - 1 \ + X##_e = (_FP_EXPBIAS_##fs \ + + 2 * _FP_W_TYPE_SIZE - 1 \ + - _FP_FROM_INT_lz); \ + }) \ + : ({ \ + int _FP_FROM_INT_lz; \ + if (_FP_FROM_INT_ur >> (2 * _FP_W_TYPE_SIZE)) \ + { \ + rtype _FP_FROM_INT_uru \ + = _FP_FROM_INT_ur >> (2 * _FP_W_TYPE_SIZE); \ + __FP_CLZ_2 (_FP_FROM_INT_lz, \ + (_FP_W_TYPE) (_FP_FROM_INT_uru \ + >> _FP_W_TYPE_SIZE),\ + (_FP_W_TYPE) _FP_FROM_INT_uru); \ + } \ + else \ + { \ + __FP_CLZ_2 (_FP_FROM_INT_lz, \ + (_FP_W_TYPE) (_FP_FROM_INT_ur \ + >> _FP_W_TYPE_SIZE),\ + (_FP_W_TYPE) _FP_FROM_INT_ur); \ + _FP_FROM_INT_lz += 2 * _FP_W_TYPE_SIZE; \ + } \ + X##_e = (_FP_EXPBIAS_##fs \ + + 4 * _FP_W_TYPE_SIZE - 1 \ - _FP_FROM_INT_lz); \ })); \ \ From patchwork Thu Jul 27 17:14:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 127072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1246419vqo; Thu, 27 Jul 2023 10:16:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFvaZ8+E3G7cNz7yXwWr8Erovn6x164tZyKRmvKioiXNGWIC87+HXOmawslrh9U1grDg/QV X-Received: by 2002:a05:6402:8d2:b0:522:59a7:5453 with SMTP id d18-20020a05640208d200b0052259a75453mr2241354edz.35.1690478200620; Thu, 27 Jul 2023 10:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690478200; cv=none; d=google.com; s=arc-20160816; b=LwXyVXD+9IB0U1e5AE3ZX7dDOm7EoH8eifiSWzuqJjTVREFY2tEXqOtRDHEvf1Q30a TeiBXa1M/+VbO+Btt4f3vmcHe9XM70mA07Y73bEu7mXHwppDhDRnsFwdzDID+hguWts8 Vle02i1yx1B8Iys/mwn3xjKRcSz3pM6j+WqZF6KDrC6qfCCUx+lZZgPYmD1K9aRZusW9 zZy7eBQqoaM9DJWWKt9lHAnDy/CKZl/YR4fii7evlKotKr9iW412KVHhY98pxag14gKe 6OEQeMXKSUi78275h3+SDk5L+EEfzZbPJNdEGKBfNAMmjVFpGs56cPXJ506s7chrbWqQ M8Cw== 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=OxwZrJfa0PZjoPvOCoSZq4UMy9OkUeTvls4jdNSYGj0=; fh=c4z+NT3Sw2ybe8UBBBOSbxS5q11ovsIBRU4o97L+YT0=; b=mHDONxVYeLE3jOc08+s94bXaavgD9AvVm5wFsHPhBUWNACmR2S+1jZET03EMqDY4/x M/mIec5Ux4c/T/wua9Wx9orj1xtydeTIawxWNwQfTBrJg408MnMqik6U+BdBb59gza05 vFMqdK1PrrUFnJbMpkFDa9VCi+0HrTJ5a8lqW0jRFwh333v+W9c+krziCY1cWhdSQjI5 5QkRjFaipiKWBig9cLZgJVbPUjaCJ3T2zRy0j5zj7eqqE+hOfk3kWW/NU7Bv7UZ6Viz3 Fybz0P+4N1241pKQxzvDkCmnU7sccz3N5yAKlw03AyLz+wxkV2JnwMyFG1OGNqk9WqBr JhRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GpJKB3KH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m8-20020a056402050800b00522394947c9si1256067edv.632.2023.07.27.10.16.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GpJKB3KH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 F10EA3854C61 for ; Thu, 27 Jul 2023 17:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F10EA3854C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690478159; bh=OxwZrJfa0PZjoPvOCoSZq4UMy9OkUeTvls4jdNSYGj0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GpJKB3KHx8I9R/bFBHFSdqDdNNR3Vc8HHG+QvLkjZzl+wYTrwEbHJOMXirQ1FI7Hh nWTmijrMv7Kp/Er9vi4Ek3cUtbzvQx1eDA2ofWl99iZzg9oC13NsP44T0AYS0BnOA/ iWMH3XlHjvEL6m0jhBJmSkB25bh4zT8NE8xzEWzQ= 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 924353855594 for ; Thu, 27 Jul 2023 17:14:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 924353855594 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-641-G0NxLe7oNNOGP4L-hnxAvg-1; Thu, 27 Jul 2023 13:14:28 -0400 X-MC-Unique: G0NxLe7oNNOGP4L-hnxAvg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A0A298065D2; Thu, 27 Jul 2023 17:14:27 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D17D4A9004; Thu, 27 Jul 2023 17:14:27 +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 36RHEOMe2823073 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 19:14:25 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 36RHEOGj2823072; Thu, 27 Jul 2023 19:14:24 +0200 Date: Thu, 27 Jul 2023 19:14:23 +0200 To: gcc-patches@gcc.gnu.org Cc: "Joseph S. Myers" Subject: [PATCH 3/5] C _BitInt support [PR102989] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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: 1772594869732852756 X-GMAIL-MSGID: 1772594869732852756 Hi! This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous two patches really do nothing without this, which enables all the support. 2023-07-27 Jakub Jelinek PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-ubsan.cc (ubsan_instrument_shift): Use UBSAN_PRINT_FORCE_INT for type0 type descriptor. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (composite_type, c_common_type, comptypes_internal): Handle BITINT_TYPE. (build_array_ref, build_unary_op, build_conditional_expr, convert_for_assignment, digest_init, build_binary_op): Likewise. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define. Jakub --- gcc/glimits.h.jj 2023-01-03 00:20:35.071086812 +0100 +++ gcc/glimits.h 2023-07-27 15:03:24.238234396 +0200 @@ -157,6 +157,11 @@ see the files COPYING3 and COPYING.RUNTI # undef BOOL_WIDTH # define BOOL_WIDTH 1 +# ifdef __BITINT_MAXWIDTH__ +# undef BITINT_MAXWIDTH +# define BITINT_MAXWIDTH __BITINT_MAXWIDTH__ +# endif + # define __STDC_VERSION_LIMITS_H__ 202311L #endif --- gcc/c-family/c-common.cc.jj 2023-07-24 17:48:26.436041278 +0200 +++ gcc/c-family/c-common.cc 2023-07-27 15:03:24.276233865 +0200 @@ -349,6 +349,7 @@ const struct c_common_resword c_common_r { "_Alignas", RID_ALIGNAS, D_CONLY }, { "_Alignof", RID_ALIGNOF, D_CONLY }, { "_Atomic", RID_ATOMIC, D_CONLY }, + { "_BitInt", RID_BITINT, D_CONLY }, { "_Bool", RID_BOOL, D_CONLY }, { "_Complex", RID_COMPLEX, 0 }, { "_Imaginary", RID_IMAGINARY, D_CONLY }, @@ -2728,6 +2729,9 @@ c_common_signed_or_unsigned_type (int un || TYPE_UNSIGNED (type) == unsignedp) return type; + if (TREE_CODE (type) == BITINT_TYPE) + return build_bitint_type (TYPE_PRECISION (type), unsignedp); + #define TYPE_OK(node) \ (TYPE_MODE (type) == TYPE_MODE (node) \ && TYPE_PRECISION (type) == TYPE_PRECISION (node)) @@ -6341,8 +6345,10 @@ check_builtin_function_arguments (locati code0 = TREE_CODE (TREE_TYPE (args[0])); code1 = TREE_CODE (TREE_TYPE (args[1])); if (!((code0 == REAL_TYPE && code1 == REAL_TYPE) - || (code0 == REAL_TYPE && code1 == INTEGER_TYPE) - || (code0 == INTEGER_TYPE && code1 == REAL_TYPE))) + || (code0 == REAL_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) + || ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && code1 == REAL_TYPE))) { error_at (loc, "non-floating-point arguments in call to " "function %qE", fndecl); @@ -8402,6 +8408,7 @@ keyword_begins_type_specifier (enum rid case RID_FRACT: case RID_ACCUM: case RID_BOOL: + case RID_BITINT: case RID_WCHAR: case RID_CHAR8: case RID_CHAR16: --- gcc/c-family/c-common.h.jj 2023-06-26 09:27:04.276367532 +0200 +++ gcc/c-family/c-common.h 2023-07-27 15:03:24.278233837 +0200 @@ -101,7 +101,7 @@ enum rid RID_ENUM, RID_STRUCT, RID_UNION, RID_IF, RID_ELSE, RID_WHILE, RID_DO, RID_FOR, RID_SWITCH, RID_CASE, RID_DEFAULT, RID_BREAK, RID_CONTINUE, RID_RETURN, RID_GOTO, - RID_SIZEOF, + RID_SIZEOF, RID_BITINT, /* C extensions */ RID_ASM, RID_TYPEOF, RID_TYPEOF_UNQUAL, RID_ALIGNOF, RID_ATTRIBUTE, --- gcc/c-family/c-cppbuiltin.cc.jj 2023-07-02 12:07:08.382165397 +0200 +++ gcc/c-family/c-cppbuiltin.cc 2023-07-27 15:03:24.278233837 +0200 @@ -1190,6 +1190,29 @@ c_cpp_builtins (cpp_reader *pfile) builtin_define_type_width ("__PTRDIFF_WIDTH__", ptrdiff_type_node, NULL_TREE); builtin_define_type_width ("__SIZE_WIDTH__", size_type_node, NULL_TREE); + if (!c_dialect_cxx ()) + { + struct bitint_info info; + /* For now, restrict __BITINT_MAXWIDTH__ to what can be represented in + wide_int and widest_int. */ + if (targetm.c.bitint_type_info (WIDE_INT_MAX_PRECISION - 1, &info)) + { + cpp_define_formatted (pfile, "__BITINT_MAXWIDTH__=%d", + (int) WIDE_INT_MAX_PRECISION - 1); + if (flag_building_libgcc) + { + scalar_int_mode limb_mode + = as_a (info.limb_mode); + cpp_define_formatted (pfile, "__LIBGCC_BITINT_LIMB_WIDTH__=%d", + (int) GET_MODE_PRECISION (limb_mode)); + cpp_define_formatted (pfile, "__LIBGCC_BITINT_ORDER__=%s", + info.big_endian + ? "__ORDER_BIG_ENDIAN__" + : "__ORDER_LITTLE_ENDIAN__"); + } + } + } + if (c_dialect_cxx ()) for (i = 0; i < NUM_INT_N_ENTS; i ++) if (int_n_enabled_p[i]) --- gcc/c-family/c-lex.cc.jj 2023-05-16 18:51:56.669064839 +0200 +++ gcc/c-family/c-lex.cc 2023-07-27 15:03:24.279233823 +0200 @@ -809,6 +809,170 @@ interpret_integer (const cpp_token *toke *overflow = OT_NONE; + if (UNLIKELY (flags & CPP_N_BITINT)) + { + unsigned int suffix_len = 2 + ((flags & CPP_N_UNSIGNED) ? 1 : 0); + int max_bits_per_digit = 4; // ceil (log2 (10)) + unsigned int prefix_len = 0; + bool hex = false; + const int bitint_maxwidth = WIDE_INT_MAX_PRECISION - 1; + if ((flags & CPP_N_RADIX) == CPP_N_OCTAL) + { + max_bits_per_digit = 3; + prefix_len = 1; + } + else if ((flags & CPP_N_RADIX) == CPP_N_HEX) + { + max_bits_per_digit = 4; + prefix_len = 2; + hex = true; + } + else if ((flags & CPP_N_RADIX) == CPP_N_BINARY) + { + max_bits_per_digit = 1; + prefix_len = 2; + } + int max_digits + = TYPE_PRECISION (intmax_type_node) >> max_bits_per_digit; + const int max_buf = 128; + if (max_digits > max_buf) + max_digits = max_buf; + + widest_int wval; + unsigned int prec; + gcc_checking_assert (token->val.str.len > prefix_len + suffix_len + || token->val.str.len == 1 + suffix_len); + if (token->val.str.len - (prefix_len + suffix_len) + <= (unsigned) max_digits) + { + integer = cpp_interpret_integer (parse_in, token, + (flags & CPP_N_RADIX) + | CPP_N_UNSIGNED); + ival[0] = integer.low; + ival[1] = integer.high; + ival[2] = 0; + wval = widest_int::from_array (ival, 3); + } + else + { + unsigned char buf[3 + max_buf]; + memcpy (buf, token->val.str.text, prefix_len); + wval = 0U; + const unsigned char *p = token->val.str.text + prefix_len; + cpp_token tok = *token; + tok.val.str.text = buf; + if (!prefix_len) + max_digits = 19; + do + { + unsigned char *q = buf + prefix_len; + do + { + unsigned char c = *p++; + if (ISDIGIT (c) || (hex && ISXDIGIT (c))) + { + *q++ = c; + if (q == buf + prefix_len + max_digits) + break; + } + else if (c != '\'') + { + --p; + break; + } + } + while (1); + if (q == buf + prefix_len) + break; + else + { + wi::overflow_type wioverflow; + *q = '\0'; + tok.val.str.len = q - buf; + if (wval == 0) + ; + else if (prefix_len) + { + prec = wi::min_precision (wval, UNSIGNED); + unsigned HOST_WIDE_INT shift + = (tok.val.str.len - prefix_len) * max_bits_per_digit; + if (prec + shift > bitint_maxwidth) + goto bitint_overflow; + wval = wi::lshift (wval, shift); + } + else + { + static unsigned HOST_WIDE_INT tens[] + = { 1U, 10U, 100U, 1000U, + HOST_WIDE_INT_UC (10000), + HOST_WIDE_INT_UC (100000), + HOST_WIDE_INT_UC (1000000), + HOST_WIDE_INT_UC (10000000), + HOST_WIDE_INT_UC (100000000), + HOST_WIDE_INT_UC (1000000000), + HOST_WIDE_INT_UC (10000000000), + HOST_WIDE_INT_UC (100000000000), + HOST_WIDE_INT_UC (1000000000000), + HOST_WIDE_INT_UC (10000000000000), + HOST_WIDE_INT_UC (100000000000000), + HOST_WIDE_INT_UC (1000000000000000), + HOST_WIDE_INT_UC (10000000000000000), + HOST_WIDE_INT_UC (100000000000000000), + HOST_WIDE_INT_UC (1000000000000000000), + HOST_WIDE_INT_UC (10000000000000000000) }; + widest_int ten = tens[q - buf]; + wval = wi::umul (wval, ten, &wioverflow); + if (wioverflow) + goto bitint_overflow; + } + integer = cpp_interpret_integer (parse_in, &tok, + (flags & CPP_N_RADIX) + | CPP_N_UNSIGNED); + ival[0] = integer.low; + ival[1] = integer.high; + ival[2] = 0; + if (prefix_len) + wval = wval + widest_int::from_array (ival, 3); + else + { + widest_int addend = widest_int::from_array (ival, 3); + wval = wi::add (wval, addend, UNSIGNED, &wioverflow); + if (wioverflow) + goto bitint_overflow; + } + } + } + while (1); + } + + prec = wi::min_precision (wval, UNSIGNED); + if (prec == 0) + prec = 1; + if ((flags & CPP_N_UNSIGNED) == 0) + ++prec; + if (prec > bitint_maxwidth) + { + bitint_overflow: + if ((flags & CPP_N_UNSIGNED) != 0) + error ("integer constant is too large for " + "% type", bitint_maxwidth); + else + error ("integer constant is too large for " + "%<_BitInt(%d)%> type", bitint_maxwidth); + return integer_zero_node; + } + + struct bitint_info info; + if (!targetm.c.bitint_type_info (prec, &info)) + { + sorry ("%<_BitInt(%d)%> is not supported on this target", prec); + return integer_zero_node; + } + + type = build_bitint_type (prec, (flags & CPP_N_UNSIGNED) != 0); + return wide_int_to_tree (type, wval); + } + integer = cpp_interpret_integer (parse_in, token, flags); if (integer.overflow) *overflow = OT_OVERFLOW; --- gcc/c-family/c-pretty-print.cc.jj 2023-01-16 23:19:05.561727075 +0100 +++ gcc/c-family/c-pretty-print.cc 2023-07-27 15:03:24.277233851 +0200 @@ -399,6 +399,23 @@ c_pretty_printer::simple_type_specifier } break; + case BITINT_TYPE: + if (TYPE_NAME (t)) + { + t = TYPE_NAME (t); + simple_type_specifier (t); + } + else + { + int prec = TYPE_PRECISION (t); + if (TYPE_UNSIGNED (t)) + pp_c_ws_string (this, "unsigned"); + pp_c_ws_string (this, "_BitInt(");; + pp_decimal_int (this, prec); + pp_right_paren (this); + } + break; + case TYPE_DECL: if (DECL_NAME (t)) id_expression (t); @@ -688,6 +705,7 @@ c_pretty_printer::direct_abstract_declar case REAL_TYPE: case FIXED_POINT_TYPE: case ENUMERAL_TYPE: + case BITINT_TYPE: case RECORD_TYPE: case UNION_TYPE: case VECTOR_TYPE: @@ -1019,8 +1037,18 @@ pp_c_integer_constant (c_pretty_printer pp_minus (pp); wi = -wi; } - print_hex (wi, pp_buffer (pp)->digit_buffer); - pp_string (pp, pp_buffer (pp)->digit_buffer); + unsigned int prec = wi.get_precision (); + if ((prec + 3) / 4 > sizeof (pp_buffer (pp)->digit_buffer) - 3) + { + char *buf = XALLOCAVEC (char, (prec + 3) / 4 + 3); + print_hex (wi, buf); + pp_string (pp, buf); + } + else + { + print_hex (wi, pp_buffer (pp)->digit_buffer); + pp_string (pp, pp_buffer (pp)->digit_buffer); + } } } --- gcc/c-family/c-ubsan.cc.jj 2023-05-20 15:31:09.071663282 +0200 +++ gcc/c-family/c-ubsan.cc 2023-07-27 15:03:24.279233823 +0200 @@ -256,8 +256,8 @@ ubsan_instrument_shift (location_t loc, tt = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0); else { - tree data = ubsan_create_data ("__ubsan_shift_data", 1, &loc, - ubsan_type_descriptor (type0), + tree utd0 = ubsan_type_descriptor (type0, UBSAN_PRINT_FORCE_INT); + tree data = ubsan_create_data ("__ubsan_shift_data", 1, &loc, utd0, ubsan_type_descriptor (type1), NULL_TREE, NULL_TREE); data = build_fold_addr_expr_loc (loc, data); --- gcc/c/c-convert.cc.jj 2023-05-20 15:31:09.073663254 +0200 +++ gcc/c/c-convert.cc 2023-07-27 15:03:24.272233921 +0200 @@ -117,6 +117,7 @@ c_convert (tree type, tree expr, bool in gcc_fallthrough (); case INTEGER_TYPE: + case BITINT_TYPE: if (sanitize_flags_p (SANITIZE_FLOAT_CAST) && current_function_decl != NULL_TREE && SCALAR_FLOAT_TYPE_P (TREE_TYPE (expr)) --- gcc/c/c-decl.cc.jj 2023-07-02 12:07:08.386165342 +0200 +++ gcc/c/c-decl.cc 2023-07-27 15:03:24.265234019 +0200 @@ -11538,14 +11538,18 @@ declspecs_add_type (location_t loc, stru ("both % and % in " "declaration specifiers")); else if (specs->typespec_word == cts_int_n) - error_at (loc, - ("both % and %<__int%d%> in " - "declaration specifiers"), - int_n_data[specs->int_n_idx].bitsize); + error_at (loc, + ("both % and %<__int%d%> in " + "declaration specifiers"), + int_n_data[specs->u.int_n_idx].bitsize); else if (specs->typespec_word == cts_bool) error_at (loc, ("both % and %<_Bool%> in " "declaration specifiers")); + else if (specs->typespec_word == cts_bitint) + error_at (loc, + ("both % and %<_BitInt%> in " + "declaration specifiers")); else if (specs->typespec_word == cts_char) error_at (loc, ("both % and % in " @@ -11558,8 +11562,8 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->typespec_word == cts_dfloat32) @@ -11598,11 +11602,15 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<__int%d%> in " "declaration specifiers"), - int_n_data[specs->int_n_idx].bitsize); + int_n_data[specs->u.int_n_idx].bitsize); else if (specs->typespec_word == cts_bool) error_at (loc, ("both % and %<_Bool%> in " "declaration specifiers")); + else if (specs->typespec_word == cts_bitint) + error_at (loc, + ("both % and %<_BitInt%> in " + "declaration specifiers")); else if (specs->typespec_word == cts_char) error_at (loc, ("both % and % in " @@ -11619,8 +11627,8 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->typespec_word == cts_dfloat32) @@ -11671,8 +11679,8 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->typespec_word == cts_dfloat32) @@ -11723,8 +11731,8 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->typespec_word == cts_dfloat32) @@ -11762,6 +11770,10 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<_Bool%> in " "declaration specifiers")); + else if (specs->typespec_word == cts_bitint) + error_at (loc, + ("both % and %<_BitInt%> in " + "declaration specifiers")); else if (specs->typespec_word == cts_dfloat32) error_at (loc, ("both % and %<_Decimal32%> in " @@ -11801,7 +11813,7 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both %<_Sat%> and %<__int%d%> in " "declaration specifiers"), - int_n_data[specs->int_n_idx].bitsize); + int_n_data[specs->u.int_n_idx].bitsize); } else if (specs->typespec_word == cts_auto_type) error_at (loc, @@ -11815,6 +11827,10 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both %<_Sat%> and %<_Bool%> in " "declaration specifiers")); + else if (specs->typespec_word == cts_bitint) + error_at (loc, + ("both %<_Sat%> and %<_BitInt%> in " + "declaration specifiers")); else if (specs->typespec_word == cts_char) error_at (loc, ("both %<_Sat%> and % in " @@ -11835,8 +11851,8 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both %<_Sat%> and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->typespec_word == cts_dfloat32) @@ -11874,7 +11890,7 @@ declspecs_add_type (location_t loc, stru { /* "void", "_Bool", "char", "int", "float", "double", "_FloatN", "_FloatNx", "_Decimal32", "__intN", - "_Decimal64", "_Decimal128", "_Fract", "_Accum" or + "_Decimal64", "_Decimal128", "_Fract", "_Accum", "_BitInt(N)" or "__auto_type". */ if (specs->typespec_word != cts_none) { @@ -11919,7 +11935,7 @@ declspecs_add_type (location_t loc, stru case RID_INT_N_1: case RID_INT_N_2: case RID_INT_N_3: - specs->int_n_idx = i - RID_INT_N_0; + specs->u.int_n_idx = i - RID_INT_N_0; if (!in_system_header_at (input_location) /* If the INT_N type ends in "__", and so is of the format "__intN__", don't pedwarn. */ @@ -11927,29 +11943,29 @@ declspecs_add_type (location_t loc, stru + (IDENTIFIER_LENGTH (type) - 2), "__", 2) != 0)) pedwarn (loc, OPT_Wpedantic, "ISO C does not support %<__int%d%> types", - int_n_data[specs->int_n_idx].bitsize); + int_n_data[specs->u.int_n_idx].bitsize); if (specs->long_p) error_at (loc, ("both %<__int%d%> and % in " "declaration specifiers"), - int_n_data[specs->int_n_idx].bitsize); + int_n_data[specs->u.int_n_idx].bitsize); else if (specs->saturating_p) error_at (loc, ("both %<_Sat%> and %<__int%d%> in " "declaration specifiers"), - int_n_data[specs->int_n_idx].bitsize); + int_n_data[specs->u.int_n_idx].bitsize); else if (specs->short_p) error_at (loc, ("both %<__int%d%> and % in " "declaration specifiers"), - int_n_data[specs->int_n_idx].bitsize); - else if (! int_n_enabled_p[specs->int_n_idx]) + int_n_data[specs->u.int_n_idx].bitsize); + else if (! int_n_enabled_p[specs->u.int_n_idx]) { specs->typespec_word = cts_int_n; error_at (loc, "%<__int%d%> is not supported on this target", - int_n_data[specs->int_n_idx].bitsize); + int_n_data[specs->u.int_n_idx].bitsize); } else { @@ -12107,12 +12123,12 @@ declspecs_add_type (location_t loc, stru } return specs; CASE_RID_FLOATN_NX: - specs->floatn_nx_idx = i - RID_FLOATN_NX_FIRST; + specs->u.floatn_nx_idx = i - RID_FLOATN_NX_FIRST; if (!in_system_header_at (input_location)) pedwarn (loc, OPT_Wpedantic, "ISO C does not support the %<_Float%d%s%> type", - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); @@ -12120,49 +12136,49 @@ declspecs_add_type (location_t loc, stru error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->short_p) error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->signed_p) error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->unsigned_p) error_at (loc, ("both % and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); else if (specs->saturating_p) error_at (loc, ("both %<_Sat%> and %<_Float%d%s%> in " "declaration specifiers"), - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); - else if (FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx) == NULL_TREE) + else if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE) { specs->typespec_word = cts_floatn_nx; error_at (loc, "%<_Float%d%s%> is not supported on this target", - floatn_nx_types[specs->floatn_nx_idx].n, - (floatn_nx_types[specs->floatn_nx_idx].extended + floatn_nx_types[specs->u.floatn_nx_idx].n, + (floatn_nx_types[specs->u.floatn_nx_idx].extended ? "x" : "")); } @@ -12259,6 +12275,63 @@ declspecs_add_type (location_t loc, stru pedwarn (loc, OPT_Wpedantic, "ISO C does not support fixed-point types"); return specs; + case RID_BITINT: + if (specs->long_p) + error_at (loc, + ("both % and %<_BitInt%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both % and %<_BitInt%> in " + "declaration specifiers")); + else if (specs->complex_p) + error_at (loc, + ("both % and %<_BitInt%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<_BitInt%> in " + "declaration specifiers")); + else + { + specs->typespec_word = cts_bitint; + specs->locations[cdw_typespec] = loc; + specs->u.bitint_prec = -1; + if (error_operand_p (spec.expr)) + return specs; + if (TREE_CODE (spec.expr) != INTEGER_CST + || !INTEGRAL_TYPE_P (TREE_TYPE (spec.expr))) + { + error_at (loc, "%<_BitInt%> argument is not an integer " + "constant expression"); + return specs; + } + if (tree_int_cst_sgn (spec.expr) <= 0) + { + error_at (loc, "%<_BitInt%> argument %qE is not " + "positive integer constant expression", + spec.expr); + return specs; + } + if (wi::to_widest (spec.expr) > WIDE_INT_MAX_PRECISION - 1) + { + error_at (loc, "%<_BitInt%> argument %qE is larger than " + "% %qd", + spec.expr, (int) WIDE_INT_MAX_PRECISION - 1); + return specs; + } + specs->u.bitint_prec = tree_to_uhwi (spec.expr); + struct bitint_info info; + if (!targetm.c.bitint_type_info (specs->u.bitint_prec, + &info)) + { + sorry_at (loc, "%<_BitInt(%d)%> is not supported on " + "this target", specs->u.bitint_prec); + specs->u.bitint_prec = -1; + return specs; + } + } + return specs; default: /* ObjC reserved word "id", handled below. */ break; @@ -12660,12 +12733,12 @@ finish_declspecs (struct c_declspecs *sp case cts_int_n: gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p); gcc_assert (!(specs->signed_p && specs->unsigned_p)); - if (! int_n_enabled_p[specs->int_n_idx]) + if (! int_n_enabled_p[specs->u.int_n_idx]) specs->type = integer_type_node; else specs->type = (specs->unsigned_p - ? int_n_trees[specs->int_n_idx].unsigned_type - : int_n_trees[specs->int_n_idx].signed_type); + ? int_n_trees[specs->u.int_n_idx].unsigned_type + : int_n_trees[specs->u.int_n_idx].signed_type); if (specs->complex_p) { pedwarn (specs->locations[cdw_complex], OPT_Wpedantic, @@ -12725,12 +12798,12 @@ finish_declspecs (struct c_declspecs *sp case cts_floatn_nx: gcc_assert (!specs->long_p && !specs->short_p && !specs->signed_p && !specs->unsigned_p); - if (FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx) == NULL_TREE) + if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE) specs->type = integer_type_node; else if (specs->complex_p) - specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx); + specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx); else - specs->type = FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx); + specs->type = FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx); break; case cts_dfloat32: case cts_dfloat64: @@ -12832,6 +12905,22 @@ finish_declspecs (struct c_declspecs *sp : accum_type_node; } break; + case cts_bitint: + gcc_assert (!specs->long_p && !specs->short_p + && !specs->complex_p); + if (!specs->unsigned_p && specs->u.bitint_prec == 1) + { + error_at (specs->locations[cdw_typespec], + "% argument must be at least 2"); + specs->type = integer_type_node; + break; + } + if (specs->u.bitint_prec == -1) + specs->type = integer_type_node; + else + specs->type = build_bitint_type (specs->u.bitint_prec, + specs->unsigned_p); + break; default: gcc_unreachable (); } --- gcc/c/c-parser.cc.jj 2023-06-16 12:01:15.001684150 +0200 +++ gcc/c/c-parser.cc 2023-07-27 15:03:24.272233921 +0200 @@ -580,6 +580,7 @@ c_keyword_starts_typename (enum rid keyw case RID_DFLOAT128: CASE_RID_FLOATN_NX: case RID_BOOL: + case RID_BITINT: case RID_ENUM: case RID_STRUCT: case RID_UNION: @@ -783,6 +784,7 @@ c_token_starts_declspecs (c_token *token case RID_DFLOAT128: CASE_RID_FLOATN_NX: case RID_BOOL: + case RID_BITINT: case RID_ENUM: case RID_STRUCT: case RID_UNION: @@ -3332,6 +3334,30 @@ c_parser_declspecs (c_parser *parser, st t = c_parser_typeof_specifier (parser); declspecs_add_type (loc, specs, t); break; + case RID_BITINT: + if (!typespec_ok) + goto out; + else + { + attrs_ok = true; + seen_type = true; + t.kind = ctsk_resword; + t.spec = c_parser_peek_token (parser)->value; + t.expr = error_mark_node; + t.expr_const_operands = true; + t.has_enum_type_specifier = false; + c_parser_consume_token (parser); + matching_parens parens; + if (parens.require_open (parser)) + { + c_expr expr = c_parser_expr_no_commas (parser, NULL); + t.expr = convert_lvalue_to_rvalue (loc, expr, true, + true).value; + parens.skip_until_found_close (parser); + } + declspecs_add_type (loc, specs, t); + } + break; case RID_ATOMIC: /* C parser handling of Objective-C constructs needs checking for correct lvalue-to-rvalue conversions, and @@ -4979,6 +5005,7 @@ c_parser_gnu_attribute_any_word (c_parse case RID_DFLOAT128: CASE_RID_FLOATN_NX: case RID_BOOL: + case RID_BITINT: case RID_FRACT: case RID_ACCUM: case RID_SAT: --- gcc/c/c-tree.h.jj 2023-05-30 17:52:34.410858192 +0200 +++ gcc/c/c-tree.h 2023-07-27 15:03:24.273233907 +0200 @@ -270,7 +270,7 @@ enum c_storage_class { /* A type specifier keyword "void", "_Bool", "char", "int", "float", "double", "_Decimal32", "_Decimal64", "_Decimal128", "_Fract", "_Accum", - or none of these. */ + "_BitInt", or none of these. */ enum c_typespec_keyword { cts_none, cts_void, @@ -286,6 +286,7 @@ enum c_typespec_keyword { cts_floatn_nx, cts_fract, cts_accum, + cts_bitint, cts_auto_type }; @@ -366,11 +367,16 @@ struct c_declspecs { specifier, in bytes, or -1 if no such specifiers with nonzero alignment. */ int align_log; - /* For the __intN declspec, this stores the index into the int_n_* arrays. */ - int int_n_idx; - /* For the _FloatN and _FloatNx declspec, this stores the index into - the floatn_nx_types array. */ - int floatn_nx_idx; + union { + /* For the __intN declspec, this stores the index into the int_n_* + arrays. */ + int int_n_idx; + /* For the _FloatN and _FloatNx declspec, this stores the index into + the floatn_nx_types array. */ + int floatn_nx_idx; + /* For _BitInt(N) this stores the N. */ + int bitint_prec; + } u; /* The storage class specifier, or csc_none if none. */ enum c_storage_class storage_class; /* Any type specifier keyword used such as "int", not reflecting --- gcc/c/c-typeck.cc.jj 2023-07-02 12:07:08.388165315 +0200 +++ gcc/c/c-typeck.cc 2023-07-27 15:03:24.268233977 +0200 @@ -413,10 +413,14 @@ composite_type (tree t1, tree t2) the composite type. */ if (code1 == ENUMERAL_TYPE - && (code2 == INTEGER_TYPE || code2 == BOOLEAN_TYPE)) + && (code2 == INTEGER_TYPE + || code2 == BOOLEAN_TYPE + || code2 == BITINT_TYPE)) return t1; if (code2 == ENUMERAL_TYPE - && (code1 == INTEGER_TYPE || code1 == BOOLEAN_TYPE)) + && (code1 == INTEGER_TYPE + || code1 == BOOLEAN_TYPE + || code1 == BITINT_TYPE)) return t2; gcc_assert (code1 == code2); @@ -764,10 +768,10 @@ c_common_type (tree t1, tree t2) gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE - || code1 == INTEGER_TYPE); + || code1 == INTEGER_TYPE || code1 == BITINT_TYPE); gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE - || code2 == INTEGER_TYPE); + || code2 == INTEGER_TYPE || code2 == BITINT_TYPE); /* When one operand is a decimal float type, the other operand cannot be a generic float type or a complex type. We also disallow vector types @@ -1004,6 +1008,20 @@ c_common_type (tree t1, tree t2) if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i)) return FLOATNX_TYPE_NODE (i); + if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2) + { + /* Prefer any other integral types over bit-precise integer types. */ + if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2)) + return code1 == BITINT_TYPE ? t2 : t1; + /* If BITINT_TYPE is unsigned and the other type is signed + non-BITINT_TYPE with the same precision, the latter has higher rank. + In that case: + Otherwise, both operands are converted to the unsigned integer type + corresponding to the type of the operand with signed integer type. */ + if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2)) + return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1); + } + /* Otherwise prefer the unsigned one. */ if (TYPE_UNSIGNED (t1)) @@ -1177,6 +1195,7 @@ comptypes_internal (const_tree type1, co case INTEGER_TYPE: case FIXED_POINT_TYPE: case REAL_TYPE: + case BITINT_TYPE: /* With these nodes, we can't determine type equivalence by looking at what is stored in the nodes themselves, because two nodes might have different TYPE_MAIN_VARIANTs but still @@ -2790,7 +2809,8 @@ build_array_ref (location_t loc, tree ar if (index == error_mark_node) return error_mark_node; - gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE); + gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE + || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE); bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array)); bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index); @@ -4558,6 +4578,7 @@ build_unary_op (location_t location, enu associativity, but won't generate any code. */ if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE + || typecode == BITINT_TYPE || gnu_vector_type_p (TREE_TYPE (arg)))) { error_at (location, "wrong type argument to unary plus"); @@ -4571,6 +4592,7 @@ build_unary_op (location_t location, enu case NEGATE_EXPR: if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE + || typecode == BITINT_TYPE || gnu_vector_type_p (TREE_TYPE (arg)))) { error_at (location, "wrong type argument to unary minus"); @@ -4583,6 +4605,7 @@ build_unary_op (location_t location, enu case BIT_NOT_EXPR: /* ~ works on integer types and non float vectors. */ if (typecode == INTEGER_TYPE + || typecode == BITINT_TYPE || (gnu_vector_type_p (TREE_TYPE (arg)) && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg)))) { @@ -4657,7 +4680,8 @@ build_unary_op (location_t location, enu case TRUTH_NOT_EXPR: if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE && typecode != REAL_TYPE && typecode != POINTER_TYPE - && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE) + && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE + && typecode != BITINT_TYPE) { error_at (location, "wrong type argument to unary exclamation mark"); @@ -4769,7 +4793,7 @@ build_unary_op (location_t location, enu if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE && typecode != INTEGER_TYPE && typecode != REAL_TYPE - && typecode != COMPLEX_TYPE + && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE && !gnu_vector_type_p (TREE_TYPE (arg))) { if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) @@ -5394,9 +5418,9 @@ build_conditional_expr (location_t colon result_type = TYPE_MAIN_VARIANT (type1); } else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE - || code1 == COMPLEX_TYPE) + || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE) && (code2 == INTEGER_TYPE || code2 == REAL_TYPE - || code2 == COMPLEX_TYPE)) + || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE)) { /* In C11, a conditional expression between a floating-point type and an integer type should convert the integer type to @@ -5583,7 +5607,8 @@ build_conditional_expr (location_t colon (build_qualified_type (void_type_node, qual)); } } - else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) + else if (code1 == POINTER_TYPE + && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op2)) pedwarn (colon_loc, 0, @@ -5594,7 +5619,8 @@ build_conditional_expr (location_t colon } result_type = type1; } - else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE) + else if (code2 == POINTER_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op1)) pedwarn (colon_loc, 0, @@ -7131,11 +7157,11 @@ convert_for_assignment (location_t locat else if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == FIXED_POINT_TYPE || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE - || codel == BOOLEAN_TYPE) + || codel == BOOLEAN_TYPE || codel == BITINT_TYPE) && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == FIXED_POINT_TYPE || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE - || coder == BOOLEAN_TYPE)) + || coder == BOOLEAN_TYPE || coder == BITINT_TYPE)) { if (warnopt && errtype == ic_argpass) maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type, @@ -8562,7 +8588,8 @@ digest_init (location_t init_loc, tree t if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE - || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE) + || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE + || code == BITINT_TYPE) { tree unconverted_init = inside_init; if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE @@ -12357,12 +12384,14 @@ build_binary_op (location_t location, en { case PLUS_EXPR: /* Handle the pointer + int case. */ - if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + if (code0 == POINTER_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { ret = pointer_int_sum (location, PLUS_EXPR, op0, op1); goto return_build_binary_op; } - else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE) + else if (code1 == POINTER_TYPE + && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE)) { ret = pointer_int_sum (location, PLUS_EXPR, op1, op0); goto return_build_binary_op; @@ -12381,7 +12410,8 @@ build_binary_op (location_t location, en goto return_build_binary_op; } /* Handle pointer minus int. Just like pointer plus int. */ - else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + else if (code0 == POINTER_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { ret = pointer_int_sum (location, MINUS_EXPR, op0, op1); goto return_build_binary_op; @@ -12403,11 +12433,11 @@ build_binary_op (location_t location, en warn_for_div_by_zero (location, op1); if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE - || code0 == FIXED_POINT_TYPE + || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE || code0 == COMPLEX_TYPE || gnu_vector_type_p (type0)) && (code1 == INTEGER_TYPE || code1 == REAL_TYPE - || code1 == FIXED_POINT_TYPE + || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE || code1 == COMPLEX_TYPE || gnu_vector_type_p (type1))) { @@ -12418,8 +12448,9 @@ build_binary_op (location_t location, en if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE) tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1))); - if (!((tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE) - || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE))) + if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE) + && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE)) + || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE))) resultcode = RDIV_EXPR; else /* Although it would be tempting to shorten always here, that @@ -12435,7 +12466,8 @@ build_binary_op (location_t location, en case BIT_AND_EXPR: case BIT_IOR_EXPR: case BIT_XOR_EXPR: - if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) shorten = -1; /* Allow vector types which are not floating point types. */ else if (gnu_vector_type_p (type0) @@ -12455,7 +12487,8 @@ build_binary_op (location_t location, en && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE) common = 1; - else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { /* Although it would be tempting to shorten always here, that loses on some targets, since the modulo instruction is undefined if the @@ -12473,10 +12506,12 @@ build_binary_op (location_t location, en case TRUTH_XOR_EXPR: if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE - || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE) + || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE + || code0 == BITINT_TYPE) && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE - || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE)) + || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE + || code1 == BITINT_TYPE)) { /* Result of these operations is always an int, but that does not mean the operands should be @@ -12539,9 +12574,10 @@ build_binary_op (location_t location, en converted = 1; } else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE + || code0 == BITINT_TYPE || (gnu_vector_type_p (type0) && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)) - && code1 == INTEGER_TYPE) + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { doing_shift = true; if (TREE_CODE (op1) == INTEGER_CST) @@ -12599,9 +12635,10 @@ build_binary_op (location_t location, en converted = 1; } else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE + || code0 == BITINT_TYPE || (gnu_vector_type_p (type0) && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)) - && code1 == INTEGER_TYPE) + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { doing_shift = true; if (TREE_CODE (op0) == INTEGER_CST @@ -12715,9 +12752,10 @@ build_binary_op (location_t location, en /* Result of comparison is always int, but don't convert the args to int! */ build_type = integer_type_node; - if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE) && (code1 == INTEGER_TYPE || code1 == REAL_TYPE + || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE)) short_compare = 1; else if (code0 == POINTER_TYPE @@ -12778,12 +12816,14 @@ build_binary_op (location_t location, en (build_qualified_type (void_type_node, qual)); } } - else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + else if (code0 == POINTER_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { result_type = type0; pedwarn (location, 0, "comparison between pointer and integer"); } - else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) + else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && code1 == POINTER_TYPE) { result_type = type1; pedwarn (location, 0, "comparison between pointer and integer"); @@ -12871,9 +12911,9 @@ build_binary_op (location_t location, en } build_type = integer_type_node; if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE - || code0 == FIXED_POINT_TYPE) + || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE) && (code1 == INTEGER_TYPE || code1 == REAL_TYPE - || code1 == FIXED_POINT_TYPE)) + || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE)) short_compare = 1; else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) { @@ -12932,12 +12972,14 @@ build_binary_op (location_t location, en warning_at (location, OPT_Wextra, "ordered comparison of pointer with integer zero"); } - else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + else if (code0 == POINTER_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { result_type = type0; pedwarn (location, 0, "comparison between pointer and integer"); } - else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) + else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && code1 == POINTER_TYPE) { result_type = type1; pedwarn (location, 0, "comparison between pointer and integer"); @@ -12991,12 +13033,11 @@ build_binary_op (location_t location, en } if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE - || code0 == FIXED_POINT_TYPE + || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE || gnu_vector_type_p (type0)) - && - (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE - || code1 == FIXED_POINT_TYPE - || gnu_vector_type_p (type1))) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE + || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE + || gnu_vector_type_p (type1))) { bool first_complex = (code0 == COMPLEX_TYPE); bool second_complex = (code1 == COMPLEX_TYPE); --- libcpp/expr.cc.jj 2023-07-11 13:39:49.680108934 +0200 +++ libcpp/expr.cc 2023-07-11 15:28:55.224672554 +0200 @@ -327,9 +327,9 @@ static unsigned int interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len) { size_t orig_len = len; - size_t u, l, i, z; + size_t u, l, i, z, wb; - u = l = i = z = 0; + u = l = i = z = wb = 0; while (len--) switch (s[len]) @@ -343,11 +343,23 @@ interpret_int_suffix (cpp_reader *pfile, if (l == 2 && s[len] != s[len + 1]) return 0; break; + case 'b': + if (len == 0 || s[len - 1] != 'w') + return 0; + wb++; + len--; + break; + case 'B': + if (len == 0 || s[len - 1] != 'W') + return 0; + wb++; + len--; + break; default: return 0; } - if (l > 2 || u > 1 || i > 1 || z > 1) + if (l > 2 || u > 1 || i > 1 || z > 1 || wb > 1) return 0; if (z) @@ -358,6 +370,14 @@ interpret_int_suffix (cpp_reader *pfile, return 0; } + if (wb) + { + if (CPP_OPTION (pfile, cplusplus)) + return 0; + if (l > 0 || i > 0 || z > 0) + return 0; + } + if (i) { if (!CPP_OPTION (pfile, ext_numeric_literals)) @@ -376,7 +396,8 @@ interpret_int_suffix (cpp_reader *pfile, | (u ? CPP_N_UNSIGNED : 0) | ((l == 0) ? CPP_N_SMALL : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE) - | (z ? CPP_N_SIZE_T : 0)); + | (z ? CPP_N_SIZE_T : 0) + | (wb ? CPP_N_BITINT : 0)); } /* Return the classification flags for an int suffix. */ --- libcpp/include/cpplib.h.jj 2023-07-11 13:40:40.400429973 +0200 +++ libcpp/include/cpplib.h 2023-07-11 15:28:55.225672540 +0200 @@ -1284,6 +1284,7 @@ struct cpp_num #define CPP_N_SIZE_T 0x2000000 /* C++23 size_t literal. */ #define CPP_N_BFLOAT16 0x4000000 /* std::bfloat16_t type. */ +#define CPP_N_BITINT 0x8000000 /* C2X _BitInt literal. */ #define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value of N, divided by 16. */ From patchwork Thu Jul 27 17:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 127074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1247655vqo; Thu, 27 Jul 2023 10:18:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlHKPzP799frfs6dlCcw7P+wXErKSVhbyIQolq3vhOH8ByirXayQoWx/9LFeaoh9wPpZc9Tq X-Received: by 2002:a05:6512:32d2:b0:4fb:89b3:3373 with SMTP id f18-20020a05651232d200b004fb89b33373mr2360825lfg.43.1690478321265; Thu, 27 Jul 2023 10:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690478321; cv=none; d=google.com; s=arc-20160816; b=cVC+OayGz65m1xSnr9lDFyZ4guEJb8jms8ccMczxw2w6bdJYRKVLIxeNusdaSz9F2I 3vFgKPvbcdmANwxJuVlKnXY2uD5OGJJJ+gKd3COHQWfP1h6VYbsgG3piuwd+DYlfvNxG G8ZLFFsJpPVZ/exeLse6NvVPEliqJjaS0rcFecQnnafbtfZeqI7OA+CJ7LvfO65W0Tz1 L/ES0gPl9QxoqAYFnkabwRdi0LBPtAEIB6mAduS+kELUdhdTsmZ4Q668c7S8Xwh8eDG7 O6fE6c/QPmgnSeNVx+pGeZsO/ZooevOHY2tCslR088rSQqT5of1gyhgbpLGwzuLlYAJf v5Mw== 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=HMrAapoN4gY5m4lXeqmC7u/uUU2pLViEfSHzE2R7sLY=; fh=WsnZmklt8G06AL40EcEdnVgOM8uIHnTd15u+ffpb1ek=; b=ywl1t1QyA/TPA3EPYsGbBHEtbX5YjM7zVJ0tcqo9fU/9FP22AydrlEAdLm8qo+J82I AcxA1Qu9HA963U/SRXSwbV/vrIZBgD3Vday85wHW1Byqh0Jje42JcKiUFPgc4lYjVZ5d oR3CbZs67VGXEG+RamHLqhDBNX+bWwYExhwepDPEXzPOvlWnQfEQeqkjuzO3EsO1jtR7 A+iOUttRG3qRwSQtxu9RxTCEDCIkg9D902ssHsjrgdSbHC3w+cO+F3QUN7rlrrg0vEp2 Zm0Cs9Ahw4S0RJp+1oN2eISje0CK3j6Gu1cjknFpbDWqZxawTcgmYO+K5CNtOuNuiEW3 POVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KfdYcas2; 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 v26-20020aa7d65a000000b0052196e1378csi1173370edr.17.2023.07.27.10.18.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:18:41 -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=KfdYcas2; 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 B65413854C6F for ; Thu, 27 Jul 2023 17:17:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B65413854C6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690478258; bh=HMrAapoN4gY5m4lXeqmC7u/uUU2pLViEfSHzE2R7sLY=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KfdYcas2JMilopK+r8pFtvjfztjuT35wJoA8wOuHORLjZcOEXI3ElomaSOWi7hcfI cSRvKgXvc6h0jC8Km2Z2qFe60oOysp9u5ZkatrinxXwYjSXyDt4SBM5asw8FkdHKtB 6uEeptDSCqmg0XP7rb+MXbNy9g2zb9Rhp5im17vA= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id B2B703854C60 for ; Thu, 27 Jul 2023 17:15:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2B703854C60 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-py0OkUSDPi6ksnz748hV3g-1; Thu, 27 Jul 2023 13:15:34 -0400 X-MC-Unique: py0OkUSDPi6ksnz748hV3g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9AAF43803513; Thu, 27 Jul 2023 17:15:33 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9F0CC57965; Thu, 27 Jul 2023 17:15:32 +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 36RHFUR52823087 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 19:15:30 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 36RHFTrH2823085; Thu, 27 Jul 2023 19:15:29 +0200 Date: Thu, 27 Jul 2023 19:15:28 +0200 To: gcc-patches@gcc.gnu.org Cc: Richard Biener , "Joseph S. Myers" Subject: [PATCH 4/5] testsuite part 1 for _BitInt support [PR102989] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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, KAM_LOTSOFHASH, PDS_BTC_ID, PDS_BTC_MSGID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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: 1772594996187660660 X-GMAIL-MSGID: 1772594996187660660 Hi! This patch adds first part of the testsuite support. When creating the testcases, I've been using https://defuse.ca/big-number-calculator.htm tool, a randombitint tool I wrote (will post as a reply to this) plus LLVM trunk on godbolt and the WIP GCC support checking if both compilers agree on stuff (and in case of differences tried constant evaluation etc.). The whole testsuite has been also tested with make -j32 -k check-gcc GCC_TEST_RUN_EXPENSIVE=1 \ RUNTESTFLAGS='GCC_TEST_RUN_EXPENSIVE=1 --target_board=unix\{-m32,-m64\} ubsan.exp=bitint*.c dg.exp=bitint* dg-torture.exp=bitint*' to verify it in all modes, normally I'm limitting the torture tests to just -O0 and -O2 because they are quite large and expensive. Generally it is needed to test different _BitInt precisions because they are lowered differently (the small vs. medium vs. large vs. huge, precision of multiples of limb precision or some other etc.). 2023-07-27 Jakub Jelinek PR c/102989 gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bitint, check_effective_target_bitint128, check_effective_target_bitint575): New effective targets. * gcc.dg/bitint-1.c: New test. * gcc.dg/bitint-2.c: New test. * gcc.dg/bitint-3.c: New test. * gcc.dg/bitint-4.c: New test. * gcc.dg/bitint-5.c: New test. * gcc.dg/bitint-6.c: New test. * gcc.dg/bitint-7.c: New test. * gcc.dg/bitint-8.c: New test. * gcc.dg/bitint-9.c: New test. * gcc.dg/bitint-10.c: New test. * gcc.dg/bitint-11.c: New test. * gcc.dg/bitint-12.c: New test. * gcc.dg/bitint-13.c: New test. * gcc.dg/bitint-14.c: New test. * gcc.dg/bitint-15.c: New test. * gcc.dg/torture/bitint-1.c: New test. * gcc.dg/torture/bitint-2.c: New test. * gcc.dg/torture/bitint-3.c: New test. * gcc.dg/torture/bitint-4.c: New test. * gcc.dg/torture/bitint-5.c: New test. * gcc.dg/torture/bitint-6.c: New test. * gcc.dg/torture/bitint-7.c: New test. * gcc.dg/torture/bitint-8.c: New test. * gcc.dg/torture/bitint-9.c: New test. * gcc.dg/torture/bitint-10.c: New test. * gcc.dg/torture/bitint-11.c: New test. * gcc.dg/torture/bitint-12.c: New test. * gcc.dg/torture/bitint-13.c: New test. * gcc.dg/torture/bitint-14.c: New test. * gcc.dg/torture/bitint-15.c: New test. * gcc.dg/torture/bitint-16.c: New test. * gcc.dg/torture/bitint-17.c: New test. * gcc.dg/torture/bitint-18.c: New test. * gcc.dg/torture/bitint-19.c: New test. Jakub --- gcc/testsuite/lib/target-supports.exp.jj 2023-07-24 17:48:26.528040081 +0200 +++ gcc/testsuite/lib/target-supports.exp 2023-07-27 15:03:24.244234312 +0200 @@ -3581,6 +3581,33 @@ proc check_effective_target_fixed_point }] } +# Return 1 if the target supports _BitInt(N), 0 otherwise. + +proc check_effective_target_bitint { } { + return [check_no_compiler_messages bitint object { + _BitInt (2) a = 1wb; + unsigned _BitInt (__BITINT_MAXWIDTH__) b = 0uwb; + } "-std=c2x"] +} + +# Return 1 if the target supports _BitInt(128), 0 otherwise. + +proc check_effective_target_bitint128 { } { + return [check_no_compiler_messages bitint128 object { + _BitInt (2) a = 1wb; + unsigned _BitInt (128) b = 0uwb; + } "-std=c2x"] +} + +# Return 1 if the target supports _BitInt(575), 0 otherwise. + +proc check_effective_target_bitint575 { } { + return [check_no_compiler_messages bitint575 object { + _BitInt (2) a = 1wb; + unsigned _BitInt (575) b = 0uwb; + } "-std=c2x"] +} + # Return 1 if the target supports compiling decimal floating point, # 0 otherwise. --- gcc/testsuite/gcc.dg/bitint-1.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-1.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,26 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c2x" } */ + +void +foo (int x) +{ + _BitInt (1) a; /* { dg-error "'signed _BitInt' argument must be at least 2" } */ + signed _BitInt (1) b; /* { dg-error "'signed _BitInt' argument must be at least 2" } */ + _BitInt (0) c; /* { dg-error "'_BitInt' argument '0' is not positive integer constant expression" } */ + unsigned _BitInt (0) d; /* { dg-error "'_BitInt' argument '0' is not positive integer constant expression" } */ + _BitInt (-42) e; /* { dg-error "'_BitInt' argument '-42' is not positive integer constant expression" } */ + _BitInt (-5) unsigned f; /* { dg-error "'_BitInt' argument '-5' is not positive integer constant expression" } */ + _BitInt (4294967295ULL) g; /* { dg-error "'_BitInt' argument '4294967295' is larger than 'BITINT_MAXWIDTH' '\[0-9]+'" } */ + long _BitInt (42) h; /* { dg-error "both 'long' and '_BitInt' in declaration specifiers" } */ + long long _BitInt (42) i; /* { dg-error "both 'long' and '_BitInt' in declaration specifiers" } */ + _BitInt (42) long j; /* { dg-error "both 'long' and '_BitInt' in declaration specifiers" } */ + _BitInt (42) long long k; /* { dg-error "both 'long' and '_BitInt' in declaration specifiers" } */ + short _BitInt (42) l; /* { dg-error "both 'short' and '_BitInt' in declaration specifiers" } */ + _BitInt (42) short m; /* { dg-error "both 'short' and '_BitInt' in declaration specifiers" } */ + _Complex _BitInt (42) n; /* { dg-error "both 'complex' and '_BitInt' in declaration specifiers" } */ + _BitInt (42) _Complex o; /* { dg-error "both 'complex' and '_BitInt' in declaration specifiers" } */ + int _BitInt (42) p; /* { dg-error "two or more data types in declaration specifiers" } */ + _BitInt (42) int q; /* { dg-error "two or more data types in declaration specifiers" } */ + _BitInt (x) r; /* { dg-error "'_BitInt' argument is not an integer constant expression" } */ +} --- gcc/testsuite/gcc.dg/bitint-2.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-2.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,116 @@ +/* PR c/102989 */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#define expr_has_type(e, t) _Generic (e, default : 0, t : 1) + +#ifdef __BITINT_MAXWIDTH__ +void +foo (void) +{ + _BitInt(42) a = (_BitInt(42)) 1; + _BitInt(42) unsigned b = (unsigned _BitInt(42)) 2; + _BitInt(5) c = (_BitInt(5)) 3; + _BitInt(5) unsigned d = (unsigned _BitInt(5)) 4; + _BitInt(32) e = (_BitInt(32)) 5; + _BitInt(32) unsigned f = (unsigned _BitInt(32)) 6; + static_assert (expr_has_type (a, signed _BitInt(42)), ""); + static_assert (expr_has_type (a, _BitInt(42)), ""); + static_assert (!expr_has_type (a, unsigned _BitInt(42)), ""); + static_assert (!expr_has_type (b, signed _BitInt(42)), ""); + static_assert (!expr_has_type (b, _BitInt(42)), ""); + static_assert (expr_has_type (b, unsigned _BitInt(42)), ""); + static_assert (expr_has_type (a + b, unsigned _BitInt(42)), ""); + static_assert (expr_has_type (a * b, unsigned _BitInt(42)), ""); + static_assert (expr_has_type (a - b, unsigned _BitInt(42)), ""); + static_assert (expr_has_type (a * a, _BitInt(42)), ""); + static_assert (expr_has_type (a / b, unsigned _BitInt(42)), ""); + static_assert (expr_has_type (c, signed _BitInt(5)), ""); + static_assert (expr_has_type (c, _BitInt(5)), ""); + static_assert (!expr_has_type (c, unsigned _BitInt(5)), ""); + static_assert (!expr_has_type (d, signed _BitInt(5)), ""); + static_assert (!expr_has_type (d, _BitInt(5)), ""); + static_assert (expr_has_type (d, unsigned _BitInt(5)), ""); + static_assert (expr_has_type (c + d, unsigned _BitInt(5)), ""); + static_assert (expr_has_type (c * d, unsigned _BitInt(5)), ""); + static_assert (expr_has_type (c - d, unsigned _BitInt(5)), ""); + static_assert (expr_has_type (c * c, _BitInt(5)), ""); + static_assert (expr_has_type (c / d, unsigned _BitInt(5)), ""); + static_assert (expr_has_type (e, signed _BitInt(32)), ""); + static_assert (expr_has_type (e, _BitInt(32)), ""); + static_assert (!expr_has_type (e, unsigned _BitInt(32)), ""); + static_assert (!expr_has_type (f, signed _BitInt(32)), ""); + static_assert (!expr_has_type (f, _BitInt(32)), ""); + static_assert (expr_has_type (f, unsigned _BitInt(32)), ""); + static_assert (expr_has_type (e + f, unsigned _BitInt(32)), ""); + static_assert (expr_has_type (e * f, unsigned _BitInt(32)), ""); + static_assert (expr_has_type (e - f, unsigned _BitInt(32)), ""); + static_assert (expr_has_type (e * e, _BitInt(32)), ""); + static_assert (expr_has_type (e / f, unsigned _BitInt(32)), ""); +#if __CHAR_BIT__ * __SIZEOF_INT__ == 32 + static_assert (expr_has_type (e + 1, int), ""); + static_assert (expr_has_type (f + 1, unsigned int), ""); + static_assert (expr_has_type (e + 1U, unsigned int), ""); + static_assert (expr_has_type (f + 1U, unsigned int), ""); + static_assert (expr_has_type (1 - e, int), ""); + static_assert (expr_has_type (1 - f, unsigned int), ""); + static_assert (expr_has_type (1U * e, unsigned int), ""); + static_assert (expr_has_type (1U / f, unsigned int), ""); +#endif + static_assert (expr_has_type (0wb, _BitInt(2)), ""); + static_assert (expr_has_type (-1WB, _BitInt(2)), ""); + static_assert (expr_has_type (-1wb - 1wb, _BitInt(2)), ""); + static_assert (expr_has_type (1wb, _BitInt(2)), ""); + static_assert (expr_has_type (2wb, _BitInt(3)), ""); + static_assert (expr_has_type (0wbu, unsigned _BitInt(1)), ""); + static_assert (expr_has_type (-1UWB, unsigned _BitInt(1)), ""); + static_assert (expr_has_type (1uWB, unsigned _BitInt(1)), ""); + static_assert (expr_has_type (2Uwb, unsigned _BitInt(2)), ""); + static_assert (0wb == 0, ""); + static_assert (-1wb == -1, ""); + static_assert (0xffffffffwb == 4294967295wb, ""); + static_assert (0xffffffffwb == 000000000000000000000000000037777777777wb, ""); + static_assert (0x0000000000000000000000000ffffffffwb == 0b00011111111111111111111111111111111wb, ""); +#if __BITINT_MAXWIDTH__ >= 128 + static_assert (expr_has_type (0xffffffffffffffffffffffffffffffffuwb, unsigned _BitInt(128)), ""); + static_assert (0xffffffffffffffffffffffffffffffffuwb == 340282366920938463463374607431768211455uwb, ""); + static_assert (200000000000000000000000000000000000000wb == 0x96769950b50d88f41314448000000000WB, ""); + static_assert (02263551452055206610750114242110000000000000wb == 200000000000000000000000000000000000000wb, ""); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static_assert (expr_has_type (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567UWB, unsigned _BitInt(575)), ""); + static_assert (expr_has_type (0x00000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwbu, unsigned _BitInt(575)), ""); + static_assert (expr_has_type (0377777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777uwb, unsigned _BitInt(575)), ""); + static_assert (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb == 0x00000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwbu, ""); + static_assert (0377777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777WBU == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffuWB, ""); + static_assert (100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000uwb == 0X67815961'0903F797'4A7CB3F2'2F01FA5D'9A2CD603'9DE4A7A6'0F713676'CE7D7113'FF1A499D'9BFD0FDC'D2999652'EB4C7F39'8DE2A000'00000000'00000000'00000000'00000000'00000000UWB, ""); + static_assert (expr_has_type (-61'832600368'276133515'125630254'911797508'782837275'302959978'515764023'224306276'632966792'579100265'310761247'399417856'504034834'837841258'576687802'491886538'775473291'979151693'037174783wb, _BitInt(575)), ""); + static_assert (expr_has_type (0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, signed _BitInt(575)), ""); + static_assert (expr_has_type (0177777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777wb, _BitInt(575)), ""); + static_assert (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783WB == -0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, ""); + static_assert (0177777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777wb / 2wb * 2wb + 1wb == 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, ""); +#endif +#if (0wb != 0) || (0wbU != 0U) || (1wb != 1) || (1uWB != 1u) \ + || (-1wb >= 0) || (-1UWB < 0) || (4294967295uwb != 4294967295U) \ + || 18446744073709551615wbu != 18446744073709551615ULL +#error "" +#endif +} + +void +bar (void) +{ + _BitInt(2) a = (_BitInt(2)) 1; + unsigned _BitInt(1) b = 1uwb; + _BitInt(4) c; + c = 7; + _BitInt(2) d = 1; + _BitInt(5) e = 2wb; + unsigned _BitInt(6) f = 3uwb; +} +#endif + +int +main () +{ +} --- gcc/testsuite/gcc.dg/bitint-3.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-3.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,40 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +_BitInt(32) a, b = 2147483647wb; +_BitInt(64) c, d = 9223372036854775807wb; +struct S { + _BitInt(2) a; + _BitInt(6) b; +} s, t = { -1wb - 1wb, 31wb }; + +void +foo (void) +{ + a = b; + c = d; + s.a = t.a; + s.b = t.b; +} + +void +bar (void) +{ + a += b; + c += d; + s.a += t.a; + s.b += t.b; +} + +#if __BITINT_MAXWIDTH__ >= 128 +unsigned _BitInt(128) e = 340282366920938463463374607431768211455uwb; +_BitInt(128) f = 20000000000000000000000000000000000000wb; +_BitInt(128) g = -20000000000000000000000000000000000000wb; +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +unsigned _BitInt(575) h = 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb; +_BitInt(575) i = 2000000000000000000000000000000000000000000wb; +_BitInt(575) j = -2000000000000000000000000000000000000000000wb; +#endif --- gcc/testsuite/gcc.dg/bitint-4.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-4.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,39 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +_BitInt(2) +foo (_BitInt(2) x, _BitInt(15) y) +{ + return x + y; +} + +_BitInt(64) +bar (_BitInt(64) x, _BitInt(64) y) +{ + return x + y; +} + +#if __BITINT_MAXWIDTH__ >= 128 +_BitInt(128) a, b, c; + +_BitInt(128) +baz (_BitInt(128) x, _BitInt(128) y) +{ + a = x; + b = y; + return c; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +_BitInt(575) d, e, f; + +_BitInt(575) +qux (_BitInt(575) x, _BitInt(575) y) +{ + d = x; + e = y; + return f; +} +#endif --- gcc/testsuite/gcc.dg/bitint-5.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/bitint-5.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,63 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#include +#include + +#if __BITINT_MAXWIDTH__ >= 128 +unsigned _BitInt(128) b, c; +#endif +#if __BITINT_MAXWIDTH__ >= 575 +signed _BitInt(575) d, e; +#endif + +void +foo (int a, ...) +{ + va_list ap; + va_start (ap, a); + if (a == 1) + { + if (va_arg (ap, _BitInt(2)) != 1wb) + abort (); + if (va_arg (ap, _BitInt(3)) != 3wb) + abort (); + if (va_arg (ap, _BitInt(15)) != 16383wb) + abort (); + if (va_arg (ap, unsigned _BitInt(32)) != 4294967295uwb) + abort (); + if (va_arg (ap, _BitInt(64)) != 0x7fffffffffffffffwb) + abort (); + } +#if __BITINT_MAXWIDTH__ >= 128 + b = va_arg (ap, unsigned _BitInt(128)); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + d = va_arg (ap, _BitInt(575)); +#endif + if (va_arg (ap, int) != 42) + abort (); + va_end (ap); +} + +void +bar (void) +{ + foo (1, 1wb, 3wb, 16383wb, 4294967295uwb, 9223372036854775807wb, +#if __BITINT_MAXWIDTH__ >= 128 + c, +#endif +#if __BITINT_MAXWIDTH__ >= 575 + e, +#endif + 42); + foo (2, +#if __BITINT_MAXWIDTH__ >= 128 + c, +#endif +#if __BITINT_MAXWIDTH__ >= 575 + e, +#endif + 42); +} --- gcc/testsuite/gcc.dg/bitint-6.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/bitint-6.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,15 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +int *q, *r, *s; + +void +foo (int *p) +{ + p[4wb] = 0; + 6wb[p] = 0; + q = p + 8wb; + r = 10uwb + q; + s = r - 2wb; +} --- gcc/testsuite/gcc.dg/bitint-7.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/bitint-7.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,16 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#if __BITINT_MAXWIDTH__ >= 257 +void +foo (_BitInt(135) *p, _BitInt(193) *q, _BitInt(257) *r) +{ + r[0] = (((p[0] + p[1] + p[2]) + q[0] + (p[3] + p[4] + p[5])) + q[1]) + r[1] + (((p[6] + p[7] + p[8]) + q[2] + (p[9] + p[10] + p[11])) + q[3]) + r[2]; +} +#else +void +foo (void) +{ +} +#endif --- gcc/testsuite/gcc.dg/bitint-8.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/bitint-8.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,34 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c2x -Wno-uninitialized" } */ + +#if __BITINT_MAXWIDTH__ >= 135 +_BitInt(135) +foo (void) +{ + _BitInt(135) d; + _BitInt(135) e = d + 2wb; + return e; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +_BitInt(575) +bar (void) +{ + _BitInt(575) d; + _BitInt(575) e = d * 42wb; + return e; +} + +_BitInt(575) +baz (int x) +{ + _BitInt(575) d; + if (x) + return 59843758943759843574wb; + return d; +} +#endif + +int x; --- gcc/testsuite/gcc.dg/bitint-9.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/bitint-9.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,52 @@ +/* PR c/102989 */ +/* { dg-do compile { target { bitint && exceptions } } } */ +/* { dg-options "-O2 -std=gnu2x -fnon-call-exceptions -fexceptions" } */ + +__attribute__((noipa)) void +baz (int *p) +{ +} + +#if __BITINT_MAXWIDTH__ >= 575 +void +foo (volatile _BitInt(575) *p, _BitInt(575) q) +{ + int a __attribute__((cleanup (baz))) = 1; + *p = q; +} + +_BitInt(575) +bar (volatile _BitInt(575) *p) +{ + int a __attribute__((cleanup (baz))) = 1; + return *p; +} + +_BitInt(575) +qux (long double l) +{ + int a __attribute__((cleanup (baz))) = 1; + return l; +} + +long double +corge (_BitInt(575) b) +{ + int a __attribute__((cleanup (baz))) = 1; + return b; +} + +_BitInt(575) +garply (_BitInt(575) x, _BitInt(575) y) +{ + int a __attribute__((cleanup (baz))) = 1; + return x / y; +} + +_BitInt(575) +waldo (_BitInt(575) x, _BitInt(575) y) +{ + int a __attribute__((cleanup (baz))) = 1; + return x % y; +} +#endif --- gcc/testsuite/gcc.dg/bitint-10.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/bitint-10.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,15 @@ +/* PR c/102989 */ +/* { dg-do compile { target { bitint && dfp } } } */ +/* { dg-options "-O2 -std=c2x -pedantic-errors" } */ + +#if __BITINT_MAXWIDTH__ >= 129 +void +foo (_BitInt(129) *x, _Decimal64 *y) +{ + x[0] = y[0]; + y[1] = x[1]; +} +#endif + +/* _Decimal* <-> _BitInt conversions are unsupported for now. */ +/* { dg-prune-output "unsupported conversion between" } */ --- gcc/testsuite/gcc.dg/bitint-11.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-11.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,9 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c2x -pedantic-errors" } */ + +int +foo (_BitInt(127) x, _BitInt(127) y) +{ + return x < y; +} --- gcc/testsuite/gcc.dg/bitint-12.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-12.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,31 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=gnu2x -w" } */ + +_BitInt(37) +foo (_BitInt(37) x, _BitInt(37) y) +{ + _BitInt(37) w; + __asm ("# %0 %1 %2 %3" : "=r" (w) : "r" (x), "r" (x + y), "g" (68719476735wb)); + return w; +} + +#if __BITINT_MAXWIDTH__ >= 125 +_BitInt(125) +bar (_BitInt(125) x, _BitInt(125) y) +{ + _BitInt(125) w; + __asm ("# %0 %1 %2 %3" : "=g" (w) : "g" (x), "g" (x + y), "g" (21267647932558653966460912964485513215wb)); + return w; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +_BitInt(575) +baz (_BitInt(575) x, _BitInt(575) y) +{ + _BitInt(575) w; + __asm ("# %0 %1 %2 %3" : "=g" (w) : "g" (x), "g" (x + y), "g" (61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb)); + return w; +} +#endif --- gcc/testsuite/gcc.dg/bitint-13.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/bitint-13.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,17 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c2x -pedantic-errors" } */ + +#if __BITINT_MAXWIDTH__ >= 315 +_Bool +foo (_BitInt (315) a, _BitInt (315) b, unsigned *c) +{ + if (a < -8 || a > 7) + __builtin_unreachable (); + if (b < 0 || b > 63) + __builtin_unreachable (); + return __builtin_add_overflow (a, b, c); +} +#else +int i; +#endif --- gcc/testsuite/gcc.dg/bitint-14.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/bitint-14.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,11 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +enum A : _BitInt(15) { A0 = 0, A1 = 1 }; /* { dg-error "invalid 'enum' underlying type" } */ +enum B : unsigned _BitInt(575) { B0 = 0, B1 = 1 }; /* { dg-error "invalid 'enum' underlying type" } */ +enum C { C0 = 459875743wb, C1 = 3298437354uwb }; +enum D { D0 = 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, D1 }; +/* { dg-error "enumerator value outside the range of 'intmax_t'" "" { target *-*-* } .-1 } */ +/* { dg-error "overflow in enumeration values" "" { target *-*-* } .-2 } */ +/* { dg-error "enumeration values exceed range of largest integer" "" { target *-*-* } .-3 } */ --- gcc/testsuite/gcc.dg/bitint-15.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/bitint-15.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,10 @@ +/* PR c/102989 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=gnu2x" } */ + +enum A : _BitInt(15) { A0 = 0, A1 = 1 }; /* { dg-error "invalid 'enum' underlying type" } */ +enum B : unsigned _BitInt(575) { B0 = 0, B1 = 1 }; /* { dg-error "invalid 'enum' underlying type" } */ +enum C { C0 = 459875743wb, C1 = 3298437354uwb }; +enum D { D0 = 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, D1 }; +/* { dg-error "overflow in enumeration values" "" { target *-*-* } .-1 } */ +/* { dg-warning "enumeration values exceed range of largest integer" "" { target *-*-* } .-2 } */ --- gcc/testsuite/gcc.dg/torture/bitint-1.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-1.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,114 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +__attribute__((noipa)) void +foo (_BitInt(6) a, _BitInt(27) b, _BitInt(6) *p, _BitInt(27) *q, float c) +{ + p[0] = b; + q[0] = a; + q[1] = (unsigned _BitInt(6)) a; + q[2] = (unsigned _BitInt(9)) a; + q[3] = c; + q[4] += a; + q[5] = a + b; + q[6] = a - b; + q[7] = a * b; + q[8] = a / b; + q[9] = a % b; + q[10] = b << (-20wb - a); + q[11] = (b * 131wb) >> (-20wb - a); + q[12]++; + ++q[13]; + q[14]--; + --q[15]; + q[16] = a == b; + q[17] = a != b; + q[18] = a > b; + q[19] = a < b; + q[20] = a >= b; + q[21] = a <= b; + q[22] = a && b; + q[23] = a || b; + q[24] = !a; + q[25] = a & b; + q[26] = a | b; + q[27] = a ^ b; + q[28] = ~a; + q[29] -= a; + q[30] *= b; + q[31] /= b; + q[32] %= a; + q[33] <<= b; + q[34] >>= b; + q[35] &= a; + q[36] |= b; + q[37] ^= a; + q[38] = sizeof (a); + q[39] = q[39] ? a : b; + q[40] = 12345wb; + switch (a) + { + case 31wb: + if (b != 8wb) + __builtin_abort (); + break; + case -18wb: + if (b != 9wb) + __builtin_abort (); + break; + case 26wb: + if (b != 12wb) + __builtin_abort (); + break; + case -25wb: + if (b != 6wb) + __builtin_abort (); + break; + case -19wb: + if (b != 15wb) + __builtin_abort (); + break; + default: + __builtin_abort (); + } +} + +int +main () +{ + _BitInt(6) p; + _BitInt(27) q[41]; + static _BitInt(27) qe[41] = { + -25wb, 39wb, 487wb, 17wb, -7wb, -19wb, -31wb, -150wb, -4wb, -1, + 192wb, 24wb, 8wb, 10wb, 10wb, 12wb, 0, 1wb, 0wb, 1, + 0, 1, 1, 1wbu, 0, 6wb, -25wb, -31wb, 24wb, 32wb, + -6wb, -2wb, 2uwb, 320wb, 192wb, 7wb, 30wb, -30wb, 1, -25wb, + 12345wb + }; + q[4] = 18wb; + q[12] = 7wb; + q[13] = 9wb; + q[14] = 11wb; + q[15] = 13wb; + q[29] = 7wb; + q[30] = -1wb; + q[31] = -13wb; + q[32] = 52wb; + q[33] = 5wb; + q[34] = 12345wb; + q[35] = 15wb; + q[36] = 28wb; + q[37] = 5wb; + q[39] = 2wb; + foo (-25wb, 6wb, &p, q, 17.0f); + if (p != 6wb) + __builtin_abort (); + q[38] -= sizeof (p) - 1; + for (int i = 0; i < 41; ++i) + if (q[i] != qe[i]) + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-2.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-2.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,118 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +__attribute__((noipa)) void +foo (unsigned _BitInt(25) a, unsigned _BitInt(27) b, unsigned _BitInt(25) *p, unsigned _BitInt(27) *q, float c) +{ + p[0] = b; + q[0] = a; + q[1] = (signed _BitInt(25)) a; + q[2] = (_BitInt(12)) a; + q[3] = c; + q[4] += a; + q[5] = a + b; + q[6] = a - b; + q[7] = a * b; + q[8] = a / b; + q[9] = a % b; + q[10] = b << (24320393uwb - a); + q[11] = (b * 131uwb) >> (24320393uwb - a); + q[12]++; + ++q[13]; + q[14]--; + --q[15]; + q[16] = a == b; + q[17] = a != b; + q[18] = a > b; + q[19] = a < b; + q[20] = a >= b; + q[21] = a <= b; + q[22] = a && b; + q[23] = a || b; + q[24] = !a; + q[25] = a & b; + q[26] = a | b; + q[27] = a ^ b; + q[28] = ~a; + q[29] -= a; + q[30] *= b; + q[31] /= b; + q[32] %= a; + q[33] <<= (125900uwb - b); + q[34] >>= (125901uwb - b); + q[35] &= a; + q[36] |= b; + q[37] ^= a; + q[38] = sizeof (a); + q[39] = q[39] ? a : b; + q[40] = 24196214uwb; + switch (a) + { + case 12345641uwb: + if (b != 1244wb) + __builtin_abort (); + break; + case 11821400uwb: + if (b != 133445uwb) + __builtin_abort (); + break; + case 12145uwb: + if (b != 1212uwb) + __builtin_abort (); + break; + case 24320389uwb: + if (b != 125897uwb) + __builtin_abort (); + break; + case 7128412uwb: + if (b != 150uwb) + __builtin_abort (); + break; + default: + __builtin_abort (); + } +} + +int +main () +{ + unsigned _BitInt(25) p; + unsigned _BitInt(27) q[41]; + static unsigned _BitInt(27) qe[41] = { + 24320389uwb, 124983685uwb, 134216069uwb, 42uwb, 24320407uwb, + 24446286uwb, 24194492uwb, 89202797uwb, 193uwb, 22268uwb, + 2014352uwb, 1030781uwb, 8uwb, 10uwb, 10uwb, + 12uwb, 0uwb, 1uwb, 1uwb, 0uwb, + 1uwb, 0uwb, 1uwb, 1uwb, 0uwb, + 67969uwb, 24378317uwb, 24310348uwb, 9234042uwb, 109897346uwb, + 125897uwb, 0uwb, 52uwb, 40uwb, 771uwb, + 5uwb, 125917uwb, 24320384uwb, 1uwb, 24320389uwb, + 24196214uwb + }; + q[4] = 18uwb; + q[12] = 7uwb; + q[13] = 9uwb; + q[14] = 11uwb; + q[15] = 13uwb; + q[29] = 7uwb; + q[30] = -1uwb; + q[31] = -13uwb; + q[32] = 52uwb; + q[33] = 5uwb; + q[34] = 12345uwb; + q[35] = 15uwb; + q[36] = 28uwb; + q[37] = 5uwb; + q[39] = 2uwb; + foo (24320389uwb, 125897uwb, &p, q, 42.0f); + if (p != 125897uwb) + __builtin_abort (); + q[38] -= sizeof (p) - 1; + for (int i = 0; i < 41; ++i) + if (q[i] != qe[i]) + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-3.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-3.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,134 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 128 +__attribute__((noipa)) void +foo (_BitInt(125) a, _BitInt(128) b, _BitInt(125) *p, _BitInt(128) *q, float c) +{ + p[0] = b; + q[0] = a; + q[1] = (unsigned _BitInt(125)) a; + q[2] = (unsigned _BitInt(68)) a; + q[3] = c; + q[4] += a; + q[5] = a + b; + q[6] = a - b; + q[7] = a * b; + q[8] = a / b; + q[9] = a % b; + q[10] = b << (-80694244678005661015504159217709wb - a); + q[11] = a >> (-80694244678005661015504159217709wb - a); + q[12]++; + ++q[13]; + q[14]--; + --q[15]; + q[16] = a == b; + q[17] = a != b; + q[18] = a > b; + q[19] = a < b; + q[20] = a >= b; + q[21] = a <= b; + q[22] = a && b; + q[23] = a || b; + q[24] = !a; + q[25] = a & b; + q[26] = a | b; + q[27] = a ^ b; + q[28] = ~a; + q[29] -= a; + q[30] *= b; + q[31] /= b; + q[32] %= a; + q[33] <<= (b - 468021wb); + q[34] >>= (b - 468021wb); + q[35] &= a; + q[36] |= b; + q[37] ^= a; + q[38] = sizeof (a); + q[39] = q[39] ? a : b; + q[40] = 80694244678005661015504159217732wb; + switch (a) + { + case 313298472398574896574578475487548wb: + if (b != 813298738947385454wb) + __builtin_abort (); + break; + case -18198347584784758927893783748374wb: + if (b != 9439847384738wb) + __builtin_abort (); + break; + case 261243875485748189278344574857484wb: + if (b != 12549857489574wb) + __builtin_abort (); + break; + case -80694244678005661015504159217733wb: + if (b != 468071wb) + __builtin_abort (); + break; + case -193984372895748547584754854wb: + if (b != 15549857489574wb) + __builtin_abort (); + break; + default: + __builtin_abort (); + } +} + +int +main () +{ + _BitInt(125) p; + _BitInt(128) q[41]; + static _BitInt(128) qe[41] = { + -80694244678005661015504159217733wb, 42535215170872629927260810424811808699wb, + 211591633426360068027wb, -42wb, + -80694244678005661015504143312912wb, -80694244678005661015504158749662wb, + -80694244678005661015504159685804wb, -37770635800678787757188047309203503043wb, + -172397445426026523786998466wb, -238647wb, + 7852928270336wb, -4809751789450982869595538wb, + 821095840985901334959wb, 13895798174897154898wb, + 1465897921835729857453wb, 154987847598437549873142wb, + 0, 1, 0, 1, 0, 1, 1, 1, 0, + 271395wb, -80694244678005661015504159021057wb, + -80694244678005661015504159292452wb, 80694244678005661015504159217732wb, + 80694244678240648474427914115297wb, -5822736520666880936123wb, + 9818355413803wb, 54398547589478975845wb, + 39390147499089156967386811811758080wb, 30486wb, + 5910462358441918751905wb, 1342984375894755194479wb, + -80694244535621434450947930710749wb, 1, -80694244678005661015504159217733wb, + 80694244678005661015504159217732wb + }; + q[4] = 15904821wb; + q[12] = 821095840985901334958wb; + q[13] = 13895798174897154897wb; + q[14] = 1465897921835729857454wb; + q[15] = 154987847598437549873143wb; + q[29] = 234987458923754897564wb; + q[30] = -12439857458947213wb; + q[31] = 4595687436894573685wb; + q[32] = 54398547589478975845wb; + q[33] = 34985478957495847545wb; + q[34] = 34324329847328473343wb; + q[35] = 5984758947589437584545wb; + q[36] = 1342984375894754857545wb; + q[37] = 159847589475894768597656wb; + q[39] = 394857584wb; + foo (-80694244678005661015504159217733wb, 468071wb, &p, q, -42.0f); + if (p != 468071wb) + __builtin_abort (); + q[38] -= sizeof (p) - 1; + for (int i = 0; i < 41; ++i) + if (q[i] != qe[i]) + __builtin_abort (); + return 0; +} +#else +int +main () +{ + return 0; +} +#endif --- gcc/testsuite/gcc.dg/torture/bitint-4.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-4.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,134 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 128 +__attribute__((noipa)) void +foo (unsigned _BitInt(125) a, unsigned _BitInt(127) b, unsigned _BitInt(125) *p, unsigned _BitInt(127) *q, float c) +{ + p[0] = b; + q[0] = a; + q[1] = (signed _BitInt(125)) a; + q[2] = (_BitInt(73)) a; + q[3] = c; + q[4] += a; + q[5] = a + b; + q[6] = a - b; + q[7] = a * b; + q[8] = a / b; + q[9] = a % b; + q[10] = b << (26105549790521884176764218952781428833uwb - a); + q[11] = (a * 131uwb) >> (26105549790521884176764218952781428833uwb - a); + q[12]++; + ++q[13]; + q[14]--; + --q[15]; + q[16] = a == b; + q[17] = a != b; + q[18] = a > b; + q[19] = a < b; + q[20] = a >= b; + q[21] = a <= b; + q[22] = a && b; + q[23] = a || b; + q[24] = !a; + q[25] = a & b; + q[26] = a | b; + q[27] = a ^ b; + q[28] = ~a; + q[29] -= a; + q[30] *= b; + q[31] /= b; + q[32] %= a; + q[33] <<= (12589712345465422uwb - b); + q[34] >>= (12589712345465417uwb - b); + q[35] &= a; + q[36] |= b; + q[37] ^= a; + q[38] = sizeof (a); + q[39] = q[39] ? a : b; + q[40] = 26105549790654675897348954738956342847uwb; + switch (a) + { + case 26105549790521884176764218952781428772uwb: + if (b != 1244154958745894754wb) + __builtin_abort (); + break; + case 11821400154985748973289734545487uwb: + if (b != 133445145984759847584574uwb) + __builtin_abort (); + break; + case 12145uwb: + if (b != 12121243985745894732uwb) + __builtin_abort (); + break; + case 26105549790521884176764218952781428771uwb: + if (b != 12589712345465342uwb) + __builtin_abort (); + break; + case 71284121548547895457123873874452345uwb: + if (b != 150123439857459847uwb) + __builtin_abort (); + break; + default: + __builtin_abort (); + } +} + +int +main () +{ + unsigned _BitInt(125) p; + unsigned _BitInt(127) q[41]; + static unsigned _BitInt(127) qe[41] = { + 26105549790521884176764218952781428771uwb, 153711437385873807975529696739694508067uwb, + 2816339038065666848803uwb, 97uwb, + 26105549790521884178598517527767103757uwb, 26105549790521884176776808665126894113uwb, + 26105549790521884176751629240435963429uwb, 49552990805035300718174502183957321146uwb, + 2073562054015060870989uwb, 8076837748665533uwb, + 58059800399605194176279512422023168uwb, 3687014528101034113uwb, + 7439587439856743895438uwb, 95435435436uwb, + 112349587439856746858975446545uwb, 13145398574895748967847348972322uwb, + 0, 1, 1, 0, 1, 0, 1, 1, 0, + 3439290896351266uwb, 26105549790521884176773369374230542847uwb, + 26105549790521884176769930083334191581uwb, 16429746074595423756157606976189597660uwb, + 144035633670022787123399980532060335632uwb, 63332113050644322882197117954233460326uwb, + 27442uwb, 3245984754897548957498574895745uwb, + 14236875428959659760604435112230125568uwb, 326775104184uwb, + 1170981383577634uwb, 2843243404090270511102uwb, + 26313477358277918295486482038303331024uwb, 1, 26105549790521884176764218952781428771uwb, + 26105549790654675897348954738956342847uwb + }; + q[4] = 1834298574985674986uwb; + q[12] = 7439587439856743895437uwb; + q[13] = 95435435435uwb; + q[14] = 112349587439856746858975446546uwb; + q[15] = 13145398574895748967847348972323uwb; + q[29] = 75439568476895768957658675uwb; + q[30] = 455984375894754983574895745485uwb; + q[31] = 345495847589475847548uwb; + q[32] = 3245984754897548957498574895745uwb; + q[33] = 32594875648957489754854664897464uwb; + q[34] = 12345214395483754897548574857485748uwb; + q[35] = 1523143544545454uwb; + q[36] = 2843243245456456576876uwb; + q[37] = 542359486759867589675986576895765235uwb; + q[39] = 5498657685976587653uwb; + foo (26105549790521884176764218952781428771UWB, 12589712345465342uwb, &p, q, 97.0f); + if (p != 12589712345465342uwb) + __builtin_abort (); + q[38] -= sizeof (p) - 1; + for (int i = 0; i < 41; ++i) + if (q[i] != qe[i]) + __builtin_abort (); + return 0; +} +#else +int +main () +{ + return 0; +} +#endif --- gcc/testsuite/gcc.dg/torture/bitint-5.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-5.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,359 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +struct S135 { unsigned _BitInt(135) c, d; } s135[2]; +unsigned _BitInt(135) v135; + +__attribute__((noipa)) void +test135 (unsigned _BitInt(135) a, unsigned _BitInt(135) *b, int i, int *j) +{ + s135[0].c = a + (b[0] - b[i + 1]) + (b[2] << 7) - (b[3] + 42); + s135[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s135[1 - i].d == 0; + j[1] = b[7] == 41066216447087484049564603714591595841626uwb; + if (b[8] != (b[9] << 25)) + b[10] = -1; + v135 = b[11] + 42953568208323086417402824216666875252142uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check135 (void) +{ + static unsigned _BitInt(135) b[] = { + 8463654185126215364154304684888703364649uwb, + 13658636853650784933344312223424772115066uwb, + 18390507727765446703890200284988625150777uwb, + 39889350586873865111357164950780819590308uwb, + 33022475220127125972541408550886872946157uwb, + 11333291582071369827887273502665555805026uwb, + 3902203683482045798302423557190uwb, + 41066216447087484049564603714591595841626uwb, + 16784965627356370497109555127280042979599uwb, + 7643716056186238617582842123439581326016uwb, + 19836147734043931654921333860970539101678uwb, + 12432610573803574406235637996243202359232uwb, + 21082105046139319624321070809125021432333uwb, + 4451745762839330307043673589610uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(135) a + = 31187320352518101815881924683645645881322uwb; + s135[1].d = 11834999377838661704814127001992153922683uwb; + test135 (a, b, 0, &j[0]); + if (s135[0].c != 31612399059450309097747051855757230322507uwb + || s135[0].d != 42086989921663500164906031508060611173292uwb + || j[0] != 0 + || j[1] != 1 + || v135 != 11830035816246537500326512461643746545006uwb + || b[10] != (unsigned _BitInt(135)) -1wb + || b[12] != 43556142961428377560472619444222657476757uwb + || b[14] != 43556142961428377560472619444222657476758uwb) + __builtin_abort (); + static unsigned _BitInt(135) c[] = { + 1551285959809994210151290388254024769929uwb, + 9215997233892929635003694907344971975862uwb, + 39194975204437258458997572112485704553492uwb, + 30855703323230132032090704189294312024903uwb, + 21369469779496743410402906224964849075932uwb, + 14841665908022079679702934181971886622844uwb, + 19630534803796254511661738870561125391241uwb, + 43019675483091641860333234580998356788381uwb, + 39970634580048249544562112517644333613056uwb, + 1191217737795360372798505798508058uwb, + 37946572714876419093215575675176896482623uwb, + 4232750244223021640360996638731476646770uwb, + 4052758609491127849063467754379555742566uwb, + 39722275064055273051470447567883559006300uwb, + 0uwb + }; + a = 24657112304265243122405775577311943535949uwb; + s135[1].d = 0; + test135 (a, c, 0, &j[0]); + if (s135[0].c != 37693225764587199559589625622735125586095uwb + || s135[0].d != 28346681648428908942498835305586873104084uwb + || j[0] != 1 + || j[1] != 0 + || v135 != 3630175486665984734451871104132020832544uwb + || c[10] != 37946572714876419093215575675176896482623uwb + || c[12] != 3833867901824850271841502183382772060067uwb + || c[14] != 3833867901824850271841502183382772060068uwb) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +struct S192 { unsigned _BitInt(192) c, d; } s192[2]; +unsigned _BitInt(192) v192; + +__attribute__((noipa)) void +test192 (unsigned _BitInt(192) a, unsigned _BitInt(192) *b, int i, int *j) +{ + s192[0].c = a + (b[0] - b[i + 1]) + (b[2] << 7) - (b[3] + 42); + s192[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s192[1 - i].d == (unsigned _BitInt(192)) -1; + j[1] = (b[7] - b[6]) == 255187001951392025884741936737034599050205342889367592965uwb; + if (b[8] != (b[9] << 25)) + b[10] = -1; + v192 = b[11] + 2163738967454769289750177070635481073128375537642482578981uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check192 (void) +{ + static unsigned _BitInt(192) b[] = { + 3228866936540682691868394180939247213045089209876303887643uwb, + 3908758529346495655434258047388434965374712986050611884354uwb, + 1851532482363341717513713701170081412289228794495066903175uwb, + 5975293786133775194483789296663647337052708600272963495919uwb, + 2820057475559560607299380550839942093606275933232105346229uwb, + 5362817792426405848910790868188776921236918437924704229050uwb, + 979877290520863780830672004560233786791511895586353138705uwb, + 1235064292472255806715413941297268385841717238475720731670uwb, + 5829209170873343132786365572649959801760991694267006189140uwb, + 3298265737098071024465207026022448799296008756143231498035uwb, + 940670103332613157768642186014034108249816638700548072517uwb, + 2237128221585286673265910175884786455449703050136766895084uwb, + 5343797638430338971087457378870861887867024738000778783665uwb, + 2529390643742992876667887597532819348219532837015437654241uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(192) a + = 2618661874473674031833709426402867675358124955059180091771uwb; + s192[1].d = 3240880288967057869631914892069482190385384187140994012855uwb; + test192 (a, b, 0, &j[0]); + if (s192[0].c != 706870028734637453615201354376795963209926828811195228347uwb + || s192[0].d != 2285738979037264170090375369163685923831632419516523901418uwb + || j[0] != 0 + || j[1] != 1 + || v192 != 4400867189040055963016087246520267528578078587779249474065uwb + || b[10] != 6277101735386680763835789423207666416102355444464034512895uwb + || b[12] != 3747711091643687887167901825674847067882822607448596858654uwb + || b[14] != 3747711091643687887167901825674847067882822607448596858655uwb) + __builtin_abort (); + static unsigned _BitInt(192) c[] = { + 5056545299578942817419004982927444283363838129353580295745uwb, + 3531417693480247808623806953213145420554761387079781845903uwb, + 344995382910742860278210827312297947555943126346350032667uwb, + 1665878021517466104406447387862080652541968946313097848513uwb, + 3702336991937894056852499403052128743722086447309795810459uwb, + 3047176269106908247893091430981158526415914935872745232818uwb, + 5837808927599143324365016946161962633699774149391236391641uwb, + 616230573526655023040079960385747061734409792273035529358uwb, + 4899745987387470009167824739532983626288828402149586108416uwb, + 146023809533937871729368708715825784989858520095038uwb, + 1818078651877174878773673167465776979421635253130676590402uwb, + 708253875247724856385503140762213862078700660051492170198uwb, + 1918646725296468312732447651696775312079697668357127231420uwb, + 3407896467949241097221562008023866460487016701943186636216uwb, + 0uwb + }; + a = 4334425031127766761089651540568319387961460796342206894467uwb; + s192[1].d = -1; + test192 (a, c, 0, &j[0]); + if (s192[0].c != 4413371480577316434238862115941009972672800653387470086858uwb + || s192[0].d != 2226914616394806622299956064802345362767073196810043931466uwb + || j[0] != 1 + || j[1] != 0 + || v192 != 2871992842702494146135680211397694935207076197693974749179uwb + || c[10] != 1818078651877174878773673167465776979421635253130676590402uwb + || c[12] != 2869205267437439666614227415183799955615338742520847876679uwb + || c[14] != 2869205267437439666614227415183799955615338742520847876680uwb) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 255 +struct S255 { unsigned _BitInt(255) c, d; } s255[2]; +unsigned _BitInt(255) v255; + +__attribute__((noipa)) void +test255 (unsigned _BitInt(255) a, unsigned _BitInt(255) *b, int i, int *j) +{ + s255[0].c = a + (b[0] - b[i + 1]) + (b[2] << 12) - (b[3] + 42); + s255[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s255[1 - i].d == 255187001951392025884741936737034599050205342889367592965uwb; + j[1] = (b[7] - b[6]) == 35079516404010817908112229771536766101092256322770268596592519563335917296247uwb; + if (b[8] != (b[9] << 42)) + b[10] = -1; + v255 = b[11] + 9589198606702369375056479928174941699714421508271337355764754830579779054882uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check255 (void) +{ + static unsigned _BitInt(255) b[] = { + 3861714047960214860503769476754636024261469188339866686856553775336008577557uwb, + 51175255900783946984470019707544472774211315503709121319713624735134204561369uwb, + 17345603833958095509660462595097262634109622426516669177449315775424443341657uwb, + 42823701374562019745772585881781652129981403461863690469883912594099541433080uwb, + 51319674321995616727877469124404951867658380853042706770000900262120757183208uwb, + 52906636245432908656398520278306560145122955700637871390327152110192649720972uwb, + 17358815113825560149028333410813032121665286465083593038209986169266901681646uwb, + 52438331517836378057140563182349798222757542787853861634802505732602818977893uwb, + 2788004462553513100609800852000190119799062917794460119684836482863393638874uwb, + 1371934028037182110859712841210549299053627214483532073119322938817156900802uwb, + 27446425677305660137811201333992510946884519570968084003836788091973600281223uwb, + 26953886320773144921523720569352939441073773759009802807981124464100414571230uwb, + 4136701104931368824349366292837727313467036617036788061778000290667287672703uwb, + 16284209316703094594160217903483772091891615489911326105642136930965810318850uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(255) a + = 43671209527014657031076032832534182807479171149570250544322965577348390656271uwb; + s255[1].d = 255187001951392025884741936737034599050205342889367592965uwb; + test255 (a, b, 0, &j[0]); + if (s255[0].c != 20576567717160318081578175912662929186060780346948500086480401311222111385641uwb + || s255[0].d != 39177534735914878791230670587295539597881897796949856541813587771063479852129uwb + || j[0] != 1 + || j[1] != 1 + || v255 != 36543084927475514296580200497527881140788195267281140163745879294680193626112uwb + || b[10] != 57896044618658097711785492504343953926634992332820282019728792003956564819967uwb + || b[12] != 41611835301955003117625274600860181834743376842908955914086655072990754501117uwb + || b[14] != 41611835301955003117625274600860181834743376842908955914086655072990754501118uwb) + __builtin_abort (); + static unsigned _BitInt(255) c[] = { + 7981769630282326956199854914771456697123750044016665635797085873395082876412uwb, + 53388853971156757275720047407967538568298021437528793620790412040317130403689uwb, + 26701828432251973964608431737798795253412436987727543352462415534788835630812uwb, + 5440780860746561756714149436754163126067503344036226572647314943619048388690uwb, + 33986332817169953208946609849689345925961381637863140695485139248791268070886uwb, + 4100939267210968649446715463008507186522717252282546996073651959494281461390uwb, + 51781097727624204498405281053756240112648760803686514440326944560679935060229uwb, + 39871871446047940023148355012724181415135167919226806605949531421611900671463uwb, + 22669501989113495379481452050938385508947296877470428714787872701608093548544uwb, + 5154447987732395490520832948036146605988346181554886405771838486uwb, + 22291959629998533921508247788279156576466986919969930954212934913917085206989uwb, + 1961549937179049997528355604457213261448618818592679790977249627688612403787uwb, + 41836060567948575115843842705609341074148894754978250388257622994608010108015uwb, + 21250627322648087754897420116830444064785267321586891615233932456372363316960uwb, + 0uwb + }; + a = 4334425031127766761089651540568319387961460796342206894467uwb; + s255[1].d = 41611835301955003117625274600860181834743376842908955914086655072990754501117uwb; + test255 (a, c, 0, &j[0]); + if (s255[0].c != 12109153275975887113226632923657866254324254170345083268415546710877474684826uwb + || s255[0].d != 55850175013735185955402882706756822737483750660992935334535260602616242125954uwb + || j[0] != 0 + || j[1] != 0 + || v255 != 11550748543881419372584835532632154961163040326864017146742004458268391458669uwb + || c[10] != 22291959629998533921508247788279156576466986919969930954212934913917085206989uwb + || c[12] != 36645417296010009956888072387513509861849725011233390404494859547584201503007uwb + || c[14] != 36645417296010009956888072387513509861849725011233390404494859547584201503008uwb) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 256 +struct S256 { unsigned _BitInt(256) c, d; } s256[2]; +unsigned _BitInt(256) v256; + +__attribute__((noipa)) void +test256 (unsigned _BitInt(256) a, unsigned _BitInt(256) *b, int i, int *j) +{ + s256[0].c = a + (b[0] - b[i + 1]) + (b[2] << 15) - (b[3] - 135wb); + s256[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s256[1 - i].d == 53206656141818470791424256353006269277597513345110510288076840335108990485400uwb; + j[1] = (b[7] - b[6]) == 100099038883167575868168369054142100716577408309486879759875338591874183239821uwb; + if (b[8] != (b[9] << 63)) + b[10] = -1; + v256 = b[11] + 105302399496355811946682562261964785380738245520086820947909580844925217183297uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check256 (void) +{ + static unsigned _BitInt(256) b[] = { + 32009310487117026679674626072407603367594653139936438287667930528262453801915uwb, + 65176902468824044453790267089157089693737812535360753024943201863160377679656uwb, + 82344070090465165315955757521075336622529332575448066816076316414765425718982uwb, + 1700965766421539490938858830624234600098958435316757520284868641071726580981uwb, + 43634292917714777985622413899887802700784049405471615230478960221105984199159uwb, + 100631692904819207373422601372327472587552135350288379476708675217470156851657uwb, + 110129860579524893207321038633598210672223454232798756477691416433717017519769uwb, + 22023582511300831410026311598353795806875331462942548421790016502461571529072uwb, + 40138510211986216232290944684699787930583492725766883760868504701674647977984uwb, + 4351825997216706075548423101456944800498099170105917024323uwb, + 169752993639582224244050634348149779190985669780902142577260914458554153598uwb, + 32145284966541819913159374355840318160537667734553997019437196071417771295134uwb, + 54664388217936175028491213294153178079954834597579823229832063212225827892844uwb, + 20191860868728322538097431032697551245493230687142770900578302601765403775815uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(256) a + = 35032284611123531672148181265368654016291603806765316452453041084857012399819uwb; + s256[1].d = 18495552704607464237917826961539803493777535452633922395016139213747075459320uwb; + test256 (a, b, 0, &j[0]); + if (s256[0].c != 63389043283546287594263459568996583234036639501854425943006627750610451754736uwb + || s256[0].d != 85940937558229637292496709413287085767649546821453763197795096316568198990162uwb + || j[0] != 0 + || j[1] != 0 + || v256 != 21655595225581436436270951609117195688005928589000253927889192908429858838495uwb + || b[10] != 169752993639582224244050634348149779190985669780902142577260914458554153598uwb + || b[12] != 95600228368587872885473553975990356607776753978497793138879281406147725864120uwb + || b[14] != 95600228368587872885473553975990356607776753978497793138879281406147725864121uwb) + __builtin_abort (); + static unsigned _BitInt(256) c[] = { + 32343204662160194495085563951007642761735079004830363200819846414562640245919uwb, + 24084137699661809462548106377371635219349193031343667516905836190779613998386uwb, + 101379688603662938586655900818791548427393428573101695287405037352360497544008uwb, + 49527008749469396581891560939525147311301744659706134394761856095820111704400uwb, + 78611633605884634807198913241948438916640856307470257529328762903676002499180uwb, + 7725329946357185150163578923822973618563365182619444740561512924522337085644uwb, + 87230734821522736453376619836617027268082314423737558813724810260551555679101uwb, + 71537684467374116897974003882071220131389738067583874534142564844512609278986uwb, + 52523168514171623670932664104908233302972408272520282168521737371661091576905uwb, + 55534995177165851478287456502449363262630885721301994816018615193922251275498uwb, + 36185028875353330724983116385242607835574307465276274632872421166901316306305uwb, + 105156498492189914423239302852802412965634513221765962480547101568217183385322uwb, + 107291868576624602610288559845636897859595852848306710447908839132037475007641uwb, + 31763533437617266501468240129359520348601211969709950732394000355828663205766uwb, + 0uwb + }; + a = 9837521119254571559208641097198297536765546083418356216057243384350911670458uwb; + s256[1].d = 53206656141818470791424256353006269277597513345110510288076840335108990485400uwb; + test256 (a, c, 0, &j[0]); + if (s256[0].c != 18957614795124660722423653645379624133127098231408367194845756641321108143966uwb + || s256[0].d != 96521194298766978603491920349693757511095007817895085416680901426339418123139uwb + || j[0] != 1 + || j[1] != 1 + || v256 != 94666808751229530946350880106079290493102774076212219388999098405229270928683uwb + || c[10] != 115792089237316195423570985008687907853269984665640564039457584007913129639935uwb + || c[12] != 84028555799698928922102744879328387504668772695930613307063583652084466434169uwb + || c[14] != 84028555799698928922102744879328387504668772695930613307063583652084466434170uwb) + __builtin_abort (); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + check135 (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + check192 (); +#endif +#if __BITINT_MAXWIDTH__ >= 255 + check255 (); +#endif +#if __BITINT_MAXWIDTH__ >= 256 + check256 (); +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-6.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-6.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,359 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 259 +struct S259 { unsigned _BitInt(259) c, d; } s259[2]; +unsigned _BitInt(259) v259; + +__attribute__((noipa)) void +test259 (unsigned _BitInt(259) a, unsigned _BitInt(259) *b, int i, int *j) +{ + s259[0].c = a + (b[0] - b[i + 1]) + (b[2] << 7) - (b[3] + 42); + s259[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s259[1 - i].d == 0; + j[1] = b[7] == 853796348253166026572322331766419194644297857346047602312235759502541501989541uwb; + if (b[8] != (b[9] << 25)) + b[10] = -1; + v259 = b[11] + 131672585462768721291717421546274215675860478844820049742378853291513419577293uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check259 (void) +{ + static unsigned _BitInt(259) b[] = { + 918480562371960593090410127982602516965623024307296422252015063457072276190019uwb, + 805591267508470730905808815897672235976825560202638463105454632689132956230159uwb, + 918331245995907029502562304060195532137531507866437159352108797919955179870191uwb, + 813875127751611422577721650805025403235043641932299023318765404699420543383496uwb, + 312693756633721376836885884755241545403854394304071110713260437525889451361210uwb, + 649538941042539125892439630557027126879421922847150643068762916100064243451309uwb, + 773306487188996490948079630445764609771546927800966605886964877358699258715670uwb, + 853796348253166026572322331766419194644297857346047602312235759502541501989541uwb, + 76083267877106286558555438489752654093377337000667150108584195505702104870323uwb, + 433731305334336103344926930540791423313226370883401849111287164916738117506640uwb, + 57656267431091314368862950118941867863238118931858464589826085330125773498121uwb, + 64173041359832501449385133817329349658818599309611908558002991010875611848746uwb, + 42346589146173514762997245981921905757283138481803437257678854533030144461674uwb, + 61227931681037412178262565289688995250776671963152062289442760797238154015232uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(259) a + = 466268672176961050215569613615746490713100259736768099838759141406021022194231uwb; + s259[1].d = 289647636390911494735348665819031670280022785262945335571175835860869121921853uwb; + test259 (a, b, 0, &j[0]); + if (s259[0].c != 593256375550214279190871305843268365974742545847394880963235621252368145099513uwb + || s259[0].d != 258470741923291377781882672832254987468877297321140017579156131137149865493929uwb + || j[0] != 0 + || j[1] != 1 + || v259 != 195845626822601222741102555363603565334679078154431958300381844302389031426039uwb + || b[10] != 926336713898529563388567880069503262826159877325124512315660672063305037119487uwb + || b[12] != 865108782217492151210305314779814267575383205361972450026217911266066883104255uwb + || b[14] != 865108782217492151210305314779814267575383205361972450026217911266066883104256uwb) + __builtin_abort (); + static unsigned _BitInt(259) c[] = { + 280836731241256517108451767043891202691471765896401168847540724952507405972497uwb, + 840411222605516639870988613734990053662001382735609723401814266406994078815101uwb, + 315675972612806440596502686972210055502484407915611896031513380334465695474313uwb, + 203899119027212320906468030526379653925169232409139699654080707114835986996999uwb, + 128451577752218373908172046011152144714641252063864956677744337179480421046978uwb, + 287567473759168733146788470777196081514207657452235204870489646221804917429977uwb, + 750296306916736952737909920532226142314659927184810908344954406682013838424980uwb, + 656663422127941740082895518453608245693505586454580487767696297787796578828932uwb, + 879879542531872983872988522489746684941859186676324312036446053929728989986816uwb, + 26222453788872748132735148742489417938645457824359068633212031541160613uwb, + 721087878418777615469711741435156333032292047533740164381818331009890349325379uwb, + 441184423645775123821015863267700095523103297061220954332335218574744406423193uwb, + 84779661426980563874304295256885870100654945451373784779121036518843563800060uwb, + 720201829457536541913713975070870089885671802608506320469648510576137739651426uwb, + 0uwb + }; + a = 18070271922856865288654809596744903817727150511379287511935119712627107404963uwb; + s259[1].d = 0; + test259 (a, c, 0, &j[0]); + if (s259[0].c != 754979172232367155652142901903016464541317666806124208079545327296101909258886uwb + || s259[0].d != 726067720449610868402876758678941562623370067217056480941991810113614143071607uwb + || j[0] != 1 + || j[1] != 0 + || v259 != 572857009108543845112733284813974311198963775906041004074714071866257826000486uwb + || c[10] != 721087878418777615469711741435156333032292047533740164381818331009890349325379uwb + || c[12] != 206134884440993021474853904998633172940488074716618191846012161487167297468061uwb + || c[14] != 206134884440993021474853904998633172940488074716618191846012161487167297468062uwb) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 508 +struct S508 { unsigned _BitInt(508) c, d; } s508[2]; +unsigned _BitInt(508) v508; + +__attribute__((noipa)) void +test508 (unsigned _BitInt(508) a, unsigned _BitInt(508) *b, int i, int *j) +{ + s508[0].c = a + (b[0] - b[i + 1]) + (b[2] << 7) - (b[3] + 42); + s508[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s508[1 - i].d == (unsigned _BitInt(508)) -1; + j[1] = (b[7] - b[6]) == 323515224000201027366899758000237142291440124580568781353226908396916757538679852963577209476426722029505026752120305126905670783187399192585916919546571uwb; + if (b[8] != (b[9] << 25)) + b[10] = -1; + v508 = b[11] + 716024231508310591151659913627069746319678908481108351681014830741662356869311236055018626572200723297424975249553920015269741669328444662913268383663677uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check508 (void) +{ + static unsigned _BitInt(508) b[] = { + 832078183434045927540487103804907011739266549356223191691643561067749769975943908404638920166502402329694585519922110244852912407804057166046933883008194uwb, + 713936147229868929139293139988718979167626862529198392930772721993480948457421027732398866594698271934473685041618760204074421885407508961194284075992372uwb, + 617361847118081522653471977724056261996473287264427111568008587684000569753190215945768169015576241392153003921766059387579429385226558246856562678192104uwb, + 558345641413420470280223467353393511714120008866888151814287282910208158712080338084981427985120538158019424401062183786473300529579273867747687575759264uwb, + 499761439373420902958682462789094939629857960756907734602342350501615831252037617149223977152737393272833291045861050465948469241674239312800301147123184uwb, + 41458778840616754230715683890502356563717287755866620113981050014317462591845066532973853075702831495501272233490672301990969026267150137016150650508199uwb, + 418458681135681746732437152058641717690726059977788598152959959313259063414620594315807075298922056786187386710006952502872115288914005302859339669672594uwb, + 178590258028275731715530947756428839232212382672258470295756987295058447444774755851491768941934611483011083453873652899758014544959831694913681677646689uwb, + 356770203054529564617317933555709062197425817471944056561734674021988369183029131819074076937899959445814817800565023050865025285444839826004948142681410uwb, + 584112461551758657888253754473884153359686350173736669541862380483308304473624923065781205318194340854082383073991675143564628127579536789385040891716043uwb, + 680157864635886168227443104616994718021643051017205364932604743260844971234200794270551054794576522886616288751944237137476474081129540389630063933035924uwb, + 624234678396543393542036481071764142163163163113602945911969155623637623734341260164471554708546709676358706745261925658188877241381613170733888758848256uwb, + 454784507207582406161930055875861559038811204428592354757758685948743133937531828752051902975778637734147167150365830445107092680154259745175825282331123uwb, + 319986047127156205965562926466827182744423938150941443628321307635789163001042001590072115090024768392582441327268266695557745771318045725281606272507745uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(508) a + = 711291826680524221552366807721297346517830107349701196208230744872277012932938686554048942571552181657477920414828724120656294188547596916447951866844703uwb; + s508[1].d = 44300483028507681832691655975564116229472905643882332053402780694878295874197390896801387042830042144560060996721375070892413197614373985836807183707843uwb; + test508 (a, b, 0, &j[0]); + if (s508[0].c != 522533064172957689320353588403947403982656359176197029733990042723046927465640381488621700421437034411326731632519943219324383970178228415895248995946467uwb + || s508[0].d != 544171514892154666305054228710247267670694798806087644332682606744854247388929324492327007054644882499782210854566003344906189740262758953265414281741613uwb + || j[0] != 0 + || j[1] != 0 + || v508 != 502270914283441665970319832310968505515381707807686711485261396132689728724055810169373037645315968743156690858160467495099001234963397211995054079631677uwb + || b[10] != 837987995621412318723376562387865382967460363787024586107722590232610251879596686050117143635431464230626991136655378178359617675746660621652103062880255uwb + || b[12] != 518001948494256112757813635921038200223036425636083142479401282596821088878554684460045028545406695838044549809387111482801871904428614896370496790372510uwb + || b[14] != 518001948494256112757813635921038200223036425636083142479401282596821088878554684460045028545406695838044549809387111482801871904428614896370496790372511uwb) + __builtin_abort (); + static unsigned _BitInt(508) c[] = { + 647557698892184285650475800644782894130830134743039316064874048572238802447391019320461822795528468837172509913850428906715002084926186679743636685547834uwb, + 19893833808289543304534784415999074892775857443659529983103990809804459295154825463722400943836101951812379338522524133647269361956787413321377320775949uwb, + 167225090603369392131840179341189845624248307670461180275627141145612180756017010718187841360639781066493394970424816391919242343853725482848930838565833uwb, + 425038857255644658246682026149139094877872271690333163307937973752297810646903055053327010856106694556745086838630642887918900506053243909959679540607590uwb, + 710399860501404196180909731021634278197730505954614106387836731661196474327340462005364906935941520263965559590135721186838498741274345456365502514761552uwb, + 517100391187257228299118348633309855520848206928211390424040909382822545139910418018096605353580518981578830214711288569084195564658992133538762776045012uwb, + 337049882664509041243030742301206305462316697436525762870825130294272111721357923024083663351305745791606079615492796115999045732841532642628230422676768uwb, + 660565106664710068609930500301443447753756822017094544224052038691188869260037775987660872827732467821111106367613101242904716516028931835214147342223339uwb, + 264311519140803818482685788811186614544730978154943534367495114584051059508245461660412877555306257793689596804946554756871772168758950748494862728822784uwb, + 7877097104215735747894221210813123421213954036085114907249662714721294030792875935447599814990349346211242580561237178947680359147755823984589062uwb, + 67442667089892250469544199468501425015399920231234867688030078116216928480132993764590084699986918086331763703967003811392074730155208796825341891897256uwb, + 85129756049329066391994997807963865671611392223804816975886973237646888963379984739504507746795881579055447505908308844315081721803505794221196177586220uwb, + 707371868440287371388093572489945370955349752876981733417655198143352744491182974880452293708290631899668322081620029303621428033853319295154190475832548uwb, + 538419296440305382227520128849893548498555312954035671105518356624711212650496087782309622044337222159048223665137702366210806405686462563977378378472852uwb, + 0uwb + }; + a = 708586050532895903124837960170867540022772026063196035415656948205052808113573236752572838768221960601298200594769808975966326249462737081924621284351278uwb; + s508[1].d = -1; + test508 (a, c, 0, &j[0]); + if (s508[0].c != 528334769435707893291849283838312547132767955028634494668975752805681928519569910180983209404481539444766030992803736389428118910242578080095668810055499uwb + || s508[0].d != 626861153942807538339962839367652023698436836743736597401578432880275274177104419034373833881253982548479037772997711030061561577382993299825586823026782uwb + || j[0] != 1 + || j[1] != 1 + || v508 != 801153987557639657543654911435033611991290300704913168656901803979309245832691220794523134318996604876480422755462228859584823391131950457134464561249897uwb + || c[10] != 67442667089892250469544199468501425015399920231234867688030078116216928480132993764590084699986918086331763703967003811392074730155208796825341891897256uwb + || c[12] != 299568699181106936495856433537971834468905050832988915002204233607899039229100598267807521591094242071578767471517675812148811270060198057674724684407403uwb + || c[14] != 299568699181106936495856433537971834468905050832988915002204233607899039229100598267807521591094242071578767471517675812148811270060198057674724684407404uwb) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 512 +struct S512 { unsigned _BitInt(512) c, d; } s512[2]; +unsigned _BitInt(512) v512; + +__attribute__((noipa)) void +test512 (unsigned _BitInt(512) a, unsigned _BitInt(512) *b, int i, int *j) +{ + s512[0].c = a + (b[0] - b[i + 1]) + (b[2] << 15) - (b[3] - 259wb); + s512[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s512[1 - i].d == 4522353484324747955267125937291948655749617973066893955369024131525488299108320993071208813642361430492411037439152575330738596343613170269621629934531241uwb; + j[1] = (b[7] - b[6]) == 374577815990281408677256593783629954432691286119512435557712294960563169554809756081207157974945869359369961439855092584877150233312923919236788786326875uwb; + if (b[8] != (b[9] << 63)) + b[10] = -1; + v512 = b[11] + 105302399496355811946685122261964785380738245520086820947909580844925217183297uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check512 (void) +{ + static unsigned _BitInt(512) b[] = { + 6021199531765212801884676816470799034908236595092557744734057443805875347290483033829674243182977894869999446238486916822395301604705319217995654295432902uwb, + 2118944847509270465197760108216002226005910220953364492400962085188310835486567249208768553765555672830161371433385656186687932945648641289635143624153621uwb, + 2468011621780240906908738384251283152842243623265843874579649124218711735704146024693879862235081238297926460688162588400193067305227164327914340959869992uwb, + 7852261253584637784169919081877553866282673859198296203117153724887988256894439079095114803178078464315049063160714347766105329320309211116124084359320890uwb, + 6881429107351001058295162119545491230166185795246928525617516768009088834586165228975554760023030849264752345389888178729929909699157633918182461033495556uwb, + 7490938212743615293405934133782451317533822019734363666709765080515130781799097345699393688357934162148290248912225980297047575683793284504381422978757040uwb, + 10120569572654605122639402565568718563995238635532261987812601502126969028367382422209505735533685455107591090283702679606268593966759672963076962700307022uwb, + 6544115361584477201664859993249450245040478983518054359791236989888339451701690370158568050118785002344520392336988100105900733099550716973249399480839328uwb, + 7998211385715595185432216755958202893898483475426306631076103969688188023218591677753885970448355780373235280537235089173590925156414399326886601942858952uwb, + 1101608905235198391935063146859712526167216410759556463737474438201976460429148065105316982180322610546500122551969559689893274021338053420958788359583115uwb, + 5547339070657168956577880025794227235978722359584966491999832792960847505505357241452219444649567336517274817160074290099346053369308053580179899142505418uwb, + 1750269279776476441267578744631933548060353310561690992260040183595109596951578483669111308170823694772335056351746927981021331305166802991213646334514404uwb, + 4192336828386954798960532308463588917660266569128375313949004426859425573394438991510991296156896119249870038323974327749964728970306928745553011492449651uwb, + 1900177384209047479231940933911260783674256383613355641699143750453309311902806908717431412257630234621978137884266303399427482666060857148046946256701407uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(512) a + = 10930130497064002394702882970302938462793108526726281176439996378763909442554754292732278993783426604574021331155984114583431563021614093376741477610729300uwb; + s512[1].d = 1062548863735806614766555155689890005619504886385354582078741512313209800319722918322963204342249477855349130571262241563029708157593686639667293170464985uwb; + test512 (a, b, 0, &j[0]); + if (s512[0].c != 2887513008923639902240466565062692784517178403522406023075811881559011847285804098407629056403311082480905591628208975136041938382372340398331672243318734uwb + || s512[0].d != 972130803422634759391069517910461958937573607139260059384360471797756640789653835842301525452796103317707145350644624256211972219907968589876206212846874uwb + || j[0] != 0 + || j[1] != 0 + || v512 != 1750269279776476441267578744631933548060353310561690992260040183595109596951683786068607663982770379894597021137127666226541418126114712572058571551697701uwb + || b[10] != 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095uwb + || b[12] != 11507630545733549620342084064294585343805109436979037736024417693268454718170740068084442885909273193068053720302219747454326400145885712798386702749382688uwb + || b[14] != 11507630545733549620342084064294585343805109436979037736024417693268454718170740068084442885909273193068053720302219747454326400145885712798386702749382689uwb) + __builtin_abort (); + static unsigned _BitInt(512) c[] = { + 4310457364893777373602665157014873559135384447597675565065759273827483949324526981781306465942744538806150653124143200561193417791157963881792904451069362uwb, + 5958789020370015340565416950487013712033450466320460334048228974568661716557882588498670105211169302921483448876614084424938615986458325610065852828118306uwb, + 8284743202872517242207866690683488538720128091867223206119391935721931034359590521893173196995749495634003248491356217756384997245149844917613657244100946uwb, + 12664079984606974422077559239355618815941897900272441909795959033933251997534364342568914887960377305762259523811571861079808666818626009150755656127832627uwb, + 1277280061505669581991258509578719709995272247404983496353130395005685346463372196431685623256422418143892881140710485556437791815840558839002633040897782uwb, + 12215250731983666777320125323169237871547944066095330125912513738032966095255991063167892594205142430862706904005862880547898319287711754622854549074643186uwb, + 9251003287718566323105383813392168970560299412448652319116761599247007001244197366325250786747301353984616744521839526461090225556617577043580629233001099uwb, + 9625581103708847731782640407175798924992990698568164754674473894207570170799007122406457944722247223343986705961694619045967375789930500962817418019327974uwb, + 9625581103708847731782640407175798924992990698568164754674473894207570170799007122406457944722247223343986705961694619045967375789930495977475637258485760uwb, + 1043607594407655227216500911938969602142764645410552381359002950524059754591300096857049049719237072025508574484388968507628527351266845uwb, + 11998753448729239344000141538200052195237540636029454316657436691685826543599848607581685084378245778577663489979887014434647868686320656434403040763612551uwb, + 11434040832182557441766779829155897224389793286294752961027160601623012283276511030063398944055141766189843896068181650049692814441787333867085760205626564uwb, + 3023331158039332614691238368394682484299421409956298474635469941534054266475913779087200438226804802431840397460566948014999950457892777550113994388831586uwb, + 6643992699881938834553303739293839845351896246066261353792165016004958058241209888845214001951224186762526613611217678738912897449639764896432567428225735uwb, + 0uwb + }; + a = 8297086167455412951314345399041666622690871902388991853000149614722648899348042581378229717518281695539366926410544760114561024579207473131456671312516393uwb; + s512[1].d = 4522353484324747955267125937291948655749617973066893955369024131525488299108320993071208813642361430492411037439152575330738596343613170269621629934531241uwb; + test512 (a, c, 0, &j[0]); + if (s512[0].c != 562788706253718154365616008999801360288452754375064525508119581728036130536904720042355361715252120605188469823973820439731595153197657174657215322741897uwb + || s512[0].d != 2450664880034868237736952350867106482818480521222495256778680955285041346939852822760111651975591771880097571588399256063032055281563320405249761438168944uwb + || j[0] != 1 + || j[1] != 1 + || v512 != 11434040832182557441766779829155897224389793286294752961027160601623012283276616332462895299867088451312105860853562388295212901262735243447930685422809861uwb + || c[10] != 11998753448729239344000141538200052195237540636029454316657436691685826543599848607581685084378245778577663489979887014434647868686320656434403040763612551uwb + || c[12] != 6763815230060658265020721258912006282127469574526132023931396427716805971832337087956660296215679240927505244575268372114840985362306805050001081577858360uwb + || c[14] != 6763815230060658265020721258912006282127469574526132023931396427716805971832337087956660296215679240927505244575268372114840985362306805050001081577858361uwb) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +struct S575 { unsigned _BitInt(575) c, d; } s575[2]; +unsigned _BitInt(575) v575; + +__attribute__((noipa)) void +test575 (unsigned _BitInt(575) a, unsigned _BitInt(575) *b, int i, int *j) +{ + s575[0].c = a + (b[0] - b[i + 1]) + (b[2] << 27) - (b[3] + 4958475968475894375894357484535984375489wb); + s575[i].d = (a | (b[4] & b[5])) ^ b[6 + i]; + j[0] = s575[1 - i].d == 95573020206290249524150023772890126071219633117171019262766503336310672999410172030736216511031014256906040106668955921896748704905692143264499542165901631357858279597168868uwb; + j[1] = (b[7] - b[6]) == 27145700341365416267735847217275690336177396856349392593186862163108423829551399123342676161793491631779988040463555034191451268734796110296927769088083654195518127550378112uwb; + if (b[8] != (b[9] << 42)) + b[10] = -1; + v575 = b[11] + 23747340451678047735163360653763407761482933548732248545666538557842792154643066748753917518601117103336304219106042161459437965550611189291922027839274834493025750978734016uwb; + b[12] = ~b[13]; + b[14] = -b[i + 13]; +} + +__attribute__((noipa)) void +check575 (void) +{ + static unsigned _BitInt(575) b[] = { + 109629911866606562961096883957886177157168492273877379264846777289230149818443125999912223814388744273336157512735477622882702153104102811897060843654669684146016128756706531uwb, + 49737336835254330810961852329841465152166265671267895624334663745208596732097722057750738167775257956975985814734408710423060394871412870929476144910662495171305515147160358uwb, + 38554548935224072640061799348846572892670189944581591586656577942689453406789240916780049368436228529892778822796853383245767382205374048871923124561885190260824233296311215uwb, + 71058269942432013527315378010985114704370555413208353814319452373530227298981545120481154232525349782777377989106743248998743352091363716737509221664926215529843633715687782uwb, + 4160385932463020068352363207252688161266437324266506898550050263305674040252431030407032416831730109735167157770872898962184845623991414528191955840335425228637597057146575uwb, + 92940635878626680004989100258386964603204572877596438304889779253809889656868292370355114313083957669380421733891295145627252962536732023763637134129797695217583987460880286uwb, + 2497863814760324764248624507199774997376419692946013954829621482125467045874636227196983588067358574709667157879971660264026959433911373287725284674927778585806087674600393uwb, + 39669551656169181196901167730139627329430801053972757381518801156276770602506281629333177027704798069522455806177708556852756692341281267078419473323939938196300261349249844uwb, + 34099204187046170921511393567690620643856679870121903412545567510502014273081623781684214852562822343760228918685024070983005024483424026237793838354204070380961780255948800uwb, + 7753261385697935775513404580053843493227914193567335908607121271075360317145537870074853083807016069786238612933862912310133884712609875859423900318280191272825uwb, + 110004311053786619259986678143505471501869971439303158252331533020072292936027495587470733973742054917424528022233289606593259788774806137554470308009293095009499747765639537uwb, + 96833004631961538015767463838833105015474376492192681907732908245833058438294860656404685183010591497179132293246891860908865398765545161691520277203799562157174917228796219uwb, + 80702609348091643417538298383109408004428354134511559457823339372643632518010615100071083122949651809745536686693833088575054309697466950053942939485340693253073606951812769uwb, + 33407553983903825388268227905051448847634610694178184538233348977258089995501154824364933504268463263804419263252997491873433785923300213087774501277469095977333397324099995uwb, + 0uwb + }; + int j[2]; + unsigned _BitInt(575) a + = 37458390908651944486318701298774946253221298284079678879752196062749754015767054813622389341442171327838532365078549465402085621913002861059272532398763941224574356382919877uwb; + s575[1].d = 95573020206290249524150023772890126071219633117171019262766503336310672999410172030736216511031014256906040106668955921896748704905692143264499542165901631357858279597168868uwb; + test575 (a, b, 0, &j[0]); + if (s575[0].c != 71835056112914750846225746791835613082740285561642802348494468629675719606761159266011893596664019145187589550627068973430325671456228503438760044269704956730966806603380315uwb + || s575[0].d != 35092678436051398145450456092160957085574382283207240091541444540207322324444176804583959098631686867119531362746451350477963519431922701372937009164511004298364112449348870uwb + || j[0] != 1 + || j[1] != 0 + || v575 != 120580345083639585750930824492596512776957310040924930453399446803675850592937927405158602701611708600515436512352934022368303364316156350983442305043074396650200668207530235uwb + || b[10] != 110004311053786619259986678143505471501869971439303158252331533020072292936027495587470733973742054917424528022233289606593259788774806137554470308009293095009499747765639537uwb + || b[12] != 90257646752648441641983032604772146169931063856427735418798179069190522557764778760793267026353059230994416449755072177802248731230075391895998576273477487980969988750249572uwb + || b[14] != 90257646752648441641983032604772146169931063856427735418798179069190522557764778760793267026353059230994416449755072177802248731230075391895998576273477487980969988750249573uwb) + __builtin_abort (); + static unsigned _BitInt(575) c[] = { + 82504361427244542991820094956691549960754114745978822099335511938351682595536290531725259255179129363075052806202441257721202109466202003805606931995490008444343669600699853uwb, + 42079105016133747306704896727331693360594255070597992997150557389990664988368628699356162986776491822580146238976269442994821141806156379826188754250358560351182286381406736uwb, + 711769802844526498820507696850878181897548931161560217731770512934668229904523420294613194965001881326982097300327085293326593185529346399uwb, + 89175170277971754813127791070754356690231836881294855904530631438372575707050409381165002268066908066508189405070930638781220028058233443902931422213686026604811589591935872uwb, + 94050888747959189678836802993335292608994888939368012114118213842817585341848237784852826131167319219605431056321492019432538459246136124892413917192336008119041481208682712uwb, + 38239296209217737134837463059250986563276353222124626638871007389306434648840299613965667293607942327919361664341059433984563767109851991087195673676603874741464175459967356uwb, + 97333559006669714102408081289832637446384482871277430301688457830360630424953635234987417481437096537137502568526675247478692954009451991021793982942577536513823999917011895uwb, + 814058611482863339892667997284732764996205177020902937843791947020441701239100773171893112609065674118654895982160611994461705590872496334948674479714606751038741393040439uwb, + 97705579217072075210280690501837541720113857756901619907589735305607760170945080008347962500870233338612695073361639697585534957702253004388475713115759324045158713339246602uwb, + 10982982241715500518624383020617613623499620192753751475894180095116406586056643710374985626416110420394932716762424522515613555006307631143920933236927136144852926571503121uwb, + 55829504657908340201404797796793782979617205764045686020250304202907511578861596703885712251150659580577184194460916884943183841026041393794213790496185940144912189048827888uwb, + 100875306823715847300644682553337559470837966294108010157772959400031914000172409603541204719305055682465391367527242389796209306256295618004852296452270010541263847504922010uwb, + 15279010635266215057483690428202871735658936908535846754770399078825578981747757698046709583412828936255448971025234637952103022364332558473695317217263761931457640744952794uwb, + 48444770867335255303325633099437372188650970089231857000193390748362558989590160188759337817835818168773038925935268431818011879469195339807606486208276196817195956747180163uwb, + 0uwb + }; + a = 8297086167455412951314345399041666622690871902388991853000149614722648899348042581378229717518281695539366926410544760114561024579207473131456671312516393uwb; + s575[1].d = 4522353484324747955267125937291948655749617973066893955369024131525488299108320993071208813642361430492411037439152575330738596343613170269621629934531241uwb; + test575 (a, c, 0, &j[0]); + if (s575[0].c != 74915286869691307910535753931416633675608326651216782655214347437885792615716349010228495093791076801730572987413666208183802410598889783023687426699732483562656666028609189uwb + || s575[0].d != 67322626164534684432128142510263628633851970452429406664125475042690110884386765927066456699852665904022478919125681907729713202628765997176929559711053556150174518973540046uwb + || j[0] != 0 + || j[1] != 1 + || v575 != 957446538841628005556782697277372214755225292234338746407969911426093601549542767136921707284650291002859873625214881579964754653531202313001246740598261075986212409306458uwb + || c[10] != 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb + || c[12] != 75220429869217011726925627410386222828914704461374062956838137298086053563675773396398862712785704326025796787072801237857670637684180265176166591342670387141107429327169404uwb + || c[14] != 75220429869217011726925627410386222828914704461374062956838137298086053563675773396398862712785704326025796787072801237857670637684180265176166591342670387141107429327169405uwb) + __builtin_abort (); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 259 + check259 (); +#endif +#if __BITINT_MAXWIDTH__ >= 508 + check508 (); +#endif +#if __BITINT_MAXWIDTH__ >= 512 + check512 (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + check575 (); +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-7.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-7.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,386 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) void +test135 (unsigned _BitInt(135) *p, unsigned _BitInt(135) *q, + int n1, int n2, int n3, int n4) +{ + p[0] = q[0] << n1; + p[1] = q[1] >> n1; + p[2] = ((_BitInt(135)) q[2]) >> n1; + p[3] = ((_BitInt(135)) q[3]) >> n1; + p[4] = q[0] << n2; + p[5] = q[1] >> n2; + p[6] = ((_BitInt(135)) q[2]) >> n2; + p[7] = ((_BitInt(135)) q[3]) >> n2; + p[8] = q[0] << n3; + p[9] = q[1] >> n3; + p[10] = ((_BitInt(135)) q[2]) >> n3; + p[11] = ((_BitInt(135)) q[3]) >> n3; + p[12] = q[0] << n4; + p[13] = q[1] >> n4; + p[14] = ((_BitInt(135)) q[2]) >> n4; + p[15] = ((_BitInt(135)) q[3]) >> n4; + p[16] = q[0] << 42; + p[17] = q[1] >> 42; + p[18] = ((_BitInt(135)) q[2]) >> 42; + p[19] = ((_BitInt(135)) q[3]) >> 42; + p[20] = q[0] << 64; + p[21] = q[1] >> 64; + p[22] = ((_BitInt(135)) q[2]) >> 64; + p[23] = ((_BitInt(135)) q[3]) >> 64; + p[24] = q[0] << 128; + p[25] = q[1] >> 128; + p[26] = ((_BitInt(135)) q[2]) >> 128; + p[27] = ((_BitInt(135)) q[3]) >> 128; + p[28] = q[0] << 134; + p[29] = q[1] >> 134; + p[30] = ((_BitInt(135)) q[2]) >> 134; + p[31] = ((_BitInt(135)) q[3]) >> 134; + p[32] = 42476074745096429931122498134186165182882uwb << n1; + p[33] = ((unsigned _BitInt(135)) 7182038401320930422841151460488443466941uwb) >> n1; + p[34] = ((_BitInt(135)) 19085908020200472220560502294394961233399uwb) >> n1; + p[35] = ((_BitInt(135)) 22116103719729384017971523177401136866663uwb) >> n1; + p[36] = 42476074745096429931122498134186165182882uwb << n2; + p[37] = ((unsigned _BitInt(135)) 7182038401320930422841151460488443466941uwb) >> n2; + p[38] = ((_BitInt(135)) 19085908020200472220560502294394961233399uwb) >> n2; + p[39] = ((_BitInt(135)) 22116103719729384017971523177401136866663uwb) >> n2; + p[40] = 42476074745096429931122498134186165182882uwb << n3; + p[41] = ((unsigned _BitInt(135)) 7182038401320930422841151460488443466941uwb) >> n3; + p[42] = ((_BitInt(135)) 19085908020200472220560502294394961233399uwb) >> n3; + p[43] = ((_BitInt(135)) 22116103719729384017971523177401136866663uwb) >> n3; + p[44] = 42476074745096429931122498134186165182882uwb << n4; + p[45] = ((unsigned _BitInt(135)) 7182038401320930422841151460488443466941uwb) >> n4; + p[46] = ((_BitInt(135)) 19085908020200472220560502294394961233399uwb) >> n4; + p[47] = ((_BitInt(135)) 22116103719729384017971523177401136866663uwb) >> n4; +} + +__attribute__((noipa)) void +check135 (void) +{ + static unsigned _BitInt(135) q[] = { + 42476074745096429931122498134186165182882uwb, + 7182038401320930422841151460488443466941uwb, + 19085908020200472220560502294394961233399uwb, + 22116103719729384017971523177401136866663uwb + }; + static unsigned _BitInt(135) e[] = { + 42476074745096429931122498134186165182882uwb, + 7182038401320930422841151460488443466941uwb, + 19085908020200472220560502294394961233399uwb, + 22116103719729384017971523177401136866663uwb, + 20575191318237441766935416597984462241792uwb, + 1633006468482774476533711881uwb, + 4339633055724441924339885712uwb, + 43556142965875248422786905315316132038280uwb, + 37177976900770126499921313117382843039744uwb, + 389339081879323596127uwb, + 1034649146967993241391uwb, + 43556142965880123322149682894823775650690uwb, + 0uwb, + 0uwb, + 0uwb, + 43556142965880123323311949751266331066367uwb, + 20575191318237441766935416597984462241792uwb, + 1633006468482774476533711881uwb, + 4339633055724441924339885712uwb, + 43556142965875248422786905315316132038280uwb, + 37177976900770126499921313117382843039744uwb, + 389339081879323596127uwb, + 1034649146967993241391uwb, + 43556142965880123322149682894823775650690uwb, + 11569600475311907757754736652680119189504uwb, + 21uwb, + 56uwb, + 43556142965880123323311949751266331066304uwb, + 0uwb, + 0uwb, + 0uwb, + 43556142965880123323311949751266331066367uwb, + 42476074745096429931122498134186165182882uwb, + 7182038401320930422841151460488443466941uwb, + 19085908020200472220560502294394961233399uwb, + 22116103719729384017971523177401136866663uwb, + 20575191318237441766935416597984462241792uwb, + 1633006468482774476533711881uwb, + 4339633055724441924339885712uwb, + 43556142965875248422786905315316132038280uwb, + 37177976900770126499921313117382843039744uwb, + 389339081879323596127uwb, + 1034649146967993241391uwb, + 43556142965880123322149682894823775650690uwb, + 0uwb, + 0uwb, + 0uwb, + 43556142965880123323311949751266331066367uwb + }; + unsigned _BitInt(135) p[48]; + test135 (p, q, 0, 42, 64, 134); + for (int i = 0; i < 48; ++i) + if (p[i] != e[i]) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 512 +__attribute__((noipa)) void +test512 (unsigned _BitInt(512) *p, unsigned _BitInt(512) *q, + int n1, int n2, int n3, int n4) +{ + p[0] = q[0] << n1; + p[1] = q[1] >> n1; + p[2] = ((_BitInt(512)) q[2]) >> n1; + p[3] = ((_BitInt(512)) q[3]) >> n1; + p[4] = q[0] << n2; + p[5] = q[1] >> n2; + p[6] = ((_BitInt(512)) q[2]) >> n2; + p[7] = ((_BitInt(512)) q[3]) >> n2; + p[8] = q[0] << n3; + p[9] = q[1] >> n3; + p[10] = ((_BitInt(512)) q[2]) >> n3; + p[11] = ((_BitInt(512)) q[3]) >> n3; + p[12] = q[0] << n4; + p[13] = q[1] >> n4; + p[14] = ((_BitInt(512)) q[2]) >> n4; + p[15] = ((_BitInt(512)) q[3]) >> n4; + p[16] = q[0] << 42; + p[17] = q[1] >> 42; + p[18] = ((_BitInt(512)) q[2]) >> 42; + p[19] = ((_BitInt(512)) q[3]) >> 42; + p[20] = q[0] << 128; + p[21] = q[1] >> 128; + p[22] = ((_BitInt(512)) q[2]) >> 128; + p[23] = ((_BitInt(512)) q[3]) >> 128; + p[24] = q[0] << 448; + p[25] = q[1] >> 448; + p[26] = ((_BitInt(512)) q[2]) >> 448; + p[27] = ((_BitInt(512)) q[3]) >> 448; + p[28] = q[0] << 508; + p[29] = q[1] >> 508; + p[30] = ((_BitInt(512)) q[2]) >> 508; + p[31] = ((_BitInt(512)) q[3]) >> 508; + p[32] = 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb << n1; + p[33] = ((unsigned _BitInt(512)) 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb) >> n1; + p[34] = ((_BitInt(512)) 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb) >> n1; + p[35] = ((_BitInt(512)) 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb) >> n1; + p[36] = 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb << n2; + p[37] = ((unsigned _BitInt(512)) 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb) >> n2; + p[38] = ((_BitInt(512)) 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb) >> n2; + p[39] = ((_BitInt(512)) 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb) >> n2; + p[40] = 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb << n3; + p[41] = ((unsigned _BitInt(512)) 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb) >> n3; + p[42] = ((_BitInt(512)) 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb) >> n3; + p[43] = ((_BitInt(512)) 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb) >> n3; + p[44] = 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb << n4; + p[45] = ((unsigned _BitInt(512)) 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb) >> n4; + p[46] = ((_BitInt(512)) 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb) >> n4; + p[47] = ((_BitInt(512)) 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb) >> n4; +} + +__attribute__((noipa)) void +check512 (void) +{ + static unsigned _BitInt(512) q[] = { + 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb, + 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb, + 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb, + 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb + }; + static unsigned _BitInt(512) e[] = { + 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb, + 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb, + 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb, + 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb, + 10218316460994285180012649605314270523237657334799736878274366250937214257494608460860805097020820895335285270507764849854590883398363325859206256763338752uwb, + 2496685507255794194454446853132278798878918827021882395199712741806282457113788753934482872466652415380931962020389152658035575413780272415995uwb, + 13407807929942476349503027617752125851028760573258773505654590291089987162470240268148950606329516537581906483867747705640627526941493352884606809182595733uwb, + 969085030254540147052327290987383773044464127243093048207926179679468140554897112278845487588172918559506186738354258875941458688582335528613uwb, + 4525270648672298630142654159362692277322833548500556080109956060745476990024701673931929946646742265188085348185747949082408104800714710883682097140072448uwb, + 32268903863189288488713934263516911045475287395472229484457927100461194379105000512730600516708300749874729300692099uwb, + 13407807929942597099574024998205846127477805162503433459831226837705045157447168014945448530707208458194409230122434920121875298152320690554956588365115043uwb, + 12525130452217498057057362011967217536814658172404918356180491125021477447649640662315333513294816018260736989782778uwb, + 837987995621412318723376562387865382967460363787024586107722590232610251879596686050117143635431464230626991136655378178359617675746660621652103062880256uwb, + 13uwb, + 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095uwb, + 5uwb, + 10218316460994285180012649605314270523237657334799736878274366250937214257494608460860805097020820895335285270507764849854590883398363325859206256763338752uwb, + 2496685507255794194454446853132278798878918827021882395199712741806282457113788753934482872466652415380931962020389152658035575413780272415995uwb, + 13407807929942476349503027617752125851028760573258773505654590291089987162470240268148950606329516537581906483867747705640627526941493352884606809182595733uwb, + 969085030254540147052327290987383773044464127243093048207926179679468140554897112278845487588172918559506186738354258875941458688582335528613uwb, + 4525270648672298630142654159362692277322833548500556080109956060745476990024701673931929946646742265188085348185747949082408104800714710883682097140072448uwb, + 32268903863189288488713934263516911045475287395472229484457927100461194379105000512730600516708300749874729300692099uwb, + 13407807929942597099574024998205846127477805162503433459831226837705045157447168014945448530707208458194409230122434920121875298152320690554956588365115043uwb, + 12525130452217498057057362011967217536814658172404918356180491125021477447649640662315333513294816018260736989782778uwb, + 2707788752018291762501261467556359376968672839961555769866726160891698235759394800413405351174494371110296852192103378240576483613979086982233831308787712uwb, + 15107256420812902421uwb, + 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569215784041721807999uwb, + 5863860707758186186uwb, + 837987995621412318723376562387865382967460363787024586107722590232610251879596686050117143635431464230626991136655378178359617675746660621652103062880256uwb, + 13uwb, + 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095uwb, + 5uwb, + 9097527363082920087640486649000739646642554439676331761072078127377091353030522027251795224024156478638697322090297961146123620822988442336252791731131761uwb, + 10980538984510266134209038127076610665614456653719209946870695541404134523537659134772423950250404838052362402691773947760040210438889408262830474547160577uwb, + 12876743501477007697566238617479065502697488744690997490715841276784967745445096442239218949897451583348811842533777310497473584791607823667593623282470690uwb, + 4262081036274094578799387151850586986318909215082769698752506214098468276589787535239660955472257640044493313997722061552113957148668088011463028119497203uwb, + 10218316460994285180012649605314270523237657334799736878274366250937214257494608460860805097020820895335285270507764849854590883398363325859206256763338752uwb, + 2496685507255794194454446853132278798878918827021882395199712741806282457113788753934482872466652415380931962020389152658035575413780272415995uwb, + 13407807929942476349503027617752125851028760573258773505654590291089987162470240268148950606329516537581906483867747705640627526941493352884606809182595733uwb, + 969085030254540147052327290987383773044464127243093048207926179679468140554897112278845487588172918559506186738354258875941458688582335528613uwb, + 4525270648672298630142654159362692277322833548500556080109956060745476990024701673931929946646742265188085348185747949082408104800714710883682097140072448uwb, + 32268903863189288488713934263516911045475287395472229484457927100461194379105000512730600516708300749874729300692099uwb, + 13407807929942597099574024998205846127477805162503433459831226837705045157447168014945448530707208458194409230122434920121875298152320690554956588365115043uwb, + 12525130452217498057057362011967217536814658172404918356180491125021477447649640662315333513294816018260736989782778uwb, + 837987995621412318723376562387865382967460363787024586107722590232610251879596686050117143635431464230626991136655378178359617675746660621652103062880256uwb, + 13uwb, + 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095uwb, + 5uwb + }; + unsigned _BitInt(512) p[48]; + test512 (p, q, 0, 42, 128, 508); + for (int i = 0; i < 48; ++i) + if (p[i] != e[i]) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test575 (unsigned _BitInt(575) *p, unsigned _BitInt(575) *q, + int n1, int n2, int n3, int n4) +{ + p[0] = q[0] << n1; + p[1] = q[1] >> n1; + p[2] = ((_BitInt(575)) q[2]) >> n1; + p[3] = ((_BitInt(575)) q[3]) >> n1; + p[4] = q[0] << n2; + p[5] = q[1] >> n2; + p[6] = ((_BitInt(575)) q[2]) >> n2; + p[7] = ((_BitInt(575)) q[3]) >> n2; + p[8] = q[0] << n3; + p[9] = q[1] >> n3; + p[10] = ((_BitInt(575)) q[2]) >> n3; + p[11] = ((_BitInt(575)) q[3]) >> n3; + p[12] = q[0] << n4; + p[13] = q[1] >> n4; + p[14] = ((_BitInt(575)) q[2]) >> n4; + p[15] = ((_BitInt(575)) q[3]) >> n4; + p[16] = q[0] << 42; + p[17] = q[1] >> 42; + p[18] = ((_BitInt(575)) q[2]) >> 42; + p[19] = ((_BitInt(575)) q[3]) >> 42; + p[20] = q[0] << 192; + p[21] = q[1] >> 192; + p[22] = ((_BitInt(575)) q[2]) >> 192; + p[23] = ((_BitInt(575)) q[3]) >> 192; + p[24] = q[0] << 512; + p[25] = q[1] >> 512; + p[26] = ((_BitInt(575)) q[2]) >> 512; + p[27] = ((_BitInt(575)) q[3]) >> 512; + p[28] = q[0] << 571; + p[29] = q[1] >> 571; + p[30] = ((_BitInt(575)) q[2]) >> 571; + p[31] = ((_BitInt(575)) q[3]) >> 571; + p[32] = 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb << n1; + p[33] = ((unsigned _BitInt(575)) 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb) >> n1; + p[34] = ((_BitInt(575)) 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb) >> n1; + p[35] = ((_BitInt(575)) 146719349625858150924070326030117352429884uwb) >> n1; + p[36] = 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb << n2; + p[37] = ((unsigned _BitInt(575)) 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb) >> n2; + p[38] = ((_BitInt(575)) 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb) >> n2; + p[39] = ((_BitInt(575)) 146719349625858150924070326030117352429884uwb) >> n2; + p[40] = 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb << n3; + p[41] = ((unsigned _BitInt(575)) 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb) >> n3; + p[42] = ((_BitInt(575)) 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb) >> n3; + p[43] = ((_BitInt(575)) 146719349625858150924070326030117352429884uwb) >> n3; + p[44] = 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb << n4; + p[45] = ((unsigned _BitInt(575)) 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb) >> n4; + p[46] = ((_BitInt(575)) 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb) >> n4; + p[47] = ((_BitInt(575)) 146719349625858150924070326030117352429884uwb) >> n4; +} + +__attribute__((noipa)) void +check575 (void) +{ + static unsigned _BitInt(575) q[] = { + 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb, + 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb, + 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb, + 146719349625858150924070326030117352429884uwb + }; + static unsigned _BitInt(575) e[] = { + 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb, + 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb, + 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb, + 146719349625858150924070326030117352429884uwb, + 101455192616810418556035937342706675871010989953664553100414183440061081538258837413103429652228409332846843840874129218733451063018756151973814520650589185972971648957022208uwb, + 9426705271486518506775721962796496212479581187376392961820308506521488593386399890224411040421708368266404866319586947893875853523246846167443285623443607687449uwb, + 123665200736549141698114476634013378335753822194910362276561280288452288465223455053720457123832123393578819366656336301874379580455931868022178318582504526998711692029382704uwb, + 33360117783071962304363825303uwb, + 119335782055317388350429004017843053262176261916736710874511715722133065797591485333905865472877802228449910525321848531626543800663717410928997924003288981168896718112030720uwb, + 6604813810288358087498962398528278947817002383742106838987637054195488521780512729133747937326520831885279330684711uwb, + 123665200736552267030251260509823595017565674550605919957029338284886722431114354919535001603397736344270114443080692270543186446588141616503700255078449149331258830163424370uwb, + 0uwb, + 15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696uwb, + 5uwb, + 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349566uwb, + 0uwb, + 101455192616810418556035937342706675871010989953664553100414183440061081538258837413103429652228409332846843840874129218733451063018756151973814520650589185972971648957022208uwb, + 9426705271486518506775721962796496212479581187376392961820308506521488593386399890224411040421708368266404866319586947893875853523246846167443285623443607687449uwb, + 123665200736549141698114476634013378335753822194910362276561280288452288465223455053720457123832123393578819366656336301874379580455931868022178318582504526998711692029382704uwb, + 33360117783071962304363825303uwb, + 119335782055317388350429004017843053262176261916736710874511715722133065797591485333905865472877802228449910525321848531626543800663717410928997924003288981168896718112030720uwb, + 6604813810288358087498962398528278947817002383742106838987637054195488521780512729133747937326520831885279330684711uwb, + 123665200736552267030251260509823595017565674550605919957029338284886722431114354919535001603397736344270114443080692270543186446588141616503700255078449149331258830163424370uwb, + 0uwb, + 71526316958236649113771106427618495658375006450241431334816139660708009688265701502532725246129480508017794237793207540593595178136921012216679830157648896249487052159057920uwb, + 3092160064277148905uwb, + 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946582933127893402865396uwb, + 0uwb, + 15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696uwb, + 5uwb, + 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349566uwb, + 0uwb, + 113324867609914841703175642134276622099380829892372739396576941405077427208321982380320777205398087845718962965838410365091485839739660235868692128339145588495862488649829794uwb, + 41459088230466967850496491762687877054451372305979858752985908904079765739347588525764439571939913205917422711129986893243036538436025937944895336127976720299879937518567087uwb, + 109919844636328732719844961828946648695154594766841929826820254974351382414676962372262457317295280532708618631627677422093887137875656283935370428037454681114775307971502401uwb, + 146719349625858150924070326030117352429884uwb, + 101455192616810418556035937342706675871010989953664553100414183440061081538258837413103429652228409332846843840874129218733451063018756151973814520650589185972971648957022208uwb, + 9426705271486518506775721962796496212479581187376392961820308506521488593386399890224411040421708368266404866319586947893875853523246846167443285623443607687449uwb, + 123665200736549141698114476634013378335753822194910362276561280288452288465223455053720457123832123393578819366656336301874379580455931868022178318582504526998711692029382704uwb, + 33360117783071962304363825303uwb, + 119335782055317388350429004017843053262176261916736710874511715722133065797591485333905865472877802228449910525321848531626543800663717410928997924003288981168896718112030720uwb, + 6604813810288358087498962398528278947817002383742106838987637054195488521780512729133747937326520831885279330684711uwb, + 123665200736552267030251260509823595017565674550605919957029338284886722431114354919535001603397736344270114443080692270543186446588141616503700255078449149331258830163424370uwb, + 0uwb, + 15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696uwb, + 5uwb, + 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349566uwb, + 0uwb + }; + unsigned _BitInt(575) p[48]; + test575 (p, q, 0, 42, 192, 571); + for (int i = 0; i < 48; ++i) + if (p[i] != e[i]) + __builtin_abort (); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + check135 (); +#endif +#if __BITINT_MAXWIDTH__ >= 512 + check512 (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + check575 (); +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-8.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-8.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,391 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +__attribute__((noipa)) void +foo (int *p) +{ + *p = 1; +} + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) void +test135 (unsigned _BitInt(135) *p, _BitInt(135) *q, int *r, int i, int j, int k) +{ + int l; + for (l = 0; l < 15; ++l) + { + r[l * 4] = p[l * 2] < p[l * 2 + 1]; + r[l * 4 + 1] = p[l * 2 + i] <= p[l * 2 + 1 + i]; + r[l * 4 + 2] = p[l * 2 + j] > p[l * 2 + 1 + j]; + r[l * 4 + 3] = p[l * 2 + k] >= p[l * 2 + 1 + k]; + } + r[60] = 0; + if (p[30] < p[31]) + foo (r + 60); + r[61] = 0; + if (p[30 + i] <= p[31 + i]) + foo (r + 61); + r[62] = 0; + if (p[30 + j] > p[31 + j]) + foo (r + 62); + r[63] = 0; + if (p[30 + k] >= p[31 + k]) + foo (r + 63); + for (l = 0; l < 15; ++l) + { + r[64 + l * 4] = q[l * 2] < q[l * 2 + 1]; + r[64 + l * 4 + 1] = q[l * 2 + i] <= q[l * 2 + 1 + i]; + r[64 + l * 4 + 2] = q[l * 2 + j] > q[l * 2 + 1 + j]; + r[64 + l * 4 + 3] = q[l * 2 + k] >= q[l * 2 + 1 + k]; + } + r[124] = 0; + if (q[30] < q[31]) + foo (r + 124); + r[125] = 0; + if (q[30 + i] <= q[31 + i]) + foo (r + 125); + r[126] = 0; + if (q[30 + j] > q[31 + j]) + foo (r + 126); + r[127] = 0; + if (q[30 + k] >= q[31 + k]) + foo (r + 127); + r[128] = p[1] > 6186175750610900443940276860313653051587uwb; + r[129] = p[1 + i] >= 6186175750610900443940276860313653051587uwb; + r[130] = p[1 + j] < 6186175750610900443940276860313653051587uwb; + r[131] = p[1 + k] <= 6186175750610900443940276860313653051587uwb; + r[132] = p[9] > 532538687817519087313655352171198726194uwb; + r[133] = p[9 + i] >= 532538687817519087313655352171198726194uwb; + r[134] = p[9 + j] < 532538687817519087313655352171198726194uwb; + r[135] = p[9 + k] <= 532538687817519087313655352171198726194uwb; + r[136] = p[26] > 21437789116019123198192600268201397321728uwb; + r[137] = p[26 + i] >= 21437789116019123198192600268201397321728uwb; + r[138] = p[26 + j] < 21437789116019123198192600268201397321728uwb; + r[139] = p[26 + k] <= 21437789116019123198192600268201397321728uwb; + r[140] = 0; + if (p[27] > 21437789116019123198192600268201397321728uwb) + foo (r + 140); + r[141] = 0; + if (p[27 + i] >= 21437789116019123198192600268201397321728uwb) + foo (r + 141); + r[142] = 0; + if (p[27 + j] < 21437789116019123198192600268201397321728uwb) + foo (r + 142); + r[143] = 0; + if (p[27 + k] <= 21437789116019123198192600268201397321728uwb) + foo (r + 143); + r[144] = q[1] > -16254965323536794558278256870539623121621wb; + r[145] = q[1 + i] >= -16254965323536794558278256870539623121621wb; + r[146] = q[1 + j] < -16254965323536794558278256870539623121621wb; + r[147] = q[1 + k] <= -16254965323536794558278256870539623121621wb; + r[148] = q[9] > 18613347261447279579326452222842126033978wb; + r[149] = q[9 + i] >= 18613347261447279579326452222842126033978wb; + r[150] = q[9 + j] < 18613347261447279579326452222842126033978wb; + r[151] = q[9 + k] <= 18613347261447279579326452222842126033978wb; + r[152] = q[26] > -17354400712967861636632104979020178784256wb; + r[153] = q[26 + i] >= -17354400712967861636632104979020178784256wb; + r[154] = q[26 + j] < -17354400712967861636632104979020178784256wb; + r[155] = q[26 + k] <= -17354400712967861636632104979020178784256wb; + r[156] = 0; + if (q[27] > -17354400712967861636632104979020178784256wb) + foo (r + 156); + r[157] = 0; + if (q[27 + i] >= -17354400712967861636632104979020178784256wb) + foo (r + 157); + r[158] = 0; + if (q[27 + j] < -17354400712967861636632104979020178784256wb) + foo (r + 158); + r[159] = 0; + if (q[27 + k] <= -17354400712967861636632104979020178784256wb) + foo (r + 159); +} + +__attribute__((noipa)) void +check135 (void) +{ + static unsigned _BitInt(135) p[] = { + 6186175750610900443940276860313653051587uwb, + 1185851028480769106318384044302924011586uwb, + 2130297273067766631305678853840898568773uwb, + 41295820948916414032635520696820459346946uwb, + 37051876633129642187163899121207069631425uwb, + 15692033609114144435279308788278869814829uwb, + 34806164389591686493621017551199759953285uwb, + 39807523118275305743074861168614282970261uwb, + 532538687817519087313655352171198726194uwb, + 532538687817519087313655352171198726194uwb - 1, + 24327491730922412594497820631861542598095uwb, + 24327491730922412594497820631861542598095uwb + 1, + 19767147107472646435672732641055578521600uwb, + 19767147107472646435672732641055578521600uwb - 18446744073709551616uwb, + 19767147107472646435672732641055578521600uwb, + 19767147107472646435672732641055578521600uwb - 1, + 19767147107472646435672732641055578521600uwb, + 19767147107472646435672732641055578521600uwb + 1, + 19767147107472646435672732641055578521600uwb, + 19767147107472646435672732641055578521600uwb, + 21437789116019123198192600268201397321728uwb, + 21437789116019123198192600268201397321728uwb - 340282366920938463463374607431768211456uwb, + 21437789116019123198192600268201397321728uwb, + 21437789116019123198192600268201397321728uwb + 340282366920938463463374607431768211456uwb, + 21437789116019123198192600268201397321728uwb, + 21437789116019123198192600268201397321728uwb - 1, + 21437789116019123198192600268201397321728uwb, + 21437789116019123198192600268201397321728uwb + 1, + 21437789116019123198192600268201397321728uwb, + 21437789116019123198192600268201397321728uwb, + 40857776145745083896508605528597836546969uwb, + 40857776145745083896508605528597836546969uwb + }; + static _BitInt(135) q[] = { + -16254965323536794558278256870539623121621wb, + 3211106991591472362840917277276886624653wb, + -11957968557477998661714306628455379156870wb, + 573207689638265971114859293369887620578wb, + 13215265693976315010419972479490962566290wb, + -14420717597022955156949317923525514408615wb, + 9945875060497908168424655458843572357117wb, + 17414314981046040218358459297638362112560wb, + 18613347261447279579326452222842126033978wb, + 18613347261447279579326452222842126033978wb - 1, + -7726660695587525737931429184041790718605wb, + -7726660695587525737931429184041790718605wb + 1, + 10658663373399224161452650292046381187072wb, + 10658663373399224161452650292046381187072wb - 18446744073709551616wb, + 10658663373399224161452650292046381187072wb, + 10658663373399224161452650292046381187072wb - 1, + 10658663373399224161452650292046381187072wb, + 10658663373399224161452650292046381187072wb + 1, + 10658663373399224161452650292046381187072wb, + 10658663373399224161452650292046381187072wb, + -17354400712967861636632104979020178784256wb, + -17354400712967861636632104979020178784256wb - 340282366920938463463374607431768211456wb, + -17354400712967861636632104979020178784256wb, + -17354400712967861636632104979020178784256wb + 340282366920938463463374607431768211456wb, + -17354400712967861636632104979020178784256wb, + -17354400712967861636632104979020178784256wb - 1, + -17354400712967861636632104979020178784256wb, + -17354400712967861636632104979020178784256wb + 1, + -17354400712967861636632104979020178784256wb, + -17354400712967861636632104979020178784256wb, + -9715765131124575245669270443035217820180wb, + -9715765131124575245669270443035217820180wb + }; + int r[160]; + static int e[160] = { + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, + 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, + }; + test135 (p, q, r, 0, 0, 0); + for (int i = 0; i < 160; ++i) + if (r[i] != e[i]) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) void +test192 (unsigned _BitInt(192) *p, _BitInt(192) *q, int *r, int i, int j, int k) +{ + int l; + for (l = 0; l < 15; ++l) + { + r[l * 4] = p[l * 2] < p[l * 2 + 1]; + r[l * 4 + 1] = p[l * 2 + i] <= p[l * 2 + 1 + i]; + r[l * 4 + 2] = p[l * 2 + j] > p[l * 2 + 1 + j]; + r[l * 4 + 3] = p[l * 2 + k] >= p[l * 2 + 1 + k]; + } + r[60] = 0; + if (p[30] < p[31]) + foo (r + 60); + r[61] = 0; + if (p[30 + i] <= p[31 + i]) + foo (r + 61); + r[62] = 0; + if (p[30 + j] > p[31 + j]) + foo (r + 62); + r[63] = 0; + if (p[30 + k] >= p[31 + k]) + foo (r + 63); + for (l = 0; l < 15; ++l) + { + r[64 + l * 4] = q[l * 2] < q[l * 2 + 1]; + r[64 + l * 4 + 1] = q[l * 2 + i] <= q[l * 2 + 1 + i]; + r[64 + l * 4 + 2] = q[l * 2 + j] > q[l * 2 + 1 + j]; + r[64 + l * 4 + 3] = q[l * 2 + k] >= q[l * 2 + 1 + k]; + } + r[124] = 0; + if (q[30] < q[31]) + foo (r + 124); + r[125] = 0; + if (q[30 + i] <= q[31 + i]) + foo (r + 125); + r[126] = 0; + if (q[30 + j] > q[31 + j]) + foo (r + 126); + r[127] = 0; + if (q[30 + k] >= q[31 + k]) + foo (r + 127); + r[128] = p[1] > 1301676158706974885001669913388788249117177822518209770103uwb; + r[129] = p[1 + i] >= 1301676158706974885001669913388788249117177822518209770103uwb; + r[130] = p[1 + j] < 1301676158706974885001669913388788249117177822518209770103uwb; + r[131] = p[1 + k] <= 1301676158706974885001669913388788249117177822518209770103uwb; + r[132] = p[9] > 4156228030920822065505406977886113255775912982125511770811uwb; + r[133] = p[9 + i] >= 4156228030920822065505406977886113255775912982125511770811uwb; + r[134] = p[9 + j] < 4156228030920822065505406977886113255775912982125511770811uwb; + r[135] = p[9 + k] <= 4156228030920822065505406977886113255775912982125511770811uwb; + r[136] = p[26] > 2105720889788939126298431571815399749254098004540680830976uwb; + r[137] = p[26 + i] >= 2105720889788939126298431571815399749254098004540680830976uwb; + r[138] = p[26 + j] < 2105720889788939126298431571815399749254098004540680830976uwb; + r[139] = p[26 + k] <= 2105720889788939126298431571815399749254098004540680830976uwb; + r[140] = 0; + if (p[27] > 2105720889788939126298431571815399749254098004540680830976uwb) + foo (r + 140); + r[141] = 0; + if (p[27 + i] >= 2105720889788939126298431571815399749254098004540680830976uwb) + foo (r + 141); + r[142] = 0; + if (p[27 + j] < 2105720889788939126298431571815399749254098004540680830976uwb) + foo (r + 142); + r[143] = 0; + if (p[27 + k] <= 2105720889788939126298431571815399749254098004540680830976uwb) + foo (r + 143); + r[144] = q[1] > 1979551028038258779576810033088645171455206196499080052958wb; + r[145] = q[1 + i] >= 1979551028038258779576810033088645171455206196499080052958wb; + r[146] = q[1 + j] < 1979551028038258779576810033088645171455206196499080052958wb; + r[147] = q[1 + k] <= 1979551028038258779576810033088645171455206196499080052958wb; + r[148] = q[9] > -1885318755168553153865626302112859755681798781213110674779wb; + r[149] = q[9 + i] >= -1885318755168553153865626302112859755681798781213110674779wb; + r[150] = q[9 + j] < -1885318755168553153865626302112859755681798781213110674779wb; + r[151] = q[9 + k] <= -1885318755168553153865626302112859755681798781213110674779wb; + r[152] = q[26] > 2339763120586619043754378424358306157273374438118242910208wb; + r[153] = q[26 + i] >= 2339763120586619043754378424358306157273374438118242910208wb; + r[154] = q[26 + j] < 2339763120586619043754378424358306157273374438118242910208wb; + r[155] = q[26 + k] <= 2339763120586619043754378424358306157273374438118242910208wb; + r[156] = 0; + if (q[27] > 2339763120586619043754378424358306157273374438118242910208wb) + foo (r + 156); + r[157] = 0; + if (q[27 + i] >= 2339763120586619043754378424358306157273374438118242910208wb) + foo (r + 157); + r[158] = 0; + if (q[27 + j] < 2339763120586619043754378424358306157273374438118242910208wb) + foo (r + 158); + r[159] = 0; + if (q[27 + k] <= 2339763120586619043754378424358306157273374438118242910208wb) + foo (r + 159); +} + +__attribute__((noipa)) void +check192 (void) +{ + static unsigned _BitInt(192) p[] = { + 1301676158706974885001669913388788249117177822518209770103uwb, + 747337726037626556190542632789198678519387021556252140610uwb, + 3725653947307680330137362665700857624320118783723331730354uwb, + 5392755653771808504964234887707929379898418126658160517063uwb, + 909108582379360036592925704487999488985548889672948755121uwb, + 1640061693011887757120264107651184372780544025461004778485uwb, + 1730451763775632602140993282640477950273220311662029360199uwb, + 5445606583665251502205919499903327925600190799372595230746uwb, + 4156228030920822065505406977886113255775912982125511770811uwb, + 4156228030920822065505406977886113255775912982125511770811uwb - 1, + 4265142937033285044176150866007262334836422938393615775285uwb, + 4265142937033285044176150866007262334836422938393615775285uwb + 1, + 5906690378849769161966354556531052466604912051358709841920uwb, + 5906690378849769161966354556531052466604912051358709841920uwb - 18446744073709551616uwb, + 5906690378849769161966354556531052466604912051358709841920uwb, + 5906690378849769161966354556531052466604912051358709841920uwb - 1, + 5906690378849769161966354556531052466604912051358709841920uwb, + 5906690378849769161966354556531052466604912051358709841920uwb + 1, + 5906690378849769161966354556531052466604912051358709841920uwb, + 5906690378849769161966354556531052466604912051358709841920uwb, + 2105720889788939126298431571815399749254098004540680830976uwb, + 2105720889788939126298431571815399749254098004540680830976uwb - 340282366920938463463374607431768211456uwb, + 2105720889788939126298431571815399749254098004540680830976uwb, + 2105720889788939126298431571815399749254098004540680830976uwb + 340282366920938463463374607431768211456uwb, + 2105720889788939126298431571815399749254098004540680830976uwb, + 2105720889788939126298431571815399749254098004540680830976uwb - 1, + 2105720889788939126298431571815399749254098004540680830976uwb, + 2105720889788939126298431571815399749254098004540680830976uwb + 1, + 2105720889788939126298431571815399749254098004540680830976uwb, + 2105720889788939126298431571815399749254098004540680830976uwb, + 3158000566128353648045936726901376808119543972196705250436uwb, + 3158000566128353648045936726901376808119543972196705250436uwb + }; + static _BitInt(192) q[] = { + 1979551028038258779576810033088645171455206196499080052958wb, + -2365185798961627132333096424325796455553365108690644933803wb, + -72665485213084327598421838628274737858136897938197299611wb, + -2684371926785696941292431816009231520283744219656369376907wb, + 2328570543620873568764731049988092721657822189058449467691wb, + 1166480801277674369406023216484203046859890984318705969207wb, + 2554342282302399647952757689834517321971737916674443522004wb, + -844209391020771146100885710857828304368226088928768368272wb, + -1885318755168553153865626302112859755681798781213110674779wb, + -1885318755168553153865626302112859755681798781213110674779wb - 1, + -2489570249266057242333359792314407344590632488455880158241wb, + -2489570249266057242333359792314407344590632488455880158241wb + 1, + -1791854374279093549336635324484455337109530403038654627840wb, + -1791854374279093549336635324484455337109530403038654627840wb - 18446744073709551616wb, + -1791854374279093549336635324484455337109530403038654627840wb, + -1791854374279093549336635324484455337109530403038654627840wb - 1, + -1791854374279093549336635324484455337109530403038654627840wb, + -1791854374279093549336635324484455337109530403038654627840wb + 1, + -1791854374279093549336635324484455337109530403038654627840wb, + -1791854374279093549336635324484455337109530403038654627840wb, + 2339763120586619043754378424358306157273374438118242910208wb, + 2339763120586619043754378424358306157273374438118242910208wb - 340282366920938463463374607431768211456wb, + 2339763120586619043754378424358306157273374438118242910208wb, + 2339763120586619043754378424358306157273374438118242910208wb + 340282366920938463463374607431768211456wb, + 2339763120586619043754378424358306157273374438118242910208wb, + 2339763120586619043754378424358306157273374438118242910208wb - 1, + 2339763120586619043754378424358306157273374438118242910208wb, + 2339763120586619043754378424358306157273374438118242910208wb + 1, + 2339763120586619043754378424358306157273374438118242910208wb, + 2339763120586619043754378424358306157273374438118242910208wb, + -3052391096360403193678321062607799919228465512652019987951wb, + -3052391096360403193678321062607799919228465512652019987951wb + }; + int r[160]; + static int e[160] = { + 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0 + }; + test192 (p, q, r, 0, 0, 0); + for (int i = 0; i < 160; ++i) + if (r[i] != e[i]) + __builtin_abort (); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + check135 (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + check192 (); +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-9.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-9.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,391 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +__attribute__((noipa)) void +foo (int *p) +{ + *p = 1; +} + +#if __BITINT_MAXWIDTH__ >= 512 +__attribute__((noipa)) void +test512 (unsigned _BitInt(512) *p, _BitInt(512) *q, int *r, int i, int j, int k) +{ + int l; + for (l = 0; l < 15; ++l) + { + r[l * 4] = p[l * 2] < p[l * 2 + 1]; + r[l * 4 + 1] = p[l * 2 + i] <= p[l * 2 + 1 + i]; + r[l * 4 + 2] = p[l * 2 + j] > p[l * 2 + 1 + j]; + r[l * 4 + 3] = p[l * 2 + k] >= p[l * 2 + 1 + k]; + } + r[60] = 0; + if (p[30] < p[31]) + foo (r + 60); + r[61] = 0; + if (p[30 + i] <= p[31 + i]) + foo (r + 61); + r[62] = 0; + if (p[30 + j] > p[31 + j]) + foo (r + 62); + r[63] = 0; + if (p[30 + k] >= p[31 + k]) + foo (r + 63); + for (l = 0; l < 15; ++l) + { + r[64 + l * 4] = q[l * 2] < q[l * 2 + 1]; + r[64 + l * 4 + 1] = q[l * 2 + i] <= q[l * 2 + 1 + i]; + r[64 + l * 4 + 2] = q[l * 2 + j] > q[l * 2 + 1 + j]; + r[64 + l * 4 + 3] = q[l * 2 + k] >= q[l * 2 + 1 + k]; + } + r[124] = 0; + if (q[30] < q[31]) + foo (r + 124); + r[125] = 0; + if (q[30 + i] <= q[31 + i]) + foo (r + 125); + r[126] = 0; + if (q[30 + j] > q[31 + j]) + foo (r + 126); + r[127] = 0; + if (q[30 + k] >= q[31 + k]) + foo (r + 127); + r[128] = p[1] > 6439347061437255154344143895240926184374246647113289384213701629724754669640618959339573646567333876513773564431668184949351528059730009728584631317244784uwb; + r[129] = p[1 + i] >= 6439347061437255154344143895240926184374246647113289384213701629724754669640618959339573646567333876513773564431668184949351528059730009728584631317244784uwb; + r[130] = p[1 + j] < 6439347061437255154344143895240926184374246647113289384213701629724754669640618959339573646567333876513773564431668184949351528059730009728584631317244784uwb; + r[131] = p[1 + k] <= 6439347061437255154344143895240926184374246647113289384213701629724754669640618959339573646567333876513773564431668184949351528059730009728584631317244784uwb; + r[132] = p[9] > 2716607166516370952811015778464637315429428288163165175168021720761495785980681441127279995453132974713988249553556243035771473482679750625718958791524521uwb; + r[133] = p[9 + i] >= 2716607166516370952811015778464637315429428288163165175168021720761495785980681441127279995453132974713988249553556243035771473482679750625718958791524521uwb; + r[134] = p[9 + j] < 2716607166516370952811015778464637315429428288163165175168021720761495785980681441127279995453132974713988249553556243035771473482679750625718958791524521uwb; + r[135] = p[9 + k] <= 2716607166516370952811015778464637315429428288163165175168021720761495785980681441127279995453132974713988249553556243035771473482679750625718958791524521uwb; + r[136] = p[26] > 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb; + r[137] = p[26 + i] >= 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb; + r[138] = p[26 + j] < 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb; + r[139] = p[26 + k] <= 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb; + r[140] = 0; + if (p[27] > 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb) + foo (r + 140); + r[141] = 0; + if (p[27 + i] >= 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb) + foo (r + 141); + r[142] = 0; + if (p[27 + j] < 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb) + foo (r + 142); + r[143] = 0; + if (p[27 + k] <= 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb) + foo (r + 143); + r[144] = q[1] > 2090630783083976726560608899307022527212315311978198188753257152565888263284874347844598962661131937985796633260411082466462809997821330828145983020205878wb; + r[145] = q[1 + i] >= 2090630783083976726560608899307022527212315311978198188753257152565888263284874347844598962661131937985796633260411082466462809997821330828145983020205878wb; + r[146] = q[1 + j] < 2090630783083976726560608899307022527212315311978198188753257152565888263284874347844598962661131937985796633260411082466462809997821330828145983020205878wb; + r[147] = q[1 + k] <= 2090630783083976726560608899307022527212315311978198188753257152565888263284874347844598962661131937985796633260411082466462809997821330828145983020205878wb; + r[148] = q[9] > -696290237363643551117711996671220443230309432588348036053438948181530078288074148843479004574555088489161912619769067173411081743987060302136728183033248wb; + r[149] = q[9 + i] >= -696290237363643551117711996671220443230309432588348036053438948181530078288074148843479004574555088489161912619769067173411081743987060302136728183033248wb; + r[150] = q[9 + j] < -696290237363643551117711996671220443230309432588348036053438948181530078288074148843479004574555088489161912619769067173411081743987060302136728183033248wb; + r[151] = q[9 + k] <= -696290237363643551117711996671220443230309432588348036053438948181530078288074148843479004574555088489161912619769067173411081743987060302136728183033248wb; + r[152] = q[26] > 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb; + r[153] = q[26 + i] >= 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb; + r[154] = q[26 + j] < 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb; + r[155] = q[26 + k] <= 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb; + r[156] = 0; + if (q[27] > 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb) + foo (r + 156); + r[157] = 0; + if (q[27 + i] >= 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb) + foo (r + 157); + r[158] = 0; + if (q[27 + j] < 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb) + foo (r + 158); + r[159] = 0; + if (q[27 + k] <= 3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb) + foo (r + 159); +} + +__attribute__((noipa)) void +check512 (void) +{ + static unsigned _BitInt(512) p[] = { + 6439347061437255154344143895240926184374246647113289384213701629724754669640618959339573646567333876513773564431668184949351528059730009728584631317244784uwb, + 6762041868534283027737681277586698577353418805123389711320743680311823204229693866395914533471197396356562852824213136960386892331859705466032560089589592uwb, + 7100250278744661687919272778464450926810863027145401799102911979534742186567792066709428057992170537490418870754413231800386208987723160090542309342698220uwb, + 7431268529135416278983437544316801791166063098864169546640210976381712748574214253654088092817057535251702063086179197094765059987561230250458545651487418uwb, + 9387962895034579582865984241538651927900235272350318828874682759815638374313243456156983345067518642781984662712425803679907225577643018022275640009873699uwb, + 3166230719682742738348931360884455391542162846555514350392658765013906649241346404508710229903813619084763077863317735446920504536945766338357887078773371uwb, + 11992372489178914246038509566828166672578807653701495597132497332700673199287169715202932677475715468669004681974601325099819634089747001502188758884172602uwb, + 7183772320147988217157628195460873099945185725664709745424293290802245140824151762181161628318220701467892891169914379357484378623421022918276231818933625uwb, + 2716607166516370952811015778464637315429428288163165175168021720761495785980681441127279995453132974713988249553556243035771473482679750625718958791524521uwb, + 2716607166516370952811015778464637315429428288163165175168021720761495785980681441127279995453132974713988249553556243035771473482679750625718958791524521uwb - 1, + 12641036253945464668613158871576838890244642877026977530604698385615142732677552062689011995329072722635530415107759810021792111602714418929346777947581722uwb, + 12641036253945464668613158871576838890244642877026977530604698385615142732677552062689011995329072722635530415107759810021792111602714418929346777947581722uwb + 1, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb - 18446744073709551616uwb, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb - 1, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb + 1, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb, + 8922448217105188951537312155524913197158477782806467330054048115953920100033906218746035610108190050394196228624539921400738404901092299164323787527159808uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb - 39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb + 39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb - 1, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb + 1, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb, + 419738665353613393951601598131892680944319219800892426789126665343642933931943588470723015570704289785844248033634460199784949778501149813068325535612928uwb, + 10128841244658791126648561211937592176780958236989426886389971194372978046367048331953118621224361972312674509897766160468914015517030880732802761461031257uwb, + 10128841244658791126648561211937592176780958236989426886389971194372978046367048331953118621224361972312674509897766160468914015517030880732802761461031257uwb + }; + static _BitInt(512) q[] = { + 2090630783083976726560608899307022527212315311978198188753257152565888263284874347844598962661131937985796633260411082466462809997821330828145983020205878wb, + 5297891122069759152190358277191301380039917110906456442739988947584072293285648331709545720897009753992228929981833882700804979946892323846480198848327132wb, + -5175455635851811471365509786771967259502175482181487858405840994248880218291771627060836702250940532261110768615360129062649520600089218199000819977507401wb, + -1197417987356054452650938717940723527397958134105969279763141389784758850378928132483783317153283733701258756175700200053452996288076889759098734389999989wb, + 376956342115769081675826480328100204258176592231230579846860212707171684351927919252138022581568644395505257039021425128449272854523981924151678168936546wb, + -3213922658862209387519332343658781663313426526489443455850614508466930839492348067449248688649920694680442694775272326426735943224604674195708324515087099wb, + -26226634446852143139032827542275726163637222096291661272058678439249826123155608154486599937246756733481215161556643451523636377101397790340001692756671wb, + 2387778007768951206967793842263829269147949222877356804856598206833350996940762526208017209413841449433410232587427590886259349063804766729190889440858025wb, + -696290237363643551117711996671220443230309432588348036053438948181530078288074148843479004574555088489161912619769067173411081743987060302136728183033248wb, + -696290237363643551117711996671220443230309432588348036053438948181530078288074148843479004574555088489161912619769067173411081743987060302136728183033248wb - 1, + 5076345582133566846688236290712078493812804531016237797772016838314392198062936803967594662767716104530499878914245621558744394736829525675805759950337585wb, + 5076345582133566846688236290712078493812804531016237797772016838314392198062936803967594662767716104530499878914245621558744394736829525675805759950337585wb + 1, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb - 18446744073709551616wb, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb - 1, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb + 1, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb, + 76333981980921012896605396538225276147251180731694673353838618004648399286703323410022822396010620396184658817947322688521663381589809974158923162189824wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb - 6277101735386680763835789423207666416102355444464034512896wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb + 6277101735386680763835789423207666416102355444464034512896wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb - 1, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb + 1, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb, + -3803169810302811951423866897603196308644585632212248377372707505362914913528085871414141191637221346044389898087027979721998214953093947532239443142377472wb, + -663334509177964622465622357697170286154368667858847871698225590542683746494347453401587549116942795508119009999390315794925881271012501058045923403034199wb, + -663334509177964622465622357697170286154368667858847871698225590542683746494347453401587549116942795508119009999390315794925881271012501058045923403034199wb + }; + int r[160]; + static int e[160] = { + 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, + 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 + }; + test512 (p, q, r, 0, 0, 0); + for (int i = 0; i < 160; ++i) + if (r[i] != e[i]) + __builtin_abort (); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test575 (unsigned _BitInt(575) *p, _BitInt(575) *q, int *r, int i, int j, int k) +{ + int l; + for (l = 0; l < 15; ++l) + { + r[l * 4] = p[l * 2] < p[l * 2 + 1]; + r[l * 4 + 1] = p[l * 2 + i] <= p[l * 2 + 1 + i]; + r[l * 4 + 2] = p[l * 2 + j] > p[l * 2 + 1 + j]; + r[l * 4 + 3] = p[l * 2 + k] >= p[l * 2 + 1 + k]; + } + r[60] = 0; + if (p[30] < p[31]) + foo (r + 60); + r[61] = 0; + if (p[30 + i] <= p[31 + i]) + foo (r + 61); + r[62] = 0; + if (p[30 + j] > p[31 + j]) + foo (r + 62); + r[63] = 0; + if (p[30 + k] >= p[31 + k]) + foo (r + 63); + for (l = 0; l < 15; ++l) + { + r[64 + l * 4] = q[l * 2] < q[l * 2 + 1]; + r[64 + l * 4 + 1] = q[l * 2 + i] <= q[l * 2 + 1 + i]; + r[64 + l * 4 + 2] = q[l * 2 + j] > q[l * 2 + 1 + j]; + r[64 + l * 4 + 3] = q[l * 2 + k] >= q[l * 2 + 1 + k]; + } + r[124] = 0; + if (q[30] < q[31]) + foo (r + 124); + r[125] = 0; + if (q[30 + i] <= q[31 + i]) + foo (r + 125); + r[126] = 0; + if (q[30 + j] > q[31 + j]) + foo (r + 126); + r[127] = 0; + if (q[30 + k] >= q[31 + k]) + foo (r + 127); + r[128] = p[1] > 20670903802240325105911328843875002676780679796965659887810279910476905646991707533359633196332088191362534479568251649420016839659631716684161458660332642627037004465943031uwb; + r[129] = p[1 + i] >= 20670903802240325105911328843875002676780679796965659887810279910476905646991707533359633196332088191362534479568251649420016839659631716684161458660332642627037004465943031uwb; + r[130] = p[1 + j] < 20670903802240325105911328843875002676780679796965659887810279910476905646991707533359633196332088191362534479568251649420016839659631716684161458660332642627037004465943031uwb; + r[131] = p[1 + k] <= 20670903802240325105911328843875002676780679796965659887810279910476905646991707533359633196332088191362534479568251649420016839659631716684161458660332642627037004465943031uwb; + r[132] = p[9] > 3090473864111819272422440709625579853033878497967848058942349684272558230226217367538319212654996864729950831478837556651015327221470111893258987353940473822396493825387378uwb; + r[133] = p[9 + i] >= 3090473864111819272422440709625579853033878497967848058942349684272558230226217367538319212654996864729950831478837556651015327221470111893258987353940473822396493825387378uwb; + r[134] = p[9 + j] < 3090473864111819272422440709625579853033878497967848058942349684272558230226217367538319212654996864729950831478837556651015327221470111893258987353940473822396493825387378uwb; + r[135] = p[9 + k] <= 3090473864111819272422440709625579853033878497967848058942349684272558230226217367538319212654996864729950831478837556651015327221470111893258987353940473822396493825387378uwb; + r[136] = p[26] > 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb; + r[137] = p[26 + i] >= 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb; + r[138] = p[26 + j] < 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb; + r[139] = p[26 + k] <= 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb; + r[140] = 0; + if (p[27] > 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb) + foo (r + 140); + r[141] = 0; + if (p[27 + i] >= 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb) + foo (r + 141); + r[142] = 0; + if (p[27 + j] < 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb) + foo (r + 142); + r[143] = 0; + if (p[27 + k] <= 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb) + foo (r + 143); + r[144] = q[1] > -16024899825125698861378150913416105280348720287461133876385645855428118759753753693038310256905822130840919293800517449664090240148479686087771461105141796446993957309177045wb; + r[145] = q[1 + i] >= -16024899825125698861378150913416105280348720287461133876385645855428118759753753693038310256905822130840919293800517449664090240148479686087771461105141796446993957309177045wb; + r[146] = q[1 + j] < -16024899825125698861378150913416105280348720287461133876385645855428118759753753693038310256905822130840919293800517449664090240148479686087771461105141796446993957309177045wb; + r[147] = q[1 + k] <= -16024899825125698861378150913416105280348720287461133876385645855428118759753753693038310256905822130840919293800517449664090240148479686087771461105141796446993957309177045wb; + r[148] = q[9] > 58304255896761105723976011538967955499349019141200282089271806304495956703405537252312168244240400239567714934306206832214441693408953280684020766705604407959670312862112067wb; + r[149] = q[9 + i] >= 58304255896761105723976011538967955499349019141200282089271806304495956703405537252312168244240400239567714934306206832214441693408953280684020766705604407959670312862112067wb; + r[150] = q[9 + j] < 58304255896761105723976011538967955499349019141200282089271806304495956703405537252312168244240400239567714934306206832214441693408953280684020766705604407959670312862112067wb; + r[151] = q[9 + k] <= 58304255896761105723976011538967955499349019141200282089271806304495956703405537252312168244240400239567714934306206832214441693408953280684020766705604407959670312862112067wb; + r[152] = q[26] > 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb; + r[153] = q[26 + i] >= 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb; + r[154] = q[26 + j] < 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb; + r[155] = q[26 + k] <= 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb; + r[156] = 0; + if (q[27] > 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb) + foo (r + 156); + r[157] = 0; + if (q[27 + i] >= 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb) + foo (r + 157); + r[158] = 0; + if (q[27 + j] < 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb) + foo (r + 158); + r[159] = 0; + if (q[27 + k] <= 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb) + foo (r + 159); +} + +__attribute__((noipa)) void +check575 (void) +{ + static unsigned _BitInt(575) p[] = { + 20670903802240325105911328843875002676780679796965659887810279910476905646991707533359633196332088191362534479568251649420016839659631716684161458660332642627037004465943031uwb, + 49836863281122150110976162564317489099243240060228310477726588559007020237654535886855965503007498301850523952960694293079759086994244623132359873685415478540406438465172529uwb, + 101667739273597064965717829455384743619074292631575734674415300078314703020971656449536574871164441895580568359346194993799527328879777131705988166820718349177377030581506226uwb, + 80233423044307189839832679537616515928636785173353789034947437038572207116613067927657166726935743880478344956088014540963626767254100174497579222671797940959076429057916182uwb, + 97607764806301954960180192904514327019672797546593465640967968069805351962335581135107484573411646213834310418744666537049560033943330633542409774950231074157796998179151769uwb, + 99099235847887185556638324204228969647146126640633556693610768362203817464971524250335424151842349844365719435719612388970493211957199457919255952798632861734037338994194966uwb, + 96074581713567517318016295073161521338909508333544695778644303001677582373061974284621003059876740600584228853347041280615851508249074891807094765318948991008650765902599128uwb, + 15041679461477111400649592642834193580709001861981524454028015552897618001389619787056916841370949982467368838858876017142572779037936015252240846631518852370288984853313032uwb, + 3090473864111819272422440709625579853033878497967848058942349684272558230226217367538319212654996864729950831478837556651015327221470111893258987353940473822396493825387378uwb, + 3090473864111819272422440709625579853033878497967848058942349684272558230226217367538319212654996864729950831478837556651015327221470111893258987353940473822396493825387378uwb - 1, + 24687788671445747328062841851441115170362216714281949080981056837718636733099501838839343860093294574222940008960321348311574274097362076438265776869659934585082628479484536uwb, + 24687788671445747328062841851441115170362216714281949080981056837718636733099501838839343860093294574222940008960321348311574274097362076438265776869659934585082628479484536uwb + 1,\ + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb - 18446744073709551616uwb, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb - 1, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb + 1, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb, + 47614907307737548529956044769514214288024476724410617147178248001248351816791887941016492346949195777207895982954879948136089705588820700968975703834863097085713265316593664uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb - 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb + 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb - 1, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb + 1, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb, + 32300371493042338295430399331232255118632292468465563882493105489267627026599093946004621996863635202389007853529819771477875971454599651226062726008225128378230201091358720uwb, + 51633735166516291946287076289285239234614696135400087552338648850396978875047534195381428791244881087469912840942965704049340728476496893527920582382910651979554452116116272uwb, + 51633735166516291946287076289285239234614696135400087552338648850396978875047534195381428791244881087469912840942965704049340728476496893527920582382910651979554452116116272uwb + }; + static _BitInt(575) q[] = { + -16024899825125698861378150913416105280348720287461133876385645855428118759753753693038310256905822130840919293800517449664090240148479686087771461105141796446993957309177045wb, + -51390644150207754083049224884205617519374685858021340086606047722946185332781222093929175551224144597441976819384400839391617209092608330883818358373143049025398242971422533wb, + -20809715567752942978812919265762383091400170370538364777815196254289178900619639932788104439550680105583194256562402043742602192720264733467556618411468069787890087436518391wb, + -43478068345605895172576873114727639397122657577727331984515310626703015763793150203012686140133812758008909595858389385754649550027270841464683283530974333174240307326289977wb, + 21067536974893828187213625307418104748755825376641087283640893104632378341787632507091012136429031707836504909794544075439508068134695815107226742106718247426895718454571312wb, + 21059037076325069627888376003421918344895371516177629929139897951865178711273978220082835739571514841970324298196012637442412751291560252279454786817442227655976906976548376wb, + 55073439925103775330639545123285198131334712919437487448183092392908579762995884122632962257443311586409720754276146674776790868518679130616646045890806469671103608966017526wb, + -3663639803402473230919436108605440689203511417836937035771974096034195998647953190615349428343475558818004598945205472788914786751065095519363354010927131384676070154882437wb, + 58304255896761105723976011538967955499349019141200282089271806304495956703405537252312168244240400239567714934306206832214441693408953280684020766705604407959670312862112067wb, + 58304255896761105723976011538967955499349019141200282089271806304495956703405537252312168244240400239567714934306206832214441693408953280684020766705604407959670312862112067wb - 1, + 19766430864130481024653308710810905134755769634549241890712862316488061577142782818791682881169095930184520701227673190291943682114543262971807474281675881316596313965163891wb, + 19766430864130481024653308710810905134755769634549241890712862316488061577142782818791682881169095930184520701227673190291943682114543262971807474281675881316596313965163891wb + 1, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb - 18446744073709551616wb, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb - 1, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb + 1, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb, + -34289018974597784349033110006663080173300111534374645051386853751555192083544833095189889341716428776365054335337832864819656266482761085202092232298171290655379977534439424wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb - 39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb + 39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb - 1, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb + 1, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb, + 5792382359367624136729259459647895570083840504542461480157806156670329217124243749211279307138790818182646144303340305156516829311465729191448709861740266920986130350342144wb, + 8558311355808808607005104837820226337084035299904651624497753594925617942910238887167551309507473356128849516219332540284243795507166584146318106852798224239555032058705368wb, + 8558311355808808607005104837820226337084035299904651624497753594925617942910238887167551309507473356128849516219332540284243795507166584146318106852798224239555032058705368wb + }; + int r[160]; + static int e[160] = { + 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0 + }; + test575 (p, q, r, 0, 0, 0); + for (int i = 0; i < 160; ++i) + if (r[i] != e[i]) + __builtin_abort (); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 512 + check512 (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + check575 (); +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-10.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-10.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,38 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) void +test135 (_BitInt(135) *p) +{ + *p = 18514202188641047858083570207027263585014wb; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 512 +__attribute__((noipa)) void +test512 (_BitInt(512) *p) +{ + *p = -3850276968594657220525735372507394006353780328347442833283734788531702263728014201878916354908375176401574990646289191313473197873422312093114382157952958wb; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + _BitInt(135) b135; + test135 (&b135); + if (b135 != 18514202188641047858083570207027263585014wb) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 512 + _BitInt(512) b512; + test512 (&b512); + if (b512 != -3850276968594657220525735372507394006353780328347442833283734788531702263728014201878916354908375176401574990646289191313473197873422312093114382157952958wb) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-11.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-11.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,77 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && int32plus } } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#ifdef __SIZEOF_INT128__ +#define int128_val(x, y) x +#define int128_bitfld(x) x +#define int128 __int128 +#else +#define int128_val(x, y) y +#define int128_bitfld(x) 1 +#define int128 int +#endif + +struct S { + int i : 1; + int j : 27; + long long k : 56; + int128 l : int128_bitfld (120); + unsigned m : 3; + unsigned long long n : 42; + unsigned int128 o : int128_bitfld (125); +}; + +#if __BITINT_MAXWIDTH__ >= 188 +__attribute__((noipa)) _BitInt(188) +test188 (int a, long long b, int128 c, unsigned short d, + unsigned long long e, unsigned int128 f, _BitInt(188) *g, + struct S *p) +{ + return *g + a + b + c + d + e + f + p->i + p->j + p->k + p->l + p->m + p->n + p->o; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +test575 (int a, long long b, int128 c, unsigned short d, + unsigned long long e, unsigned int128 f, _BitInt(575) *g, + struct S *p) +{ + return *g + a + b + c + d + e + f + p->i + p->j + p->k + p->l + p->m + p->n + p->o; +} +#endif + +int +main () +{ + struct S s = { -1, 34877496, -5580713461260169LL, + int128_val (329913978417840804084945075673166782wb, 0), + 1U, 68262565354ULL, + int128_val (5169264897230903304574466460949339423uwb, 0) }; + (void) &s; +#if __BITINT_MAXWIDTH__ >= 188 + _BitInt(188) b188 = 51625354135609169507415940782602403562057573230992065937wb; + if (test188 (-943502954, 6037882847713389759LL, + int128_val (-83021930809076074533830959108195408798wb, 0), + 55564, 16536837072610496559ULL, + int128_val (237527410537432634851289433535592281366uwb, 0), + &b188, &s) + != int128_val (51625354135609169667420599386607708010744598469228066319wb, + 51625354135609169507415940782602403584626712505208687546wb)) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + _BitInt(575) b575 = -20179593413257295974034559327597105210986698104682733481090257927308152867107766179792744096926808179875378122328280563720406829353405990702024578604764643194143342705864832wb; + if (test575 (-943502954, 6037882847713389759LL, + int128_val (-83021930809076074533830959108195408798wb, 0), + 55564, 16536837072610496559ULL, + int128_val (237527410537432634851289433535592281366uwb, 0), + &b575, &s) + != int128_val (-20179593413257295974034559327597105210986698104682733481090257927308152867107766179792744096926808179875378122328280563720406829353405830697365974599460194507118104469864450wb, + -20179593413257295974034559327597105210986698104682733481090257927308152867107766179792744096926808179875378122328280563720406829353405990702024578604764620625004068489243223wb)) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-12.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-12.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,128 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && int32plus } } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#ifdef __SIZEOF_INT128__ +#define int128_val(x, y) x +#define int128 __int128 +#else +#define int128_val(x, y) y +#define int128 int +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test575 (_BitInt(575) *a, int b, int128 c, unsigned int d, unsigned int128 e, + int f, int g, int128 h, unsigned int i, unsigned int128 j, + _BitInt(575) *p, int *r) +{ + r[0] = *a > b; + r[1] = *a >= c; + r[2] = *a < d; + r[3] = *a <= e; + p[0] = ((_BitInt(575)) g) << f; + p[1] = ((_BitInt(575)) h) << f; + p[2] = ((_BitInt(575)) i) << f; + p[3] = ((_BitInt(575)) j) << f; + p[4] = ((unsigned _BitInt(575)) g) >> f; + p[5] = ((unsigned _BitInt(575)) h) >> f; + p[6] = ((unsigned _BitInt(575)) i) >> f; + p[7] = ((unsigned _BitInt(575)) j) >> f; +} + +_BitInt(575) a575 = -37335077053906536248085160049937130279057714970866686325204063930452920311842187828021093674979068589644104434897698233644810906211958229904753029173357201859433853689386323wb; +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 575 + int r[12]; + _BitInt(575) b575[24]; + int er[12] = { +#ifdef __SIZEOF_INT128__ + 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 +#else + 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1 +#endif + }; + static _BitInt(575) eb575[24] = { +#ifdef __SIZEOF_INT128__ + 20329374714419634196895318109902140892207297977139593216wb, + -1712803473999893185713719997722323414959591613021414111612885795955340439235139207168wb, + 24459948786509903061037979887398299261116601758241521664wb, + 266261172647138617905132542512773540174694514212873439044818615992883558384930914304wb, + 0wb, + 10830740992659433045228180406808920716548582325686783496759685861775864483615725089999900023844295226942934417817982702456930303wb, + 0wb, + 0wb, + 7830590302633896968192wb, + -659747899885375730707839505890120862245951494946816wb, + 9421629561223530938368wb, + 102560073085756776493593811652595116491535756034048wb, + 0wb, + 28118211215894977392565865673037386617935606989386978956879722328823984879196799189494004288149317857187005691459505594520051662846839338948136222520490158359458wb, + 0wb, + 5302231504909973601023497wb, + 1780470098wb, + -150009304862891379049833518795394607479wb, + 2142230542wb, + 23319460771235020841594135084186545212wb, + 1780470098wb, + -150009304862891379049833518795394607479wb, + 2142230542wb, + 23319460771235020841594135084186545212wb +#else + 20329374714419634196895318109902140892207297977139593216wb, + 479555224749202520035584085735030365824602865664wb, + 24459948786509903061037979887398299261116601758241521664wb, + 171269723124715185726994316333939416365929594880wb, + 0wb, + 0wb, + 0wb, + 0wb, + 7830590302633896968192wb, + 184717953466368wb, + 9421629561223530938368wb, + 65970697666560wb, + 0wb, + 0wb, + 0wb, + 0wb, + 1780470098wb, + 42wb, + 2142230542wb, + 15wb, + 1780470098wb, + 42wb, + 2142230542wb, + 15wb +#endif + }; + test575 (&a575, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42), + 2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15), + 153, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42), + 2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15), + &b575[0], &r[0]); + a575 = 1780470099wb; + test575 (&a575, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42), + 2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15), + 42, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42), + 2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15), + &b575[8], &r[4]); + a575 = -150009304862891379049833518795394607478wb; + test575 (&a575, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42), + 2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15), + 0, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42), + 2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15), + &b575[16], &r[8]); + for (int i = 0; i < 12; ++i) + if (r[i] != er[i]) + __builtin_abort (); + for (int i = 0; i < 24; ++i) + if (b575[i] != eb575[i]) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-13.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-13.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,171 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && int32plus } } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ * __CHAR_BIT__ == 128 +#define int128_val(x, y) x +#define int128_bitfld(x) x +#define int128 __int128 +#else +#define int128_val(x, y) y +#define int128_bitfld(x) 1 +#define int128 int +#endif +#if __SIZEOF_SHORT__ * __CHAR_BIT__ == 16 +#define shrt_val(x, y) x +#else +#define shrt_val(x, y) y +#endif +#if __SIZEOF_INT__ * __CHAR_BIT__ == 32 +#define int_val(x, y) x +#else +#define int_val(x, y) y +#endif +#if __SIZEOF_LONG_LONG__ * __CHAR_BIT__ == 64 +#define llong_val(x, y) x +#else +#define llong_val(x, y) y +#endif + +struct S { + int i : 1; + int j : 27; + long long k : 56; + int128 l : int128_bitfld (120); + unsigned m : 3; + unsigned long long n : 42; + unsigned int128 o : int128_bitfld (125); +}; + +#if __BITINT_MAXWIDTH__ >= 188 +__attribute__((noipa)) void +test188 (int *a, long long *b, int128 *c, unsigned short *d, + unsigned long long *e, unsigned int128 *f, _BitInt(188) *g, + struct S *p) +{ + *a = g[0] + g[1]; + *b = (_BitInt(188)) ((unsigned _BitInt(188)) g[2] - g[3]); + *c = g[4]; + *d = (_BitInt(188)) ((unsigned _BitInt(188)) g[5] << 3); + *e = (unsigned _BitInt(188)) g[6]; + *f = -g[7]; + p->i = g[8] | 256wb; + p->j = g[9] ^ 513wb; + p->k = g[10] & g[11]; + p->l = g[12]; + p->m = (g[13] | g[14]) + g[15]; + p->n = g[16]; + p->o = g[17]; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test575 (int *a, long long *b, int128 *c, unsigned short *d, + unsigned long long *e, unsigned int128 *f, _BitInt(575) *g, + struct S *p) +{ + *a = g[0] + g[1]; + *b = g[2] - g[3]; + *c = g[4]; + *d = g[5] << 3; + *e = (unsigned _BitInt(575)) g[6]; + *f = -g[7]; + p->i = g[8] | 256wb; + p->j = g[9] ^ 513wb; + p->k = g[10] & g[11]; + p->l = g[12]; + p->m = (g[13] | g[14]) + g[15]; + p->n = g[16]; + p->o = g[17]; +} +#endif + +int +main () +{ + struct S s; + int a; + long long b; + int128 c; + unsigned short d; + unsigned long long e; + unsigned int128 f; + (void) &s; +#if __BITINT_MAXWIDTH__ >= 188 + _BitInt(188) g188[18] = { + -159047363318536960484353065517373654721104396757490314295wb, + -3121544831087579708485147608149039646353048280619431708wb, + 159318071862725567512368472768918962735450536041547197357wb, + -40707507555068524326919847225737421498619613998666182429wb, + 165320903343659124097264390671505112912629878959843721491wb, + -127515148002861399222757129930766493340235768486498578219wb, + -105034079444454534611827588421185078564296081131064901461wb, + 92590184827335405203162269451222486819220604151446603018wb, + -180312039117739394533672196677501644999924031772292123301wb, + -144189136904129889279453036150725630022817508409138149279wb, + -149481812493652088098408785514342084106630686193276241281wb, + -167177289711809249257738519322903628222027157941774765457wb, + -143084017548841355414802324960482130843700645074551425158wb, + 58479706299212198491939673148493577279739517540183806582wb, + -56927106028567263826833143638316408260616106349933917222wb, + -51398435670153923584906245550632035515359744807385001406wb, + 42134285326135692487901360354060672379510798359809381879wb, + 88023866651707391895300914626945857947221302817073781445wb + }; + test188 (&a, &b, &c, &d, &e, &f, &g188[0], &s); + if (a != int_val (0x07181cad, (int) 230149950312043007546898625824956456638939770240892411053uwb) + || b != llong_val ((long long) 0xde59a69b154ddacaLL, (long long) 200025579417794091839288319994656384234070150040213379786uwb) + || c != int128_val ((int128) 0xd1d8047ea714e976fb0ddacd903a4113uwb, int_val ((int) 0x903a4113, (int) 165320903343659124097264390671505112912629878959843721491uwb)) + || d != shrt_val (0x86a8, (unsigned short) 156835391362111449437153477405305506297305497945017845416uwb) + || e != llong_val (0xf4603045301e40abULL, (unsigned long long) 287284779017213013127909250529294072442101134147937255595uwb) + || f != int128_val ((unsigned int128) 0x36333fc0e67c1648df996844ae607af6uwb, int_val ((unsigned) 0xae607af6, (unsigned) 299728673634332142536574569499256664187176611127555554038uwb)) + || s.i != -1 + || s.j != 0x3150a60 + || s.k != 0x0501922b16326fLL + || s.l != int128_val ((int128) 0xffa05b2a80ae9f589ff82df4ec30377auwb, 0) + || s.m != 0 + || s.n != 0xbea55655f7ULL + || s.o != int128_val ((unsigned int128) 0x11424021a09eb39f0078be56f505dac5uwb, 1)) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + _BitInt(575) g575[18] = { + -47005092370981353509019585272930171576138837874594474940633343041444523868768398171568402914237822300343064860032430047905208253183368063860751727493912961793713775785286761wb, + 42995314282090421850185028248818616047989631648441809220202839707075135953582887789310579563290411495625582960818510026163313766713468119555853185204024156985186870447558448wb, + -4310949275737056279952323703666519147345926215446595910688661460043187233007608392215115192894183359414559767132447689960645444722310313612870802800517291553651832872230377wb, + -60174333254167907860375485189824486743221145295071697779574672977710903042875235567137515476943834663106195143844820080789913163377976708972634731997186324672887273760550843wb, + 514999616465082372590625134373624423612122508361343296847148750502235576952627411211915080142588943086581680871086375952582973053262315744074678352482468176498475765238014wb, + -34524529098838981071360498102806028847960079898011114995185678340915753622610778619950150604678383174181175565220899355393832542080300168653321490778607415279583262404019715wb, + 57435829357765689198701253918538231677782825819649130906117703766412930883719480639328241453985120284446411689340430788174994800799501628170332549761733355178989958217690176wb, + 55372038211321583831991526729411129160052836002754320808356246247126956944240411995457998940239431679806969029801755058644044152079840612142503912508386823751242378280351248wb, + 16465587034692152401588675199252528652333806863385560487958043658459465122879621696065063317705307064863781999117926295249319492796685349901264833471330673488325230233633156wb, + 29447367895156340838084654771430520820905636269084897202980661633115991361986283452296000775941804019961160709602424696981982973428884144037654036591675815222144356989137377wb, + -11405270033186719236304815495700559798454505639686440514251001395033465367140240658561115444561532342526965619895711017904459977515469290641005572154684851264335049868864497wb, + 108093905149568033165371492635656748567249268116953654298668927833251941040419562425217780888127352768755220577595921193600804563557700826867049089803222938826670338302530wb, + -31360750000107936163671456129190056884574874172627927813113803212980739137815442376155550405060248732467083955605320651972161402853892464960579922753500965033770359737153351wb, + -8682946747028473458400698043390376356896046446946536663094478822504353095327345833145506855874926356083877643554724567774187375944555393553847900623220497209797513931185240wb, + -22144855016132297032977142230889176517935104503579623594553342478323802903759572545707546713930097548953805249628758279309623598839610808070152925878316419950140234764905470wb, + -10411562563660012059020319572234253583259323305689321838048522585769451002745393609294442107707749261789472265492124615971403756074402546875951159988775650555291608910079211wb, + -35303144058707185327630269206553728380732193353770095499658757423571059983534369285427585500543929872684039303017125049206013674506050937891922504600168970885730004765890909wb, + -10288638308173362696633233706439807781761277611815792314525923347956953720054374840733498198399501888078817738532473821245337293721068994241744635656437058172223152460622488wb + }; + test575 (&a, &b, &c, &d, &e, &f, &g575[0], &s); + if (a != int_val (-0x2a104d39, (int) -4009778088890931658834557024111555528149206226152665720430503334369387915185510382257823350947410804717481899213920021741894486469899944304898542289888804808526905337728313wb) + || b != llong_val ((long long) 0xf6c7e117bacd11d2LL, (long long) 55863383978430851580423161486157967595875219079625101868886011517667715809867627174922400284049651303691635376712372390829267718655666395359763929196669033119235440888320466uwb) + || c != int128_val ((int128) 0x75504b73f68a3225400491eb337288feuwb, int_val ((int) 0x337288fe, (int) 514999616465082372590625134373624423612122508361343296847148750502235576952627411211915080142588943086581680871086375952582973053262315744074678352482468176498475765238014uwb)) + || d != shrt_val (0xcfe8, (unsigned short) 94799369418944952519869796707022554269016384467728839909609157412019808678911571795873396754437502090947102617257014165876387214817725465724747306423980429638244058990890984uwb) + || e != llong_val (0xa6a61a4adeb96c40ULL, (unsigned long long) 57435829357765689198701253918538231677782825819649130906117703766412930883719480639328241453985120284446411689340430788174994800799501628170332549761733355178989958217690176uwb) + || f != int128_val ((unsigned int128) 0xd2a8d84eae8410641083c38afaa549f0uwb, int_val ((unsigned) 0xfaa549f0, (unsigned) 68293162525230683198259733780412465857512838547851599148675281799321655609025521589700201590382090814991866683206314611031638365073534992841269165042559760207061007793998320uwb)) + || s.i != 0 + || s.j != -0x2920c20 + || s.k != -0x1bddffff3afffeLL + || s.l != int128_val ((int128) 0xffb52493069ee4e254bf24bbba7a08b9uwb, -1) + || s.m != 7 + || s.n != 0x1cbf11e26a3ULL + || s.o != int128_val ((unsigned int128) 0x12a63362222ec8f7f2c7e52793b49568uwb, 0)) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-14.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-14.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,140 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 256 +__attribute__((noipa)) void +test256 (_BitInt(256) *p, _BitInt(256) *q, unsigned n) +{ + _BitInt(256) x = q[0], y; + unsigned _BitInt(256) z; + p[0] = x >= 0 ? x : -x; + x = q[1]; + p[1] = (_BitInt(256)) (-(_BitInt(256)) (x < 0) | 1) * (unsigned _BitInt(256)) x; + x = q[2]; + y = q[3]; + p[2] = x > y ? x : y; + p[3] = x < y ? x : y; + z = q[4]; + p[4] = (z << n) | (z >> (-n) % 256); + z = q[5]; + p[5] = (z >> n) | (z << (-n) % 256); + z = q[6]; + p[6] = (z << 42) | (z >> (256 - 42)); + p[7] = (z << 196) | (z >> (256 - 196)); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test575 (_BitInt(575) *p, _BitInt(575) *q, unsigned n) +{ + _BitInt(575) x = q[0], y; + + p[0] = x >= 0 ? x : -x; + x = q[1]; + p[1] = (_BitInt(575)) (-(_BitInt(575)) (x < 0) | 1) * (unsigned _BitInt(575)) x; + x = q[2]; + y = q[3]; + p[2] = x > y ? x : y; + p[3] = x < y ? x : y; + x = q[4]; + p[4] = (x << n) | (x >> (-n) % 575); + x = q[5]; + p[5] = (x >> n) | (x << (-n) % 575); + x = q[6]; + p[6] = (x << 42) | (x >> (575 - 42)); + p[7] = (x << 196) | (x >> (575 - 196)); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 256 + _BitInt(256) p256[16]; + static _BitInt(256) q256[14] = { + 45345032714412617256156490782169070529322290545773058110333871537162440472587wb, + -57896044618658097711785492504343953926634992332820282019728792003956564819968wb, + 56362660930901219937245963089077503913881996661810533276822951833224961233515wb, + 51868771107222588126287278424861243128427600270521502351207927942060821222194wb, + -19284414951568262238262918143892955489617856897512953183940840506431869697041wb, + 2658782266882101281962762454025964999131551132761759005892140732613414118676wb, + 54220248433725687265393292224175077483742748899396150017145360542924235344802wb, + -37463226851796965187185951868838571299559805464590722337979740082646767802569wb, + -40419708661355022203345898421408637080086749636846240100217688555626587286030wb, + -55754487912560053024413264564540814098917966752804384445133242149913646068176wb, + 26265770627437470876117322526967897715823682246510518833106882615653395455635wb, + -52596268389191266164863111650546248051760002564726896605115288580144402763386wb, + -44308970341715903069333400701791033613751134794232782967956437254511180029758wb, + 4750616739884184263118039796682749720523215747547537773188931304361332774085wb + }; + static const _BitInt(256) r256[16] = { + 45345032714412617256156490782169070529322290545773058110333871537162440472587wb, + -57896044618658097711785492504343953926634992332820282019728792003956564819968wb, + 56362660930901219937245963089077503913881996661810533276822951833224961233515wb, + 51868771107222588126287278424861243128427600270521502351207927942060821222194wb, + 28504845637216227099157296646299447493773190228564580204434798695467761710135wb, + 13952419655888133019367679114949332038269119423004786217260238955159715384317wb, + 55062854366581286125448024237607745201868855087201663327097902939898842371913wb, + -48537283185021244092191938290513862066611838578912383503471331209866218456054wb, + 37463226851796965187185951868838571299559805464590722337979740082646767802569wb, + 40419708661355022203345898421408637080086749636846240100217688555626587286030wb, + 26265770627437470876117322526967897715823682246510518833106882615653395455635wb, + -55754487912560053024413264564540814098917966752804384445133242149913646068176wb, + -52596268389191266164863111650546248051760002564726896605115288580144402763386wb, + -44308970341715903069333400701791033613751134794232782967956437254511180029758wb, + -18143335929783282380882063933743228881911720395868748284571317433159558897346wb, + 29051936395101664965352348496634886321943246606527498619351354372469657269685wb + }; + test256 (p256, q256, 31); + test256 (p256 + 8, q256 + 7, 0); + for (int i = 0; i < 16; ++i) + if (p256[i] != r256[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + _BitInt(575) p575[16]; + static _BitInt(575) q575[14] = { + -22872451846054556417350916741013404184330732279497241442289048103235716890482482649099537178446621346041121532737887637378213104798444471078041166778940100084060290561371455wb, + 17785619680254441647827488871998638273432777299970128558821267200272839955229298488625220894043625699693270092672797162273950619203800446486815325568472958573446749051572825wb, + -734234098097989409262727998397700256489421637915860389242752385873657556883074595636809785650192226409399868870242355685621686958186408269916495700324885703256092385869434wb, + 38120499666250922171546613830180673200675976218799529299148065967941552755802535392332731940070002883710338820964987361658591561975335652756278138538832118604974787875400446wb, + 5684104948137619484333794789281535519196217253613879268155482366016410402198153437845962821374710383639946025491278662358930601323825409782517946368713730166779501012971475wb, + 32087820847816972971171692099083158156912701591228441301893931157856913053317602595432786417564970426631926727346659054532034068327088444234192931989166459782227197939321057wb, + -21721263360652995330393989849576970088245889949682845009460695472717466152081539971263312012527739590286540576183877575156900293418340395132947924863443109127173995560078279wb, + -15480195498062309558312832142884391233286002177523144097946171600675924728664105138320506609593544010951582863517501340004263677508611453722210182190275179605668158636665993wb, + 55995880469793772523539449728006933885804379190436425191858349409824731357990351725719664053451797096177518772823017250471021319053248877819795135618917529149253258308759354wb, + 24370295507731130004798276928243731386820125439099070643489522771145691875100529624831680686321147169119505764999828531144118172785865370931653507615753544737698580795350286wb, + -13016142173054302003336690685586422149429100823007010246177815738538602088089262263144796610097444570064192302085091825355979550567585055268099892750197109319237803857300389wb, + -35368478429854967484145020710656986046297257815593959870285507974957270671233443946755652228033821286859588583452449353741836352125387357246827468277473775502648515381353900wb, + 58764573942155814375791739663233093461596472170763698081763161612851239717416911428930198048960628406552049393162750872881771056037803284665755551481777372772007145066447638wb, + 44433183924809544824417284909271563263644800797277575618994531425499154930034075648536496209651260196970467671003251328672885483954369513730487082628591112972000580073953662wb, + }; + static const _BitInt(575) r575[16] = { + 22872451846054556417350916741013404184330732279497241442289048103235716890482482649099537178446621346041121532737887637378213104798444471078041166778940100084060290561371455wb, + 17785619680254441647827488871998638273432777299970128558821267200272839955229298488625220894043625699693270092672797162273950619203800446486815325568472958573446749051572825wb, + 38120499666250922171546613830180673200675976218799529299148065967941552755802535392332731940070002883710338820964987361658591561975335652756278138538832118604974787875400446wb, + -734234098097989409262727998397700256489421637915860389242752385873657556883074595636809785650192226409399868870242355685621686958186408269916495700324885703256092385869434wb, + 21703548306654828422881171931811440617567232925929621047938944826274955122606664179955511692787137409674737460976041867927943552583691691300165016729177283086471793752300456wb, + 26132710036535820372804820434723627712036525396244440920377271153766059995978577234280974829431879549681083853195499953729715766325604759212344321343859158691727036603084808wb, + -772498050957wb, + -17640736973552882046941821064235973435654602283914963062775wb, + 15480195498062309558312832142884391233286002177523144097946171600675924728664105138320506609593544010951582863517501340004263677508611453722210182190275179605668158636665993wb, + 55995880469793772523539449728006933885804379190436425191858349409824731357990351725719664053451797096177518772823017250471021319053248877819795135618917529149253258308759354wb, + 24370295507731130004798276928243731386820125439099070643489522771145691875100529624831680686321147169119505764999828531144118172785865370931653507615753544737698580795350286wb, + -13016142173054302003336690685586422149429100823007010246177815738538602088089262263144796610097444570064192302085091825355979550567585055268099892750197109319237803857300389wb, + -35368478429854967484145020710656986046297257815593959870285507974957270671233443946755652228033821286859588583452449353741836352125387357246827468277473775502648515381353900wb, + 58764573942155814375791739663233093461596472170763698081763161612851239717416911428930198048960628406552049393162750872881771056037803284665755551481777372772007145066447638wb, + -49246536424904916635319663180286717016047461257207957146338535716423124695209459892760482984419623560832895613229564098885770525356171820890930378678203734061651571774762747wb, + -24090226615157470281984717279507286428793968193916029900229071481754838071202669524668562579828294907607719783763180294251525168293397875645175326412340936012077133238990588wb + }; + test575 (p575, q575, 31); + test575 (p575 + 8, q575 + 7, 0); + for (int i = 0; i < 16; ++i) + if (p575[i] != r575[i]) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-15.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-15.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,264 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) void +test135_171_192 (_BitInt(135) *p, _BitInt(171) *q, _BitInt(192) *r, + unsigned _BitInt(135) *s, unsigned _BitInt(171) *t, + unsigned _BitInt(192) *u, int n) +{ + p[5] = q[0]; + q[5] = p[0] + p[1]; + p[6] = r[0]; + r[5] = p[1]; + q[6] = r[1] + r[0]; + r[6] = q[1]; + p[7] = (unsigned _BitInt(135)) t[0] + (_BitInt(135)) t[1]; + q[7] = s[0]; + p[8] = u[0]; + r[7] = s[1]; + q[8] = u[1]; + r[8] = t[1]; + s[5] = q[2] - q[3]; + t[5] = p[2]; + s[6] = r[2]; + u[5] = p[3]; + t[6] = r[3]; + u[6] = q[3]; + s[7] = t[2]; + t[7] = s[2]; + s[8] = u[2]; + u[7] = s[3]; + t[8] = u[3]; + u[8] = t[3]; + u[9] = ((_BitInt(171)) (p[2] + p[3]) + q[2]) + u[2]; + p[9] = q[4] < p[4]; + q[9] = t[4] >= u[4]; + s[9] = ((_BitInt(171)) p[4]) << n; + t[9] = ((_BitInt(171)) s[4]) >> n; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test522_547_575 (_BitInt(522) *p, _BitInt(547) *q, _BitInt(575) *r, + unsigned _BitInt(522) *s, unsigned _BitInt(547) *t, + unsigned _BitInt(575) *u, int n) +{ + p[5] = q[0]; + q[5] = p[0] + p[1]; + p[6] = r[0]; + r[5] = p[1]; + q[6] = r[1] + r[0]; + r[6] = q[1]; + p[7] = (unsigned _BitInt(522)) t[0] + (_BitInt(522)) t[1]; + q[7] = s[0]; + p[8] = u[0]; + r[7] = s[1]; + q[8] = u[1]; + r[8] = t[1]; + s[5] = q[2] - q[3]; + t[5] = p[2]; + s[6] = r[2]; + u[5] = p[3]; + t[6] = r[3]; + u[6] = q[3]; + s[7] = t[2]; + t[7] = s[2]; + s[8] = u[2]; + u[7] = s[3]; + t[8] = u[3]; + u[8] = t[3]; + u[9] = ((_BitInt(547)) (p[2] + p[3]) + q[2]) + u[2]; + p[9] = q[4] < p[4]; + q[9] = t[4] >= u[4]; + s[9] = ((_BitInt(547)) p[4]) << n; + t[9] = ((_BitInt(547)) s[4]) >> n; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 192 + static _BitInt(135) p135[15] = { + -21017626881393060962682831099345275646127wb, + 3694296893212130938499913614460066245857wb, + -346978153630491292366720842786572608600wb, + -12051883812785324688960115817645360041052wb, + 894554736479161756765856528934783wb, + 0, 0, 0, 0, 0, + -10126751695395432170173641758862456728384wb, + 5972941260331487493885375988782293547456wb, + 1994359513041991206938472369666304432410wb, + -6563811307898601259032789037472160962572wb, + 0wb + }; + static _BitInt(171) q171[15] = { + -625366993761622480400669212262678861717858330946368wb, + 824211109381944261174032176940659654188131012437179wb, + 546292738086463798921197562372110173424343217923278wb, + 511148834019524346739032507408677732131367119592267wb, + 347611384453999342493570524785293850801864814800614wb, + 0, 0, 0, 0, 0, + -17323329988180930024182917484885209400270wb, + -1427703038865092853121951937517407564490420667866520wb, + 38147269358417182782171905780014948953272wb, + 467958077036848086326034408503276340843337835865495wb, + 0wb + }; + static _BitInt(192) r192[15] = { + 1392184189278706283348529493736576751111606618688367065536wb, + 1141852629791713898948497335488732622599274881068663548072wb, + -2714462128387415582772926191122594432964111301268533078042wb, + 2425769388758313376333650042373508250767256770936531653671wb, + 2720431110756499648348639705956093809255126267584967484234wb, + 0, 0, 0, 0, 0, + 3694296893212130938499913614460066245857wb, + 824211109381944261174032176940659654188131012437179wb, + 24158489198104933635096197097903724015499wb, + 606766803137851050688065717544996275384988908585315wb, + 0wb + }; + static unsigned _BitInt(135) s135[15] = { + 38147269358417182782171905780014948953272uwb, + 24158489198104933635096197097903724015499uwb, + 15056704170354189252536066857287800623071uwb, + 25206995790075003034339862074263410882988uwb, + 19207954769547491779143235037830592504231uwb, + 0, 0, 0, 0, 0, + 31754930256886813275958100253331871451523uwb, + 15245728220153286789447947809930478163942uwb, + 9156112246512545688879043617340759142722uwb, + 40264644850602433398431024975343109499285uwb, + 41168227647461841063600478959378800574464uwb + }; + static unsigned _BitInt(171) t171[15] = { + 485349495244621624686447991535899196145754495768503uwb, + 606766803137851050688065717544996275384988908585315uwb, + 333199438528630292656855934377866394553406065406274uwb, + 2139385105954223838532102833374805075850015235549769uwb, + 1678008128571185237771726930519720682651619103697237uwb, + 0, 0, 0, 0, 0, + 2993155353253342198327516046110580903412563275406248uwb, + 2550578100027524622604893738184060999550811074270247uwb, + 15056704170354189252536066857287800623071uwb, + 699234106698292061166730462199993896682394735156989uwb, + 4367383273699372643737486905uwb + }; + static unsigned _BitInt(192) u192[15] = { + 4671639464410605725298192070070307015392908693211956881396uwb, + 715636974522854835742140132808616653707176693849553888663uwb, + 457579096729186368426895847730802215502050535098936945045uwb, + 1103175995161405903311011421434916994075193954478175624957uwb, + 5439093776557462873830329048469734037495210381156250832820uwb, + 0, 0, 0, 0, 0, + 6277101735386680751783905610422341727142239626818674471844uwb, + 511148834019524346739032507408677732131367119592267uwb, + 25206995790075003034339862074263410882988uwb, + 2139385105954223838532102833374805075850015235549769uwb, + 457579643021924442491832802512548606285387299010222218671uwb + }; + test135_171_192 (p135, q171, r192, s135, t171, u192, 42); + for (int i = 5; i < 10; ++i) + if (p135[i] != p135[i + 5] + || q171[i] != q171[i + 5] + || r192[i] != r192[i + 5] + || s135[i] != s135[i + 5] + || t171[i] != t171[i + 5] + || u192[i] != u192[i + 5]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _BitInt(522) p522[15] = { + 1688583697238081957015024340932764748327491668109158685467058555721380506305071231550264349039164029945469865795968233973631543964236809100573066960995245177wb, + 150663282285775450662414365350419405945541820765219523130929531002923088277160545114254251148525286476983773283235468282002045173141196158353616014355287094wb, + -479060863800931266429781304885104017131749664329186246406335179483194313801808166262041921602861985862332756318078499039394820190197870580545316549380449074wb, + 1359131269843466711194682581441372588504604777186075559309941421522168913086212721229905012023237380094986736934464910421922092415050027946837562847761546642wb, + 38005189198839309539384162035472227153066377585338581102543574055575777451369497515143095968263424053357137645031423561696064649082930963wb, + 0, 0, 0, 0, 0, + 1911076617401423887269840833410267237705130466676958152037861477885277722749139605040038160132075189228439111066941630564324402605816835862488337890450123441wb, + 2143747820933189266943449152733920616973804237879618575235243631855378946947754007625444647681930476713800905339559157073740302180956472245149919774437085550wb, + 3020328738802050781697314194154464021447637901030508296205170033161531452424686777206896481266404991349073132253866303142608091273541629412071886412132279688wb, + 3548552946267883916132218767540000478942702862442658213517298532968411704728913569849574500607350293984423898514369017381981825383513090204371793724097677500wb, + 0wb + }; + static _BitInt(547) q547[15] = { + -165353820935998006231385303476800492106677276950834360813262262140867129737290132086107434762098834639119492256272880571578714556242252134191835397505691625332102479wb, + 183695555784071631934553514377048200879108759149452364923958570648444896373196632060114376244737698247102365620343713172199496472928539579603161884440477984840044187wb, + 139975743565335456314316356647588328869546947948448304225648231332737456493208842047425843515598984558359834966436458515450535075922755618635258426884425597017306862wb, + -68977268331926408936317559581002324220146009615687701127254186456806021645364222184642001923334926042747842307638529875034306779796443629804024646337944171607895438wb, + 91932189605038085807227077574075596679601857184786010334359253878486168031464536332131456527844457578512045265477412819469725001337530261064906167819503147594853366wb, + 0, 0, 0, 0, 0, + 1839246979523857407677438706283184154273033488874378208597988086724303594582231776664518600187689316422453639079203702255633589137378005258926682975350532271wb, + 49151230401218799957130323446282917069028231656715550463945235235623430774823230155689924560414670278246826717504404635655151576036315823360722825188858286217308439wb, + 9553161692302515408090681902990032962274757557255101236499698228392460650767938620693069133770230123184487473131034348424915457011452743114281594442529356918wb, + 148466349169509850971880825885649862512888667929683428885486286008574376924695036417770580112507292038258577594242665019379719515779240480203475588034326681778827837wb, + 0wb + }; + static _BitInt(575) r575[15] = { + 26826731245669206245461391126964073367685598786847623620556904941634299886033194729072082303506281733460775551098898854360334228479162479457887049265892154734615530822766958wb, + -17252637235610200065109317402231975926530699783926188946291304643884915080832768297094963378392971235218154081350840664198841060114648240981027529664968282740385246545569879wb, + -52927846040946009564438022882734367309063070035915874157090678963969555482365010516321242268874731309847996546526357803037049653154886399755465425844249799943139498370138356wb, + 43797192926762436278400269352553576566711887692587698009480808423919842536790683665562833898774167035902777714908510813261288364232387952547718429572231820909634939092793538wb, + 20234448725793738746286884524404371396011280587539411448314107254021820060093226611203035940379115510914907477160212849326875709895927134019157662749025851187493640146044781wb, + 0, 0, 0, 0, 0, + 150663282285775450662414365350419405945541820765219523130929531002923088277160545114254251148525286476983773283235468282002045173141196158353616014355287094wb, + 183695555784071631934553514377048200879108759149452364923958570648444896373196632060114376244737698247102365620343713172199496472928539579603161884440477984840044187wb, + 4851258619379431619519122339214063398230494067942295987016754503060997355109186638667322723996572842157209194651881355085513631695628096402419719096882984119wb, + 270940858229872855030935066513853051367534588484589172383739756326100509416298021769516239928911004114519037087137992976731526127660469862578530915810061315551592797wb, + 0wb + }; + static unsigned _BitInt(522) s522[15] = { + 9553161692302515408090681902990032962274757557255101236499698228392460650767938620693069133770230123184487473131034348424915457011452743114281594442529356918uwb, + 4851258619379431619519122339214063398230494067942295987016754503060997355109186638667322723996572842157209194651881355085513631695628096402419719096882984119uwb, + 6042770678215430693640419990277820504092375118859355031950453294245655804901016852383090438332300632578629742514358616423826815593825261808316937209844323511uwb, + 12051208019451501933403724997574202861308205865422702777923943166771946439789370797531339169859679650622650974816793351928749417853531441599839154382248843947uwb, + 4221662083598509731422820533439331938122897651286500598721158769592271101088973546986107452648130743363570867708770978567950497328105753210259754199339698436uwb, + 0, 0, 0, 0, 0, + 7875787883122370015751284313157111317906983827437747001268058546750891954500439966161560575930887369730973089278944338386239832138713121400371960426603537532uwb, + 1744137654875073805109882450938570695232931878270397801451971688045434401366666192926859108662009962657770297731676696275736871955838688525022864084574797580uwb, + 1384759081458967898144776881134701550216992364037761109180860974761009009582780990796335747812536429464522433496147744197656107248393986692577240524935263967uwb, + 5124843933530741349702512002787631405197501632531242713014934699385673582868823319052853705098680028945536856890553829308345383420583019490169170519445809329uwb, + 167148589759802650246016819120863239719632156514525854640607511535259699817887971573240690630534000867480233158226351195963838422746014594980644913152uwb + }; + static unsigned _BitInt(547) t547[15] = { + 118704181285368794475444886856018739380810770111464325340905883331118179085356913273672350794295633026214255802587734669771992302197074150034392332589894477800891435uwb, + 270940858229872855030935066513853051367534588484589172383739756326100509416298021769516239928911004114519037087137992976731526127660469862578530915810061315551592797uwb, + 148318595435099152643319192673870560615622574014851374282185242873863044665507345404380126683143560616100080924441878075099797842853873146415865873849906128482858719uwb, + 400009336874533540769201404797235801738671871521831649835366524748844548359672560304665337919920648881530376390480880285772783211641574132727624581374918623770667162uwb, + 312402853341542293879363014443999872603984243465217297921316340174779530859340793778010030453656373118302384722907441723040044092150534190429029290814183834885671793uwb, + 0, 0, 0, 0, 0, + 460688772082162445798867876757263237463152967782366598900331124229116988777566044118861599994996502169289915386539783342538027404687796097956601373975276229385346254uwb, + 110154623692678850196652173379922527637463658741605878515537649114990721104784513051339522805651918716345423521491055109328010793688754512750702811781309047768676546uwb, + 6042770678215430693640419990277820504092375118859355031950453294245655804901016852383090438332300632578629742514358616423826815593825261808316937209844323511uwb, + 399932168246430744543441055162559648552560119213629719844739099564504242321283467689573394637126627461985951275205392441444721842415628268892060247464270805433239423uwb, + 959894824427126361893629230835206712554940543506404673899205310952372906533349475236288402049497277258426690357003048704416527773015730692863997uwb + }; + static unsigned _BitInt(575) u575[15] = { + 99465403292080375994166564143758974423715332054535509951564765439354460753284837794651681099567775806058182781885452212314717097157170419602135858778485292072068230160566460uwb, + 88608049883790202897201248133818379667781926476953929504091250051759382873398323059272759974739854128718622623196375150866798266503497028016169226040920220555730755500552765uwb, + 109996629797150279215121425420517668082012320009431263010584742106213909329388552729870453505045429145144806346761163201752908500506299217142569716987778685190706093716744369uwb, + 79085012468256116329498575277619682348270018511342269619476165669326091481750859826134218624634485255862979362030324907252864643018828592244764325998135532395602379128096639uwb, + 66159275290347502690275324386397674256469688848451250551469155682688473691401346605236603803735518810344975633814051516285290687587632060625865757225821322257077271128705141uwb, + 0, 0, 0, 0, 0, + 1359131269843466711194682581441372588504604777186075559309941421522168913086212721229905012023237380094986736934464910421922092415050027946837562847761546642uwb, + 123665200667574998698324851573506035436563350330459910341343826919194426096459911939793978345979520571463909670260227362037152642119068825187329447746921937620359214466454130uwb, + 12051208019451501933403724997574202861308205865422702777923943166771946439789370797531339169859679650622650974816793351928749417853531441599839154382248843947uwb, + 400009336874533540769201404797235801738671871521831649835366524748844548359672560304665337919920648881530376390480880285772783211641574132727624581374918623770667162uwb, + 109996629937126023660527287777369469494501925435246782331888159188751453565732251262053894836875827628606881325496392400843347632343245675592597560475194478367377989115148799uwb + }; + test522_547_575 (p522, q547, r575, s522, t547, u575, 42); + for (int i = 5; i < 10; ++i) + if (p522[i] != p522[i + 5] + || q547[i] != q547[i + 5] + || r575[i] != r575[i + 5] + || s522[i] != s522[i + 5] + || t547[i] != t547[i + 5] + || u575[i] != u575[i + 5]) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-16.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-16.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,385 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 256 +__attribute__((noipa)) void +test135_192_228_256 (unsigned _BitInt(135) *p, unsigned _BitInt(192) *q, + unsigned _BitInt(228) *r, unsigned _BitInt(256) *s) +{ + r[6] = (_BitInt(135)) (p[0] + p[1] + p[2]); + s[6] = (_BitInt(135)) (p[0] - p[1] + p[2]); + r[7] = p[0] + p[1] - p[2]; + s[7] = p[0] - p[1] - p[2]; + r[8] = (_BitInt(192)) (q[0] + q[1] + q[2]); + s[8] = (_BitInt(192)) (q[0] - q[1] + q[2]); + r[9] = q[0] + q[1] - q[2]; + s[9] = q[0] - q[1] - q[2]; + p[6] = (_BitInt(135)) (r[0] + r[1] + r[2]); + q[6] = (_BitInt(135)) (r[0] - r[1] + r[2]); + p[7] = r[0] + r[1] - r[2]; + q[7] = r[0] - r[1] - r[2]; + p[8] = (_BitInt(192)) (s[0] + s[1] + s[2]); + q[8] = (_BitInt(192)) (s[0] - s[1] + s[2]); + p[9] = s[0] + s[1] - s[2]; + q[9] = s[0] - s[1] - s[2]; + r[10] = ((unsigned _BitInt(228)) ((_BitInt(135)) p[3])) + ((_BitInt(135)) p[4]) + ((_BitInt(135)) p[5]); + s[10] = ((unsigned _BitInt(256)) ((_BitInt(135)) p[3])) + ((_BitInt(135)) p[4]) + ((_BitInt(135)) p[5]); + r[11] = ((unsigned _BitInt(228)) p[3]) + p[4] + p[5]; + s[11] = ((unsigned _BitInt(256)) p[3]) + p[4] + p[5]; + r[12] = ((unsigned _BitInt(228)) ((_BitInt(192)) q[3])) + ((_BitInt(192)) q[4]) + ((_BitInt(192)) q[5]); + s[12] = ((unsigned _BitInt(256)) ((_BitInt(192)) q[3])) + ((_BitInt(192)) q[4]) + ((_BitInt(192)) q[5]); + r[13] = ((unsigned _BitInt(228)) q[3]) + q[4] + q[5]; + s[13] = ((unsigned _BitInt(256)) q[3]) + q[4] + q[5]; + p[10] = ((unsigned _BitInt(135)) r[3]) + ((unsigned _BitInt(135)) r[4]) + ((unsigned _BitInt(135)) r[5]); + q[10] = ((unsigned _BitInt(192)) r[3]) + ((unsigned _BitInt(192)) r[4]) + ((unsigned _BitInt(192)) r[5]); + p[11] = ((unsigned _BitInt(135)) s[3]) + ((unsigned _BitInt(135)) s[4]) + ((unsigned _BitInt(135)) s[5]); + q[11] = ((unsigned _BitInt(192)) s[3]) + ((unsigned _BitInt(192)) s[4]) + ((unsigned _BitInt(192)) s[5]); + p[12] = ((_BitInt(228)) ((_BitInt(135)) p[3])) < ((_BitInt(228)) ((_BitInt(135)) p[4])); + q[12] = ((_BitInt(256)) ((_BitInt(135)) p[3])) > ((_BitInt(256)) ((_BitInt(135)) p[4])); + p[13] = ((_BitInt(228)) ((unsigned _BitInt(135)) p[3])) <= ((unsigned _BitInt(228)) ((_BitInt(135)) p[4])); + q[13] = ((_BitInt(256)) ((unsigned _BitInt(135)) p[3])) >= ((unsigned _BitInt(256)) ((_BitInt(135)) p[4])); + p[14] = ((_BitInt(228)) ((_BitInt(192)) q[3])) < ((_BitInt(228)) ((_BitInt(192)) q[4])); + q[14] = ((_BitInt(256)) ((_BitInt(192)) q[3])) <= ((_BitInt(256)) ((_BitInt(192)) q[4])); + r[14] = ((_BitInt(228)) ((unsigned _BitInt(192)) q[3])) >= ((unsigned _BitInt(228)) ((_BitInt(192)) q[4])); + s[14] = ((_BitInt(256)) ((unsigned _BitInt(192)) q[3])) > ((unsigned _BitInt(256)) ((_BitInt(192)) q[4])); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test470_512_519_575 (unsigned _BitInt(470) *p, unsigned _BitInt(512) *q, + unsigned _BitInt(519) *r, unsigned _BitInt(575) *s) +{ + r[6] = (_BitInt(470)) (p[0] + p[1] + p[2]); + s[6] = (_BitInt(470)) (p[0] - p[1] + p[2]); + r[7] = p[0] + p[1] - p[2]; + s[7] = p[0] - p[1] - p[2]; + r[8] = (_BitInt(512)) (q[0] + q[1] + q[2]); + s[8] = (_BitInt(512)) (q[0] - q[1] + q[2]); + r[9] = q[0] + q[1] - q[2]; + s[9] = q[0] - q[1] - q[2]; + p[6] = (_BitInt(470)) (r[0] + r[1] + r[2]); + q[6] = (_BitInt(470)) (r[0] - r[1] + r[2]); + p[7] = r[0] + r[1] - r[2]; + q[7] = r[0] - r[1] - r[2]; + p[8] = (_BitInt(512)) (s[0] + s[1] + s[2]); + q[8] = (_BitInt(512)) (s[0] - s[1] + s[2]); + p[9] = s[0] + s[1] - s[2]; + q[9] = s[0] - s[1] - s[2]; + r[10] = ((unsigned _BitInt(519)) ((_BitInt(470)) p[3])) + ((_BitInt(470)) p[4]) + ((_BitInt(470)) p[5]); + s[10] = ((unsigned _BitInt(575)) ((_BitInt(470)) p[3])) + ((_BitInt(470)) p[4]) + ((_BitInt(470)) p[5]); + r[11] = ((unsigned _BitInt(519)) p[3]) + p[4] + p[5]; + s[11] = ((unsigned _BitInt(575)) p[3]) + p[4] + p[5]; + r[12] = ((unsigned _BitInt(519)) ((_BitInt(512)) q[3])) + ((_BitInt(512)) q[4]) + ((_BitInt(512)) q[5]); + s[12] = ((unsigned _BitInt(575)) ((_BitInt(512)) q[3])) + ((_BitInt(512)) q[4]) + ((_BitInt(512)) q[5]); + r[13] = ((unsigned _BitInt(519)) q[3]) + q[4] + q[5]; + s[13] = ((unsigned _BitInt(575)) q[3]) + q[4] + q[5]; + p[10] = ((unsigned _BitInt(470)) r[3]) + ((unsigned _BitInt(470)) r[4]) + ((unsigned _BitInt(470)) r[5]); + q[10] = ((unsigned _BitInt(512)) r[3]) + ((unsigned _BitInt(512)) r[4]) + ((unsigned _BitInt(512)) r[5]); + p[11] = ((unsigned _BitInt(470)) s[3]) + ((unsigned _BitInt(470)) s[4]) + ((unsigned _BitInt(470)) s[5]); + q[11] = ((unsigned _BitInt(512)) s[3]) + ((unsigned _BitInt(512)) s[4]) + ((unsigned _BitInt(512)) s[5]); + p[12] = ((_BitInt(519)) ((_BitInt(470)) p[3])) < ((_BitInt(519)) ((_BitInt(470)) p[4])); + q[12] = ((_BitInt(575)) ((_BitInt(470)) p[3])) > ((_BitInt(575)) ((_BitInt(470)) p[4])); + p[13] = ((_BitInt(519)) ((unsigned _BitInt(470)) p[3])) <= ((unsigned _BitInt(519)) ((_BitInt(470)) p[4])); + q[13] = ((_BitInt(575)) ((unsigned _BitInt(470)) p[3])) >= ((unsigned _BitInt(575)) ((_BitInt(470)) p[4])); + p[14] = ((_BitInt(519)) ((_BitInt(512)) q[3])) < ((_BitInt(519)) ((_BitInt(512)) q[4])); + q[14] = ((_BitInt(575)) ((_BitInt(512)) q[3])) <= ((_BitInt(575)) ((_BitInt(512)) q[4])); + r[14] = ((_BitInt(519)) ((unsigned _BitInt(512)) q[3])) >= ((unsigned _BitInt(519)) ((_BitInt(512)) q[4])); + s[14] = ((_BitInt(575)) ((unsigned _BitInt(512)) q[3])) > ((unsigned _BitInt(575)) ((_BitInt(512)) q[4])); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 574 +__attribute__((noipa)) void +test138_192_523_574 (unsigned _BitInt(138) *p, unsigned _BitInt(192) *q, + unsigned _BitInt(523) *r, unsigned _BitInt(574) *s) +{ + r[6] = (_BitInt(138)) (p[0] + p[1] + p[2]); + s[6] = (_BitInt(138)) (p[0] - p[1] + p[2]); + r[7] = p[0] + p[1] - p[2]; + s[7] = p[0] - p[1] - p[2]; + r[8] = (_BitInt(192)) (q[0] + q[1] + q[2]); + s[8] = (_BitInt(192)) (q[0] - q[1] + q[2]); + r[9] = q[0] + q[1] - q[2]; + s[9] = q[0] - q[1] - q[2]; + p[6] = (_BitInt(138)) (r[0] + r[1] + r[2]); + q[6] = (_BitInt(138)) (r[0] - r[1] + r[2]); + p[7] = r[0] + r[1] - r[2]; + q[7] = r[0] - r[1] - r[2]; + p[8] = (_BitInt(192)) (s[0] + s[1] + s[2]); + q[8] = (_BitInt(192)) (s[0] - s[1] + s[2]); + p[9] = s[0] + s[1] - s[2]; + q[9] = s[0] - s[1] - s[2]; + r[10] = ((unsigned _BitInt(523)) ((_BitInt(138)) p[3])) + ((_BitInt(138)) p[4]) + ((_BitInt(138)) p[5]); + s[10] = ((unsigned _BitInt(574)) ((_BitInt(138)) p[3])) + ((_BitInt(138)) p[4]) + ((_BitInt(138)) p[5]); + r[11] = ((unsigned _BitInt(523)) p[3]) + p[4] + p[5]; + s[11] = ((unsigned _BitInt(574)) p[3]) + p[4] + p[5]; + r[12] = ((unsigned _BitInt(523)) ((_BitInt(192)) q[3])) + ((_BitInt(192)) q[4]) + ((_BitInt(192)) q[5]); + s[12] = ((unsigned _BitInt(574)) ((_BitInt(192)) q[3])) + ((_BitInt(192)) q[4]) + ((_BitInt(192)) q[5]); + r[13] = ((unsigned _BitInt(523)) q[3]) + q[4] + q[5]; + s[13] = ((unsigned _BitInt(574)) q[3]) + q[4] + q[5]; + p[10] = ((unsigned _BitInt(138)) r[3]) + ((unsigned _BitInt(138)) r[4]) + ((unsigned _BitInt(138)) r[5]); + q[10] = ((unsigned _BitInt(192)) r[3]) + ((unsigned _BitInt(192)) r[4]) + ((unsigned _BitInt(192)) r[5]); + p[11] = ((unsigned _BitInt(138)) s[3]) + ((unsigned _BitInt(138)) s[4]) + ((unsigned _BitInt(138)) s[5]); + q[11] = ((unsigned _BitInt(192)) s[3]) + ((unsigned _BitInt(192)) s[4]) + ((unsigned _BitInt(192)) s[5]); + p[12] = ((_BitInt(523)) ((_BitInt(138)) p[3])) < ((_BitInt(523)) ((_BitInt(138)) p[4])); + q[12] = ((_BitInt(574)) ((_BitInt(138)) p[3])) > ((_BitInt(574)) ((_BitInt(138)) p[4])); + p[13] = ((_BitInt(523)) ((unsigned _BitInt(138)) p[3])) <= ((unsigned _BitInt(523)) ((_BitInt(138)) p[4])); + q[13] = ((_BitInt(574)) ((unsigned _BitInt(138)) p[3])) >= ((unsigned _BitInt(574)) ((_BitInt(138)) p[4])); + p[14] = ((_BitInt(523)) ((_BitInt(192)) q[3])) < ((_BitInt(523)) ((_BitInt(192)) q[4])); + q[14] = ((_BitInt(574)) ((_BitInt(192)) q[3])) <= ((_BitInt(574)) ((_BitInt(192)) q[4])); + r[14] = ((_BitInt(523)) ((unsigned _BitInt(192)) q[3])) >= ((unsigned _BitInt(523)) ((_BitInt(192)) q[4])); + s[14] = ((_BitInt(574)) ((unsigned _BitInt(192)) q[3])) > ((unsigned _BitInt(574)) ((_BitInt(192)) q[4])); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 256 + static unsigned _BitInt(135) p135[24] = { + 4187273188098476865668456823817923591884uwb, + 6807534906955493735159263291613578822092uwb, + 41026661032626929517457579844514879338728uwb, + 21107725719388574292787309710748598888876uwb, + 37762806761430755157975144430695583115875uwb, + 26495620887646122219041406684145481614415uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 24294442897610200845563470372394790405427uwb, + 14494728260279138634407444539578218061153uwb, + 35692618919905757032302955601299560733828uwb, + 2073608133107652132583703172274308589354uwb, + 23162446968047093866488519785733079173672uwb, + 23215356388255044329396934936113503903836uwb, + 0uwb, + 1uwb, + 0uwb + }; + static unsigned _BitInt(192) q192[24] = { + 2086085555369597859021791929925392355640686637062909369671uwb, + 2680579114698255110186052616880338377881530773942412775534uwb, + 3327728695296211902341553047509833116972847770197432421329uwb, + 5940317943727487997168783552089315457607206947999336887004uwb, + 5542354187267299678821667349861772942889507214082859925027uwb, + 3271998891636156295842018666243687525289384908182662772181uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 19403341198470336643414519815259741762743uwb, + 5896270732876306173690375572457711356577732208000026578149uwb, + 5124631678261056717896926088333660842277657529754581693718uwb, + 3443509077298665851293720223028023121358922119534917222332uwb, + 5756578284734093802702142887739107033567473420998759418408uwb, + 4630861060283249917347323439223922476602768583090317402204uwb, + 1uwb, + 0uwb, + 0uwb + }; + static unsigned _BitInt(228) r228[24] = { + 161966633757691155241945327015229701994331693366818788921573408319756uwb, + 38296346596827362616775983079516749483975676455899963878059782490174uwb, + 241591800199660287949868996521720659189646617902754527264229209396201uwb, + 428902738798964850544466128550714169355105701114620489106903291340964uwb, + 235528598555728562847947927417825731721784962388084030737368213942614uwb, + 256292789834236084059292238814861516121661392325304427878120090497070uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 8465326161800776794973350208680050686336uwb, + 13524290028307164406682090022182954141616uwb, + 1817291629977384107713608171107897434392709736738720053638uwb, + 1438935974771641066866291499295897616549369640807889723876uwb, + 431359146674410236714672241390567958214899515783829121020714765473886uwb, + 85366153368465451669803860825589663619166uwb, + 431359146670333602531143143072639192076766087438128192434530520032980uwb, + 14754671022630943971832469568194775925786099070264859584212uwb, + 0uwb + }; + static unsigned _BitInt(256) s256[24] = { + 33689368506800899324387091792297880425309542585828646830789259960880991063584uwb, + 39571323848345650718084485253626478678560275338021939071625078673058668106679uwb, + 110504693488819055796063554254198165064817853023249665372075921323272516500141uwb, + 102297428517176642359444223748374693989314404662584768443522888625651626181283uwb, + 80244728165314710913956389448156622901095909768247496334097456157707270969074uwb, + 103665915010005983358711046736784166330673952063454224485339530724102504302279uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 115792089237316195423570985008687907848120241013530353364112407633366022682088uwb, + 43465363180276300259675513190222127563800uwb, + 2733235135967554651177292360554887094732003633317929015466uwb, + 2354879480761811610329975688742887276888663537387098685704uwb, + 115792089237316195423570985008687907851523852102345769062637545330970131126366uwb, + 85366153368465451669803860825589663619166uwb, + 115792089237316195419494350825158809533595085964212340716936616744785885685460uwb, + 14754671022630943971832469568194775925786099070264859584212uwb, + 0uwb + }; + test135_192_228_256 (p135, q192, r228, s256); + for (int i = 6; i < 15; ++i) + if (p135[i] != p135[i + 9] + || q192[i] != q192[i + 9] + || r228[i] != r228[i + 9] + || s256[i] != s256[i + 9]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static unsigned _BitInt(470) p470[24] = { + 290679861857217105576749510785172236097196317219002071340131005135259342235163792727727620685697644545754092322618593967328975789101613622756uwb, + 3007766161917260990990922308983802917798001363835330597758175849272351861703814650851622073672692222948955250827120638757725725607466346547961uwb, + 574060276709923148626402211078479568921550247040425483673763765831291153847648453629069366560426848580089729851582562589160127450838856742850uwb, + 1513032643015460548072615957037831807842396447090608200111284706851223881642236182620260811534047670872236957008209636843038402328412186623867uwb, + 736018121751614604248763744490396332128994581237940802611521314820643126961848250509301799425532301686788266718861244200351342613056372468552uwb, + 30155063271645468057678848208011195960933215968662731964986808367634269990062216294334734731269355557159014770813970386099476462377224708070uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2336276654669971355000545579045474018643499545251683574017489057360457587609182251538648565538596336349157530705582440962441081292975829750725uwb, + 2811887457092416012110559147431839355552932271928059605261212342070741952382405730371093476958614469776023370616340687057532287796176219869449uwb, + 1454614080118846581654283867177010224989739028600678358170065228650331074859011839166100981351630244514069807407054058295180885648638359156315uwb, + 1452099984535181412105251439415950646129930223001670876794248464265033550302786152371528494721306355739311614007226227128382131037961688117145uwb, + 1700131771206195433306793035837240564903007159128880173423363038992576767815643454391004339339329935701073991719473097155654566696420734301605uwb, + 687646008549017812028590579565520345681613774085522641973968443446824759773421489288886130070355380390157446333512774944224841451835655874095uwb, + 0uwb, + 0uwb, + 1uwb + }; + static unsigned _BitInt(512) q512[24] = { + 11999607180890662234640611094796125402682182607671756821443119677915957826104697013256706604957461530042481930446302956354396703791101848051437136984190670uwb, + 1669399929141703249463393746110522414573291237669539702537374904052097169767189303794997941915228747803109873985069631915369758962889453579386958506452828uwb, + 11378992935330313540343401440793120879643841271871581700686172052228324616806874974534345697693861690426360116949795282888644662188134499896194148433768387uwb, + 9993083190971384981726645923137348157759809443699348826766460590248782912389872021894301181692065821343040669086846645954670076835055767363529908044878460uwb, + 4194741102820399815388565886074911339757551809782406262401319165104710890785047966633447456093482200519894213755964462654816313685699735398967845201704233uwb, + 2421595337545745821088215118098296983215379552867408581490131959698723606384411644669422390261525987191387981272012502904825570949628276538570672660290088uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1513903473639259387274129463605791299347099137673287344952013483163916537193546764015586855259820134007663746976291793381162392640818043683999uwb, + 12277156682318352235712463688522823330952278031457456554222055921981909263024261498262481023121115845377546131965398459894872235113782544708914458317029859uwb, + 4027845254315197169423233647114376033430305844071443075105613565290966574715062841638133555232740863237407025233981863916917198547523085200055676796066563uwb, + 10707639349311374361511081362429794348061398948029634783963376915733257208356397594815368492279579755336561685612483789993986308827288890748132804532704321uwb, + 11909891944680678452073045961414477447224653685643721320079864331428768064778333088269746747399111241079878764522077445502337140106279379768026249427056037uwb, + 5596625625751028170955045723080584878265817548746738005171988990687430526534540571089022256509279287347335747951148567883951414510786508005390890674578991uwb, + 1uwb, + 1uwb, + 1uwb + }; + static unsigned _BitInt(519) r519[24] = { + 1030342010401113812244886675533462199253435182769422147430754601621146628252085744300635665226057568402783959871999680067593144181093412956713229194456894164uwb, + 1399286804337892133001051165724092281210924970185276871571622362921173888386145177372320997003882614750136133472548611361735698398271314700469097220046489491uwb, + 1187491577184187187658283970910931091626643735561997844498566871693437222121521301715871480084581538847004007675304538195851777836706064395267954449805214046uwb, + 1590038038660143030887559697627655997346700459420257472659393551660904723658903805269248515919541163543209428329235720802030325145482255847896549116166445779uwb, + 884402951942479884942778411278542758813719790602900630698855595508395145632292880569268024966776717352051287824788383446062053991609910742048548988449536210uwb, + 326292950770117959333132136682031715802512494345703440528331497456255817028879418424543059879797143305345789113287071774990765627898999338681127138076566016uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 823923731816440081735482986127565752359132554398497263261175151854750269095449533809682632145875337989030585578073140142878915098101850794143uwb, + 2724385747064554947941269608690495584973647434013907185424543088576320050091329989950280327797963018914619613298156670135894573945729103427867uwb, + 1714431799218129913570774556055636380759299408511854443817835408543138647401945680368622211813596383857215966052878410278731400359247393614777658018691007981uwb, + 2290014174702051943760603400113526937611632573469714823294322529739730379065011342517358849178828587419231687481577305381121800565856801734629947056875111uwb, + 2279205828038720620379058549736239335932324244297211734687792830039501278594146649423897345690849328116184238497884851429489221403845783800489uwb, + 2279205828038720620379058549736239335932324244297211734687792830039501278594146649423897345690849328116184238497884851429489221403845783800489uwb, + 3201611701394933518629401929104710353253374985756770292934350271330453379485784656395296729880170581364291005928337560660558078658437209354634776900788685uwb, + 16609419631337530618203426927310556480732740806349163670657911715052217409559331633197171028047074009054322864114823611514311961470383779301068425906872781uwb, + 1uwb + }; + static unsigned _BitInt(575) s575[24] = { + 96927313110651552741697906285845027560278665167912446772243994455709167318164555507475733363294500975052442014691905285678776198101396126432691790596947740988776944060654926uwb, + 102707772385622802706823804871287360126470122215207829602545757786870641626119828685986043329520959072898431094747590180228385563652833016000194460109692900249703592758013356uwb, + 110583747014804561196219218561034468168713024547408050239450245043477530907411843124501635977214033600051542621634445064425297114819990148482732834711384300709771384106312545uwb, + 54306775370484796829739172393424070839859954453514190131950827429084664762249620446751937114044786249494515203860165437770921772021031551664278887501083036990545747406428169uwb, + 46114759885997746928772223321204027410936673207704735367438056888037044881883997045448409583831956188379542065205564192543381437121786101651883495914008056100188006564313178uwb, + 35190453913973191463478013966823372048936778121696189495901809463574016396767724553244869787736619209084040172125210006605333310947417602727114932375121134023666009552590284uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 905556545317840426670820457599737857678360574120357846766614390078350723070174958903911342346373648262657058770329172970099291381779089937069uwb, + 2806018560565955292876607080162667690292875453735767768929982326799920504066055415044509037998461329188246086490412702963114950229406342570793uwb, + 123665200736552267025144844837017673343938243343672951569825529047137624617410727523806857743618811225191141477410357286961350974191432110603936918943400338433680414973687605uwb, + 12359022246361242544407840906098328235944415918723028795943134165357300069604179711729237263515274519503043797697924092404136165452024464522289679050053551uwb, + 2279205828038720620379058549736239335932324244297211734687792830039501278594146649423897345690849328116184238497884851429489221403845783800489uwb, + 2279205828038720620379058549736239335932324244297211734687792830039501278594146649423897345690849328116184238497884851429489221403845783800489uwb, + 3201611701394933518629401929104710353253374985756770292934350271330453379485784656395296729880170581364291005928337560660558078658437209354634776900788685uwb, + 16609419631337530618203426927310556480732740806349163670657911715052217409559331633197171028047074009054322864114823611514311961470383779301068425906872781uwb, + 1uwb + }; + test470_512_519_575 (p470, q512, r519, s575); + for (int i = 6; i < 15; ++i) + if (p470[i] != p470[i + 9] + || q512[i] != q512[i + 9] + || r519[i] != r519[i + 9] + || s575[i] != s575[i + 9]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 574 + static unsigned _BitInt(138) p138[24] = { + 101422284254667607392742201719883227411625uwb, + 160466466586635795278252037831376082677350uwb, + 25107605609849786823351214520760656620933uwb, + 295969175246745649031682884402595713219313uwb, + 13181527086641487248448136085636319944955uwb, + 235130534778709326353598872018612896874473uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 167302456247167982996160810773690897220075uwb, + 297389206356979455260412959683265332806635uwb, + 335394759052458807357434855405547433962500uwb, + 321901396962914134364671486134447068161226uwb, + 120351777790732110377699121565672639601425uwb, + 198373944314536120634408834917264425196481uwb, + 1uwb, + 0uwb, + 1uwb + }; + static unsigned _BitInt(192) t192[24] = { + 911018684451330895893338523816772465484522458698266889768uwb, + 2046183627271691614636061554682220483052698404211100534853uwb, + 4678069061913127216263854322789964375230426789917042687454uwb, + 3459784480694777343275716409755634649190978443376335561303uwb, + 3867595273303447369888355921671728883273018646069926566645uwb, + 4813052987333975223830750234077960301742057680559503213273uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6277101735386680684990022390197371509564931202241440203909uwb, + 1278608194268128077434264942601213585924783150489231066757uwb, + 4029427835151946963573253373549922510624267261072515255840uwb, + 672033229033398034156049846020027986275380626166731032294uwb, + 1357991472586126795792080074222943985598370321805879319313uwb, + 2856538916789713009071224987092580961800045494832854440897uwb, + 0uwb, + 1uwb, + 1uwb + }; + static unsigned _BitInt(523) r523[24] = { + 3195765699538496998535864601292347963256629173162679399458238383409531673496364786350189170351629279748663665677408547146700561030889355712400808816914064440uwb, + 11159477301642000894502707350448750665412836731536210953742141163262563390545287499722678844509966339767235942912910312315832667904302744531360002727358824115uwb, + 22101560948582634345286310809677329764046784779464227969587135587282924532940609616951363156766482627364659628549350689295905244730986420796580267097794699008uwb, + 3492227525200477614910950479637037651613240112641204783475954014565794311494477327458692721172240707535504736878649393132370069751011176314509944329056779358uwb, + 4470424684397392413407392569484317542436005833167916532642765757801563745613041876920796693178762870199674360069594704277190939739704629258367293449899462004uwb, + 13549742618125959998093915668094856307843206900469464436576203440358812289708508455667681082349827642620118118540849103671482396581682398406739495271235801407uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 27459190640522438859927603196325572869077741200573221637577853836742172733590624208490238562645818219909185245565923370695700676111069483100152175053778407572uwb, + 236781145231453615847643025030498653468042uwb, + 1358169638249468962957464978081290907665292208362375599179uwb, + 4556234985196576058101335178916694989409149517456359250063uwb, + 27459190640522438859927603196325572869077741200573221637577853836742172733590624208490238562645818219909185245565923279531437610013356035988992599748093205461uwb, + 544281237112096462633729892506844930038741uwb, + 27459190640522438859927603196325572869077741200573221637577853836742172733590624208490238562645818213218312780738081077635942247881191161149284549778122031141uwb, + 12140432741332199936994822565505323834206054770005765341221uwb, + 0uwb + }; + static unsigned _BitInt(574) s574[24] = { + 49523656310311432476097096707674348247864532997580458449189999134679927949102290921020347613627600560130921641399166416960416734901407545116688589513670229626633588928674165uwb, + 42569658590233851212367348547775997184555788503209190045856322440515976044599442772511746833320065456241311597243171150757254859304810272116865990700066734780242713347731186uwb, + 19981999860412564491215269984435969976814910925473334223760435541572601828084228297697056388524273994976358111097326046010839057122757304450178767567932398574496781000082333uwb, + 8558322198907185372332169456108688881070480268559248312027066736995799133128362338305761323248219317368913715505110464564580744145522428754123209057064241016828671823488793uwb, + 43811765949130776561433192718564194559949284938162910217959397270715482324290476494691373258084890889610745910962659657029995968487465144041804156738366622609326192386149788uwb, + 45992921207674703917316226268947032522368981737128477902399950788131403664441772601690186531393245791394478464207683996776726761730838587963296718352656413407075666840676108uwb, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576653865915164420374411133357560960838529992uwb, + 264297355785223011877634547377877136644286uwb, + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504032100640224964662421487833755255625414851874551633211704257uwb, + 463867730653192828829212069552254023303752709034158180357uwb, + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576535185441544553264934030675638276670151637uwb, + 544281237112096462633729892506844930038741uwb, + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504028143965376430734333289946182421100059190967588306698977317uwb, + 12140432741332199936994822565505323834206054770005765341221uwb, + 0uwb + }; + test138_192_523_574 (p138, t192, r523, s574); + for (int i = 6; i < 15; ++i) + if (p138[i] != p138[i + 9] + || t192[i] != t192[i + 9] + || r523[i] != r523[i + 9] + || s574[i] != s574[i + 9]) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-17.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-17.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,82 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) _BitInt(192) +test192 (int a, int b, int c, int d, int e, int f, int g) +{ + _BitInt(192) r; + if (a) + r = 0wb; + else if (b) + r = -1wb; + else if (c) + r = 8509079622807245684wb; + else if (d) + r = -906140470171472463wb; + else if (e) + r = 16213049720239626860wb; + else if (f) + r = 147892183939833533694801609136018843670wb; + else if (g) + r = -65591640145960897840899726907249505215wb; + else + r = 2430673202376479588648422478850704999441011825542092986793wb; + return r; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +test575 (int a, int b, int c, int d, int e, int f, int g) +{ + _BitInt(575) r; + if (a) + r = 0wb; + else if (b) + r = -1wb; + else if (c) + r = 8509079622807245684wb; + else if (d) + r = -906140470171472463wb; + else if (e) + r = 16213049720239626860wb; + else if (f) + r = 147892183939833533694801609136018843670wb; + else if (g) + r = -65591640145960897840899726907249505215wb; + else + r = -61793624342683909782972416440098036406501521208177932544452266579025268523357080574330290352054553626825262073339234752683755828499698570848704076099511077751520231100121930wb; + return r; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 192 + if (test192 (1, 0, 0, 0, 0, 0, 0) != 0wb + || test192 (0, 1, 0, 0, 0, 0, 0) != -1wb + || test192 (0, 0, 1, 0, 0, 0, 0) != 8509079622807245684wb + || test192 (0, 0, 0, 1, 0, 0, 0) != -906140470171472463wb + || test192 (0, 0, 0, 0, 1, 0, 0) != 16213049720239626860wb + || test192 (0, 0, 0, 0, 0, 1, 0) != 147892183939833533694801609136018843670wb + || test192 (0, 0, 0, 0, 0, 0, 1) != -65591640145960897840899726907249505215wb + || test192 (0, 0, 0, 0, 0, 0, 0) != 2430673202376479588648422478850704999441011825542092986793wb) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + if (test575 (1, 0, 0, 0, 0, 0, 0) != 0wb + || test575 (0, 1, 0, 0, 0, 0, 0) != -1wb + || test575 (0, 0, 1, 0, 0, 0, 0) != 8509079622807245684wb + || test575 (0, 0, 0, 1, 0, 0, 0) != -906140470171472463wb + || test575 (0, 0, 0, 0, 1, 0, 0) != 16213049720239626860wb + || test575 (0, 0, 0, 0, 0, 1, 0) != 147892183939833533694801609136018843670wb + || test575 (0, 0, 0, 0, 0, 0, 1) != -65591640145960897840899726907249505215wb + || test575 (0, 0, 0, 0, 0, 0, 0) != -61793624342683909782972416440098036406501521208177932544452266579025268523357080574330290352054553626825262073339234752683755828499698570848704076099511077751520231100121930wb) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-18.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-18.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,117 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && int32plus } } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 251 +__attribute__((noipa)) _BitInt(251) +foo_251 (_BitInt(251) x, _BitInt(251) y, _BitInt(251) z) +{ + return (x * 42) + (y + z) * -13295847598437589437584395wb; +} + +__attribute__((noipa)) _BitInt(251) +bar_251 (_BitInt(251) x, unsigned _BitInt(211) y, _BitInt(251) z) +{ + if (x >= 139845735984wb || x <= -139845735984wb) + __builtin_unreachable (); + return (x * 42) + y * z; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 274 && defined(__SIZEOF_INT128__) +__attribute__((noipa)) _BitInt(574) +foo_574 (_BitInt(574) x, __int128 y, int z) +{ + return x * y + x * z; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 274 +__attribute__((noipa)) unsigned _BitInt(574) +bar_574 (unsigned _BitInt(574) x, _BitInt(231) y, unsigned _BitInt(231) z, unsigned _BitInt(574) a) +{ + _BitInt(287) w = y; + _BitInt(231) v = (_BitInt(231)) z; + _BitInt(287) u = v; + return x * w + a * u; +} + +__attribute__((noipa)) unsigned _BitInt(271) +baz_574 (unsigned _BitInt(271) x, _BitInt(574) y) +{ + if (y >= 139845735984wb || y <= -139845735984wb) + __builtin_unreachable (); + return x * (unsigned _BitInt(271)) y; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 251 + static _BitInt(251) s251[] = { + 14492268074422240072381201900068160215333038638908804267546082474872103453wb, + 675218251468166080020913826378654880460963853057558284085495091870180550wb, + -675218251468166080020959605725458087975245668339558473870927889256690061wb, + -139845735981wb, + 324639141258847384727959753569292057577687203071371684930924253wb, + 1087290800830wb + }; + _BitInt(251) a251 = foo_251 (s251[0], s251[1], s251[2]); + if (a251 != 1217350477377202249120031439408588187131962868502518732097281406269161025871wb) + __builtin_abort (); + _BitInt(251) b251 = bar_251 (s251[3], s251[4], s251[5]); + if (b251 != 352977151880095667263614472150365012179801988966714554955131068402918618788wb) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 574 + static _BitInt(574) s574 + = -219356128782553279814913626158411711140801689317931406799100755440262023325014648411412728943485405803043129187408541215111743475318581wb; +#ifdef __SIZEOF_INT128__ + _BitInt(574) a574 = foo_574 (s574, 82625523151678902953603407887262843433wb, -1845137725); + if (a574 != -18124414897185514989959611747585480593042904176332662608326479231051632926435887114574980277665683285141927551496724599123576825185653577703648854819279658769883513402160348wb) + __builtin_abort (); +#endif + static unsigned _BitInt(574) u574[] = { + 52437079816179410811636905891411754807147405868482583243559735153324503490239312503359712796401481190029201386135205713917847314204739635852931994918423899615130723009259686uwb, + 45269866460552189474732773540973151549203847819115194862112414296072167098695417407106646749337072175534165739911745591080506448641600205866240027517670273657001894552180234uwb, + 9180917912712609437909586196568830786346456714119640856730259437790973527459849487895103863584234525859590698749982125884487194000401583172193548884761272331911564480124878uwb, + 11049512233686559553687636036663446413022165259892524030717648180326957779916930880483808447448446584642734113622685260963900225478745988370450191005955141795745690734947571uwb, + 47663369272354253242910978827267365842851495123515313737663958515768452802250710665542640440990559573730917816406856556730100799652539291367902764980370386873495017607993411uwb, + 18215014622276393791745550421148998901660352490811211087424965165803902184090598141881549641537877241526565777992183348471991467868259791203907545956986039786453071578011434uwb, + 31740235950157332221439070489628722839769958133906789091713734411951000853909663917518016071789015372380206595539133512032995220911059581277451361109633464034310397164665564uwb, + 10450847162543795294901585004050399762545006892613453868263703161802323302908254646557151245191494710406620278412346326386062698341158038281632905480774145352377805385543092uwb, + 19453023158842453405396915599369210861261573519874550548893523502986640805175433191781338575797970717670733269190857402493766307964168520080852675173587364248259309552168430uwb, + 41244368675818170615108799247368989151384052534670384186902588532722396202878099538345240688084993610469542913084982675850069064350042690913662957238816036434888665664037846uwb, + 16719362016737006280008309688585219733130381598157287999202010698266470616548718462522730730476541950851348747767571521700255425942578137654761356039235313588531776459325708uwb, + 10475917472649802727102296550431840421435279490948846996006476240420369031587862359912739671064811272746210509826242404174149288385636488194271969135287801110662285317095981uwb, + 1163912911803352668493394805506325912661919234067386269274323760640925113542354050648690202267829712352143945896104268132186183304256748687336699391633352420957751382619669uwb, + 8802741787945718202007440863180520530918335416409181790035566968168103145420485853909047361251267032896173190843315221928932703515727560628431319297083973682964053958087246uwb, + 19791342948421817380238010195638893503615644292584928829415951859564239969766035100704913746176442012398341262166756998845831007892328794072245007765812537811265165604315700uwb, + 16642284329136906697237309134287786314682533828330755403465475806950133035971596597211127434533311710048393623437103786994963036388804007132262710130242198695003152238215628uwb, + 2155325970411161010229823956524370uwb, + 697446886254974788952071928578631979965uwb, + 108165657554251490446057511316485495uwb, + 9487120152929104576906851118100261958096487535uwb, + -136538663022088871346045694473572wb, + -1666960912074801530926062313122413146603wb, + -15940673946961553912565090695396320wb, + 264462353975419400604468749561884442664wb, + 50826882861731683785919742135963976479884717145067744452535625618737864973658554226615085532399945662542810296565555980855512176679463978891752486331179893311834461777517318uwb, + 16170033701813896205634802741964500343094214191596485883117074926829904835328260995277267910766680743976283458668064421272599104442706448899915189301332650772687724575723182uwb, + 13009027737564179578240898152688856367334005472217232817755080920783012286505432066490161649175068937710374621121911926344239719476459487715714492624089105621335225676985872uwb, + 49336707246523391872334763713437428863232354140618977476842520346079224652928216135156362963444355821534349959448992339768542254081420292190058456423815350822979116396882390uwb, + 1026180591140992942712368030740883182331172637458255292975945323684907793150051875uwb, + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761243411314314780717702156716099193191615778530561481120811604064555385654220uwb, + 3635377841759794164811391623635227990564259993543952474130713407348044048553863186uwb, + -139845735971wb + }; + for (int i = 0; i < 6; ++i) + if (bar_574 (u574[4 * i], u574[4 * i + 1], u574[4 * i + 2], u574[4 * i + 3]) != u574[i + 24]) + __builtin_abort (); + if (baz_574 (u574[30], u574[31]) != 1212103790378493380735221770817318414499452864884443699768488049528961780122040714uwb) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-19.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-19.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,190 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && int32plus } } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) void +test_135 (unsigned _BitInt(135) *p, unsigned _BitInt(39) *q, int i) +{ + p[3] = p[0] / p[1]; + p[4] = p[2] / *q; + p[5] = p[i] % p[1 + i]; + p[6] = p[2 + i] % q[i]; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) void +test_192 (unsigned _BitInt(192) *p, unsigned _BitInt(62) *q, int i) +{ + p[3] = p[0] / p[1]; + p[4] = p[2] / *q; + p[5] = p[i] % p[1 + i]; + p[6] = p[2 + i] % q[i]; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test_575 (unsigned _BitInt(575) *p, unsigned _BitInt(125) *q, int i) +{ + p[3] = p[0] / p[1]; + p[4] = p[2] / *q; + p[5] = p[i] % p[1 + i]; + p[6] = p[2 + i] % q[i]; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + static unsigned _BitInt(135) s135[] = { + 39967592296255191197035336461290090324829uwb, + 312558523056789678960549094065358uwb, + 32832062726968675550596542626872563693099uwb, + 0, 0, 0, 0, + 39684305085076546670125468925068uwb, + 6804617795530664696186192571276807994017uwb, + 908900452537968951389639987294090uwb, + 0, 0, 0, 0, + 20395215776806618633686937572550377003558uwb, + 1uwb, + 2017874535031304931048003948865783841241uwb, + 0, 0, 0, 0, + 16804502949303659647220377886348649uwb, + 15969624846496231063802991739581uwb, + 12583271616670577644431817717623569600333uwb, + 0, 0, 0, 0, + 127872348uwb, + 89851078235647451008683745245uwb, + 65571357606183724433879897404245uwb, + 87071527329uwb, + 0uwb, + 2093478262068616207802533uwb, + 39684305085076546670125468925068uwb, + 228138242uwb, + 20395215776806618633686937572550377003558uwb, + 12999486295301452164134194354389uwb, + 0uwb, + 65232213uwb, + 1052uwb, + 299601705158823277248376612324370704769uwb, + 4457610789624568099630576309437uwb, + 35uwb + }; + static unsigned _BitInt(39) s39[] = { + 365405328146uwb, + 434158056uwb, + 155227252uwb, + 42uwb + }; + for (int i = 0; i < 4; ++i) + { + test_135 (s135 + 7 * i, s39 + i, 0); + for (int j = 0; j < 4; ++j) + if (s135[7 * i + 3 + j] != s135[7 * 4 + 4 * i + j]) + __builtin_abort (); + } +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static unsigned _BitInt(192) s192[] = { + 1124505164324393257294640774883626666393496137407657383285uwb, + 267770052679215918410877624132556357420375522461819642uwb, + 4639722531344459905931256257525470190970246632351027146771uwb, + 0, 0, 0, 0, + 37076404019741709360338653279977uwb, + 4017103983634913740425503780735862298200532685100197316953uwb, + 3278541912894246916134094695331450716143029898422059693966uwb, + 0, 0, 0, 0, + 181260360652955273548771772757571198044332327135683350561uwb, + 3uwb, + 278424729322219534657080470631020618602047522343uwb, + 0, 0, 0, 0, + 1546922522984382736106987324181069322701408057466881095437uwb, + 2859498891267655913293729558067200232488079281528uwb, + 3754903553201168811081807274774774084224112858563658575772uwb, + 0, 0, 0, 0, + 4199uwb, + 1361868478710180046608174894774272890845uwb, + 138713124365615887365631151022521585339318590476706527uwb, + 704022636372799201uwb, + 0uwb, + 1800071738275562493471915107371110587374384505uwb, + 37076404019741709360338653279977uwb, + 989224815596uwb, + 60420120217651757849590590919190399348110775711894450187uwb, + 35811149155369659378220712438655uwb, + 0uwb, + 971271817233568uwb, + 540976787uwb, + 268207396657226343648700519626769577444579489897404183983uwb, + 356343883111794920610945410844353911944595204901uwb, + 10uwb + }; + static unsigned _BitInt(62) s62[] = { + 3406880035683564506uwb, + 1821339585074uwb, + 7774805776666105uwb, + 14uwb + }; + for (int i = 0; i < 4; ++i) + { + test_192 (s192 + 7 * i, s62 + i, 0); + for (int j = 0; j < 4; ++j) + if (s192[7 * i + 3 + j] != s192[7 * 4 + 4 * i + j]) + __builtin_abort (); + } +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static unsigned _BitInt(575) s575[] = { + 68262105478469356136430990337792292171975154797241096882998520215082649730969604949380226799284423285674920339289406073226899446201591827481846481242318203838114185414101609uwb, + 522191246473430521641066810210970739255168853016819760532584735359478867620239849176927824047731938802486584777452655079470889576128018146184619338332252916338uwb, + 3435470059299599312416077239534464560179043115309368866437635382063534713476732558299272800804091725646363342046360614869573337710790812486381755554721429381220646362uwb, + 0, 0, 0, 0, + 1395593888697848626057320338038084790564831152710988743807319327067660279846004696629681887779842129545558985841571482256386uwb, + 21441995702257150447349407715894435455050772126685461031315827571889336447926694701361700730379084806621691641000793333457504299685338550064151630805530260276144722300318378uwb, + 1810496946211232933828329287232831944898449501818263455079805575961543103376888822223202088001971904867510317357383306521333499198279246848350610021364570531uwb, + 0, 0, 0, 0, + 49645180073615279861687094823459626955281549193691328477580826482861925123118554141451230055925103484376691314925103229496483975307219087542024089047037648064847114147876643uwb, + 5uwb, + 107934287940096962208124285810972463665238866518161589834947495273979231095066254158254278656128778606292981405785821524489035396101282777095285918056890626313652996363360635uwb, + 0, 0, 0, 0, + 23608107814490548232484082204335368855445148092939475311496653239338164906367806895605948777993633707136572413097677855946274968766053297446456942019070196462866449343995194uwb, + 2583203116898176965174690967993977971553570592649244007260134674599130988578292547989776393639164uwb, + 275574884364090029934989506452294812428150053792728044335881034126425125444715551780251783116966457185581504439797097624639857491748084495990405201247685674533629814uwb, + 0, 0, 0, 0, + 130722423900191uwb, + 98209305532955450849963417931387543706587302562952677389372338515039360888927455577958981902466648551427758908831114835123178381uwb, + 452871192905895539483003814306315901853065835276102489810630370966701886335873219401733574293829636677996055324174200714778800368052970790656772945453428881051uwb, + 22873946842052620485494389199978222125uwb, + 0uwb, + 47552124733256427939572722329767524480111793387357122806941820665877774450470824535764237662603507442099431904312121406656289uwb, + 1395593888697848626057320338038084790564831152710988743807319327067660279846004696629681887779842129545558985841571482256386uwb, + 12402931424678892069400953011343uwb, + 9929036014723055972337418964691925391056309838738265695516165296572385024623710828290246011185020696875338262985020645899296795061443817508404817809407529612969422829575328uwb, + 765676291859168654790768770138076157159515580930329832291016877204190990758886004368955392441159337179098419446671535422387547862111454482076132380462913464uwb, + 3uwb, + 139483670059084867uwb, + 9139083047731208433628027573752517850138452745189939065766817977544782897707uwb, + 582502183871265798930967135317783829723227597448966288820692884195884049998974821351103238544771373433464199926206342695349404216240804690670860uwb, + 331751853749540937734694164624358910388009028150635800666238028944699092436048473910402462998246uwb, + 30656037717616877434uwb + }; + static unsigned _BitInt(125) s125[] = { + 34981105310298535974120492274604066977uwb, + 38073944253116192522082228985492uwb, + 140965952697865937uwb, + 473088156567311094933uwb + }; + for (int i = 0; i < 4; ++i) + { + test_575 (s575 + 7 * i, s125 + i, 0); + for (int j = 0; j < 4; ++j) + if (s575[7 * i + 3 + j] != s575[7 * 4 + 4 * i + j]) + __builtin_abort (); + } +#endif +} From patchwork Thu Jul 27 17:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 127076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1248402vqo; Thu, 27 Jul 2023 10:20:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsFDkASXq50KFGaYQiMTxcYOyinGQpzLrHWSqtXYFWoB5vIw8DTTZ+blvMVC7jA8aTD0J3 X-Received: by 2002:a17:907:7857:b0:99b:cf4f:909a with SMTP id lb23-20020a170907785700b0099bcf4f909amr2375271ejc.37.1690478400898; Thu, 27 Jul 2023 10:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690478400; cv=none; d=google.com; s=arc-20160816; b=Po2KOoU7WY+/Bh1BUZW18gB7Wci9N5IMnNWEOV05sXFqmqkvI2xv/Z00T7GmIybV6B 7gUrgP95r9s6Aua/S6uXXQLqtJzuycUgPmhHA9JQBjk4TJ54O4MytSKyzYbkAQsUdTeL RfL51fhBDAmxWQK/SINrK+Uk06GWAR3BZNgks97/WHMnbmxt7N/KU1sAidFEeQ4w+7yg rSqzAgApbBJL2FmZDrrgFS/4vlH4TleL8nhezZ629rQVmBSj3dSo6fQIYWox8ehJ3Y8u HHx1bNX/PfFfo1JCD+6MySDZ7gCUyKgaHrjVJqsPPZZarc7No6neLUMPy+JY/h+0SyEJ w7kw== 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=OL/F+VrP7x24WPxsaWODCsiqcWWD3aMkn4m0Tbx0tWQ=; fh=WsnZmklt8G06AL40EcEdnVgOM8uIHnTd15u+ffpb1ek=; b=aQTeDXguB4R9TXkE/P+JQaa1Ke/AdA15iE6Bm23s87K3XU9hFu4b5L8oq42zXhkLsk UOI+17UMGrivA0nTiFOesOaUB4ScPSzhs2bfnMrq++OK2bb5WIwsFrcnzfWpp6XIDQo3 IuJVF46td3+nR6y43VeGY2GFoFrAwwQbcHo2Y1EsWme0PjjPm0oX2czCGg5fznuGDVje uXwhsy6Dv1JcaTxtkQpTJIMznIZy+kg77nuHmOauzbYmcVyOQwrz48/qGaeYX/D8U+gy Huj5wcOxrD8fY2FF1Z2NOVNhgPHZVB5dY+Zz1HQa/jv0767oggD1rzu5qBY/S46BFHtT E+fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=klj610V7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z24-20020a170906815800b0099bd1dc4c3fsi1325761ejw.154.2023.07.27.10.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:20:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=klj610V7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 AD2A63854822 for ; Thu, 27 Jul 2023 17:19:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD2A63854822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690478346; bh=OL/F+VrP7x24WPxsaWODCsiqcWWD3aMkn4m0Tbx0tWQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=klj610V76co5Qa6cLJ57CJJwW6kJDnaWc4oaBgok0skC0xkMmDz2oCh7DGQT6OKbD 6t3PKFSI3QpPtPBDI+xSApyusA8XgEzmQVh8L7OEgIbUOtn67fZoOUx8Fsx/422y9Y wPJ8vmtdF03Vhm+o+fFRZoGSzuCcr28M3ObjADYI= 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 4A7EB385AF89 for ; Thu, 27 Jul 2023 17:16:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A7EB385AF89 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-255-2M37LfWSPbCpL_1wiDdBFA-1; Thu, 27 Jul 2023 13:16:43 -0400 X-MC-Unique: 2M37LfWSPbCpL_1wiDdBFA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E276D83FC20; Thu, 27 Jul 2023 17:16:42 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E53740C2063; Thu, 27 Jul 2023 17:16:42 +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 36RHGd6v2823103 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 19:16:39 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 36RHGcv82823102; Thu, 27 Jul 2023 19:16:38 +0200 Date: Thu, 27 Jul 2023 19:16:38 +0200 To: gcc-patches@gcc.gnu.org Cc: Richard Biener , "Joseph S. Myers" Subject: [PATCH 5/5] testsuite part 2 for _BitInt support [PR102989] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, 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: 1772595079628649808 X-GMAIL-MSGID: 1772595079628649808 Hi! This is second part of the testcase additions in order to fit into mailing lists limits. Most of these tests are for the floating point conversions, __builtin_*_overflow and -fsanitize=undefined. 2023-07-27 Jakub Jelinek PR c/102989 gcc/testsuite/ * gcc.dg/torture/bitint-20.c: New test. * gcc.dg/torture/bitint-21.c: New test. * gcc.dg/torture/bitint-22.c: New test. * gcc.dg/torture/bitint-23.c: New test. * gcc.dg/torture/bitint-24.c: New test. * gcc.dg/torture/bitint-25.c: New test. * gcc.dg/torture/bitint-26.c: New test. * gcc.dg/torture/bitint-27.c: New test. * gcc.dg/torture/bitint-28.c: New test. * gcc.dg/torture/bitint-29.c: New test. * gcc.dg/torture/bitint-30.c: New test. * gcc.dg/torture/bitint-31.c: New test. * gcc.dg/torture/bitint-32.c: New test. * gcc.dg/torture/bitint-33.c: New test. * gcc.dg/torture/bitint-34.c: New test. * gcc.dg/torture/bitint-35.c: New test. * gcc.dg/torture/bitint-36.c: New test. * gcc.dg/torture/bitint-37.c: New test. * gcc.dg/torture/bitint-38.c: New test. * gcc.dg/torture/bitint-39.c: New test. * gcc.dg/torture/bitint-40.c: New test. * gcc.dg/torture/bitint-41.c: New test. * gcc.dg/ubsan/bitint-1.c: New test. * gcc.dg/ubsan/bitint-2.c: New test. * gcc.dg/ubsan/bitint-3.c: New test. Jakub --- gcc/testsuite/gcc.dg/torture/bitint-20.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-20.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,190 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && int32plus } } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) void +test_135 (_BitInt(135) *p, _BitInt(39) *q, int i) +{ + p[3] = p[0] / p[1]; + p[4] = p[2] / *q; + p[5] = p[i] % p[1 + i]; + p[6] = p[2 + i] % q[i]; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) void +test_192 (_BitInt(192) *p, _BitInt(62) *q, int i) +{ + p[3] = p[0] / p[1]; + p[4] = p[2] / *q; + p[5] = p[i] % p[1 + i]; + p[6] = p[2 + i] % q[i]; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test_575 (_BitInt(575) *p, _BitInt(125) *q, int i) +{ + p[3] = p[0] / p[1]; + p[4] = p[2] / *q; + p[5] = p[i] % p[1 + i]; + p[6] = p[2 + i] % q[i]; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + static _BitInt(135) s135[] = { + 11379259456099690377988816293288418659013wb, + -18507519859761926375595173102925837392wb, + -3487341362606172228883239379216537732914wb, + 0, 0, 0, 0, + -18302253895694594136150902133229wb, + 2910721282054679865681699220999829323779wb, + -17020765241462394475777917185801328548533wb, + 0, 0, 0, 0, + 18652952612120070842749648336935165019219wb, + -1wb, + -2328827552140837061029007041281845428062wb, + 0, 0, 0, 0, + 4586448317141516754412034429451793085778wb, + 302326133131500453732826275685wb, + -13254392454085872482685218784341305341217wb, + 0, 0, 0, 0, + -614wb, + 16712959282178433685159137405wb, + 15642262205867583373380008091954500325wb, + -27731730774wb, + 0wb, + -75263829692564968827327018348wb, + -18302253895694594136150902133229wb, + -35227765213wb, + -18652952612120070842749648336935165019219wb, + 112934753510539598517482519823570410wb, + 0wb, + -3452wb, + 15170532132wb, + -315580772716330297206790923436697746219wb, + 126779339685614070998610275358wb, + -19wb + }; + static _BitInt(39) s39[] = { + -208660914188wb, + 226148009090wb, + -20621wb, + 42wb + }; + for (int i = 0; i < 4; ++i) + { + test_135 (s135 + 7 * i, s39 + i, 0); + for (int j = 0; j < 4; ++j) + if (s135[7 * i + 3 + j] != s135[7 * 4 + 4 * i + j]) + __builtin_abort (); + } +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static _BitInt(192) s192[] = { + -2179289138164349400542345646041597314396798352437085702063wb, + -79910962432789464031897580939163427724139130993wb, + -3036473005246707700116012885952806814462013063553154406939wb, + 0, 0, 0, 0, + 641265343041674918120574087098wb, + -72968858271155659573911879940731439944647195520825153965wb, + 2701717062040203003887103138051480805185032453926240220524wb, + 0, 0, 0, 0, + -841691204113630961349106466971783187865820857103239354134wb, + 3wb, + -87971197399776002207343095550078219wb, + 0, 0, 0, 0, + 1975530920339244356926809414608241391203379490466789216052wb, + -1491609620853264847219953011450130087411551266523269wb, + -1446625088493520499379069533952596205wb, + 0, 0, 0, 0, + 27271466539wb, + 1706692225050149442221770028739016905019wb, + -79245495764706738784157700565393118980948358836wb, + -1501915295097973757wb, + 0wb, + 4771029735868622050569106388224414265428wb, + 641265343041674918120574087098wb, + 333711124246457812wb, + -280563734704543653783035488990594395955273619034413118044wb, + -11314906111712376578wb, + -2wb, + -2479408421589529wb, + -1324428wb, + -11301758503855628901398980734004657wb, + 1373411796501852981487559368499793073469647909100920wb, + -109wb + }; + static _BitInt(62) s62[] = { + -1779156757544544378wb, + 566275460772898254wb, + 7774805776666105wb, + 128wb + }; + for (int i = 0; i < 4; ++i) + { + test_192 (s192 + 7 * i, s62 + i, 0); + for (int j = 0; j < 4; ++j) + if (s192[7 * i + 3 + j] != s192[7 * 4 + 4 * i + j]) + __builtin_abort (); + } +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _BitInt(575) s575[] = { + -46295454425650349106237210715560972814514774894381316941718135777652722445546437187679065682949497046056192846156902024414635126978980056110286059194406244047429103543013567wb, + 8168911130831183937943637579544406842555974190640492967747336926965525847745100099776294868623258477082653103560744709659980631459947315392636659059426713543595666476280533wb, + -35562636740560878776057515364478086997557966107967281638887951768166903062463010597490396666936792092197907362468852658846219038084825902297279012227062238709275022706654710wb, + 0, 0, 0, 0, + 8943720225181967953483417970wb, + -5686323784402794959708902425053022672027524027657863695096812917030055678499948429234881641591266594283291408732579354863768974925810198523510127753699305465302067821wb, + 45545655058039702583745674825335158540648677810736798412180196426599514263661272184545433928331514411963531127261916383264154901783937763805071704477825859668914160192614845wb, + 0, 0, 0, 0, + 50424935157410302671220896696045811569932594372403814676921199727418115659236492512040645301161966980307514350263276765199536014825688175664310129375564263158984wb, + -7wb, + -1570414268527860342275074326241251266943768106178059338676497087694509262100926288185672140837995480549018141550944901112529623354869552332831768648238175848946606383367442wb, + 0, 0, 0, 0, + 33743599683183012321962199340752013311691198627837686174760810997243129260923502613536719907475631360213576483574943246620765095970215288302282988013296681749186377007244629wb, + -241344364975185779312145695113143874342953936016290256207617251781961618409457239212648767218870128884542434148wb, + 264442076257762743508952577439304094891926651736030778233607159152726518015778933421402285405943871924053070093963838538880775338376789919798084050039162wb, + 0, 0, 0, 0, + -5wb, + 5102554304763340573123278154007968305825944534675387388100485979831828339912883404866537264221784637582259122678928387415569088293221166wb, + -5450898771494429416519022817838938601734903941178852102981451142825093206820936688797591339833204660642927328353178476114731969679243479147102763897272676329450771161610902wb, + -27841416716804082903535753217607970wb, + 0wb, + 2845786405948228702992300882035725001599103765023382470517698884483710061812613500615722877137078798659301720051530203483092161498954792wb, + 8943720225181967953483417970wb, + 14857023063025350938701283170104334549wb, + -7203562165344328953031556670863687367133227767486259239560171389631159379890927501720092185880280997186787764323325252171362287832241167952044304196509180451283wb, + 193782868826267453015550702420724985315443493285153355021508389301944425453072371810496604181725982879795555170278476391923261741289049794434571591514767wb, + 3wb, + -5203319495353646668wb, + -139815154526820696318711149230487844769233301636772309388492158wb, + -323204355193745164479045143032958628560847774063940216640778815817376770038460708119250193248428869489076997487384931038wb, + 180305213672139436589458419226578301650781616412684462286468318018185661952458180767935939240752755560277833245wb, + 316649622804067950787613592683370wb + }; + static _BitInt(125) s125[] = { + -6969575357064287919545125499931812390wb, + 16004593655673074838414651760840291513wb, + -8103989160857077722wb, + -818188468095495446473587377169784wb + }; + for (int i = 0; i < 4; ++i) + { + test_575 (s575 + 7 * i, s125 + i, 0); + for (int j = 0; j < 4; ++j) + if (s575[7 * i + 3 + j] != s575[7 * 4 + 4 * i + j]) + __builtin_abort (); + } +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-21.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-21.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,282 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __FLT_MANT_DIG__ == 24 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) _BitInt(135) +testflt_135 (float d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(135) +testfltu_135 (float d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) _BitInt(192) +testflt_192 (float d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(192) +testfltu_192 (float d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +testflt_575 (float d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(575) +testfltu_575 (float d) +{ + return d; +} +#endif +#endif + +#if __DBL_MANT_DIG__ == 53 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) _BitInt(135) +testdbl_135 (double d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(135) +testdblu_135 (double d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) _BitInt(192) +testdbl_192 (double d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(192) +testdblu_192 (double d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +testdbl_575 (double d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(575) +testdblu_575 (double d) +{ + return d; +} +#endif +#endif + +int +main () +{ +#if __FLT_MANT_DIG__ == 24 +#if __BITINT_MAXWIDTH__ >= 135 + static float flt_135[] = { + 0.25f, 0.0f, 1.0f, -42.0f, 16777215.25f, + -50855501824.5f, 39580962846540824576.0f, + -122147759335346835551823516808712814592.0f, + -85070591730234615865843651857942052864.0f + }; + static _BitInt(135) fltr_135[] = { + 0wb, 0wb, 1wb, -42wb, 16777215wb, + -50855501824wb, 39580962846540824576wb, + -122147759335346835551823516808712814592wb, + -85070591730234615865843651857942052864wb + }; + for (int i = 0; i < 9; ++i) + if (testflt_135 (flt_135[i]) != fltr_135[i]) + __builtin_abort (); + static float fltu_135[] = { + 0.125f, 0.0f, 1.0f, 42.59375f, 16777215.75f, + 397530272.5f, 1557145973265213792232550652968960.0f, + 69722182498815269047577928656018735104.0f + }; + static unsigned _BitInt(135) fltur_135[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 16777216uwb, + 397530272uwb, 1557145973265213792232550652968960uwb, + 69722182498815269047577928656018735104uwb + }; + for (int i = 0; i < 8; ++i) + if (testfltu_135 (fltu_135[i]) != fltur_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static float flt_192[] = { + 0.625f, 0.0f, 1.0f, -42.0f, 16777215.25f, + -166724322197504.5f, 7557890186859550768856301568.0f, + 6614377725485260848635133905887821824.0f, + -85070591730234615865843651857942052864.0f + }; + static _BitInt(192) fltr_192[] = { + 0wb, 0wb, 1wb, -42wb, 16777215wb, + -166724322197504wb, 7557890186859550768856301568wb, + 6614377725485260848635133905887821824wb, + -85070591730234615865843651857942052864wb + }; + for (int i = 0; i < 9; ++i) + if (testflt_192 (flt_192[i]) != fltr_192[i]) + __builtin_abort (); + static float fltu_192[] = { + __FLT_MIN__, 0.0f, 1.0f, 42.125f, 16777216.75f, + 2197600337920.75f, 4591683053408742366929307227985543168.0f, + 89668786387864080590151097276117811200.0f + }; + static unsigned _BitInt(192) fltur_192[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 16777216uwb, + 2197600337920uwb, 4591683053408742366929307227985543168uwb, + 89668786387864080590151097276117811200uwb + }; + for (int i = 0; i < 8; ++i) + if (testfltu_192 (fltu_192[i]) != fltur_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static float flt_575[] = { + 0.0001f, 0.0f, 1.0f, -28.0f, 16777214.75f, + -1321998852554752.5f, 3447217350995641328695097279119360.0f, + -153684583933125564944797950598195445760.0f, + -6614377725485260848635133905887821824.0f + }; + static _BitInt(575) fltr_575[] = { + 0wb, 0wb, 1wb, -28wb, 16777215wb, + -1321998852554752wb, 3447217350995641328695097279119360wb, + -153684583933125564944797950598195445760wb, + -6614377725485260848635133905887821824wb + }; + for (int i = 0; i < 9; ++i) + if (testflt_575 (flt_575[i]) != fltr_575[i]) + __builtin_abort (); + static float fltu_575[] = { + 4.0f * __FLT_MIN__, 0.0f, 1.0f, 38.125f, 16777210.75f, + 450604433408.75f, 49420393052787309452540595771398946816.0f, + 144076816645080570490809349637635309568.0f + }; + static unsigned _BitInt(575) fltur_575[] = { + 0uwb, 0uwb, 1uwb, 38uwb, 16777211uwb, + 450604433408uwb, 49420393052787309452540595771398946816uwb, + 144076816645080570490809349637635309568uwb + }; + for (int i = 0; i < 8; ++i) + if (testfltu_575 (fltu_575[i]) != fltur_575[i]) + __builtin_abort (); +#endif +#endif +#if __DBL_MANT_DIG__ == 53 +#if __BITINT_MAXWIDTH__ >= 135 + static double dbl_135[] = { + 0.25, 0.0, 1.0, -42.0, 4294967295.25, + -600381955574889.5, 31830517255028909053694705664.0, + -18738990071541038357046558935673124945920.0, + -21778071482940061661655974875633165533184.0 + }; + static _BitInt(135) dblr_135[] = { + 0wb, 0wb, 1wb, -42wb, 4294967295wb, + -600381955574889wb, 31830517255028909053694705664wb, + -18738990071541038357046558935673124945920wb, + -21778071482940061661655974875633165533183wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testdbl_135 (dbl_135[i]) != dblr_135[i]) + __builtin_abort (); + static double dblu_135[] = { + 0.125, 0.0, 1.0, 42.59375, 4294967295.75, + 1379919377114330.5, 1887176628826898072984354816.0, + 28122698032432725461429202074509590396928.0 + }; + static unsigned _BitInt(135) dblur_135[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb, + 1379919377114330uwb, 1887176628826898072984354816uwb, + 28122698032432725461429202074509590396928uwb + }; + for (int i = 0; i < 8; ++i) + if (testdblu_135 (dblu_135[i]) != dblur_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static double dbl_192[] = { + 0.625, 0.0, 1.0, -42.0, 4294967295.25, + -334692618508390720.5, 7241713824636372052614321786924022698463985664.0, + 1051470826442514757151114043324296190023320100185399361536.0, + -3138550867693340381917894711603833208051177722232017256448.0 + }; + static _BitInt(192) dblr_192[] = { + 0wb, 0wb, 1wb, -42wb, 4294967295wb, + -334692618508390720wb, 7241713824636372052614321786924022698463985664wb, + 1051470826442514757151114043324296190023320100185399361536wb, + -3138550867693340381917894711603833208051177722232017256447wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testdbl_192 (dbl_192[i]) != dblr_192[i]) + __builtin_abort (); + static double dblu_192[] = { + __DBL_MIN__, 0.0, 1.0, 42.125, 4294967296.75, + 85543274084479312.75, 1452517026416706854711122198528.0, + 4878159368183578289135952951143197426988727705359645409280.0 + }; + static unsigned _BitInt(192) dblur_192[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb, + 85543274084479312uwb, 1452517026416706854711122198528uwb, + 4878159368183578289135952951143197426988727705359645409280uwb + }; + for (int i = 0; i < 8; ++i) + if (testdblu_192 (dblu_192[i]) != dblur_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static double dbl_575[] = { + 0.0001, 0.0, 1.0, -28.0, 4294967294.75, + -37518052491018912.5, 103740344328578397848785318842252129922803939603530145015162908477052192630505472.0, + -60264112735379285992549557294906950572505306720710356591257742566415478531569283626542380634430345616295459560427283714375540825055746407845009719778430303250931745441185792.0, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174784.0 + }; + static _BitInt(575) dblr_575[] = { + 0wb, 0wb, 1wb, -28wb, 4294967294wb, + -37518052491018912wb, 103740344328578397848785318842252129922803939603530145015162908477052192630505472wb, + -60264112735379285992549557294906950572505306720710356591257742566415478531569283626542380634430345616295459560427283714375540825055746407845009719778430303250931745441185792wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testdbl_575 (dbl_575[i]) != dblr_575[i]) + __builtin_abort (); + static double dblu_575[] = { + 4.0 * __DBL_MIN__, 0.0, 1.0, 38.125, 4294967297.75, + 138240328005104064.75, 1588129215384992270224118343146332410113351482118715170651778867930903010675691494429363974899842924150784.0, + 106390366882040443685518677989907085524608028099417390750037507495093586319031581000179209552004867195248003952212636389496136628539779816025838629984567658036669448510767104.0 + }; + static unsigned _BitInt(575) dblur_575[] = { + 0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb, + 138240328005104064uwb, 1588129215384992270224118343146332410113351482118715170651778867930903010675691494429363974899842924150784uwb, + 106390366882040443685518677989907085524608028099417390750037507495093586319031581000179209552004867195248003952212636389496136628539779816025838629984567658036669448510767104uwb + }; + for (int i = 0; i < 8; ++i) + if (testdblu_575 (dblu_575[i]) != dblur_575[i]) + __builtin_abort (); +#endif +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-22.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-22.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,282 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __LDBL_MANT_DIG__ == 64 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) _BitInt(135) +testldbl_135 (long double d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(135) +testldblu_135 (long double d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) _BitInt(192) +testldbl_192 (long double d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(192) +testldblu_192 (long double d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +testldbl_575 (long double d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(575) +testldblu_575 (long double d) +{ + return d; +} +#endif +#endif + +#if __FLT128_MANT_DIG__ == 113 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) _BitInt(135) +testflt128_135 (_Float128 d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(135) +testflt128u_135 (_Float128 d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) _BitInt(192) +testflt128_192 (_Float128 d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(192) +testflt128u_192 (_Float128 d) +{ + return d; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +testflt128_575 (_Float128 d) +{ + return d; +} + +__attribute__((noipa)) unsigned _BitInt(575) +testflt128u_575 (_Float128 d) +{ + return d; +} +#endif +#endif + +int +main () +{ +#if __LDBL_MANT_DIG__ == 64 +#if __BITINT_MAXWIDTH__ >= 135 + static long double ldbl_135[] = { + 0.25L, 0.0L, 1.0L, -42.0L, 4294967295.25L, + -8790480341948727187.25L, 27274375615880435204096.0L, + -14925443517338257613013233930892304449536.0L, + -21778071482940061661655974875633165533184.0L + }; + static _BitInt(135) ldblr_135[] = { + 0wb, 0wb, 1wb, -42wb, 4294967295wb, + -8790480341948727187wb, 27274375615880435204096wb, + -14925443517338257613013233930892304449536wb, + -21778071482940061661655974875633165533183wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testldbl_135 (ldbl_135[i]) != ldblr_135[i]) + __builtin_abort (); + static long double ldblu_135[] = { + 0.125L, 0.0L, 1.0L, 42.59375L, 4294967295.75L, + 176563931524327024.5L, 33864941055480177570480471932928.0L, + 25454535165593017203571842988709209178112.0L + }; + static unsigned _BitInt(135) ldblur_135[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb, + 176563931524327024uwb, 33864941055480177570480471932928uwb, + 25454535165593017203571842988709209178112uwb + }; + for (int i = 0; i < 8; ++i) + if (testldblu_135 (ldblu_135[i]) != ldblur_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static long double ldbl_192[] = { + 0.625L, 0.0L, 1.0L, -42.0L, 4294967295.25L, + -5824742198306330891.5L, 440458331210868742661519441920.0L, + 1835666805014205039814897225189119947560942436848001613824.0L, + -3138550867693340381917894711603833208051177722232017256448.0L + }; + static _BitInt(192) ldblr_192[] = { + 0wb, 0wb, 1wb, -42wb, 4294967295wb, + -5824742198306330891wb, 440458331210868742661519441920wb, + 1835666805014205039814897225189119947560942436848001613824wb, + -3138550867693340381917894711603833208051177722232017256447wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testldbl_192 (ldbl_192[i]) != ldblr_192[i]) + __builtin_abort (); + static long double ldblu_192[] = { + __LDBL_MIN__, 0.0L, 1.0L, 42.125L, 4294967296.75L, + 2076918887405157419.75L, 20675944534182826922963677915852149395069559898112.0L, + 5501434424609388038261967254007295028886638351806353113088.0L + }; + static unsigned _BitInt(192) ldblur_192[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb, + 2076918887405157419uwb, 20675944534182826922963677915852149395069559898112uwb, + 5501434424609388038261967254007295028886638351806353113088uwb + }; + for (int i = 0; i < 8; ++i) + if (testldblu_192 (ldblu_192[i]) != ldblur_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static long double ldbl_575[] = { + 0.0001L, 0.0L, 1.0L, -28.0L, 4294967294.75L, + -3665832965020207456.5L, 163698889538251840454153874702336.0L, + 32915174451748642699300864037265677114762093753017270154115822402734463611341115095984060833654391570465670441530007982951775959694729040694137686724336684263404019031998464.0L, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174784.0L + }; + static _BitInt(575) ldblr_575[] = { + 0wb, 0wb, 1wb, -28wb, 4294967294wb, + -3665832965020207456wb, 163698889538251840454153874702336wb, + 32915174451748642699300864037265677114762093753017270154115822402734463611341115095984060833654391570465670441530007982951775959694729040694137686724336684263404019031998464wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testldbl_575 (ldbl_575[i]) != ldblr_575[i]) + __builtin_abort (); + static long double ldblu_575[] = { + 4.0L * __LDBL_MIN__, 0.0L, 1.0L, 38.125L, 4294967297.75L, + 1378703406647015633.75L, 611519358004879551476944320883148018860550235384446976.0L, + 115943866857281393364910134541262519802574312323472821552898049002204954780753923929784955305825114286696121504922573067409422635510048274769753298552619702526028834918105088.0L + }; + static unsigned _BitInt(575) ldblur_575[] = { + 0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb, + 1378703406647015633uwb, 611519358004879551476944320883148018860550235384446976uwb, + 115943866857281393364910134541262519802574312323472821552898049002204954780753923929784955305825114286696121504922573067409422635510048274769753298552619702526028834918105088uwb + }; + for (int i = 0; i < 8; ++i) + if (testldblu_575 (ldblu_575[i]) != ldblur_575[i]) + __builtin_abort (); +#endif +#endif +#if __FLT128_MANT_DIG__ == 113 +#if __BITINT_MAXWIDTH__ >= 135 + static _Float128 flt128_135[] = { + 0.25F128, 0.0F128, 1.0F128, -42.0F128, 4294967295.25F128, + -622114258022893415468272077014949.5F128, 6846686534183872435237780851340978176.0F128, + -18109992041001989671440396535501724581888.0F128, + -21778071482940061661655974875633165533184.0F128 + }; + static _BitInt(135) flt128r_135[] = { + 0wb, 0wb, 1wb, -42wb, 4294967295wb, + -622114258022893415468272077014949wb, 6846686534183872435237780851340978176wb, + -18109992041001989671440396535501724581888wb, + -21778071482940061661655974875633165533183wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testflt128_135 (flt128_135[i]) != flt128r_135[i]) + __builtin_abort (); + static _Float128 flt128u_135[] = { + 0.125F128, 0.0F128, 1.0F128, 42.59375F128, 4294967295.75F128, + 3866883549893778868343627501393297.5F128, 1884508847679496004639718578196282112.0F128, + 40418154190724512480670668005754087145472.0F128 + }; + static unsigned _BitInt(135) flt128ur_135[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb, + 3866883549893778868343627501393297uwb, 1884508847679496004639718578196282112uwb, + 40418154190724512480670668005754087145472uwb + }; + for (int i = 0; i < 8; ++i) + if (testflt128u_135 (flt128u_135[i]) != flt128ur_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static _Float128 flt128_192[] = { + 0.625F128, 0.0F128, 1.0F128, -42.0F128, 4294967295.25F128, + -2985198467222342042164811285508981.5F128, 431282768955649236431442335280406747022360576.0F128, + 1589969577168452878096502186670522088231011726426596442112.0F128, + -3138550867693340381917894711603833208051177722232017256448.0F128 + }; + static _BitInt(192) flt128r_192[] = { + 0wb, 0wb, 1wb, -42wb, 4294967295wb, + -2985198467222342042164811285508981wb, 431282768955649236431442335280406747022360576wb, + 1589969577168452878096502186670522088231011726426596442112wb, + -3138550867693340381917894711603833208051177722232017256447wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testflt128_192 (flt128_192[i]) != flt128r_192[i]) + __builtin_abort (); + static _Float128 flt128u_192[] = { + __FLT128_MIN__, 0.0F128, 1.0F128, 42.125F128, 4294967296.75F128, + 1198221816583045676753413578483973.75F128, 321058543109670204450967161534914741927936.0F128, + 4124250833671183507048495617931376186682553019928355536896.0F128 + }; + static unsigned _BitInt(192) flt128ur_192[] = { + 0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb, + 1198221816583045676753413578483973uwb, 321058543109670204450967161534914741927936uwb, + 4124250833671183507048495617931376186682553019928355536896uwb + }; + for (int i = 0; i < 8; ++i) + if (testflt128u_192 (flt128u_192[i]) != flt128ur_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _Float128 flt128_575[] = { + 0.0001F128, 0.0F128, 1.0F128, -28.0F128, 4294967294.75F128, + -4434536963340205213805292449887836.5F128, 7798956314177801818163892326325236647148010864640.0F128, + -48379475169482975928082617475070980956970510451882414558095669485086407691242420689411465910847147042640064381848760072045866350077715681395831023828798188292450661613699072.0F128, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174784.0F128 + }; + static _BitInt(575) flt128r_575[] = { + 0wb, 0wb, 1wb, -28wb, 4294967294wb, + -4434536963340205213805292449887836wb, 7798956314177801818163892326325236647148010864640wb, + -48379475169482975928082617475070980956970510451882414558095669485086407691242420689411465910847147042640064381848760072045866350077715681395831023828798188292450661613699072wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb + }; + for (int i = 0; i < 9; ++i) + if (testflt128_575 (flt128_575[i]) != flt128r_575[i]) + __builtin_abort (); + static _Float128 flt128u_575[] = { + 4.0F128 * __FLT128_MIN__, 0.0F128, 1.0F128, 38.125F128, 4294967297.75F128, + 1286565442597535616086070715374552.75F128, 2888274376848382435313359223769917404575136171432777745913780227423600640.0F128, + 101012352069182509789055890148950528106809264092697629422634347377509770791198015780931797016594366657511165718215124632216959526129296364564413818230848005073384975475146752.0F128 + }; + static unsigned _BitInt(575) flt128ur_575[] = { + 0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb, + 1286565442597535616086070715374552uwb, 2888274376848382435313359223769917404575136171432777745913780227423600640uwb, + 101012352069182509789055890148950528106809264092697629422634347377509770791198015780931797016594366657511165718215124632216959526129296364564413818230848005073384975475146752uwb + }; + for (int i = 0; i < 8; ++i) + if (testflt128u_575 (flt128u_575[i]) != flt128ur_575[i]) + __builtin_abort (); +#endif +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-23.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-23.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,804 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __FLT_MANT_DIG__ == 24 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) float +testflt_135 (_BitInt(135) b) +{ + return b; +} + +__attribute__((noipa)) float +testfltu_135 (unsigned _BitInt(135) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) float +testflt_192 (_BitInt(192) b) +{ + return b; +} + +__attribute__((noipa)) float +testfltu_192 (unsigned _BitInt(192) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) float +testflt_575 (_BitInt(575) b) +{ + return b; +} + +__attribute__((noipa)) float +testfltu_575 (unsigned _BitInt(575) b) +{ + return b; +} +#endif +#endif + +#if __DBL_MANT_DIG__ == 53 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) double +testdbl_135 (_BitInt(135) b) +{ + return b; +} + +__attribute__((noipa)) double +testdblu_135 (unsigned _BitInt(135) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) double +testdbl_192 (_BitInt(192) b) +{ + return b; +} + +__attribute__((noipa)) double +testdblu_192 (unsigned _BitInt(192) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) double +testdbl_575 (_BitInt(575) b) +{ + return b; +} + +__attribute__((noipa)) double +testdblu_575 (unsigned _BitInt(575) b) +{ + return b; +} +#endif +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + static _BitInt(135) s_135[] = { + -39242093wb, + -36246971635108657318127321wb, + -816440703352wb, + 8409360wb, + 231875wb, + -1859wb, + 8123250453541347379290840008816194983wb, + 42642091wb, + -2499664813007708583619356686wb, + -14022533493907734339644wb, + 737816709430180009697449492wb, + 3094418595787172583521548578719419wb, + 84096wb, + -3856393637064417wb, + 5494wb, + -7227655824382622730861wb, + 185250722103742953wb, + -266695839223233222300219080587185431wb, + 124wb, + -4540724906728461994579131745203067wb, + -34474123wb, + 6171186wb, + -1738448518309495501564259945530043942wb, + 3714wb, + 22759310366655438105064084505115489wb, + -461wb, + -1891475049610273521994429918325638525836wb, + -350wb, + 3721759411106519959861226774340wb, + -42485872965031409753wb, + 4362279409022137273490486629950wb, + 521928664204421037572709995195346211111wb, + -50129wb, + -21525556783117336078661729wb + }; + static unsigned _BitInt(135) u_135[] = { + 773802493804221964748670742461281016363uwb, + 897485218654369665002411485681173uwb, + 37306898634990773758633uwb, + 3uwb, + 920156uwb, + 15230973698181139105641901258312096uwb, + 1383843491123931387484696uwb, + 143810081711544975903357370071668200uwb, + 83615891310230331473978uwb, + 1239150390uwb, + 39792042288uwb, + 20985035121604uwb, + 3700707uwb, + 14510535740825uwb, + 5675982879048653163399531637816917uwb, + 593909622129190124122830uwb, + 413008891327830587264uwb, + 34694483328uwb, + 592129uwb, + 2649uwb, + 154468451808267466822214091328849uwb, + 8905088171048376399858691570634230197204uwb, + 456uwb, + 12101uwb, + 5879086272uwb, + 115170058487623uwb, + 2274163249406113742515726136586945854500uwb, + 63923152267905666653uwb, + 624302860090054295150365837280525227924uwb, + 9uwb, + 5703520721951508439418uwb, + 44653119094uwb, + 1440439605268989101uwb, + 3496654014361uwb + }; +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static _BitInt(192) s_192[] = { + 81945579384314684613279565479277935940wb, + 1640150770700583136800158704601080wb, + 432402469012491481987292073086668wb, + -15369197386440508323548800500962985157137866798390wb, + 217705797486262wb, + 1wb, + -150837356854711044278780637wb, + 1247354027519369533750440146304wb, + -700073531555662209687924602081wb, + -441651351073606706893667405889558445894wb, + -743993151249791392844844248857961054wb, + 1681039wb, + -170386616439159353410812029301398243129730wb, + -97703172400304820221345002831889wb, + 9wb, + 7277656199366069102639319241893wb, + 7201222364wb, + -4671533967546296507223686237333335wb, + 13311155734490577635922550wb, + 76150533189365685907637983428512213977569647wb, + -283560863483321465221194695455688610811wb, + 6438368552004797088499844257634549000496626110080371wb, + 1122038765213390728664343086041576wb, + -9541613313421359977755878156940wb, + 21551012076757076795102244535269250wb, + -4794294047755173531367558272wb, + -5708612827808554221wb, + -2649648007071280662902443553973167294046518180wb, + -35698660478241255546377wb, + -79587921140918wb, + 469393710173925646wb, + -261330983098092746969723637867599382044980841179747207wb, + -115wb, + -1717706681396wb + }; + static unsigned _BitInt(192) u_192[] = { + 87197051833867272589618945858714291675632402028uwb, + 175207476610687227705633653396153452205075322355946uwb, + 289472685412214318981767004188uwb, + 58352315342320048378103056601781218026976uwb, + 68512267071922032916894194298300228491490143452269uwb, + 8654067584750856592691725728280108682858075uwb, + 57027948061283099317671673937496946487124629uwb, + 512829256101uwb, + 8815296701808550493421309771596155666520uwb, + 1918805208198312310092547265227uwb, + 99680639255733807uwb, + 313647272226958893709907781719uwb, + 534434342549592762863366619879590694414818uwb, + 1751643652514709uwb, + 24084146046683127013882581681582087uwb, + 1282076uwb, + 13590701668411111769uwb, + 62207549230439503653uwb, + 144040025133692457990548614076288499046uwb, + 11981724905403945793356785358565398049196880116uwb, + 1823479497818478859136796209626920064416489979129893695uwb, + 4649uwb, + 2095541338428713427585867932062430293488017906261402uwb, + 605377488765896342050766363050545164888333863362uwb, + 11488350477184223uwb, + 9492972359709013710789022084605392630683565515935199uwb, + 36826148417259uwb, + 554404239122129842026250702689uwb, + 2804528919100uwb, + 127uwb, + 66823885107232870336040073990324uwb, + 297736625249uwb, + 3701132312864550550157874952341371502832960625370598966uwb, + 107247048428uwb + }; +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _BitInt(575) s_575[] = { + 822555268170764275096048134868384963633463468104839796862654006268369616wb, + -960580267694575830808697063169243963045681635800151938720065734940592300657700227419337766780029829446319203wb, + 33504080263976494448954627475165765154890874061543914469206217657999706310163279811015042121096338719830090426757797138233202615461wb, + 275983725374553564148936957707321552749wb, + 5534912144897227754137156977371639235252437172582938580045103986268272085395760563838753817115093434280932847973705994570261258933419373885658991359441723005813683395590541wb, + 1412920302762671055711845665320769771488824036206881359103417821581950493952853265134760513685359011001836948515905971331797139790wb, + -262974997977953570994865210107604152900839198803859287819970850481583440338320059wb, + -92488905333378799268618025132022462336176863903734682501838771365453998891689279398wb, + 242604167696163732697906496386839396751068wb, + -3523803651131338645439245946293wb, + -5147220779398204849222374563179412010462379234108857688330486391319694172748210918710342389194957287070617133280194810193962683650761347126311504766504260691wb, + -126995956651641937332005246092202755154992252553028943468563459072746155379181900761169956344678911600wb, + 8137926360495wb, + -15994393111836746332671329788635258wb, + -277068516868681202554828866807401284583187899477211188256772654837767448404666578906477389363058609157862574wb, + 12643256666940489874033990964997310860090310878838229112053311027168830831623703103010815387wb, + 197250790460297242975596746662998763328365874997wb, + 2003391279347376998472wb, + -199877387236416475658211887841938073691092213166438343739wb, + 683783725793437346966376731991835336458591392078548990419792641719902684445391913394174240265031277360362886303597899811253111402611797905136669wb, + 13527430925075101894748577029275389339063875642859674079897983403256wb, + 539267000300803493510458136103246878203019746178696339759252798818676107273127463057162208073142618039409911wb, + 25132435181738021677664552852329012363786311024121402747618663944355967806315928846073722774898wb, + -24501129715197464074815490290653wb, + -26621511339033230503491791253914731850253401wb, + 219726795681725191949095808767196099036895435893837474958165415185577738548053399820419849wb, + 142706206515281341916417852232439287400819155237127620529348000437671770471697052705666056232742428920527wb, + -1272097813202031618710288063584910456400985264371503722255927680393419899507092728461wb, + 104580584066897755717617980935051171929519336855902844943415231226523598033953128466889325153396268078513996620240379420239887wb, + -10163452549280413821027501723364683075067110986059205073343287754152825761658667193285948456506970145368258900765489010580419998927374372004822965287098902519382wb, + -1462817702603947401421838547412731208810505797188084686210372939517152226213737422286025118826482655559744680456146694118022879735528111700409wb, + -1004473459167555639043426932334304398038355185104669wb, + 383945882095471823332216311173956104021530654187057868803605149628498470119801535759629951357637987556377174553957515312582545289930138018wb, + 147266903774875157001493887893421901156259749590403482558013070wb + }; + static unsigned _BitInt(575) u_575[] = { + 340315902121482071031uwb, + 9193736781349493374149172723522049938732355975055uwb, + 121133456126887617775249483436586396232697894267611535022240817951287068117843073672uwb, + 1253811282917666038992497uwb, + 279807426767721176279253888473522991149118862415710500804613956730247764438409575562386uwb, + 4763192686302836059965684032432862167583119264783uwb, + 19433750446582365356875213925336734177599085624532213292961813424848222698351037862663241858724337375675uwb, + 8615689860907972907203187028321798323548254692780962654211537619771698680316938530412569744897459065621193843349775333790731199245018643579445580816793381624810616262uwb, + 126055589776274659515356020606486923511478187977197128509709117843059226901071386846700207970626608150351060714322162254429913496135590117225450775153364768928781244uwb, + 34636325529158225079379169125604752070369970834816893592982969115088710130160324580864333959889906313467177163564702338046445540uwb, + 2295982750677874548137685137480985649627965059590627454944uwb, + 22288650253829612832302454550260146151077393473uwb, + 61551827uwb, + 948415991495935226718622697967024251064408554619458611515264819726244946850447758605031396753280209023664964305741301009407513619686102uwb, + 7599947921908039117808602805272900633862767543347735124983729771592896283177667324402886239291446uwb, + 3064098671438076295010586583414642866550259610904044948559784636731818131096680869327433283805326015689481397549653557650965154282598345191654721039973597171695049076467uwb, + 26163216482276433755253744705785501134309546797499410671258175352214852627310317854549342428286751107453875459uwb, + 1083530146709801198539441549736949256980046185455966999062614188586191607484611079705240990524552846829821534154580456458426794497253838343299379036578711641930103uwb, + 241446995995054305582384233456322509709013171336859127uwb, + 224319712854uwb, + 1851847735563213275uwb, + 3517907813008404838784133683859253992uwb, + 57026061017409510123542169719303829618100077009666501089739966522905673377916488253uwb, + 218054639772618074096850378810323560503313926757275788155487065187235936858569852576120793613879980uwb, + 1035184782769221379uwb, + 20229959242348674822834301353257599618846169820699281424077697412860273533283192155424030349307384555863768665398854990uwb, + 48688062002166777196074419660880812175599377353811333642743225865182422320253615211852611218169059717666168172585704763331192485699241038689921302806665184uwb, + 38974159722814402881994907079236516884965127718714589284306855526034875317101125387287977578141556918226042568695412232uwb, + 195268331869690963115384309853070889302314974440838447729079592004150231uwb, + 131384791058457562831689753115846222538215620945564207628285200123621656731679644407994773520965uwb, + 1334982489788592107403503927792629194402uwb, + 2146uwb, + 25165296015221802429838428736907886uwb, + 6254uwb + }; +#endif +#if __FLT_MANT_DIG__ == 24 +#if __BITINT_MAXWIDTH__ >= 135 + static float flt_135[] = { + -39242092.0f, + -36246971272809749294350336.0f, + -816440672256.0f, + 8409360.0f, + 231875.0f, + -1859.0f, + 8123250192256220137057345512566423552.0f, + 42642092.0f, + -2499664867657543876622680064.0f, + -14022533900570342719488.0f, + 737816710112426075969552384.0f, + 3094418676109759732222008215207936.0f, + 84096.0f, + -3856393689890816.0f, + 5494.0f, + -7227655905181068951552.0f, + 185250718389633024.0f, + -266695840144413128032863408636297216.0f, + 124.0f, + -4540724759502527537506259606437888.0f, + -34474124.0f, + 6171186.0f, + -1738448585705717460364844982721314816.0f, + 3714.0f, + 22759309744814802127092016612376576.0f, + -461.0f, + -__builtin_inff (), + -350.0f, + 3721759435945004998144961806336.0f, + -42485872567125016576.0f, + 4362279465016690611605542535168.0f, + __builtin_inff (), + -50129.0f, + -21525556388157878481977344.0f + }; + static float fltu_135[] = { + __builtin_inff (), + 897485251387475481828390233702400.0f, + 37306898327013391597568.0f, + 3.0f, + 920156.0f, + 15230974228367008360756701604872192.0f, + 1383843467413878101508096.0f, + 143810078160377684059996776503967744.0f, + 83615893330389964423168.0f, + 1239150336.0f, + 39792041984.0f, + 20985036144640.0f, + 3700707.0f, + 14510535475200.0f, + 5675982933774352481468669797335040.0f, + 593909606786098794594304.0f, + 413008901830615236608.0f, + 34694483968.0f, + 592129.0f, + 2649.0f, + 154468455934475733304034734374912.0f, + __builtin_inff (), + 456.0f, + 12101.0f, + 5879086080.0f, + 115170059747328.0f, + __builtin_inff (), + 63923151928943443968.0f, + __builtin_inff (), + 9.0f, + 5703520697688581472256.0f, + 44653117440.0f, + 1440439672101666816.0f, + 3496654143488.0f + }; + for (int i = 0; i < 34; ++i) + if (testflt_135 (s_135[i]) != flt_135[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testfltu_135 (u_135[i]) != fltu_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static float flt_192[] = { + 81945579470551984745273979116049137664.0f, + 1640150781354328003699743106531328.0f, + 432402474830816591643797717254144.0f, + -__builtin_inff (), + 217705802104832.0f, + 1.0f, + -150837356860384332849610752.0f, + 1247354020200583118196884635648.0f, + -700073528334631668550369017856.0f, + -__builtin_inff (), + -743993169284474461872900775245512704.0f, + 1681039.0f, + -__builtin_inff (), + -97703169989152795899105082605568.0f, + 9.0f, + 7277656062827612295463998324736.0f, + 7201222144.0f, + -4671533860148685993668956641034240.0f, + 13311155535609252557094912.0f, + __builtin_inff (), + -283560864177100653079149659746813870080.0f, + __builtin_inff (), + 1122038754191063555360632711675904.0f, + -9541613258608657772880016179200.0f, + 21551010941830070997495077018796032.0f, + -4794294027361853497357107200.0f, + -5708612694366486528.0f, + -__builtin_inff (), + -35698660648279573790720.0f, + -79587925032960.0f, + 469393711604695040.0f, + -__builtin_inff (), + -115.0f, + -1717706686464.0f + }; + static float fltu_192[] = { + __builtin_inff (), + __builtin_inff (), + 289472678477035675109665275904.0f, + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + 512829259776.0f, + __builtin_inff (), + 1918805247503610004149880487936.0f, + 99680641842413568.0f, + 313647265860414511058971000832.0f, + __builtin_inff (), + 1751643624308736.0f, + 24084145747217780385007409962156032.0f, + 1282076.0f, + 13590701491613597696.0f, + 62207548751752462336.0f, + 144040024354059546360660309323802476544.0f, + __builtin_inff (), + __builtin_inff (), + 4649.0f, + __builtin_inff (), + __builtin_inff (), + 11488350322032640.0f, + __builtin_inff (), + 36826148503552.0f, + 554404238373758103887118598144.0f, + 2804528971776.0f, + 127.0f, + 66823887263746144234653953818624.0f, + 297736634368.0f, + __builtin_inff (), + 107247050752.0f + }; + for (int i = 0; i < 34; ++i) + if (testflt_192 (s_192[i]) != flt_192[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testfltu_192 (u_192[i]) != fltu_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static float flt_575[] = { + __builtin_inff (), + -__builtin_inff (), + __builtin_inff (), + 275983721032549254738830597716881440768.0f, + __builtin_inff (), + __builtin_inff (), + -__builtin_inff (), + -__builtin_inff (), + __builtin_inff (), + -3523803575380752640275405340672.0f, + -__builtin_inff (), + -__builtin_inff (), + 8137926508544.0f, + -15994393281493713095582868026949632.0f, + -__builtin_inff (), + __builtin_inff (), + __builtin_inff (), + 2003391250601164668928.0f, + -__builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + -24501130336514943435685610127360.0f, + -__builtin_inff (), + __builtin_inff (), + __builtin_inff (), + -__builtin_inff (), + __builtin_inff (), + -__builtin_inff (), + -__builtin_inff (), + -__builtin_inff (), + __builtin_inff (), + __builtin_inff () + }; + static float fltu_575[] = { + 340315913217135083520.0f, + __builtin_inff (), + __builtin_inff (), + 1253811215516794865319936.0f, + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + 61551828.0f, + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + 224319717376.0f, + 1851847786157309952.0f, + 3517907886717368541269560933367152640.0f, + __builtin_inff (), + __builtin_inff (), + 1035184768712441856.0f, + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + __builtin_inff (), + 2146.0f, + 25165295728767510106569460506689536.0f, + 6254.0f + }; + for (int i = 0; i < 34; ++i) + if (testflt_575 (s_575[i]) != flt_575[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testfltu_575 (u_575[i]) != fltu_575[i]) + __builtin_abort (); +#endif +#endif +#if __DBL_MANT_DIG__ == 53 +#if __BITINT_MAXWIDTH__ >= 135 + static double dbl_135[] = { + -39242093.0, + -36246971635108657531715584.0, + -816440703352.0, + 8409360.0, + 231875.0, + -1859.0, + 8123250453541346905042562585110511616.0, + 42642091.0, + -2499664813007708750469922816.0, + -14022533493907733348352.0, + 737816709430180073007218688.0, + 3094418595787172340280288631324672.0, + 84096.0, + -3856393637064417.0, + 5494.0, + -7227655824382622695424.0, + 185250722103742944.0, + -266695839223233236177082217685581824.0, + 124.0, + -4540724906728462124105811223379968.0, + -34474123.0, + 6171186.0, + -1738448518309495524665904679484391424.0, + 3714.0, + 22759310366655439518928576500989952.0, + -461.0, + -1891475049610273567723258005078180626432.0, + -350.0, + 3721759411106519834940439265280.0, + -42485872965031411712.0, + 4362279409022137156015669379072.0, + 521928664204421058633672118513103273984.0, + -50129.0, + -21525556783117337240797184.0 + }; + static double dblu_135[] = { + 773802493804221992623001034499154771968.0, + 897485218654369723848104601452544.0, + 37306898634990774386688.0, + 3.0, + 920156.0, + 15230973698181137968871516305096704.0, + 1383843491123931258028032.0, + 143810081711544982658521010624528384.0, + 83615891310230336700416.0, + 1239150390.0, + 39792042288.0, + 20985035121604.0, + 3700707.0, + 14510535740825.0, + 5675982879048652786568565738176512.0, + 593909622129190116524032.0, + 413008891327830556672.0, + 34694483328.0, + 592129.0, + 2649.0, + 154468451808267468485637384962048.0, + 8905088171048376547587929854079236308992.0, + 456.0, + 12101.0, + 5879086272.0, + 115170058487623.0, + 2274163249406113722963963066981556420608.0, + 63923152267905662976.0, + 624302860090054299856857502421553774592.0, + 9.0, + 5703520721951508135936.0, + 44653119094.0, + 1440439605268989184.0, + 3496654014361.0 + }; + for (int i = 0; i < 34; ++i) + if (testdbl_135 (s_135[i]) != dbl_135[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testdblu_135 (u_135[i]) != dblu_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static double dbl_192[] = { + 81945579384314687557742233571238608896.0, + 1640150770700583037463354142621696.0, + 432402469012491501348574281596928.0, + -15369197386440508938509968376382119346509732380672.0, + 217705797486262.0, + 1.0, + -150837356854711041828847616.0, + 1247354027519369502575283929088.0, + -700073531555662276303601532928.0, + -441651351073606679519160525300938309632.0, + -743993151249791396098631688421113856.0, + 1681039.0, + -170386616439159361826828161968707433660416.0, + -97703172400304826279491553722368.0, + 9.0, + 7277656199366069333121407385600.0, + 7201222364.0, + -4671533967546296379435628906938368.0, + 13311155734490577941561344.0, + 76150533189365686624757419076841278552408064.0, + -283560863483321472582205283908875976704.0, + 6438368552004797730833578371043525700779108699471872.0, + 1122038765213390753205991088586752.0, + -9541613313421359725756721135616.0, + 21551012076757076520029583197601792.0, + -4794294047755173506637103104.0, + -5708612827808553984.0, + -2649648007071280532341234166535418312753414144.0, + -35698660478241256505344.0, + -79587921140918.0, + 469393710173925632.0, + -261330983098092727670915068943820759127419298070396928.0, + -115.0, + -1717706681396.0 + }; + static double dblu_192[] = { + 87197051833867272390202829166908318800909697024.0, + 175207476610687217879860344599290566299997853188096.0, + 289472685412214309690412105728.0, + 58352315342320052737011578650960945217536.0, + 68512267071922037583525562378571212344840731754496.0, + 8654067584750856522039960763727020807946240.0, + 57027948061283101680073163019018106591772672.0, + 512829256101.0, + 8815296701808550079625439512864915193856.0, + 1918805208198312244509799350272.0, + 99680639255733808.0, + 313647272226958910616850399232.0, + 534434342549592748637063994840786615140352.0, + 1751643652514709.0, + 24084146046683127568067882664329216.0, + 1282076.0, + 13590701668411111424.0, + 62207549230439505920.0, + 144040025133692463994664792383004082176.0, + 11981724905403944877595374666928320404518862848.0, + 1823479497818478827998416063488921051624645800235106304.0, + 4649.0, + 2095541338428713553559812835366404384524126144954368.0, + 605377488765896315082607405999750595789425999872.0, + 11488350477184224.0, + 9492972359709013522794710883315474336917948771336192.0, + 36826148417259.0, + 554404239122129838954063593472.0, + 2804528919100.0, + 127.0, + 66823885107232869968562331058176.0, + 297736625249.0, + 3701132312864550589964164920177814261972243111315767296.0, + 107247048428.0 + }; + for (int i = 0; i < 34; ++i) + if (testdbl_192 (s_192[i]) != dbl_192[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testdblu_192 (u_192[i]) != dblu_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static double dbl_575[] = { + 822555268170764297634225399451759946746992540590809881338557024729825280.0, + -960580267694575822855611495941585347204287976360447994911667455476231250947192048882720653908949004193890304.0, + 33504080263976494977558165276907141142985667083206076858318677497395449849522674033540660299812700936436629271063580537369602818048.0, + 275983725374553560382241222733294731264.0, + 5534912144897227981721785252365318913099024300479520929615780375858014135428545244514013933284386952701873840884059278413011909801315647098618874845818373456314285330268160.0, + 1412920302762670981724654587829101441064363178039081649317449002875219686863615617096481906597938056255380563207859934619548778496.0, + -262974997977953547412616819382246513411941636601411079958856272578116216992825344.0, + -92488905333378800887332041285981414442679115849793894833270926171369794209000194048.0, + 242604167696163745705487164545064266366976.0, + -3523803651131338905043794395136.0, + -5147220779398204956062097693667869669268514878983078506579452381903246893001528080183706343394366450560829994902536411900094807055106480897434592050304516096.0, + -126995956651641932664992814931771424612524306428042763656077526441611704177400372487041993300114407424.0, + 8137926360495.0, + -15994393111836745817684083180830720.0, + -277068516868681208843378539444762089120272250101874770818281861285776026097252118136221894703961747524419584.0, + 12643256666940490094502018407000917191440297183002304612995222607645672663994449919572180992.0, + 197250790460297249337611855831853736085011038208.0, + 2003391279347377111040.0, + -199877387236416487880239440186867935179678108631030562816.0, + 683783725793437376953847532054635915450883103104150353591684114076623183460343349044869993313461680324691804857056989176851941526653681669242880.0, + 13527430925075103137395594360375039920265895975276069404569617039360.0, + 539267000300803467143224409095377978528526384444410994726548852694612047977432378724606879533366903144710144.0, + 25132435181738021158181758368227989609664280796006529821958155232496895580737809559413590065152.0, + -24501129715197465145324272091136.0, + -26621511339033229577933593130365525581365248.0, + 219726795681725203086615878008721704050996541338139327356409273606611142342004775592132608.0, + 142706206515281338563561427905630882997359612390115520631287147248801675296196390219660900162069776564224.0, + -1272097813202031695774673850580967606153271008283204619545732236750677292631566843904.0, + 104580584066897764106493049954563517551311873970918028573957449051117037877644455167894862496406485527470814840408584063287296.0, + -10163452549280414266636885849517652803498703924514090324303688401722691539656540095676077155202913299163727204412770763270991539282383353646632785170429061890048.0, + -1462817702603947424514705987528105462111189926351038186632282100495484739291866737828490405005509893174352599206536639203945990323918788886528.0, + -1004473459167555693379448563952458083163231922159616.0, + 383945882095471809778477642717090299126500715170441296829413124731981221073489411436597060515704853514279862909459893170581511755452645376.0, + 147266903774875160122803299680751368800498930915627484017852416.0 + }; + static double dblu_575[] = { + 340315902121482059776.0, + 9193736781349493621405581031201638729956693377024.0, + 121133456126887614949840563267333164930922114527830924098169755757644187539060293632.0, + 1253811282917665907146752.0, + 279807426767721167224232624903862775521562023356169096523467570552357504424852523581440.0, + 4763192686302836266016084152796744123294035214336.0, + 19433750446582363914783523863519537892469170046699527182095230312993931481088146791402683275534315552768.0, + 8615689860907973684813089916677872622369301590036773127424335682014143120538819857749267776316706246365207593078790418785926108454964638864284607647395585351338688512.0, + 126055589776274664055563357164473926765229686711256362550309370211691455811892471436667901827515295553040869973224666092493870267949222939304809964524921924217733120.0, + 34636325529158225609732004478359404024810355780116436151965488784911880463832346975056353708910319963631363476007842111096356864.0, + 2295982750677874440830690242430022722310395038479306194944.0, + 22288650253829611656582899585105561922738061312.0, + 61551827.0, + 948415991495935277158065207187216102893971687538169358437498088171511819979329197955070708594226287655578579327935243978625908341735424.0, + 7599947921908039201020389523460283262016591366306988284476594385856376859892071911998135440769024.0, + 3064098671438076262631558926659124050612030123593391586289496610357367704588066201089697403929948683093930760302363801622713089626566308942422673109893593769913375260672.0, + 26163216482276434323059552752807045466093212833119225389172469300377369630622147477953596829696868035573317632.0, + 1083530146709801287488575139896111218252634145778954464029109940268038137024528653987999105697728348938546608345738475665376063185384327227976954513446733080428544.0, + 241446995995054294694559180878245213888164982782164992.0, + 224319712854.0, + 1851847735563213312.0, + 3517907813008404560136740290886107136.0, + 57026061017409511227244639666735331364603008817984523485318163959373956415485902848.0, + 218054639772618086702097627512642011917064593803091900409463425864524464099706282773581011770933248.0, + 1035184782769221376.0, + 20229959242348673341261734187831508959698424427160892456742004821954487315365414763816110107652513076773401171962363904.0, + 48688062002166779121886848500298978377358186775166569744218208875095511886249915901603271262547063601222998163903380246886122115788425950691666910366400512.0, + 38974159722814403783188765470424741900583576369459629735378952745201038923704525454001059605107694314700748523810324480.0, + 195268331869690962780067959053006275481517082721312675880802634445094912.0, + 131384791058457555617616111281677184113372650274571562034279153020161645779289769480396688326656.0, + 1334982489788592098527293353260669206528.0, + 2146.0, + 25165296015221801457062319885385728.0, + 6254.0 + }; + for (int i = 0; i < 34; ++i) + if (testdbl_575 (s_575[i]) != dbl_575[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testdblu_575 (u_575[i]) != dblu_575[i]) + __builtin_abort (); +#endif +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-24.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-24.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,804 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __LDBL_MANT_DIG__ == 64 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) long double +testldbl_135 (_BitInt(135) b) +{ + return b; +} + +__attribute__((noipa)) long double +testldblu_135 (unsigned _BitInt(135) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) long double +testldbl_192 (_BitInt(192) b) +{ + return b; +} + +__attribute__((noipa)) long double +testldblu_192 (unsigned _BitInt(192) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) long double +testldbl_575 (_BitInt(575) b) +{ + return b; +} + +__attribute__((noipa)) long double +testldblu_575 (unsigned _BitInt(575) b) +{ + return b; +} +#endif +#endif + +#if __FLT128_MANT_DIG__ == 113 +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) _Float128 +testflt128_135 (_BitInt(135) b) +{ + return b; +} + +__attribute__((noipa)) _Float128 +testflt128u_135 (unsigned _BitInt(135) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) _Float128 +testflt128_192 (_BitInt(192) b) +{ + return b; +} + +__attribute__((noipa)) _Float128 +testflt128u_192 (unsigned _BitInt(192) b) +{ + return b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _Float128 +testflt128_575 (_BitInt(575) b) +{ + return b; +} + +__attribute__((noipa)) _Float128 +testflt128u_575 (unsigned _BitInt(575) b) +{ + return b; +} +#endif +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + static _BitInt(135) s_135[] = { + -39242093wb, + -36246971635108657318127321wb, + -816440703352wb, + 8409360wb, + 231875wb, + -1859wb, + 8123250453541347379290840008816194983wb, + 42642091wb, + -2499664813007708583619356686wb, + -14022533493907734339644wb, + 737816709430180009697449492wb, + 3094418595787172583521548578719419wb, + 84096wb, + -3856393637064417wb, + 5494wb, + -7227655824382622730861wb, + 185250722103742953wb, + -266695839223233222300219080587185431wb, + 124wb, + -4540724906728461994579131745203067wb, + -34474123wb, + 6171186wb, + -1738448518309495501564259945530043942wb, + 3714wb, + 22759310366655438105064084505115489wb, + -461wb, + -1891475049610273521994429918325638525836wb, + -350wb, + 3721759411106519959861226774340wb, + -42485872965031409753wb, + 4362279409022137273490486629950wb, + 521928664204421037572709995195346211111wb, + -50129wb, + -21525556783117336078661729wb + }; + static unsigned _BitInt(135) u_135[] = { + 773802493804221964748670742461281016363uwb, + 897485218654369665002411485681173uwb, + 37306898634990773758633uwb, + 3uwb, + 920156uwb, + 15230973698181139105641901258312096uwb, + 1383843491123931387484696uwb, + 143810081711544975903357370071668200uwb, + 83615891310230331473978uwb, + 1239150390uwb, + 39792042288uwb, + 20985035121604uwb, + 3700707uwb, + 14510535740825uwb, + 5675982879048653163399531637816917uwb, + 593909622129190124122830uwb, + 413008891327830587264uwb, + 34694483328uwb, + 592129uwb, + 2649uwb, + 154468451808267466822214091328849uwb, + 8905088171048376399858691570634230197204uwb, + 456uwb, + 12101uwb, + 5879086272uwb, + 115170058487623uwb, + 2274163249406113742515726136586945854500uwb, + 63923152267905666653uwb, + 624302860090054295150365837280525227924uwb, + 9uwb, + 5703520721951508439418uwb, + 44653119094uwb, + 1440439605268989101uwb, + 3496654014361uwb + }; +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static _BitInt(192) s_192[] = { + 81945579384314684613279565479277935940wb, + 1640150770700583136800158704601080wb, + 432402469012491481987292073086668wb, + -15369197386440508323548800500962985157137866798390wb, + 217705797486262wb, + 1wb, + -150837356854711044278780637wb, + 1247354027519369533750440146304wb, + -700073531555662209687924602081wb, + -441651351073606706893667405889558445894wb, + -743993151249791392844844248857961054wb, + 1681039wb, + -170386616439159353410812029301398243129730wb, + -97703172400304820221345002831889wb, + 9wb, + 7277656199366069102639319241893wb, + 7201222364wb, + -4671533967546296507223686237333335wb, + 13311155734490577635922550wb, + 76150533189365685907637983428512213977569647wb, + -283560863483321465221194695455688610811wb, + 6438368552004797088499844257634549000496626110080371wb, + 1122038765213390728664343086041576wb, + -9541613313421359977755878156940wb, + 21551012076757076795102244535269250wb, + -4794294047755173531367558272wb, + -5708612827808554221wb, + -2649648007071280662902443553973167294046518180wb, + -35698660478241255546377wb, + -79587921140918wb, + 469393710173925646wb, + -261330983098092746969723637867599382044980841179747207wb, + -115wb, + -1717706681396wb + }; + static unsigned _BitInt(192) u_192[] = { + 87197051833867272589618945858714291675632402028uwb, + 175207476610687227705633653396153452205075322355946uwb, + 289472685412214318981767004188uwb, + 58352315342320048378103056601781218026976uwb, + 68512267071922032916894194298300228491490143452269uwb, + 8654067584750856592691725728280108682858075uwb, + 57027948061283099317671673937496946487124629uwb, + 512829256101uwb, + 8815296701808550493421309771596155666520uwb, + 1918805208198312310092547265227uwb, + 99680639255733807uwb, + 313647272226958893709907781719uwb, + 534434342549592762863366619879590694414818uwb, + 1751643652514709uwb, + 24084146046683127013882581681582087uwb, + 1282076uwb, + 13590701668411111769uwb, + 62207549230439503653uwb, + 144040025133692457990548614076288499046uwb, + 11981724905403945793356785358565398049196880116uwb, + 1823479497818478859136796209626920064416489979129893695uwb, + 4649uwb, + 2095541338428713427585867932062430293488017906261402uwb, + 605377488765896342050766363050545164888333863362uwb, + 11488350477184223uwb, + 9492972359709013710789022084605392630683565515935199uwb, + 36826148417259uwb, + 554404239122129842026250702689uwb, + 2804528919100uwb, + 127uwb, + 66823885107232870336040073990324uwb, + 297736625249uwb, + 3701132312864550550157874952341371502832960625370598966uwb, + 107247048428uwb + }; +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _BitInt(575) s_575[] = { + 822555268170764275096048134868384963633463468104839796862654006268369616wb, + -960580267694575830808697063169243963045681635800151938720065734940592300657700227419337766780029829446319203wb, + 33504080263976494448954627475165765154890874061543914469206217657999706310163279811015042121096338719830090426757797138233202615461wb, + 275983725374553564148936957707321552749wb, + 5534912144897227754137156977371639235252437172582938580045103986268272085395760563838753817115093434280932847973705994570261258933419373885658991359441723005813683395590541wb, + 1412920302762671055711845665320769771488824036206881359103417821581950493952853265134760513685359011001836948515905971331797139790wb, + -262974997977953570994865210107604152900839198803859287819970850481583440338320059wb, + -92488905333378799268618025132022462336176863903734682501838771365453998891689279398wb, + 242604167696163732697906496386839396751068wb, + -3523803651131338645439245946293wb, + -5147220779398204849222374563179412010462379234108857688330486391319694172748210918710342389194957287070617133280194810193962683650761347126311504766504260691wb, + -126995956651641937332005246092202755154992252553028943468563459072746155379181900761169956344678911600wb, + 8137926360495wb, + -15994393111836746332671329788635258wb, + -277068516868681202554828866807401284583187899477211188256772654837767448404666578906477389363058609157862574wb, + 12643256666940489874033990964997310860090310878838229112053311027168830831623703103010815387wb, + 197250790460297242975596746662998763328365874997wb, + 2003391279347376998472wb, + -199877387236416475658211887841938073691092213166438343739wb, + 683783725793437346966376731991835336458591392078548990419792641719902684445391913394174240265031277360362886303597899811253111402611797905136669wb, + 13527430925075101894748577029275389339063875642859674079897983403256wb, + 539267000300803493510458136103246878203019746178696339759252798818676107273127463057162208073142618039409911wb, + 25132435181738021677664552852329012363786311024121402747618663944355967806315928846073722774898wb, + -24501129715197464074815490290653wb, + -26621511339033230503491791253914731850253401wb, + 219726795681725191949095808767196099036895435893837474958165415185577738548053399820419849wb, + 142706206515281341916417852232439287400819155237127620529348000437671770471697052705666056232742428920527wb, + -1272097813202031618710288063584910456400985264371503722255927680393419899507092728461wb, + 104580584066897755717617980935051171929519336855902844943415231226523598033953128466889325153396268078513996620240379420239887wb, + -10163452549280413821027501723364683075067110986059205073343287754152825761658667193285948456506970145368258900765489010580419998927374372004822965287098902519382wb, + -1462817702603947401421838547412731208810505797188084686210372939517152226213737422286025118826482655559744680456146694118022879735528111700409wb, + -1004473459167555639043426932334304398038355185104669wb, + 383945882095471823332216311173956104021530654187057868803605149628498470119801535759629951357637987556377174553957515312582545289930138018wb, + 147266903774875157001493887893421901156259749590403482558013070wb + }; + static unsigned _BitInt(575) u_575[] = { + 340315902121482071031uwb, + 9193736781349493374149172723522049938732355975055uwb, + 121133456126887617775249483436586396232697894267611535022240817951287068117843073672uwb, + 1253811282917666038992497uwb, + 279807426767721176279253888473522991149118862415710500804613956730247764438409575562386uwb, + 4763192686302836059965684032432862167583119264783uwb, + 19433750446582365356875213925336734177599085624532213292961813424848222698351037862663241858724337375675uwb, + 8615689860907972907203187028321798323548254692780962654211537619771698680316938530412569744897459065621193843349775333790731199245018643579445580816793381624810616262uwb, + 126055589776274659515356020606486923511478187977197128509709117843059226901071386846700207970626608150351060714322162254429913496135590117225450775153364768928781244uwb, + 34636325529158225079379169125604752070369970834816893592982969115088710130160324580864333959889906313467177163564702338046445540uwb, + 2295982750677874548137685137480985649627965059590627454944uwb, + 22288650253829612832302454550260146151077393473uwb, + 61551827uwb, + 948415991495935226718622697967024251064408554619458611515264819726244946850447758605031396753280209023664964305741301009407513619686102uwb, + 7599947921908039117808602805272900633862767543347735124983729771592896283177667324402886239291446uwb, + 3064098671438076295010586583414642866550259610904044948559784636731818131096680869327433283805326015689481397549653557650965154282598345191654721039973597171695049076467uwb, + 26163216482276433755253744705785501134309546797499410671258175352214852627310317854549342428286751107453875459uwb, + 1083530146709801198539441549736949256980046185455966999062614188586191607484611079705240990524552846829821534154580456458426794497253838343299379036578711641930103uwb, + 241446995995054305582384233456322509709013171336859127uwb, + 224319712854uwb, + 1851847735563213275uwb, + 3517907813008404838784133683859253992uwb, + 57026061017409510123542169719303829618100077009666501089739966522905673377916488253uwb, + 218054639772618074096850378810323560503313926757275788155487065187235936858569852576120793613879980uwb, + 1035184782769221379uwb, + 20229959242348674822834301353257599618846169820699281424077697412860273533283192155424030349307384555863768665398854990uwb, + 48688062002166777196074419660880812175599377353811333642743225865182422320253615211852611218169059717666168172585704763331192485699241038689921302806665184uwb, + 38974159722814402881994907079236516884965127718714589284306855526034875317101125387287977578141556918226042568695412232uwb, + 195268331869690963115384309853070889302314974440838447729079592004150231uwb, + 131384791058457562831689753115846222538215620945564207628285200123621656731679644407994773520965uwb, + 1334982489788592107403503927792629194402uwb, + 2146uwb, + 25165296015221802429838428736907886uwb, + 6254uwb + }; +#endif +#if __LDBL_MANT_DIG__ == 64 +#if __BITINT_MAXWIDTH__ >= 135 + static long double ldbl_135[] = { + -39242093.0L, + -36246971635108657317806080.0L, + -816440703352.0L, + 8409360.0L, + 231875.0L, + -1859.0L, + 8123250453541347379469761730828042240.0L, + 42642091.0L, + -2499664813007708583503069184.0L, + -14022533493907734339584.0L, + 737816709430180009723559936.0L, + 3094418595787172583474668509331456.0L, + 84096.0L, + -3856393637064417.0L, + 5494.0L, + -7227655824382622730752.0L, + 185250722103742953.0L, + -266695839223233222305995365384454144.0L, + 124.0L, + -4540724906728461994627321936478208.0L, + -34474123.0L, + 6171186.0L, + -1738448518309495501607474587347451904.0L, + 3714.0L, + 22759310366655438104798293506654208.0L, + -461.0L, + -1891475049610273521975332702278492618752.0L, + -350.0L, + 3721759411106519959735009017856.0L, + -42485872965031409752.0L, + 4362279409022137273388535644160.0L, + 521928664204421037567490386336795328512.0L, + -50129.0L, + -21525556783117336078974976.0L + }; + static long double ldblu_135[] = { + 773802493804221964731523995050312728576.0L, + 897485218654369665019834468925440.0L, + 37306898634990773757952.0L, + 3.0L, + 920156.0L, + 15230973698181139106030422216146944.0L, + 1383843491123931387527168.0L, + 143810081711544975903121569568784384.0L, + 83615891310230331473920.0L, + 1239150390.0L, + 39792042288.0L, + 20985035121604.0L, + 3700707.0L, + 14510535740825.0L, + 5675982879048653163182084577034240.0L, + 593909622129190124126208.0L, + 413008891327830587264.0L, + 34694483328.0L, + 592129.0L, + 2649.0L, + 154468451808267466823175803764736.0L, + 8905088171048376400013977264402823380992.0L, + 456.0L, + 12101.0L, + 5879086272.0L, + 115170058487623.0L, + 2274163249406113742443724808818842927104.0L, + 63923152267905666652.0L, + 624302860090054295134491019551908560896.0L, + 9.0L, + 5703520721951508439552.0L, + 44653119094.0L, + 1440439605268989101.0L, + 3496654014361.0L + }; + for (int i = 0; i < 34; ++i) + if (testldbl_135 (s_135[i]) != ldbl_135[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testldblu_135 (u_135[i]) != ldblu_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static long double ldbl_192[] = { + 81945579384314684615486553814565126144.0L, + 1640150770700583136824020921483264.0L, + 432402469012491481997169632739328.0L, + -15369197386440508323699427265690859620608677773312.0L, + 217705797486262.0L, + 1.0L, + -150837356854711044278321152.0L, + 1247354027519369533773926367232.0L, + -700073531555662209714428575744.0L, + -441651351073606706894128730685912907776.0L, + -743993151249791392856039956714356736.0L, + 1681039.0L, + -170386616439159353411571089494999662854144.0L, + -97703172400304820218983461421056.0L, + 9.0L, + 7277656199366069102773721366528.0L, + 7201222364.0L, + -4671533967546296507225268333576192.0L, + 13311155734490577636425728.0L, + 76150533189365685909073333864980807126351872.0L, + -283560863483321465221954398498764881920.0L, + 6438368552004797088286842127358606670130187958484992.0L, + 1122038765213390728647299370582016.0L, + -9541613313421359977544883896320.0L, + 21551012076757076794749160467202048.0L, + -4794294047755173531333165056.0L, + -5708612827808554221.0L, + -2649648007071280662943908311143037314611019776.0L, + -35698660478241255546880.0L, + -79587921140918.0L, + 469393710173925646.0L, + -261330983098092746965490195259240226746743657452273664.0L, + -115.0L, + -1717706681396.0L + }; + static long double ldblu_192[] = { + 87197051833867272588273235452569162784769572864.0L, + 175207476610687227706687797568524886702441101262848.0L, + 289472685412214318984721334272.0L, + 58352315342320048378267314962278412976128.0L, + 68512267071922032918571353538687014836972935970816.0L, + 8654067584750856592762121211182827528257536.0L, + 57027948061283099315414259852803440866492416.0L, + 512829256101.0L, + 8815296701808550493422802574317577043968.0L, + 1918805208198312310068180156416.0L, + 99680639255733807.0L, + 313647272226958893711859122176.0L, + 534434342549592762879721307175636579647488.0L, + 1751643652514709.0L, + 24084146046683127014125128497758208.0L, + 1282076.0L, + 13590701668411111769.0L, + 62207549230439503652.0L, + 144040025133692457990249596390545031168.0L, + 11981724905403945793671003738109723829870788608.0L, + 1823479497818478859069120464961329580751135834288160768.0L, + 4649.0L, + 2095541338428713427646614015896834392659590161367040.0L, + 605377488765896342059796742106757546391141089280.0L, + 11488350477184223.0L, + 9492972359709013711015472005202975871148440705564672.0L, + 36826148417259.0L, + 554404239122129842012080308224.0L, + 2804528919100.0L, + 127.0L, + 66823885107232870337998237990912.0L, + 297736625249.0L, + 3701132312864550550087325046630338074858031302905430016.0L, + 107247048428.0L + }; + for (int i = 0; i < 34; ++i) + if (testldbl_192 (s_192[i]) != ldbl_192[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testldblu_192 (u_192[i]) != ldblu_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static long double ldbl_575[] = { + 822555268170764275077806657331958312785072234722196584950240570089930752.0L, + -960580267694575830812783278498171621690403946709581436518965868233794729994615679173272606109483012722786304.0L, + 33504080263976494448478492229617991564043478238504231331124912879329149376584163966764611121993710792934518914942887118335291424768.0L, + 275983725374553564145377013770043260928.0L, + 5534912144897227754208044441151874379702287612174069453950291607680839007181861996360330547973886690095069343864416739797783816199380471673982675880600014677768303758278656.0L, + 1412920302762671055675563434211562120848328209741725967322941102900395775694793728702679689406728724040334624347456855689117302784.0L, + -262974997977953570989611804750151836163609455430948784164618597359252696534614016.0L, + -92488905333378799268155556881914668962189440213360997930258834387927208673968914432.0L, + 242604167696163732690645137756322057420800.0L, + -3523803651131338645559050240000.0L, + -5147220779398204849257508190774210744388677252688140210517976277065981842998232251783846790859222005317012238819263034139406832143929230632126090335152504832.0L, + -126995956651641937331951286489675247329200371648605762035297081195775007184684091195737834711064510464.0L, + 8137926360495.0L, + -15994393111836746332220340607909888.0L, + -277068516868681202557212831225058932276240633526059351948516115207300877649787450206685852465539880786591744.0L, + 12643256666940489873646135309702875993528109590137490134559735498193302898793674757994708992.0L, + 197250790460297242979551814062140644203109023744.0L, + 2003391279347376998528.0L, + -199877387236416475651341878965641904464653154051860463616.0L, + 683783725793437346957771892228315489408774085809131650337993219889398577200119614673432810174598052160906191944536223932553104679193775255322624.0L, + 13527430925075101895119202629107559447133788166435502697026955509760.0L, + 539267000300803493497377352922791719626542478240740953329921195747662290582499442246914945221535539392413696.0L, + 25132435181738021677436908541817803462240416694341366601465742717478799945180412844899030794240.0L, + -24501129715197464074399946637312.0L, + -26621511339033230503970770955171473406296064.0L, + 219726795681725191947197274288751751131300579623020247100319392523607242309690678380068864.0L, + 142706206515281341912722598102787801262511939753862115682796537774690209934320984609531887855849227419648.0L, + -1272097813202031618686076349197106943277274743836448162114522403548727854475931287552.0L, + 104580584066897755721462109894862071102150680746488173021715848651881249493019658369304827516906027223482984669789074019581952.0L, + -10163452549280413820781685181828332647679763634230328394877439998644536448688077844493834184118223902098524496370094218227350253632267534838755399334577766924288.0L, + -1462817702603947401460379075968185573663143558708148172616668782116177216739740002633588435639151707520878885121466080144202470951229168025600.0L, + -1004473459167555639022590826165981346984598475636736.0L, + 383945882095471823335289502673360394820076368186253637060368537085404663434451033274997076104121125319917967630183508209073164612376985600.0L, + 147266903774875157000698971886464128985498372744856873180594176.0L + }; + static long double ldblu_575[] = { + 340315902121482071040.0L, + 9193736781349493374213713986696905438099568328704.0L, + 121133456126887617773526383630522733268849231796244390648544501184867233045273378816.0L, + 1253811282917666039005184.0L, + 279807426767721176282774705066477746529679092594765002865548096525989858075665567318016.0L, + 4763192686302836060022861615709466380079764340736.0L, + 19433750446582365356243841895010508514709904909750555910761104889681456249932954817669662897799021199360.0L, + 8615689860907972907222987015567999691990010815316564361117521521881809095333131098584672097178927461838400993199702306526955489286031755082939241644835174978131329024.0L, + 126055589776274659510297467904389237873624120132406221380350474491493460160959938222126650105936552657875183912780356083785858555181180003532557375481178518259236864.0L, + 34636325529158225078961380771473094521787740905726267965061232731631589683984587408777114033008811740835389841050115225879052288.0L, + 2295982750677874548189777005986107945005083683202176909312.0L, + 22288650253829612832625936906216823076906074112.0L, + 61551827.0L, + 948415991495935226723497275802282711176800359354343687935431821975740085005513640520546841077796705045317773075243223746142080749010944.0L, + 7599947921908039117650085272592622557045482160051694630122205426595170751482611426300682100015104.0L, + 3064098671438076294956291179633525016992278379765933214428836815032632500735568461039018643426109912566222922020667353487719095386222010158443081500511850171532585205760.0L, + 26163216482276433754726515355485427397196865766902718455812787467581155703138962108081214195725927010405449728.0L, + 1083530146709801198518741455890332623877113096673714750194062874316360337538555304664904549334408175509822671036217297610308526225295574707709647653730601851158528.0L, + 241446995995054305577613396367243923288085288827486208.0L, + 224319712854.0L, + 1851847735563213275.0L, + 3517907813008404838855514029591363584.0L, + 57026061017409510124756586261527283120773656504559685146885133984875447971917856768.0L, + 218054639772618074103918318492639949832541424857847525973689094242831096606721142712632506945896448.0L, + 1035184782769221379.0L, + 20229959242348674822030474865930581759882432185790556800837709536659306775612115303354290565630013099091822016569802752.0L, + 48688062002166777197217906565531932202748743487730562775775885775077288260863868471270436338269362633469095873857458641986964902395586782692041797794791424.0L, + 38974159722814402882041466859823829059112658796999627209873147217197515116287035613100423934964813946613319590312148992.0L, + 195268331869690963115301358617419463247405494910442809797401817422757888.0L, + 131384791058457562832910671881942611444639653628436820141165072497889292487990472973483579015168.0L, + 1334982489788592107381730508641253982208.0L, + 2146.0L, + 25165296015221802429839839397412864.0L, + 6254.0L + }; + for (int i = 0; i < 34; ++i) + if (testldbl_575 (s_575[i]) != ldbl_575[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testldblu_575 (u_575[i]) != ldblu_575[i]) + __builtin_abort (); +#endif +#endif +#if __FLT128_MANT_DIG__ == 113 +#if __BITINT_MAXWIDTH__ >= 135 + static _Float128 flt128_135[] = { + -39242093.0F128, + -36246971635108657318127321.0F128, + -816440703352.0F128, + 8409360.0F128, + 231875.0F128, + -1859.0F128, + 8123250453541347379290840008816194560.0F128, + 42642091.0F128, + -2499664813007708583619356686.0F128, + -14022533493907734339644.0F128, + 737816709430180009697449492.0F128, + 3094418595787172583521548578719419.0F128, + 84096.0F128, + -3856393637064417.0F128, + 5494.0F128, + -7227655824382622730861.0F128, + 185250722103742953.0F128, + -266695839223233222300219080587185440.0F128, + 124.0F128, + -4540724906728461994579131745203067.0F128, + -34474123.0F128, + 6171186.0F128, + -1738448518309495501564259945530043904.0F128, + 3714.0F128, + 22759310366655438105064084505115488.0F128, + -461.0F128, + -1891475049610273521994429918325638430720.0F128, + -350.0F128, + 3721759411106519959861226774340.0F128, + -42485872965031409753.0F128, + 4362279409022137273490486629950.0F128, + 521928664204421037572709995195346190336.0F128, + -50129.0F128, + -21525556783117336078661729.0F128 + }; + static _Float128 flt128u_135[] = { + 773802493804221964748670742461281075200.0F128, + 897485218654369665002411485681173.0F128, + 37306898634990773758633.0F128, + 3.0F128, + 920156.0F128, + 15230973698181139105641901258312096.0F128, + 1383843491123931387484696.0F128, + 143810081711544975903357370071668192.0F128, + 83615891310230331473978.0F128, + 1239150390.0F128, + 39792042288.0F128, + 20985035121604.0F128, + 3700707.0F128, + 14510535740825.0F128, + 5675982879048653163399531637816917.0F128, + 593909622129190124122830.0F128, + 413008891327830587264.0F128, + 34694483328.0F128, + 592129.0F128, + 2649.0F128, + 154468451808267466822214091328849.0F128, + 8905088171048376399858691570634230595584.0F128, + 456.0F128, + 12101.0F128, + 5879086272.0F128, + 115170058487623.0F128, + 2274163249406113742515726136586945953792.0F128, + 63923152267905666653.0F128, + 624302860090054295150365837280525221888.0F128, + 9.0F128, + 5703520721951508439418.0F128, + 44653119094.0F128, + 1440439605268989101.0F128, + 3496654014361.0F128, + }; + for (int i = 0; i < 34; ++i) + if (testflt128_135 (s_135[i]) != flt128_135[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testflt128u_135 (u_135[i]) != flt128u_135[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static _Float128 flt128_192[] = { + 81945579384314684613279565479277936640.0F128, + 1640150770700583136800158704601080.0F128, + 432402469012491481987292073086668.0F128, + -15369197386440508323548800500962985275185701060608.0F128, + 217705797486262.0F128, + 1.0F128, + -150837356854711044278780637.0F128, + 1247354027519369533750440146304.0F128, + -700073531555662209687924602081.0F128, + -441651351073606706893667405889558413312.0F128, + -743993151249791392844844248857961088.0F128, + 1681039.0F128, + -170386616439159353410812029301398240755712.0F128, + -97703172400304820221345002831889.0F128, + 9.0F128, + 7277656199366069102639319241893.0F128, + 7201222364.0F128, + -4671533967546296507223686237333335.0F128, + 13311155734490577635922550.0F128, + 76150533189365685907637983428512210753683456.0F128, + -283560863483321465221194695455688622080.0F128, + 6438368552004797088499844257634549357780509986390016.0F128, + 1122038765213390728664343086041576.0F128, + -9541613313421359977755878156940.0F128, + 21551012076757076795102244535269248.0F128, + -4794294047755173531367558272.0F128, + -5708612827808554221.0F128, + -2649648007071280662902443553973167373493993472.0F128, + -35698660478241255546377.0F128, + -79587921140918.0F128, + 469393710173925646.0F128, + -261330983098092746969723637867599366653101971873988608.0F128, + -115.0F128, + -1717706681396.0F128 + }; + static _Float128 flt128u_192[] = { + 87197051833867272589618945858714289326891466752.0F128, + 175207476610687227705633653396153448946982933495808.0F128, + 289472685412214318981767004188.0F128, + 58352315342320048378103056601781215690752.0F128, + 68512267071922032916894194298300226631128387158016.0F128, + 8654067584750856592691725728280108697911296.0F128, + 57027948061283099317671673937496946996412416.0F128, + 512829256101.0F128, + 8815296701808550493421309771596155584512.0F128, + 1918805208198312310092547265227.0F128, + 99680639255733807.0F128, + 313647272226958893709907781719.0F128, + 534434342549592762863366619879590707855360.0F128, + 1751643652514709.0F128, + 24084146046683127013882581681582088.0F128, + 1282076.0F128, + 13590701668411111769.0F128, + 62207549230439503653.0F128, + 144040025133692457990548614076288499712.0F128, + 11981724905403945793356785358565397335132602368.0F128, + 1823479497818478859136796209626919944362858664695955456.0F128, + 4649.0F128, + 2095541338428713427585867932062430298743231209275392.0F128, + 605377488765896342050766363050545174870818291712.0F128, + 11488350477184223.0F128, + 9492972359709013710789022084605392379617455653257216.0F128, + 36826148417259.0F128, + 554404239122129842026250702689.0F128, + 2804528919100.0F128, + 127.0F128, + 66823885107232870336040073990324.0F128, + 297736625249.0F128, + 3701132312864550550157874952341371337719347203092250624.0F128, + 107247048428.0F128 + }; + for (int i = 0; i < 34; ++i) + if (testflt128_192 (s_192[i]) != flt128_192[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testflt128u_192 (u_192[i]) != flt128u_192[i]) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _Float128 flt128_575[] = { + 822555268170764275096048134868384975231305202380698070398256893835345920.0F128, + -960580267694575830808697063169243925424347053477730475548747760281578375092219925810414573005477242346668032.0F128, + 33504080263976494448954627475165766133582184724974885918953650948043300306793972216863395126909133067122418159809305365193504587776.0F128, + 275983725374553564148936957707321540608.0F128, + 5534912144897227754137156977371639095192412221957522338641107839687274928618580082609389790489874004597965113744368228739650952266120186965187634240183436521269153476116480.0F128, + 1412920302762671055711845665320769739585982745090302228751251561257591917233120715027663177911819317605963828665882521916923707392.0F128, + -262974997977953570994865210107604174211285573449595140085961138156042539763761152.0F128, + -92488905333378799268618025132022457141142846570320249542701164032605273639863975936.0F128, + 242604167696163732697906496386839380754432.0F128, + -3523803651131338645439245946293.0F128, + -5147220779398204849222374563179412133730483913244844947741095427844771020506369407923839149503287374038736861390994705329184147880909168291858806583886610432.0F128, + -126995956651641937332005246092202760396991711130361124184051111962275756857424469430504968451843424256.0F128, + 8137926360495.0F128, + -15994393111836746332671329788635258.0F128, + -277068516868681202554828866807401284897736575250260327862135188106751832616437168642952110232327515317207040.0F128, + 12643256666940489874033990964997310311509982541568852403544135424197738165753506401380990976.0F128, + 197250790460297242975596746662998771990764978176.0F128, + 2003391279347376998472.0F128, + -199877387236416475658211887841938078116745459015943716864.0F128, + 683783725793437346966376731991835350216389560350369725901413018663785858547865033572885485563448799017573485017347368404816660544180811049467904.0F128, + 13527430925075101894748577029275390536381026872613143284679822016512.0F128, + 539267000300803493510458136103246882259019817595681864105782809148075261013592028608675098514927074416787456.0F128, + 25132435181738021677664552852329012575221796248107329953164935247044160207130354864627942162432.0F128, + -24501129715197464074815490290653.0F128, + -26621511339033230503491791253914733242220544.0F128, + 219726795681725191949095808767196088027323027463729625239897408186970438805069530998505472.0F128, + 142706206515281341916417852232439290189748851664859866651282555201592789754864805842059991220441617268736.0F128, + -1272097813202031618710288063584910381967486400606337174633920325485235383013308628992.0F128, + 104580584066897755717617980935051170305797669115984125432799736278374300011999760896397625133977276440200975782266619201323008.0F128, + -10163452549280413821027501723364683055953700133730297193238300661557892457130680244331940377983114543931479834308368189407852102459256936746559008186557007921152.0F128, + -1462817702603947401421838547412731245576629932826602450317303690796368281340685443455159080277069867736216994863788876540424722028886424027136.0F128, + -1004473459167555639043426932334304453164309296447488.0F128, + 383945882095471823332216311173956128684860565442900813809054240626596219564185981250247929792487147923720686617427927221102360379955085312.0F128, + 147266903774875157001493887893421894471609745020407505370480640.0F128 + }; + static _Float128 flt128u_575[] = { + 340315902121482071031.0F128, + 9193736781349493374149172723522049989237037596672.0F128, + 121133456126887617775249483436586393077503068671965236572261282102895601164339904512.0F128, + 1253811282917666038992497.0F128, + 279807426767721176279253888473523001912720192704990464927491539867791671603022985691136.0F128, + 4763192686302836059965684032432862322867369410560.0F128, + 19433750446582365356875213925336732513880424973437320406724993874129714386347241802580335495811686203392.0F128, + 8615689860907972907203187028321797859877386013383767881250826182682427913148188824772809437492048511967461413139431335435390421932095562711387007040942408370667651072.0F128, + 126055589776274659515356020606486933259536337762793314648917307764206055685941649262118277933003906979239670868955670671312897309994725986907806357486538234999603200.0F128, + 34636325529158225079379169125604750695785810484482739930710385070599465675115027923570016766582469711320673437462251387815460864.0F128, + 2295982750677874548137685137480985746757882615322149650432.0F128, + 22288650253829612832302454550260146257726013440.0F128, + 61551827.0F128, + 948415991495935226718622697967024239258764159275032239689900905479457935391294424204960412146551901344394652585549587358170098052366336.0F128, + 7599947921908039117808602805272900645537701743475990438308994289927813380793983514791799884349440.0F128, + 3064098671438076295010586583414642942579869059363710430687661115226367832562244997089071440248013792356608654440236754254640577193658338300579944911876551907294312398848.0F128, + 26163216482276433755253744705785501643665555701904644656073951369763934041725743914298920119135277939192496128.0F128, + 1083530146709801198539441549736949272615707866142747675126337487600174059213906750437224937669383865518151504262638122920877713397402240447485732907072897115226112.0F128, + 241446995995054305582384233456322524985744615968604160.0F128, + 224319712854.0F128, + 1851847735563213275.0F128, + 3517907813008404838784133683859253760.0F128, + 57026061017409510123542169719303831161096310734855482941686454210514675616939245568.0F128, + 218054639772618074096850378810323562095353038053985944696037552052916135283715799629412817614929920.0F128, + 1035184782769221379.0F128, + 20229959242348674822834301353257600173306714018005091825486635184900252137125196224692061477495530409091482128339697664.0F128, + 48688062002166777196074419660880812364369698930536203875840059698600317657977119368587792531578529291152047948106379901115479025495192432692355212848922624.0F128, + 38974159722814402881994907079236517852974167599450685098668223152330886687288507721175784841029076691372600892770484224.0F128, + 195268331869690963115384309853070885336463825745125450367383853651197952.0F128, + 131384791058457562831689753115846222841883611947373268365763186683292391066729693706687923355648.0F128, + 1334982489788592107403503927792629186560.0F128, + 2146.0F128, + 25165296015221802429838428736907888.0F128, + 6254.0F128 + }; + for (int i = 0; i < 34; ++i) + if (testflt128_575 (s_575[i]) != flt128_575[i]) + __builtin_abort (); + for (int i = 0; i < 34; ++i) + if (testflt128u_575 (u_575[i]) != flt128u_575[i]) + __builtin_abort (); +#endif +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-25.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-25.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,91 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint && float16_runtime } } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ +/* { dg-add-options float16 } */ + +int +main () +{ +#if __FLT16_MANT_DIG__ == 11 + static volatile _Float16 s[] = { + 0.0F16, + 42.0F16, + -65504.0F16, + 65504.0F16 + }; + static volatile _Float16 u[] = { + 0.0F16, + 1.0F16, + 178.0F16, + 65504.0F16 + }; +#if __BITINT_MAXWIDTH__ >= 135 + static volatile _BitInt(135) s_135[] = { + 0wb, + 42wb, + -65504wb, + 65504wb + }; + static volatile unsigned _BitInt(135) u_135[] = { + 0uwb, + 1uwb, + 178uwb, + 65504uwb + }; + for (int i = 0; i < 4; ++i) + { + if (s[i] != (_Float16) s_135[i] + || u[i] != (_Float16) u_135[i] + || (_BitInt(135)) s[i] != s_135[i] + || (unsigned _BitInt(135)) u[i] != u_135[i]) + __builtin_abort (); + } +#endif +#if __BITINT_MAXWIDTH__ >= 192 + static volatile _BitInt(192) s_192[] = { + 0wb, + 42wb, + -65504wb, + 65504wb + }; + static volatile unsigned _BitInt(192) u_192[] = { + 0uwb, + 1uwb, + 178uwb, + 65504uwb + }; + for (int i = 0; i < 4; ++i) + { + if (s[i] != (_Float16) s_192[i] + || u[i] != (_Float16) u_192[i] + || (_BitInt(192)) s[i] != s_192[i] + || (unsigned _BitInt(192)) u[i] != u_192[i]) + __builtin_abort (); + } +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static volatile _BitInt(575) s_575[] = { + 0wb, + 42wb, + -65504wb, + 65504wb + }; + static volatile unsigned _BitInt(575) u_575[] = { + 0uwb, + 1uwb, + 178uwb, + 65504uwb + }; + for (int i = 0; i < 4; ++i) + { + if (s[i] != (_Float16) s_575[i] + || u[i] != (_Float16) u_575[i] + || (_BitInt(575)) s[i] != s_575[i] + || (unsigned _BitInt(575)) u[i] != u_575[i]) + __builtin_abort (); + } +#endif +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-26.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-26.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,66 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) _BitInt(135) +test_135 (_BitInt(135) x) +{ + return x; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) unsigned _BitInt(192) +test_192 (unsigned _BitInt(192) x) +{ + return x; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) _BitInt(575) +test_575 (_BitInt(575) x) +{ + return x; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + if (test_135 (-3544625980220396993429741165699996713118wb) + != -3544625980220396993429741165699996713118wb) + __builtin_abort (); + if (test_135 (2169804wb) != 2169804wb) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 192 + if (test_192 (3548247468860296534428690122730090696161878417599647607527uwb) + != 3548247468860296534428690122730090696161878417599647607527uwb) + __builtin_abort (); + if (test_192 (2169804wb) != 2169804wb) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 575 + if (test_575 (-33874713055088145128482141398907153733216500583643955589065159154103468056485975553675944430696955474989655597693729139818286384955989466009330817447458608627989731550807841wb) + != -33874713055088145128482141398907153733216500583643955589065159154103468056485975553675944430696955474989655597693729139818286384955989466009330817447458608627989731550807841wb) + __builtin_abort (); + if (test_575 (-3433547832854987708194667330190358661244810661613962474981319303539871wb) + != -3433547832854987708194667330190358661244810661613962474981319303539871wb) + __builtin_abort (); + if (test_575 (-49693319wb) != -49693319wb) + __builtin_abort (); + if (test_575 (57563058931861084391041643822550577259264793697002277417254009715684553274763772399490655207001200602249198262962055591804634113396033194657392511369609233430583407788096333wb) + != 57563058931861084391041643822550577259264793697002277417254009715684553274763772399490655207001200602249198262962055591804634113396033194657392511369609233430583407788096333wb) + __builtin_abort (); + if (test_575 (158093724114624905837287422406159616673122916308832353wb) + != 158093724114624905837287422406159616673122916308832353wb) + __builtin_abort (); + if (test_575 (3807354285642wb) != 3807354285642wb) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-27.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-27.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,373 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +int expected; + +__attribute__((noipa)) void +test (int x, int y, int z) +{ + (void) x; + (void) y; + if (z != expected) + __builtin_abort (); +} + +#if __BITINT_MAXWIDTH__ >= 135 +__attribute__((noipa)) void +test_135 (_BitInt(135) a) +{ + switch (a) + { + case -33841133710wb: + test (1, 2, 1); break; + case -55283508608004252890371630137wb: + test (2, 3, 2); break; + case -1065119162618253595246332535wb: + test (3, 4, 3); break; + case 265225687803630460135wb: + test (4, 5, 4); break; + case 12802219454007328327057691wb: + test (5, 6, 5); break; + case -59157301wb: + test (6, 7, 6); break; + case 28029296819738wb: + test (7, 8, 7); break; + case 23771967952817687922824184198772908114wb: + test (8, 9, 8); break; + case -528wb: + test (10, 9, 9); break; + case -21743705968wb: + test (11, 8, 10); break; + case 3761322442803929370621734404255158wb: + test (12, 7, 11); break; + case 7581882536870984828946588790215963wb: + test (13, 6, 12); break; + case -3601335158354600803149652143011wb: + test (14, 5, 13); break; + case 104802210847691888333394846958wb: + test (15, 4, 14); break; + case 145823237253137988087297wb: + test (16, 3, 15); break; + case 3871725619091wb: + test (17, 2, 16); break; + case -480987385702wb: + test (18, 1, 17); break; + case -1084968414543030wb: + test (19, 0, 18); break; + case -12928976wb: + test (20, -1, 19); break; + case -268774wb: + test (21, -2, 20); break; + case 532464351235328336949014678wb: + test (22, -3, 21); break; + case -1145290618187237284790705482290160wb: + test (23, -4, 22); break; + case -249459466889744wb: + test (24, -5, 23); break; + case -1403065236wb: + test (25, 1, 24); break; + case -25456270573862478377606wb: + test (26, 2, 25); break; + case 33340794611915791wb: + test (27, 3, 26); break; + case -674079586163272813wb: + test (28, 4, 27); break; + case -41952758959718119236303556590897001668wb: + test (29, 5, 28); break; + case 2947453415wb: + test (30, 6, 29); break; + case -677wb: + test (31, 7, 30); break; + case -463646803422851872253575745194919wb: + test (32, 8, 31); break; + case -71367919591514155952975401251963194wb: + test (33, 7, 32); break; + case -14346961913818709867962386609601wb: + test (34, 6, 33); break; + case 690wb: + test (35, 5, 34); break; + default: + test (36, 4, 35); break; + break; + } +} +#endif + +#if __BITINT_MAXWIDTH__ >= 192 +__attribute__((noipa)) int +test_192 (unsigned _BitInt(192) a) +{ + switch (a) + { + case 1505160143063006983093195408894239764415303566721254616896uwb + 48: + case 1505160143063006983093195408894239764415303566721254616896uwb + 49: + case 1505160143063006983093195408894239764415303566721254616896uwb + 50: + case 1505160143063006983093195408894239764415303566721254616896uwb + 51: + case 1505160143063006983093195408894239764415303566721254616896uwb + 52: + case 1505160143063006983093195408894239764415303566721254616896uwb + 53: + case 1505160143063006983093195408894239764415303566721254616896uwb + 54: + case 1505160143063006983093195408894239764415303566721254616896uwb + 55: + case 1505160143063006983093195408894239764415303566721254616896uwb + 56: + case 1505160143063006983093195408894239764415303566721254616896uwb + 57: + case 1505160143063006983093195408894239764415303566721254616896uwb + 65: + case 1505160143063006983093195408894239764415303566721254616896uwb + 66: + case 1505160143063006983093195408894239764415303566721254616896uwb + 67: + case 1505160143063006983093195408894239764415303566721254616896uwb + 68: + case 1505160143063006983093195408894239764415303566721254616896uwb + 69: + case 1505160143063006983093195408894239764415303566721254616896uwb + 70: + return 1; + default: + return 0; + } +} +#endif + +#if __BITINT_MAXWIDTH__ >= 574 +__attribute__((noipa)) void +test_574 (unsigned _BitInt(574) a) +{ + switch (a) + { + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891246uwb: + test (22, -3, 1); break; + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891247uwb: + test (23, -4, 2); break; + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891248uwb: + test (24, -5, 3); break; + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891249uwb: + test (25, 1, 4); break; + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891250uwb: + test (26, 2, 5); break; + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891251uwb: + test (27, 3, 6); break; + case 6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891257uwb: + test (28, 4, 7); break; + default: + test (29, 5, 8); break; + break; + } +} +#endif + +#if __BITINT_MAXWIDTH__ >= 575 +__attribute__((noipa)) void +test_575 (_BitInt(575) a) +{ + switch (a) + { + case 57158236877324191282832099954551676419657688516114213070568173374483038461911230482096734270573673572006270803057167488583704wb: + test (1, 2, 1); break; + case 55932752002978259755258693759201176077252755664748wb: + test (2, 3, 2); break; + case -4218363291370143377367234486177453689054229233132334373089588356145503900632432151470684730299990106009156255994430506676467506300235609892554834254413957477779209219867825wb: + test (3, 4, 3); break; + case -19380856704203460544565443028wb: + test (4, 5, 4); break; + case 37691457600250454282496246135038751153145234859661859831059667050412054918743986000946778819692986258358820458161034213280wb: + test (5, 6, 5); break; + case 827003152758795459486819489974390601625339063627401335603123746581523657253393870961575744071183196915560771288079061574485309986042624106685495948664669wb: + test (6, 7, 6); break; + case 2001882657256786505981789524889669355393757203160978wb: + test (7, 8, 7); break; + case 2273951349206310803215316642428483249009583047771549wb: + test (8, 9, 8); break; + case -63640037492105525397657594648433413082358686497544854829581174487203243151113011293858381773246wb: + test (10, 9, 9); break; + case -5043989193130150016980754467018673356423436330428309162407512361831163237wb: + test (11, 8, 10); break; + case -86904413785414524864201428752820860524832869110219388825241400306401wb: + test (12, 7, 11); break; + case -7159581406wb: + test (13, 6, 12); break; + case -430416863734662045942802859497964wb: + test (14, 5, 13); break; + case -282099469984391093781566wb: + test (15, 4, 14); break; + case 259191242782270578340350840252447902477249511321245827805053349778984004438373803812874430619356951005300429wb: + test (16, 3, 15); break; + case -17427431700557396203431wb: + test (17, 2, 16); break; + case -324305733281944621534wb: + test (18, 1, 17); break; + case 39167932287702074309519944575154814029176054304655900600154735991016090154633448789399330wb: + test (19, 0, 18); break; + case 198828227576458371467364915441164050473274232622009526563856039032wb: + test (20, -1, 19); break; + case 7522018863556878842079508104211164618555wb: + test (21, -2, 20); break; + case -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891246wb: + test (22, -3, 21); break; + case -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891247wb: + test (23, -4, 22); break; + case -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891248wb: + test (24, -5, 23); break; + case -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891249wb: + test (25, 1, 24); break; + case -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891250wb: + test (26, 2, 25); break; + case -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891251wb: + test (27, 3, 26); break; + case 25232715496072790939146860623749108256506615788345509143038026592127702780903347954226870163752427434085269890371577229233150314692259399042327414965711510629wb: + test (28, 4, 27); break; + case 21376200838998904075479297127185224975235208544658573531790808467114261325514834503383673531634166234wb: + test (29, 5, 28); break; + case -12950763061001084589012736558965423479147155000678492177259830314151681149963956790935448632739537613359984550457633150573373wb: + test (30, 6, 29); break; + case -2588834879960231787797472372536501710262304078735816335394876043103825991870347510560085648304946wb: + test (31, 7, 30); break; + case -2701643349985817058465875459099740236751728453427684wb: + test (32, 8, 31); break; + case 5836201004021438163265930908885473220627459728279406489088525555799694670629946003808237930825748wb: + test (33, 7, 32); break; + case 44108809764408326456612205445124618284924483635588993217673301668963284129265963564132943970751645671455967029559660507196902756491684232894669648136319146730wb: + test (34, 6, 33); break; + case 2296104972770686523043774188826290903188890257660332269411533641473619626906874515994186550107564291006924533677263136416982312042wb: + test (35, 5, 34); break; + case 2194074380385385359486226752708738wb: + test (36, 4, 35); break; + case 538995045833371297308662695915673724930785814100527903453604wb: + test (37, 3, 36); break; + case 2085626377217975761550063150555904902911153438008474368944585344266562733501648381wb: + test (38, 2, 37); break; + case -33688835949886075020354777490957071wb: + test (39, 1, 38); break; + case 1391419408329070356813886663340861253838000363084420822349730519562112746630131027735880100996653wb: + test (40, 0, 39); break; + default: + test (41, -1, 40); break; + break; + } +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + static _BitInt(135) a_135[] = { + -33841133710wb, + -55283508608004252890371630137wb, + -1065119162618253595246332535wb, + 265225687803630460135wb, + 12802219454007328327057691wb, + -59157301wb, + 28029296819738wb, + 23771967952817687922824184198772908114wb, + -528wb, + -21743705968wb, + 3761322442803929370621734404255158wb, + 7581882536870984828946588790215963wb, + -3601335158354600803149652143011wb, + 104802210847691888333394846958wb, + 145823237253137988087297wb, + 3871725619091wb, + -480987385702wb, + -1084968414543030wb, + -12928976wb, + -268774wb, + 532464351235328336949014678wb, + -1145290618187237284790705482290160wb, + -249459466889744wb, + -1403065236wb, + -25456270573862478377606wb, + 33340794611915791wb, + -674079586163272813wb, + -41952758959718119236303556590897001668wb, + 2947453415wb, + -677wb, + -463646803422851872253575745194919wb, + -71367919591514155952975401251963194wb, + -14346961913818709867962386609601wb, + 690wb + }; + for (int i = 0; i < 34; ++i) + { + expected = i + 1; + test_135 (a_135[i]); + expected = 35; + test_135 (a_135[i] - 1); + test_135 (a_135[i] + 1); + } +#endif +#if __BITINT_MAXWIDTH__ >= 192 + if (test_192 (0uwb) + || test_192 (1505160143063006983093195408894239764415303566721254616896uwb) + || test_192 (1505160143063006983093195408894239764415303566721254616896uwb + 47) + || test_192 (1505160143063006983093195408894239764415303566721254616896uwb + 71) + || test_192 (-1uwb)) + __builtin_abort (); + for (int i = 48; i <= 70; ++i) + if (test_192 (1505160143063006983093195408894239764415303566721254616896uwb + i) != (i < 58 || i > 64)) + __builtin_abort (); +#endif +#if __BITINT_MAXWIDTH__ >= 574 + expected = 8; + test_574 (0uwb); + test_574 (6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891246uwb - 0x10000000000000000uwb); + test_574 (6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891245uwb); + test_574 (6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891258uwb); + test_574 (6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891246uwb + 0x10000000000000000uwb); + test_574 (6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891258uwb + 0x10000000000000000uwb); + for (int i = 0; i <= 11; ++i) + { + expected = i == 11 ? 7 : i > 5 ? 8 : i + 1; + test_574 (6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891246uwb + i); + } +#endif +#if __BITINT_MAXWIDTH__ >= 575 + static _BitInt(575) a_575[] = { + 57158236877324191282832099954551676419657688516114213070568173374483038461911230482096734270573673572006270803057167488583704wb, + 55932752002978259755258693759201176077252755664748wb, + -4218363291370143377367234486177453689054229233132334373089588356145503900632432151470684730299990106009156255994430506676467506300235609892554834254413957477779209219867825wb, + -19380856704203460544565443028wb, + 37691457600250454282496246135038751153145234859661859831059667050412054918743986000946778819692986258358820458161034213280wb, + 827003152758795459486819489974390601625339063627401335603123746581523657253393870961575744071183196915560771288079061574485309986042624106685495948664669wb, + 2001882657256786505981789524889669355393757203160978wb, + 2273951349206310803215316642428483249009583047771549wb, + -63640037492105525397657594648433413082358686497544854829581174487203243151113011293858381773246wb, + -5043989193130150016980754467018673356423436330428309162407512361831163237wb, + -86904413785414524864201428752820860524832869110219388825241400306401wb, + -7159581406wb, + -430416863734662045942802859497964wb, + -282099469984391093781566wb, + 259191242782270578340350840252447902477249511321245827805053349778984004438373803812874430619356951005300429wb, + -17427431700557396203431wb, + -324305733281944621534wb, + 39167932287702074309519944575154814029176054304655900600154735991016090154633448789399330wb, + 198828227576458371467364915441164050473274232622009526563856039032wb, + 7522018863556878842079508104211164618555wb, + -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891246wb, + -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891247wb, + -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891248wb, + -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891249wb, + -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891250wb, + -6286965391667017312339071741838237504698922691411382973783611300502970166307629280084891251wb, + 25232715496072790939146860623749108256506615788345509143038026592127702780903347954226870163752427434085269890371577229233150314692259399042327414965711510629wb, + 21376200838998904075479297127185224975235208544658573531790808467114261325514834503383673531634166234wb, + -12950763061001084589012736558965423479147155000678492177259830314151681149963956790935448632739537613359984550457633150573373wb, + -2588834879960231787797472372536501710262304078735816335394876043103825991870347510560085648304946wb, + -2701643349985817058465875459099740236751728453427684wb, + 5836201004021438163265930908885473220627459728279406489088525555799694670629946003808237930825748wb, + 44108809764408326456612205445124618284924483635588993217673301668963284129265963564132943970751645671455967029559660507196902756491684232894669648136319146730wb, + 2296104972770686523043774188826290903188890257660332269411533641473619626906874515994186550107564291006924533677263136416982312042wb, + 2194074380385385359486226752708738wb, + 538995045833371297308662695915673724930785814100527903453604wb, + 2085626377217975761550063150555904902911153438008474368944585344266562733501648381wb, + -33688835949886075020354777490957071wb, + 1391419408329070356813886663340861253838000363084420822349730519562112746630131027735880100996653wb + }; + for (int i = 0; i < 39; ++i) + { + expected = i + 1; + test_575 (a_575[i]); + expected = 40; + if (i < 20 || i >= 25) + test_575 (a_575[i] - 1); + if (i <= 20 || i > 25) + test_575 (a_575[i] + 1); + } +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-28.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-28.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,20 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#include "../../c-c++-common/torture/builtin-arith-overflow-1.h" + +#define U(s, op) op +TESTS (_BitInt(19), (-262143wb - 1), 262143wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); + +int +main () +{ + TESTS (_BitInt(19), (-262143wb - 1), 262143wb) + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-29.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-29.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,24 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 119 +#include "../../c-c++-common/torture/builtin-arith-overflow-1.h" + +#define U(s, op) op +TESTS (_BitInt(119), (-332306998946228968225951765070086143wb - 1), 332306998946228968225951765070086143wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 119 + TESTS (_BitInt(119), (-332306998946228968225951765070086143wb - 1), 332306998946228968225951765070086143wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-30.c.jj 2023-07-27 15:03:24.250234229 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-30.c 2023-07-27 15:03:24.250234229 +0200 @@ -0,0 +1,19 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#include "../../c-c++-common/torture/builtin-arith-overflow-12.h" + +TESTS (_BitInt(19), (-262143wb - 1), 262143wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); + +int +main () +{ + TESTS (_BitInt(19), (-262143wb - 1), 262143wb) + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-31.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-31.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,23 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 119 +#include "../../c-c++-common/torture/builtin-arith-overflow-12.h" + +TESTS (_BitInt(119), (-332306998946228968225951765070086143wb - 1), 332306998946228968225951765070086143wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 119 + TESTS (_BitInt(119), (-332306998946228968225951765070086143wb - 1), 332306998946228968225951765070086143wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-32.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-32.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,24 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +#include "../../c-c++-common/torture/builtin-arith-overflow-1.h" + +#define U(s, op) op +TESTS (_BitInt(135), (-21778071482940061661655974875633165533183wb - 1), 21778071482940061661655974875633165533183wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + TESTS (_BitInt(135), (-21778071482940061661655974875633165533183wb - 1), 21778071482940061661655974875633165533183wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-33.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-33.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,24 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 192 +#include "../../c-c++-common/torture/builtin-arith-overflow-1.h" + +#define U(s, op) op +TESTS (_BitInt(192), (-3138550867693340381917894711603833208051177722232017256447wb - 1), 3138550867693340381917894711603833208051177722232017256447wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 192 + TESTS (_BitInt(192), (-3138550867693340381917894711603833208051177722232017256447wb - 1), 3138550867693340381917894711603833208051177722232017256447wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-34.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-34.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,24 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 575 +#include "../../c-c++-common/torture/builtin-arith-overflow-1.h" + +#define U(s, op) op +TESTS (_BitInt(575), (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 575 + TESTS (_BitInt(575), (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-35.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-35.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,23 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 135 +#include "../../c-c++-common/torture/builtin-arith-overflow-12.h" + +TESTS (_BitInt(135), (-21778071482940061661655974875633165533183wb - 1), 21778071482940061661655974875633165533183wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 135 + TESTS (_BitInt(135), (-21778071482940061661655974875633165533183wb - 1), 21778071482940061661655974875633165533183wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-36.c.jj 2023-07-27 15:03:24.246234285 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-36.c 2023-07-27 15:03:24.246234285 +0200 @@ -0,0 +1,23 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 192 +#include "../../c-c++-common/torture/builtin-arith-overflow-12.h" + +TESTS (_BitInt(192), (-3138550867693340381917894711603833208051177722232017256447wb - 1), 3138550867693340381917894711603833208051177722232017256447wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 192 + TESTS (_BitInt(192), (-3138550867693340381917894711603833208051177722232017256447wb - 1), 3138550867693340381917894711603833208051177722232017256447wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-37.c.jj 2023-07-27 15:03:24.249234243 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-37.c 2023-07-27 15:03:24.249234243 +0200 @@ -0,0 +1,23 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 575 +#include "../../c-c++-common/torture/builtin-arith-overflow-12.h" + +TESTS (_BitInt(575), (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb) + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 575 + TESTS (_BitInt(575), (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb) +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-38.c.jj 2023-07-27 15:03:24.248234257 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-38.c 2023-07-27 15:03:24.248234257 +0200 @@ -0,0 +1,56 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 575 +#include "../../c-c++-common/torture/builtin-arith-overflow.h" + +#ifdef __SIZEOF_INT128__ +#define WTYPE __int128 +#else +#define WTYPE long long int +#endif + +#define TESTS \ +T (100, signed _BitInt(38), signed char, unsigned _BitInt(162), -1wb, 0, -1wb, add, 1) \ +T (101, unsigned char, unsigned _BitInt(38), unsigned _BitInt(162), 5, 5wb, 10wb, add, 0) \ +T (102, signed _BitInt(38), unsigned short, unsigned _BitInt(162), 5wb, 5, 0wb, sub, 0) \ +T (103, signed _BitInt(38), unsigned _BitInt(72), unsigned _BitInt(162), 5wb, 6wb, -1wb, sub, 1) \ +T (104, signed _BitInt(38), signed _BitInt(38), unsigned _BitInt(162), -1wb, -1wb, 1wb, mul, 0) \ +T (105, unsigned _BitInt(38), signed _BitInt(38), unsigned _BitInt(162), 17wb, -2wb, -34wb, mul, 1) \ +T (106, unsigned _BitInt(162), signed _BitInt(162), signed _BitInt(38), 5wb, -2wb, -10wb, mul, 0) \ +T (107, signed _BitInt(321), signed _BitInt(321), unsigned _BitInt(38), -3wb, 5wb, 2wb, add, 0) \ +T (108, signed _BitInt(321), int, unsigned _BitInt(38), -5wb, 3, -2wb, add, 1) \ +T (109, int, _BitInt(162), unsigned _BitInt(38), -3, 5wb, 2wb, add, 0) \ +T (110, unsigned _BitInt(38), unsigned _BitInt(38), unsigned _BitInt(162), 137438953471wb - 1, (unsigned _BitInt(38)) 137438953471wb + 4, -5wb, sub, 1) \ +T (111, signed _BitInt(315), signed _BitInt(315), unsigned, -1wb, 0wb, -1, add, 1) \ +T (112, signed _BitInt(315), signed _BitInt(315), unsigned, 5wb, 42wb, 47, add, 0) \ +T (113, signed _BitInt(315), signed _BitInt(315), unsigned WTYPE, -1wb, 0wb, -1, add, 1) \ +T (114, signed _BitInt(315), signed _BitInt(315), unsigned WTYPE, 15wb, 5wb, 20, add, 0) +T (115, signed _BitInt(315), signed _BitInt(315), unsigned _BitInt(135), -1wb, 0wb, -1wb, add, 1) \ +T (116, signed _BitInt(315), signed _BitInt(315), unsigned _BitInt(135), 5wb, 125wb, 130wb, add, 0) \ +T (117, signed _BitInt(275), signed _BitInt(275), unsigned _BitInt(125), -1wb, 0wb, -1wb, add, 1) \ +T (118, signed _BitInt(275), signed _BitInt(275), unsigned _BitInt(125), 5wb, 125wb, 130wb, add, 0) \ +T (119, signed _BitInt(415), signed _BitInt(415), signed _BitInt(178), 95780971304118053647396689196894323976171195136475135wb, 95780971304118053647396689196894323976171195136475137wb, -191561942608236107294793378393788647952342390272950271wb - 1, add, 1) \ +T (120, signed _BitInt(415), signed _BitInt(415), signed _BitInt(178), 95780971304118053647396689196894323976171195136475135wb, 95780971304118053647396689196894323976171195136475136wb, 191561942608236107294793378393788647952342390272950271wb, add, 0) \ +T (121, signed _BitInt(439), signed _BitInt(439), signed _BitInt(192), 1569275433846670190958947355801916604025588861116008628223wb, 1569275433846670190958947355801916604025588861116008628225wb, -3138550867693340381917894711603833208051177722232017256447wb - 1, add, 1) \ +T (122, signed _BitInt(439), signed _BitInt(439), signed _BitInt(192), 1569275433846670190958947355801916604025588861116008628223wb, 1569275433846670190958947355801916604025588861116008628224wb, 3138550867693340381917894711603833208051177722232017256447wb, add, 0) \ +T (123, signed _BitInt(575), signed _BitInt(575), signed _BitInt(193), 3138550867693340381917894711603833208051177722232017256447wb, 3138550867693340381917894711603833208051177722232017256449wb, -6277101735386680763835789423207666416102355444464034512895wb - 1, add, 1) \ +T (124, signed _BitInt(575), signed _BitInt(575), signed _BitInt(193), 3138550867693340381917894711603833208051177722232017256447wb, 3138550867693340381917894711603833208051177722232017256448wb, 6277101735386680763835789423207666416102355444464034512895wb, add, 0) + +TESTS + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 575 + TESTS +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-39.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-39.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,57 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=gnu2x" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 575 +#define OVFP +#include "../../c-c++-common/torture/builtin-arith-overflow.h" + +#ifdef __SIZEOF_INT128__ +#define WTYPE __int128 +#else +#define WTYPE long long int +#endif + +#define TESTS \ +T (100, signed _BitInt(38), signed char, unsigned _BitInt(162), -1wb, 0, -1wb, add, 1) \ +T (101, unsigned char, unsigned _BitInt(38), unsigned _BitInt(162), 5, 5wb, 10wb, add, 0) \ +T (102, signed _BitInt(38), unsigned short, unsigned _BitInt(162), 5wb, 5, 0wb, sub, 0) \ +T (103, signed _BitInt(38), unsigned _BitInt(72), unsigned _BitInt(162), 5wb, 6wb, -1wb, sub, 1) \ +T (104, signed _BitInt(38), signed _BitInt(38), unsigned _BitInt(162), -1wb, -1wb, 1wb, mul, 0) \ +T (105, unsigned _BitInt(38), signed _BitInt(38), unsigned _BitInt(162), 17wb, -2wb, -34wb, mul, 1) \ +T (106, unsigned _BitInt(162), signed _BitInt(162), signed _BitInt(38), 5wb, -2wb, -10wb, mul, 0) \ +T (107, signed _BitInt(321), signed _BitInt(321), unsigned _BitInt(38), -3wb, 5wb, 2wb, add, 0) \ +T (108, signed _BitInt(321), int, unsigned _BitInt(38), -5wb, 3, -2wb, add, 1) \ +T (109, int, _BitInt(162), unsigned _BitInt(38), -3, 5wb, 2wb, add, 0) \ +T (110, unsigned _BitInt(38), unsigned _BitInt(38), unsigned _BitInt(162), 137438953471wb - 1, (unsigned _BitInt(38)) 137438953471wb + 4, -5wb, sub, 1) \ +T (111, signed _BitInt(315), signed _BitInt(315), unsigned, -1wb, 0wb, -1, add, 1) \ +T (112, signed _BitInt(315), signed _BitInt(315), unsigned, 5wb, 42wb, 47, add, 0) \ +T (113, signed _BitInt(315), signed _BitInt(315), unsigned WTYPE, -1wb, 0wb, -1, add, 1) \ +T (114, signed _BitInt(315), signed _BitInt(315), unsigned WTYPE, 15wb, 5wb, 20, add, 0) +T (115, signed _BitInt(315), signed _BitInt(315), unsigned _BitInt(135), -1wb, 0wb, -1wb, add, 1) \ +T (116, signed _BitInt(315), signed _BitInt(315), unsigned _BitInt(135), 5wb, 125wb, 130wb, add, 0) \ +T (117, signed _BitInt(275), signed _BitInt(275), unsigned _BitInt(125), -1wb, 0wb, -1wb, add, 1) \ +T (118, signed _BitInt(275), signed _BitInt(275), unsigned _BitInt(125), 5wb, 125wb, 130wb, add, 0) \ +T (119, signed _BitInt(415), signed _BitInt(415), signed _BitInt(178), 95780971304118053647396689196894323976171195136475135wb, 95780971304118053647396689196894323976171195136475137wb, -191561942608236107294793378393788647952342390272950271wb - 1, add, 1) \ +T (120, signed _BitInt(415), signed _BitInt(415), signed _BitInt(178), 95780971304118053647396689196894323976171195136475135wb, 95780971304118053647396689196894323976171195136475136wb, 191561942608236107294793378393788647952342390272950271wb, add, 0) \ +T (121, signed _BitInt(439), signed _BitInt(439), signed _BitInt(192), 1569275433846670190958947355801916604025588861116008628223wb, 1569275433846670190958947355801916604025588861116008628225wb, -3138550867693340381917894711603833208051177722232017256447wb - 1, add, 1) \ +T (122, signed _BitInt(439), signed _BitInt(439), signed _BitInt(192), 1569275433846670190958947355801916604025588861116008628223wb, 1569275433846670190958947355801916604025588861116008628224wb, 3138550867693340381917894711603833208051177722232017256447wb, add, 0) \ +T (123, signed _BitInt(575), signed _BitInt(575), signed _BitInt(193), 3138550867693340381917894711603833208051177722232017256447wb, 3138550867693340381917894711603833208051177722232017256449wb, -6277101735386680763835789423207666416102355444464034512895wb - 1, add, 1) \ +T (124, signed _BitInt(575), signed _BitInt(575), signed _BitInt(193), 3138550867693340381917894711603833208051177722232017256447wb, 3138550867693340381917894711603833208051177722232017256448wb, 6277101735386680763835789423207666416102355444464034512895wb, add, 0) + +TESTS + +#undef T +#define T(n, t1, t2, tr, v1, v2, vr, b, o) t##n##b (); +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 575 + TESTS +#endif + return 0; +} --- gcc/testsuite/gcc.dg/torture/bitint-40.c.jj 2023-07-27 15:03:24.247234271 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-40.c 2023-07-27 15:03:24.247234271 +0200 @@ -0,0 +1,40 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 323 +__attribute__((noipa)) _BitInt(323) +foo (_BitInt(318) x, _BitInt(323) y) +{ + return x + y; +} + +__attribute__((noipa)) _BitInt(323) +bar (_BitInt(117) x, _BitInt(323) y) +{ + return x + y; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 323 + if (foo (-27733041854193447641086572824547940096595738628642819753407953445763239714154199953745005898992wb, + 4767458710334760668834645815738583537909191474644120198636728988961922824468904018596948147773722wb) + != 4739725668480567221193559242914035597812595736015477378883321035516159584754749818643203141874730wb + || (foo (22167179033351019542845489620035412963406090796537167425591583962059414367893933412196721063711wb, + 5235750662037407195417484618645691209305675673195256409842928988743249911043551311451335001624960wb) + != 5257917841070758214960330108265726622269081763991793577268520572705309325411445244863531722688671wb)) + __builtin_abort (); + if (bar (-12653567664155974398995022748067044wb, + 7190977642064159111525225823679712940862545424809645152399787447341776579576645887978584020321431wb) + != 7190977642064159111525225823679712940862545424809645152399787434688208915420671488983561272254387wb + || (bar (30518211833575333685611432934770228wb, + 2152360419596992042662178082767272400451689654640037233902067223067458441134717528282349099466966wb) + != 2152360419596992042662178082767272400451689654640037233902067253585670274710051213893782034237194wb)) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/torture/bitint-41.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/torture/bitint-41.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,34 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 256 +__attribute__((noipa)) _Bool +test256 (_BitInt(256) *q) +{ + return __builtin_sub_overflow ((_BitInt(256)) 0, q[0], q + 1); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 256 + static _BitInt(256) q256[] = { + 45345032714412617256156490782169070529322290545773058110333871537162440472587wb, + 0wb, + -45345032714412617256156490782169070529322290545773058110333871537162440472587wb, + -45345032714412617256156490782169070529322290545773058110333871537162440472587wb, + 0wb, + 45345032714412617256156490782169070529322290545773058110333871537162440472587wb, + -57896044618658097711785492504343953926634992332820282019728792003956564819967wb - 1, + 0wb, + -57896044618658097711785492504343953926634992332820282019728792003956564819967wb - 1 + }; + for (int i = 0; i < 3; ++i) + if (test256 (q256 + 3 * i) != (i == 2) || q256[3 * i + 1] != q256[3 * i + 2]) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.dg/ubsan/bitint-1.c.jj 2023-07-27 15:03:24.245234299 +0200 +++ gcc/testsuite/gcc.dg/ubsan/bitint-1.c 2023-07-27 15:03:24.245234299 +0200 @@ -0,0 +1,49 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-fsanitize=signed-integer-overflow,shift -fsanitize-recover=signed-integer-overflow,shift" } */ + +__attribute__((noipa)) int +foo (_BitInt(15) *p, _BitInt(15) *q, int n) +{ + q[0] = p[0] + p[1]; + q[1] = p[2] - p[3]; + q[2] = p[4] * p[5]; + q[3] = p[6] / p[7]; + q[4] = p[8] << n; + q[5] = p[9] >> n; + return n; +} + +int +main () +{ + static _BitInt(15) p[] = { + 16382wb, 1wb, + -16383wb, 1wb, + 127wb, 129wb, + -16383wb - 1, 1wb, + 0wb, 1wb, + 16383wb, 1wb, + -16383wb - 1, 1wb, + 127wb, 130wb, + -16383wb - 1, -1wb, + 0wb, 1wb + }; + _BitInt(15) q[6]; + int n = foo (p, q, 14); + q[4] = p[8] << (n + 2); + q[5] = p[9] >> (n + 2); + foo (p + 10, q, 15); +} + +/* The 16-bit type vs. 15-bit is small inaccuracy. */ +/* { dg-output "shift exponent 16 is too large for 16-bit type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 16 is too large for 16-bit type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: 16383 \\+ 1 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: -16384 - 1 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: 127 \\* 130 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division of -16384 by -1 cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* This isn't accurate, but libubsan right now doesn't know it is 15-bit type rather than 16-bit. */ +/* { dg-output "\[^\n\r]*left shift of 0 by 15 places cannot be represented in type '_BitInt\\\(15\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* The wording is totally incorrect, but at least it is diagnosed. */ +/* { dg-output "\[^\n\r]*left shift of 1 by 15 places cannot be represented in type '_BitInt\\\(15\\\)'" } */ --- gcc/testsuite/gcc.dg/ubsan/bitint-2.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/ubsan/bitint-2.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,49 @@ +/* PR c/102989 */ +/* { dg-do run { target { bitint128 && int128 } } } */ +/* { dg-options "-fsanitize=signed-integer-overflow,shift -fsanitize-recover=signed-integer-overflow,shift" } */ + +__attribute__((noipa)) int +foo (_BitInt(125) *p, _BitInt(125) *q, int n) +{ + q[0] = p[0] + p[1]; + q[1] = p[2] - p[3]; + q[2] = p[4] * p[5]; + q[3] = p[6] / p[7]; + q[4] = p[8] << n; + q[5] = p[9] >> n; + return n; +} + +int +main () +{ + static _BitInt(125) p[] = { + 21267647932558653966460912964485513214wb, 1wb, + -21267647932558653966460912964485513215wb, 1wb, + 4611686018427387903wb, 4611686018427387905wb, + -21267647932558653966460912964485513215wb - 1, 1wb, + 0wb, 1wb, + 21267647932558653966460912964485513215wb, 1wb, + -21267647932558653966460912964485513215wb - 1, 1wb, + 4611686018427387903wb, 4611686018427387906wb, + -21267647932558653966460912964485513215wb - 1, -1wb, + 0wb, 1wb + }; + _BitInt(125) q[6]; + int n = foo (p, q, 123); + q[4] = p[8] << (n + 5); + q[5] = p[9] >> (n + 5); + foo (p + 10, q, 125); +} + +/* The 128-bit type vs. 125-bit is small inaccuracy. */ +/* { dg-output "shift exponent 128 is too large for 128-bit type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 128 is too large for 128-bit type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: 0x0fffffffffffffffffffffffffffffff \\+ 1 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: 0xf0000000000000000000000000000000 - 1 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: 4611686018427387903 \\* 4611686018427387906 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division of 0xf0000000000000000000000000000000 by -1 cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* This isn't accurate, but libubsan right now doesn't know it is 125-bit type rather than 128-bit. */ +/* { dg-output "\[^\n\r]*left shift of 0 by 125 places cannot be represented in type '_BitInt\\\(125\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* The wording is totally incorrect, but at least it is diagnosed. */ +/* { dg-output "\[^\n\r]*left shift of 1 by 125 places cannot be represented in type '_BitInt\\\(125\\\)'" } */ --- gcc/testsuite/gcc.dg/ubsan/bitint-3.c.jj 2023-07-27 15:03:24.244234312 +0200 +++ gcc/testsuite/gcc.dg/ubsan/bitint-3.c 2023-07-27 15:03:24.244234312 +0200 @@ -0,0 +1,45 @@ +/* PR c/102989 */ +/* { dg-do run { target bitint575 } } */ +/* { dg-options "-fsanitize=signed-integer-overflow,shift -fsanitize-recover=signed-integer-overflow,shift" } */ + +__attribute__((noipa)) int +foo (_BitInt(575) *p, _BitInt(575) *q, int n) +{ + q[0] = p[0] + p[1]; + q[1] = p[2] - p[3]; + q[2] = p[4] * p[5]; + q[3] = p[6] / p[7]; + q[4] = p[8] << n; + q[5] = p[9] >> n; + return n; +} + +int +main () +{ + static _BitInt(575) p[] = { + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174782wb, 1wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1wb, + 248661618204893321077691124073410420050228075398673858720231988446579748506266687766527wb, 248661618204893321077691124073410420050228075398673858720231988446579748506266687766529wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 1wb, + 0wb, 1wb, + 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 1wb, + 248661618204893321077691124073410420050228075398673858720231988446579748506266687766527wb, 248661618204893321077691124073410420050228075398673858720231988446579748506266687766530wb, + -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, -1wb, + 0wb, 1wb + }; + _BitInt(575) q[6]; + foo (p, q, 574); + foo (p + 10, q, 575); +} + +/* These print unsigned integer overflow even when it is signed. */ +/* { dg-output "signed integer overflow: \\+ cannot be represented in type '_BitInt\\\(575\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: - cannot be represented in type '_BitInt\\\(575\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*signed integer overflow: \\* cannot be represented in type '_BitInt\\\(575\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* Inaccurate. */ +/* { dg-output "\[^\n\r]*division by zero\[^\n\r]*(\n|\r\n|\r)" } */ +/* The wording is totally incorrect, but at least it is diagnosed. */ +/* { dg-output "\[^\n\r]*shift exponent 575 is too large for \[0-9]*-bit type '_BitInt\\\(575\\\)'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 575 is too large for \[0-9]*-bit type '_BitInt\\\(575\\\)'" } */