Skip to content

Commit

Permalink
[PowerPC] Fix byte ordering of ld/st with length on BE
Browse files Browse the repository at this point in the history
The builtins vec_xl_len_r and vec_xst_len_r actually use the
wrong side of the vector on big endian Power9 systems. We never
spotted this before because there was no such thing as a big
endian distro that supported Power9. Now we have AIX and the
elements are in the wrong part of the vector. This just fixes
it so the elements are loaded to and stored from the right
side of the vector.
  • Loading branch information
nemanjai committed Jul 30, 2021
1 parent 460d220 commit 9019b55
Show file tree
Hide file tree
Showing 3 changed files with 408 additions and 122 deletions.
9 changes: 1 addition & 8 deletions clang/lib/Headers/altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -3049,13 +3049,10 @@ static __inline__ vector unsigned char __ATTRS_o_ai
vec_xl_len_r(const unsigned char *__a, size_t __b) {
vector unsigned char __res =
(vector unsigned char)__builtin_vsx_lxvll(__a, (__b << 56));
#ifdef __LITTLE_ENDIAN__
vector unsigned char __mask =
(vector unsigned char)__builtin_altivec_lvsr(16 - __b, (int *)NULL);
__res = (vector unsigned char)__builtin_altivec_vperm_4si(
return (vector unsigned char)__builtin_altivec_vperm_4si(
(vector int)__res, (vector int)__res, __mask);
#endif
return __res;
}

// vec_xst_len
Expand Down Expand Up @@ -3130,15 +3127,11 @@ static __inline__ void __ATTRS_o_ai vec_xst_len(vector double __a, double *__b,
static __inline__ void __ATTRS_o_ai vec_xst_len_r(vector unsigned char __a,
unsigned char *__b,
size_t __c) {
#ifdef __LITTLE_ENDIAN__
vector unsigned char __mask =
(vector unsigned char)__builtin_altivec_lvsl(16 - __c, (int *)NULL);
vector unsigned char __res =
__builtin_altivec_vperm_4si((vector int)__a, (vector int)__a, __mask);
return __builtin_vsx_stxvll((vector int)__res, __b, (__c << 56));
#else
return __builtin_vsx_stxvll((vector int)__a, __b, (__c << 56));
#endif
}
#endif
#endif
Expand Down
Loading

0 comments on commit 9019b55

Please sign in to comment.