[Oberon] Oberon-7 - IF ELSE optimisation
Chris Burrows
chris at cfbsoftware.com
Fri Mar 8 23:45:22 CET 2019
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Tomas Kral
> Sent: Saturday, 9 March 2019 12:55 AM
> To: Oberon at lists.inf.ethz.ch
> Subject: [Oberon] Oberon-7 - IF ELSE optimisation
>
> Hi,
>
> Trying to make this more effective,
>
> IF (x >= 0) & (y >= 0) THEN
> ELSIF (x < 0) & (y >= 0) THEN
> ELSIF (x >= 0) & (y < 0) THEN
> ELSIF (x < 0) & (y < 0) THEN
> END ;
>
> Recoded to below, correct?
> Above has better readability.
>
> IF x >= 0 THEN IF y >=0 ELSE (*y < 0*) THEN END ELSIF (*x < 0*) y >=
> 0 THEN ELSE (*y < 0*) END ;
>
> Compiler seems optimising loose ELSE IF to ELSIF?
>
That doesn't compile. I found it easier to understand the refactoring by
including some statements i.e. S0, S1 etc. e.g.
Original:
IF (x >= 0) & (y >= 0) THEN S0
ELSIF (x < 0) & (y >= 0) THEN S1
ELSIF (x >= 0) & (y < 0) THEN S2
ELSIF (x < 0) & (y < 0) THEN S3
END
Step1:
IF (x >= 0) & (y >= 0) THEN S0
ELSIF (x < 0) & (y >= 0) THEN S1
ELSIF (x >= 0) & (y < 0) THEN S2
ELSE S3
END
Step2:
IF (x >= 0) THEN
IF (y >= 0) THEN S0 ELSE S2 END
ELSIF (y >= 0) THEN S1
ELSE S3
END
Then, possibly, because the negative tests have been eliminated, step3:
xPositive := x >= 0;
yPositive := y >= 0;
IF xPositive THEN
IF yPositive THEN S0 ELSE S2 END
ELSIF yPositive THEN S1
ELSE S3
END
Regards,
Chris
Chris Burrows
CFB Software
http://www.astrobe.com
More information about the Oberon
mailing list