[clang] 38a34e2 - [PowerPC] Use modulo arithmetic for vec_extract in altivec.h
Nemanja Ivanovic via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 1 17:49:44 PST 2021
Author: Nemanja Ivanovic
Date: 2021-03-01T19:49:26-06:00
New Revision: 38a34e207f30747a4b0288d97ce67e422bf5f363
URL: https://github.com/llvm/llvm-project/commit/38a34e207f30747a4b0288d97ce67e422bf5f363
DIFF: https://github.com/llvm/llvm-project/commit/38a34e207f30747a4b0288d97ce67e422bf5f363.diff
LOG: [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).
Added:
Modified:
clang/lib/Headers/altivec.h
Removed:
################################################################################
diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 4d50d47d51b5..402f3b389496 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__
More information about the cfe-commits
mailing list