On Thursday, 6 October 2016 at 20:45:24 UTC, Iain Buclaw wrote:
On 6 October 2016 at 22:31, Ilya Yaroshenko via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
On Thursday, 6 October 2016 at 20:07:19 UTC, Iain Buclaw wrote:

On 6 October 2016 at 18:53, Ilya Yaroshenko via Digitalmars-d <digitalmars-d@puremagic.com> wrote:

[...]


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).

[...]


LLVM math functions are pure :P http://llvm.org/docs/LangRef.html


I picked a random example.

http://llvm.org/docs/LangRef.html#llvm-sin-intrinsic

"""

Semantics:

This function returns the sine of the specified operand, returning the same values as the libm sin functions would, and handles error conditions in the same way.

"""

This would have me believe that they are infact not pure. ;-)

But, I've never looked under the hood of LLVM, so I can only believe those who have. In any case, IMO, you should focus on getting this into core.math. That's where compiler intrinsics should go. The intrinsics of std.math are historical baggage and are probably due a deprecation - that is, in the sense that their symbols be converted into aliases.

Iain.

Current code is (please look in LDC's fork):

version(LDC)
{
real cos(real x) @safe pure nothrow @nogc { return llvm_cos(x); }
    ///ditto
double cos(double x) @safe pure nothrow @nogc { return llvm_cos(x); }
    ///ditto
float cos(float x) @safe pure nothrow @nogc { return llvm_cos(x); }
}
else
{

real cos(real x) @safe pure nothrow @nogc { pragma(inline, true); return core.math.cos(x); }
//FIXME
///ditto
double cos(double x) @safe pure nothrow @nogc { return cos(cast(real)x); }
//FIXME
///ditto
float cos(float x) @safe pure nothrow @nogc { return cos(cast(real)x); }

}

So, I don't see a reason why this change break something, hehe

Reply via email to