> Denys Vlasenko wrote:
> > > On Wednesday 07 July 2010 12:58, Maksym Kryzhanovskyy wrote:
> > >
> >> >> Hi Denis,
> >> >>
> >> >> can we use the __builtin_expect function in busybox?
> >> >>
> > > - if (!G.detect_link_func) {
> > > + if (__builtin_expect(G.detect_link_func == NULL, 0)) {
> > >
> > > I don't see any changes in size, only obfuscated code.
> > >
> I think the main point of __builtin_expect is to make the code faster by
> telling the compiler which branch is more likely, not to make the
> assembly code smaller or easier to read.
> Actually I would expect the above sequence to require an extra jump,
> making the code bigger.
>
> Ralf
>
when we use the __builtin_expect in smaller code,
the compiler adds a few extra instructions (the result
should be slightly larger):
if (detect_link_func == 0)
testl %eax, %eax
jne .L4
if (__builtin_expect(detect_link_func == 0, 0))
testl %eax, %eax
sete %al
movzbl %al, %eax
testl %eax, %eax
je .L4
Is it intentionally turned off in busybox?
cat >> a.c << EOF
int (*detect_link_func)(void) = 0;
static int detect_link_0(void)
{
return 0;
}
static int detect_link(void)
{
// if (detect_link_func == 0)
if (__builtin_expect(detect_link_func == 0, 0))
detect_link_func = detect_link_0;
return detect_link_func();
}
int main(void)
{
detect_link();
return 0;
}
EOF
gcc -std=c99 -pedantic -Wall -save-temps -c a.c
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox