Skip to content

Commit 9d424e0

Browse files
authored
win: __builtin_ctz* for MSVC (#4953)
fix MSVC compilation support `__builtin_ctz`, `__builtin_ctzll` based on https://gist.github.com/pps83/3210a2f980fd02bb2ba2e5a1fc4a2ef0
1 parent b6c4829 commit 9d424e0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/Tools/LinearLayout.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
1717
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
1818

19+
#if defined(_MSC_VER) && !defined(__clang__)
20+
// from https://gist.github.com/pps83/3210a2f980fd02bb2ba2e5a1fc4a2ef0
21+
#include <intrin.h>
22+
23+
static int __builtin_ctz(unsigned x) {
24+
unsigned long r;
25+
_BitScanForward(&r, x);
26+
return static_cast<int>(r);
27+
}
28+
29+
static int __builtin_ctzll(unsigned long long x) {
30+
unsigned long r;
31+
_BitScanForward64(&r, x);
32+
return static_cast<int>(r);
33+
}
34+
35+
#endif
36+
1937
namespace mlir::triton {
2038

2139
namespace {

0 commit comments

Comments
 (0)