public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+lkml@arm.linux.org.uk>
To: Michal Srajer <michal@mat.uni.torun.pl>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] include/linux/etherdevice.h, kernel 2.6.14
Date: Sat, 29 Oct 2005 15:17:57 +0100	[thread overview]
Message-ID: <20051029141757.GA14039@flint.arm.linux.org.uk> (raw)
In-Reply-To: <20051029141046.GA17715@ultra60.mat.uni.torun.pl>

On Sat, Oct 29, 2005 at 04:10:46PM +0200, Michal Srajer wrote:
> Description: Very small optimization patch for include/linux/etherdevice.h in 2.6.14 kernel.

How is this an optimisation?

typedef unsigned char u8;
 
static int is_zero_ether_addr1(const u8 *addr)
{
       return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
}
 
static int is_zero_ether_addr2(const u8 *addr)
{
       return !(addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5]);
}

produces on x86:

is_zero_ether_addr1:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        movb    1(%edx), %al
        orb     (%edx), %al
        orb     2(%edx), %al
        orb     3(%edx), %al
        orb     4(%edx), %al
        orb     5(%edx), %al
        sete    %al
        movzbl  %al, %eax
        leave
        ret

is_zero_ether_addr2:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        xorl    %eax, %eax
        cmpb    $0, (%edx)
        jne     .L3
        cmpb    $0, 1(%edx)
        jne     .L3
        cmpb    $0, 2(%edx)
        jne     .L3
        cmpb    $0, 3(%edx)
        jne     .L3
        cmpb    $0, 4(%edx)
        jne     .L3
        cmpb    $0, 5(%edx)
        jne     .L3
        movl    $1, %eax
.L3:
        leave
        ret

and on ARM:

is_zero_ether_addr1:
        ldrb    r1, [r0, #1]    @ zero_extendqisi2
        ldrb    r3, [r0, #0]    @ zero_extendqisi2
        ldrb    r2, [r0, #2]    @ zero_extendqisi2
        orr     r3, r3, r1
        ldrb    r1, [r0, #3]    @ zero_extendqisi2
        orr     r2, r2, r3
        ldrb    r3, [r0, #4]    @ zero_extendqisi2
        orr     r1, r1, r2
        ldrb    r2, [r0, #5]    @ zero_extendqisi2
        orr     r3, r3, r1
        orrs    r2, r2, r3
        movne   r0, #0
        moveq   r0, #1
        mov     pc, lr

is_zero_ether_addr2:
        ldrb    r3, [r0, #0]    @ zero_extendqisi2
        mov     r2, #0
        cmp     r3, r2
        bne     .L3
        ldrb    r3, [r0, #1]    @ zero_extendqisi2
        cmp     r3, r2
        bne     .L3
        ldrb    r3, [r0, #2]    @ zero_extendqisi2
        cmp     r3, r2
        bne     .L3
        ldrb    r3, [r0, #3]    @ zero_extendqisi2
        cmp     r3, r2
        bne     .L3
        ldrb    r3, [r0, #4]    @ zero_extendqisi2
        cmp     r3, r2
        bne     .L3
        ldrb    r3, [r0, #5]    @ zero_extendqisi2
        cmp     r3, r2
        movne   r2, #0
        moveq   r2, #1
.L3:
        mov     r0, r2
        mov     pc, lr

The former looks far more optimised in both cases.  In fact, the
latter on ARM is many times less efficient due to the LDR result
delays being incurred for every test.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

  reply	other threads:[~2005-10-29 14:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-29 14:10 [PATCH] include/linux/etherdevice.h, kernel 2.6.14 Michal Srajer
2005-10-29 14:17 ` Russell King [this message]
     [not found]   ` <20051029154027.GC17715@ultra60.mat.uni.torun.pl>
2005-10-29 16:00     ` Russell King
2005-10-29 21:36       ` J.A. Magallon
2005-10-30 10:22         ` Eric Piel
2005-10-30 10:46         ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051029141757.GA14039@flint.arm.linux.org.uk \
    --to=rmk+lkml@arm.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal@mat.uni.torun.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox