From patchwork Thu Jan 11 08:20:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 187223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1301698dyi; Thu, 11 Jan 2024 00:21:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM6Nljp9eQtk7Mb3gToZAfitLudaeBtR6iGMOmy9GNG7Qx4ck0Z34P5RSElgjzVzx7Lexw X-Received: by 2002:a05:622a:3c9:b0:429:b485:4e03 with SMTP id k9-20020a05622a03c900b00429b4854e03mr282024qtx.78.1704961280284; Thu, 11 Jan 2024 00:21:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704961280; cv=pass; d=google.com; s=arc-20160816; b=DeeBHM9k1V1+/VU9M8u2iCnamv9ndxKdwNf519yxxqjzwDBJhgEfmPptV3QTyXVkhx U3zo53edMzWTZdFZ2tFX6mYjlnXrQeraRx0Ech5F3xwt0xTZQtRGG1abegP4MPceYzYT Ri6IfllNjZBDPs+onjBqrlb2FjPsk0uvkm5kMSAPZQfqp/HEfxUYN77G6rzNldyNCPZC NQ6CCmThhKMaKEnzAaP6UYr06VpScaJip7c7ifPx4pVhEn/9UVY3cx32L6l2ti7RyeP2 Uc1q3mfqHAmfVmlTXYaZdvbYYRINXtAQkf8vkjpsiqACKhMlPOc9IlqSP7iEQnU8+XJ6 lxgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=gSrfk3KAz8tueUwrGxR0N4+vpXI8Cxf1wQJ/WEnBYCo=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=RxPiyMcGPKKVMmjulE6djIf46brvUR9Fzc73TZII8hn5TrI0Vmv/B804NDh6/i+dXu ylYPNDbjr/Do86WlWLiOO7ZG2GbaWaKMfdrVM1sOTY0N6Dx4E/L5uM1faFkcV3M0G+z8 cTQk7+QoWZpRaW72WnQ3kFLhPEUxTaw8sADK4P1FQJ6JL/uzv1qhWS1P1TKFqy91xoVX Dry4RaIxWG5+Vr/+2231UCVpeE3UQyWvVVYFEGBCi3uKNWPsbhNEUCfRrR0Kx4hz3Q9V W986Z2yHdwggCSiVx+nXL9bjuZ4uDFk+iw+QGPnmLDOgawENOnr2TBpHuMtabk28j3+V Evtw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=APlbkSGU; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o13-20020a05622a008d00b004299df60374si489756qtw.714.2024.01.11.00.21.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 00:21:20 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=APlbkSGU; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3F9538497B6 for ; Thu, 11 Jan 2024 08:21:19 +0000 (GMT) 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 737BD385E01D for ; Thu, 11 Jan 2024 08:20:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 737BD385E01D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 737BD385E01D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704961225; cv=none; b=XGldAne9sNjMJ6vBGdfAOaGQMGEs1xcr33n9esRwFOZ1ClRsiEi1EKCCY0OmedDAjzSyd99BsKBeU9QOZg0tpgtW2OSzXFYX5QIRzrIQyrMk/1rm00K5LFc9zik4TaQmJSqQZtbhFvbyFLeHy2iPjYWGU9ZvMSW2k2x3K9QSs3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704961225; c=relaxed/simple; bh=gX0bvFdbk/GbBGtYZTB4NJsfoiNqPEjpXMhGw8/1ifQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UsJhlFDi7ad3RROcaijbP060DghSjR5ht2ZRwII2ReyenhCB5U3nw9D62hgay2LiY6+yRhU/kqLEnWHmW0lxpayPW3uU7Ll1RusNTEdoN9qcEd+i0ENwYCznA84B1NuSMCogRJaPw4670Ne0mc/DfEMevyJ9BNRv7bk3IplHTFM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704961223; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=gSrfk3KAz8tueUwrGxR0N4+vpXI8Cxf1wQJ/WEnBYCo=; b=APlbkSGUz/cwjqKNvfPZpk7gBdxCSIUuVpu6AX4qCe8THJo9mhczAbwM4r10wwotIBEeza yZvtJv+BZbC5ouw6lKqKe471gM322KjqEltVSQkGqwC8OkOn0/I0J4stZL2pXkioa9Fr3d AAbtigBXXaQocXcHAtGK5HiLQyseS0A= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-hJBCwNFeO2KwV09x29rZOQ-1; Thu, 11 Jan 2024 03:20:21 -0500 X-MC-Unique: hJBCwNFeO2KwV09x29rZOQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CBC6C38143B8; Thu, 11 Jan 2024 08:20:20 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FBF02026D66; Thu, 11 Jan 2024 08:20:20 +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 40B8KH5M425114 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 11 Jan 2024 09:20:18 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40B8KHmv425113; Thu, 11 Jan 2024 09:20:17 +0100 Date: Thu, 11 Jan 2024 09:20:16 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] libgcc: Use may_alias attribute in bitint handlers Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.9 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787781479548810830 X-GMAIL-MSGID: 1787781479548810830 Hi! As discussed on IRC, the following patch uses may_alias attribute, so that on targets like aarch64 where abi_limb_mode != limb_mode the library accesses the limbs (half limbs of the ABI) in the arrays with conservative alias set. So far tested on x86_64-linux with make check-gcc check-g++ -j32 -k GCC_TEST_RUN_EXPENSIVE=1 RUNTESTFLAGS="GCC_TEST_RUN_EXPENSIVE=1 dg.exp='*bitint* pr112673.c builtin-stdc-bit-*.c pr112566-2.c pr112511.c' dg-torture.exp=*bitint* dfp.exp=*bitint*" Ok for trunk if it passes full bootstrap/regtest? 2024-01-11 Jakub Jelinek * libgcc2.h (UBILtype): New typedef with may_alias attribute. (__mulbitint3, __divmodbitint4): Use UBILtype * instead of UWtype * and const UBILtype * instead of const UWtype *. * libgcc2.c (bitint_reduce_prec, bitint_mul_1, bitint_addmul_1, __mulbitint3, bitint_negate, bitint_submul_1, __divmodbitint4): Likewise. * soft-fp/bitint.h (UBILtype): Change define into a typedef with may_alias attribute. Jakub --- libgcc/libgcc2.h.jj 2024-01-03 12:07:28.134370411 +0100 +++ libgcc/libgcc2.h 2024-01-11 08:42:02.417235956 +0100 @@ -402,10 +402,12 @@ extern UDWtype __udivmoddi4 (UDWtype, UD #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); +typedef UWtype __attribute__((__may_alias__)) UBILtype; +extern void __mulbitint3 (UBILtype *, SItype, const UBILtype *, SItype, + const UBILtype *, SItype); +extern void __divmodbitint4 (UBILtype *, SItype, UBILtype *, SItype, + const UBILtype *, SItype, const UBILtype *, + SItype); #endif /* __negdi2 is static inline when building other libgcc2 portions. */ --- libgcc/libgcc2.c.jj 2024-01-03 12:07:29.323353753 +0100 +++ libgcc/libgcc2.c 2024-01-11 08:44:56.260727411 +0100 @@ -1309,7 +1309,7 @@ __udivdi3 (UDWtype n, UDWtype d) some narrower _BitInt value, reduce precision. */ static inline __attribute__((__always_inline__)) SItype -bitint_reduce_prec (const UWtype **p, SItype prec) +bitint_reduce_prec (const UBILtype **p, SItype prec) { UWtype mslimb; SItype i; @@ -1421,7 +1421,7 @@ bitint_reduce_prec (const UWtype **p, SI /* D = S * L. */ static UWtype -bitint_mul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n) +bitint_mul_1 (UBILtype *d, const UBILtype *s, UWtype l, SItype n) { UWtype sv, hi, lo, c = 0; do @@ -1440,7 +1440,7 @@ bitint_mul_1 (UWtype *d, const UWtype *s /* D += S * L. */ static UWtype -bitint_addmul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n) +bitint_addmul_1 (UBILtype *d, const UBILtype *s, UWtype l, SItype n) { UWtype sv, hi, lo, c = 0; do @@ -1465,9 +1465,9 @@ bitint_addmul_1 (UWtype *d, const UWtype positive. */ void -__mulbitint3 (UWtype *ret, SItype retprec, - const UWtype *u, SItype uprec, - const UWtype *v, SItype vprec) +__mulbitint3 (UBILtype *ret, SItype retprec, + const UBILtype *u, SItype uprec, + const UBILtype *v, SItype vprec) { uprec = bitint_reduce_prec (&u, uprec); vprec = bitint_reduce_prec (&v, vprec); @@ -1480,7 +1480,7 @@ __mulbitint3 (UWtype *ret, SItype retpre || (avprec > auprec && !(uprec >= 0 && vprec < 0))) { SItype p; - const UWtype *t; + const UBILtype *t; p = uprec; uprec = vprec; vprec = p; p = auprec; auprec = avprec; avprec = p; t = u; u = v; v = t; @@ -1643,7 +1643,7 @@ __mulbitint3 (UWtype *ret, SItype retpre /* D = -S. */ static void -bitint_negate (UWtype *d, const UWtype *s, SItype n) +bitint_negate (UBILtype *d, const UBILtype *s, SItype n) { UWtype c = 1; do @@ -1660,7 +1660,7 @@ bitint_negate (UWtype *d, const UWtype * /* D -= S * L. */ static UWtype -bitint_submul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n) +bitint_submul_1 (UBILtype *d, const UBILtype *s, UWtype l, SItype n) { UWtype sv, hi, lo, c = 0; do @@ -1687,10 +1687,10 @@ bitint_submul_1 (UWtype *d, const UWtype should be 0. */ void -__divmodbitint4 (UWtype *q, SItype qprec, - UWtype *r, SItype rprec, - const UWtype *u, SItype uprec, - const UWtype *v, SItype vprec) +__divmodbitint4 (UBILtype *q, SItype qprec, + UBILtype *r, SItype rprec, + const UBILtype *u, SItype uprec, + const UBILtype *v, SItype vprec) { uprec = bitint_reduce_prec (&u, uprec); vprec = bitint_reduce_prec (&v, vprec); @@ -1747,7 +1747,7 @@ __divmodbitint4 (UWtype *q, SItype qprec if (qn >= qn2) qn2 = 0; USItype sz = un + 1 + vn + qn2; - UWtype *buf = __builtin_alloca (sz * sizeof (UWtype)); + UBILtype *buf = __builtin_alloca (sz * sizeof (UWtype)); USItype uidx, vidx; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ uidx = un - 1; @@ -1768,9 +1768,9 @@ __divmodbitint4 (UWtype *q, SItype qprec __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; + UBILtype *u2 = buf; + UBILtype *v2 = u2 + un + 1; + UBILtype *q2 = v2 + vn; if (!qn2) q2 = q + BITINT_END (qn - (un - vn + 1), 0); --- libgcc/soft-fp/bitint.h.jj 2023-09-06 17:42:14.501093073 +0200 +++ libgcc/soft-fp/bitint.h 2024-01-11 08:39:09.590746494 +0100 @@ -33,19 +33,19 @@ see the files COPYING3 and COPYING.RUNTI #if BIL_UNITS_PER_WORD == 8 #define BIL_TYPE_SIZE (8 * __CHAR_BIT__) #define BILtype DItype -#define UBILtype UDItype +typedef UDItype __attribute__ ((__may_alias__)) UBILtype; #elif BIL_UNITS_PER_WORD == 4 #define BIL_TYPE_SIZE (4 * __CHAR_BIT__) #define BILtype SItype -#define UBILtype USItype +typedef USItype __attribute__ ((__may_alias__)) UBILtype; #elif BIL_UNITS_PER_WORD == 2 #define BIL_TYPE_SIZE (2 * __CHAR_BIT__) #define BILtype HItype -#define UBILtype UHItype +typedef UHItype __attribute__ ((__may_alias__)) UBILtype; #else #define BIL_TYPE_SIZE __CHAR_BIT__ #define BILtype QItype -#define UBILtype UQItype +typedef UQItype __attribute__ ((__may_alias__)) UBILtype; #endif /* If *P is zero or sign extended (the latter only for PREC < 0) from