@@ -209,41 +209,65 @@ fn test_arithmetic_operations() {
209209/// Test SIMD vector arithmetic compilation (integer lanes)
210210#[ test]
211211fn 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" ) ;
212+ assert_vector_binary_compiles ( "vec_i32x4_add" , BinaryOp :: Add , HirType :: I32 , 4 ) ;
213+ }
214+
215+ #[ test]
216+ fn test_vector_i32x4_sub_compilation ( ) {
217+ assert_vector_binary_compiles ( "vec_i32x4_sub" , BinaryOp :: Sub , HirType :: I32 , 4 ) ;
218+ }
219+
220+ #[ test]
221+ fn test_vector_i32x4_mul_compilation ( ) {
222+ assert_vector_binary_compiles ( "vec_i32x4_mul" , BinaryOp :: Mul , HirType :: I32 , 4 ) ;
217223}
218224
219225/// Test SIMD vector arithmetic compilation (floating lanes)
220226#[ test]
221227fn 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" ) ;
228+ assert_vector_binary_compiles ( "vec_f32x4_add" , BinaryOp :: FAdd , HirType :: F32 , 4 ) ;
229+ }
230+
231+ #[ test]
232+ fn test_vector_f32x4_sub_compilation ( ) {
233+ assert_vector_binary_compiles ( "vec_f32x4_sub" , BinaryOp :: FSub , HirType :: F32 , 4 ) ;
234+ }
235+
236+ #[ test]
237+ fn test_vector_f32x4_mul_compilation ( ) {
238+ assert_vector_binary_compiles ( "vec_f32x4_mul" , BinaryOp :: FMul , HirType :: F32 , 4 ) ;
227239}
228240
229241/// Test SIMD vector arithmetic compilation (f64x2 lanes)
230242#[ test]
231243fn test_vector_f64x2_add_compilation ( ) {
232- let mut backend = CraneliftBackend :: new ( ) . expect ( "Failed to create backend" ) ;
233- let func = create_vector_arithmetic_function ( "vec_f64x2_add" , BinaryOp :: FAdd , HirType :: F64 , 2 ) ;
234- backend
235- . compile_function ( func. id , & func)
236- . expect ( "Failed to compile f64x2 add function" ) ;
244+ assert_vector_binary_compiles ( "vec_f64x2_add" , BinaryOp :: FAdd , HirType :: F64 , 2 ) ;
245+ }
246+
247+ #[ test]
248+ fn test_vector_f64x2_sub_compilation ( ) {
249+ assert_vector_binary_compiles ( "vec_f64x2_sub" , BinaryOp :: FSub , HirType :: F64 , 2 ) ;
250+ }
251+
252+ #[ test]
253+ fn test_vector_f64x2_mul_compilation ( ) {
254+ assert_vector_binary_compiles ( "vec_f64x2_mul" , BinaryOp :: FMul , HirType :: F64 , 2 ) ;
237255}
238256
239257/// Test SIMD vector arithmetic compilation (i64x2 lanes)
240258#[ test]
241259fn test_vector_i64x2_add_compilation ( ) {
242- let mut backend = CraneliftBackend :: new ( ) . expect ( "Failed to create backend" ) ;
243- let func = create_vector_arithmetic_function ( "vec_i64x2_add" , BinaryOp :: Add , HirType :: I64 , 2 ) ;
244- backend
245- . compile_function ( func. id , & func)
246- . expect ( "Failed to compile i64x2 add function" ) ;
260+ assert_vector_binary_compiles ( "vec_i64x2_add" , BinaryOp :: Add , HirType :: I64 , 2 ) ;
261+ }
262+
263+ #[ test]
264+ fn test_vector_i64x2_sub_compilation ( ) {
265+ assert_vector_binary_compiles ( "vec_i64x2_sub" , BinaryOp :: Sub , HirType :: I64 , 2 ) ;
266+ }
267+
268+ #[ test]
269+ fn test_vector_i64x2_mul_compilation ( ) {
270+ assert_vector_binary_compiles ( "vec_i64x2_mul" , BinaryOp :: Mul , HirType :: I64 , 2 ) ;
247271}
248272
249273/// Unsupported vector lane shapes should fail with a clear diagnostic.
@@ -506,6 +530,14 @@ fn create_vector_arithmetic_function(
506530 func
507531}
508532
533+ fn assert_vector_binary_compiles ( name : & str , op : BinaryOp , elem_ty : HirType , lanes : u32 ) {
534+ let mut backend = CraneliftBackend :: new ( ) . expect ( "Failed to create backend" ) ;
535+ let func = create_vector_arithmetic_function ( name, op, elem_ty, lanes) ;
536+ backend
537+ . compile_function ( func. id , & func)
538+ . expect ( "Failed to compile vector binary function" ) ;
539+ }
540+
509541/// Helper function to create scalar float arithmetic operations.
510542fn create_float_arithmetic_function ( name : & str , op : BinaryOp , ty : HirType ) -> HirFunction {
511543 let name = create_test_string ( name) ;
0 commit comments