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

Reply via email to