From 97054171ba329891fa63df9b61414b60076b3142 Mon Sep 17 00:00:00 2001 From: Tony Jiang Date: Tue, 8 Nov 2016 04:15:45 +0000 Subject: [PATCH] [PowerPC] Implement remaining vector comparison builtins. vector bool char vec_cmpeq (vector bool char, vector bool char); vector bool int vec_cmpeq (vector bool int, vector bool int); vector bool long long vec_cmpeq (vector bool long long, vector bool long lon vector bool short vec_cmpeq (vector bool short, vector bool short); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286205 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Headers/altivec.h | 77 +++++++++++++++++++--------- test/CodeGen/builtins-ppc-altivec.c | 24 +++++++++ test/CodeGen/builtins-ppc-p8vector.c | 5 ++ 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/lib/Headers/altivec.h b/lib/Headers/altivec.h index b2608cfb46..a4446b61a4 100644 --- a/lib/Headers/altivec.h +++ b/lib/Headers/altivec.h @@ -1564,6 +1564,12 @@ vec_cmpeq(vector unsigned char __a, vector unsigned char __b) { (vector char)__b); } +static __inline__ vector bool char __ATTRS_o_ai +vec_cmpeq(vector bool char __a, vector bool char __b) { + return (vector bool char)__builtin_altivec_vcmpequb((vector char)__a, + (vector char)__b); +} + static __inline__ vector bool short __ATTRS_o_ai vec_cmpeq(vector short __a, vector short __b) { return (vector bool short)__builtin_altivec_vcmpequh(__a, __b); @@ -1575,6 +1581,12 @@ vec_cmpeq(vector unsigned short __a, vector unsigned short __b) { (vector short)__b); } +static __inline__ vector bool short __ATTRS_o_ai +vec_cmpeq(vector bool short __a, vector bool short __b) { + return (vector bool short)__builtin_altivec_vcmpequh((vector short)__a, + (vector short)__b); +} + static __inline__ vector bool int __ATTRS_o_ai vec_cmpeq(vector int __a, vector int __b) { return (vector bool int)__builtin_altivec_vcmpequw(__a, __b); @@ -1586,6 +1598,12 @@ vec_cmpeq(vector unsigned int __a, vector unsigned int __b) { (vector int)__b); } +static __inline__ vector bool int __ATTRS_o_ai vec_cmpeq(vector bool int __a, + vector bool int __b) { + return (vector bool int)__builtin_altivec_vcmpequw((vector int)__a, + (vector int)__b); +} + #ifdef __POWER8_VECTOR__ static __inline__ vector bool long long __ATTRS_o_ai vec_cmpeq(vector signed long long __a, vector signed long long __b) { @@ -1597,6 +1615,13 @@ vec_cmpeq(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)__builtin_altivec_vcmpequd( (vector long long)__a, (vector long long)__b); } + +static __inline__ vector bool long long __ATTRS_o_ai +vec_cmpeq(vector bool long long __a, vector bool long long __b) { + return (vector bool long long)__builtin_altivec_vcmpequd( + (vector long long)__a, (vector long long)__b); +} + #endif static __inline__ vector bool int __ATTRS_o_ai vec_cmpeq(vector float __a, @@ -2298,14 +2323,15 @@ vec_first_match_or_eos_index(vector signed char __a, vector signed char __b) { result if either is zero. */ vector bool char __tmp1 = vec_cmpeq(__a, __b); - vector bool char __tmp2 = __tmp1 | vec_cmpeq(__tmp1, __a) | - vec_cmpeq(__tmp1, __b); + vector bool char __tmp2 = __tmp1 | + vec_cmpeq((vector signed char)__tmp1, __a) | + vec_cmpeq((vector signed char)__tmp1, __b); vector unsigned long long __res = #ifdef __LITTLE_ENDIAN__ - vec_cnttz((vector unsigned long long)__tmp2); + vec_cnttz((vector unsigned long long)__tmp2); #else - vec_cntlz((vector unsigned long long)__tmp2); + vec_cntlz((vector unsigned long long)__tmp2); #endif if (__res[0] == 64) { return (__res[1] + 64) >> 3; @@ -2317,14 +2343,15 @@ static __inline__ unsigned __ATTRS_o_ai vec_first_match_or_eos_index(vector unsigned char __a, vector unsigned char __b) { vector bool char __tmp1 = vec_cmpeq(__a, __b); - vector bool char __tmp2 = __tmp1 | vec_cmpeq(__tmp1, __a) | - vec_cmpeq(__tmp1, __b); + vector bool char __tmp2 = __tmp1 | + vec_cmpeq((vector unsigned char)__tmp1, __a) | + vec_cmpeq((vector unsigned char)__tmp1, __b); vector unsigned long long __res = #ifdef __LITTLE_ENDIAN__ - vec_cnttz((vector unsigned long long)__tmp2); + vec_cnttz((vector unsigned long long)__tmp2); #else - vec_cntlz((vector unsigned long long)__tmp2); + vec_cntlz((vector unsigned long long)__tmp2); #endif if (__res[0] == 64) { return (__res[1] + 64) >> 3; @@ -2335,14 +2362,15 @@ vec_first_match_or_eos_index(vector unsigned char __a, static __inline__ unsigned __ATTRS_o_ai vec_first_match_or_eos_index(vector signed short __a, vector signed short __b) { vector bool short __tmp1 = vec_cmpeq(__a, __b); - vector bool short __tmp2 = __tmp1 | vec_cmpeq(__tmp1, __a) | - vec_cmpeq(__tmp1, __b); + vector bool short __tmp2 = __tmp1 | + vec_cmpeq((vector signed short)__tmp1, __a) | + vec_cmpeq((vector signed short)__tmp1, __b); vector unsigned long long __res = #ifdef __LITTLE_ENDIAN__ - vec_cnttz((vector unsigned long long)__tmp2); + vec_cnttz((vector unsigned long long)__tmp2); #else - vec_cntlz((vector unsigned long long)__tmp2); + vec_cntlz((vector unsigned long long)__tmp2); #endif if (__res[0] == 64) { return (__res[1] + 64) >> 4; @@ -2354,14 +2382,15 @@ static __inline__ unsigned __ATTRS_o_ai vec_first_match_or_eos_index(vector unsigned short __a, vector unsigned short __b) { vector bool short __tmp1 = vec_cmpeq(__a, __b); - vector bool short __tmp2 = __tmp1 | vec_cmpeq(__tmp1, __a) | - vec_cmpeq(__tmp1, __b); + vector bool short __tmp2 = __tmp1 | + vec_cmpeq((vector unsigned short)__tmp1, __a) | + vec_cmpeq((vector unsigned short)__tmp1, __b); vector unsigned long long __res = #ifdef __LITTLE_ENDIAN__ - vec_cnttz((vector unsigned long long)__tmp2); + vec_cnttz((vector unsigned long long)__tmp2); #else - vec_cntlz((vector unsigned long long)__tmp2); + vec_cntlz((vector unsigned long long)__tmp2); #endif if (__res[0] == 64) { return (__res[1] + 64) >> 4; @@ -2372,14 +2401,14 @@ vec_first_match_or_eos_index(vector unsigned short __a, static __inline__ unsigned __ATTRS_o_ai vec_first_match_or_eos_index(vector signed int __a, vector signed int __b) { vector bool int __tmp1 = vec_cmpeq(__a, __b); - vector bool int __tmp2 = __tmp1 | vec_cmpeq(__tmp1, __a) | - vec_cmpeq(__tmp1, __b); + vector bool int __tmp2 = __tmp1 | vec_cmpeq((vector signed int)__tmp1, __a) | + vec_cmpeq((vector signed int)__tmp1, __b); vector unsigned long long __res = #ifdef __LITTLE_ENDIAN__ - vec_cnttz((vector unsigned long long)__tmp2); + vec_cnttz((vector unsigned long long)__tmp2); #else - vec_cntlz((vector unsigned long long)__tmp2); + vec_cntlz((vector unsigned long long)__tmp2); #endif if (__res[0] == 64) { return (__res[1] + 64) >> 5; @@ -2388,11 +2417,11 @@ vec_first_match_or_eos_index(vector signed int __a, vector signed int __b) { } static __inline__ unsigned __ATTRS_o_ai -vec_first_match_or_eos_index(vector unsigned int __a, - vector unsigned int __b) { +vec_first_match_or_eos_index(vector unsigned int __a, vector unsigned int __b) { vector bool int __tmp1 = vec_cmpeq(__a, __b); - vector bool int __tmp2 = __tmp1 | vec_cmpeq(__tmp1, __a) | - vec_cmpeq(__tmp1, __b); + vector bool int __tmp2 = __tmp1 | + vec_cmpeq((vector unsigned int)__tmp1, __a) | + vec_cmpeq((vector unsigned int)__tmp1, __b); vector unsigned long long __res = #ifdef __LITTLE_ENDIAN__ diff --git a/test/CodeGen/builtins-ppc-altivec.c b/test/CodeGen/builtins-ppc-altivec.c index abe49f17df..56b4f7d569 100644 --- a/test/CodeGen/builtins-ppc-altivec.c +++ b/test/CodeGen/builtins-ppc-altivec.c @@ -936,6 +936,14 @@ void test2() { res_vbc = vec_cmpeq(vuc, vuc); // CHECK: @llvm.ppc.altivec.vcmpequb +// CHECK-LE: @llvm.ppc.altivec.vcmpequb + + res_vbc = vec_cmpeq(vbc, vbc); +// CHECK: @llvm.ppc.altivec.vcmpequb +// CHECK-LE: @llvm.ppc.altivec.vcmpequb + + res_vbc = vec_cmpeq(vbc, vbc); +// CHECK: @llvm.ppc.altivec.vcmpequb // CHECK-LE: @llvm.ppc.altivec.vcmpequb res_vbs = vec_cmpeq(vs, vs); @@ -944,6 +952,14 @@ void test2() { res_vbs = vec_cmpeq(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpequh +// CHECK-LE: @llvm.ppc.altivec.vcmpequh + + res_vbs = vec_cmpeq(vbs, vbs); +// CHECK: @llvm.ppc.altivec.vcmpequh +// CHECK-LE: @llvm.ppc.altivec.vcmpequh + + res_vbs = vec_cmpeq(vbs, vbs); +// CHECK: @llvm.ppc.altivec.vcmpequh // CHECK-LE: @llvm.ppc.altivec.vcmpequh res_vbi = vec_cmpeq(vi, vi); @@ -952,6 +968,14 @@ void test2() { res_vbi = vec_cmpeq(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpequw +// CHECK-LE: @llvm.ppc.altivec.vcmpequw + + res_vbi = vec_cmpeq(vbi, vbi); +// CHECK: @llvm.ppc.altivec.vcmpequw +// CHECK-LE: @llvm.ppc.altivec.vcmpequw + + res_vbi = vec_cmpeq(vbi, vbi); +// CHECK: @llvm.ppc.altivec.vcmpequw // CHECK-LE: @llvm.ppc.altivec.vcmpequw res_vbi = vec_cmpeq(vf, vf); diff --git a/test/CodeGen/builtins-ppc-p8vector.c b/test/CodeGen/builtins-ppc-p8vector.c index 5edb9481dd..3e298442b6 100644 --- a/test/CodeGen/builtins-ppc-p8vector.c +++ b/test/CodeGen/builtins-ppc-p8vector.c @@ -151,6 +151,11 @@ void test1() { // CHECK-PPC: warning: implicit declaration of function 'vec_mergeo' /* vec_cmpeq */ + res_vbll = vec_cmpeq(vbll, vbll); +// CHECK: @llvm.ppc.altivec.vcmpequd +// CHECK-LE: @llvm.ppc.altivec.vcmpequd +// CHECK-PPC: error: call to 'vec_cmpeq' is ambiguous + res_vbll = vec_cmpeq(vsll, vsll); // CHECK: @llvm.ppc.altivec.vcmpequd // CHECK-LE: @llvm.ppc.altivec.vcmpequd -- 2.40.0