Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys be friendly with gcc-3.1.1 -O2, which takes advantage of...



details:   https://anonhg.NetBSD.org/src/rev/6b859b4b3f1f
branches:  trunk
changeset: 534550:6b859b4b3f1f
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jul 29 09:14:36 2002 +0000

description:
be friendly with gcc-3.1.1 -O2, which takes advantage of ANSI C
pointer aliasing rule (gcc optimization/7427).  from tsubai, sync w/kame

diffstat:

 sys/arch/mips/mips/in_cksum.c       |  19 +++++++++++--------
 sys/arch/powerpc/powerpc/in_cksum.c |  19 +++++++++++--------
 sys/netinet/in4_cksum.c             |  22 ++++++++++++----------
 3 files changed, 34 insertions(+), 26 deletions(-)

diffs (121 lines):

diff -r cd1720567df7 -r 6b859b4b3f1f sys/arch/mips/mips/in_cksum.c
--- a/sys/arch/mips/mips/in_cksum.c     Mon Jul 29 07:42:52 2002 +0000
+++ b/sys/arch/mips/mips/in_cksum.c     Mon Jul 29 09:14:36 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_cksum.c,v 1.8 2002/06/01 11:41:33 simonb Exp $ */
+/* $NetBSD: in_cksum.c,v 1.9 2002/07/29 09:14:36 itojun Exp $ */
 
 /*
  * Copyright (c) 1993 Regents of the University of California.
@@ -284,15 +284,18 @@
 
        if (nxt != 0) {
                uint16_t *w;
-               struct ipovly ipov;
+               union {
+                       struct ipovly ipov;
+                       u_int16_t w[10];
+               } u;
 
                /* pseudo header */
-               memset(&ipov, 0, sizeof(ipov));
-               ipov.ih_len = htons(len);
-               ipov.ih_pr = nxt;
-               ipov.ih_src = mtod(m, struct ip *)->ip_src;
-               ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
-               w = (uint16_t *)&ipov;
+               memset(&u.ipov, 0, sizeof(u.ipov));
+               u.ipov.ih_len = htons(len);
+               u.ipov.ih_pr = nxt;
+               u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
+               u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+               w = u.w;
                /* assumes sizeof(ipov) == 20 */
                sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
                sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
diff -r cd1720567df7 -r 6b859b4b3f1f sys/arch/powerpc/powerpc/in_cksum.c
--- a/sys/arch/powerpc/powerpc/in_cksum.c       Mon Jul 29 07:42:52 2002 +0000
+++ b/sys/arch/powerpc/powerpc/in_cksum.c       Mon Jul 29 09:14:36 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_cksum.c,v 1.3 2001/06/13 06:01:50 simonb Exp $      */
+/*     $NetBSD: in_cksum.c,v 1.4 2002/07/29 09:14:37 itojun Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -237,16 +237,19 @@
 {
        uint16_t *w;
        u_int sum = 0;
-       struct ipovly ipov;
+       union {
+               struct ipovly ipov;
+               u_int16_t w[10];
+       } u;
 
        if (nxt != 0) {
                /* pseudo header */
-               memset(&ipov, 0, sizeof(ipov));
-               ipov.ih_len = htons(len);
-               ipov.ih_pr = nxt; 
-               ipov.ih_src = mtod(m, struct ip *)->ip_src; 
-               ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
-               w = (uint16_t *)&ipov;
+               memset(&u.ipov, 0, sizeof(u.ipov));
+               u.ipov.ih_len = htons(len);
+               u.ipov.ih_pr = nxt; 
+               u.ipov.ih_src = mtod(m, struct ip *)->ip_src; 
+               u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+               w = u.w;
                /* assumes sizeof(ipov) == 20 */
                sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
                sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
diff -r cd1720567df7 -r 6b859b4b3f1f sys/netinet/in4_cksum.c
--- a/sys/netinet/in4_cksum.c   Mon Jul 29 07:42:52 2002 +0000
+++ b/sys/netinet/in4_cksum.c   Mon Jul 29 09:14:36 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in4_cksum.c,v 1.8 2001/12/21 02:50:28 itojun Exp $     */
+/*     $NetBSD: in4_cksum.c,v 1.9 2002/07/29 09:14:37 itojun Exp $     */
 
 /*
  * Copyright (C) 1999 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.8 2001/12/21 02:50:28 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.9 2002/07/29 09:14:37 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -101,8 +101,10 @@
        int sum = 0;
        int mlen = 0;
        int byte_swapped = 0;
-       struct ipovly ipov;
-
+       union {
+               struct ipovly ipov;
+               u_int16_t w[10];
+       } u;
        union {
                u_int8_t  c[2];
                u_int16_t s;
@@ -118,12 +120,12 @@
                        panic("in4_cksum: offset too short");
                if (m->m_len < sizeof(struct ip))
                        panic("in4_cksum: bad mbuf chain");
-               bzero(&ipov, sizeof(ipov));
-               ipov.ih_len = htons(len);
-               ipov.ih_pr = nxt;
-               ipov.ih_src = mtod(m, struct ip *)->ip_src;
-               ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
-               w = (u_int16_t *)&ipov;
+               bzero(&u.ipov, sizeof(u.ipov));
+               u.ipov.ih_len = htons(len);
+               u.ipov.ih_pr = nxt;
+               u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
+               u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+               w = u.w;
                /* assumes sizeof(ipov) == 20 */
                sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
                sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];



Home | Main Index | Thread Index | Old Index