Skip to content

riscv: Fix feholdexcept() - #324

Merged
ViralBShah merged 2 commits into
JuliaMath:masterfrom
AlekseyZhmulin:master
Jun 22, 2026
Merged

ViralBShah merged 2 commits into
JuliaMath:masterfrom
AlekseyZhmulin:master

Conversation

@AlekseyZhmulin

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented May 7, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.09%. Comparing base (c9c6fd6) to head (361868e).
⚠️ Report is 12 commits behind head on master.

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 Harness.
📢 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.

@inkydragon inkydragon left a comment

Copy link
Copy Markdown
Member

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

AlekseyZhmulin commented May 9, 2025 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Member

@ViralBShah

Copy link
Copy Markdown
Member

@inkydragon Thoughts on whether we should merge?

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

Copilot AI left a comment

Copy link
Copy Markdown

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);

@AlekseyZhmulin

Copy link
Copy Markdown
Contributor Author

I also added clearing of all exception flags in feholdexcept()

@ViralBShah
ViralBShah merged commit 3329022 into JuliaMath:master Jun 22, 2026
20 checks passed
maleadt added a commit to JuliaLang/julia that referenced this pull request Sep 3, 2026
Picks up JuliaMath/openlibm#360, which stops the riscv64 port from
exporting its fenv functions. Those symbols shadowed glibc's through the
dynamic linker while carrying FreeBSD's pre-shifted `FE_*` encodings, so
`fesetround` rejected every constant a caller had compiled against the
system header and left the rounding mode untouched. Julia's own rounding
path stopped going through that symbol in `6081d7ceb7`, but anything
else linked against the bundled library still did.

The release also carries three riscv64 fixes that never reached the
0.8.7 build: JuliaMath/openlibm#324 (`feholdexcept` always returned -1),
and JuliaMath/openlibm#330 and JuliaMath/openlibm#349 for the lp64f ABI.

Assisted-by: Claude Code (Opus 5)
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
openlibm 0.8.8

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Update riscv64 fenv.c initialization to fix warnings by @ViralBShah in JuliaMath/openlibm#330
* Musl compatibility fixes for s390 and powerpc by @sertonix in JuliaMath/openlibm#331
* Fix cmake error for 4.x by @HIllya51 in JuliaMath/openlibm#333
* Bump actions/checkout from 4 to 5 by @dependabot[bot] in JuliaMath/openlibm#335
* Bump actions/upload-artifact from 4 to 5 by @dependabot[bot] in JuliaMath/openlibm#336
* Bump actions/checkout from 5 to 6 by @dependabot[bot] in JuliaMath/openlibm#338
* Bump actions/upload-artifact from 5 to 6 by @dependabot[bot] in JuliaMath/openlibm#339
* Bump actions/upload-artifact from 6 to 7 by @dependabot[bot] in JuliaMath/openlibm#341
* Bump codecov/codecov-action from 5 to 6 by @dependabot[bot] in JuliaMath/openlibm#342
* ci: add native ARM (Linux + Windows) and Intel macOS runners by @ViralBShah in JuliaMath/openlibm#345
* ci: workflow hygiene (concurrency, timeouts, loongarch fold, mips64, fork-safe codecov) by @ViralBShah in JuliaMath/openlibm#346
* riscv: Fix feholdexcept() by @AlekseyZhmulin in JuliaMath/openlibm#324
* CI: add -Werror strict lane and an auto-discovered regression-test harness by @ViralBShah in JuliaMath/openlibm#350
* ci: speed up Windows jobs by trimming the msys2 install by @ViralBShah in JuliaMath/openlibm#354
* ci: make codecov coverage status informational by @ViralBShah in JuliaMath/openlibm#358
* riscv: allow single-precision float ABI (lp64f / ilp32f) by @ViralBShah in JuliaMath/openlibm#349
* Fix powl() returning NaN instead of +0 on extreme underflow (#334) by @ViralBShah in JuliaMath/openlibm#351
* Make powl() thread-safe (#222) by @ViralBShah in JuliaMath/openlibm#355
* Bump codecov/codecov-action from 6 to 7 by @dependabot[bot] in JuliaMath/openlibm#359
* riscv64: Keep hard-float fenv functions private by @maleadt in JuliaMath/openlibm#360

## New Contributors
* @sertonix made their first contribution in JuliaMath/openlibm#331
* @HIllya51 made their first contribution in JuliaMath/openlibm#333
* @AlekseyZhmulin made their first contribution in JuliaMath/openlibm#324

**Full Changelog**: https://github.com/JuliaMath/openlibm/compare/v0.8.7...v0.8.8</pre>
  <p>View the full release notes at <a href="https://github.com/JuliaMath/openlibm/releases/tag/v0.8.8">https://github.com/JuliaMath/openlibm/releases/tag/v0.8.8</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!18388
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.

4 participants