在 2018/5/14 23:41, Jacek Caban 写道:
Based on patch by Tom Ritter.
Tom explained it here:
https://sourceforge.net/p/mingw-w64/mailman/message/36238073/
I added WIDL_EXPLICIT_AGGREGATE_RETURNS preprocessor guards so that it's
not used then not needed.
Signed-off-by: Jacek Caban <[email protected]>
---
mingw-w64-headers/include/d2d1.h | 117
+++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
The trick should work, but it can still be improved a little by changing
```
+ D2D1_SIZE_F __ret;
+ return *GetSize(&__ret);
```
to
```
+ D2D1_SIZE_F __ret;
+ GetSize(&__ret);
+ return __ret;
```
GCC now implements the famous 'named return value optimization' (NRVO),
which elides the copy/move construction of local automatic objects by
constructing them in the storage allocated by the caller directly.
For example, using `gcc test.cc -S -O2` to compile this snippet
```
struct foo {
char a[1000];
};
struct bar {
virtual foo * fancy(foo *) = 0;
foo fancy_orig();
foo fancy_nrvo();
};
foo bar::fancy_orig(){
foo f;
return *fancy(&f);
}
foo bar::fancy_nrvo(){
foo f;
fancy(&f);
return f;
}
```
results in the `fancy_orig()` function being
```
_ZN3bar10fancy_origEv:
.LFB0:
pushq %rdi
.seh_pushreg %rdi
pushq %rsi
.seh_pushreg %rsi
pushq %rbx
.seh_pushreg %rbx
subq $1040, %rsp
.seh_stackalloc 1040
.seh_endprologue
movq %rcx, %rbx
movq %rdx, %rcx
leaq 32(%rsp), %rdx
movq (%rcx), %rax
call *(%rax)
movq %rbx, %rdi
movq %rax, %rsi
movl $1000, %eax
testb $1, %bl
jne .L27
testb $2, %dil
jne .L28
.L3:
testb $4, %dil
jne .L29
.L4:
movl %eax, %ecx
shrl $3, %ecx
rep movsq
testb $4, %al
je .L5
movsl
.L5:
testb $2, %al
je .L6
movsw
.L6:
testb $1, %al
je .L1
movsb
.L1:
movq %rbx, %rax
addq $1040, %rsp
popq %rbx
popq %rsi
popq %rdi
ret
.L27:
movzbl (%rsi), %eax
movb %al, (%rbx)
leaq 1(%rbx), %rdi
addq $1, %rsi
movl $999, %eax
testb $2, %dil
je .L3
.L28:
movzwl (%rsi), %edx
movw %dx, (%rdi)
addq $2, %rdi
addq $2, %rsi
subl $2, %eax
testb $4, %dil
je .L4
.L29:
movl (%rsi), %edx
movl %edx, (%rdi)
addq $4, %rdi
addq $4, %rsi
subl $4, %eax
jmp .L4
.seh_endproc
.align 2
.globl _ZN3bar10fancy_nrvoEv
.def _ZN3bar10fancy_nrvoEv; .scl 2; .type 32; .endef
.seh_proc _ZN3bar10fancy_nrvoEv
```
while the NRVO one being:
```
_ZN3bar10fancy_nrvoEv:
.LFB1:
pushq %rbx
.seh_pushreg %rbx
subq $32, %rsp
.seh_stackalloc 32
.seh_endprologue
movq %rcx, %rbx
movq %rdx, %rcx
movq (%rdx), %rax
movq %rbx, %rdx
call *(%rax)
movq %rbx, %rax
addq $32, %rsp
popq %rbx
ret
```
so it is quite a little enhancement.
--
Best regards,
LH_Mouse
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public