Skip to content

Commit 1dde678

Browse files
committed
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.
1 parent 563a369 commit 1dde678

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/nvim/math.c

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <stdint.h>
55
#include <string.h>
66

7+
#ifdef _MSC_VER
8+
# include <intrin.h> // Required for _BitScanForward64
9+
#endif
10+
711
#include "nvim/math.h"
812

913
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -52,6 +56,10 @@ int xctz(uint64_t x)
5256
// Use compiler builtin if possible.
5357
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 4))
5458
return __builtin_ctzll(x);
59+
#elif defined(_MSC_VER)
60+
unsigned long index;
61+
_BitScanForward64(&index, x);
62+
return (int)index;
5563
#else
5664
int count = 0;
5765
// Set x's trailing zeroes to ones and zero the rest.

0 commit comments

Comments
 (0)