Skip to content
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

std.math: Implement more optimal floorImpl for ieeeSingle #5820

Merged
merged 2 commits into from Mar 28, 2018

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Oct 28, 2017

Less branching, and doesn't care about endian-ness. Tested against PPC64/LE.

For comparison between old (source view 1) and new (source view 2) https://explore.dgnu.org/g/fTvttz

Probably better to review with https://github.com/dlang/phobos/pull/5820/files?w=1

@dlang-bot
Copy link
Contributor

dlang-bot commented Oct 28, 2017

Thanks for your pull request, @ibuclaw!

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 + phobos#5820"

@ibuclaw
Copy link
Member Author

ibuclaw commented Jan 6, 2018

Ping?

@JackStouffer
Copy link
Member

Pinging people who are qualified to review this from git blame @yebblies @wilzbach @don-clugston-sociomantic @klickverbot

@ibuclaw
Copy link
Member Author

ibuclaw commented Jan 8, 2018

Or you know, you could just request a review. :)

@ibuclaw ibuclaw requested review from donc and wilzbach January 8, 2018 20:17
Copy link
Contributor

@don-clugston-sociomantic don-clugston-sociomantic left a comment

Choose a reason for hiding this comment

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

I think the code itself is probably OK but it's so cryptic that it's hard to review. I think this low-level stuff really needs copious comments.


// Other kinds of extractors for real formats.
static if (F.realFormat == RealFormat.ieeeSingle)
int vi;
}
floatBits y = void;
y.rv = x;

// Find the exponent (power of 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

This deserves a much better comment since this code is actually quite tricky.

// Find the exponent (power of 2)
// Do this by shifting the raw value so that the exponent lies in the low bits.
// Then mask out the sign bit, and subtract the bias

std/math.d Outdated
exp -= 16;
if (exp < (T.mant_dig - 1))
{
const uint i = F.MANTISSAMASK_INT >> exp;
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable deserves a better name. I think this is actually fraction_mask, the bits of the mantissa which form the fraction.

std/math.d Outdated
if ((y.vi & i) != 0)
{
if (y.vi < 0)
y.vi += 0x00800000 >> exp;
Copy link
Contributor

Choose a reason for hiding this comment

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

This REALLY needs a comment. My guess is that this is the float value 0.5, added so that it rounds up towards zero? Or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is subtracting one, adding comment.

@ibuclaw
Copy link
Member Author

ibuclaw commented Mar 17, 2018

@redstar - And this you might be interested in also.

@dlang-bot dlang-bot merged commit 8c22235 into dlang:master Mar 28, 2018
@ibuclaw ibuclaw deleted the floatfloor branch March 28, 2018 07:13
andreiv05 pushed a commit to andreiv05/phobos that referenced this pull request Mar 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants