This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Alternative to named return value extension is worse.


I have compiled a simple routine with named return
value extension with gcc v3.03 (DJGPP environment)
and results that it is a bit more efficient to use
this extension than not to use it. 
(gxx file.cpp -O2 -S )
Therefore I think that the alternative to return value
extension is not superior, as says in the info docs...
It is just a little bit worse (In what efficiency
concerns, at least in this example).

Here is the code:

//-----------------------------
struct te{
    int* q;
    te(void){q=new (int);}
    te(int a){q=new (int);*q=a;}
    te operator+(const te &a);
    ~te(void){delete q;}
};/*
te te::operator+(const te &a){
    return te(*q+*a.q);
}*/
te te::operator+(const te &a) return r{
    *r.q=*q+*a.q;
    }
//-----------------------------

you can uncomment the other version of operator+
to get the other code.

the assembler with the extension is 21 instructions 
long:

__ZN2teplERKS_:
LFB1:
	pushl	%ebp
LCFI0:
	movl	%esp, %ebp
LCFI1:
	pushl	%ebx
LCFI2:
	subl	$16, %esp
LCFI3:
	movl	8(%ebp), %ebx
	pushl	$4
LCFI4:
	call	__Znwm
	movl	12(%ebp), %edx
	addl	$16, %esp
	movl	%eax, (%ebx)
	movl	(%edx), %ecx
	movl	16(%ebp), %edx
	movl	(%edx), %edx
	movl	(%edx), %edx
	addl	(%ecx), %edx
	movl	%edx, (%eax)
	movl	%ebx, %eax
	movl	-4(%ebp), %ebx
	movl	%ebp, %esp
	popl	%ebp
	ret	$4

and without the extension it is 24 lines long.

__ZN2teplERKS_:
LFB1:
	pushl	%ebp
LCFI0:
	movl	%esp, %ebp
LCFI1:
	pushl	%esi
LCFI2:
	pushl	%ebx
LCFI3:
	movl	12(%ebp), %eax
	subl	$12, %esp
	movl	8(%ebp), %esi
	movl	(%eax), %edx
	movl	16(%ebp), %eax
	movl	(%eax), %eax
	movl	(%eax), %ebx
	movl	(%edx), %eax
	addl	%eax, %ebx
	pushl	$4
LCFI4:
	call	__Znwm
	addl	$16, %esp
	movl	%eax, (%esi)
	movl	%ebx, (%eax)
	leal	-8(%ebp), %esp
	movl	%esi, %eax
	popl	%ebx
	popl	%esi
	popl	%ebp
	ret	$4

> Date: Tue, 14 Nov 2000 19:30:25 +0100
> From: Carlo Wood <carlo@alinoe.com>
> To: gcc@gcc.gnu.org

.....
.....
> Can someone tell me what the "superior alternative"
is for
> the named return value extension?

Sure.  The Standardization committee deliberated at
length about this
and came up with a solution.  The Standard permits the
compiler to
optimize in several places were it wasn't permitted
before.  Because
the compiler can now optimize objects in these more
interesting ways,
the extension, which was merely a way of telling the
compiler it was
ok to optimize, is largely unnecessary.  I won't try
and recite all
the specifics about where the compiler can now
optimize (I wouldn't
want to get it wrong), but instead I would refer you
to the Standard
(cop out), or comp.std.c++.  A quick glance turns up:

.....
....




_______________________________________________________________
Do You Yahoo!?
Yahoo! Messenger
Comunicación instantánea gratis con tu gente.
http://messenger.yahoo.es


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]