Sign in Join

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

Mailing lists / fpc-devel / 2019-07

Another benefit of pure functions

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

J. Gareth Moreton

This is for my own benefit and note-taking, but I've just found another use for pure functions.

Though this is not exactly how the compiler source is structured, you get situations such as this.

RegName := debug_regname(taicpu(p).oper[0]^.reg); { 32-bit register name }
DebugMsg(SPeepholeOptimization + PreMessage + RegName + ',' + RegName +
' (removes REX prefix)', p);

When not in debug mode, DebugMsg is just a null procedure that does nothing (as is debug_regname, but let's ignore that for the moment).

One of the definitions of pure functions is that it has no side-effects, so if it can be shown that RegName is not used after its assignment, and a pure function is being used to assign said value, then the entire call can be safely removed, since it won't affect any other part of the program.

If anyone is able to notice potential areas where pure functions can optimise a program, sound off!

Gareth aka. Kit

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email