modify FAISS_PRAGMA_IMPRECISE_FUNCTION_* flags to make old clang versions to generate FMAs on x64 (#2726)

Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2726

Old versions of clang (prior to 14) do not generate FMAs on x86 unless this option is used. On the other hand, ARM does not support the needed pragma flag.

Reviewed By: DenisYaroshevskiy

Differential Revision: D43503265

fbshipit-source-id: a024dd221288e44d4e2ade2f5db2c4402e26ff3d
pull/2684/head
Alexandr Guzhva 2023-02-22 12:19:32 -08:00 committed by Facebook GitHub Bot
parent 8ef0985c11
commit 521e271cb8
1 changed files with 12 additions and 0 deletions

View File

@ -117,8 +117,20 @@ inline int __builtin_clzll(uint64_t x) {
#elif defined(__clang__)
#define FAISS_PRAGMA_IMPRECISE_LOOP \
_Pragma("clang loop vectorize(enable) interleave(enable)")
// the following ifdef is needed, because old versions of clang (prior to 14)
// do not generate FMAs on x86 unless this pragma is used. On the other hand,
// ARM does not support the following pragma flag.
// TODO: find out how to enable FMAs on clang 10 and earlier.
#if defined(__x86_64__) && (defined(__clang_major__) && (__clang_major__ > 10))
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN \
_Pragma("float_control(precise, off, push)")
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_END _Pragma("float_control(pop)")
#else
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_END
#endif
#else
#define FAISS_PRAGMA_IMPRECISE_LOOP
#define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN