Skip to content

Commit 2289ecd

Browse files
authored
Merge pull request neovim#27969 from famiu/refactor/misc/xctz
refactor(misc): use MSVC compiler builtin for `xctz()`
2 parents 563a369 + 1dde678 commit 2289ecd

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)