Maksym Kryzhanovskyy wrote:
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.
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
If you want small code, you should turn on optimization.
Also, it seems that GCC doesn't rearrange the code when optimizing for
size (-Os) if that would result in bigger code (and it would, for an
"if" without "else").
Try these versions and see the resulting files:
$ gcc -Os -S a.c
$ gcc -O2 -S a.c
Ralf
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox