add dummy fenv implementation

This commit is contained in:
Erik 2018-07-15 13:14:29 -04:00
parent 865fedeac6
commit 7084ce52b7
3 changed files with 44 additions and 4 deletions

View file

@ -0,0 +1,33 @@
// src: musl/src/fenv/fenv.c
/* Dummy functions for archs lacking fenv implementation */
pub(crate) const FE_UNDERFLOW: i32 = 0;
pub(crate) const FE_INEXACT: i32 = 0;
pub(crate) const FE_TONEAREST: i32 = 0;
pub(crate) const FE_TOWARDZERO: i32 = 0;
#[inline]
pub(crate) fn feclearexcept(_mask: i32) -> i32 {
0
}
#[inline]
pub(crate) fn feraiseexcept(_mask: i32) -> i32 {
0
}
#[inline]
pub(crate) fn fetestexcept(_mask: i32) -> i32 {
0
}
#[inline]
pub(crate) fn fegetround() -> i32 {
FE_TONEAREST
}
#[inline]
pub(crate) fn fesetround(_r: i32) -> i32 {
0
}

View file

@ -28,6 +28,11 @@
use core::f32;
use core::ptr::read_volatile;
use super::fenv::{
feclearexcept, fegetround, feraiseexcept, fesetround, fetestexcept, FE_INEXACT, FE_TONEAREST,
FE_TOWARDZERO, FE_UNDERFLOW,
};
/*
* Fused multiply-add: Compute x * y + z with a single rounding error.
*
@ -61,12 +66,12 @@ pub fn fmaf(x: f32, y: f32, mut z: f32) -> f32 {
underflow may not be raised correctly, example:
fmaf(0x1p-120f, 0x1p-120f, 0x1p-149f)
*/
if e < 0x3ff - 126 && e >= 0x3ff - 149 && fetestexcept(FE_INEXACT) {
if e < 0x3ff - 126 && e >= 0x3ff - 149 && fetestexcept(FE_INEXACT) != 0 {
feclearexcept(FE_INEXACT);
/* TODO: gcc and clang bug workaround */
// prevent `xy + vz` from being CSE'd with `xy + z` above
let vz: f32 = unsafe { read_volatile(&z) };
result = xy + vz as f64;
if fetestexcept(FE_INEXACT) {
if fetestexcept(FE_INEXACT) != 0 {
feraiseexcept(FE_UNDERFLOW);
} else {
feraiseexcept(FE_INEXACT);
@ -81,7 +86,8 @@ pub fn fmaf(x: f32, y: f32, mut z: f32) -> f32 {
* we need to adjust the low-order bit in the direction of the error.
*/
fesetround(FE_TOWARDZERO);
let vxy: f64 = unsafe { read_volatile(&xy) }; /* XXX work around gcc CSE bug */
// prevent `vxy + z` from being CSE'd with `xy + z` above
let vxy: f64 = unsafe { read_volatile(&xy) };
let mut adjusted_result: f64 = vxy + z as f64;
fesetround(FE_TONEAREST);
if result == adjusted_result {

View file

@ -122,6 +122,7 @@ pub use self::truncf::truncf;
// Private modules
mod expo2;
mod fenv;
mod k_cos;
mod k_cosf;
mod k_expo2f;