From: Nemanja Ivanovic Date: Tue, 2 Mar 2021 01:23:26 +0000 (-0600) Subject: [PowerPC] Use modulo arithmetic for vec_extract in altivec.h X-Git-Tag: llvmorg-14-init~13690 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=38a34e207f30747a4b0288d97ce67e422bf5f363;p=platform%2Fupstream%2Fllvm.git [PowerPC] Use modulo arithmetic for vec_extract in altivec.h These interfaces are not covered in the ELFv2 ABI but are rather implemented to emulate those available in GCC/XLC. However, the ones in the other compilers are documented to perform modulo arithmetic on the element number. This patch just brings clang inline with the other compilers at -O0 (with optimization, clang already does the right thing). --- diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h index 4d50d47..402f3b3 100644 --- a/clang/lib/Headers/altivec.h +++ b/clang/lib/Headers/altivec.h @@ -12915,73 +12915,75 @@ vec_vxor(vector bool long long __a, vector bool long long __b) { /* vec_extract */ static __inline__ signed char __ATTRS_o_ai vec_extract(vector signed char __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0xf]; } static __inline__ unsigned char __ATTRS_o_ai -vec_extract(vector unsigned char __a, int __b) { - return __a[__b]; +vec_extract(vector unsigned char __a, unsigned int __b) { + return __a[__b & 0xf]; } static __inline__ unsigned char __ATTRS_o_ai vec_extract(vector bool char __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0xf]; } static __inline__ signed short __ATTRS_o_ai vec_extract(vector signed short __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0x7]; } static __inline__ unsigned short __ATTRS_o_ai -vec_extract(vector unsigned short __a, int __b) { - return __a[__b]; +vec_extract(vector unsigned short __a, unsigned int __b) { + return __a[__b & 0x7]; } static __inline__ unsigned short __ATTRS_o_ai vec_extract(vector bool short __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0x7]; } static __inline__ signed int __ATTRS_o_ai vec_extract(vector signed int __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0x3]; } static __inline__ unsigned int __ATTRS_o_ai vec_extract(vector unsigned int __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0x3]; } static __inline__ unsigned int __ATTRS_o_ai vec_extract(vector bool int __a, - int __b) { - return __a[__b]; + unsigned int __b) { + return __a[__b & 0x3]; } #ifdef __VSX__ static __inline__ signed long long __ATTRS_o_ai -vec_extract(vector signed long long __a, int __b) { - return __a[__b]; +vec_extract(vector signed long long __a, unsigned int __b) { + return __a[__b & 0x1]; } static __inline__ unsigned long long __ATTRS_o_ai -vec_extract(vector unsigned long long __a, int __b) { - return __a[__b]; +vec_extract(vector unsigned long long __a, unsigned int __b) { + return __a[__b & 0x1]; } static __inline__ unsigned long long __ATTRS_o_ai -vec_extract(vector bool long long __a, int __b) { - return __a[__b]; +vec_extract(vector bool long long __a, unsigned int __b) { + return __a[__b & 0x1]; } -static __inline__ double __ATTRS_o_ai vec_extract(vector double __a, int __b) { - return __a[__b]; +static __inline__ double __ATTRS_o_ai vec_extract(vector double __a, + unsigned int __b) { + return __a[__b & 0x1]; } #endif -static __inline__ float __ATTRS_o_ai vec_extract(vector float __a, int __b) { - return __a[__b]; +static __inline__ float __ATTRS_o_ai vec_extract(vector float __a, + unsigned int __b) { + return __a[__b & 0x3]; } #ifdef __POWER9_VECTOR__