Why is std.math slower than the C baseline?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 4 17:04:54 UTC 2020


On Thu, Jun 04, 2020 at 04:49:38PM +0000, kinke via Digitalmars-d wrote:
> On Thursday, 4 June 2020 at 14:14:22 UTC, Andrei Alexandrescu wrote:
> > D should just use the C functions when they offer better speed.
> 
> They don't, or at least, not always, and can be beaten (e.g., by
> inlinable D implementations). The culprit is Phobos, apparently
> originating from the pre-SSE world and hence mostly focused on reals,
> many times not even offering single and double precision overloads
> (and if offered, many times casting and using the real version).

Yes, std.math seriously needs to offer single/double precision overloads
that do NOT cast to real. This is a significant performance degrader in
compute intensive software, and makes D look antiquated.  Leave the real
overload there for when people are obsessed with the extra precision,
but if the caller passes in a double, please oh please don't just
forward it to the real overload!


[...]
> The latest LDC beta also comes with a significantly improved
> core.math.ldexp, easily beating the C version on my system (inlinable,
> no errno handling...).

Would LDC consider providing float/double overloads for std.math
functions?  Ideally this would be merged upstream, but sometimes if
there's no other way to get things done...


T

-- 
EMACS = Extremely Massive And Cumbersome System


More information about the Digitalmars-d mailing list