?? cksum.c
字號:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/cksum.c,v 1.3 2003/01/15 14:04:31 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1993-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: cksum.c,v $ * Revision 1.3 2003/01/15 14:04:31 josh * directory structure shifting * * Revision 1.2 2001/11/08 15:56:20 tneale * Updated for newest file layout * * Revision 1.1.1.1 2001/11/05 17:48:41 tneale * Tornado shuffle * * Revision 1.3 2001/01/19 22:23:40 paul * Update copyright. * * Revision 1.2 2000/03/17 00:12:37 meister * Update copyright message * * Revision 1.1 1998/07/15 20:58:21 sra * Initial version. * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//* * Checksum routine for Snark demos. * You can almost certainly do better than this in assembly language. */#include <wrn/wm/common/config.h>#include <wrn/wm/common/glue.h>#include <wrn/wm/demo/snarklib.h>#ifndef INSTALL_SNARK_GLUE_CKSUM_ALIGNMENT_KLUDGE#define INSTALL_SNARK_GLUE_CKSUM_ALIGNMENT_KLUDGE defined(__sparc__)#endif#if INSTALL_ATTACHE/* * This code is borrowed from RFC 1071. Note that our checksum function * takes the number of words as an argument, rather than the number of * bytes. Also, we let the caller perform the one's complement change. */bits16_t glue_cksum(bits16_t *addr, unsigned count){ register bits32_t sum = 0; #if INSTALL_SNARK_GLUE_CKSUM_ALIGNMENT_KLUDGE /* * Kludge around alignment restrictions. */ if (count > 0 && (((unsigned long) addr) & 1) != 0) { bits8_t *a = (bits8_t *) addr; sum = glue_cksum((bits16_t *) (a+1), count - 1); sum = ((sum << 8) & 0xFF00) | ((sum >> 8) & 0x00FF); sum += ((a[0] << 8) + a[count * 2 - 1]); count = 0; }#endif while (count-- > 0) sum += *addr++; sum = (sum >> 16) + (sum & 0xFFFF); /* This can only wrap twice */ return (sum >> 16) + (sum & 0xFFFF);}#endif /* INSTALL_ATTACHE */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -