[BACK]Return to in_cksum.c CVS log [TXT][DIR] Up to [local] / sys / arch / hppa64 / hppa64

Annotation of sys/arch/hppa64/hppa64/in_cksum.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: in_cksum.c,v 1.1 2005/04/01 10:40:47 mickey Exp $     */
                      2:
                      3: /*
                      4:  * Copyright (c) 2000 Michael Shalayeff
                      5:  * All rights reserved.
                      6:  *
                      7:  * based on a sparc version of Zubin Dittia.
                      8:  * Copyright (c) 1995 Zubin Dittia.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     20:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     21:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     22:  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
                     23:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     24:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     25:  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     27:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
                     28:  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
                     29:  * THE POSSIBILITY OF SUCH DAMAGE.
                     30:  */
                     31:
                     32: #include <sys/param.h>
                     33: #include <sys/systm.h>
                     34: #include <sys/mbuf.h>
                     35: #include <netinet/in.h>
                     36:
                     37: /*
                     38:  * Checksum routine for Internet Protocol family headers.
                     39:  *
                     40:  * This routine is very heavily used in the network
                     41:  * code and should be modified for each CPU to be as fast as possible.
                     42:  *
                     43:  * HPPA version.
                     44:  */
                     45:
                     46: /* TODO optimize */
                     47:
                     48: #define ADD32  asm volatile(   "ldw 0x00(%1), %%r19! ldw 0x04(%1), %%r20\n\t" \
                     49:                                "add  %0, %%r19, %0 ! addc  %0, %%r20, %0\n\t" \
                     50:                                "ldw 0x08(%1), %%r19! ldw 0x0c(%1), %%r20\n\t" \
                     51:                                "addc %0, %%r19, %0 ! addc  %0, %%r20, %0\n\t" \
                     52:                                "ldw 0x10(%1), %%r19! ldw 0x14(%1), %%r20\n\t" \
                     53:                                "addc %0, %%r19, %0 ! addc  %0, %%r20, %0\n\t" \
                     54:                                "ldw 0x18(%1), %%r19! ldw 0x1c(%1), %%r20\n\t" \
                     55:                                "addc %0, %%r19, %0 ! addc  %0, %%r20, %0\n\t" \
                     56:                                "ldo 0x20(%1), %1   ! addc  %0, %%r0 , %0" \
                     57:                                : "+r" (sum), "+r" (w) :: "r20", "r19")
                     58: #define ADD16  asm volatile(   "ldw 0x00(%1), %%r19! ldw 0x04(%1), %%r20\n\t" \
                     59:                                "add   %0, %%r19, %0! addc  %0, %%r20, %0\n\t" \
                     60:                                "ldw 0x08(%1), %%r19! ldw 0x0c(%1), %%r20\n\t" \
                     61:                                "addc  %0, %%r19, %0! addc  %0, %%r20, %0\n\t" \
                     62:                                "ldo 0x10(%1), %1   ! addc  %0, %%r0 , %0" \
                     63:                                : "+r" (sum), "+r" (w) :: "r20", "r19")
                     64:
                     65: #define ADDCARRY       {if (sum > 0xffff) sum -= 0xffff;}
                     66: #define REDUCE         {sum = (sum & 0xffff) + (sum >> 16); ADDCARRY}
                     67: #define ROL            asm volatile ("shd %0, %0, 8, %0" : "+r" (sum))
                     68: #define ADDBYTE                {ROL; sum += *w++; bins++; mlen--;}
                     69: #define ADDSHORT       {sum += *((u_short *)w)++; mlen -= 2;}
                     70: #define ADDWORD        asm volatile(   "ldwm 4(%1), %%r19! add %0, %%r19, %0\n\t" \
                     71:                                "ldo -4(%2), %2   ! addc    %0, 0, %0" \
                     72:                                : "+r" (sum), "+r" (w), "+r" (mlen) :: "r19")
                     73:
                     74: int
                     75: in_cksum(m, len)
                     76:        register struct mbuf *m;
                     77:        register int len;
                     78: {
                     79:        register u_int sum = 0;
                     80:        register u_int bins = 0;
                     81:
                     82:        for (; m && len; m = m->m_next) {
                     83:                register int mlen = m->m_len;
                     84:                register u_char *w;
                     85:
                     86:                if (!mlen)
                     87:                        continue;
                     88:                if (len < mlen)
                     89:                        mlen = len;
                     90:                len -= mlen;
                     91:                w = mtod(m, u_char *);
                     92:
                     93:                if (mlen > 16) {
                     94:                        /*
                     95:                         * If we are aligned on a doubleword boundary
                     96:                         * do 32 bit bundled operations
                     97:                         */
                     98:                        if ((7 & (u_long)w) != 0) {
                     99:                                if ((1 & (u_long)w) != 0)
                    100:                                        ADDBYTE;
                    101:                                if ((2 & (u_long)w) != 0)
                    102:                                        ADDSHORT;
                    103:                                if ((4 & (u_long)w) != 0)
                    104:                                        ADDWORD;
                    105:                        }
                    106:
                    107:                        while ((mlen -= 32) >= 0)
                    108:                                ADD32;
                    109:
                    110:                        mlen += 32;
                    111:                        if (mlen >= 16) {
                    112:                                ADD16;
                    113:                                mlen -= 16;
                    114:                        }
                    115:                }
                    116:
                    117:                while (mlen > 0)
                    118:                        ADDBYTE;
                    119:        }
                    120:        if (bins & 1)
                    121:                ROL;
                    122:        REDUCE;
                    123:
                    124:        return (0xffff ^ sum);
                    125: }

CVSweb