Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corpus2
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
corpus2
Commits
22f15f15
Commit
22f15f15
authored
14 years ago
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
Adding non-GCC specific alternative for lowest_bit, and as well adding a MSVC-specific one
parent
79c2cd63
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libpwrutils/bitset.h
+45
-7
45 additions, 7 deletions
libpwrutils/bitset.h
with
45 additions
and
7 deletions
libpwrutils/bitset.h
+
45
−
7
View file @
22f15f15
...
...
@@ -8,6 +8,10 @@
#include
<boost/pending/lowest_bit.hpp>
#include
<climits>
#ifdef _MSC_VER
#include
<intrin.h>
#pragma intrinsic(_BitScanForward)
#endif
namespace
PwrNlp
{
...
...
@@ -37,13 +41,6 @@ size_t count_bits_set(const std::bitset<S>& b)
return
b
.
count
();
}
template
<
size_t
S
>
inline
size_t
lowest_bit
(
const
bitset
<
S
>&
b
)
{
// GCC specific
return
b
.
_Find_first
();
}
/**
* Get index of lowest set bit in an integral type
*/
...
...
@@ -55,8 +52,49 @@ inline size_t lowest_bit(const unsigned long long& t)
inline
size_t
lowest_bit
(
const
unsigned
long
&
t
)
{
#ifndef _MSC_VER
if
(
t
<=
0
)
return
static_cast
<
size_t
>
(
-
1
);
return
boost
::
lowest_bit
(
t
);
#else
unsigned
long
index
=
0
;
if
(
_BitScanForward
(
&
index
,
t
))
return
index
;
return
static_cast
<
size_t
>
(
-
1
);
#endif
}
template
<
size_t
S
>
inline
size_t
lowest_bit
(
const
bitset
<
S
>&
b
)
{
#ifdef __GNUC__
return
b
.
_Find_first
();
#elif _MSC_VER
for
(
size_t
w
=
0
;
w
<=
S
/
ulong_bits
;
++
w
)
{
unsigned
long
index
=
0
;
if
(
_BitScanForward
(
&
index
,
b
.
_Getword
(
w
)))
{
return
index
+
w
*
PwrNlp
::
ulong_bits
;
}
}
return
static_cast
<
size_t
>
(
-
1
);
#else
if
(
b
.
none
())
return
static_cast
<
size_t
>
(
-
1
);
const
bitset
<
S
>
mask
(
std
::
numeric_limits
<
unsigned
long
>::
max
());
bitset
<
S
>
c
(
b
);
unsigned
long
offset
=
0
;
unsigned
long
ul
=
(
c
&
mask
).
to_ulong
();
while
(
ul
==
0
)
{
c
>>=
PwrNlp
::
ulong_bits
;
offset
+=
PwrNlp
::
ulong_bits
;
ul
=
(
c
&
mask
).
to_ulong
();
}
return
lowest_bit
(
ul
)
+
offset
;
#endif
}
template
<
>
inline
size_t
lowest_bit
(
const
word_bitset
&
b
)
{
return
lowest_bit
(
b
.
to_ulong
());
}
/// Helper iterator class for iterating through set bits
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment