mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-14 22:55:40 +00:00
Refactored math intrinsics into its own module
This commit is contained in:
parent
4e23cd4bab
commit
5c0e404d96
@ -23,6 +23,7 @@ use super::memory::LinearMemory;
|
|||||||
use super::module::Export;
|
use super::module::Export;
|
||||||
use super::module::Module;
|
use super::module::Module;
|
||||||
use super::relocation::{Reloc, RelocSink, RelocationType};
|
use super::relocation::{Reloc, RelocSink, RelocationType};
|
||||||
|
use super::math_intrinsics;
|
||||||
|
|
||||||
pub fn protect_codebuf(code_buf: &Vec<u8>) -> Result<(), String> {
|
pub fn protect_codebuf(code_buf: &Vec<u8>) -> Result<(), String> {
|
||||||
match unsafe {
|
match unsafe {
|
||||||
@ -246,28 +247,28 @@ impl Instance {
|
|||||||
grow_memory as isize
|
grow_memory as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::CeilF32) => {
|
RelocationType::LibCall(LibCall::CeilF32) => {
|
||||||
_ceilf32 as isize
|
math_intrinsics::ceilf32 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::FloorF32) => {
|
RelocationType::LibCall(LibCall::FloorF32) => {
|
||||||
_floorf32 as isize
|
math_intrinsics::floorf32 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::TruncF32) => {
|
RelocationType::LibCall(LibCall::TruncF32) => {
|
||||||
_truncf32 as isize
|
math_intrinsics::truncf32 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::NearestF32) => {
|
RelocationType::LibCall(LibCall::NearestF32) => {
|
||||||
_nearbyintf32 as isize
|
math_intrinsics::nearbyintf32 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::CeilF64) => {
|
RelocationType::LibCall(LibCall::CeilF64) => {
|
||||||
_ceilf64 as isize
|
math_intrinsics::ceilf64 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::FloorF64) => {
|
RelocationType::LibCall(LibCall::FloorF64) => {
|
||||||
_floorf64 as isize
|
math_intrinsics::floorf64 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::TruncF64) => {
|
RelocationType::LibCall(LibCall::TruncF64) => {
|
||||||
_truncf64 as isize
|
math_intrinsics::truncf64 as isize
|
||||||
},
|
},
|
||||||
RelocationType::LibCall(LibCall::NearestF64) => {
|
RelocationType::LibCall(LibCall::NearestF64) => {
|
||||||
_nearbyintf64 as isize
|
math_intrinsics::nearbyintf64 as isize
|
||||||
},
|
},
|
||||||
_ => unimplemented!()
|
_ => unimplemented!()
|
||||||
// RelocationType::Intrinsic(name) => {
|
// RelocationType::Intrinsic(name) => {
|
||||||
@ -624,60 +625,3 @@ extern "C" fn current_memory(memory_index: u32, instance: &mut Instance) -> u32
|
|||||||
let memory = &instance.memories[memory_index as usize];
|
let memory = &instance.memories[memory_index as usize];
|
||||||
memory.current_size() as u32
|
memory.current_size() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because of this bug https://github.com/rust-lang/rust/issues/34123
|
|
||||||
// We create internal functions for it
|
|
||||||
|
|
||||||
// use std::intrinsics::{
|
|
||||||
// ceilf32, ceilf64, floorf32, floorf64, nearbyintf32, nearbyintf64, truncf32, truncf64,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// F32
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _ceilf32(x: f32) -> f32 {
|
|
||||||
// ceilf32(x)
|
|
||||||
x.ceil()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _floorf32(x: f32) -> f32 {
|
|
||||||
// floorf32(x)
|
|
||||||
x.floor()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _truncf32(x: f32) -> f32 {
|
|
||||||
// truncf32(x)
|
|
||||||
x.trunc()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _nearbyintf32(x: f32) -> f32 {
|
|
||||||
// nearbyintf32(x)
|
|
||||||
x.round()
|
|
||||||
}
|
|
||||||
|
|
||||||
// F64
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _ceilf64(x: f64) -> f64 {
|
|
||||||
// ceilf64(x)
|
|
||||||
x.ceil()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _floorf64(x: f64) -> f64 {
|
|
||||||
// floorf64(x)
|
|
||||||
x.floor()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _truncf64(x: f64) -> f64 {
|
|
||||||
// truncf64(x)
|
|
||||||
x.trunc()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
extern "C" fn _nearbyintf64(x: f64) -> f64 {
|
|
||||||
// nearbyintf64(x)
|
|
||||||
x.round()
|
|
||||||
}
|
|
||||||
|
41
src/webassembly/math_intrinsics.rs
Normal file
41
src/webassembly/math_intrinsics.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// F32
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn ceilf32(x: f32) -> f32 {
|
||||||
|
x.ceil()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn floorf32(x: f32) -> f32 {
|
||||||
|
x.floor()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn truncf32(x: f32) -> f32 {
|
||||||
|
x.trunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn nearbyintf32(x: f32) -> f32 {
|
||||||
|
x.round()
|
||||||
|
}
|
||||||
|
|
||||||
|
// F64
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn ceilf64(x: f64) -> f64 {
|
||||||
|
x.ceil()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn floorf64(x: f64) -> f64 {
|
||||||
|
x.floor()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn truncf64(x: f64) -> f64 {
|
||||||
|
x.trunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub extern "C" fn nearbyintf64(x: f64) -> f64 {
|
||||||
|
x.round()
|
||||||
|
}
|
@ -5,6 +5,7 @@ pub mod memory;
|
|||||||
pub mod module;
|
pub mod module;
|
||||||
pub mod relocation;
|
pub mod relocation;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
pub mod math_intrinsics;
|
||||||
|
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
Loading…
Reference in New Issue
Block a user