|Mathematics of if-else statements firstname.lastname@example.org (Bora Eryilmaz) (2001-09-05)|
|Re: Mathematics of if-else statements email@example.com (Adrian 'Dagurashibanipal' von Bidder) (2001-09-10)|
|Re: Mathematics of if-else statements firstname.lastname@example.org (2001-09-10)|
|Re: Mathematics of if-else statements email@example.com (Joachim Durchholz) (2001-09-11)|
|Re:Mathematics of if-else statements firstname.lastname@example.org (Dmitry Shaporenkov) (2001-09-11)|
|From:||"Adrian 'Dagurashibanipal' von Bidder" <email@example.com>|
|Date:||10 Sep 2001 23:03:49 -0400|
|Posted-Date:||10 Sep 2001 23:03:49 EDT|
Behold! For Bora Eryilmaz declaimed:
> Are there any mathematical/logical approaches to analyze nested if-else
> statements in order to simplify or optimize them, or to understand the
> flow of successive tests. For example, if I have
Probably the best way to optimize jumps (applies to conditions as well
as to loops, but I'd imagine the latter would be more complicated)
would be using profiling information.
If you know which branch is taken how often (sometimes you know it
even while programming) you then optimize so that the rarely taken
branch is on the slower path (depends on your architecture, perhaps an
unconditional taken branch may be faster than a conditional one not
taken or vice versa. You'd know quite a lot about the pipeline
architecture for this kind of optimizations).
One optimization which probably applies to almost any architecture (it
saves one jump) would be to transform:
But again, depending on how big the penalty for taken/not taken branches
is, the one saved (unconditional) is not much.
Return to the
Search the comp.compilers archives again.