dmd asm output

John Colvin john.loughran.colvin at gmail.com
Sun Mar 31 18:54:09 PDT 2013


I've been learning assembler a bit and I decided to have a look 
at what dmd spits out. I tried a simple function with arrays to 
see what vectorization gets done

void addto(int[] a, int[] b) {
     a[] += b[];
}

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

disassembled with gdb:
_D3sse5addtoFAiAiZv:
0x0000000000000040 <+0>:      push   rbp
0x0000000000000041 <+1>:      mov    rbp,rsp
0x0000000000000044 <+4>:      sub    rsp,0x30
0x0000000000000048 <+8>:      mov    QWORD PTR [rbp-0x20],rdi
0x000000000000004c <+12>:    mov    QWORD PTR [rbp-0x18],rsi
0x0000000000000050 <+16>:    mov    QWORD PTR [rbp-0x10],rdx
0x0000000000000054 <+20>:    mov    QWORD PTR [rbp-0x8],rcx
0x0000000000000058 <+24>:    mov    rcx,QWORD PTR [rbp-0x18]
0x000000000000005c <+28>:    mov    rax,QWORD PTR [rbp-0x20]
0x0000000000000060 <+32>:    mov    rdx,rax
0x0000000000000063 <+35>:    mov    QWORD PTR [rbp-0x28],rdx
0x0000000000000067 <+39>:    mov    rdx,QWORD PTR [rbp-0x8]
0x000000000000006b <+43>:    mov    rdi,QWORD PTR [rbp-0x10]
0x000000000000006f <+47>:     mov    rsi,rdx
0x0000000000000072 <+50>:    mov    rdx,QWORD PTR [rbp-0x28]
0x0000000000000076 <+54>:    call   0x7b <_D3sse5addtoFAiAiZv+59>
0x000000000000007b <+59>:    mov    rsp,rbp
0x000000000000007e <+62>:    pop    rbp
0x000000000000007f <+63>:     ret

This looks nothing like what I expected. At first I thought maybe 
it was due to a crazy calling convention, but adding extern(C) 
changed nothing.

Can anyone explain what on earth is going on here? All that 
moving things on and off the stack, a call to the next line 
(strange) and then we're done bar the cleanup?  I feel i must be 
missing something.


More information about the Digitalmars-d-learn mailing list