From 2f782a796a2b0a4bb5ff772577f96eacdb9254c1 Mon Sep 17 00:00:00 2001 From: Nemanja Ivanovic Date: Tue, 23 Mar 2021 05:51:19 -0500 Subject: [PATCH] [PowerPC] Add more missing overloads to altivec.h Add overloads that perform subtraction on v1i128 that take and produce vector unsigned char to avoid needing to use __int128. The overloads are suffixed with _u128 and are needed for targets where __int128 isn't supported (AIX). --- clang/lib/Headers/altivec.h | 28 ++++++++++++++++++++++++++++ clang/test/CodeGen/builtins-ppc-quadword.c | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h index f3340f2..c567441 100644 --- a/clang/lib/Headers/altivec.h +++ b/clang/lib/Headers/altivec.h @@ -11636,6 +11636,12 @@ static __inline__ vector signed __int128 __ATTRS_o_ai vec_subc(vector signed __int128 __a, vector signed __int128 __b) { return __builtin_altivec_vsubcuq(__a, __b); } + +static __inline__ vector unsigned char __attribute__((__always_inline__)) +vec_subc_u128(vector unsigned char __a, vector unsigned char __b) { + return (vector unsigned char)__builtin_altivec_vsubcuq( + (vector unsigned __int128)__a, (vector unsigned __int128)__b); +} #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_vsubcuw */ @@ -11852,6 +11858,12 @@ vec_vsubuqm(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __a - __b; } +static __inline__ vector unsigned char __attribute__((__always_inline__)) +vec_sub_u128(vector unsigned char __a, vector unsigned char __b) { + return (vector unsigned char)((vector unsigned __int128)__a - + (vector unsigned __int128)__b); +} + /* vec_vsubeuqm */ @@ -11879,6 +11891,14 @@ vec_sube(vector unsigned __int128 __a, vector unsigned __int128 __b, return __builtin_altivec_vsubeuqm(__a, __b, __c); } +static __inline__ vector unsigned char __attribute__((__always_inline__)) +vec_sube_u128(vector unsigned char __a, vector unsigned char __b, + vector unsigned char __c) { + return (vector unsigned char)__builtin_altivec_vsubeuqm( + (vector unsigned __int128)__a, (vector unsigned __int128)__b, + (vector unsigned __int128)__c); +} + /* vec_vsubcuq */ static __inline__ vector signed __int128 __ATTRS_o_ai @@ -11928,6 +11948,14 @@ vec_subec(vector unsigned __int128 __a, vector unsigned __int128 __b, vector unsigned __int128 __c) { return __builtin_altivec_vsubecuq(__a, __b, __c); } + +static __inline__ vector unsigned char __attribute__((__always_inline__)) +vec_subec_u128(vector unsigned char __a, vector unsigned char __b, + vector unsigned char __c) { + return (vector unsigned char)__builtin_altivec_vsubecuq( + (vector unsigned __int128)__a, (vector unsigned __int128)__b, + (vector unsigned __int128)__c); +} #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) static __inline__ vector signed int __ATTRS_o_ai diff --git a/clang/test/CodeGen/builtins-ppc-quadword.c b/clang/test/CodeGen/builtins-ppc-quadword.c index 66cc9e8..561f0c2 100644 --- a/clang/test/CodeGen/builtins-ppc-quadword.c +++ b/clang/test/CodeGen/builtins-ppc-quadword.c @@ -14,6 +14,7 @@ vector signed __int128 vlll = { -1 }; // CHECK-PPC: error: __int128 is not supported on this target vector unsigned __int128 vulll = { 1 }; +vector unsigned char vuc; signed long long param_sll; // CHECK-PPC: error: __int128 is not supported on this target @@ -25,6 +26,7 @@ unsigned __int128 param_ulll; vector signed __int128 res_vlll; // CHECK-PPC: error: __int128 is not supported on this target vector unsigned __int128 res_vulll; +vector unsigned char res_vuc; // CHECK-LABEL: define{{.*}} void @test1 @@ -119,6 +121,10 @@ void test1() { // CHECK-LE: sub <1 x i128> // CHECK-PPC: error: assigning to '__vector unsigned __int128' (vector of 1 'unsigned __int128' value) from incompatible type 'int' + res_vuc = vec_sub_u128(vuc, vuc); +// CHECK: sub <1 x i128> +// CHECK-LE: sub <1 x i128> + /* vec_vsubeuqm */ res_vlll = vec_vsubeuqm(vlll, vlll, vlll); // CHECK: @llvm.ppc.altivec.vsubeuqm @@ -151,6 +157,10 @@ void test1() { // CHECK-LE: @llvm.ppc.altivec.vsubeuqm // CHECK-PPC: error: call to 'vec_sube' is ambiguous + res_vuc = vec_sube_u128(vuc, vuc, vuc); +// CHECK: @llvm.ppc.altivec.vsubeuqm +// CHECK-LE: @llvm.ppc.altivec.vsubeuqm + /* vec_subc */ res_vlll = vec_subc(vlll, vlll); // CHECK: @llvm.ppc.altivec.vsubcuq @@ -162,6 +172,10 @@ void test1() { // CHECK-LE: @llvm.ppc.altivec.vsubcuq // KCHECK-PPC: error: call to 'vec_subc' is ambiguous + res_vuc = vec_subc_u128(vuc, vuc); +// CHECK: @llvm.ppc.altivec.vsubcuq +// CHECK-LE: @llvm.ppc.altivec.vsubcuq + /* vec_vsubcuq */ res_vlll = vec_vsubcuq(vlll, vlll); // CHECK: @llvm.ppc.altivec.vsubcuq @@ -194,6 +208,10 @@ void test1() { // CHECK-LE: @llvm.ppc.altivec.vsubecuq // CHECK-PPC: error: assigning to '__vector unsigned __int128' (vector of 1 'unsigned __int128' value) from incompatible type 'int' + res_vuc = vec_subec_u128(vuc, vuc, vuc); +// CHECK: @llvm.ppc.altivec.vsubecuq +// CHECK-LE: @llvm.ppc.altivec.vsubecuq + res_vulll = vec_revb(vulll); // CHECK: store <16 x i8> , <16 x i8>* {{%.+}}, align 16 // CHECK: call <4 x i32> @llvm.ppc.altivec.vperm(<4 x i32> {{%.+}}, <4 x i32> {{%.+}}, <16 x i8> {{%.+}}) -- 2.7.4