@ -453,43 +453,107 @@ where
}
fn visit_f32_floor ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Down , & mut self . context , OperandSize ::S32 ) ;
self . masm . float_round (
RoundingMode ::Down ,
& mut self . env ,
& mut self . context ,
OperandSize ::S32 ,
| env , cx , masm | {
let builtin = env . builtins . floor_f32 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f64_floor ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Down , & mut self . context , OperandSize ::S64 ) ;
self . masm . float_round (
RoundingMode ::Down ,
& mut self . env ,
& mut self . context ,
OperandSize ::S64 ,
| env , cx , masm | {
let builtin = env . builtins . floor_f64 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f32_ceil ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Up , & mut self . context , OperandSize ::S32 ) ;
self . masm . float_round (
RoundingMode ::Up ,
& mut self . env ,
& mut self . context ,
OperandSize ::S32 ,
| env , cx , masm | {
let builtin = env . builtins . ceil_f32 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f64_ceil ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Up , & mut self . context , OperandSize ::S64 ) ;
self . masm . float_round (
RoundingMode ::Up ,
& mut self . env ,
& mut self . context ,
OperandSize ::S64 ,
| env , cx , masm | {
let builtin = env . builtins . ceil_f64 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f32_nearest ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Nearest , & mut self . context , OperandSize ::S32 ) ;
self . masm . float_round (
RoundingMode ::Nearest ,
& mut self . env ,
& mut self . context ,
OperandSize ::S32 ,
| env , cx , masm | {
let builtin = env . builtins . nearest_f32 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) )
} ,
) ;
}
fn visit_f64_nearest ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Nearest , & mut self . context , OperandSize ::S64 ) ;
self . masm . float_round (
RoundingMode ::Nearest ,
& mut self . env ,
& mut self . context ,
OperandSize ::S64 ,
| env , cx , masm | {
let builtin = env . builtins . nearest_f64 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f32_trunc ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Zero , & mut self . context , OperandSize ::S32 ) ;
self . masm . float_round (
RoundingMode ::Zero ,
& mut self . env ,
& mut self . context ,
OperandSize ::S32 ,
| env , cx , masm | {
let builtin = env . builtins . trunc_f32 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f64_trunc ( & mut self ) {
self . masm
. float_round ( RoundingMode ::Zero , & mut self . context , OperandSize ::S64 ) ;
self . masm . float_round (
RoundingMode ::Zero ,
& mut self . env ,
& mut self . context ,
OperandSize ::S64 ,
| env , cx , masm | {
let builtin = env . builtins . trunc_f64 ::< M ::ABI > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( masm , cx , Callee ::Builtin ( builtin ) ) ;
} ,
) ;
}
fn visit_f32_sqrt ( & mut self ) {
@ -1291,8 +1355,12 @@ where
}
fn visit_call ( & mut self , index : u32 ) {
let callee = self . env . callee_from_index ( FuncIndex ::from_u32 ( index ) ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | _ | callee . clone ( ) ) ;
FnCall ::emit ::< M , M ::Ptr > (
self . masm ,
& mut self . context ,
self . env
. callee_from_index ::< M ::ABI > ( FuncIndex ::from_u32 ( index ) ) ,
)
}
fn visit_call_indirect ( & mut self , type_index : u32 , table_index : u32 , _ : u8 ) {
@ -1321,9 +1389,11 @@ where
}
}
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | _ | {
self . env . funcref ( type_index )
} )
FnCall ::emit ::< M , M ::Ptr > (
self . masm ,
& mut self . context ,
self . env . funcref ::< M ::ABI > ( type_index ) ,
)
}
fn visit_table_init ( & mut self , elem : u32 , table : u32 ) {
@ -1335,15 +1405,19 @@ where
self . context . stack . insert_many (
at ,
[
& [
vmctx . into ( ) ,
table . try_into ( ) . unwrap ( ) ,
elem . try_into ( ) . unwrap ( ) ,
] ,
) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | cx | {
Callee ::Builtin ( cx . builtins . table_init ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . table_init ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > (
self . masm ,
& mut self . context ,
Callee ::Builtin ( builtin . clone ( ) ) ,
)
}
fn visit_table_copy ( & mut self , dst : u32 , src : u32 ) {
@ -1353,16 +1427,15 @@ where
let at = self . context . stack . len ( ) - 3 ;
self . context . stack . insert_many (
at ,
[
& [
vmctx . into ( ) ,
dst . try_into ( ) . unwrap ( ) ,
src . try_into ( ) . unwrap ( ) ,
] ,
) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | context | {
Callee ::Builtin ( context . builtins . table_copy ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . table_copy ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( builtin ) )
}
fn visit_table_get ( & mut self , table : u32 ) {
@ -1385,10 +1458,7 @@ where
let table_index = TableIndex ::from_u32 ( table ) ;
let table_plan = self . env . table_plan ( table_index ) ;
let builtin = match table_plan . table . wasm_ty . heap_type {
WasmHeapType ::Func = > self
. context
. builtins
. table_grow_func_ref ::< M ::ABI , M ::Ptr > ( ) ,
WasmHeapType ::Func = > self . env . builtins . table_grow_func_ref ::< M ::ABI , M ::Ptr > ( ) ,
ty = > unimplemented ! ( "Support for HeapType: {ty}" ) ,
} ;
@ -1406,11 +1476,13 @@ where
self . context . stack . inner_mut ( ) . swap ( len - 1 , len - 2 ) ;
self . context
. stack
. insert_many ( at , [ vmctx . into ( ) , table . try_into ( ) . unwrap ( ) ] ) ;
. insert_many ( at , & [ vmctx . into ( ) , table . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | _ | {
Callee ::Builtin ( builtin . clone ( ) )
} ) ;
FnCall ::emit ::< M , M ::Ptr > (
self . masm ,
& mut self . context ,
Callee ::Builtin ( builtin . clone ( ) ) ,
)
}
fn visit_table_size ( & mut self , table : u32 ) {
@ -1425,10 +1497,7 @@ where
let table_index = TableIndex ::from_u32 ( table ) ;
let table_plan = self . env . table_plan ( table_index ) ;
let builtin = match table_plan . table . wasm_ty . heap_type {
WasmHeapType ::Func = > self
. context
. builtins
. table_fill_func_ref ::< M ::ABI , M ::Ptr > ( ) ,
WasmHeapType ::Func = > self . env . builtins . table_fill_func_ref ::< M ::ABI , M ::Ptr > ( ) ,
ty = > unimplemented ! ( "Support for heap type: {ty}" ) ,
} ;
@ -1437,10 +1506,12 @@ where
let at = len - 3 ;
self . context
. stack
. insert_many ( at , [ vmctx . into ( ) , table . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | _ | {
Callee ::Builtin ( builtin . clone ( ) )
} )
. insert_many ( at , & [ vmctx . into ( ) , table . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr > (
self . masm ,
& mut self . context ,
Callee ::Builtin ( builtin . clone ( ) ) ,
)
}
fn visit_table_set ( & mut self , table : u32 ) {
@ -1482,14 +1553,12 @@ where
fn visit_elem_drop ( & mut self , index : u32 ) {
let ptr_type = self . env . ptr_type ( ) ;
let elem_drop = self . context . builtins . elem_drop ::< M ::ABI , M ::Ptr > ( ) ;
let elem_drop = self . env . builtins . elem_drop ::< M ::ABI , M ::Ptr > ( ) ;
let vmctx = TypedReg ::new ( ptr_type , < M ::ABI as ABI > ::vmctx_reg ( ) ) ;
self . context
. stack
. extend ( [ vmctx . into ( ) , index . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | _ | {
Callee ::Builtin ( elem_drop . clone ( ) )
} ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( elem_drop ) )
}
fn visit_memory_init ( & mut self , data_index : u32 , mem : u32 ) {
@ -1499,15 +1568,14 @@ where
let vmctx = TypedReg ::new ( ptr_type , < M ::ABI as ABI > ::vmctx_reg ( ) ) ;
self . context . stack . insert_many (
at ,
[
& [
vmctx . into ( ) ,
mem . try_into ( ) . unwrap ( ) ,
data_index . try_into ( ) . unwrap ( ) ,
] ,
) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | cx | {
Callee ::Builtin ( cx . builtins . memory_init ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . memory_init ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( builtin ) )
}
fn visit_memory_copy ( & mut self , dst_mem : u32 , src_mem : u32 ) {
@ -1522,17 +1590,17 @@ where
let at = self . context . stack . len ( ) - 2 ;
self . context
. stack
. insert_many ( at , [ src_mem . try_into ( ) . unwrap ( ) ] ) ;
. insert_many ( at , & [ src_mem . try_into ( ) . unwrap ( ) ] ) ;
// One element was inserted above, so instead of 3, we use 4.
let at = self . context . stack . len ( ) - 4 ;
self . context
. stack
. insert_many ( at , [ vmctx . into ( ) , dst_mem . try_into ( ) . unwrap ( ) ] ) ;
. insert_many ( at , & [ vmctx . into ( ) , dst_mem . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | cx | {
Callee ::Builtin ( cx . builtins . memory_copy ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . memory_copy ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( builtin ) )
}
fn visit_memory_fill ( & mut self , mem : u32 ) {
@ -1543,11 +1611,10 @@ where
self . context
. stack
. insert_many ( at , [ vmctx . into ( ) , mem . try_into ( ) . unwrap ( ) ] ) ;
. insert_many ( at , & [ vmctx . into ( ) , mem . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | cx | {
Callee ::Builtin ( cx . builtins . memory_fill ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . memory_fill ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( builtin ) )
}
fn visit_memory_size ( & mut self , mem : u32 , _ : u8 ) {
@ -1563,12 +1630,11 @@ where
// The stack at this point contains: [ delta ]
// The desired state is
// [ vmctx, delta, index ]
self . context . stack . insert_many ( at , [ vmctx . into ( ) ] ) ;
self . context . stack . insert_many ( at , & [ vmctx . into ( ) ] ) ;
self . context . stack . extend ( [ mem . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | cx | {
Callee ::Builtin ( cx . builtins . memory32_grow ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . memory32_grow ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( builtin ) )
}
fn visit_data_drop ( & mut self , data_index : u32 ) {
@ -1578,9 +1644,8 @@ where
. stack
. extend ( [ vmctx . into ( ) , data_index . try_into ( ) . unwrap ( ) ] ) ;
FnCall ::emit ::< M , M ::Ptr , _ > ( self . masm , & mut self . context , | cx | {
Callee ::Builtin ( cx . builtins . data_drop ::< M ::ABI , M ::Ptr > ( ) )
} ) ;
let builtin = self . env . builtins . data_drop ::< M ::ABI , M ::Ptr > ( ) ;
FnCall ::emit ::< M , M ::Ptr > ( self . masm , & mut self . context , Callee ::Builtin ( builtin ) )
}
fn visit_nop ( & mut self ) { }