Replace pointer casts in std.math with union repainting#3499
Replace pointer casts in std.math with union repainting#3499ivan-timokhin wants to merge 24 commits intodlang:masterfrom
Conversation
|
Let's start with the bike shedding first, as that should be the easy bit.... :-)
64bit, 128bit, and x87 reals by the looks of it. (Considering that DMD code would be using the catch-all else block in there). There should be an explicit You'll just be dereferencing the Maybe from I'm thinking along the lines of: Something that you have already sort of done with |
|
On Sat, Jul 18, 2015 at 05:07:57AM -0700, Iain Buclaw wrote:
Well, I don't like the names too much myself :).
I can probably try and come up with something using bitfields, but I'd like to |
|
Great work! Thanks!
+1 |
|
FloatRep, DoubleRep are not fast enough. |
|
But they do look similar to what Iain suggested, so maybe a better course of action would be to improve them? |
|
Any improvement will break code. The bitfields concept is slow for math. |
|
Yes, |
|
Hm. Then I don't quite understand what the proposed |
|
Anyhow, what I really wanted to know was whether I should try and unify the code with |
|
@ivan-timokhin perhaps after this PR is done we can make |
FloatTraits is package stuff |
Uhh, no. Any bitfieldish stuff like the one done in those two is most definitely out of scope of this PR. I brought them up because if we do want something similar in |
|
Will the result be CTFE-able? |
|
@quickfur Currently unions are not CTFE-able. But they can be in the future. |
This is on my long todo list. |
|
@ibuclaw I've tried to come up with better names. |
1a2c8ef to
2770611
Compare
|
@ivan-timokhin - OK. I've been out of action this week, I'll have a review when I can. In any case, this is for post-2.068 release. |
|
@ibuclaw any chance to review/destroy this ? ;) |
|
I've rewritten functions already using unions for uniformity, and the rewrite is usually very straightforward (though I've taken some liberties in |
There was a problem hiding this comment.
This should be the same as mant_dig == 64. All bit manipulation is identical to ieeeExtended for this type.
|
Apart from the nits already mentioned (I may find more). Has there been any benchmarking on this? Are we loosing or gaining performance by switching to higher level accessors? I haven't checked, but I assume that |
|
I didn't look into performance much (will do), but I'd expect the generated code to be more or less the same; e.g., in both https://goo.gl/umkAtu and https://goo.gl/jFzuR2 assembly output is the same for pointers and unions. And yes, it seems that most functions are |
|
😞 Unfortunately, I must admit defeat. The resulting assembly does not look as similar as I hoped it would, and the new one is frequently longer. While for most functions it seems that the new instructions are mostly a slightly permuted version of old ones, my knowledge of assembly is not deep enough to tell if that's significant or not. |
|
No problem. I can dig out a couple from my mailing list archives |
|
For the most part, I think this is fine. Just having a mental pass at it, I can only see one notable place of concern. Last nits will follow and I will give the green light |
std/math.d
Outdated
There was a problem hiding this comment.
This would be turned into a memcmp for ieeeQuadruple and ibmExtended, and goodness knows what for ieeeExtended. For efficiency, I'd recommend keeping the previous behaviour and inline the bit comparison.
|
Because you are dereferencing static arrays instead of pointers, I'd expect there to be more bounds checks, this will distort some things if you plan on doing comparison of assembly. |
|
Why would indexing a static array by a (compile-time) constant offset cause a bounds check to be emitted? |
All peeks are constant offsets, not all pokes are though. |
|
What's the state of this? |
|
I'm afraid I won't be able to devote any time or effort to this in a foreseeable
future, so if it doesn't look mergeable now, I'd suggest just closing this PR,
especially since it doesn't provide any tangible benefits to the end user right
now.
|
|
Two optional nits, but otherwise I'm ok with this. |
From the comments received on #3022, I was left with an impression that unions are generally preferred to pointer casts, and should be used instead wherever possible. So I went ahead and replaced most of the pointer casts with unions.
This is mostly straightforward one-to-one replacement, with notable exception of
isIdentical, because I couldn't resist the temptation.I didn't touch
NaNandgetNaNPayload, becauseDestroy!