Formal annotating Code for Optimizations?

Sean Kelly sean at invisibleduck.org
Fri Jul 18 09:19:43 PDT 2008


JAnderson wrote:
> Manfred_Nowak wrote:
>> Example:
>> If two actions `a1',`a2' are based on a binary decision `b' then on a 
>> pure logical level one can code:
>>
>>   if( b)
>>     a1.do; // actions have `do'- and `undo'-methods
>>   else
>>     a2.do;
>> But if one knows, that the probability of `b' to be `true' is much 
>> greater than .5, then in order to use the precomputing capabilities of 
>> the CPU one would probably like to code:
>>
>>   a1.do;
>>   if( !b){
>>     a1.undo;
>>     a2.do;
>>   }        The other case requires similar code.
>>
>> In this latter code the abstraction of a simple binary decision seems 
>> to be less obvious, which seems to be bad for maintenance.
>>
>> Of course one can annotate with comments. But since comments can be 
>> hints for defencies in the language, the question rises whether one 
>> should formalize this:
>>
>>   if( b)note( p(b)>.8)
>>     a1.do;
>>     undo a1.undo;
>>   else
>>     a2;
>>     undo a2.undo;
>>
>> -manfred
> 
> MSVC++ 2005 has this profile that you can run on the code and then it 
> will use that to optimize the code to use the most common paths.  I'm 
> not sure if it also optimizes IF statements.  I know it optimizes 
> functions layout to be more cache friendly.

The Sun compiler does this too.  It's the code rearranging that's the 
killer feature here IMO.  I love that the compiler can ensure that the 
code for heavily used functions doesn't cross page boundaries, etc.


Sean



More information about the Digitalmars-d mailing list