On Monday, 1 April 2013 at 01:54:10 UTC, John Colvin wrote:
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.
It just looks like wrong snippet. Probably GDB isn't best
assembly level debugger.
.text._D4test5addtoFAiAiZAi:08000044 public
_D4test5addtoFAiAiZAi
.text._D4test5addtoFAiAiZAi:08000044 _D4test5addtoFAiAiZAi proc
near
.text._D4test5addtoFAiAiZAi:08000044
.text._D4test5addtoFAiAiZAi:08000044 arg_0 = dword ptr
8
.text._D4test5addtoFAiAiZAi:08000044 arg_8 = dword ptr
10h
.text._D4test5addtoFAiAiZAi:08000044 arg_C = dword ptr
14h
.text._D4test5addtoFAiAiZAi:08000044
.text._D4test5addtoFAiAiZAi:08000044 push ebp
.text._D4test5addtoFAiAiZAi:08000045 mov ebp,
esp
.text._D4test5addtoFAiAiZAi:08000047 push
dword ptr [esp+0Ch]
.text._D4test5addtoFAiAiZAi:0800004B push
[ebp+arg_0]
.text._D4test5addtoFAiAiZAi:0800004E push
[ebp+arg_C]
.text._D4test5addtoFAiAiZAi:08000051 push
[ebp+arg_8]
.text._D4test5addtoFAiAiZAi:08000054 call
_arraySliceSliceAddass_i
.text._D4test5addtoFAiAiZAi:08000059 add esp,
10h
.text._D4test5addtoFAiAiZAi:0800005C pop ebp
.text._D4test5addtoFAiAiZAi:0800005D retn 10h
.text._D4test5addtoFAiAiZAi:0800005D _D4test5addtoFAiAiZAi endp
Pardon 32bits, my IDA free doesn't handle 64bit too well.
The only difference is the fact that arguments here are passed on
stack instead of rdi, rsi etc like it takes place on System V
AMD64 calling convention