std.math API rework

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 6 13:07:19 PDT 2016


On 6 October 2016 at 18:53, Ilya Yaroshenko via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> Effective work with std.experimental.ndslice and and mir.ndslice.array
> requires half of std.math be an exactly aliases to LLVM intrinsics (for
> LDC).
>
> To enable vectorization for mir.ndslice.algorithm I created internal math
> module [1] in Mir. But this is weird, because third side packages like DCV
> [2] requires to use the module too. Also, some optimisation for std.complex
> and future std.exprimental.color would be very ugly without proposed change.
>
> Proposed change is very simple:
> Each math function listed in [1] should be a template for DMD/GDC and an
> alias for LDC in std.math.
>
> If some one has strong arguments against it, please let me know now.
>
> [1] https://github.com/libmir/mir/blob/master/source/mir/internal/math.d
> [2] https://github.com/ljubobratovicrelja/dcv
>
> Best regards,
> Ilya

If you can prove that llvm intrinsics are pure (gcc math intrinsics
are not) and that llvm intrinsics pass the unittest (gcc math
intrinsics aren't guaranteed to due to the vagary of libm
implementations and quirky cpu support that trades correctness for
efficiency).

I have a reasonable belief to say that the answer is no on both parts.
Even if some llvm intrinsics lower to native instructions on x86, most
other platforms will just forward it to an impure, mixed bag of long
double support libm.  :-)

If you need it specialized, do it yourself.  Phobos seems more of a
place for generalized application support, from what I gather, and how
I approach it.

Iain.


More information about the Digitalmars-d mailing list