From 5208938e838bb9013760a02dda788e701eb155a6 Mon Sep 17 00:00:00 2001 From: Noah Czaplewski Date: Thu, 12 Dec 2024 09:21:50 +0100 Subject: [PATCH 1/3] Fixed platform macro for arm64 --- faiss/impl/platform_macros.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/faiss/impl/platform_macros.h b/faiss/impl/platform_macros.h index 3e9716b06f..3f65cf153a 100644 --- a/faiss/impl/platform_macros.h +++ b/faiss/impl/platform_macros.h @@ -59,8 +59,12 @@ inline int __builtin_ctz(unsigned long x) { #ifndef __clang__ inline int __builtin_clzll(uint64_t x) { - return (int)__lzcnt64(x); -} + #if defined(_M_X64) || defined(__x86_64__) + return (int)__lzcnt64(x); + #elif defined(_M_ARM64) + return (x == 0) ? 64 : __builtin_clzll(x); + #endif + } #endif #define __builtin_popcount __popcnt From ceb4ce038c8ea8bc14ff84c8b6d21658bed93747 Mon Sep 17 00:00:00 2001 From: Noah Czaplewski Date: Fri, 13 Dec 2024 09:02:14 +0100 Subject: [PATCH 2/3] Windows arm64 __builtin_clzll fix --- faiss/impl/platform_macros.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/faiss/impl/platform_macros.h b/faiss/impl/platform_macros.h index 3f65cf153a..928cbeaf63 100644 --- a/faiss/impl/platform_macros.h +++ b/faiss/impl/platform_macros.h @@ -39,6 +39,7 @@ // redefine the GCC intrinsics with Windows equivalents #include +#include #ifndef __clang__ inline int __builtin_ctzll(uint64_t x) { @@ -62,7 +63,12 @@ inline int __builtin_clzll(uint64_t x) { #if defined(_M_X64) || defined(__x86_64__) return (int)__lzcnt64(x); #elif defined(_M_ARM64) - return (x == 0) ? 64 : __builtin_clzll(x); + unsigned long index; + int count = sizeof(uint64_t) * CHAR_BIT; + if (_BitScanReverse64(&index, x)) { + count = count - 1 - index; + } + return count; #endif } #endif From ddf2a5bbffeb853fb38b2a113d2b3b098f60a8e7 Mon Sep 17 00:00:00 2001 From: Noah Czaplewski Date: Tue, 17 Dec 2024 07:59:14 +0100 Subject: [PATCH 3/3] Format fix --- faiss/impl/platform_macros.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/faiss/impl/platform_macros.h b/faiss/impl/platform_macros.h index 928cbeaf63..8d069995b3 100644 --- a/faiss/impl/platform_macros.h +++ b/faiss/impl/platform_macros.h @@ -60,17 +60,17 @@ inline int __builtin_ctz(unsigned long x) { #ifndef __clang__ inline int __builtin_clzll(uint64_t x) { - #if defined(_M_X64) || defined(__x86_64__) - return (int)__lzcnt64(x); - #elif defined(_M_ARM64) - unsigned long index; - int count = sizeof(uint64_t) * CHAR_BIT; - if (_BitScanReverse64(&index, x)) { - count = count - 1 - index; - } - return count; - #endif +#if defined(_M_X64) || defined(__x86_64__) + return (int)__lzcnt64(x); +#elif defined(_M_ARM64) + unsigned long index; + int count = sizeof(uint64_t) * CHAR_BIT; + if (_BitScanReverse64(&index, x)) { + count = count - 1 - index; } + return count; +#endif +} #endif #define __builtin_popcount __popcnt