On Sunday, May 14, 2017 16:20:21 David Nadlinger via Digitalmars-d-announce wrote: > On Sunday, 14 May 2017 at 15:30:19 UTC, Walter Bright wrote: > > On 5/14/2017 3:39 AM, Tomer Filiba wrote: > >> Of course it only applies to runtime division -- the compiler > >> can do the same if > >> the divisor is known in compile time. > > > > I hate to say this, but modern compilers already do this for > > generated runtime code when dividing by a constant. […] > > As Tomer points out, a runtime implementation can still be useful > if the divisor is only known dynamically (but constant across > number of operations).
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. - Jonathan M Davis
