-
Notifications
You must be signed in to change notification settings - Fork 38
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
Optimize fabs, fneg, fcopysign #560
Conversation
Also please squash the commits into a single one. |
Codecov Report
@@ Coverage Diff @@
## master #560 +/- ##
=======================================
Coverage 98.23% 98.24%
=======================================
Files 62 62
Lines 9023 9039 +16
=======================================
+ Hits 8864 8880 +16
Misses 159 159 |
94c147f
to
f545ae7
Compare
bae0f48
to
b6d21fd
Compare
lib/fizzy/execute.cpp
Outdated
@@ -356,6 +362,62 @@ T fnearest(T value) noexcept | |||
return t; | |||
} | |||
|
|||
|
|||
template <typename T> | |||
T fabs(T) noexcept = delete; |
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.
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 was actually going to suggest to keep the f
prefix and also use fneg
, given these functions are specifically working on floating points. Since there's no abs
on integers in Wasm, it doesn't come up as an issue. Should there be one in the future, happy to rename it to abs
.
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.
Same for fcopysign
then?
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.
https://en.cppreference.com/w/cpp/numeric/math/copysign seems to be floating point only, so fine to keep it as copysign
, but okay either way.
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.
Keeping fcopysign
then.
0ccb8fb
to
9db9af5
Compare
b2d1126
to
25c9dba
Compare
@@ -19,6 +20,11 @@ namespace | |||
// code_offset + imm_offset + stack_height | |||
constexpr auto BranchImmediateSize = 3 * sizeof(uint32_t); | |||
|
|||
constexpr uint32_t F32AbsMask = 0x7fffffff; |
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.
Could go crazy and use std::numeric_limits<uint32_t>::max() >> 1
, but the constant is nicer.
Use unsigned integers and bit manipulations to implement three floating-point operators: fabs, fneg, and fcopysign. This is slightly better than using compiler's builtins because compiler is able to inline them earlier and avoid using SSE registers required by calling convention. Co-authored-by: Paweł Bylica <[email protected]>
25c9dba
to
21d65e9
Compare
Closes #540.
I created optimized first single case of issue #540 to be sure that i understood a problem.