std.math.trigonometry: fix tan asm x86 implementation for ldc compiler#8199
std.math.trigonometry: fix tan asm x86 implementation for ldc compiler#8199RazvanN7 merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @ljmf00! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8199" |
|
@kinke meanwhile I found out that declaring |
f0b0b25 to
5e2338f
Compare
maxhaton
left a comment
There was a problem hiding this comment.
Needs a test case, i.e. What wrong value? Would also be good to make sure that there is coverage for exactly this implementation rather than just the top level tan
This behaviour is already being tested and the assembly version is being covered, but unfortunately, coverage reporting doesn't work with AFAIK phobos doesn't run LDC test cases at all so the problem needs to be fixed on the LDC test suite, that's why I tagged @kinke to be aware of this problem. |
OK, but what does "fail" mean, does the moon fall out of the sky or does it return wrong values? Nan values? This would also benefit from a comment in the code noting the change |
It returns wrong values on LDC. More precisely, 0 when not fed with infinity. The point is: this is already being tested. I don't see the point of creating more test cases. The failing point here is not compiling the tests with
Can you suggest something? I wrote a brief description on the commit body in case someone does a |
You're right, what is being tested is LDC's fork of Phobos, which already includes a workaround for this: https://github.com/ldc-developers/phobos/blob/e5258ae22258cf839790d267a281c1237453b3c0/std/math/trigonometry.d#L214-L315 |
Why not upstream these changes? |
|
This is just one of a bunch of std.math adaptations for LDC, see e.g. ldc-developers@b3efcea. This one is a particularly ugly workaround for LDC limitations wrt. DMD-style inline asm; others don't make much too much sense upstream IMO, just uglifying Phobos with LDC specifics (and further if the GDC-specifica would be upstreamed too). |
There are some things I already fixed here in the upstream, like relying on the runtime function when possible. I'm not totally sure, but those patches seem to lack code review because there are better options to go with. E.g. ldc-developers@b3efcea#diff-b7811717fbf1cc1b4465a9a51fdd2bf5e1ee6cdfe51f3d77deb3943ce0f941daR3394-R3396 this decreases binary compatibility and does not actually follow Phobos. It may compile fine, but not portable when switching binaries at runtime. Another stuff that clearly isn't good is disabling unittests. These are the type of things that makes LDC adoption more breakable in a production-ready environment, and we all know that everyone uses LDC for release code. I don't see the problem of including some LDC and GDC specifics in the standard library if they are sane changes. Maintaining three different repositories are not productive in a long run. |
Decreases binary compatibility in what way? The signature is identical, are you talking about the Feel free to try to improve the existing implementations; but note that testing them is a PITA for non-LDC devs like you, as our Phobos fork doesn't have CI, and needs to be tested by opening an LDC PR and advancing the Phobos submodule accordingly. |
https://run.dlang.io/is/CCcCT2 I just realized that those overloads are not part of the official standard library. This should be fixed. This is pretty much enforcing people using People that do https://godbolt.org/z/T1h3Y9oqc
Can we do better? I would love to see more integration with other compilers in the official Phobos test suite, at least for LDC. Most people use LDC for releases and I've seen code breakage for LDC only when compiling with release mode. I think this will not only increase stability but also make D more production-ready, although I understand that the official team doesn't want to mix those implementations, which is unfortunate. |
Ah that's what you meant - yes, this is exactly why they are commented out, just waiting for upstream to finally get them. There are multiple issues about this, e.g., https://issues.dlang.org/show_bug.cgi?id=18559 and https://issues.dlang.org/show_bug.cgi?id=19346. I've had a go at a bunch of them a while back (especially those for which there's no LLVM intrinsic), but there sadly hasn't been much movement on that front since then: #6272 |
I can write some overrides for these situations then, but this may introduce a breaking change if there are people relying on the previous overloads. |
|
Anyway, is this good to go? @maxhaton If yes, can you elaborate on the comment suggestion? |
| return real.nan; | ||
|
|
||
| Clear1: asm pure nothrow @nogc{ | ||
| fld rnan ; // return rnan |
There was a problem hiding this comment.
How is this supposed to work? You're pushing rnan, then popping it immediately again via fstp in Clear1 before returning, right?
There was a problem hiding this comment.
Ups, forgot to jump to Lret label. Nice catch, even though, it doesn't fail. Fixed
That'd be great.
Breaking changes for a new compiler/druntime/Phobos version wouldn't be something new, and good ones like these are warmly welcome, especially if the old behavior can be restored via an explicit cast to real. |
260d94a to
8c944cf
Compare
Sure, I'll add this on a separate PR as it is unrelated. |
Somehow, separating asm blocks in small pieces produces additional `mov`s and other instructions on LDC that breaks the tanAsm logic and therefore returns wrong values. Signed-off-by: Luís Ferreira <contact@lsferreira.net>
8c944cf to
62e01fc
Compare
|
@maxhaton I added a comment describing why I added the additional immutable variable. Is this good to go now? Let me know if anything is still missing. |
maxhaton
left a comment
There was a problem hiding this comment.
LGTM but if any one has objections please speak up
Somehow, separating asm blocks in small pieces produces additional
movs and other instructions on LDC that breaks the tanAsm logic andtherefore returns wrong values.
Signed-off-by: Luís Ferreira contact@lsferreira.net
CC: @kinke
I'm pretty sure this is not being tested on LDC. I would love to see some coverage reporting for LDC builds. A comparison of DMD and LDC coverage is desired to seek some problems on LDC code generation.
Here's the problem isolated: https://godbolt.org/z/bEhGa1d9P
Here is the asm diff of this change for more context: