Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
3bc815a5
There was an error fetching the commit references. Please try again later.
Commit
3bc815a5
authored
6 years ago
by
Fernando Sahmkow
Committed by
FernandoS27
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement intrinsics CountTrailingZeroes and test it.
parent
522957f9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common/bit_util.h
+33
-12
33 additions, 12 deletions
src/common/bit_util.h
src/tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
src/tests/CMakeLists.txt
src/tests/common/bit_utils.cpp
+42
-0
42 additions, 0 deletions
src/tests/common/bit_utils.cpp
with
76 additions
and
12 deletions
src/common/bit_util.h
+
33
−
12
View file @
3bc815a5
...
...
@@ -59,22 +59,43 @@ inline u64 CountLeadingZeroes64(u64 value) {
}
#endif
#ifdef _MSC_VER
inline
u32
CountTrailingZeroes32
(
u32
value
)
{
u32
count
=
0
;
while
(((
value
>>
count
)
&
0xf
)
==
0
&&
count
<
32
)
count
+=
4
;
while
(((
value
>>
count
)
&
1
)
==
0
&&
count
<
32
)
count
++
;
return
count
;
unsigned
long
trailing_zero
=
0
;
if
(
_BitScanForward
(
&
trailing_zero
,
value
)
!=
0
)
{
return
trailing_zero
;
}
return
32
;
}
inline
u64
CountTrailingZeroes64
(
u64
value
)
{
u64
count
=
0
;
while
(((
value
>>
count
)
&
0xf
)
==
0
&&
count
<
64
)
count
+=
4
;
while
(((
value
>>
count
)
&
1
)
==
0
&&
count
<
64
)
count
++
;
return
count
;
unsigned
long
trailing_zero
=
0
;
if
(
_BitScanForward64
(
&
trailing_zero
,
value
)
!=
0
)
{
return
trailing_zero
;
}
return
64
;
}
#else
inline
u32
CountTrailingZeroes32
(
u32
value
)
{
if
(
value
==
0
)
{
return
32
;
}
return
__builtin_ctz
(
value
);
}
inline
u64
CountTrailingZeroes64
(
u64
value
)
{
if
(
value
==
0
)
{
return
64
;
}
return
__builtin_ctzll
(
value
);
}
#endif
}
// namespace Common
This diff is collapsed.
Click to expand it.
src/tests/CMakeLists.txt
+
1
−
0
View file @
3bc815a5
add_executable
(
tests
common/bit_field.cpp
common/bit_utils.cpp
common/param_package.cpp
common/ring_buffer.cpp
core/arm/arm_test_common.cpp
...
...
This diff is collapsed.
Click to expand it.
src/tests/common/bit_utils.cpp
0 → 100644
+
42
−
0
View file @
3bc815a5
// Copyright 2017 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include
<catch2/catch.hpp>
#include
<math.h>
#include
"common/bit_util.h"
namespace
Common
{
inline
u32
CTZ32
(
u32
value
)
{
u32
count
=
0
;
while
(((
value
>>
count
)
&
0xf
)
==
0
&&
count
<
32
)
count
+=
4
;
while
(((
value
>>
count
)
&
1
)
==
0
&&
count
<
32
)
count
++
;
return
count
;
}
inline
u64
CTZ64
(
u64
value
)
{
u64
count
=
0
;
while
(((
value
>>
count
)
&
0xf
)
==
0
&&
count
<
64
)
count
+=
4
;
while
(((
value
>>
count
)
&
1
)
==
0
&&
count
<
64
)
count
++
;
return
count
;
}
TEST_CASE
(
"BitUtils"
,
"[common]"
)
{
REQUIRE
(
Common
::
CountTrailingZeroes32
(
0
)
==
CTZ32
(
0
));
REQUIRE
(
Common
::
CountTrailingZeroes64
(
0
)
==
CTZ64
(
0
));
REQUIRE
(
Common
::
CountTrailingZeroes32
(
9
)
==
CTZ32
(
9
));
REQUIRE
(
Common
::
CountTrailingZeroes32
(
8
)
==
CTZ32
(
8
));
REQUIRE
(
Common
::
CountTrailingZeroes32
(
0x801000
)
==
CTZ32
(
0x801000
));
REQUIRE
(
Common
::
CountTrailingZeroes64
(
9
)
==
CTZ64
(
9
));
REQUIRE
(
Common
::
CountTrailingZeroes64
(
8
)
==
CTZ64
(
8
));
REQUIRE
(
Common
::
CountTrailingZeroes64
(
0x801000
)
==
CTZ64
(
0x801000
));
REQUIRE
(
Common
::
CountTrailingZeroes64
(
0x801000000000UL
)
==
CTZ64
(
0x801000000000UL
));
}
}
// namespace Common
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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