-
Notifications
You must be signed in to change notification settings - Fork 98
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
Correct Quantity::new
to be zero-cost for float storage types.
#144
Conversation
My "full code" does not omit the add 0.0, but I'm unable to pinpoint why, since it's just the following benchmark tests:
with uom_ops::Trigonometric being:
I fail to see why it doesn't vanish here but vanishes in the previous example program. I did make sure I was Now a bit off-topic, would you be interested to collaborate on a crate which impl's functions similar to the above? Surely there's a better implementation for it than this, and I find these functions to be of such basic use to require users to extract a value, use the op, and convert to another value. (I actually believe it removes all value of the uom crate itself). If so, how do you wish to proceed, by opening an issue? |
I'll checkout those benchmark examples this weekend and see if I can reproduce / solve the issue. For Lines 67 to 82 in c02d306
|
I ended up being busy all weekend and will try to review this week. |
I found the issue. Lines 284 to 286 in c02d306
Lines 302 to 304 in c02d306
So far I have two thoughts about how to fix the issue. Neither are great so I welcome suggestions.
@raimundomartins I've currently gone with the second option. The updated code causes llvm to optimize the benchmarks down to a single llvm-ir function definition. If you could review the code and double check that the optimization is still happening that would be greatly appreciated. |
I had thought of that, but some quick tests didn't point to the opposite operation to not being optimized, so I thought that Lines 404 to 406 in 32d36e2
|
Glad to hear it's fixed this time! For the default implementation of |
…ypes. For a value, `v: Float`, adding `-0.0` is a no-op while adding `0.0` will change the sign if `v` is `-0.0`. The opposite is true for subtraction. When no constant factor exists use an appropriated signed `0.0`. A new enum, `ConstantOp`, is added to allow the `constant(op: ConstantOp)` function to return an appropriately signed `0.0`. v 0.0 + -0.0 = 0.0 -0.0 + 0.0 = 0.0 // v + 0.0 != v -0.0 + -0.0 = -0.0 0.0 - -0.0 = 0.0 -0.0 - 0.0 = 0.0 -0.0 - -0.0 = 0.0 // v - -0.0 != v
Merged! I'll try to get a new version published in the next couple days! |
v0.24.0 published! Thanks again for submitting the issue. |
Use a default constant of
-0.0
to allow for floating pointoptimizations. For a value,
v: Float
, adding-0.0
is a no-op whileadding
0.0
will change the sign ifv
is-0.0
. Resolves #143.@raimundomartins with the changes in this PR your example program generates the expected zero-cost LLVM-IR! If you could review / test with your full code that would be greatly appreciated.