@ -854,9 +854,10 @@ mod tests {
use cranelift_codegen ::ir ::{
use cranelift_codegen ::ir ::{
AbiParam , ExternalName , Function , InstBuilder , MemFlags , Signature ,
AbiParam , ExternalName , Function , InstBuilder , MemFlags , Signature ,
} ;
} ;
use cranelift_codegen ::isa ::CallConv ;
use cranelift_codegen ::isa ::{ CallConv , TargetFrontendConfig } ;
use cranelift_codegen ::settings ;
use cranelift_codegen ::settings ;
use cranelift_codegen ::verifier ::verify_function ;
use cranelift_codegen ::verifier ::verify_function ;
use target_lexicon ::PointerWidth ;
fn sample_function ( lazy_seal : bool ) {
fn sample_function ( lazy_seal : bool ) {
let mut sig = Signature ::new ( CallConv ::SystemV ) ;
let mut sig = Signature ::new ( CallConv ::SystemV ) ;
@ -968,24 +969,18 @@ mod tests {
sample_function ( true )
sample_function ( true )
}
}
/// Helper function to construct a fixed frontend configuration.
fn systemv_frontend_config ( ) -> TargetFrontendConfig {
TargetFrontendConfig {
default_call_conv : CallConv ::SystemV ,
pointer_width : PointerWidth ::U64 ,
}
}
#[ test ]
#[ test ]
#[ cfg_attr(not(target_arch = " x86_64 " ), ignore) ]
fn memcpy ( ) {
fn memcpy ( ) {
use core ::str ::FromStr ;
let frontend_config = systemv_frontend_config ( ) ;
use cranelift_codegen ::{ isa , settings } ;
let mut sig = Signature ::new ( frontend_config . default_call_conv ) ;
let shared_builder = settings ::builder ( ) ;
let shared_flags = settings ::Flags ::new ( shared_builder ) ;
let triple =
::target_lexicon ::Triple ::from_str ( "x86_64" ) . expect ( "Couldn't create x86_64 triple" ) ;
let target = isa ::lookup ( triple )
. ok ( )
. map ( | b | b . finish ( shared_flags ) )
. expect ( "This test requires x86_64 support." ) ;
let mut sig = Signature ::new ( target . default_call_conv ( ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
@ -997,8 +992,8 @@ mod tests {
let x = Variable ::new ( 0 ) ;
let x = Variable ::new ( 0 ) ;
let y = Variable ::new ( 1 ) ;
let y = Variable ::new ( 1 ) ;
let z = Variable ::new ( 2 ) ;
let z = Variable ::new ( 2 ) ;
builder . declare_var ( x , target . pointer_type ( ) ) ;
builder . declare_var ( x , frontend_config . pointer_type ( ) ) ;
builder . declare_var ( y , target . pointer_type ( ) ) ;
builder . declare_var ( y , frontend_config . pointer_type ( ) ) ;
builder . declare_var ( z , I32 ) ;
builder . declare_var ( z , I32 ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . switch_to_block ( block0 ) ;
builder . switch_to_block ( block0 ) ;
@ -1006,7 +1001,7 @@ mod tests {
let src = builder . use_var ( x ) ;
let src = builder . use_var ( x ) ;
let dest = builder . use_var ( y ) ;
let dest = builder . use_var ( y ) ;
let size = builder . use_var ( y ) ;
let size = builder . use_var ( y ) ;
builder . call_memcpy ( target . frontend_config ( ) , dest , src , size ) ;
builder . call_memcpy ( frontend_config , dest , src , size ) ;
builder . ins ( ) . return_ ( & [ size ] ) ;
builder . ins ( ) . return_ ( & [ size ] ) ;
builder . seal_all_blocks ( ) ;
builder . seal_all_blocks ( ) ;
@ -1032,23 +1027,9 @@ block0:
}
}
#[ test ]
#[ test ]
#[ cfg_attr(not(target_arch = " x86_64 " ), ignore) ]
fn small_memcpy ( ) {
fn small_memcpy ( ) {
use core ::str ::FromStr ;
let frontend_config = systemv_frontend_config ( ) ;
use cranelift_codegen ::{ isa , settings } ;
let mut sig = Signature ::new ( frontend_config . default_call_conv ) ;
let shared_builder = settings ::builder ( ) ;
let shared_flags = settings ::Flags ::new ( shared_builder ) ;
let triple =
::target_lexicon ::Triple ::from_str ( "x86_64" ) . expect ( "Couldn't create x86_64 triple" ) ;
let target = isa ::lookup ( triple )
. ok ( )
. map ( | b | b . finish ( shared_flags ) )
. expect ( "This test requires x86_64 support." ) ;
let mut sig = Signature ::new ( target . default_call_conv ( ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
@ -1059,8 +1040,8 @@ block0:
let block0 = builder . create_block ( ) ;
let block0 = builder . create_block ( ) ;
let x = Variable ::new ( 0 ) ;
let x = Variable ::new ( 0 ) ;
let y = Variable ::new ( 16 ) ;
let y = Variable ::new ( 16 ) ;
builder . declare_var ( x , target . pointer_type ( ) ) ;
builder . declare_var ( x , frontend_config . pointer_type ( ) ) ;
builder . declare_var ( y , target . pointer_type ( ) ) ;
builder . declare_var ( y , frontend_config . pointer_type ( ) ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . switch_to_block ( block0 ) ;
builder . switch_to_block ( block0 ) ;
@ -1068,7 +1049,7 @@ block0:
let dest = builder . use_var ( y ) ;
let dest = builder . use_var ( y ) ;
let size = 8 ;
let size = 8 ;
builder . emit_small_memory_copy (
builder . emit_small_memory_copy (
target . frontend_config ( ) ,
frontend_config ,
dest ,
dest ,
src ,
src ,
size ,
size ,
@ -1100,23 +1081,9 @@ block0:
}
}
#[ test ]
#[ test ]
#[ cfg_attr(not(target_arch = " x86_64 " ), ignore) ]
fn not_so_small_memcpy ( ) {
fn not_so_small_memcpy ( ) {
use core ::str ::FromStr ;
let frontend_config = systemv_frontend_config ( ) ;
use cranelift_codegen ::{ isa , settings } ;
let mut sig = Signature ::new ( frontend_config . default_call_conv ) ;
let shared_builder = settings ::builder ( ) ;
let shared_flags = settings ::Flags ::new ( shared_builder ) ;
let triple =
::target_lexicon ::Triple ::from_str ( "x86_64" ) . expect ( "Couldn't create x86_64 triple" ) ;
let target = isa ::lookup ( triple )
. ok ( )
. map ( | b | b . finish ( shared_flags ) )
. expect ( "This test requires x86_64 support." ) ;
let mut sig = Signature ::new ( target . default_call_conv ( ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
@ -1127,8 +1094,8 @@ block0:
let block0 = builder . create_block ( ) ;
let block0 = builder . create_block ( ) ;
let x = Variable ::new ( 0 ) ;
let x = Variable ::new ( 0 ) ;
let y = Variable ::new ( 16 ) ;
let y = Variable ::new ( 16 ) ;
builder . declare_var ( x , target . pointer_type ( ) ) ;
builder . declare_var ( x , frontend_config . pointer_type ( ) ) ;
builder . declare_var ( y , target . pointer_type ( ) ) ;
builder . declare_var ( y , frontend_config . pointer_type ( ) ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . switch_to_block ( block0 ) ;
builder . switch_to_block ( block0 ) ;
@ -1136,7 +1103,7 @@ block0:
let dest = builder . use_var ( y ) ;
let dest = builder . use_var ( y ) ;
let size = 8192 ;
let size = 8192 ;
builder . emit_small_memory_copy (
builder . emit_small_memory_copy (
target . frontend_config ( ) ,
frontend_config ,
dest ,
dest ,
src ,
src ,
size ,
size ,
@ -1171,23 +1138,9 @@ block0:
}
}
#[ test ]
#[ test ]
#[ cfg_attr(not(target_arch = " x86_64 " ), ignore) ]
fn small_memset ( ) {
fn small_memset ( ) {
use core ::str ::FromStr ;
let frontend_config = systemv_frontend_config ( ) ;
use cranelift_codegen ::{ isa , settings } ;
let mut sig = Signature ::new ( frontend_config . default_call_conv ) ;
let shared_builder = settings ::builder ( ) ;
let shared_flags = settings ::Flags ::new ( shared_builder ) ;
let triple =
::target_lexicon ::Triple ::from_str ( "x86_64" ) . expect ( "Couldn't create x86_64 triple" ) ;
let target = isa ::lookup ( triple )
. ok ( )
. map ( | b | b . finish ( shared_flags ) )
. expect ( "This test requires x86_64 support." ) ;
let mut sig = Signature ::new ( target . default_call_conv ( ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
@ -1197,13 +1150,13 @@ block0:
let block0 = builder . create_block ( ) ;
let block0 = builder . create_block ( ) ;
let y = Variable ::new ( 16 ) ;
let y = Variable ::new ( 16 ) ;
builder . declare_var ( y , target . pointer_type ( ) ) ;
builder . declare_var ( y , frontend_config . pointer_type ( ) ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . switch_to_block ( block0 ) ;
builder . switch_to_block ( block0 ) ;
let dest = builder . use_var ( y ) ;
let dest = builder . use_var ( y ) ;
let size = 8 ;
let size = 8 ;
builder . emit_small_memset ( target . frontend_config ( ) , dest , 1 , size , 8 , MemFlags ::new ( ) ) ;
builder . emit_small_memset ( frontend_config , dest , 1 , size , 8 , MemFlags ::new ( ) ) ;
builder . ins ( ) . return_ ( & [ dest ] ) ;
builder . ins ( ) . return_ ( & [ dest ] ) ;
builder . seal_all_blocks ( ) ;
builder . seal_all_blocks ( ) ;
@ -1225,23 +1178,9 @@ block0:
}
}
#[ test ]
#[ test ]
#[ cfg_attr(not(target_arch = " x86_64 " ), ignore) ]
fn not_so_small_memset ( ) {
fn not_so_small_memset ( ) {
use core ::str ::FromStr ;
let frontend_config = systemv_frontend_config ( ) ;
use cranelift_codegen ::{ isa , settings } ;
let mut sig = Signature ::new ( frontend_config . default_call_conv ) ;
let shared_builder = settings ::builder ( ) ;
let shared_flags = settings ::Flags ::new ( shared_builder ) ;
let triple =
::target_lexicon ::Triple ::from_str ( "x86_64" ) . expect ( "Couldn't create x86_64 triple" ) ;
let target = isa ::lookup ( triple )
. ok ( )
. map ( | b | b . finish ( shared_flags ) )
. expect ( "This test requires x86_64 support." ) ;
let mut sig = Signature ::new ( target . default_call_conv ( ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
sig . returns . push ( AbiParam ::new ( I32 ) ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
let mut fn_ctx = FunctionBuilderContext ::new ( ) ;
@ -1251,13 +1190,13 @@ block0:
let block0 = builder . create_block ( ) ;
let block0 = builder . create_block ( ) ;
let y = Variable ::new ( 16 ) ;
let y = Variable ::new ( 16 ) ;
builder . declare_var ( y , target . pointer_type ( ) ) ;
builder . declare_var ( y , frontend_config . pointer_type ( ) ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . append_block_params_for_function_params ( block0 ) ;
builder . switch_to_block ( block0 ) ;
builder . switch_to_block ( block0 ) ;
let dest = builder . use_var ( y ) ;
let dest = builder . use_var ( y ) ;
let size = 8192 ;
let size = 8192 ;
builder . emit_small_memset ( target . frontend_config ( ) , dest , 1 , size , 8 , MemFlags ::new ( ) ) ;
builder . emit_small_memset ( frontend_config , dest , 1 , size , 8 , MemFlags ::new ( ) ) ;
builder . ins ( ) . return_ ( & [ dest ] ) ;
builder . ins ( ) . return_ ( & [ dest ] ) ;
builder . seal_all_blocks ( ) ;
builder . seal_all_blocks ( ) ;