Begin replacing floatTraits pointer math with RealRep union#4336
Begin replacing floatTraits pointer math with RealRep union#4336tsbockman wants to merge 2 commits intodlang:masterfrom
Conversation
8a35e27 to
b40630e
Compare
44bdfbf to
529b7c9
Compare
f851ecf to
f471022
Compare
| TODO: Make this publically available through std.bitmanip once the API | ||
| is stable and tested. | ||
| */ | ||
| union RealRep(N) |
There was a problem hiding this comment.
Should be at least package as long as it's not exposed publicly?
There was a problem hiding this comment.
That whole section was already marked package, starting on line 214.
|
I have now tuned this PR to produce the best assembly code that I can. I optimized to minimize memory access, instruction count, branches, and embedded constant size, in about that order. (Note that the runtime code affected by this PR is all bitwise integer ops, so there are no slow, precision-destroying FPU ops to worry about.) Here is a summary of the net change.
Overall, I expect that the new EDIT: LDC uses the |
|
Ping @9il and @ibuclaw . I know this is a lot to review, but can you guys at least take a first look and let me know if this is worth pursuing? I want to start working on follow-up pull requests to convert the rest of the pointer-based code in |
202d8ba to
8160b90
Compare
|
Converting I might reopen if someone asks me to, soon. |
|
There is good work in here. Please do not close. |
std/math.d
Outdated
| alias Mant; | ||
| +/ | ||
|
|
||
| static if (N.mant_dig == 11 && N.max_exp == 0x6) |
There was a problem hiding this comment.
please use decimals for N.max_exp also
There was a problem hiding this comment.
I used hexadecimal for N.max_exp because for all other formats, N.max_exp == (1 << (expDig - 1)) and hexadecimal makes it easy to verify at a glance that the numbers are actually correct.
There was a problem hiding this comment.
In fact... this one should be (1 << (expDig - 1)) == 0x10, also; I don't know where I got 0x6 from. I'll fix that now.
| expDig = 11; | ||
| alias Mant = ulong; | ||
| } | ||
| else static if (N.mant_dig == 53 && N.max_exp == 0x4000) |
|
On the forum, Simen Kjærås questioned the need for a separate While I don't think it can be consolidated with the others, I am wondering if we should just drop it completely. What do you guys think, @ibuclaw and @kinke ? Is |
|
How difficult a change would it be? If trivial then I'd say let's just deal with it when someone has the hardware (or emulator) to test. |
I don't really know how difficult adding Even if I succeed in writing code that is correct, I definitely can't optimize it much without access to a test environment. (Removing the existing incomplete |
|
From https://gcc.gnu.org/wiki/Ieee128PowerPC:
As D Nice PR btw (no time for a proper review though). |
|
Btw such a FP union might come in handy already in druntime instead of Phobos; core.internal.convert could |
OK. I'll keep that in mind for the future. Currently my plan is to keep We can look into publicising it and moving it to druntime or |
|
Note that CTFE supports the special casts: in order to support bit manipulation of floating point values. Changing these to unions will break CTFE support. |
|
@WalterBright I can manually lower the Are those really the only supported casts, though? What about |
|
Those are the only supported casts. Hence, |
|
When I moved type painting out of ctfe, I wrote it with the intention of it being a simple addition to paint basic and vector types to static array and vice versa [1]. Where all you need is to add the case for Tsarray, and do a loop passing the pointer adjusted buffer to encodeXXX or decodeXXX. Then allowing the cast in ctfe as being valid where Target.paintAsType is called from. I had also intended to use this for union support too, but I never got round to it. [1] https://github.com/dlang/dmd/blob/master/src/ddmd/target.d#L374 |
|
@ibuclaw @Biotronic @WalterBright I have opened a DMD PR to extend the repainting capabilities as needed. |
| { | ||
| RealRep!double lo; | ||
| RealRep!double hi; | ||
| } |
There was a problem hiding this comment.
After some testing, can safely say that this is wrong. The most significant part is always first, regardless of of endian-ness on ibmExtended.
Pros:
union.unioncode is easier to read and understand.unioncode is also easier to write, thus freeing mental energy for performance optimizations.ibmExtended, and one for everything else.halforquad) gets easier as more ofstd.mathis converted to useRealRep. (ucentwould help here, though.)std.mathhas been converted, I expect that (in net)RealRepwill have reduced the total line count substantially.RealRepcode; the codegen seems to be very clean, for the most part.Cons:
std.mathwill become substantially more dependant upon inlining for good performance.