[fpc-devel] Successful implementation of inlinesupportforpureassembler routines on x86
Jonas Maebe
jonas at freepascal.org
Mon Mar 18 21:23:06 CET 2019
On 18/03/2019 11:36, J. Gareth Moreton wrote:
> I think that is the fundamental difference between intrinsics and
> reusable, inlinable assembly language... you would use intrinsics mostly
> to use one or two special instructions in a convenient, concise way,
> while assembly language is a "give me all the power!" request.
> Admittedly though my patch does allow the peephole optimizer to touch
> the assembly language in the inlined procedure, mostly to help optimize
> parameter and result passing.
No optimizer must ever be allowed to interact with inline assembly
(apart from parametrised operands related to constraints). Inline
assembly is completely the responsibility of the programmer, and must
always appear literally in the output. It is impossible to analyse all
possible tricks a programmer may use and safely handle those in an
optimizer.
Similarly, replacing return instructions with jumps is something you
cannot do. You can do that with Pascal-level "exit" statements, but not
with assembler-level return instructions. As you wrote yourself: "If the
program breaks because of what they've coded, it's on them to fix it."
That is again why I argue for never allowing the inlining of pure
assembler routines, and only for inlining Pascal routines that happen to
also contain inline assembly. In that case, you will (almost?) never
encounter the case where a routine works if it's not inlined, but breaks
once it's inlined, without needing any warnings or target-specific analyses.
Jonas
More information about the fpc-devel
mailing list