Oberon Community Platform Forum

Development => General => Topic started by: sage on December 03, 2008, 09:22:53 AM



Title: inline procedures
Post by: sage on December 03, 2008, 09:22:53 AM
Hi, All!

For example, I'm writing inline procedure for fast fixed point multiplication.
Code:
PROCEDURE -FPMul(fp1, fp2: LONGINT): LONGINT; 
CODE {SYSTEM.i386} 
    POP     EAX 
    POP     EDX 
    IMUL    EDX  (* IMUL r/m32  (EDX:EAX <-- EAX * r/m dword) *)
    SHRD    EAX, EDX, BITS 
END FPMul;
How better to get operands inside inline procedures? Seems only POP works  ???
Non-inline working variant of procedure looks like:
Code:
PROCEDURE FPMul(fp1, fp2: LONGINT): LONGINT;
CODE {SYSTEM.i386}
MOV EAX, fp1[ESP]
IMUL fp2[ESP]  (* IMUL r/m32  (EDX:EAX <-- EAX * r/m dword) *)
SHRD EAX, EDX, BITS
END FPMul;
But compiler didn't allows such operations MOV EAX, fp1[ESP] nor IMUL fp2[ESP] in inline code  ???
Why compiler places all operands in stack in generated code? Is it possible to use registers EAX, EBX, and so on, as possible optimization here?  ;)


Title: Re: inline procedures
Post by: sage on December 03, 2008, 11:52:27 AM
Why AO language lacks of normal inline procedures?
It seems such semantics as in assembler ones is fully suitable for this task.
It is very desired language feature ::)


Title: Re: inline procedures
Post by: sage on December 03, 2008, 03:44:49 PM
How better to get operands inside inline procedures? Seems only POP works  ???
At last, with help of BohdanT I've discovered the alternative solution ;D
If POP not used, fixing of ESP needed:
Code:
PROCEDURE -FPMul(fp1, fp2: LONGINT): LONGINT; 
CODE {SYSTEM.i386} 
    POP     EAX 
    IMUL    DWORD [ESP] 
    SHRD    EAX, EDX, BITS 
    ADD     ESP, 4 
END FPMul;
Code:
PROCEDURE -FPMul(fp1, fp2: LONGINT): LONGINT; 
CODE {SYSTEM.i386} 
    MOV     EAX, DWORD 4[ESP] 
    IMUL    DWORD [ESP] 
    SHRD    EAX, EDX, BITS 
    ADD     ESP, 8 
END FPMul;


Title: Re: inline procedures
Post by: staubesv on December 12, 2008, 04:58:23 PM
Have a look at the procedure I386.IDCT.TransformSSE. It passes parameters to the callee over registers using SYSTEM.PUTREG().