[fpc-devel] Successful implementation of inline support for pure assembler routines on x86

Florian Klämpfl florian at freepascal.org
Sun Mar 17 18:37:32 CET 2019


Am 15.03.19 um 11:32 schrieb J. Gareth Moreton:
> Hi everyone,
> 
> Sorry for the slightly long-winded title.  This was something I've been 
> working on for the past few weeks to allow the use of "inline" with 
> certain x86 assembler routines, subject to restrictions for safety 
> reasons.  I have successfully written code that implements this support 
> while ensuring it doesn't affect platforms with a different assembly 
> languages.  Regression tests have passed, as have some new tests, some 
> of which test modified RTL assembler functions that have had "inline" 
> added to their list of directives.

As said before, I have a lot of concerns against this as it opens a can 
of worms hard to handle:
* using inline assembler is always the worst solution to do something, 
it normally means either:
   - the compiler misses a certain feature
   - the compiler is generating bad code
* intrinsics provide a much better way to achieve exactly what this 
approach aims at:
   - they enable the use of all registers as the compiler does register 
allocation
   - constraints on instructions (like a certain operand needs to be a 
constant) can be easily forced

Is there any advantage over intrinsics, I missed so far?

> 
> There was a previous concern about it breaking too much and it being 
> impossible to implement on all platforms - the latter point may be true, 
> but through the careful use of virtual methods within the compiler, it 
> should be possible to extend the inline support one platform at a time 
> without breaking the others.
> 
> All the details, including a PDF specification that explains the design 
> and implementation choices, a couple of existing tests that touch on the 
> functionality, along with any new tests, limitations or problems found, 
> can be found here: https://bugs.freepascal.org/view.php?id=35232
> 
> I hope it proves to be insightful and useful.
> 
> Gareth aka. Kit
> 
> P.S. Though this feature can be used for implementing intrinsics, it is 
> not a direct replacement for them because instructions like SHUFPS 
> cannot be flexibly encoded due to its immediate operand (i.e. it has to 
> be a raw number... it can't take its value from a parameter).

Well, with intrinsics, this can be easily done.



More information about the fpc-devel mailing list