Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc/powerpc - Care about carry bit when adding ...



details:   https://anonhg.NetBSD.org/src/rev/6cd829c33806
branches:  trunk
changeset: 534873:6cd829c33806
user:      enami <enami%NetBSD.org@localhost>
date:      Mon Aug 05 02:55:39 2002 +0000

description:
- Care about carry bit when adding short value to force 4 byte boundary.
  It may contain any 32 bit value there.
- Use correct instruction to clear carry bit.
- Don't use series of load with update instruction.  It's slower.

diffstat:

 sys/arch/powerpc/powerpc/in_cksum.c |  137 ++++++++++++++++++-----------------
 1 files changed, 72 insertions(+), 65 deletions(-)

diffs (178 lines):

diff -r 7f85720114e2 -r 6cd829c33806 sys/arch/powerpc/powerpc/in_cksum.c
--- a/sys/arch/powerpc/powerpc/in_cksum.c       Mon Aug 05 02:18:43 2002 +0000
+++ b/sys/arch/powerpc/powerpc/in_cksum.c       Mon Aug 05 02:55:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_cksum.c,v 1.4 2002/07/29 09:14:37 itojun Exp $      */
+/*     $NetBSD: in_cksum.c,v 1.5 2002/08/05 02:55:39 enami Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -62,6 +62,7 @@
        uint8_t *w;
        int mlen = 0;
        int byte_swapped = 0;
+       int n;
 
        union {
                uint8_t  c[2];
@@ -103,7 +104,7 @@
                 * Force to a word boundary.
                 */
                if ((3 & (long) w) && (mlen > 0)) {
-                       if ((1 & (long) w) && (mlen > 0)) {
+                       if ((1 & (long) w)) {
                                REDUCE;
                                sum <<= 8;
                                s_util.c[0] = *w++;
@@ -111,82 +112,88 @@
                                byte_swapped = 1;
                        }
                        if ((2 & (long) w) && (mlen > 1)) {
-                               sum += *(uint16_t *)w;
+                               /*
+                                * Since the `sum' may contain full 32 bit
+                                * value, we can't simply add any value.
+                                */
+                               __asm __volatile(
+                                   "lhz 7,0(%1);"      /* load current data
+                                                          half word */
+                                   "addc %0,%0,7;"     /* add to sum */
+                                   "addze %0,%0;"      /* add carry bit */
+                                   : "+r"(sum)
+                                   : "b"(w)
+                                   : "7");             /* clobber r7 */
                                w += 2;
                                mlen -= 2;
                        }
                }
 
                if (mlen >= 64) {
-                       register int n __asm("r0");
-                       uint8_t *tmpw;
-
                        n = mlen >> 6;
-                       tmpw = w - 4;
-                       asm volatile(
-                               "addze 7,7;"            /* clear carry */
-                               "mtctr %1;"             /* load loop count */
-                               "1:"
-                               "lwzu 7,4(%2);"         /* load current data word */
-                               "lwzu 8,4(%2);"
-                               "lwzu 9,4(%2);"
-                               "lwzu 10,4(%2);"
-                               "adde %0,%0,7;"         /* add to sum */
-                               "adde %0,%0,8;"
-                               "adde %0,%0,9;"
-                               "adde %0,%0,10;"
-                               "lwzu 7,4(%2);"
-                               "lwzu 8,4(%2);"
-                               "lwzu 9,4(%2);"
-                               "lwzu 10,4(%2);"
-                               "adde %0,%0,7;"
-                               "adde %0,%0,8;"
-                               "adde %0,%0,9;"
-                               "adde %0,%0,10;"
-                               "lwzu 7,4(%2);"
-                               "lwzu 8,4(%2);"
-                               "lwzu 9,4(%2);"
-                               "lwzu 10,4(%2);"
-                               "adde %0,%0,7;"
-                               "adde %0,%0,8;"
-                               "adde %0,%0,9;"
-                               "adde %0,%0,10;"
-                               "lwzu 7,4(%2);"
-                               "lwzu 8,4(%2);"
-                               "lwzu 9,4(%2);"
-                               "lwzu 10,4(%2);"
-                               "adde %0,%0,7;"
-                               "adde %0,%0,8;"
-                               "adde %0,%0,9;"
-                               "adde %0,%0,10;"
-                               "bdnz 1b;"              /* loop */
-                               "addze %0,%0;"          /* add carry bit */
-                               : "+r"(sum)
-                               : "r"(n), "r"(tmpw)
-                               : "7", "8", "9", "10"); /* clobber r7, r8, r9, r10 */
+                       __asm __volatile(
+                           "addic 0,0,0;"              /* clear carry */
+                           "mtctr %1;"                 /* load loop count */
+                           "1:"
+                           "lwz 7,4(%2);"              /* load current data
+                                                          word */
+                           "lwz 8,8(%2);"
+                           "lwz 9,12(%2);"
+                           "lwz 10,16(%2);"
+                           "adde %0,%0,7;"             /* add to sum */
+                           "adde %0,%0,8;"
+                           "adde %0,%0,9;"
+                           "adde %0,%0,10;"
+                           "lwz 7,20(%2);"
+                           "lwz 8,24(%2);"
+                           "lwz 9,28(%2);"
+                           "lwz 10,32(%2);"
+                           "adde %0,%0,7;"
+                           "adde %0,%0,8;"
+                           "adde %0,%0,9;"
+                           "adde %0,%0,10;"
+                           "lwz 7,36(%2);"
+                           "lwz 8,40(%2);"
+                           "lwz 9,44(%2);"
+                           "lwz 10,48(%2);"
+                           "adde %0,%0,7;"
+                           "adde %0,%0,8;"
+                           "adde %0,%0,9;"
+                           "adde %0,%0,10;"
+                           "lwz 7,52(%2);"
+                           "lwz 8,56(%2);"
+                           "lwz 9,60(%2);"
+                           "lwzu 10,64(%2);"
+                           "adde %0,%0,7;"
+                           "adde %0,%0,8;"
+                           "adde %0,%0,9;"
+                           "adde %0,%0,10;"
+                           "bdnz 1b;"                  /* loop */
+                           "addze %0,%0;"              /* add carry bit */
+                           : "+r"(sum)
+                           : "r"(n), "b"(w - 4)
+                           : "7", "8", "9", "10");     /* clobber r7, r8, r9,
+                                                          r10 */
                        w += n * 64;
                        mlen -= n * 64;
                }
 
                if (mlen >= 8) {
-                       register int n __asm("r0");
-                       uint8_t *tmpw;
-
                        n = mlen >> 3;
-                       tmpw = w - 4;
-                       asm volatile(
-                               "addze %1,%1;"          /* clear carry */
-                               "mtctr %1;"             /* load loop count */
-                               "1:"
-                               "lwzu 7,4(%2);"         /* load current data word */
-                               "lwzu 8,4(%2);"
-                               "adde %0,%0,7;"         /* add to sum */
-                               "adde %0,%0,8;"
-                               "bdnz 1b;"              /* loop */
-                               "addze %0,%0;"          /* add carry bit */
-                               : "+r"(sum)
-                               : "r"(n), "r"(tmpw)
-                               : "7", "8");            /* clobber r7, r8 */
+                       __asm __volatile(
+                           "addic 0,0,0;"              /* clear carry */
+                           "mtctr %1;"                 /* load loop count */
+                           "1:"
+                           "lwz 7,4(%2);"              /* load current data
+                                                          word */
+                           "lwzu 8,8(%2);"
+                           "adde %0,%0,7;"             /* add to sum */
+                           "adde %0,%0,8;"
+                           "bdnz 1b;"                  /* loop */
+                           "addze %0,%0;"              /* add carry bit */
+                           : "+r"(sum)
+                           : "r"(n), "b"(w - 4)
+                           : "7", "8");                /* clobber r7, r8 */
                        w += n * 8;
                        mlen -= n * 8;
                }



Home | Main Index | Thread Index | Old Index