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

8265940: Enable C2's optimization for Math.pow(x, 0.5) on all platforms #3755

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
@@ -2571,6 +2571,9 @@ void MacroAssembler::fast_pow(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
jccb(Assembler::notEqual, L_NOT_DOUBLE0DOT5);
jccb(Assembler::parity, L_NOT_DOUBLE0DOT5);
ucomisd(xmm0, ExternalAddress(DOUBLE0));
// According to the API specs, pow(-0.0, 0.5) = 0.0 and sqrt(-0.0) = -0.0.
// So pow(-0.0, 0.5) shouldn't be replaced with sqrt(-0.0).
// -0.0/+0.0 are both excluded since floating-point comparison doesn't distinguish -0.0 from +0.0.
jccb(Assembler::belowEqual, L_NOT_DOUBLE0DOT5); // pow(x, 0.5) => sqrt(x) only for x > 0.0

This comment has been minimized.

Loading
@vnkozlov

vnkozlov Apr 28, 2021
Contributor

Add comment about why 0. case is skipped: -0.0 case.

This comment has been minimized.

Loading
@DamonFool

DamonFool Apr 28, 2021
Author Member

Add comment about why 0. case is skipped: -0.0 case.

Thanks @vnkozlov for your review.

Comments have been added.
Thanks.

sqrtsd(xmm0, xmm0);
jmp(L_2TAG_PACKET_21_0_2);
@@ -1652,6 +1652,9 @@ bool LibraryCallKit::inline_math_pow() {
Node* phi = new PhiNode(region, Type::DOUBLE);

Node* cmp = _gvn.transform(new CmpDNode(base, zero));
// According to the API specs, pow(-0.0, 0.5) = 0.0 and sqrt(-0.0) = -0.0.
// So pow(-0.0, 0.5) shouldn't be replaced with sqrt(-0.0).
// -0.0/+0.0 are both excluded since floating-point comparison doesn't distinguish -0.0 from +0.0.
Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::le));

Node* if_pow = generate_slow_guard(test, NULL);