[PATCH] D13414: Define GNU clz builtins equivalents for MSVC
angelsl via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 23:50:39 PDT 2015
angelsl updated this revision to Diff 36485.
angelsl added a comment.
Corrections made.
http://reviews.llvm.org/D13414
Files:
lib/builtins/int_lib.h
Index: lib/builtins/int_lib.h
===================================================================
--- lib/builtins/int_lib.h
+++ lib/builtins/int_lib.h
@@ -88,4 +88,38 @@
COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
#endif
+/* Definitions for builtins unavailable on MSVC */
+#if defined(_MSC_VER) && !defined(__clang__)
+#include <intrin.h>
+
+uint32_t __inline __builtin_ctz(uint32_t value) {
+ uint32_t trailing_zero = 0;
+ if (_BitScanForward(&trailing_zero, value)) {
+ return trailing_zero;
+ } else {
+ return 32;
+ }
+}
+
+uint32_t __inline __builtin_clz(uint32_t value) {
+ uint32_t leading_zero = 0;
+ if (_BitScanReverse(&leading_zero, value)) {
+ return 31 - leading_zero;
+ } else {
+ return 32;
+ }
+}
+
+uint32_t __inline __builtin_clzll(uint64_t value) {
+ uint32_t leading_zero = 0;
+ if (_BitScanReverse64(&leading_zero, value)) {
+ return 63 - leading_zero;
+ } else {
+ return 64;
+ }
+}
+
+#define __builtin_clzl __builtin_clzll
+#endif
+
#endif /* INT_LIB_H */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13414.36485.patch
Type: text/x-patch
Size: 1091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151005/dacf6b51/attachment.bin>
More information about the llvm-commits
mailing list