From patchwork Tue Feb 20 17:55:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 1901602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=X3JLIv+v; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TfRt95KnXz20Qg for ; Wed, 21 Feb 2024 04:56:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F71C3858420 for ; Tue, 20 Feb 2024 17:56:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id C4CD13858C56 for ; Tue, 20 Feb 2024 17:56:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4CD13858C56 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4CD13858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451763; cv=none; b=v35JKSMA5KMOmEs1vGIfLLYJRJ/Mf59TXTauGlimSnOPO2XSHAzcA+naPEGFSrCktRQ9JEGv64wyJ7wF7F4oV5zDJKaV7mlOvWkSlae+WfBFMfpt/XEomVrAhiHs1JIp7Rr2Q5GIlTibYPPxYT/NrcLT20FwEsUen4C5z4EO/mM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451763; c=relaxed/simple; bh=wC5gypw2TmQgwuqC2moSNk0iI2J5ZwHihTImmegwrwE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=db/t9qw8Gt0XIHV0sVYluTCLt15S9abz4B5VzRPvQ+uI+9+PoK9qk0iNvxx56iWlToyYL4w2dEKYkCvo6VzaQ4cCHjKSlP1RBPYdFwQ7YfgHXFMC8sEzC725ChNHGZZkQWM84ApkVotlLDLH24q968nOPIlPZwgJrQsTLRLFNfo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41KHE3GW001216; Tue, 20 Feb 2024 17:56:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=p9yHeYEvp7bDZP/VyzgTem6SN/28eUyFOWN7zV8l+8M=; b=X3JLIv+vUMx4RNeKDJNAToSOAIw4cVJV0MihfUmaRv3mpreV9FnV4ryDq9xzqCISxpiI ulFFbQ4t+s0RRuKEE8XbEBJE4f/FfB4AbGqWpoJvHq2/4yjuKnQVr6EeIKzcvQAyvtjX LfRxjrmGjAG6IaHBOSzBULycFYAXUMspchs1/k2OG+II897T+KDAPJWELpQPJxfDUogJ whSx1FzVrZBmUPvEzlDj3w7UBvuEpyriZv4SgCedV/w+ZtX+6UWaPaNYXa7ox8eFyUrN FfZdWLGXkIVZ3sfFZYVRhZXunFEhMcJHg3r8Y5tHzONnH18BMqcw1KWYoIhRJYoEGiNu bw== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wd0a01154-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 17:55:59 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41KGEluC003611; Tue, 20 Feb 2024 17:55:58 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wb74tj3ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 17:55:58 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41KHttm110224312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Feb 2024 17:55:57 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4FBA25805F; Tue, 20 Feb 2024 17:55:55 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 96F0C58045; Tue, 20 Feb 2024 17:55:54 +0000 (GMT) Received: from [9.67.96.239] (unknown [9.67.96.239]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Feb 2024 17:55:54 +0000 (GMT) Message-ID: <6044dc7e-7068-488c-8451-1541582fc2de@linux.ibm.com> Date: Tue, 20 Feb 2024 09:55:53 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 01/11] rs6000, Fix __builtin_vsx_cmple* args and documentation, builtins Content-Language: en-US To: gcc-patches@gcc.gnu.org, "bergner@linux.ibm.com" , Segher Boessenkool , "Kewen.Lin" References: <41290fb1-e2e8-4779-b76f-2208c2dadedd@linux.ibm.com> From: Carl Love In-Reply-To: <41290fb1-e2e8-4779-b76f-2208c2dadedd@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6wC5BGeDk-ziAK51wcvDB3FINcM-7Sat X-Proofpoint-GUID: 6wC5BGeDk-ziAK51wcvDB3FINcM-7Sat X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 bulkscore=0 suspectscore=0 mlxlogscore=998 spamscore=0 clxscore=1015 adultscore=0 priorityscore=1501 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402200128 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org GCC maintainers: This patch fixes the arguments and return type for the various __builtin_vsx_cmple* built-ins. They were defined as signed but should have been defined as unsigned. The patch has been tested on Power 10 with no regressions. Please let me know if this patch is acceptable for mainline. Thanks. Carl ----------------------------------------------------- rs6000, Fix __builtin_vsx_cmple* args and documentation, builtins The built-ins __builtin_vsx_cmple_u16qi, __builtin_vsx_cmple_u2di, __builtin_vsx_cmple_u4si and __builtin_vsx_cmple_u8hi should take unsigned arguments and return an unsigned result. This patch changes the arguments and return type from signed to unsigned. The documentation for the signed and unsigned versions of __builtin_vsx_cmple is missing from extend.texi. This patch adds the missing documentation. Test cases are added for each of the signed and unsigned built-ins. gcc/ChangeLog: * config/rs6000/rs6000-builtins.def (__builtin_vsx_cmple_u16qi, __builtin_vsx_cmple_u2di, __builtin_vsx_cmple_u4si): Change arguments and return from signed to unsigned. * doc/extend.texi (__builtin_vsx_cmple_16qi, __builtin_vsx_cmple_8hi, __builtin_vsx_cmple_4si, __builtin_vsx_cmple_u16qi, __builtin_vsx_cmple_u8hi, __builtin_vsx_cmple_u4si): Add documentation. gcc/testsuite/ChangeLog: * gcc.target/powerpc/vsx-cmple.c: New test file. --- gcc/config/rs6000/rs6000-builtins.def | 10 +- gcc/doc/extend.texi | 23 ++++ gcc/testsuite/gcc.target/powerpc/vsx-cmple.c | 127 +++++++++++++++++++ 3 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/vsx-cmple.c diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def index 3bc7fed6956..d66a53a0fab 100644 --- a/gcc/config/rs6000/rs6000-builtins.def +++ b/gcc/config/rs6000/rs6000-builtins.def @@ -1349,16 +1349,16 @@ const vss __builtin_vsx_cmple_8hi (vss, vss); CMPLE_8HI vector_ngtv8hi {} - const vsc __builtin_vsx_cmple_u16qi (vsc, vsc); + const vuc __builtin_vsx_cmple_u16qi (vuc, vuc); CMPLE_U16QI vector_ngtuv16qi {} - const vsll __builtin_vsx_cmple_u2di (vsll, vsll); + const vull __builtin_vsx_cmple_u2di (vull, vull); CMPLE_U2DI vector_ngtuv2di {} - const vsi __builtin_vsx_cmple_u4si (vsi, vsi); + const vui __builtin_vsx_cmple_u4si (vui, vui); CMPLE_U4SI vector_ngtuv4si {} - const vss __builtin_vsx_cmple_u8hi (vss, vss); + const vus __builtin_vsx_cmple_u8hi (vus, vus); CMPLE_U8HI vector_ngtuv8hi {} const vd __builtin_vsx_concat_2df (double, double); @@ -1769,7 +1769,7 @@ const vf __builtin_vsx_xvcvuxdsp (vull); XVCVUXDSP vsx_xvcvuxdsp {} - const vd __builtin_vsx_xvcvuxwdp (vsi); + const vd __builtin_vsx_xvcvuxwdp (vui); XVCVUXWDP vsx_xvcvuxwdp {} const vf __builtin_vsx_xvcvuxwsp (vsi); diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 2b8ba1949bf..4d8610f6aa8 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -22522,6 +22522,29 @@ if the VSX instruction set is available. The @samp{vec_vsx_ld} and @samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X}, @samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions. + +@smallexample +vector signed char __builtin_vsx_cmple_16qi (vector signed char, + vector signed char); +vector signed short __builtin_vsx_cmple_8hi (vector signed short, + vector signed short); +vector signed int __builtin_vsx_cmple_4si (vector signed int, + vector signed int); +vector unsigned char __builtin_vsx_cmple_u16qi (vector unsigned char, + vector unsigned char); +vector unsigned short __builtin_vsx_cmple_u8hi (vector unsigned short, + vector unsigned short); +vector unsigned int __builtin_vsx_cmple_u4si (vector unsigned int, + vector unsigned int); +@end smallexample + +The builti-ins @code{__builtin_vsx_cmple_16qi}, @code{__builtin_vsx_cmple_8hi}, +@code{__builtin_vsx_cmple_4si}, @code{__builtin_vsx_cmple_u16qi}, +@code{__builtin_vsx_cmple_u8hi} and @code{__builtin_vsx_cmple_u4si} compare +vectors of their defined type. The corresponding result element is set to +all ones if the two argument elements are less than or equal and all zeros +otherwise. + @node PowerPC AltiVec Built-in Functions Available on ISA 2.07 @subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.07 diff --git a/gcc/testsuite/gcc.target/powerpc/vsx-cmple.c b/gcc/testsuite/gcc.target/powerpc/vsx-cmple.c new file mode 100644 index 00000000000..081817b4ba3 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vsx-cmple.c @@ -0,0 +1,127 @@ +/* { dg-do run } */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec -O2 -save-temps" } */ + +#define DEBUG 0 + +#include + +#if DEBUG +#include +#include +#endif + +void abort (void); + +#if DEBUG + #define ACTION(NAME, TYPE_NAME) \ + printf ("test_vsx_cmple_%s: result_%s[%d] = 0x%x, expected_result_%s[%d] = 0x%x\n", \ + #NAME, #TYPE_NAME, i, result_##TYPE_NAME[i], \ + #TYPE_NAME, i, (int)expected_result_##TYPE_NAME[i]); +#else + #define ACTION(NAME, TYPE_NAME) \ + abort(); +#endif + +#define TEST(NAME, TYPE, TYPE_NAME) \ +void test_vsx_cmple_##NAME (vector TYPE arg1_##TYPE_NAME, \ + vector TYPE arg2_##TYPE_NAME, \ + vector TYPE expected_result_##TYPE_NAME) \ +{ \ + vector TYPE result_##TYPE_NAME; \ + int i, len = 16/sizeof(TYPE); \ + \ + result_##TYPE_NAME = __builtin_vsx_cmple_##NAME (arg1_##TYPE_NAME, \ + arg2_##TYPE_NAME); \ + for (i = 0; i < len; i++) \ + if (result_##TYPE_NAME[i] != expected_result_##TYPE_NAME[i]) \ + ACTION(TYPE, TYPE_NAME) \ +} + +int main () +{ + + vector signed char vsc_arg1, vsc_arg2, vsc_expected_result; + vector signed short vsh_arg1, vsh_arg2, vsh_expected_result; + vector signed int vsi_arg1, vsi_arg2, vsi_expected_result; + vector signed long long vsll_arg1, vsll_arg2, vsll_expected_result; + vector unsigned char vuc_arg1, vuc_arg2, vuc_expected_result; + vector unsigned short vuh_arg1, vuh_arg2, vuh_expected_result; + vector unsigned int vui_arg1, vui_arg2, vui_expected_result; + vector unsigned long long vull_arg1, vull_arg2, vull_expected_result; + + vsc_arg1 = (vector signed char) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16}; + vsc_arg2 = (vector signed char) {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26}; + vsc_expected_result = (vector signed char) {0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF}; + /* Test for __builtin_vsx_cmple_16qi */ + TEST (16qi, signed char, vsc) + test_vsx_cmple_16qi (vsc_arg1, vsc_arg2, vsc_expected_result); + + vsh_arg1 = (vector signed short) {1, 2, 3, 4, 5, 6, 7, 8}; + vsh_arg2 = (vector signed short) {11, 12, 13, 14, 15, 16, 17, 18}; + vsh_expected_result = (vector signed short) {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; + /* Test for __builtin_vsx_cmple_8hi */ + TEST (8hi, signed short, vsh) + test_vsx_cmple_8hi (vsh_arg1, vsh_arg2, vsh_expected_result); + + vsi_arg1 = (vector signed int) {1, 2, 3, 4}; + vsi_arg2 = (vector signed int) {11, 12, 13, 14}; + vsi_expected_result = (vector signed int) {0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF}; + /* Test for __builtin_vsx_cmple_4si */ + TEST (4si, signed int, vsi) + test_vsx_cmple_4si (vsi_arg1, vsi_arg2, vsi_expected_result); + + vsll_arg1 = (vector signed long long) {1, 2}; + vsll_arg2 = (vector signed long long) {11, 12}; + vsll_expected_result = (vector signed long long) {0xFFFFFFFFFFFFFFFF, + 0xFFFFFFFFFFFFFFFF}; + /* Test for __builtin_vsx_cmple_2di */ + TEST (2di, signed long long, vsll) + test_vsx_cmple_2di (vsll_arg1, vsll_arg2, vsll_expected_result); + + vuc_arg1 = (vector unsigned char) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16}; + vuc_arg2 = (vector unsigned char) {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26}; + vuc_expected_result = (vector unsigned char) {0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF}; + /* Test for __builtin_vsx_cmple_u16qi */ + TEST (u16qi, unsigned char, vuc) + test_vsx_cmple_u16qi (vuc_arg1, vuc_arg2, vuc_expected_result); + + vuh_arg1 = (vector unsigned short) {1, 2, 3, 4, 5, 6, 7, 8}; + vuh_arg2 = (vector unsigned short) {11, 12, 13, 14, 15, 16, 17, 18}; + vuh_expected_result = (vector unsigned short) {0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF}; + /* Test for __builtin_vsx_cmple_u8hi */ + TEST (u8hi, unsigned short, vuh) + test_vsx_cmple_u8hi (vuh_arg1, vuh_arg2, vuh_expected_result); + + vui_arg1 = (vector unsigned int) {1, 2, 3, 4}; + vui_arg2 = (vector unsigned int) {11, 12, 13, 14}; + vui_expected_result = (vector unsigned int) {0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF}; + /* Test for __builtin_vsx_cmple_u4si */ + TEST (u4si, unsigned int, vui) + test_vsx_cmple_u4si (vui_arg1, vui_arg2, vui_expected_result); + + vull_arg1 = (vector unsigned long long) {1, 2}; + vull_arg2 = (vector unsigned long long) {11, 12}; + vull_expected_result = (vector unsigned long long) {0xFFFFFFFFFFFFFFFF, + 0xFFFFFFFFFFFFFFFF}; + /* Test for __builtin_vsx_cmple_u2di */ + TEST (u2di, unsigned long long, vull) + test_vsx_cmple_u2di (vull_arg1, vull_arg2, vull_expected_result); + return 0; +}