[fpc-devel] Question on updating FPC packages

J. Gareth Moreton gareth at moreton-family.com
Sat Oct 26 18:51:29 CEST 2019


Hi everyone,

So recently I took it upon myself to make some minor changes to uComplex 
in order to produce more optimal code, especially under x86_64 
platforms.  The changes included adding "const" to most of the function 
and operator parameters so ones that are passed by reference aren't 
needlessly copied by the prologues, and also to align the complex type 
and utilise the vectorcall calling convention under Win64 (and the 
System V ABI on non-Windows platforms) so the compiler better utilises 
the XMM registers (it can pass the entire complex type by value this way 
through a single register).

The "const" suggestion was made by a third party, and while I went out 
of my way to ensure the functions aren't changed in Pascal code, Florian 
pointed out that it could break existing assembler code.  Maybe I'm 
being a bit stubborn or unreasonable, I'm not sure, but in my eyes, 
using assembly language to directly call the uComplex functions and 
operators seems rather unrealistic.  I figured if you're writing in 
assembly language, especially if you're using vector registers, you'd be 
using your own code to play around with complex numbers.  Plus I figured 
that if you're developing on a non-x86_64 platform, the only thing 
that's different are the 'const' modifiers, which I don't think changes 
the way you actually call the function, regardless of platform.  Am I 
right in this?

The intention was to make the lightweight unit even more lightweight and 
optimal, without breaking backwards compatibility.  Are there any known 
examples out there that could break or would otherwise need testing?

I figured uComplex was a good place to start in optimising/refactoring 
some of the existing units, mainly because I'm a mathematician and hence 
know how complex numbers work, and the individual functions are simple 
enough that you can easily see how efficient they are in a disassembler 
(so are a good test case for new compiler optimisations).

I guess a more fundamental question I should ask, and this might be 
terribly naïve of me, is this: when you call some function F(x: TType), 
is there a situation where calling F(const x: TType) produces different 
machine code or where a particular actual parameter becomes illegal? 
Note I'm talking about how you call the function, not how the function 
itself is compiled.

Gareth aka. Kit


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



More information about the fpc-devel mailing list