Good project: stride() with constant stride value

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Mar 5 05:15:27 PST 2016


On 03/04/2016 09:50 PM, John Colvin wrote:
> On Friday, 4 March 2016 at 23:33:40 UTC, Andrei Alexandrescu wrote:
>> On 03/04/2016 04:19 PM, H. S. Teoh via Digitalmars-d wrote:
>>> Why not rather improve dmd optimization, so that such manual
>>> optimizations are no longer necessary?
>>
>> As I mentioned, optimizing the use of stride in large (non-inlined)
>> functions is a tall order. -- Andrei
>
> It seems to me that if the stride is available in the calling scope as
> usable for a stride template parameter (i.e. as a compile-time value )
> then it would also be just as available to the optimiser after the
> trivial inlining of stride (note not any arbitrarily complex code that
> contains stride, just stride).
>
> Sure, if you nest it away in un-inlineable constructs then it won't be
> easily optimised, but you wouldn't be able to use it as a template
> parameter then anyway.

Again, this is just speculation, and not very credible. Why push it? Of 
course we could sit all day discussing what a sufficiently smart or 
sufficiently dumb compiler is and is not liable to do. The matter of 
fact is (a) yes, specializing a function for a particular parameter 
value is a known optimization; (b) it is mostly used for virtual methods 
to avoid vcall overheads, and in particular the compiler won't generate 
two separate large-ish functions for two separate parameter values.

> Do you have a concrete example where the optimisation(s) you want to
> occur cannot be done with `stride` as it is?

Of course. I've been working on such for a month. I cannot make the 
samples public for the time being. Point is, there's no need to.


Andrei



More information about the Digitalmars-d mailing list