janestreet / ocaml_intrinsics

Provides functions to invoke amd64 instructions (such as clz,popcnt,rdtsc,rdpmc) when available, or compatible software implementation on other targets.
MIT License
30 stars 12 forks source link

MacOS support #4

Closed yallop closed 2 years ago

yallop commented 2 years ago

At the moment some operations in this library crash with SIGTRAP or silently return wrong results on macOS (test, CI output). This means that software built using this library will build and install on macOS systems, but fail catastrophically at run time.

Is it possible to have the library either fixed to work on macOS or marked in the metadata as Linux-only for the first OPAM release?

hackedy commented 2 years ago

Hi, I think this makes the core_unix v0.15 release impossible to install on MacOS. Is there a timeline for a fix or workaround? I think the only use of anything from ocaml_intrinsics over there is in the time stamp counter module: https://github.com/janestreet/core_unix/blob/a051098a918b950e9d0a5da7248f1bbfb51388e5/time_stamp_counter/src/time_stamp_counter.ml#L100

gretay-js commented 2 years ago

Sorry about the delay, I will get it fixed asap. @yallop thank you for the detailed report and repo case! I think there is a bug (missing implementation) in the C stubs int_stubs.c when __GNUC__ is not defined, although it should be defined when building with LLVM.

gretay-js commented 2 years ago

@yallop I've updated your tests with the proposed fix and they pass on the CI.

It took a fairly old mac to reproduce the failures locally for debugging purposes. All tests in this library pass on the old mac, except one floating point input (float_stubscompiles with a warning, so it's expected to have some precision difference and the module is not yet used in base/core).

I would like to re-enable ocaml_intrinsics in opam for macos.

yallop commented 2 years ago

@yallop I've updated your tests with the proposed fix and they pass on the CI.

That's good news. Thank you for fixing this, @gretay-js

barracuda156 commented 12 months ago

@yallop @gretay-js @hackedy Could anyone say what would it take to implement these for macOS on PowerPC? :)

gretay-js commented 11 months ago

@barracuda156 We would need to either find the corresponding instructions / C compiler intrinsics and provide (slower) software implementations for the missing ones. I don't have any way to test such an implementation, do you :)

barracuda156 commented 11 months ago

@gretay-js Testing is not a problem, I got a variety of hardware (including pretty fast G5s), as well as VM set-up with Rosetta.