Libdivide ported to D
Walter Bright via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Mon May 15 07:37:28 PDT 2017
On 5/15/2017 3:51 AM, Jonathan M Davis via Digitalmars-d-announce wrote:
> Liran was telling me last year about how the folks at Weka had used this to
> speed up the stuff in core.time and std.datetime in their local branch and
> wanted me to look into updating the official implementation to use it
> (unfortunately, I haven't had the time to spend on D that I would have liked
> and haven't managed to look into that yet - though that would require
> putting at least some of this in druntime). I confess though that I was
> highly confused about the whole thing, because it sounded like this was an
> optimization that the compiler already did, and yet the Weka guys were
> having to use libdivide some portion of the time. I suppose that it makes
> sense though if the issue is that the divisor is not known until runtime.
> But unfortunately, my understanding of compiler optimizations like this is
> fairly poor.
One can do things like this:
if (divisor == 10)
foreach (i; 1..1000)
result += i / 10; // compiler generates faster code here
else
foreach (i; 1..1000)
result += i / divisor;
if one knows in advance popular values of divisor. This sort of thing is already
done in Phobos when converting numbers <==> strings (optimizing for radix==10).
More information about the Digitalmars-d-announce
mailing list