-
Notifications
You must be signed in to change notification settings - Fork 12
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
fixes to std.math such that all unit tests pass on LDC 64bit windows. #7
Conversation
Fix bad form: missing brackets in if/else statement. Fix invalid assumption about llvm_sqrt. It does not return defined values when it's argument is less than zero. Add a unit test for llvm_sqrt assumption.
…in LDC. All constants have enough significant figures for the compiler to create binary exact representations to within the closest ULP. (Unit in the last place) Remove mathematical operations from constants that might introduce rounding errors.
…e 80 bits. Disable some other tests because they are using floating point constants.
|
Thanks for your work! Regarding the floating point constants, I'd really rather fix this once and for all by using a Concerning the 64 bit |
|
Any chance we can try with the floating point constants? lol. Seriously though, they are such a pain to work with. If I am interpreting the 64 bit real issue correctly, the problem isn't one of processor support, but of calling conventions. Variables larger than 64 bits have to be stored in memory and can't be stored in registers, yet LDC stores them on the stack and pushes them into registers. I have no idea how to touch this. Mind you, a week ago I didn't know about 64 bit calling conventions and a whole lot of other stuff... so who knows what I'll be able to do in the future. |
|
No worries, keep on experimenting. At this rate, you'll be a world-class compiler expert in no time. ;) What I meant by "64 bit real issues" are the precision problems in the tests. I was just suggesting that maybe @jpf91, @ibuclaw or @smolt might already have some changes to make the tests work (maybe even in upstream Git master). At least, they might also be interested in the topic. |
|
Is there a version that is for both win64 and LDC? That was something else that I thought about.. shouldn't all of the version = whatever lines be all in one place? |
No, you need to manually nest them or define a new version locally (e.g.
How do you mean in one place? |
|
I didn't realize that they had private scope. I just checked the predefined versions. I think I assumed that some of them must not have been predefined and were therefore imported. |
|
I am interesting in following the topic. I too am working on 64-bit reals, specifically arm. I think one common problem area for us in std.math is exp(). In the unit test you versioned out there is a test set for 80-bit real. I started on a test set for 64-bit reals but have not filled in the cases for under and overflow. I find a 1 bit difference in exp() results sometimes. All other unittests work as expected except I get a funny answer from acosh() when optimization is enabled and subnormal behavior is different for some functions on iOS. If you diff ios branch with release-0.15.0 branch, you can see where I made |
|
A 1 bit difference is no biggy. Floating point math is not deterministic between different compilers or platforms. Any comparisons should be made with the std.math.approxEqual function instead of ==. I'll take at your tests in the morning. Is there a standard somewhere that tells what tests should be made or are you just winging it? |
|
No standard, just winging it with the 80-bit real exp() tests cases as starting point. Still need to calc some cases that are commented out. I agree that 1 bit diff is usually a don't care, but coming from a place that built ASIC DSP, I usually want to understand the reason. |
|
Hi Kevin,
|
|
@JohanEngelen yes, after I completed the rest of the test set. If someone else gets to it first, that would be great as I have been involved in some other fun projects :-) |
|
@KevinBrogan Thanks for the work! Like @JohanEngelen I think it is better to break this PR in parts. @JohanEngelen Yes, using the LLVM assembly results in better code. E.g. DMD style assembly is not inlined. |
|
I've come up with dlang#3285 to address the @smolt Would you please give it a shot on ARM? |
|
@kinke - I only have iOS flavored ARM setup now and it has some unique properties. I don't think I can provide any additional input at this time besides some comments and that the real-64 test cases for On iOS, subnormals generally are not supported. ARM FPU Flush-To-Zero mode is enabled by default (subnormal math results become zero) by iOS runtime. When I explicitly disable Flush-To-Zero mode, libm math routines such as |
|
I cut the |
|
Thanks! - All my std.math unittests pass for iOS now. The Out of curiosity, I had to study why I see David documented this behavior in druntime ldc/intrinsics.di back in 2012. |
|
Yep, that fixes the std.math-release issue(s) on Win64 too. @smolt Wrt. the subnormal tests: parsing subnormal literals as 0 if the target doesn't support them would probably be the best solution and fix these feqrel() asserts, right? Wrt. the IEEE flags: the LLVM exp.f64() intrinsic doesn't set the flags either (at least on Win64), so I was planning on simply skipping the flags tests in LDC altogether. |
|
@kinke - To handle subnormal cases on iOS, I pass all expected results from table through this function before comparing to Maybe a specific version to opt-in or opt-out of flag IEEE testing for |
|
@redstar - There is another instance of llvm_sqrt in druntime core.math that may need the nan recheck, depending on its purpose. Not sure if that module is supposed to be bare intrinsics. https://github.com/ldc-developers/druntime/blob/ldc/src/core/math.d#L111 I noticed that checking for and returning nan before calling |
|
I am closing this PR because all Tests in Win64 are green now. |
fixes to std.math such that all unit tests pass on LDC 64bit windows.