[Oberon] INC(i) vs i := i + 1

Diego Sardina dsar at eml.cc
Mon May 3 21:00:28 CEST 2021


On Mon, May 3, 2021, at 6:20 PM, Jeff Maggio wrote:
> Hi all,
> 
> In most Oberon source, people tend to increment i with INC(i). Is there an efficiency reason for this, or is i := i + 1 just as fast?
> 
> I'm trying to write code that would be very easy for someone coming from python/C++ to understand, so I'd prefer to use i := i + 1 because it's syntactically familiar

The main reason of INC() since the time of Pascal was to emit the inc opcode without having to deal with the parsing of the expression i := i + 1.
So the real question is: what are advantages of using inc opcode?

As Jörg said before, inc opcode is faster with some operations (for what I remember also in general, since it doesn't set the CF flag in x86 and makes loop faster).
GCC and Clang always emit the inc opcode in loops with -O3 and -march=native.

--
Diego Sardina



More information about the Oberon mailing list