1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <memory>
// compiled with -fomit-frame-pointer -O2
struct A { int a = 8 ; int b = 2 ; int c = 8 ; } ;
int foo( A* pa )
{
return ++pa->a + --pa->b + pa->c ;
/*
movl 4(%esp), %edx
movl (%edx), %eax
leal 1(%eax), %ecx
movl %ecx, (%edx)
movl 4(%edx), %eax
subl $1, %eax
movl %eax, 4(%edx)
addl %ecx, %eax
addl 8(%edx), %eax
ret
*/
}
int bar( const std::unique_ptr<A>& pa )
{
return ++pa->a + --pa->b + pa->c ;
/*
movl 4(%esp), %eax // extra pointer dereference
movl (%eax), %edx
movl (%edx), %eax
leal 1(%eax), %ecx
movl %ecx, (%edx)
movl 4(%edx), %eax
subl $1, %eax
movl %eax, 4(%edx)
addl %ecx, %eax
addl 8(%edx), %eax
ret
*/
}
int foobar( std::unique_ptr<A> pa )
{
return ++pa->a + --pa->b + pa->c ;
/*
movl 4(%esp), %eax // extra pointer dereference
movl (%eax), %edx
movl (%edx), %eax
leal 1(%eax), %ecx
movl %ecx, (%edx)
movl 4(%edx), %eax
subl $1, %eax
movl %eax, 4(%edx)
addl %ecx, %eax
addl 8(%edx), %eax
ret
*/
}
|