1 /* 2 * GRUB -- GRand Unified Bootloader 3 * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 /* 20 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 21 * Use is subject to license terms. 22 */ 23 24 #include "fsys_zfs.h" 25 26 27 void 28 fletcher_2_native(const void *buf, uint64_t size, zio_cksum_t *zcp) 29 { 30 const uint64_t *ip = buf; 31 const uint64_t *ipend = ip + (size / sizeof (uint64_t)); 32 uint64_t a0, b0, a1, b1; 33 34 for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) { 35 a0 += ip[0]; 36 a1 += ip[1]; 37 b0 += a0; 38 b1 += a1; 39 } 40 41 ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1); 42 } 43 44 void 45 fletcher_2_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp) 46 { 47 const uint64_t *ip = buf; 48 const uint64_t *ipend = ip + (size / sizeof (uint64_t)); 49 uint64_t a0, b0, a1, b1; 50 51 for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) { 52 a0 += BSWAP_64(ip[0]); 53 a1 += BSWAP_64(ip[1]); 54 b0 += a0; 55 b1 += a1; 56 } 57 58 ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1); 59 } 60 61 void 62 fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp) 63 { 64 const uint32_t *ip = buf; 65 const uint32_t *ipend = ip + (size / sizeof (uint32_t)); 66 uint64_t a, b, c, d; 67 68 for (a = b = c = d = 0; ip < ipend; ip++) { 69 a += ip[0]; 70 b += a; 71 c += b; 72 d += c; 73 } 74 75 ZIO_SET_CHECKSUM(zcp, a, b, c, d); 76 } 77 78 void 79 fletcher_4_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp) 80 { 81 const uint32_t *ip = buf; 82 const uint32_t *ipend = ip + (size / sizeof (uint32_t)); 83 uint64_t a, b, c, d; 84 85 for (a = b = c = d = 0; ip < ipend; ip++) { 86 a += BSWAP_32(ip[0]); 87 b += a; 88 c += b; 89 d += c; 90 } 91 92 ZIO_SET_CHECKSUM(zcp, a, b, c, d); 93 } 94