Why is std.math slower than the C baseline?

kinke kinke at gmx.net
Thu Jun 4 16:49:38 UTC 2020


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

See 
https://github.com/dlang/phobos/pull/6272#issuecomment-373967109 
for some results with proper Cephes ports to Phobos. I hoped 
others would take care of the rest, but as most of the time, if 
you don't do it yourself...

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


More information about the Digitalmars-d mailing list