[Oberon] Oberon Compiler Optimization (was: Oberon-07 - SYSTEM.MSET)

Chris Burrows chris at cfbsoftware.com
Sat Jun 27 01:11:04 CEST 2020


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of John
> R. Strohm
> Sent: Friday, 26 June 2020 11:45 PM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] Oberon-07 - SYSTEM.MSET
> 
> > --- chris at cfbsoftware.com wrote:
> >
> > > -----Original Message-----
> > > From: Tomas Kral [mailto:thomas.kral at email.cz]
> > > Sent: Friday, 26 June 2020 4:51 PM
> > > To: oberon at lists.inf.ethz.ch
> > > Cc: chris at cfbsoftware.com
> > > Subject: Re: [Oberon] Oberon-07 - SYSTEM.MSET
> > >
> > > > Using the auto-increment extension to SYSTEM.PUT
> > >
> > > Interesting, PUT(VAR addr...), addr passed by reference?
> > >
> >
> > Yes - there are two different signatures:
> >
> > PROCEDURE PUT*(address: INTEGER; x: <any basic type>);
> >
> > PROCEDURE PUT*(VAR address: INTEGER; x: <any basic type>; inc:
> > INTEGER);
> 
> The original code fragment was (approximately)
> 
>    REPEAT SYSTEM.PUT(addr, value, incr) UNTIL addr > limit;
> 
> This is logically equivalent to
> 
>    REPEAT
>       BEGIN
>          SYSTEM.PUT(addr, value);
>          addr := addr + incr;
>       END
>    UNTIL addr > limit;
> 
> I am admittedly not up on typical Oberon compiler optimization, but I
> would generally expect a compiler smart enough to inline the SYSTEM.PUT()
> call, in either case, to be able to optimize in the autoincrement as
> well.
> 

Optimizations in Oberon compilers tend to be confined to single statements.
The compiler is not particularly aware that the increment statement in your
example above is associated with the PUT. If instead of 

  addr := addr + incr;

you wrote

  INC(addr, incr);

The latter statement is potentially easier to optimise because you are
telling the compiler that the source and destination variables are the same,
but it still has no effect on any statements preceding or following it.
Having said that, I don't believe the INC statement is optimised in the
current Oberon compilers. RISC5 in particular does not have an
auto-increment instruction that could be useful in this case.

If you are interested in the reasoning behind the optimization strategy used
in Wirth's Oberon compilers, refer to Section 22. "Leaf procedures and
Register Variables" and Section 26.8. "Optimizations" in "An Oberon Compiler
for the ARM Processor", Niklaus Wirth 2008:

https://inf.ethz.ch/personal/wirth/Oberon/Oberon.ARM.Compiler.pdf

Regards,
Chris Burrows
CFB Software
https://www.astrobe.com/RISC5




More information about the Oberon mailing list