inline assembler procedure

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

inline assembler procedure

Пётр Косаревский
How can I write inline assembler procedure?

(FPC accepts the word "inline", but generates "call" instruction etc.)

If there is a way, could anyone point to an example, please?






Or just remember rotating bits in fpc-devel (if I get it right, they were not implemented):

(it's i386, cyclic bitwise longword l shift to the left by c bits; c may be over 32)

function lrol(l: longword; c: byte): longword; assembler; inline; // this thing is not really inline
   asm
   movb  %dl,%cl
   roll  %cl,%eax
   end; // calling register conventions: l->eax, c->dl

(it generates
.globl P$P_LROL$LONGWORD$BYTE$$LONGWORD
P$P_LROL$LONGWORD$BYTE$$LONGWORD:
# Temps allocated between ebp-4 and ebp-4
        # Register ebp allocated
        pushl %ebp
        movl %esp,%ebp
        subl $4,%esp
# Var l located in register
# Var c located in register
# Temp -4,4 allocated
# Var $result located at ebp-4
        # Register eax,ecx,edx allocated
# [97] movb  %dl,%cl
        movb %dl,%cl
# [98] roll  %cl,%eax
        roll %cl,%eax
        # Register eax,ecx,edx released
# Temp -4,4 released
        leave
        # Register ebp released
        ret
        # Register eax released


and

      (moving variables, which could already be in registers)
        call P$P_LROL$LONGWORD$BYTE$$LONGWORD

where it is expected to be inlined)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: inline assembler procedure

Michael Van Canneyt


On Thu, 20 Jul 2006, =?koi8-r?Q?=F0=A3=D4=D2 =EB=CF=D3=C1=D2=C5=D7=D3=CB=C9=CA?= wrote:

> How can I write inline assembler procedure?
>
> (FPC accepts the word "inline", but generates "call" instruction etc.)
>
> If there is a way, could anyone point to an example, please?

Currently you cannot inline assembler routines, it is a known restriction.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: inline assembler procedure

Tomas Hajny
Michael Van Canneyt wrote:

> On Thu, 20 Jul 2006, =?koi8-r?Q?=F0=A3=D4=D2
> =EB=CF=D3=C1=D2=C5=D7=D3=CB=C9=CA?= wrote:
>
>> How can I write inline assembler procedure?
>>
>> (FPC accepts the word "inline", but generates "call" instruction etc.)
>>
>> If there is a way, could anyone point to an example, please?
>
> Currently you cannot inline assembler routines, it is a known restriction.

If nothing else, you can skip the stack frame generation using
"nostackframe" keyword. Not that it would help that much probably...

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: inline assembler procedure

Florian Klaempfl
In reply to this post by Пётр Косаревский
Пётр Косаревский wrote:
> How can I write inline assembler procedure?
>
> (FPC accepts the word "inline", but generates "call" instruction etc.)

Inline is only a recommendation.

>
> If there is a way, could anyone point to an example, please?

Inlining assembler procedures efficently is rather hard, so we don't do
so currently.

>
>
>
>
>
>
> Or just remember rotating bits in fpc-devel (if I get it right, they were not implemented):
>
> (it's i386, cyclic bitwise longword l shift to the left by c bits; c may be over 32)
>
> function lrol(l: longword; c: byte): longword; assembler; inline; // this thing is not really inline
>    asm
>    movb  %dl,%cl
>    roll  %cl,%eax
>    end; // calling register conventions: l->eax, c->dl
>
> (it generates
> .globl P$P_LROL$LONGWORD$BYTE$$LONGWORD
> P$P_LROL$LONGWORD$BYTE$$LONGWORD:
> # Temps allocated between ebp-4 and ebp-4
> # Register ebp allocated
> pushl %ebp
> movl %esp,%ebp
> subl $4,%esp
> # Var l located in register
> # Var c located in register
> # Temp -4,4 allocated
> # Var $result located at ebp-4
> # Register eax,ecx,edx allocated
> # [97] movb  %dl,%cl
> movb %dl,%cl
> # [98] roll  %cl,%eax
> roll %cl,%eax
> # Register eax,ecx,edx released
> # Temp -4,4 released
> leave
> # Register ebp released
> ret
> # Register eax released
>
>
> and
>
>       (moving variables, which could already be in registers)
> call P$P_LROL$LONGWORD$BYTE$$LONGWORD
>
> where it is expected to be inlined)
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal