aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorZarko Todorovski <zarko@ca.ibm.com>2023-07-11 10:53:41 -0400
committerZarko Todorovski <zarko@ca.ibm.com>2023-07-11 11:52:07 -0400
commit14742f2a689c825adebc54cbade9c89fbe426da8 (patch)
treeb421f2d57a7d199ed9518e10529612d49e59c237 /clang/lib
parent5f8e6f0cd1acd936fd26453cdc46ab63eb0764cb (diff)
downloadllvm-14742f2a689c825adebc54cbade9c89fbe426da8.zip
llvm-14742f2a689c825adebc54cbade9c89fbe426da8.tar.gz
llvm-14742f2a689c825adebc54cbade9c89fbe426da8.tar.bz2
[PowerPC] Truncate exponent parameter for vec_cts,vec_ctf
On PowerPC, the vec_ct* builtin function take the form of eg. d=vec_cts(a,b) LLVM (llc) will crash when a user specifies a number out of the allowed range (0-31) for b.This patch truncates b so that we avoid the backend crash in some cases. Further documentation for the builtins can be found here: https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.0?topic=functions-vec-ctf https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.0?topic=functions-vec-cts Reviewed By: nemanjai, #powerpc Differential Revision: https://reviews.llvm.org/D106409
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Headers/altivec.h260
1 files changed, 136 insertions, 124 deletions
diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index f50466e..c036f5e 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -3202,71 +3202,79 @@ static __inline__ vector double __ATTRS_o_ai vec_cpsgn(vector double __a,
// the XL-compatible signatures are used for those functions.
#ifdef __XL_COMPAT_ALTIVEC__
#define vec_ctf(__a, __b) \
- _Generic( \
- (__a), vector int \
- : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)), \
- vector unsigned int \
- : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
- (__b)), \
- vector unsigned long long \
- : (vector float)(__builtin_vsx_xvcvuxdsp( \
- (vector unsigned long long)(__a)) * \
- (vector float)(vector unsigned)((0x7f - (__b)) << 23)), \
- vector signed long long \
- : (vector float)(__builtin_vsx_xvcvsxdsp( \
- (vector signed long long)(__a)) * \
- (vector float)(vector unsigned)((0x7f - (__b)) << 23)))
+ _Generic((__a), \
+ vector int: (vector float)__builtin_altivec_vcfsx((vector int)(__a), \
+ ((__b)&0x1F)), \
+ vector unsigned int: (vector float)__builtin_altivec_vcfux( \
+ (vector unsigned int)(__a), ((__b)&0x1F)), \
+ vector unsigned long long: ( \
+ vector float)(__builtin_vsx_xvcvuxdsp( \
+ (vector unsigned long long)(__a)) * \
+ (vector float)(vector unsigned)((0x7f - \
+ ((__b)&0x1F)) \
+ << 23)), \
+ vector signed long long: ( \
+ vector float)(__builtin_vsx_xvcvsxdsp( \
+ (vector signed long long)(__a)) * \
+ (vector float)(vector unsigned)((0x7f - \
+ ((__b)&0x1F)) \
+ << 23)))
#else // __XL_COMPAT_ALTIVEC__
-#define vec_ctf(__a, __b) \
- _Generic( \
- (__a), vector int \
- : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)), \
- vector unsigned int \
- : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
- (__b)), \
- vector unsigned long long \
- : (vector float)(__builtin_convertvector( \
- (vector unsigned long long)(__a), vector double) * \
- (vector double)(vector unsigned long long)((0x3ffULL - \
- (__b)) \
- << 52)), \
- vector signed long long \
- : (vector float)(__builtin_convertvector((vector signed long long)(__a), \
- vector double) * \
- (vector double)(vector unsigned long long)((0x3ffULL - \
- (__b)) \
- << 52)))
+#define vec_ctf(__a, __b) \
+ _Generic( \
+ (__a), \
+ vector int: (vector float)__builtin_altivec_vcfsx((vector int)(__a), \
+ ((__b)&0x1F)), \
+ vector unsigned int: (vector float)__builtin_altivec_vcfux( \
+ (vector unsigned int)(__a), ((__b)&0x1F)), \
+ vector unsigned long long: ( \
+ vector float)(__builtin_convertvector( \
+ (vector unsigned long long)(__a), vector double) * \
+ (vector double)(vector unsigned long long)((0x3ffULL - \
+ ((__b)&0x1F)) \
+ << 52)), \
+ vector signed long long: ( \
+ vector float)(__builtin_convertvector( \
+ (vector signed long long)(__a), vector double) * \
+ (vector double)(vector unsigned long long)((0x3ffULL - \
+ ((__b)&0x1F)) \
+ << 52)))
#endif // __XL_COMPAT_ALTIVEC__
#else
#define vec_ctf(__a, __b) \
- _Generic((__a), vector int \
- : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)), \
- vector unsigned int \
- : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
- (__b)))
+ _Generic((__a), \
+ vector int: (vector float)__builtin_altivec_vcfsx((vector int)(__a), \
+ ((__b)&0x1F)), \
+ vector unsigned int: (vector float)__builtin_altivec_vcfux( \
+ (vector unsigned int)(__a), ((__b)&0x1F)))
#endif
/* vec_ctd */
#ifdef __VSX__
#define vec_ctd(__a, __b) \
- _Generic((__a), vector signed int \
- : (vec_doublee((vector signed int)(__a)) * \
- (vector double)(vector unsigned long long)((0x3ffULL - (__b)) \
- << 52)), \
- vector unsigned int \
- : (vec_doublee((vector unsigned int)(__a)) * \
- (vector double)(vector unsigned long long)((0x3ffULL - (__b)) \
- << 52)), \
- vector unsigned long long \
- : (__builtin_convertvector((vector unsigned long long)(__a), \
- vector double) * \
- (vector double)(vector unsigned long long)((0x3ffULL - (__b)) \
- << 52)), \
- vector signed long long \
- : (__builtin_convertvector((vector signed long long)(__a), \
- vector double) * \
- (vector double)(vector unsigned long long)((0x3ffULL - (__b)) \
- << 52)))
+ _Generic((__a), \
+ vector signed int: ( \
+ vec_doublee((vector signed int)(__a)) * \
+ (vector double)(vector unsigned long long)((0x3ffULL - \
+ ((__b)&0x1F)) \
+ << 52)), \
+ vector unsigned int: ( \
+ vec_doublee((vector unsigned int)(__a)) * \
+ (vector double)(vector unsigned long long)((0x3ffULL - \
+ ((__b)&0x1F)) \
+ << 52)), \
+ vector unsigned long long: ( \
+ __builtin_convertvector((vector unsigned long long)(__a), \
+ vector double) * \
+ (vector double)(vector unsigned long long)((0x3ffULL - \
+ ((__b)&0x1F)) \
+ << 52)), \
+ vector signed long long: ( \
+ __builtin_convertvector((vector signed long long)(__a), \
+ vector double) * \
+ (vector double)(vector unsigned long long)((0x3ffULL - \
+ ((__b)&0x1F)) \
+ << 52)))
#endif // __VSX__
/* vec_vcfsx */
@@ -3281,27 +3289,27 @@ static __inline__ vector double __ATTRS_o_ai vec_cpsgn(vector double __a,
#ifdef __VSX__
#ifdef __XL_COMPAT_ALTIVEC__
#define vec_cts(__a, __b) \
- _Generic((__a), vector float \
- : (vector signed int)__builtin_altivec_vctsxs((vector float)(__a), \
- (__b)), \
- vector double \
- : __extension__({ \
+ _Generic((__a), \
+ vector float: (vector signed int)__builtin_altivec_vctsxs( \
+ (vector float)(__a), ((__b)&0x1F)), \
+ vector double: __extension__({ \
vector double __ret = \
(vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + (__b)) \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
<< 52); \
(vector signed long long)__builtin_vsx_xvcvdpsxws(__ret); \
}))
#else // __XL_COMPAT_ALTIVEC__
#define vec_cts(__a, __b) \
- _Generic((__a), vector float \
- : (vector signed int)__builtin_altivec_vctsxs((vector float)(__a), \
- (__b)), \
- vector double \
- : __extension__({ \
+ _Generic((__a), \
+ vector float: (vector signed int)__builtin_altivec_vctsxs( \
+ (vector float)(__a), ((__b)&0x1F)), \
+ vector double: __extension__({ \
vector double __ret = \
(vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + (__b)) \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
<< 52); \
(vector signed long long)__builtin_convertvector( \
__ret, vector signed long long); \
@@ -3320,27 +3328,27 @@ static __inline__ vector double __ATTRS_o_ai vec_cpsgn(vector double __a,
#ifdef __VSX__
#ifdef __XL_COMPAT_ALTIVEC__
#define vec_ctu(__a, __b) \
- _Generic((__a), vector float \
- : (vector unsigned int)__builtin_altivec_vctuxs( \
- (vector float)(__a), (__b)), \
- vector double \
- : __extension__({ \
+ _Generic((__a), \
+ vector float: (vector unsigned int)__builtin_altivec_vctuxs( \
+ (vector float)(__a), ((__b)&0x1F)), \
+ vector double: __extension__({ \
vector double __ret = \
(vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + __b) \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
<< 52); \
(vector unsigned long long)__builtin_vsx_xvcvdpuxws(__ret); \
}))
#else // __XL_COMPAT_ALTIVEC__
#define vec_ctu(__a, __b) \
- _Generic((__a), vector float \
- : (vector unsigned int)__builtin_altivec_vctuxs( \
- (vector float)(__a), (__b)), \
- vector double \
- : __extension__({ \
+ _Generic((__a), \
+ vector float: (vector unsigned int)__builtin_altivec_vctuxs( \
+ (vector float)(__a), ((__b)&0x1F)), \
+ vector double: __extension__({ \
vector double __ret = \
(vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + __b) \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
<< 52); \
(vector unsigned long long)__builtin_convertvector( \
__ret, vector unsigned long long); \
@@ -3355,60 +3363,62 @@ static __inline__ vector double __ATTRS_o_ai vec_cpsgn(vector double __a,
#ifdef __VSX__
#define vec_ctsl(__a, __b) \
- _Generic((__a), vector float \
- : __extension__({ \
- vector float __ret = \
- (vector float)(__a) * \
- (vector float)(vector unsigned)((0x7f + (__b)) << 23); \
- __builtin_vsx_xvcvspsxds( \
- __builtin_vsx_xxsldwi(__ret, __ret, 1)); \
- }), \
- vector double \
- : __extension__({ \
- vector double __ret = \
- (vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + __b) \
- << 52); \
- __builtin_convertvector(__ret, vector signed long long); \
- }))
+ _Generic( \
+ (__a), vector float \
+ : __extension__({ \
+ vector float __ret = \
+ (vector float)(__a) * \
+ (vector float)(vector unsigned)((0x7f + ((__b)&0x1F)) << 23); \
+ __builtin_vsx_xvcvspsxds(__builtin_vsx_xxsldwi(__ret, __ret, 1)); \
+ }), \
+ vector double \
+ : __extension__({ \
+ vector double __ret = \
+ (vector double)(__a) * \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
+ << 52); \
+ __builtin_convertvector(__ret, vector signed long long); \
+ }))
/* vec_ctul */
#define vec_ctul(__a, __b) \
- _Generic((__a), vector float \
- : __extension__({ \
- vector float __ret = \
- (vector float)(__a) * \
- (vector float)(vector unsigned)((0x7f + (__b)) << 23); \
- __builtin_vsx_xvcvspuxds( \
- __builtin_vsx_xxsldwi(__ret, __ret, 1)); \
- }), \
- vector double \
- : __extension__({ \
- vector double __ret = \
- (vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + __b) \
- << 52); \
- __builtin_convertvector(__ret, vector unsigned long long); \
- }))
+ _Generic( \
+ (__a), vector float \
+ : __extension__({ \
+ vector float __ret = \
+ (vector float)(__a) * \
+ (vector float)(vector unsigned)((0x7f + ((__b)&0x1F)) << 23); \
+ __builtin_vsx_xvcvspuxds(__builtin_vsx_xxsldwi(__ret, __ret, 1)); \
+ }), \
+ vector double \
+ : __extension__({ \
+ vector double __ret = \
+ (vector double)(__a) * \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
+ << 52); \
+ __builtin_convertvector(__ret, vector unsigned long long); \
+ }))
#endif
#else // __LITTLE_ENDIAN__
/* vec_ctsl */
#ifdef __VSX__
#define vec_ctsl(__a, __b) \
- _Generic((__a), vector float \
- : __extension__({ \
- vector float __ret = \
- (vector float)(__a) * \
- (vector float)(vector unsigned)((0x7f + (__b)) << 23); \
- __builtin_vsx_xvcvspsxds(__ret); \
- }), \
- vector double \
- : __extension__({ \
+ _Generic((__a), \
+ vector float: __extension__({ \
+ vector float __ret = \
+ (vector float)(__a) * \
+ (vector float)(vector unsigned)((0x7f + ((__b)&0x1F)) << 23); \
+ __builtin_vsx_xvcvspsxds(__ret); \
+ }), \
+ vector double: __extension__({ \
vector double __ret = \
(vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + __b) \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
<< 52); \
__builtin_convertvector(__ret, vector signed long long); \
}))
@@ -3420,14 +3430,16 @@ static __inline__ vector double __ATTRS_o_ai vec_cpsgn(vector double __a,
: __extension__({ \
vector float __ret = \
(vector float)(__a) * \
- (vector float)(vector unsigned)((0x7f + (__b)) << 23); \
+ (vector float)(vector unsigned)((0x7f + ((__b)&0x1F)) \
+ << 23); \
__builtin_vsx_xvcvspuxds(__ret); \
}), \
vector double \
: __extension__({ \
vector double __ret = \
(vector double)(__a) * \
- (vector double)(vector unsigned long long)((0x3ffULL + __b) \
+ (vector double)(vector unsigned long long)((0x3ffULL + \
+ ((__b)&0x1F)) \
<< 52); \
__builtin_convertvector(__ret, vector unsigned long long); \
}))