Formal annotating Code for Optimizations?
JAnderson
ask at me.com
Fri Jul 18 07:54:39 PDT 2008
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.
-Joel
More information about the Digitalmars-d
mailing list