blob: defb3e5120eaf1d7ffdceffd93cc8e6d9b5e6031 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
//============================================================
//
// eivc.h
//
// Inline implementations for MSVC compiler.
//
//============================================================
#ifndef __EIVC__
#define __EIVC__
#include <intrin.h>
#pragma intrinsic(_BitScanReverse)
/***************************************************************************
INLINE BIT MANIPULATION FUNCTIONS
***************************************************************************/
/*-------------------------------------------------
count_leading_zeros - return the number of
leading zero bits in a 32-bit value
-------------------------------------------------*/
#ifndef count_leading_zeros
#define count_leading_zeros _count_leading_zeros
static inline uint8_t _count_leading_zeros(uint32_t value)
{
uint32_t index;
return _BitScanReverse((unsigned long *)&index, value) ? (index ^ 31) : 32;
}
#endif
/*-------------------------------------------------
count_leading_ones - return the number of
leading one bits in a 32-bit value
-------------------------------------------------*/
#ifndef count_leading_ones
#define count_leading_ones _count_leading_ones
static inline uint8_t _count_leading_ones(uint32_t value)
{
uint32_t index;
return _BitScanReverse((unsigned long *)&index, ~value) ? (index ^ 31) : 32;
}
#endif
#endif /* __EIVC__ */
|