Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-12

Inc() and Dec() on properties

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

A question if I may, leading on from
http://bugs.freepascal.org/view.php?id=25440

- inc(x)/dec(x) with range checking enabled are "optimized" with taking address of x.

Is that why Inc() and Dec() can't be applied to properties, or are there other issues?

They were using untyped address, causing loss of alignment and generating large and slow code with unaligned access. This is fixed in r26256 and improves all alignment-sensitive targets.

Some platforms, for example ARM/Linux and Solaris/SPARC, fix alignment traps in the kernel so programmers might be unaware of any problems. Unfortunately, they might also be unaware that this introduces a substantial performance hit.

Incidentally, I notice that somebody in Russia is still developing SPARC systems http://lists.debian.org/debian-sparc/2013/12/msg00006.html http://en.wikipedia.org/wiki/MCST-R1000 I wonder whether they're aware that the architecture is well-supported by FPC and Lazarus?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Sven Barth
Sven Barth wrote 11 lines
On 20.12.2013 22:02, Mark Morgan Lloyd wrote: > A question if I may, leading on from > http://bugs.freepascal.org/view.php?id=25440 > > > - inc(x)/dec(x) with range checking enabled are "optimized" with > > taking address of x. > > Is that why Inc() and Dec() can't be applied to properties, or are there > other issues? http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields

Noted, but I think my real question is whether the compiler could recognise that the optimisation is inappropriate and instead generate +=n (with range checking).

Frankly, I'm fairly happy with the += idiom but I appreciate that there are some people who object that "it's not Pascal". I think that an alternative to having to repeat the full name of a deep property is desirable: it's obviously possible to use with but some people don't like that either :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Sergei Gorelkin
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 16 lines
Sven Barth wrote: > On 20.12.2013 22:02, Mark Morgan Lloyd wrote: >> A question if I may, leading on from >> http://bugs.freepascal.org/view.php?id=25440 >> >> > - inc(x)/dec(x) with range checking enabled are "optimized" with >> > taking address of x. >> >> Is that why Inc() and Dec() can't be applied to properties, or are there >> other issues? > > http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields Noted, but I think my real question is whether the compiler could recognise that the optimisation is inappropriate and instead generate +=n (with range checking).

Yes, the compiler was recognizing case with enabled range checking and generating "x:=x+n". However if "x" involves a function call (e.g. inc(somearray[foo()+2]); ) it is still necessary to avoid calling it twice, hence the optimization. I used quotes because the end result was opposite to the expected one.

Regards,
Sergei

Reply by email