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 FXTRACT for 0.0 and -0.0 #4093

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Fix FXTRACT for 0.0 and -0.0 #4093

wants to merge 4 commits into from

Conversation

pmatos
Copy link
Collaborator

@pmatos pmatos commented Sep 30, 2024

Fixes fxtract by returning the correct values for 0.0 and -0.0. We moved the split of fxtract into _sig and _exp, to the opcode dispatcher, to ease some comparisons.

Also removed the IR node F80XTRACTStack which is not needed anymore.

Depends on landing #4092 (commit d62dd50 included here but to be merged separately)

@pmatos
Copy link
Collaborator Author

pmatos commented Sep 30, 2024

For context the spec mentions that for fscale:

The FSCALE instruction can also be used to reverse the action of the FXTRACT instruction, as shown in the following example:

FXTRACT;
FSCALE;
FSTP ST(1);

When testing this, through FScaleFXtract.asm unit test, I noticed that for 0.0 and -0.0, fxtract was generating incorrect values. I fixed these there.

@pmatos pmatos force-pushed the FXtractFix branch 6 times, most recently from 96fe7af to 6fe0e35 Compare October 2, 2024 15:44
@pmatos
Copy link
Collaborator Author

pmatos commented Oct 2, 2024

All good here now - instcounci failure coming from #4092 that needs to land before this one.

Behaves like NZCVSelect for FPRs.
Fixes fxtract by returning the correct values for 0.0 and -0.0. We moved the split of fxtract into _sig and _exp, to the opcode dispatcher, to ease some comparisons.

Also removed the IR node F80XTRACTStack which is not needed anymore.
@pmatos
Copy link
Collaborator Author

pmatos commented Oct 7, 2024

pinging here for review!
One thing I would like another pair of eyes on is the IR definition of NZCVSelectV. Do we actually need to specify a ResultSize? Can't we just say that the ResultSize is the same size as the TrueVal (or FalseVal). Also maybe we need to validate that these have the same size?

Copy link
Member

@Sonicadvance1 Sonicadvance1 left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, but I'll leave it to Alyssa for the IR change.

@@ -256,6 +260,12 @@ struct FEX_PACKED X80SoftFloat {

return Result;
#else
// Zero is a special case, the exponent is always -inf
if (lhs.Exponent == 0x0 && lhs.Significand == 0x0) {
X80SoftFloat Result(1, 0x7FFFUL, 0x8000000000000000UL);
Copy link
Member

@neobrain neobrain Oct 10, 2024

Choose a reason for hiding this comment

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

Hardcoded constants with lots of zeroes like these are prone to typos that aren't easily caught in code review either. There's two ways to avoid this issue:

  • Compute the constant symbolically: 1UL << 63
  • Use digit separators to make double-checking easier: 0x8000'0000'0000'0000UL

(Mentioning this here because the PR adds a bunch such constants and I stopped counting zeroes after the first one)

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.

3 participants