Skip to content

Commit

Permalink
Fix clang's behavior on versions >= 7
Browse files Browse the repository at this point in the history
Clang 7 changed the behavior of vec_xxpermdi in order to match GCC's
behavior.  After this change, code that used to work on Clang 6 stopped
to work on Clang >= 7.

Tested on Clang 6, 7, 8 and 9.

Reference: https://bugs.llvm.org/show_bug.cgi?id=38192

Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
  • Loading branch information
tuliom authored and mscastanho committed Apr 6, 2022
1 parent 3e4af8f commit 58ad234
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions contrib/power/clang_workaround.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ __vector unsigned long long __builtin_pack_vector (unsigned long __a,
return __v;
}

#ifndef vec_xxpermdi
/*
* Clang 7 changed the behavior of vec_xxpermdi in order to provide the same
* behavior of GCC. That means code adapted to Clang >= 7 does not work on
* Clang <= 6. So, fallback to __builtin_unpack_vector() on Clang <= 6.
*/
#if !defined vec_xxpermdi || __clang_major__ <= 6

static inline
unsigned long __builtin_unpack_vector (__vector unsigned long long __v,
Expand All @@ -62,19 +67,19 @@ static inline
unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v)
{
#if defined(__BIG_ENDIAN__)
return vec_xxpermdi(__v, __v, 0x0)[1];
#else
return vec_xxpermdi(__v, __v, 0x0)[0];
#else
return vec_xxpermdi(__v, __v, 0x3)[0];
#endif
}

static inline
unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v)
{
#if defined(__BIG_ENDIAN__)
return vec_xxpermdi(__v, __v, 0x3)[1];
#else
return vec_xxpermdi(__v, __v, 0x3)[0];
#else
return vec_xxpermdi(__v, __v, 0x0)[0];
#endif
}
#endif /* vec_xxpermdi */
Expand Down

0 comments on commit 58ad234

Please sign in to comment.