www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6904] New: Skip Setting up Stack Frame if No Stack is Used


           Summary: Skip Setting up Stack Frame if No Stack is Used
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: performance
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com

--- Comment #0 from David Simcha <dsimcha yahoo.com> 2011-11-07 10:05:40 PST ---
This could affect performance slightly in real-world code if virtual functions
are used to return constants in some overrides.


int main() {
   return 0;

dmd -c -O -inline -release test.d

Disassembly of _Dmain in test.o:

_Dmain  PROC
        push    rbp                                     ; 0000 _ 55
        mov     rbp, rsp                                ; 0001 _ 48: 8B. EC
        xor     eax, eax                                ; 0004 _ 31. C0
        pop     rbp                                     ; 0006 _ 5D
        ret                                             ; 0007 _ C3
_Dmain  ENDP

Do we really need to do the push rbp; mov rbp, rsp; pop rbp when the function
doesn't actually use any stack and just sets eax to zero and returns?  GDC
elides these extra instructions.  In GDC, compiled with -O1 or higher, _Dmain's
body is:

_Dmain  PROC
        xor     eax, eax                                ; 0000 _ 31. C0
        ret                                             ; 0002 _ C3
_Dmain  ENDP

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 07 2011