From 1dde678757216b019fff7ac3b6226ab997b86a8b Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 22 Mar 2024 01:43:53 +0600 Subject: refactor(misc): use MSVC compiler builtin for `xctz()` Problem: `xctz()` uses a fallback algorithm for MSVC, even though a compiler builtin exists. Solution: Make `xctz()` use the compiler builtin for MSVC compiler. --- src/nvim/math.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/nvim/math.c b/src/nvim/math.c index 9a0825823c..39d166bb53 100644 --- a/src/nvim/math.c +++ b/src/nvim/math.c @@ -4,6 +4,10 @@ #include #include +#ifdef _MSC_VER +# include // Required for _BitScanForward64 +#endif + #include "nvim/math.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -52,6 +56,10 @@ int xctz(uint64_t x) // Use compiler builtin if possible. #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 4)) return __builtin_ctzll(x); +#elif defined(_MSC_VER) + unsigned long index; + _BitScanForward64(&index, x); + return (int)index; #else int count = 0; // Set x's trailing zeroes to ones and zero the rest. -- cgit