Skip to content

libclc: frexp: fix implementation regarding denormals #134823

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

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

rjodinchr
Copy link
Contributor

Devices not supporting denormals can compare them true against zero. It leads to result not matching the CTS expectation when either supporting or not denormals.

For example for 0x1.008p-140 we get {0x1.008p-140, 0} while the CTS expects {0x1.008p-1, -139} when supporting denormals, or {0, 0} when not supporting denormals (flushed to zero).

Ref #129871

Devices not supporting denormals can compare them true against zero.
It leads to result not matching the CTS expectation when either
supporting or not denormals.

For example for 0x1.008p-140 we get {0x1.008p-140, 0} while the CTS
expects {0x1.008p-1, -139} when supporting denormals, or {0, 0} when
not supporting denormals (flushed to zero).

Ref llvm#129871
@rjodinchr
Copy link
Contributor Author

@frasercrmck could you please review?

@@ -26,7 +26,7 @@ __clc_frexp(__CLC_GENTYPE x, __CLC_ADDRESS_SPACE __CLC_INTN *ep) {
(ai & (__CLC_INTN)MANTBITS_SP32);

__CLC_INTN is_inf_nan_or_zero =
x == __CLC_FP_LIT(0.0) || __clc_isinf(x) || __clc_isnan(x);
ai == (__CLC_INTN)0 || __clc_isinf(x) || __clc_isnan(x);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was in the original code that we're essentially reverting to, but do we know this is correct for -0.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is correct for -0.0, ai is the bitcast of the absolute value of x.

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 is passing the CTS on all platforms I could put my hand on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is correct for -0.0, ai is the bitcast of the absolute value of x.

Oh I'm silly, yes of course. Not sure how I thought the opposite was going on!

@rjodinchr rjodinchr requested a review from frasercrmck April 8, 2025 13:17
@frasercrmck frasercrmck merged commit 0e98817 into llvm:main Apr 8, 2025
10 checks passed
@rjodinchr rjodinchr deleted the pr/frexp branch April 8, 2025 13:56
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.

2 participants