#![cfg(feature = "nightly")]
#![doc(hidden)]
pub use fpu_precision::set_precision;
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
mod fpu_precision {
use core::mem::size_of;
pub struct FPUControlWord(u16);
fn set_cw(cw: u16) {
unsafe {
asm!(
"fldcw word ptr [{}]",
in(reg) &cw,
options(nostack),
)
}
}
pub fn set_precision<T>() -> FPUControlWord {
let mut cw = 0_u16;
let cw_precision = match size_of::<T>() {
4 => 0x0000, 8 => 0x0200, _ => 0x0300, };
unsafe {
asm!(
"fnstcw word ptr [{}]",
in(reg) &mut cw,
options(nostack),
)
}
set_cw((cw & 0xFCFF) | cw_precision);
FPUControlWord(cw)
}
impl Drop for FPUControlWord {
fn drop(&mut self) {
set_cw(self.0)
}
}
}
#[cfg(any(not(target_arch = "x86"), target_feature = "sse2"))]
mod fpu_precision {
pub fn set_precision<T>() {
}
}