Repository navigation
Add support for unaligned accesses on arm64 - #13807
Conversation
d80ab5c to
11a65b8
Compare
xavierleroy
left a comment
There was a problem hiding this comment.
I ran the "precheck" CI test, which includes two ARM64 configurations (macOS on an M1 and Linux on a rPi 4). Everything works fine, as expected. I'm in favor of merging this PR and see what happens.
As discussed in ocaml#13631, the decision not to support unaligned accesses on arm64 was made before any hardware was available, and in practice all ARMv8 CPUs support unaligned accesses.
11a65b8 to
7ed394b
Compare
|
Force pushed to update Changes, thanks for running the extra tests! |
|
Also in favor of merging, from the discussion cited I expect it will be fine, the caveat regarding atomic accesses on unaligned addresses should not apply to OCaml atomics that are word-aligned anyway. |
|
Well, let's merge then :-) |
@matthewelse Do you have some performance numbers to share on this change? Or a sample application that could be added to |
|
@tmcgilchrist I've been implementing string searching algorithms in OCaml, and as part of that I was experimenting with an implementation of memchr in OCaml -- usual caveats around microbenchmarks, but without this change (unscientific testing, there might be other changes between the two OPAM switches that I've forgotten about) searching through a 10,000 byte bigstring goes from about 2us to about 0.7us with this change |
Resolves #13631
Per the discussion in #13631, it seems like not supporting aligned accesses on arm64 has been unnecessarily conservative. This PR makes the trivial change to flip
allow_unaligned_accesson arm64. As it turns out, this only affects a handful of code-paths in cmm_helpers.ml, but makes a noticeable difference to performance in code that processes bigstrings, amongst other things.Testing:
I've been using this as a local build from time to time on my M2 Mac over the last few months, and I've run the test suite locally. I've also documented the behaviour of other compilers (clang and GCC) in the corresponding issue. I've also manually audited the handful of use-cases of
allow_unaligned_access, and nothing looks suspicious to my untrained eye.