@@ -206,6 +206,26 @@ fn test_arithmetic_operations() {
206206 . expect ( "Failed to compile division function" ) ;
207207}
208208
209+ /// Test SIMD vector arithmetic compilation (integer lanes)
210+ #[ test]
211+ fn test_vector_i32x4_add_compilation ( ) {
212+ let mut backend = CraneliftBackend :: new ( ) . expect ( "Failed to create backend" ) ;
213+ let func = create_vector_arithmetic_function ( "vec_i32x4_add" , BinaryOp :: Add , HirType :: I32 , 4 ) ;
214+ backend
215+ . compile_function ( func. id , & func)
216+ . expect ( "Failed to compile i32x4 add function" ) ;
217+ }
218+
219+ /// Test SIMD vector arithmetic compilation (floating lanes)
220+ #[ test]
221+ fn test_vector_f32x4_add_compilation ( ) {
222+ let mut backend = CraneliftBackend :: new ( ) . expect ( "Failed to create backend" ) ;
223+ let func = create_vector_arithmetic_function ( "vec_f32x4_add" , BinaryOp :: FAdd , HirType :: F32 , 4 ) ;
224+ backend
225+ . compile_function ( func. id , & func)
226+ . expect ( "Failed to compile f32x4 add function" ) ;
227+ }
228+
209229/// Test comparison operations
210230#[ test]
211231fn test_comparison_operations ( ) {
@@ -359,6 +379,65 @@ fn create_comparison_function(name: &str, op: BinaryOp) -> HirFunction {
359379 func
360380}
361381
382+ /// Helper function to create vector arithmetic operations
383+ fn create_vector_arithmetic_function (
384+ name : & str ,
385+ op : BinaryOp ,
386+ elem_ty : HirType ,
387+ lanes : u32 ,
388+ ) -> HirFunction {
389+ let name = create_test_string ( name) ;
390+ let vec_ty = HirType :: Vector ( Box :: new ( elem_ty) , lanes) ;
391+
392+ let sig = HirFunctionSignature {
393+ params : vec ! [
394+ HirParam {
395+ id: HirId :: new( ) ,
396+ name: create_test_string( "a" ) ,
397+ ty: vec_ty. clone( ) ,
398+ attributes: ParamAttributes :: default ( ) ,
399+ } ,
400+ HirParam {
401+ id: HirId :: new( ) ,
402+ name: create_test_string( "b" ) ,
403+ ty: vec_ty. clone( ) ,
404+ attributes: ParamAttributes :: default ( ) ,
405+ } ,
406+ ] ,
407+ returns : vec ! [ vec_ty. clone( ) ] ,
408+ type_params : vec ! [ ] ,
409+ const_params : vec ! [ ] ,
410+ lifetime_params : vec ! [ ] ,
411+ is_variadic : false ,
412+ is_async : false ,
413+ effects : vec ! [ ] ,
414+ is_pure : false ,
415+ } ;
416+
417+ let mut func = HirFunction :: new ( name, sig) ;
418+
419+ let entry_block_id = func. entry_block ;
420+ let param_a = func. create_value ( vec_ty. clone ( ) , HirValueKind :: Parameter ( 0 ) ) ;
421+ let param_b = func. create_value ( vec_ty. clone ( ) , HirValueKind :: Parameter ( 1 ) ) ;
422+
423+ let result = func. create_value ( vec_ty. clone ( ) , HirValueKind :: Instruction ) ;
424+ let inst = HirInstruction :: Binary {
425+ op,
426+ result,
427+ ty : vec_ty,
428+ left : param_a,
429+ right : param_b,
430+ } ;
431+
432+ let block = func. blocks . get_mut ( & entry_block_id) . unwrap ( ) ;
433+ block. add_instruction ( inst) ;
434+ block. set_terminator ( HirTerminator :: Return {
435+ values : vec ! [ result] ,
436+ } ) ;
437+
438+ func
439+ }
440+
362441/// Create a function with control flow (if-else)
363442fn create_control_flow_function ( ) -> HirFunction {
364443 let name = create_test_string ( "abs" ) ;
0 commit comments