* optimizing wrapper functions
@ 1998-12-05 13:04 Zack Weinberg
0 siblings, 0 replies; 3+ messages in thread
From: Zack Weinberg @ 1998-12-05 13:04 UTC (permalink / raw)
To: egcs
When writing code that loads dynamic modules, you might do something
like this:
int (*real_foo)(int, int);
int
foo(int a, int b)
{
if(real_foo)
return real_foo(a, b);
try_to_load_real_foo();
if(real_foo)
return real_foo(a, b);
return -1;
}
It would be nice if this could be optimized down to something like
this (or this but with a frame pointer):
foo:
movl real_foo, %eax
testl %eax, %eax
jne *%eax
call try_to_load_real_foo
movl real_foo, %eax
testl %eax, %eax
jne *%eax
movl $-1, %eax
ret
Instead, I get this:
foo:
pushl %esi
pushl %ebx
movl real_foo,%eax
movl 12(%esp),%esi
movl 16(%esp),%ebx
testl %eax,%eax
jne call_it
call try_to_load_real_foo
movl real_foo,%eax
testl %eax,%eax
je fail
call_it:
pushl %ebx
pushl %esi
call *%eax
addl $8,%esp
jmp done
fail:
movl $-1,%eax
done:
popl %ebx
popl %esi
ret
I guess GCC would have to recognize that the called function had an
identical prototype to the wrapper, and was being called with the
wrapper's arguments, to pull this off.
zw
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: optimizing wrapper functions
1998-12-05 15:21 ` Jason Merrill
@ 1998-12-05 15:39 ` Zack Weinberg
0 siblings, 0 replies; 3+ messages in thread
From: Zack Weinberg @ 1998-12-05 15:39 UTC (permalink / raw)
To: Jason Merrill, egcs
On 05 Dec 1998 15:20:40 -0800, Jason Merrill wrote:
>>>>>> Zack Weinberg <zack@rabi.columbia.edu> writes:
>
> > [avoid setting up the call again for a wrapper function]
>
>I like this idea.
>
> > I guess GCC would have to recognize that the called function had an
> > identical prototype to the wrapper, and was being called with the
> > wrapper's arguments, to pull this off.
>
>Yep. And that the arguments are only used under certain conditions in the
>rest of the function. This would render the 'current_function_is_thunk'
>support redundant.
Actually, would it do the trick if the C front end could recognize this
pattern and set current_function_is_thunk? That flag's only set for
internally generated code right now and I don't know the constraints
on its use.
zw
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: optimizing wrapper functions
[not found] <199812052104.QAA03955.cygnus.egcs@blastula.phys.columbia.edu>
@ 1998-12-05 15:21 ` Jason Merrill
1998-12-05 15:39 ` Zack Weinberg
0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 1998-12-05 15:21 UTC (permalink / raw)
To: Zack Weinberg, egcs
>>>>> Zack Weinberg <zack@rabi.columbia.edu> writes:
> [avoid setting up the call again for a wrapper function]
I like this idea.
> I guess GCC would have to recognize that the called function had an
> identical prototype to the wrapper, and was being called with the
> wrapper's arguments, to pull this off.
Yep. And that the arguments are only used under certain conditions in the
rest of the function. This would render the 'current_function_is_thunk'
support redundant.
Not that I'm going to have any time to work on this, mind you.
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-12-05 15:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-05 13:04 optimizing wrapper functions Zack Weinberg
[not found] <199812052104.QAA03955.cygnus.egcs@blastula.phys.columbia.edu>
1998-12-05 15:21 ` Jason Merrill
1998-12-05 15:39 ` Zack Weinberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).