-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use countl_zero/countr_zero from C++20 if available #689
Conversation
Codecov Report
@@ Coverage Diff @@
## master #689 +/- ##
=======================================
Coverage 99.02% 99.02%
=======================================
Files 80 80
Lines 12788 12812 +24
=======================================
+ Hits 12663 12687 +24
Misses 125 125
Flags with carried forward coverage won't be shown. Click here to find out more.
|
lib/fizzy/execute.cpp
Outdated
@@ -254,41 +254,29 @@ inline constexpr T rotr(T lhs, T rhs) noexcept | |||
return (lhs >> k) | (lhs << (num_bits - k)); | |||
} | |||
|
|||
inline uint32_t clz32(uint32_t value) noexcept | |||
constexpr uint32_t clz32(uint32_t value) noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can replace these with a template and use them as clz<uint32_t>
below. Would cat this code duplication into half.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we dont even need this wrapper layer, the only thing it does is explicit casting of the return value.
lib/fizzy/execute.cpp
Outdated
} | ||
|
||
inline uint32_t ctz32(uint32_t value) noexcept | ||
constexpr uint32_t ctz32(uint32_t value) noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr uint32_t ctz32(uint32_t value) noexcept | |
inline constexpr uint32_t ctz32(uint32_t value) noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually just removing these wrappers seems to be okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping the wrappers means all the results are going to be converted to i32
. This is wrong for i64.c[lt]z
. This mean you now need to construct a unit test what will reproduce this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So how about the template proposed in #689 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mean you now need to construct a unit test what will reproduce this bug.
This is still missing. It requires a special test where you pollute the stack first and then assign result of i64.clz
. If the result is int
some garbage should stay in the value. One case should be enough. See TEST(execute_numeric, i64_extend_i32_u)
.
I can also handle this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks it is not easy to omit the wrapper so I will skip creating tests for this.
@@ -9,7 +9,7 @@ | |||
|
|||
namespace fizzy::test | |||
{ | |||
constexpr std::pair<uint32_t, uint32_t> popcount32_test_cases[]{ | |||
constexpr std::pair<uint32_t, int> popcount32_test_cases[]{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicating inputs does not make sense. Create a struct with results for all instructions.
template <T>
struct SomeGoodName
{
T input;
int popcount;
int countl_zero;
int countr_zero;
};
constexpr SomeGoodName<uint32_t> bit_counting32_test_cases[]{
{0, 0, 32, 32},
{0x80, 1, 24, 7},
...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep this a separate commit even for merging, as not sure it is more readable alltogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, don't forget to remove the change in CMakeLists.txt
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
Closes #543.