Forum > General

possible to add inlined CPU-specific assembly language instructions?

<< < (3/4) > >>

Basile B.:

--- Quote from: tyates on June 13, 2014, 05:09:59 pm ---My question is does anyone know if it is possible to use processor specific statements in Pascal code, ideally via an inlined function call.

Modern x86 CPUs have PREFETCH, LFENCE/MFENCE, CMOV, SETcc, all the SSE instructions, etc.  In free pascal, if I create a function with inline assembly and then try to inline that function I get an error specifically saying I can't do that (inline assembly / inline function).

--- End quote ---

Maybe I completly miss the point but if your problem is about missing assembly instruction then don't forget that you can also directly program using x86 byte code:

e.g, instead of MOV result,$01:


--- Code: ---program Project1;
uses sysutils;
{$ASSERTIONS+}
{$ASMMODE INTEL}
function example: boolean; assembler;
asm
  DB $B0;
  DB $01;
end;
begin
  assert(example(),'not true');
  readln;
end.
--- End code ---

To be clear, you can use this trick to put the instructions which are not recognized.

For example some people uses this to put the instruction RDTSC in very old delphi versions, since when the compiler was shipped this CPU instruction didn't existed.

marcov:

--- Quote from: Leledumbo on January 22, 2015, 12:49:35 pm ---
--- Quote from: marcov on January 22, 2015, 10:48:11 am ---Afaik GCC doesn't either, it requires a special format.

--- End quote ---
with

--- Code: ---__attribute__((always_inline));
--- End code ---
it does.

--- End quote ---

Does it force inline then, or really scan the inline asm code for used registers as requested?

Laksen:
You specify operands in a gcc specific way. It's nothing like the inline assembly in fpc.

Unless something like that gets added to fpc it won't be possible to inline such stuff. All instructions would need precise semantic definitions otherwise. Like what does it change in the status register, does it modify edx, other weird stuff, etc. And there are many hundred or instructions to do that with

marcov:

--- Quote from: Laksen on January 22, 2015, 03:40:20 pm ---You specify operands in a gcc specific way. It's nothing like the inline assembly in fpc.

--- End quote ---

Ok, so it is the same as the already mentioned register-independent asm. with all the funny looking modifiers that specify what's changed?

Leledumbo:

--- Quote from: marcov on January 22, 2015, 03:27:18 pm ---Does it force inline then, or really scan the inline asm code for used registers as requested?

--- End quote ---
Force inline, no register usage scanning seems done. Maybe could break something when used improperly.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version