From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7918 invoked by alias); 7 Jul 2002 15:03:10 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 7911 invoked from network); 7 Jul 2002 15:03:08 -0000 Received: from unknown (HELO www.linux.org.uk) (195.92.249.252) by sources.redhat.com with SMTP; 7 Jul 2002 15:03:08 -0000 Received: from willy by www.linux.org.uk with local (Exim 3.33 #5) id 17RDZ5-0005im-00; Sun, 07 Jul 2002 16:03:07 +0100 Date: Sun, 07 Jul 2002 10:03:00 -0000 From: Matthew Wilcox To: Wink Saville Cc: gcc@gcc.gnu.org Subject: Re: More space efficient virtual function calls Message-ID: <20020707160307.K27706@parcelfarce.linux.theplanet.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i X-SW-Source: 2002-07/txt/msg00311.txt.bz2 On Sat, 6 Jul 2002 17:29:11 -0700, Wink Saville wrote: > I was wondering if there was switch in gcc that would cause it to generate > smaller code when invoking virtual functions. I'm using GCC 3.1 ARM cross > compiler with -O3 and -fvtable-thunks=3, and it does the following when > calling a virtual function with no parameters: > > LDR R1,[R4] /* Fetch the vtable pointer */ > MOV R0,R4 /* R0 = this */ > MOV LR, PC /* Set of the link register */ > LDR PC,[R1, #4] /* Call virtual function 1, the second entry */ > > This is good code but it takes 20 bytes, what I was hoping for when I > enabled -fvtable-thunks=3 the compiler would use intermediate "thunks" to > invoke functions such as: > > LDR R0,R4 /* R0 = this */ > BL __VTFunc1 /* Branch and Link to virtual thunk function 1 */ > > ... > > __VTFunc0: > MOV R5,[R0] /* Get vtable pointer */ > LDR PC,[R5,#0] /* Jump to the function */ > __VTFunc1: > MOV R5,[R0] /* Get vtable pointer */ > LDR PC,[R5,#4] /* Jump to the function */ > __VTFunc2: > MOV R5,[R0] /* Get vtable pointer */ > LDR PC,[R5,#8] /* Jump to the function */ The current code takes 16 bytes, not 20. The proposed code above is buggy; I think what you meant was: MOV r0, r4 /* r0 = this */ BL __VTFunc1 ... __VTFunc0: LDR r5, [r0] /* fetch vtable pointer */ LDR pc, [r5, #0] /* jump to the function */ __VTFunc1: LDR r5, [r0] LDR pc, [r5, #4] __VTFunc2: LDR r5, [r0] LDR pc, [r5, #8] if you use a call-clobbered register instead of r5 (i don't remember the apcs right now), you don't even need to reserve r5. i have no idea how to change gcc to do what you want though ;-) -- Revolutions do not require corporate support.