netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [INET] Optimise away a branch in IP_ECN_set_ce
@ 2004-09-09  0:03 Herbert Xu
  2004-09-09  0:24 ` YOSHIFUJI Hideaki / 吉藤英明
  0 siblings, 1 reply; 10+ messages in thread
From: Herbert Xu @ 2004-09-09  0:03 UTC (permalink / raw)
  To: David S. Miller, netdev

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]

Hi Dave:

I was bored so here is a patch that optimises away a branch in
IP_ECN_set_ce.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[-- Attachment #2: p --]
[-- Type: text/plain, Size: 1076 bytes --]

===== 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 09:51:08 +10:00
@@ -49,19 +49,27 @@
 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 += __constant_htons(0xFFFD)
+	 * INET_ECN_ECT_0 => check += __constant_htons(0xFFFE)
+	 */
+	if (__constant_htons(1) != 1)
+		ecn <<= 8;
+	check += __constant_htons(0xFFFB) + ecn;
+
 	iph->check = check + (check>=0xFFFF);
 	iph->tos |= INET_ECN_CE;
 }

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-09-09  4:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-09  0:03 [INET] Optimise away a branch in IP_ECN_set_ce Herbert Xu
2004-09-09  0:24 ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-09  0:27   ` Arnaldo Carvalho de Melo
2004-09-09  0:36     ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-09  0:53       ` Arnaldo Carvalho de Melo
2004-09-09  1:10   ` Herbert Xu
2004-09-09  1:27     ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-09  1:54       ` Herbert Xu
2004-09-09  1:58         ` YOSHIFUJI Hideaki / 吉藤英明
2004-09-09  4:35           ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).