Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Lhomme <robux4@ycbcr.xyz>2018-09-27 14:55:39 +0300
committerSteve Lhomme <robux4@ycbcr.xyz>2018-09-28 13:10:45 +0300
commite2d329fbeb0084432041782902a82f9cea884cbe (patch)
tree957507644df0eb536ccce9e599d27e3fe90e5cee /include
parentd262a6ae9a36aea61daf5af03f246287a30c45dd (diff)
define builtin clz/ctz calls MSVC equivalents
__builtin_ctz: Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined. _BitScanForward: Search the mask data from least significant bit (LSB) to the most significant bit (MSB) for a set bit (1). If a set bit is found, the bit position of the first set bit found is returned in the first parameter. If no set bit is found, 0 is returned; otherwise, 1 is returned. __builtin_clz: Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined. _BitScanReverse: Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1). Returns Nonzero if Index was set, or 0 if no set bits were found. Index is loaded with the bit position of the first set bit (1) found.
Diffstat (limited to 'include')
-rw-r--r--include/common/attributes.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/common/attributes.h b/include/common/attributes.h
index f3b0d47..a5347d2 100644
--- a/include/common/attributes.h
+++ b/include/common/attributes.h
@@ -51,6 +51,27 @@
#define ALIGN_STK_16(type, var, sz1d, sznd) \
ALIGN(type var[sz1d]sznd, 16)
+ #ifdef _MSC_VER
+ #include <intrin.h>
+
+static inline int ctz(const unsigned int mask) {
+ unsigned long idx;
+ _BitScanForward(&idx, mask);
+ return idx;
+}
+
+static inline int clz(const unsigned int mask) {
+ unsigned long leading_zero = 0;
+ _BitScanReverse(&leading_zero, mask);
+ return (31 - leading_zero);
+}
+
+static inline int clzll(const unsigned long long mask) {
+ unsigned long leading_zero = 0;
+ _BitScanReverse64(&leading_zero, mask);
+ return (63 - leading_zero);
+}
+#else /* !_MSC_VER */
static inline int ctz(const unsigned int mask) {
return __builtin_ctz(mask);
}
@@ -62,5 +83,6 @@ static inline int clz(const unsigned int mask) {
static inline int clzll(const unsigned long long mask) {
return __builtin_clzll(mask);
}
+#endif /* !_MSC_VER */
#endif /* __DAV1D_COMMON_ATTRIBUTES_H__ */