Oberon Community Platform Forum
October 23, 2019, 02:46:38 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: inline procedures  (Read 4548 times)
sage
Full Member
***
Posts: 170



WWW
« 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  Huh
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  Huh
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?  Wink


* inline.png (1.35 KB, 355x74 - viewed 640 times.)
« Last Edit: December 03, 2008, 12:05:16 PM by sage » Logged
sage
Full Member
***
Posts: 170



WWW
« Reply #1 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 Roll Eyes
Logged
sage
Full Member
***
Posts: 170



WWW
« Reply #2 on: December 03, 2008, 03:44:49 PM »

How better to get operands inside inline procedures? Seems only POP works  Huh
At last, with help of BohdanT I've discovered the alternative solution Grin
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;
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #3 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().
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!