Skip to content

Commit b5e33e5

Browse files
authored
Add inline annotations to core Wasm API (#1686)
* add #[inline] annotations to all core wasm API * put #[inline] annotations to load/store API Benchmarks show 2-3% performance increase on the tiny_keccak case.
1 parent 4faffa9 commit b5e33e5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/core/src/wasm.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ macro_rules! impl_untyped_val {
2727
/// # Errors
2828
///
2929
$( #[$attr] )*
30+
#[inline]
3031
pub fn $name(value: $ty) -> Result<$ret_ty, TrapCode> {
3132
($f)(value)
3233
}
@@ -37,6 +38,7 @@ macro_rules! impl_untyped_val {
3738
fn $name:ident(value: $ty:ty) -> $ret_ty:ty = $f:expr; $($tt:tt)*
3839
) => {
3940
#[doc = concat!("Execute the `", stringify!($name), "` Wasm instruction.")]
41+
#[inline]
4042
pub fn $name(value: $ty) -> $ret_ty {
4143
($f)(value)
4244
}
@@ -52,6 +54,7 @@ macro_rules! impl_untyped_val {
5254
/// # Errors
5355
///
5456
$( #[$attr] )*
57+
#[inline]
5558
pub fn $name(lhs: $lhs_ty, rhs: $rhs_ty) -> Result<$ret_ty, TrapCode> {
5659
($f)(lhs, rhs)
5760
}
@@ -62,6 +65,7 @@ macro_rules! impl_untyped_val {
6265
fn $name:ident(lhs: $lhs_ty:ty, rhs: $rhs_ty:ty) -> $ret_ty:ty = $f:expr; $($tt:tt)*
6366
) => {
6467
#[doc = concat!("Execute the `", stringify!($name), "` Wasm instruction.")]
68+
#[inline]
6569
pub fn $name(lhs: $lhs_ty, rhs: $rhs_ty) -> $ret_ty {
6670
($f)(lhs, rhs)
6771
}
@@ -312,6 +316,7 @@ macro_rules! gen_load_extend_fn {
312316
///
313317
/// - If `ptr + offset` overflows.
314318
/// - If `ptr + offset` loads out of bounds from `memory`.
319+
#[inline]
315320
pub fn $load_fn(memory: &[u8], ptr: u64, offset: u64) -> Result<$ty, TrapCode> {
316321
memory::load_extend::<$ty, $wrapped>(memory, ptr, offset)
317322
}
@@ -321,6 +326,7 @@ macro_rules! gen_load_extend_fn {
321326
/// # Errors
322327
///
323328
/// If `address` loads out of bounds from `memory`.
329+
#[inline]
324330
pub fn $load_at_fn(memory: &[u8], address: usize) -> Result<$ty, TrapCode> {
325331
memory::load_extend_at::<$ty, $wrapped>(memory, address)
326332
}
@@ -351,6 +357,7 @@ macro_rules! gen_load_fn {
351357
///
352358
/// - If `ptr + offset` overflows.
353359
/// - If `ptr + offset` loads out of bounds from `memory`.
360+
#[inline]
354361
pub fn $load_fn(memory: &[u8], ptr: u64, offset: u64) -> Result<$ty, TrapCode> {
355362
memory::load::<$ty>(memory, ptr, offset)
356363
}
@@ -360,6 +367,7 @@ macro_rules! gen_load_fn {
360367
/// # Errors
361368
///
362369
/// If `address` loads out of bounds from `memory`.
370+
#[inline]
363371
pub fn $load_at_fn(memory: &[u8], address: usize) -> Result<$ty, TrapCode> {
364372
memory::load_at::<$ty>(memory, address)
365373
}
@@ -382,6 +390,7 @@ macro_rules! gen_store_wrap_fn {
382390
///
383391
/// - If `ptr + offset` overflows.
384392
/// - If `ptr + offset` stores out of bounds from `memory`.
393+
#[inline]
385394
pub fn $store_fn(memory: &mut [u8], ptr: u64, offset: u64, value: $ty) -> Result<(), TrapCode> {
386395
memory::store_wrap::<$ty, $wrapped>(memory, ptr, offset, value)
387396
}
@@ -391,6 +400,7 @@ macro_rules! gen_store_wrap_fn {
391400
/// # Errors
392401
///
393402
/// If `address` stores out of bounds from `memory`.
403+
#[inline]
394404
pub fn $store_at_fn(memory: &mut [u8], address: usize, value: $ty) -> Result<(), TrapCode> {
395405
memory::store_wrap_at::<$ty, $wrapped>(memory, address, value)
396406
}
@@ -416,6 +426,7 @@ macro_rules! gen_store_fn {
416426
///
417427
/// - If `ptr + offset` overflows.
418428
/// - If `ptr + offset` stores out of bounds from `memory`.
429+
#[inline]
419430
pub fn $store_fn(memory: &mut [u8], ptr: u64, offset: u64, value: $ty) -> Result<(), TrapCode> {
420431
memory::store::<$ty>(memory, ptr, offset, value)
421432
}
@@ -425,6 +436,7 @@ macro_rules! gen_store_fn {
425436
/// # Errors
426437
///
427438
/// If `address` stores out of bounds from `memory`.
439+
#[inline]
428440
pub fn $store_at_fn(memory: &mut [u8], address: usize, value: $ty) -> Result<(), TrapCode> {
429441
memory::store_at::<$ty>(memory, address, value)
430442
}

0 commit comments

Comments
 (0)