This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33358] New: Slow calls through simple member function pointers
- From: "dleska at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Sep 2007 20:06:41 -0000
- Subject: [Bug c++/33358] New: Slow calls through simple member function pointers
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Hi,
By simple MFPs I mean those that point to a class with single or no inheritance
and the class is fully defined at the time of the call. For example:
class SomeClass {};
typedef void (SomeClass::*MemberFunc)();
void callMemberFunc(SomeClass *object, MemberFunc func)
{
(object->*func)();
}
g++ seems to generate the same code whether SomeClass is a complete type or
not. In the above example, VS 2005 can significantly optimise the call when
SomeClass is defined:
00424D40 mov ecx,dword ptr [esp+4]
00424D44 jmp dword ptr [esp+8]
g++ 4.2.1 generates the following:
.file "test.cpp"
.text
.align 2
.p2align 4,,15
.globl __Z12callDelegateRN12fastdelegate12FastDelegateIFvvEEE
.def __Z12callDelegateRN12fastdelegate12FastDelegateIFvvEEE; .scl
2; .type 32; .endef
__Z12callDelegateRN12fastdelegate12FastDelegateIFvvEEE:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl 8(%ebp), %eax
movl 4(%eax), %ecx
movl (%eax), %ebx
movl 8(%eax), %edx
testb $1, %cl
je L7
leal (%ebx,%edx), %edx
movl (%edx), %eax
movl -1(%eax,%ecx), %ecx
movl %edx, 8(%ebp)
popl %ebx
popl %ebp
jmp *%ecx
.p2align 4,,7
L7:
leal (%ebx,%edx), %edx
movl %edx, 8(%ebp)
popl %ebx
popl %ebp
jmp *%ecx
I've reproduced this on 4.2.1 and 3.4.2 on x86 (MinGW) and 4.1.1, 4.1.0, 4.0.1
and 3.4.4 on arm/thumb.
Would it be possible for gcc to optimise such calls?
--
Summary: Slow calls through simple member function pointers
Product: gcc
Version: 4.2.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dleska at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33358