mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-15 18:01:22 +00:00
Fix arithmetic NaN handling in f32.nearest and f64.nearest
This commit is contained in:
@ -26,7 +26,7 @@ pub extern "C" fn nearbyintf32(x: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if x.is_nan() {
|
if x.is_nan() {
|
||||||
x
|
f32::from_bits(x.to_bits() | (1 << 22))
|
||||||
} else {
|
} else {
|
||||||
let k = f32::EPSILON.recip();
|
let k = f32::EPSILON.recip();
|
||||||
let a = x.abs();
|
let a = x.abs();
|
||||||
@ -64,7 +64,7 @@ pub extern "C" fn nearbyintf64(x: f64) -> f64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if x.is_nan() {
|
if x.is_nan() {
|
||||||
x
|
f64::from_bits(x.to_bits() | (1 << 51))
|
||||||
} else {
|
} else {
|
||||||
let k = f64::EPSILON.recip();
|
let k = f64::EPSILON.recip();
|
||||||
let a = x.abs();
|
let a = x.abs();
|
||||||
|
@ -11,51 +11,8 @@ fn main() {
|
|||||||
|
|
||||||
fn create_module_1() -> Box<Instance> {
|
fn create_module_1() -> Box<Instance> {
|
||||||
let module_str = "(module
|
let module_str = "(module
|
||||||
(type (;0;) (func))
|
(import \"spectest\" \"memory\" (memory (;0;) 0))
|
||||||
(type (;1;) (func))
|
(data (;0;) (i32.const 0) \"\"))
|
||||||
(type (;2;) (func (param i64 i64 f64 i64 f64 i64 f32 i32)))
|
|
||||||
(type (;3;) (func (param f64 i64 f64 i64 f64 i64 f32 i32)))
|
|
||||||
(func (;0;) (type 0))
|
|
||||||
(func (;1;) (type 3) (param f64 i64 f64 i64 f64 i64 f32 i32))
|
|
||||||
(func (;2;) (type 0))
|
|
||||||
(func (;3;) (type 3) (param f64 i64 f64 i64 f64 i64 f32 i32))
|
|
||||||
(func (;4;) (type 3) (param f64 i64 f64 i64 f64 i64 f32 i32))
|
|
||||||
(func (;5;) (type 2) (param i64 i64 f64 i64 f64 i64 f32 i32))
|
|
||||||
(func (;6;) (type 2) (param i64 i64 f64 i64 f64 i64 f32 i32))
|
|
||||||
(func (;7;) (type 0)
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f32.const 0x0p+0 (;=0;)
|
|
||||||
i32.const 0
|
|
||||||
i32.const 0
|
|
||||||
call_indirect (type 3)
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f32.const 0x0p+0 (;=0;)
|
|
||||||
i32.const 0
|
|
||||||
i32.const 2
|
|
||||||
call_indirect (type 3)
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f64.const 0x0p+0 (;=0;)
|
|
||||||
i64.const 0
|
|
||||||
f32.const 0x0p+0 (;=0;)
|
|
||||||
i32.const 0
|
|
||||||
i32.const 3
|
|
||||||
call_indirect (type 3))
|
|
||||||
(table (;0;) 7 7 anyfunc)
|
|
||||||
(export \"signature-implicit-reused\" (func 7))
|
|
||||||
(elem (;0;) (i32.const 0) 4 2 1 4 0 5 6))
|
|
||||||
";
|
";
|
||||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||||
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled");
|
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled");
|
||||||
|
@ -179,6 +179,20 @@ impl ImportBacking {
|
|||||||
"imported tables not yet supported"
|
"imported tables not yet supported"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(ImportBacking {
|
||||||
|
functions: import_functions(module, imports)?,
|
||||||
|
memories: vec![].into_boxed_slice(),
|
||||||
|
tables: vec![].into_boxed_slice(),
|
||||||
|
globals: import_globals(module, imports)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn import_memories(module: &Module, imports: &dyn ImportResolver) -> Result<Box<[vm::ImportedMemory]>, String> {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
fn import_functions(module: &Module, imports: &dyn ImportResolver) -> Result<Box<[vm::ImportedFunc]>, String> {
|
||||||
let mut functions = Vec::with_capacity(module.imported_functions.len());
|
let mut functions = Vec::with_capacity(module.imported_functions.len());
|
||||||
for (
|
for (
|
||||||
index,
|
index,
|
||||||
@ -216,7 +230,10 @@ impl ImportBacking {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(functions.into_boxed_slice())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import_globals(module: &Module, imports: &dyn ImportResolver) -> Result<Box<[vm::ImportedGlobal]>, String> {
|
||||||
let mut globals = Vec::with_capacity(module.imported_globals.len());
|
let mut globals = Vec::with_capacity(module.imported_globals.len());
|
||||||
for (
|
for (
|
||||||
_,
|
_,
|
||||||
@ -261,12 +278,5 @@ impl ImportBacking {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(globals.into_boxed_slice())
|
||||||
Ok(ImportBacking {
|
|
||||||
functions: functions.into_boxed_slice(),
|
|
||||||
memories: vec![].into_boxed_slice(),
|
|
||||||
tables: vec![].into_boxed_slice(),
|
|
||||||
globals: globals.into_boxed_slice(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl NaNCheck for f32 {
|
|||||||
impl NaNCheck for f64 {
|
impl NaNCheck for f64 {
|
||||||
/// The MSB of the mantissa must be set for a NaN to be a quiet NaN.
|
/// The MSB of the mantissa must be set for a NaN to be a quiet NaN.
|
||||||
fn is_quiet_nan(&self) -> bool {
|
fn is_quiet_nan(&self) -> bool {
|
||||||
let bit_mask = 0b1 << 51; // Used to check if 51st bit is set, which is MSB of the mantissa
|
let bit_mask = 0b1 << 51; // Used to check if 52st bit is set, which is MSB of the mantissa
|
||||||
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
|
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user