ReactOS
0.4.16-dev-2122-g1628f5e
twidbits.h
Go to the documentation of this file.
1
/*
2
* PROJECT: FreeLoader
3
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4
* or MIT (https://spdx.org/licenses/MIT)
5
* PURPOSE: Bit twiddling helpers
6
* COPYRIGHT: Copyright 2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
7
*
8
* Based on http://www.graphics.stanford.edu/~seander/bithacks.html
9
* and other sources.
10
*/
11
12
// HAVE___BUILTIN_POPCOUNT
13
14
#pragma once
15
20
FORCEINLINE
21
ULONG
22
CountNumberOfBits
(
23
_In_
UINT32
n
)
24
{
25
#ifdef HAVE___BUILTIN_POPCOUNT
26
return
__popcnt
(
n
);
27
#else
28
n
-= ((
n
>> 1) & 0x55555555);
29
n
= (((
n
>> 2) & 0x33333333) + (
n
& 0x33333333));
30
#if 0
31
n
= (((
n
>> 4) +
n
) & 0x0f0f0f0f);
32
n
+= (
n
>> 8);
33
n
+= (
n
>> 16);
34
return
(
n
& 0x3f);
35
#else
36
return
(((
n
>> 4) +
n
) & 0x0f0f0f0f) * 0x01010101 >> 24;
37
#endif
38
#endif
/* HAVE___BUILTIN_POPCOUNT */
39
}
UINT32
unsigned int UINT32
Definition:
ProcessorBind.h:163
n
GLdouble n
Definition:
glext.h:7729
__popcnt
__INTRIN_INLINE unsigned int __popcnt(unsigned int value)
Definition:
intrin_x86.h:1458
_In_
#define _In_
Definition:
no_sal2.h:158
CountNumberOfBits
FORCEINLINE ULONG CountNumberOfBits(_In_ UINT32 n)
Return the number of bits set in a 32-bit integer.
Definition:
twidbits.h:22
ULONG
uint32_t ULONG
Definition:
typedefs.h:59
FORCEINLINE
#define FORCEINLINE
Definition:
wdftypes.h:67
boot
freeldr
freeldr
arch
twidbits.h
Generated on Sat Jan 10 2026 06:03:06 for ReactOS by
1.9.6