Inlining assembler routines ?

S

Skybuck Flying

Hello,

I have some questions about "inlining assembler routines"...

Can free pascal inline assembler routines ?

Delphi 2007 can't do it, and neither can Delphi 2010 as far as I know...

However C compilers do seem to be able to inline assembler routines thanks
to "macro's".

(Microsoft's Vistual Studio/C/C++ comes to mind...)

As far as I know inlining assembler routines in C gets rid of the "call" and
"return" overhead ?

What's the secret to inline assembler routines for compiler writers ?

How difficult is it to do ? Is the C language somehow more suited for
inlining assembler ?

Is single-pass compiler technology like pascal unsuited for inlining
assembler routines ?

Bye,
Skybuck.
 
G

Gene

Hello,

I have some questions about "inlining assembler routines"...

Can free pascal inline assembler routines ?

I got an answer by typing "free pascal inline assembler" into Google.
You can too!
Delphi 2007 can't do it, and neither can Delphi 2010 as far as I know...

For this you would need a Delphi group. Doesn't Delphi have an
asm ... end; construct?
However C compilers do seem to be able to inline assembler routines thanks
to "macro's".

(Microsoft's Vistual Studio/C/C++ comes to mind...)

The C macro facility is completely orthogonal to inline assembly.
Your assertion "thanks to 'macro's' [sic]" is not correct.
As far as I know inlining assembler routines in C gets rid of the "call" and
"return" overhead ?

Inline assembler doesn't "get rid" of anything. Inline code is
inserted in the compiler output. That's all.
What's the secret to inline assembler routines for compiler writers ?

There are no secrets.
How difficult is it to do ? Is the C language somehow more suited for
inlining assembler ?

It's fairly trivial. No.
Is single-pass compiler technology like pascal unsuited for inlining
assembler routines ?

No. And there is nothing that makes Pascal inherently more "single
pass" than C.
 
S

Skybuck Flying

I think you misinterpreted what I mean, I'll give you an example:

function Something( SomeParameters ) : SomeReturnValue;
asm
...
SomeAsmCode;
...
end;

begin

Something; // <- assembler statements from the function Something should
be inlined here (*).

end;

I think C is able to inline the Something function into "call sites" like
(*).

This "function inlining" would get rid of the "call instruction", sometimes
even some pushes and pops, and the "return instruction".

Last time I checked the "call instruction" is 13 to 15 cycles (?) and the
"return instruction" 2 cycles.

That's quite a lot !

I would prefer to get rid of these instructions if possible.

So again I wonder: Does free pascal do "assembler function inlining" ?

I know for sure Delphi doesn't do it.

And I think C can do it ?

But how do C/C compilers do it ? and how come Delphi can't do it ?

Bye,
Skybuck.
 
G

Gene

I think you misinterpreted what I mean, I'll give you an example:

function Something( SomeParameters ) : SomeReturnValue;
asm
    ...
    SomeAsmCode;
    ...
end;

Again I say that there is absolutely no difference between C and
Pascal that will limit the way a designer might choose to implement an
assembly code extension in either language with respect to the other.
If you have a quirky implementation (Free, Delphi, or whatever), it's
because the extension implementer made it so.

Then again, a quick web survey leads to question of why you are
assuming one can only write assembly code blocks as bodies of
functions in these dialects. The Free Pascal manual shows this
example:

Var
I : Integer;
begin
I:=3;
asm
movl I,%eax
end;
end;

The web page http://www.delphipraxis.net/topic94005,0,asc,0.html

Shows this Delphi example.

procedure TForm1.Button1Click(Sender: TObject);
var
zahl1, zahl2, ergebnis : Integer;
begin
zahl1 := 5;
zahl2 := 8;
asm
PUSH EAX
MOV EAX, zahl1
ADD EAX, zahl2
MOV ergebnis, EAX
POP EAX
end;
ShowMessage(IntToStr(ergebnis));
end;

Even if you have a particular implementation that requires asm ...
end; to be the body of a function, there is no reason the compiler has
to compile a use as a call instruction sequence. It could easily
inline the body code. So now we are at a discussion of very low level
Pascal compiler details, which is way, way beyond this group.
 
S

Skybuck Flying

Inlining like that is possible in Free Pascal and Delphi, however I would
like to "re-use" the assembler code... therefore I would like to store it in
functions/procedures/routines and safe them in a unit/module for easy
re-use.

The only possibility so far is to use copy & paste as a "re-use"
functionality.

However I do not feel comfortable written "asm end" just somewhere within
the code... how can I be certain that it does not interfere with the higher
level language ?

At least the Delphi manual says to "assume nothing" about the contents of
the registers !

Therefore writing "re-useable" code by simply trying copy & paste becomes
difficult... because the code where it needs to be pasted in between will
vary a great deal... requiring "customization" for every paste ! That seems
to me to require too much time and therefore is unwanted.

So I want "functioning inlining for assembler routines...".

So far it seem C has it, Free Pascal doesn't have it, Delphi doesn't have
it...

My question is: Why doesn't Free Pascal/Delphi have it ?

Is it too difficult to implement ?

Does it require something special, maybe two-pass compilers ?

You have not answered any of my questions.

Just stating that these pascal compilers don't have it and that it's the
implementors choice doesn't cut it for me...

You wrote "it's easy" to inline the asm's body code...

I am not so certain about... it requires "channeling/tunneling" the
information stream of the code into the appriorate registers that the asm is
using...

Something that might not be so easy to do since those registers could
already be being used... thus might requires pushes and pops... which might
slow it down further.

If it was easy then why does pascal/delphi not have it ? Surely it would be
usefull... it does have high level inlining but not low level ?

To me it seems there must be a technical reason for it... one reason which
comes to mind might be the two-pass compiler requirement ?

Bye,
Skybuck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top