<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 3, 2014 at 9:23 PM, Dennis Luehring <span dir="ltr"><<a href="mailto:dl.soluz@gmx.net" target="_blank">dl.soluz@gmx.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Am 04.06.2014 00:16, schrieb Richard Smith:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="">
>The standard (as of only a few months ago) allows operator new/operator<br></div>
>delete calls such as the above to be removed, but*only* if they came from<div class=""><br>
>new-expressions and delete-expressions. Under the covers, std::vector uses<br>
>direct calls to ::operator new and ::operator delete, so these provisions<br>
>do not apply.<br>
><br>
>So... we should add some way for std::allocator to say<br>
>"allocate/deallocate memory like a new-expression", and use it in libc++. I<br>
>think we should add<br>
><br>
> void *__builtin_operator_new(size_<u></u>t)<br>
> void __builtin_operator_delete(<u></u>void*)<br>
><br>
>for this.<br>
><br>
</div></blockquote><div class="">
Clang now supports these, and I have a patch out for review to make libc++<br>
use them. With the patch applied, clang+libc++ optimizes your code down to<br>
just 'return 160' for both the std::array and std::vector cases.<br>
<br>
</div></blockquote>
<br>
unbelievably fast integration :) - thanks alot for taking the time<br>
<br>
how well does your patch play with<br>
<br>
gcc.<a href="http://gcc.godbolt.org" target="_blank">http://gcc.godbolt.org</a>, clang version 3.4.1 -O3 -std=c++11<br>
<br>
#include <string><br>
int main()<br>
{<br>
return std::string("hello").size();<br>
}<br>
<br>
results in:</blockquote><div><br></div><div><div>main: # @main</div><div> movl $5, %eax<br></div><div> retq</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="">
main: # @main<br>
pushq %rbx<br></div>
subq $32, %rsp<br>
leaq 16(%rsp), %rdi<br>
leaq 8(%rsp), %rdx<br>
movl $.L.str, %esi<br>
callq std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)<br>
movq 16(%rsp), %rax<br>
leaq -24(%rax), %rdi<br>
movl std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage, %ecx<br>
cmpq %rcx, %rdi<br>
movl -24(%rax), %ebx<br>
jne .LBB0_1<br>
.LBB0_6: # %_ZNSsD1Ev.exit<br>
movl %ebx, %eax<br>
addq $32, %rsp<br>
popq %rbx<br>
ret<br>
.LBB0_1:<br>
addq $-8, %rax<br>
movl $__pthread_key_create, %ecx<br>
testq %rcx, %rcx<br>
je .LBB0_3<br>
movl $-1, %ecx<br>
lock<br>
xaddl %ecx, (%rax)<br>
movl %ecx, 28(%rsp)<br>
movl 28(%rsp), %ecx<br>
jmp .LBB0_4<br>
.LBB0_3:<br>
movl (%rax), %ecx<br>
leal -1(%rcx), %edx<br>
movl %edx, (%rax)<br>
.LBB0_4: # %_ZN9__gnu_cxxL27__exchange_<u></u>and_add_dispatchEPii.exit.i.i.<u></u>i<br>
testl %ecx, %ecx<br>
jg .LBB0_6<br>
leaq 24(%rsp), %rsi<br>
callq std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_M_destroy(std::<u></u>allocator<char> const&)<br>
jmp .LBB0_6<br>
<br>
.L.str:<br>
.asciz "hello"<br>
<br>
and<br>
<br>
#include <vector><br>
#include <numeric><div class=""><br>
<br>
typedef std::vector<int> container_t;<br>
<br></div>
int main()<br>
{<div class=""><br>
const container_t a{1,2};<br>
const container_t b{4,5};<br>
const container_t ints<br>
{<br>
std::accumulate(a.begin(),a.<u></u>end(),1),<br>
std::accumulate(b.begin(),b.<u></u>end(),2),<br>
};<br></div>
return std::accumulate(ints.begin(),<u></u>ints.end(),100);<br>
}<br>
<br>
results in:<br></blockquote><div><br></div><div><div>main: # @main</div><div> movl $115, %eax<br></div><div> retq</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
main: # @main<br>
pushq %rbp<br>
pushq %r15<br>
pushq %r14<br>
pushq %rbx<br>
pushq %rax<br>
movl $8, %edi<br>
callq operator new(unsigned long)<br>
movq %rax, %r14<br>
movabsq $8589934593, %rax # imm = 0x200000001<br>
movq %rax, (%r14)<br>
movl $8, %edi<br>
callq operator new(unsigned long)<br>
movq %rax, %rbx<br>
movabsq $21474836484, %rax # imm = 0x500000004<br>
movq %rax, (%rbx)<br>
movl (%r14), %r15d<br>
movl 4(%r14), %ebp<br>
movl $8, %edi<br>
callq operator new(unsigned long)<br>
leal 1(%r15,%rbp), %ebp<br>
testq %rax, %rax<br>
movl %ebp, (%rax)<br>
movl $11, 4(%rax)<br>
je .LBB0_5<div class=""><br>
movq %rax, %rdi<br>
callq operator delete(void*)<br></div>
.LBB0_5: # %_ZNSt6vectorIiSaIiEED2Ev.<u></u>exit25<br>
testq %rbx, %rbx<br>
je .LBB0_7<br>
movq %rbx, %rdi<br>
callq operator delete(void*)<br>
.LBB0_7: # %_ZNSt6vectorIiSaIiEED2Ev.<u></u>exit23<br>
addl $111, %ebp<br>
testq %r14, %r14<br>
je .LBB0_9<br>
movq %r14, %rdi<br>
callq operator delete(void*)<br>
.LBB0_9: # %_ZNSt6vectorIiSaIiEED2Ev.<u></u>exit21<br>
movl %ebp, %eax<br>
addq $8, %rsp<br>
popq %rbx<br>
popq %r14<br>
popq %r15<br>
popq %rbp<br>
ret<br>
movq %rax, %rbp<br>
movq %rbp, %rdi<br>
callq _Unwind_Resume<br>
movq %rax, %rbp<br>
jmp .LBB0_14<br>
movq %rax, %rbp<br>
testq %rbx, %rbx<br>
je .LBB0_14<br>
movq %rbx, %rdi<br>
callq operator delete(void*)<br>
.LBB0_14: # %_ZNSt6vectorIiSaIiEED2Ev.<u></u>exit15<br>
testq %r14, %r14<br>
je .LBB0_16<br>
movq %r14, %rdi<br>
callq operator delete(void*)<br>
.LBB0_16: # %_ZNSt6vectorIiSaIiEED2Ev.exit<br>
movq %rbp, %rdi<br>
callq _Unwind_Resume<br>
GCC_except_table0:<br>
.byte 255 # @LPStart Encoding = omit<br>
.byte 3 # @TType Encoding = udata4<br>
.asciz "\266\200\200" # @TType base offset<br>
.byte 3 # Call site Encoding = udata4<br>
.byte 52 # Call site table length<br>
.long .Lset0<br>
.long .Lset1<br>
.long .Lset2<br>
.byte 0 # On action: cleanup<br>
.long .Lset3<br>
.long .Lset4<br>
.long .Lset5<br>
.byte 0 # On action: cleanup<br>
.long .Lset6<br>
.long .Lset7<br>
.long .Lset8<br>
.byte 0 # On action: cleanup<br>
.long .Lset9<br>
.long .Lset10<br>
.long 0 # has no landing pad<br>
.byte 0 # On action: cleanup<div class=""><div class="h5"><br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div></div>