Optimization fun

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 6 15:13:35 PST 2014


On Thu, Nov 06, 2014 at 02:58:16PM -0800, H. S. Teoh via Digitalmars-d wrote:
[...]
>             auto ptr = current.ptr;
>             auto c = current.length;
>             while (c > 0 && *ptr != m.id)
>                 ptr++;
>             cert.headOffset = ptr - current.ptr;
> 
> This pushed gdc far enough in the right direction that it finally
> produced a 3-instruction inner loop. Strangely enough, the assembly had
> no check for (c > 0)... could it be because there is an assert following
> the loop claiming that that will never happen, therefore gdc elided the
> check? I thought Walter hasn't gotten around to implementing
> optimizations based on assert yet??
[...]

Argh... the reason c>0 had no check was because the code is wrong: c is
never decremented. :-(  Replacing (c > 0) with (c-- > 0) reduced the
performance improvement to about 3% instead of 4%-5%. Oh well. :-/

	mouth.open(); mouth.insert(foot);


T

-- 
I am a consultant. My job is to make your job redundant. -- Mr Tom


More information about the Digitalmars-d mailing list