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

[INTERP] Fix fpu_round #1030

Merged
merged 7 commits into from
Oct 25, 2023
Merged

[INTERP] Fix fpu_round #1030

merged 7 commits into from
Oct 25, 2023

Conversation

ksco
Copy link
Collaborator

@ksco ksco commented Oct 15, 2023

The nearbyint functions round their argument to an integer value in floating-point format, using the current rounding direction, therefore it's not "ROUND_Nearest". We should use round.

@ptitSeb
Copy link
Owner

ptitSeb commented Oct 15, 2023

I'm pretty sure nearbyint is used in more than 1 place!

@ksco
Copy link
Collaborator Author

ksco commented Oct 15, 2023

Ah, it does! Let me change all of 'em then.

@ksco
Copy link
Collaborator Author

ksco commented Oct 15, 2023

Ok, done.

@ptitSeb
Copy link
Owner

ptitSeb commented Oct 15, 2023

Tests are not happy with this changes

@ksco
Copy link
Collaborator Author

ksco commented Oct 15, 2023

Seems 0.5 in cvtps2pd cvtps2dq should be rounded to 0 in "ROUND_Nearest" mode, that's really strange, am I missing something? 🤔️

@ptitSeb
Copy link
Owner

ptitSeb commented Oct 15, 2023

Seems 0.5 in cvtps2pd should be rounded to 0 in "ROUND_Nearest" mode, that's really strange, am I missing something? 🤔️

Mmm no, cvtps2pd 0.5 should still be 0.5. Value should not be round to integer at all on cvtps2pd, as it's just packed float to packet double.

@ksco
Copy link
Collaborator Author

ksco commented Oct 15, 2023

Sorry I mean the cvtps2dq, these names confuses me :'(

@ksco
Copy link
Collaborator Author

ksco commented Oct 15, 2023

Ah, it actually "Round to Nearest, ties to Even", so 0.5 is expected to round to 0.

@ksco
Copy link
Collaborator Author

ksco commented Oct 15, 2023

@ptitSeb seems working; also tested test22 with BOX64_DYNAREC_TEST=1 locally, works too (this is how I found the issue).

@ptitSeb
Copy link
Owner

ptitSeb commented Oct 15, 2023

Ok, we don't want to set the rounding mode at each function call and not letting it reset to it's previous value

The rounding mode might needed to be tracked (might need to actually wrap fesetround to be able to restore old value after round is done (or do nothing if the current rounding mode is already ok).

@ksco ksco marked this pull request as draft October 15, 2023 17:19
@ksco ksco marked this pull request as ready for review October 24, 2023 18:33
@ksco
Copy link
Collaborator Author

ksco commented Oct 24, 2023

@ptitSeb I pushed some commits to take care of library wrapping, please review again.

@ptitSeb ptitSeb merged commit 87bf751 into ptitSeb:main Oct 25, 2023
28 checks passed
@ksco ksco deleted the round_nearest branch October 25, 2023 13:27
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