Skip to content

Commit 0415045

Browse files
committed
riscv: deprecate intrinsics that cannot be used from Rust
1 parent 333e9e9 commit 0415045

File tree

1 file changed

+39
-0
lines changed
  • crates/core_arch/src/riscv_shared

1 file changed

+39
-0
lines changed

crates/core_arch/src/riscv_shared/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,15 @@ pub unsafe fn hinval_gvma_all() {
531531

532532
/// Reads the floating-point control and status register `fcsr`
533533
///
534+
/// Note that Rust makes no guarantees whatsoever about the contents of this register: Rust
535+
/// floating-point operations may or may not result in this register getting updated with exception
536+
/// state, and the register can change between two invocations of this function even when no
537+
/// floating-point operations appear in the source code (since floating-point operations appearing
538+
/// earlier or later can be reordered).
539+
///
540+
/// If you need to perform some floating-point operations and check whether they raised an
541+
/// exception, use an inline assembly block for the entire sequence of operations.
542+
///
534543
/// Register `fcsr` is a 32-bit read/write register that selects the dynamic rounding mode
535544
/// for floating-point arithmetic operations and holds the accrued exception flag.
536545
///
@@ -549,6 +558,10 @@ pub unsafe fn hinval_gvma_all() {
549558
/// [`frflags`]: fn.frflags.html
550559
#[inline]
551560
#[unstable(feature = "stdsimd", issue = "27731")]
561+
#[deprecated(
562+
since = "1.75.0",
563+
note = "see `frcsr` documentation - use inline assembly instead"
564+
)]
552565
pub fn frcsr() -> u32 {
553566
let value: u32;
554567
unsafe { asm!("frcsr {}", out(reg) value, options(nomem, nostack)) };
@@ -557,10 +570,24 @@ pub fn frcsr() -> u32 {
557570

558571
/// Swaps the floating-point control and status register `fcsr`
559572
///
573+
/// Note that modifying the masking flags, rounding mode, or denormals-are-zero mode flags leads to
574+
/// **immediate Undefined Behavior**: Rust assumes that these are always in their default state and
575+
/// will optimize accordingly. This even applies when the register is altered and later reset to its
576+
/// original value without any floating-point operations appearing in the source code between those
577+
/// operations (since floating-point operations appearing earlier or later can be reordered).
578+
///
579+
/// If you need to perform some floating-point operations under a different masking flags, rounding
580+
/// mode, or denormals-are-zero mode, use an inline assembly block and make sure to restore the
581+
/// original `fcsr` register state before the end of the block.
582+
///
560583
/// This function swaps the value in `fcsr` by copying the original value to be returned,
561584
/// and then writing a new value obtained from input variable `value` into `fcsr`.
562585
#[inline]
563586
#[unstable(feature = "stdsimd", issue = "27731")]
587+
#[deprecated(
588+
since = "1.75.0",
589+
note = "see `fscsr` documentation - use inline assembly instead"
590+
)]
564591
pub fn fscsr(value: u32) -> u32 {
565592
let original: u32;
566593
unsafe { asm!("fscsr {}, {}", out(reg) original, in(reg) value, options(nomem, nostack)) }
@@ -597,6 +624,10 @@ pub fn frrm() -> u32 {
597624
/// input variable `value` into `frm`.
598625
#[inline]
599626
#[unstable(feature = "stdsimd", issue = "27731")]
627+
#[deprecated(
628+
since = "1.75.0",
629+
note = "see `fscsr` documentation - use inline assembly instead"
630+
)]
600631
pub fn fsrm(value: u32) -> u32 {
601632
let original: u32;
602633
unsafe { asm!("fsrm {}, {}", out(reg) original, in(reg) value, options(nomem, nostack)) }
@@ -621,6 +652,10 @@ pub fn fsrm(value: u32) -> u32 {
621652
/// | 0 | NX | Inexact |
622653
#[inline]
623654
#[unstable(feature = "stdsimd", issue = "27731")]
655+
#[deprecated(
656+
since = "1.75.0",
657+
note = "see `frcsr` documentation - use inline assembly instead"
658+
)]
624659
pub fn frflags() -> u32 {
625660
let value: u32;
626661
unsafe { asm!("frflags {}", out(reg) value, options(nomem, nostack)) };
@@ -634,6 +669,10 @@ pub fn frflags() -> u32 {
634669
/// input variable `value` into `fflags`.
635670
#[inline]
636671
#[unstable(feature = "stdsimd", issue = "27731")]
672+
#[deprecated(
673+
since = "1.75.0",
674+
note = "see `frcsr` documentation - use inline assembly instead"
675+
)]
637676
pub fn fsflags(value: u32) -> u32 {
638677
let original: u32;
639678
unsafe { asm!("fsflags {}, {}", out(reg) original, in(reg) value, options(nomem, nostack)) }

0 commit comments

Comments
 (0)