On 08.7.2010 11:02:10, Maksym Kryzhanovskyy wrote:
> On 08.7.2010 02:37:35, Denys Vlasenko wrote:
> > On Wednesday 07 July 2010 12:58, Maksym Kryzhanovskyy wrote:
> > > Hi Denis,
> > > 
> > > can we use the __builtin_expect function in busybox?
> > > In the previous patch for ifplugd it might be usefull
> > > (see attachment).
> > 
> > -       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.
> 

.. you're right it is for nothing, detect_link with __builtin_expect
 is the same as without it. It is seen from the code in attachment.

> 
> Yes, it's not for reducing the size of ifplugd, but we wanted to ask gcc to
> optimize the if statment for a negative result (moreover, it costs nothing in
> terms of size):
> 
> if (!G.detect_link_func) { // predominantly negative throughout life of 
> ifplugd
> 
> 
> This may be unlikely() if it is more readable as Marek Polacek
> and Bernhard Fischer-Reutner offers:
> 
> #define unlikely(x) __builtin_expect(!!(x), 0)
> if (unlikely(G.detect_link_func == NULL)) {
> 
> 
> If it is actually needed..
> 
> 
> Max.
> 
> > -- 
> > vda
> > 
> > 
> > 
> 
> 
detect_link:
        pushl   %edi
        pushl   %esi
        pushl   %ebx
        subl    $4, %esp
        movl    ptr_to_globals, %ebx
        cmpb    $0, 2(%ebx)
        movl    option_mask32, %eax
        jne     .L66
        andl    $65536, %eax
        cmpl    $1, %eax
        sbbl    %eax, %eax
        jmp     .L68
.L66:
        testb   $1, %al
        jne     .L69
        call    up_iface
.L69:
        cmpl    $0, 32(%ebx)
        jne     .L70
        movb    3(%ebx), %al
        testb   %al, %al
        jne     .L71
        movb    logmode, %dl
        xorl    %esi, %esi
.L74:
        movb    $0, logmode
        movl    method.8477+4(,%esi,8), %edi
        movb    %dl, (%esp)
        call    *%edi
        movb    (%esp), %dl
        movb    %dl, logmode
        cmpb    $-1, %al
        je      .L72
        movl    %edi, 32(%ebx)
        pushl   method.8477(,%esi,8)
        pushl   $.LC14
        movb    %al, 8(%esp)
        call    bb_error_msg
        popl    %edi
        popl    %eax
        movb    (%esp), %al
        jmp     .L73
.L72:
        incl    %esi
        cmpl    $5, %esi
        jne     .L74
        jmp     .L75
.L71:
        movsbl  %al,%eax
        movl    method.8477-4(,%eax,8), %eax
        movl    %eax, 32(%ebx)
.L70:
        call    *32(%ebx)
.L76:
        cmpb    $-1, %al
        jne     .L73
.L75:
        movl    option_mask32, %edx
        xorl    %eax, %eax
        testb   $8, %dl
        jne     .L73
        movb    $1, %al
        andb    $16, %dl
        jne     .L73
        movb    $-1, %al
        cmpb    $0, 3(%ebx)
        jne     .L73
        pushl   $.LC15
        call    bb_error_msg
        movb    $-1, %al
        popl    %esi
.L73:
        movb    (%ebx), %dl
        cmpb    %dl, %al
        je      .L68
        movb    %dl, 1(%ebx)
        movb    %al, (%ebx)
.L68:
        popl    %ecx
        popl    %ebx
        popl    %esi
        popl    %edi
        ret
detect_link:
        pushl   %edi
        pushl   %esi
        pushl   %ebx
        subl    $4, %esp
        movl    ptr_to_globals, %ebx
        cmpb    $0, 2(%ebx)
        movl    option_mask32, %eax
        jne     .L66
        andl    $65536, %eax
        cmpl    $1, %eax
        sbbl    %eax, %eax
        jmp     .L68
.L66:
        testb   $1, %al
        jne     .L69
        call    up_iface
.L69:
        cmpl    $0, 32(%ebx)
        jne     .L70
        movb    3(%ebx), %al
        testb   %al, %al
        jne     .L71
        movb    logmode, %dl
        xorl    %esi, %esi
.L74:
        movb    $0, logmode
        movl    method.8477+4(,%esi,8), %edi
        movb    %dl, (%esp)
        call    *%edi
        movb    (%esp), %dl
        movb    %dl, logmode
        cmpb    $-1, %al
        je      .L72
        movl    %edi, 32(%ebx)
        pushl   method.8477(,%esi,8)
        pushl   $.LC14
        movb    %al, 8(%esp)
        call    bb_error_msg
        popl    %edi
        popl    %eax
        movb    (%esp), %al
        jmp     .L73
.L72:
        incl    %esi
        cmpl    $5, %esi
        jne     .L74
        jmp     .L75
.L71:
        movsbl  %al,%eax
        movl    method.8477-4(,%eax,8), %eax
        movl    %eax, 32(%ebx)
.L70:
        call    *32(%ebx)
.L76:
        cmpb    $-1, %al
        jne     .L73
.L75:
        movl    option_mask32, %edx
        xorl    %eax, %eax
        testb   $8, %dl
        jne     .L73
        movb    $1, %al
        andb    $16, %dl
        jne     .L73
        movb    $-1, %al
        cmpb    $0, 3(%ebx)
        jne     .L73
        pushl   $.LC15
        call    bb_error_msg
        movb    $-1, %al
        popl    %esi
.L73:
        movb    (%ebx), %dl
        cmpb    %dl, %al
        je      .L68
        movb    %dl, 1(%ebx)
        movb    %al, (%ebx)
.L68:
        popl    %ecx
        popl    %ebx
        popl    %esi
        popl    %edi
        ret
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to