Skip to content

Commit 7541108

Browse files
committed
remove FCSR
1 parent 051a80a commit 7541108

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3939
### Removed
4040

4141
- User mode registers removed, as they are no longer supported in RISC-V
42+
- FCSR register operations removed to avoid UB (#148)
4243

4344
## [v0.10.1] - 2023-01-18
4445

src/register.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,35 @@
1010
//! - minstreth
1111
//! - mhpmcounter<3-31>h
1212
//! - mstatush
13+
//!
14+
//! # On Floating-Point CSRs
15+
//!
16+
//! We are deliberately *not* providing instructions that could change the floating-point rounding
17+
//! mode or exception behavior or read the accrued exceptions flags: `frcsr`, `fscsr`, `fsrm`,
18+
//! `frflags`, `fsflags`.
19+
//!
20+
//! Rust makes no guarantees whatsoever about the contents of the accrued exceptions register: Rust
21+
//! floating-point operations may or may not result in this register getting updated with exception
22+
//! state, and the register can change between two invocations of this function even when no
23+
//! floating-point operations appear in the source code (since floating-point operations appearing
24+
//! earlier or later can be reordered).
25+
//!
26+
//! Modifying the rounding mode leads to **immediate Undefined Behavior**: Rust assumes that the
27+
//! default rounding mode is always set and will optimize accordingly. This even applies when the
28+
//! rounding mode is altered and later reset to its original value without any floating-point
29+
//! operations appearing in the source code between those operations (since floating-point
30+
//! operations appearing earlier or later can be reordered).
31+
//!
32+
//! If you need to perform some floating-point operations and check whether they raised an
33+
//! exception, use a single inline assembly block for the entire sequence of operations.
34+
//!
35+
//! If you need to perform some floating-point operations under a different rounding mode, use a
36+
//! single inline assembly block and make sure to restore the original rounding mode before the end
37+
//! of the block.
1338
1439
#[macro_use]
1540
mod macros;
1641

17-
// User Floating-Point CSRs
18-
// TODO: frm, fflags
19-
pub mod fcsr;
20-
2142
// User Counter/Timers
2243
pub mod cycle;
2344
pub mod cycleh;
@@ -29,7 +50,6 @@ pub mod time;
2950
pub mod timeh;
3051

3152
// Supervisor Trap Setup
32-
// TODO: sedeleg, sideleg
3353
pub mod scounteren;
3454
pub mod sie;
3555
pub mod sstatus;

0 commit comments

Comments
 (0)