46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* $NetBSD: in_cksum.c,v 1.7 1997/09/02 13:18:15 thorpej Exp $ */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Copyright (c) 1988, 1992, 1993
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The Regents of the University of California. All rights reserved.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Copyright (c) 1996
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Matt Thomas <matt@3am-software.com>
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Redistribution and use in source and binary forms, with or without
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * modification, are permitted provided that the following conditions
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 1. Redistributions of source code must retain the above copyright
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * notice, this list of conditions and the following disclaimer.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 2. Redistributions in binary form must reproduce the above copyright
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * notice, this list of conditions and the following disclaimer in the
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * documentation and/or other materials provided with the distribution.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 3. All advertising materials mentioning features or use of this software
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * must display the following acknowledgement:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * This product includes software developed by the University of
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * California, Berkeley and its contributors.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 4. Neither the name of the University nor the names of its contributors
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * may be used to endorse or promote products derived from this software
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * without specific prior written permission.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * SUCH DAMAGE.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync__FBSDID("$FreeBSD: src/sys/amd64/amd64/in_cksum.c,v 1.5.20.1 2009/04/15 03:14:26 kensmith Exp $");
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Checksum routine for Internet Protocol family headers
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * (Portable Alpha version).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * This routine is very heavily used in the network
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * code and should be modified for each CPU to be as fast as possible.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync sum = q_util.s[0] + q_util.s[1] + q_util.s[2] + q_util.s[3]; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync l_util.l = q_util.s[0] + q_util.s[1] + q_util.s[2] + q_util.s[3]; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync 0x00000000, 0x000000FF, 0x0000FFFF, 0x00FFFFFF, /* offset 0 */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync 0x00000000, 0x0000FF00, 0x00FFFF00, 0xFFFFFF00, /* offset 1 */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync 0x00000000, 0x00FF0000, 0xFFFF0000, 0xFFFF0000, /* offset 2 */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync 0x00000000, 0xFF000000, 0xFF000000, 0xFF000000, /* offset 3 */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync sum = (u_int64_t) lw[0] + lw[1] + lw[2] + lw[3] + lw[4];
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (len <= 0) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Force to cache line boundary.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * access prefilling to start load of next cache line.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * then add current cache line
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * save result of prefilling for loop iteration.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (len >= 0) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m->m_len == 0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int64_t sum = in_cksumdata(ip, sizeof(struct ip));