Skip to content

riscv: Fix feholdexcept() #324

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AlekseyZhmulin
Copy link

The feholdexcept() function must store the current floating point environment in *__envp.
Related to #321

Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.09%. Comparing base (d463259) to head (d200afe).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #324   +/-   ##
=======================================
  Coverage   72.09%   72.09%           
=======================================
  Files         233      233           
  Lines        6139     6139           
  Branches     1607     1607           
=======================================
  Hits         4426     4426           
  Misses       1420     1420           
  Partials      293      293           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@inkydragon inkydragon left a comment

Choose a reason for hiding this comment

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

We're doing the same thing as BSD.
I'm not sure this works.

https://github.com/freebsd/freebsd-src/blob/master/lib/msun/riscv/fenv.h#L188-L195

@AlekseyZhmulin
Copy link
Author

AlekseyZhmulin commented May 9, 2025

The problem is that feholdexcept() does not save floating point environment, but feupdateenv() loads floating point environment. Therefore, in the lrint() function, "fenv_t env" is not initialized and a random value from the stack is loaded into the fcsr register. https://github.com/JuliaMath/openlibm/blob/master/src/s_lrint.c#L59. This throws an "Illegal instruction" exception.

@ViralBShah
Copy link
Member

@ViralBShah
Copy link
Member

@inkydragon Thoughts on whether we should merge?

@ViralBShah ViralBShah requested a review from Copilot June 3, 2025 22:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the feholdexcept() function to correctly store the current floating point environment in *__envp and update its return value to indicate success.

  • Added the __rfs(*__envp) call to store the floating point state.
  • Changed the return value from -1 to 0 to align with a successful operation.
Comments suppressed due to low confidence (2)

include/openlibm_fenv_riscv.h:193

  • Consider adding a brief inline comment explaining the purpose of __rfs in storing the floating point environment for better maintainability.
__rfs(*__envp);

include/openlibm_fenv_riscv.h:197

  • Returning 0 indicates success; please confirm that this change fully aligns with the API contract for feholdexcept() in this context.
return (0);

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