Skip to content

Commit 71a3f1a

Browse files
committed
compiler: expand SIMD op contract tests and gate in CI
1 parent e7118f6 commit 71a3f1a

2 files changed

Lines changed: 68 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ jobs:
102102
RUST_MIN_STACK=134217728 cargo test -p zynml --test e2e_tests execution::test_execute_implicit_numeric_casts_in_assignments -- --nocapture
103103
RUST_MIN_STACK=134217728 cargo test -p zynml --test e2e_tests execution::test_execute_implicit_numeric_casts_in_call_args -- --nocapture
104104
105+
simd-contract:
106+
name: SIMD contract (Cranelift)
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v4
111+
112+
- name: Setup Rust toolchain
113+
uses: dtolnay/rust-toolchain@stable
114+
115+
- name: Cache cargo artifacts
116+
uses: Swatinem/rust-cache@v2
117+
118+
- name: Run Cranelift SIMD vector contract tests
119+
run: cargo test -p zyntax_compiler --test cranelift_backend_tests vector_ -- --nocapture
120+
105121
runtime-smoke:
106122
name: runtime smoke
107123
runs-on: ubuntu-latest

crates/compiler/tests/cranelift_backend_tests.rs

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,41 +209,65 @@ fn test_arithmetic_operations() {
209209
/// Test SIMD vector arithmetic compilation (integer lanes)
210210
#[test]
211211
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");
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]
221227
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");
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]
231243
fn 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]
241259
fn 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.
510542
fn create_float_arithmetic_function(name: &str, op: BinaryOp, ty: HirType) -> HirFunction {
511543
let name = create_test_string(name);

0 commit comments

Comments
 (0)