<HTML>
And this e-mail contains additional files to aid with testing and showcasing:<br>
<br>
- x86-inline-assembler-rtl-samples.patch - makes some internal RTL functions inline, like Trunc, since it's just a single instruction.<br>
- x86_inline_asm_test.pp - an x86-64 test program that has some hand-written assembler routines that have been inlined. The output should be identical whether or not "inline" is specified.<br>
<br>
Additionally, "tests/test/cg/tvectorcall3.pp" has an assembler function that is inlined, and this can be used to test if it works properly for vectorcall under Win64 and the regular System V ABI under Linux (it only uses the XMM registers, so the registers that are used for the parameters and the return value are identical).<br>
<br>
Gareth aka. Kit<br>
<br>
<br>
<span style="font-weight: bold;">On Tue 12/02/19 11:43 , "J. Gareth Moreton" gareth@moreton-family.com sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
This is something I've been researching for a while, the ability to inline procedures that are written in pure assembler, and I've got something working pretty well and I'd like to showcase it.<br>
<br>
It's something that's garnered a little uncertainty from others because of how easy it is to introduce compiler bugs and offer support on other platforms, for example. Currently, my code is restricted to i386 and x86_64 because that's all I can actually test on. Nevertheless, the new virtual methods will easily allow extension to other CPUs while blocking "inline" on pure assembler routines by default.<br>
<br>
There are a number of restrictions on what can and can't be inlined, specifically:<br>
- The routine must have the "nostackframe" directive.<br>
- You cannot write to the stack.<br>
- No parameters or return values must be on the stack.<br>
- You cannot write to a non-volatile register.<br>
<br>
... among a few others. The internal procedure checks commands against the "InsProp" array (although a number of the opcodes just have "Ch_All" specified, which my code assumes to mean that everything is modified, hence it marks the procedure as 'cannot inline').<br>
<br>
I've so far built this on x86_64-win64, i386-win32 and x86_64-linux (I couldn't do i386-linux due to problems with missing tools, but it gets quite far in the compilation otherwise - if someone can do a more strenuous test, I'd be grateful) and done some tests with internal functions and some showcase functions, with promising results.<br>
<br>
Some other things that the inlining routine does:<br>
- If jumps and labels are found, new local ones are generated.<br>
- If RET is found, it is changed to a JMP and a new destination label generated at the end of the inserted code.<br>
- The markers at the beginning and end are removed, so peephole optimisation is actually performed on the inserted code - this is mostly to address some inefficiencies that crop up from moving parameters into the expected registers (e.g. the first integer parameter into RCX under Win64).<br>
<br>
To Florian, I know this work is somewhat unsanctioned, but I would like to show that it can be done in a way that's clean. Even if this is still a definite no, well, I managed to find and squash bug #35065!<br>
<br>
Another e-mail will follow this one that adds a patch that inlines some RTL routines, and a small test program.<br>
<br>
<div>Gareth aka. Kit</div><div><br>
</div><div>NOTE: Make sure you have the current trunk, because this code triggered Internal Error 200208181 due to a bug in "tai_cpu_abstract.ppuload" that was only fixed this morning.<br>
</div><br>
_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a><br>
<br>
</blockquote></HTML>