Received: with ECARTIS (v1.0.0; list netdev); Wed, 08 Sep 2004 18:55:19 -0700 (PDT) Received: from arnor.apana.org.au (mail@arnor.apana.org.au [203.14.152.115]) by oss.sgi.com (8.13.0/8.13.0) with ESMTP id i891t9Vs032646 for ; Wed, 8 Sep 2004 18:55:10 -0700 Received: from gondolin.me.apana.org.au ([192.168.0.6] ident=mail) by arnor.apana.org.au with esmtp (Exim 3.35 #1 (Debian)) id 1C5E97-00018B-00; Thu, 09 Sep 2004 11:54:45 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 3.36 #1 (Debian)) id 1C5E94-0003g6-00; Thu, 09 Sep 2004 11:54:42 +1000 Date: Thu, 9 Sep 2004 11:54:42 +1000 To: "YOSHIFUJI Hideaki / ?$B5HF#1QL@" Cc: davem@redhat.com, netdev@oss.sgi.com Subject: Re: [INET] Optimise away a branch in IP_ECN_set_ce Message-ID: <20040909015442.GA12935@gondor.apana.org.au> References: <20040909000330.GA5581@gondor.apana.org.au> <20040909.092428.125540781.yoshfuji@linux-ipv6.org> <20040909011016.GA9238@gondor.apana.org.au> <20040909.102736.94408944.yoshfuji@linux-ipv6.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="vkogqOf2sHV7VnPd" Content-Disposition: inline In-Reply-To: <20040909.102736.94408944.yoshfuji@linux-ipv6.org> User-Agent: Mutt/1.5.6+20040722i From: Herbert Xu X-archive-position: 8533 X-ecartis-version: Ecartis v1.0.0 Sender: netdev-bounce@oss.sgi.com Errors-to: netdev-bounce@oss.sgi.com X-original-sender: herbert@gondor.apana.org.au Precedence: bulk X-list: netdev Content-Length: 1993 Lines: 73 --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Sep 09, 2004 at 10:27:36AM +0900, YOSHIFUJI Hideaki / ?$B5HF#1QL@ wrote: > > > > And, I think > > > u16 ecn = (iph->tos + 1) & INET_ECN_MASK; > > > check += (u32)htons(0xfffb) + (u32)htons(ecn); > > > > The second htons is less optimal than the shift because htons doesn't > > know that ecn is only a byte. So it'll end up doing a full swap. > > Not true; gcc is clever enough to produces same code, and my code looks better. Sorry, you're right. Here is an updated patch. Signed-off-by: Herbert Xu Thanks, -- Visit Openswan at http://www.openswan.org/ Email: Herbert Xu ~{PmV>HI~} Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p ===== include/net/inet_ecn.h 1.7 vs edited ===== --- 1.7/include/net/inet_ecn.h 2004-09-09 08:04:37 +10:00 +++ edited/include/net/inet_ecn.h 2004-09-09 11:45:45 +10:00 @@ -49,19 +49,25 @@ static inline void IP_ECN_set_ce(struct iphdr *iph) { u32 check = iph->check; + u32 ecn = (iph->tos + 1) & INET_ECN_MASK; - switch (iph->tos & INET_ECN_MASK) { - default: - case INET_ECN_NOT_ECT: - case INET_ECN_CE: + /* + * After the last operation we have (in binary): + * INET_ECN_NOT_ECT => 01 + * INET_ECN_ECT_1 => 10 + * INET_ECN_ECT_0 => 11 + * INET_ECN_CE => 00 + */ + if (!(ecn & 2)) return; - case INET_ECN_ECT_1: - check += __constant_htons(0xFFFD); - break; - case INET_ECN_ECT_0: - check += __constant_htons(0xFFFE); - break; - } + + /* + * The following gives us: + * INET_ECN_ECT_1 => check += htons(0xFFFD) + * INET_ECN_ECT_0 => check += htons(0xFFFE) + */ + check += htons(0xFFFB) + htons(ecn); + iph->check = check + (check>=0xFFFF); iph->tos |= INET_ECN_CE; } --vkogqOf2sHV7VnPd--