From patchwork Sat May 6 17:26:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 90785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1171148vqo; Sat, 6 May 2023 10:26:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7DxLDjmlr1xnFbr1N14y8cVJQERFK8iiq8nP24QrC8MFDiRqPqyS/OHx+szSvt1yMKBuR/ X-Received: by 2002:a17:906:c14f:b0:94d:a2c2:9aeb with SMTP id dp15-20020a170906c14f00b0094da2c29aebmr5085908ejc.49.1683394005198; Sat, 06 May 2023 10:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683394005; cv=none; d=google.com; s=arc-20160816; b=NDfaFne5PRNkLOuFI42JnuQfPeE5hPJ7DVSsujApwAkgJcIKRHFUxbnBEyGomQbOwL lQYvmg70efz6pVhFmr2hyrYgnyrQEJo7dN6NBnGyrxlbdLavda5Q9ru3oXvj4O/98JyC VIrIaYCVxJC2o21NJezv6zpb4iMEZz8GGy41ErCASCxWGsBiMTYZJh4JHE4sO+N56QNg SN2Dk7U2OtaV1bGy82o1ChV2x/750ERC/BqqSNz96pc+ufG1bfH8dXRSdxRG+R8Jq6q9 V/v0hd7KxBgUMeESBzX6SOh78hnKW58z+7wbe1FXjtIEAQcTB/AxWDOgCmM0bflgDoF6 O+Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=aZQTtW0y5VpDdZmJCHRUHFtHMh5WBFHFMzCv3X4PXlc=; b=evz3/dLlxw8Sb/xFVv+d2yss2zQ+T81Tm6T+JpsLLGexZK2sbUFHO0reCNMuRLKkfp vUgR8+hGVwW+XsVhpZrPA7RXFeD1jo6cS70kDOfR71BRtXBJiG0U1GKVq6UUWSqm27sv aRXBnFCWUmpmcfJr2NTS0cyJx4w/F7xQ+zJhcfvUu8EOS5MNgXiMMEKlWQN26pAwSfak eoUdMLN1xVjkJtWEWc2dVMt0GWx5iAonfMz4m2Q/XHsByzOVUP/7hjK3JcNAxVErrnTB kgfkx5bbA0oNMQ8hjV374apHqomwqNBicKZVAaN9JKk3QXzWqT0FSrycSOMwkMs0rKCe TUFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=pSVQXEU9; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ku8-20020a170907788800b0094f8f46c1b1si3138709ejc.646.2023.05.06.10.26.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 10:26:45 -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=fail header.i=@nextmovesoftware.com header.s=default header.b=pSVQXEU9; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 04C8D3858401 for ; Sat, 6 May 2023 17:26:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id C10263858D1E for ; Sat, 6 May 2023 17:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C10263858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=aZQTtW0y5VpDdZmJCHRUHFtHMh5WBFHFMzCv3X4PXlc=; b=pSVQXEU9DEj+F0L0KrLIHUp3p+ wf7tYsX/9ZWgxHcookNHfLEMQhk39djO0w103sf8QGQFVhw+Z7wxv1JUlQ+OePzyPDsjInBZQku41 FNai0DNagoP55VUmL1xTLidhmFA+tCmMagtXcwUzGXeMX6NeEEcDks58kOF2PaVwlUi32gQ5yWlNK UyqoG7X77c5cWtE/nPetLNoIrQWU90O1TZOtk/em8gQ38xtvtbsWbJh3ZE3nbDf/lxSqSQK12c6FC NlnqkoJbJESXCmAPX1GtO7Z2a1tkwtc/mGICv+gY8EqF8mo4+B9e63HDQZMNKvi++ZuprBKWmwp8L VR/+Rosg==; Received: from host86-169-41-81.range86-169.btcentralplus.com ([86.169.41.81]:50163 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pvLfh-0004tw-0T for gcc-patches@gcc.gnu.org; Sat, 06 May 2023 13:26:13 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [libgcc PATCH] Add bit reversal functions __bitrev[qhsd]i2. Date: Sat, 6 May 2023 18:26:11 +0100 Message-ID: <00c401d9803f$dafe3c90$90fab5b0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmAO2YVL782eB0dQCCYTLokdiovGw== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765166552452424132?= X-GMAIL-MSGID: =?utf-8?q?1765166552452424132?= This patch proposes adding run-time library support for bit reversal, by adding a __bitrevsi2 function to libgcc. Thoughts/opinions? I'm also tempted to add __popcount[qh]i2 and __parity[qh]i2 to libgcc, to allow the RTL optimizers to perform narrowing operations, but I'm curious to hear whether QImode and HImode support, though more efficient, is frowned by the libgcc maintainers/philosophy. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} and on nvptx-none, with no new regressions. Ok for mainline? 2023-05-06 Roger Sayle gcc/ChangeLog * doc/libgcc.texi (__bitrevqi2): Document bit reversal run-time functions; __bitrevqi2, __bitrevhi2, __bitrevsi2 and __bitrevdi2. libgcc/ChangeLog * Makfile.in (lib2funcs): Add __bitrev[qhsd]i2. * libgcc-std.ver.in (GCC_14.0.0): Add __bitrev[qhsd]i2. * libgcc2.c (__bitrevqi2): New function. (__bitrevhi2): Likewise. (__bitrevsi2): Likewise. (__bitrevdi2): Likewise. * libgcc2.h (__bitrevqi2): Prototype here. (__bitrevhi2): Likewise. (__bitrevsi2): Likewise. (__bitrevdi2): Likewise. Thanks in advance, Roger diff --git a/gcc/doc/libgcc.texi b/gcc/doc/libgcc.texi index 73aa803..7611347 100644 --- a/gcc/doc/libgcc.texi +++ b/gcc/doc/libgcc.texi @@ -218,6 +218,13 @@ These functions return the number of bits set in @var{a}. These functions return the @var{a} byteswapped. @end deftypefn +@deftypefn {Runtime Function} int8_t __bitrevqi2 (int8_t @var{a}) +@deftypefnx {Runtime Function} int16_t __bitrevhi2 (int16_t @var{a}) +@deftypefnx {Runtime Function} int32_t __bitrevsi2 (int32_t @var{a}) +@deftypefnx {Runtime Function} int64_t __bitrevdi2 (int64_t @var{a}) +These functions return the bit reversed @var{a}. +@end deftypefn + @node Soft float library routines @section Routines for floating point emulation @cindex soft float library diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 6c4dc79..67c54df 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -446,7 +446,7 @@ lib2funcs = _muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3 _cmpdi2 _ucmpdi2 \ _paritysi2 _paritydi2 _powisf2 _powidf2 _powixf2 _powitf2 \ _mulhc3 _mulsc3 _muldc3 _mulxc3 _multc3 _divhc3 _divsc3 \ _divdc3 _divxc3 _divtc3 _bswapsi2 _bswapdi2 _clrsbsi2 \ - _clrsbdi2 + _clrsbdi2 _bitrevqi2 _bitrevhi2 _bitrevsi2 _bitrevdi2 # The floating-point conversion routines that involve a single-word integer. # XX stands for the integer mode. diff --git a/libgcc/libgcc-std.ver.in b/libgcc/libgcc-std.ver.in index c4f87a5..2198b0e 100644 --- a/libgcc/libgcc-std.ver.in +++ b/libgcc/libgcc-std.ver.in @@ -1944,3 +1944,12 @@ GCC_7.0.0 { __PFX__divmoddi4 __PFX__divmodti4 } + +%inherit GCC_14.0.0 GCC_7.0.0 +GCC_14.0.0 { + # bit reversal functions + __PFX__bitrevqi2 + __PFX__bitrevhi2 + __PFX__bitrevsi2 + __PFX__bitrevdi2 +} diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index e0017d1..2bef2a1 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -488,6 +488,54 @@ __bswapdi2 (DItype u) | (((u) & 0x00000000000000ffull) << 56)); } #endif + +#ifdef L_bitrevqi2 +QItype +__bitrevqi2 (QItype x) +{ + UQItype u = x; + u = (((u) >> 1) & 0x55) | (((u) & 0x55) << 1); + u = (((u) >> 2) & 0x33) | (((u) & 0x33) << 2); + return ((u) >> 4) | ((u) << 4); +} +#endif +#ifdef L_bitrevhi2 +HItype +__bitrevhi2 (HItype x) +{ + UHItype u = x; + u = (((u) >> 1) & 0x5555) | (((u) & 0x5555) << 1); + u = (((u) >> 2) & 0x3333) | (((u) & 0x3333) << 2); + u = (((u) >> 4) & 0x0f0f) | (((u) & 0x0f0f) << 4); + return ((u) >> 8) | ((u) << 8); +} +#endif +#ifdef L_bitrevsi2 +SItype +__bitrevsi2 (SItype x) +{ + USItype u = x; + u = (((u) >> 1) & 0x55555555) | (((u) & 0x55555555) << 1); + u = (((u) >> 2) & 0x33333333) | (((u) & 0x33333333) << 2); + u = (((u) >> 4) & 0x0f0f0f0f) | (((u) & 0x0f0f0f0f) << 4); + return __bswapsi2 (u); +} +#endif +#ifdef L_bitrevdi2 +DItype +__bitrevdi2 (DItype x) +{ + UDItype u = x; + u = (((u) >> 1) & 0x5555555555555555ll) + | (((u) & 0x5555555555555555ll) << 1); + u = (((u) >> 2) & 0x3333333333333333ll) + | (((u) & 0x3333333333333333ll) << 2); + u = (((u) >> 4) & 0x0f0f0f0f0f0f0f0fll) + | (((u) & 0x0f0f0f0f0f0f0f0fll) << 4); + return __bswapdi2 (u); +} +#endif + #ifdef L_ffssi2 #undef int int diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h index 3ec9bbd..e1abc0d 100644 --- a/libgcc/libgcc2.h +++ b/libgcc/libgcc2.h @@ -338,6 +338,10 @@ typedef int shift_count_type __attribute__((mode (__libgcc_shift_count__))); #define __udiv_w_sdiv __N(udiv_w_sdiv) #define __clear_cache __N(clear_cache) #define __enable_execute_stack __N(enable_execute_stack) +#define __bitrevqi2 __N(bitrevqi2) +#define __bitrevhi2 __N(bitrevhi2) +#define __bitrevsi2 __N(bitrevsi2) +#define __bitrevdi2 __N(bitrevdi2) #ifndef __powisf2 #define __powisf2 __N(powisf2) @@ -426,6 +430,15 @@ extern DWtype __subvDI3 (DWtype, DWtype); extern DWtype __mulvDI3 (DWtype, DWtype); extern DWtype __negvDI2 (DWtype); +extern QItype __bitrevqi2 (QItype); +extern HItype __bitrevhi2 (HItype); +#if MIN_UNITS_PER_WORD > 1 +extern SItype __bitrevsi2 (SItype); +#endif +#if __SIZEOF_LONG_LONG__ > 4 +extern DItype __bitrevdi2 (DItype); +#endif + #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC #define __absvsi2 __N(absvsi2) #define __negvsi2 __N(negvsi2)