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: 1758843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=mktJO5/q; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pg4fl70ndz246f for ; Mon, 20 Mar 2023 17:32:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAF47384D196 for ; Mon, 20 Mar 2023 06:32:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAF47384D196 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679293966; 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=mktJO5/qNsBLJp80waD4ILBjNnXlzlQFbEd0NsNUiJFT4RZCoiasD0uEnx2ksAt0u xageRtz58C//Fby5DgH3O/NGj18O4se6KNzqnuCjLhIWzmD3rmg7X33M9ozKVJY2u6 FLqbgA8Efqwfw6MwzCkerRRL+ZHGP+vqdJy0M/oM= 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+incoming=patchwork.ozlabs.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; +} +