Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

core.internal.convert: add IEEE Quadruple support #2257

Merged
merged 1 commit into from
Sep 20, 2018
Merged

core.internal.convert: add IEEE Quadruple support #2257

merged 1 commit into from
Sep 20, 2018

Conversation

joakim-noah
Copy link
Contributor

@joakim-noah joakim-noah commented Jul 29, 2018

This is a WIP pull, as I'm going to add another commit that reworks how druntime initializes TLS data on Android before passing it to the GC, based on a suggestion of Martin from the ldc team. I wanted to get this first math commit up now to run it through the CI and review, as this one should be done.

I've tested this commit with ldc 0.17 natively on Android/AArch64 and linux/AArch64, and by cross-compiling with ldc 1.11 master for Android/AArch64 (all tests build and pass, but only because they're all truncated at 80-bit precision), along with making sure it didn't break anything on linux/x64. With this patch, all the druntime unit tests finally compile and pass on AArch64.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @joakim-noah!

Bugzilla references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + druntime#2257"

@@ -106,8 +124,8 @@ private Float parse(bool is_denormalized = false, T)(T x) if(is(Unqual!T == iflo
private Float parse(bool is_denormalized = false, T:real)(T x_) if(floatFormat!T != FloatFormat.Real80)
{
Unqual!T x = x_;
assert(floatFormat!T != FloatFormat.DoubleDouble && floatFormat!T != FloatFormat.Quadruple,
"doubledouble and quadruple float formats are not supported in CTFE");
static assert(floatFormat!T != FloatFormat.DoubleDouble,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert was never actually triggered at compile-time.

enum NAN = Float(-1, 0x7fff, 0);
enum NNAN = Float(-1, 0x7fff, 1);
enum NAN = Float(0, 0x7fff, 0, 0x80000000000000UL);
enum NNAN = Float(0, 0x7fff, 1, 0x80000000000000UL);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't bother adding 0's everywhere else the Float constructor was called, as this is the only 112-bit mantissa where the most significant bits in mantissa2 needed to be set.

@ibuclaw
Copy link
Member

ibuclaw commented Sep 15, 2018

This is a poorly named PR, as this isn't android specific. You infact fix all platforms that have 128bit IEEE reals.

{
x *= 2.0L^^FloatTraits!T.MANTISSA;
auto fl = parse!true(x);
ulong mant = fl.mantissa >> (FloatTraits!T.MANTISSA - fl.exponent);
return shiftrRound(mant);
}

@safe pure nothrow @nogc
private Float denormalizedMantissa(T)(T x, uint sign) if(floatFormat!T == FloatFormat.Quadruple)
Copy link
Member

@ibuclaw ibuclaw Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't overload the above functions and so should have a distinct name, ie: floatDenormalizedMantissa.

Having a look at all uses of the other function, they are all Float(denormalizedMantissa(x), 0, sign), so they all could be refactored to return a Float as well as sharing the same signature as this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll fix it.

@ibuclaw
Copy link
Member

ibuclaw commented Sep 18, 2018

@joakim-noah ping

@joakim-noah
Copy link
Contributor Author

I want to get back to testing that second commit, but busy with other stuff first. Will get back to the second commit next week probably, and once that's up, this pull should be ready to go. If you've any further feedback on this commit, we can discuss it in the meantime.

@joakim-noah
Copy link
Contributor Author

Btw, is you pinging me now in any way related to the current gcc submission? If so, feel free to use and modify this patch in any way you want to there: I'm making it available under the same Boost license as the rest of druntime.

@ibuclaw
Copy link
Member

ibuclaw commented Sep 19, 2018

No, I was porting druntime to risc-v, and went about implementing this myself, only to find that you've already done it.

@ibuclaw
Copy link
Member

ibuclaw commented Sep 19, 2018

This one patch is actually blocking all ports that have 128-bit reals from being buildable. So this a high priority fix IMO. Your other patch can wait for another PR.

@joakim-noah joakim-noah changed the title Two fixes for Android/AArch64 core.internal.convert: add IEEE Quadruple support Sep 19, 2018
@joakim-noah
Copy link
Contributor Author

Fine with me, added another commit with the change you asked for. Feel free to squash the two and merge once the CI passes.

@joakim-noah
Copy link
Contributor Author

Looks like the FreeBSD64 part of the auto-tester hung, so squashed the commits to get it to restart.

@joakim-noah
Copy link
Contributor Author

CI passed, ready to go.

@@ -314,21 +354,49 @@ private uint binLog2(T)(const T x)
}

@safe pure nothrow @nogc
private ulong denormalizedMantissa(T)(T x) if(floatFormat!T == FloatFormat.Real80)
private Float denormalizedMantissa(T)(T x, uint sign) if(floatFormat!T == FloatFormat.Real80)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't suppose these could be named floatDenormalizedMantissa or floatWithDenormalizedMantissa to make it more clear from the caller what they return.

Not too fussed either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private function only used in this module at CTFE, don't think it's worth kicking off the CI again for this trivial rename.

@ibuclaw
Copy link
Member

ibuclaw commented Sep 19, 2018

Bikeshed nit, but otherwise LGTM.

@dlang-bot dlang-bot merged commit 4f86f98 into dlang:master Sep 20, 2018
kraj pushed a commit to kraj/gcc that referenced this pull request Nov 17, 2018
Backport from upstream druntime 2.083 for AArch64.

Reviewed-on: dlang/druntime#2257

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@266222 138bc75d-0d04-0410-961f-82ee72b054a4
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this pull request May 16, 2022
Backport from upstream druntime 2.083 for AArch64.

Reviewed-on: dlang/druntime#2257

From-SVN: r266222
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants