Runtime library math functions
There are several alternatives:
- openlibm (https://github.com/conda-forge/openlibm-feedstock): well maintained, community, used in Julia and elsewhere, should work on all platforms.
- libpgmath (https://github.com/conda-forge/libpgmath-feedstock, #243): used in "current/legacy Flang", has all Fortran functions that we would need. Perhaps not as community maintained, might not work on all platforms.
- Write our own implementation in pure Fortran: would work on all platforms which LFortran supports (and thus with all backends), can be inlined at the ASR level.
Ideally I would like us to support all of them, as well as any user defined runtime math functions. So the question is really more about how it should be interfaced with LFortran.
It seems there are two basic approaches:
-
One idea is to have the upper level interface in Fortran itself, and the default implementation could use
iso_c_binding
to call into, say,openlibm
. Another implementation could implement in pure Fortran, or call intolibpgmath
. LFortran will compile in the upper level interface, just like any other module, and it would know how to link inopenlibm
orlibpgmath
automatically (or nothing for pure Fortran implementation). LFortran ASR optimizations should be able to inline the "wrapper" interface, so it should be as performing as option 2. down the road. It is a little more work upfront, as we have to implementiso_c_binding
. -
Call into the C ABI directly from the LLVM backend. Can be implemented right away, but one must encode all function signatures in LLVM and those signatures might be different for
openlibm
andlibpgmath
, and it would be even harder to use a Fortran implementation.