-
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
Change implementation of fnearest() #504
Conversation
lib/fizzy/execute.cpp
Outdated
|
||
return result; | ||
const auto t = std::trunc(value); | ||
if (const auto diff = std::abs(value - t); diff > 0.5f || (diff == 0.5f && !is_even(t))) |
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.
Wouldn't it be less branching to have two if cases than using abs? Or is abs constexpr and the compiler can optimise all this out?
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.
The abs
(or fabs
in C) is recognized and replaced with __builtin_abs
or something. This just masks out the sign bit: x & 0x7fffffff
.
Codecov Report
@@ Coverage Diff @@
## master #504 +/- ##
==========================================
- Coverage 99.69% 99.69% -0.01%
==========================================
Files 54 54
Lines 17198 17180 -18
==========================================
- Hits 17146 17128 -18
Misses 52 52 |
I also have another implementation based on bit manipulation which looks to be faster but I did not perform proper benchmarks yet. We may wait with that for the next release until having more FP test cases. |
05b277f
to
2f9edfe
Compare
2f9edfe
to
db4421c
Compare
I'm checking some additional options because there are some performance regressions. |
This implementation does not need to modify rounding direction to work correctly under any rounding direction.
4e072bd
to
c413a4c
Compare
GCC:
GCC+LTO:
So not really significant difference (none of the benchmarks uses this instruction). The change is not driven by performance anyway. When marking the function with |
c413a4c
to
4e42e95
Compare
This implementation does not need to modify rounding direction to work
correctly under any rounding direction.