[PATCH] D13414: Define GNU clz builtins equivalents for MSVC
angelsl via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 3 10:55:16 PDT 2015
angelsl updated this revision to Diff 36444.
angelsl added a comment.
Put the functions in int_lib.h instead, since some of the functions defined only include that
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
@@ -78,4 +78,40 @@
COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
#endif
+/* Definitions for builtins unavailable on MSVC */
+#ifdef _MSC_VER
+#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;
+ }
+}
+
+uint32_t __inline __builtin_clzl(uint64_t value) {
+ return __builtin_clzll(value);
+}
+#endif
+
#endif /* INT_LIB_H */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13414.36444.patch
Type: text/x-patch
Size: 1113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151003/81225cb2/attachment.bin>
More information about the llvm-commits
mailing list