From patchwork Mon Mar 20 06:32:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 66631 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7F6338515D7 for ; Mon, 20 Mar 2023 06:32:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7F6338515D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679293974; bh=iWezXca+9X/QSKEslq+IXgc4f6Gbasy3/Og9tV9wGZg=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=L5GUpPLDa+xBEbOJs8mRIRns3uNEi59q2o8KUuTxYHVjXxXN44/hCQQRspBYkmTmr fMdsA8paAWIJcqd14C8sWb+dw0WnM1A+a8VdqWtIxCFGoc4M85OJKVJBREZDBNMzB0 OojobgySzifRJLPZRRHGYUtO2Tg8JdC4JA19FdOQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 4DD1F3850867 for ; Mon, 20 Mar 2023 06:32:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DD1F3850867 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32K5RTNT031236; Mon, 20 Mar 2023 06:32:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pdq4rfqwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 06:32:24 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32K6ENGW022902; Mon, 20 Mar 2023 06:32:23 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pdq4rfqvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 06:32:23 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32K4YQBI022403; Mon, 20 Mar 2023 06:32:21 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3pd4x6asp5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 06:32:21 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32K6WIga22283000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Mar 2023 06:32:18 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A70F420049; Mon, 20 Mar 2023 06:32:18 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EE7AB20040; Mon, 20 Mar 2023 06:32:16 +0000 (GMT) Received: from [9.177.11.227] (unknown [9.177.11.227]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Mar 2023 06:32:16 +0000 (GMT) Message-ID: <9cac9802-cb71-ad06-fc2d-a79b486091fa@linux.ibm.com> Date: Mon, 20 Mar 2023 14:32:15 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US Subject: [PATCH] rs6000: Make _mm_slli_si128 and _mm_bslli_si128 consistent [PR109167] To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pSOBaEKz9p2NbPg0DjW2_d5wLW__YVVZ X-Proofpoint-ORIG-GUID: gXShOtMZB1pXJgrXAn9YUXXOgms5OchI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-20_04,2023-03-16_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 mlxscore=0 spamscore=0 clxscore=1015 suspectscore=0 bulkscore=0 mlxlogscore=670 malwarescore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303200057 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP 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: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, As PR109167 shows, it's unexpected to have two different implementation ways for _mm_slli_si128 and _mm_bslli_si128, as gcc/config/i386/emmintrin.h they should be the same. So this patch is to fix it accordingly. Bootstrapped and regtested on powerpc64-linux-gnu P8 and powerpc64le-linux-gnu P9 and P10. I'm going to push this soon if no objections. BR, Kewen ----- PR target/109167 gcc/ChangeLog: * config/rs6000/emmintrin.h (_mm_bslli_si128): Move the implementation from ... (_mm_slli_si128): ... here. Change to call _mm_bslli_si128 directly. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr109167.c: New test. --- gcc/config/rs6000/emmintrin.h | 26 ++++-------- gcc/testsuite/gcc.target/powerpc/pr109167.c | 47 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr109167.c -- 2.31.1 diff --git a/gcc/config/rs6000/emmintrin.h b/gcc/config/rs6000/emmintrin.h index bfff7ff6fea..44d01a83d8d 100644 --- a/gcc/config/rs6000/emmintrin.h +++ b/gcc/config/rs6000/emmintrin.h @@ -1601,8 +1601,14 @@ _mm_bslli_si128 (__m128i __A, const int __N) __v16qu __result; const __v16qu __zeros = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - if (__N >= 0 && __N < 16) + if (__N == 0) + return __A; + else if (__N > 0 && __N < 16) +#ifdef __LITTLE_ENDIAN__ __result = vec_sld ((__v16qu) __A, __zeros, __N); +#else + __result = vec_sld (__zeros, (__v16qu) __A, (16 - __N)); +#endif else __result = __zeros; @@ -1647,23 +1653,9 @@ _mm_srli_si128 (__m128i __A, const int __N) } extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_slli_si128 (__m128i __A, const int _imm5) +_mm_slli_si128 (__m128i __A, const int __N) { - __v16qu __result; - const __v16qu __zeros = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - if (_imm5 == 0) - return __A; - else if (_imm5 > 0 && _imm5 < 16) -#ifdef __LITTLE_ENDIAN__ - __result = vec_sld ((__v16qu) __A, __zeros, _imm5); -#else - __result = vec_sld (__zeros, (__v16qu) __A, (16 - _imm5)); -#endif - else - __result = __zeros; - - return (__m128i) __result; + return _mm_bslli_si128 (__A, __N); } extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) diff --git a/gcc/testsuite/gcc.target/powerpc/pr109167.c b/gcc/testsuite/gcc.target/powerpc/pr109167.c new file mode 100644 index 00000000000..d490c995b14 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr109167.c @@ -0,0 +1,47 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vsx_hw } */ +/* { dg-options "-O2 -mvsx" } */ + +/* Verify there is no warning message. */ + +#define NO_WARN_X86_INTRINSICS 1 + +#include + +#define N 5 + +__attribute__ ((noipa)) __m128i +test1 (__m128i v) +{ + return _mm_bslli_si128 (v, N); +} + +__attribute__ ((noipa)) __m128i +test2 (__m128i v) +{ + return _mm_slli_si128 (v, N); +} + +typedef union +{ + __m128i x; + unsigned char a[16]; +} union128i_ub; + +int main() +{ + union128i_ub v; + v.x + = _mm_set_epi8 (1, 2, 3, 4, 10, 20, 30, 90, 80, 40, 100, 15, 98, 25, 98, 7); + + union128i_ub r1, r2; + r1.x = test1 (v.x); + r2.x = test2 (v.x); + + for (int i = 0; i < 16; i++) + if (r1.a[i] != r2.a[i]) + __builtin_abort(); + + return 0; +} +