fortrangoingonforty/armfortas / b4eb9d0

Browse files

Test O3 emits vneg/vabs and runtime preserves negate/abs values

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
b4eb9d0d1e254b7ae25b325e298e46ca2ddb67c5
Parents
882b38c
Tree
fa0cb8d

1 changed file

StatusFile+-
A tests/vectorize_unary.rs 70 0
tests/vectorize_unary.rsadded
@@ -0,0 +1,70 @@
1
+use std::collections::BTreeSet;
2
+use std::path::PathBuf;
3
+
4
+use armfortas::driver::OptLevel;
5
+use armfortas::testing::{capture_from_path, CaptureRequest, CapturedStage, Stage};
6
+
7
+fn fixture(name: &str) -> PathBuf {
8
+    let path = PathBuf::from("test_programs").join(name);
9
+    assert!(path.exists(), "missing test fixture {}", path.display());
10
+    path
11
+}
12
+
13
+fn capture_text(request: CaptureRequest, stage: Stage) -> String {
14
+    let result = capture_from_path(&request).expect("capture should succeed");
15
+    match result.get(stage) {
16
+        Some(CapturedStage::Text(text)) => text.clone(),
17
+        Some(CapturedStage::Run(_)) => panic!("expected text stage for {}", stage.as_str()),
18
+        None => panic!("missing requested stage {}", stage.as_str()),
19
+    }
20
+}
21
+
22
+fn capture_run_stdout(request: CaptureRequest) -> String {
23
+    let result = capture_from_path(&request).expect("capture should succeed");
24
+    match result.get(Stage::Run) {
25
+        Some(CapturedStage::Run(run)) => run.stdout.clone(),
26
+        _ => panic!("missing run stage"),
27
+    }
28
+}
29
+
30
+#[test]
31
+fn o3_vectorizes_unary_neg_and_abs_bodies() {
32
+    let source = fixture("do_loop_vectorize_unary.f90");
33
+
34
+    let o3_ir = capture_text(
35
+        CaptureRequest {
36
+            input: source.clone(),
37
+            requested: BTreeSet::from([Stage::OptIr]),
38
+            opt_level: OptLevel::O3,
39
+        },
40
+        Stage::OptIr,
41
+    );
42
+    assert!(
43
+        o3_ir.contains("vneg") && o3_ir.contains("vabs"),
44
+        "expected NeonVectorize to emit both vneg and vabs:\n{}",
45
+        o3_ir
46
+    );
47
+
48
+    // Runtime: see fixture comments for expected values.
49
+    let stdout = capture_run_stdout(CaptureRequest {
50
+        input: source,
51
+        requested: BTreeSet::from([Stage::Run]),
52
+        opt_level: OptLevel::O3,
53
+    });
54
+    let trimmed: Vec<&str> = stdout
55
+        .lines()
56
+        .map(|l| l.trim())
57
+        .filter(|l| !l.is_empty())
58
+        .collect();
59
+    assert_eq!(trimmed.len(), 5, "expected five output lines:\n{}", stdout);
60
+    // n(1) = -b(1) = -(1-16) = 15
61
+    assert!(trimmed[0].starts_with("1.5"), "n(1) should be 15, got {:?}", trimmed[0]);
62
+    // n(32) = -b(32) = -(32-16) = -16
63
+    assert!(trimmed[1].starts_with("-1.6"), "n(32) should be -16, got {:?}", trimmed[1]);
64
+    // a(1) = abs(-15) = 15
65
+    assert!(trimmed[2].starts_with("1.5"), "a(1) should be 15, got {:?}", trimmed[2]);
66
+    // a(16) = abs(0) = 0
67
+    assert!(trimmed[3].starts_with("0.0"), "a(16) should be 0, got {:?}", trimmed[3]);
68
+    // a(32) = abs(16) = 16
69
+    assert!(trimmed[4].starts_with("1.6"), "a(32) should be 16, got {:?}", trimmed[4]);
70
+}