fortrangoingonforty/armfortas / eb0ce3b

Browse files

Audit ordered i128 branches

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
eb0ce3bb60c3b4b9b5d1db424a21c407a129cbc7
Parents
be91b4c
Tree
66f41ef

2 changed files

StatusFile+-
A tests/fixtures/integer16_ordered_branch.f90 19 0
M tests/i128_memory_backend.rs 65 0
tests/fixtures/integer16_ordered_branch.f90added
@@ -0,0 +1,19 @@
1
+program integer16_ordered_branch
2
+  implicit none
3
+  integer(16) :: x
4
+  integer(16) :: y
5
+  integer(16) :: z
6
+  integer :: score
7
+
8
+  x = -4_16
9
+  y = 3_16
10
+  z = -4_16
11
+  score = 0
12
+
13
+  if (x < y) score = score + 1
14
+  if (x <= z) score = score + 1
15
+  if (y > z) score = score + 1
16
+  if (y >= x) score = score + 1
17
+
18
+  print *, score
19
+end program integer16_ordered_branch
tests/i128_memory_backend.rsmodified
@@ -146,6 +146,71 @@ fn simple_local_i128_eqne_emits_pair_compare_ops_at_o0() {
146146
     );
147147
 }
148148
 
149
+#[test]
150
+fn simple_local_i128_ordered_compares_emit_signed_and_unsigned_limb_checks_at_o0() {
151
+    let asm = capture_text(
152
+        CaptureRequest {
153
+            input: fixture("integer16_ordered_branch.f90"),
154
+            requested: BTreeSet::from([Stage::Asm]),
155
+            opt_level: OptLevel::O0,
156
+        },
157
+        Stage::Asm,
158
+    );
159
+
160
+    assert!(
161
+        asm.contains("cset w10, lt"),
162
+        "backend should use signed high-limb compare for i128 lt/le:\n{}",
163
+        asm
164
+    );
165
+    assert!(
166
+        asm.contains("cset w8, lo"),
167
+        "backend should use unsigned low-limb compare for strict ordered i128 compares:\n{}",
168
+        asm
169
+    );
170
+    assert!(
171
+        asm.contains("cset w8, ls"),
172
+        "backend should use unsigned low-limb <= compare for i128 le:\n{}",
173
+        asm
174
+    );
175
+    assert!(
176
+        asm.contains("cset w10, gt"),
177
+        "backend should use signed high-limb compare for i128 gt/ge:\n{}",
178
+        asm
179
+    );
180
+    assert!(
181
+        asm.contains("cset w8, hi"),
182
+        "backend should use unsigned low-limb > compare for i128 gt:\n{}",
183
+        asm
184
+    );
185
+    assert!(
186
+        asm.contains("cset w8, hs"),
187
+        "backend should use unsigned low-limb >= compare for i128 ge:\n{}",
188
+        asm
189
+    );
190
+}
191
+
192
+#[test]
193
+fn simple_local_i128_ordered_branch_runs_at_o0() {
194
+    let result = capture_from_path(&CaptureRequest {
195
+        input: fixture("integer16_ordered_branch.f90"),
196
+        requested: BTreeSet::from([Stage::Run]),
197
+        opt_level: OptLevel::O0,
198
+    })
199
+    .expect("ordered i128 branch program should run");
200
+
201
+    let run = result
202
+        .get(Stage::Run)
203
+        .and_then(CapturedStage::as_run)
204
+        .expect("missing run capture");
205
+
206
+    assert_eq!(run.exit_code, 0, "expected successful ordered branch run:\n{:#?}", run);
207
+    assert!(
208
+        run.stdout.contains('4'),
209
+        "ordered i128 branch program should print score 4:\n{}",
210
+        run.stdout
211
+    );
212
+}
213
+
149214
 #[test]
150215
 fn simple_local_i128_object_snapshot_is_deterministic_at_o0() {
151216
     let source = fixture("integer16_local_roundtrip.f90");