#[cfg(not(portable_atomic_no_asm))]
use core::arch::asm;
pub(super) use super::super::riscv as atomic;
#[cfg(not(portable_atomic_s_mode))]
macro_rules! status {
() => {
"mstatus"
};
}
#[cfg(portable_atomic_s_mode)]
macro_rules! status {
() => {
"sstatus"
};
}
#[cfg(not(portable_atomic_s_mode))]
const MASK: State = 0x8;
#[cfg(not(portable_atomic_s_mode))]
macro_rules! mask {
() => {
"0x8"
};
}
#[cfg(portable_atomic_s_mode)]
const MASK: State = 0x2;
#[cfg(portable_atomic_s_mode)]
macro_rules! mask {
() => {
"0x2"
};
}
#[cfg(target_arch = "riscv32")]
pub(super) type State = u32;
#[cfg(target_arch = "riscv64")]
pub(super) type State = u64;
#[inline]
pub(super) fn disable() -> State {
let r: State;
unsafe {
asm!(concat!("csrrci {0}, ", status!(), ", ", mask!()), out(reg) r, options(nostack, preserves_flags));
}
r
}
#[inline]
pub(super) unsafe fn restore(r: State) {
if r & MASK != 0 {
unsafe {
asm!(concat!("csrsi ", status!(), ", ", mask!()), options(nostack, preserves_flags));
}
}
}