Skip to content

Commit 482bc80

Browse files
authored
Disable some SIMD tests when running under Rosetta2 (#2200)
* Disable some SIMD tests when running under Rosetta2. * Fix build on non-macOS boxes. * Revert previous commit - a module cannot appear in several `modules` stanza. * Fix build on non-macOS boxes. * Fix target list. * Put helpers in a library.
1 parent c66c6c1 commit 482bc80

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

tests/simd/dune

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
; Helpers
2+
3+
(library
4+
(name simd_test_helpers)
5+
(wrapped false)
6+
(modules test_helpers))
7+
18
; Stubs
29

310
(foreign_library
@@ -12,6 +19,7 @@
1219
(executables
1320
(names basic ops arrays scalar_ops)
1421
(modules basic ops arrays scalar_ops)
22+
(libraries simd_test_helpers)
1523
(foreign_archives stubs)
1624
(ocamlopt_flags
1725
(:standard -extension simd)))
@@ -118,6 +126,7 @@
118126
consts_internal
119127
arrays_internal
120128
scalar_ops_internal)
129+
(libraries simd_test_helpers)
121130
(enabled_if
122131
(<> %{system} macosx))
123132
(foreign_archives stubs)

tests/simd/ops.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ module Float32x4 = struct
833833
[@@noalloc] [@@unboxed] [@@builtin]
834834

835835
let () =
836+
Test_helpers.run_if_not_under_rosetta2 ~f:(fun () ->
836837
Float32.check_floats (fun f0 f1 ->
837838
failmsg := (fun () -> Printf.printf "%f | %f\n%!" (Int32.float_of_bits f0) (Int32.float_of_bits f1));
838839
let fv0 = Float32.to_float32x4 f0 f0 f1 f1 in
@@ -860,6 +861,7 @@ module Float32x4 = struct
860861
eq (float32x4_low_int64 result) (float32x4_high_int64 result)
861862
(float32x4_low_int64 expect) (float32x4_high_int64 expect)
862863
);
864+
)
863865
;;
864866

865867
external dp : (int [@untagged]) -> (t [@unboxed]) -> (t [@unboxed]) -> (t [@unboxed]) = "caml_vec128_unreachable" "caml_sse41_float32x4_dp"
@@ -1036,6 +1038,7 @@ module Float64x2 = struct
10361038
[@@noalloc] [@@unboxed] [@@builtin]
10371039

10381040
let () =
1041+
Test_helpers.run_if_not_under_rosetta2 ~f:(fun () ->
10391042
Float64.check_floats (fun f0 f1 ->
10401043
failmsg := (fun () -> Printf.printf "%f | %f\n%!" f0 f1);
10411044
let fv0 = to_float64x2 f0 f0 in
@@ -1063,6 +1066,7 @@ module Float64x2 = struct
10631066
eq (float64x2_low_int64 result) (float64x2_high_int64 result)
10641067
(float64x2_low_int64 expect) (float64x2_high_int64 expect)
10651068
);
1069+
)
10661070
;;
10671071

10681072
external dp : (int [@untagged]) -> (t [@unboxed]) -> (t [@unboxed]) -> (t [@unboxed]) = "caml_vec128_unreachable" "caml_sse41_float64x2_dp"

tests/simd/scalar_ops.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ module Int64 = struct
4444
[@@noalloc] [@@unboxed] [@@builtin]
4545

4646
let () =
47-
eq' (bit_deposit 3L 4L) 0x4L;
48-
eq' (bit_deposit 235L 522L) 0xAL;
49-
eq' (bit_extract 3L 4L) 0x0L;
50-
eq' (bit_extract 235L 522L) 0x3L
47+
Test_helpers.run_if_not_under_rosetta2 ~f:(fun () ->
48+
eq' (bit_deposit 3L 4L) 0x4L;
49+
eq' (bit_deposit 235L 522L) 0xAL;
50+
eq' (bit_extract 3L 4L) 0x0L;
51+
eq' (bit_extract 235L 522L) 0x3L)
5152
;;
5253
end

tests/simd/test_helpers.ml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
type rosetta2_status =
2+
| Unknown
3+
| Off
4+
| On
5+
6+
let get_rosetta2_status () =
7+
let file_path = Filename.temp_file "ocaml-rosetta2" "sysctl" in
8+
let command = Printf.sprintf "/usr/sbin/sysctl -n sysctl.proc_translated > %S 2> /dev/null" file_path in
9+
let exit_code = Sys.command command in
10+
match exit_code with
11+
| 0 ->
12+
begin try
13+
let file_chan = open_in file_path in
14+
let first_line = input_line file_chan in
15+
match first_line with
16+
| "0" -> Off
17+
| "1" -> On
18+
| _ -> Unknown
19+
with _ ->
20+
Unknown
21+
end
22+
| _ ->
23+
Unknown
24+
25+
let run_if_not_under_rosetta2 ~f =
26+
match get_rosetta2_status () with
27+
| Unknown | On -> ()
28+
| Off -> f ()

tests/simd/test_helpers.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type rosetta2_status =
2+
| Unknown
3+
| Off
4+
| On
5+
6+
val get_rosetta2_status : unit -> rosetta2_status
7+
8+
val run_if_not_under_rosetta2 : f:(unit -> unit) -> unit

0 commit comments

Comments
 (0)