Open damianmoz opened 6 months ago
Looking back on #24464, I noticed that the square root function for a const real(w), the low level intrinsic is not called directly from AutoMath.chpl
, but rather the libm
routines (which are not macros). Would not calling the intrinsic directly from Chapel make the code simpler? Just curious.
@damianmoz - not sure what you mean? It looks to me like proc sqrt
called on a real(64)
variable/const will run this one, which runs the primitive, and eventually code-generates an the LLVM IR intrinsic:
One can argue that some of these operations that today interface to the C library should be written in Chapel directly. With the massive improvements in the Chapel compiler since the days when such operations really needed interface to the C library for various reasons, it makes a lot of sense. Crafting these routines in Chapel simplifies their implementation. This issue is related to #24464 although that focused on optimization. It is not inferred that these routines being in Chapel will be any faster (although they should not have a performance penalty either).
The coercion operation of two numbers to a complex(w) number is one such example. This could be written as
One could also write this non-generically.
For this case, and this case alone I believe, one still needs its C equivalent seen in
runtime/intrinsics/chpltypes.h
because they are referenced bycg-symbol.cpp
. Somebody way smarter than I might be able to avoid that reference.The conjugate and phase of a complex(w) number are further examples.
A further example is the more complicated (but computationally trivial) projection of a complex(w) onto the extended complex plane that is modelled by a Riemann Sphere. This particular functionality could not have been done properly in the past using Chapel because it needs the (only recently) introduced
transmute
method on floating point numbers.There may be better ways to write these routines in Chapel. Also, I have no idea why these existing C interfaces for these routines use pragmas and maybe something similar is needed (although I cannot think why).
I am very naughty. To make the above as readable as possible to new users of Chapel or those migrating to Chapel, one should really pass single complex(w) arguments as
z
because that is how they appear in most mathematics texts.The preceding is meant to be neither perfect nor prescriptive. Hopefully I did not make any typos and do not need edits!