Linux 64bit calling convention lazarus / 66-Unix ---------------------------------------------------------------------- mikerabat · 2017-07-04 08:30 I wrote quite a lot of assembler optimized functions for windows and now wanted to port it to Linux. The biggest problem I now encounter is that I learned that Linux uses a different calling convention for 64bit than windows does. Actually it uses different registers for function calls and it would be a great deal of work to rename these registers or even clone and rewrite the calls. Is there a way I can force the freepascal compiler to use the windows calling convention for 64bit? (I know for 32 bit I can force different conventions...) kind regards    Mike ---------------------------------------------------------------------- Thaddy · 2017-07-04 09:54 You do not need to. Win64 has only one (1) calling convention (four register _fastcall) and that is selected by default for that platform. If you want you can select stdcall or winapi on linux too, I seem to remember stdcall on 64 bit is aliased to 4 register __fastcall, but imho makes not much sense, unless, indeed, it is for some of your own routines. So try stdcall on Linux. (which shouldn't be really stdcall,but the aliased __fastcall64). I am not absolutely sure, though. And may be FastCall simply works. ---------------------------------------------------------------------- mikerabat · 2017-07-04 14:00 Yeah I know that - and that's the problem. My routines (40+) are implemented such that they depend on the registers windows uses. The thing is that according to wiki there is also only one calling convention on Linux/Unix which is similar to win64 calling conventions but uses different param registers. The thing is I rely on these.... Afaik on the x86 side (32bit) there are many calling conventions but they are completely ignored for 64bit (at least on the windows compiler side is the case)... so ... is there something similar I can do on the 64bit side? ---------------------------------------------------------------------- Remy Lebeau · 2017-07-05 21:20 Quote from: mikerabat on July 04, 2017, 04:00:56 pmThe thing is that according to wiki there is also only one calling convention on Linux/Unix which is similar to win64 calling conventions but uses different param registers. The thing is I rely on these.... Well, then you have to change that.  IFDEF the code to use one set of registers on Win64, and another set of registers on Linux64.  Consolidate them into a single set of common registers, or stack space, or whatever, for the rest of the code to use without caring about the underlying platform. ---------------------------------------------------------------------- mikerabat · 2017-07-19 07:20 Alright... I managed to add a little asm prologue (interchanging registers) to all 64 bit routines so they now work properly. ---------------------------------------------------------------------- avra · 2017-07-19 11:18 Quote from: mikerabat on July 19, 2017, 09:20:46 amAlright... I managed to add a little asm prologue (interchanging registers) to all 64 bit routines so they now work properly. You might also want to take a look at macros. They could potentially add less overhead. https://www.freepascal.org/docs-html/prog/progse5.html#x137-1380002.2