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

fix fabs() to not use x87 for float/double #7561

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

WalterBright
Copy link
Member

This is a partial fix for https://issues.dlang.org/show_bug.cgi?id=19663

A complete fix would be to make it a compiler intrinsic.

@WalterBright WalterBright requested a review from ibuclaw as a code owner July 21, 2020 07:59
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

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 run digger -- build "master + phobos#7561"

Comment on lines +4123 to +4124
ulong tmp = *cast(ulong*)&d & 0x7FFF_FFFF_FFFF_FFFF;
return *cast(double*)&tmp;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this Endian safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be fine. I added unittests to verify.

Copy link
Member

@ibuclaw ibuclaw Jul 21, 2020

Choose a reason for hiding this comment

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

The CI wouldn't really catch that though, as it's all LittleEndian.

However... FYI @thewilsonator, all targets I'm aware of use same endianness for both float and integer words, regardless whether the it's a BigEndian or LittleEndian architecture. The one exception to the rule (there's always one) is the PDP-11, and I doubt Phobos will ever support that. :-)

Comment on lines +4131 to +4132
uint tmp = *cast(uint*)&f & 0x7FFF_FFFF;
return *cast(float*)&tmp;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@WalterWaldron
Copy link
Contributor

Since it's still round tripping through the stack core.bitop.btr is an option, but it's not a big improvement.

    import core.bitop:btr;
    version (BigEndian) btr(cast(ulong*)&d,7);
    else                btr(cast(ulong*)&d,63);
    return d;

Link to compare functions & compilers: https://d.godbolt.org/z/bvd1Ev

@ibuclaw
Copy link
Member

ibuclaw commented Jul 21, 2020

Since it's still round tripping through the stack core.bitop.btr is an option, but it's not a big improvement.

Link to compare functions & compilers: https://d.godbolt.org/z/bvd1Ev

To be fair, the compiler can recognize the pattern and emit btr all by itself. https://d.godbolt.org/z/r5nWM4

@WalterBright WalterBright merged commit e364edf into dlang:master Jul 21, 2020
@WalterBright WalterBright deleted the fabs-float branch July 21, 2020 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants