Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly fix altivec namespace collisions #672

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3350,23 +3350,33 @@ XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(void const* ptr)
* inconsistent intrinsics, spotty coverage, and multiple endiannesses.
*/
#if XXH_VECTOR == XXH_VSX
/* Annoyingly, these headers _may_ define three macros: `bool`, `vector`,
* and `pixel`. This is a problem for obvious reasons.
*
* These keywords are unnecessary; the spec literally says they are
* equivalent to `__bool`, `__vector`, and `__pixel` and may be undef'd
* after including the header.
*
* We use pragma push_macro/pop_macro to keep the namespace clean. */
# pragma push_macro("bool")
# pragma push_macro("vector")
# pragma push_macro("pixel")
/* silence potential macro redefined warnings */
# undef bool
# undef vector
# undef pixel

# if defined(__s390x__)
# include <s390intrin.h>
# else
/* gcc's altivec.h can have the unwanted consequence to unconditionally
* #define bool, vector, and pixel keywords,
* with bad consequences for programs already using these keywords for other purposes.
* The paragraph defining these macros is skipped when __APPLE_ALTIVEC__ is defined.
* __APPLE_ALTIVEC__ is _generally_ defined automatically by the compiler,
* but it seems that, in some cases, it isn't.
* Force the build macro to be defined, so that keywords are not altered.
*/
# if defined(__GNUC__) && !defined(__APPLE_ALTIVEC__)
# define __APPLE_ALTIVEC__
# endif
# include <altivec.h>
# endif

/* Restore the original macro values, if applicable. */
# pragma pop_macro("pixel")
# pragma pop_macro("vector")
# pragma pop_macro("bool")

typedef __vector unsigned long long xxh_u64x2;
typedef __vector unsigned char xxh_u8x16;
typedef __vector unsigned xxh_u32x4;
Expand Down