1185029Spjd/*
2185029Spjd * CDDL HEADER START
3185029Spjd *
4185029Spjd * The contents of this file are subject to the terms of the
5185029Spjd * Common Development and Distribution License (the "License").
6185029Spjd * You may not use this file except in compliance with the License.
7185029Spjd *
8185029Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9185029Spjd * or http://www.opensolaris.org/os/licensing.
10185029Spjd * See the License for the specific language governing permissions
11185029Spjd * and limitations under the License.
12185029Spjd *
13185029Spjd * When distributing Covered Code, include this CDDL HEADER in each
14185029Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15185029Spjd * If applicable, add the following below this CDDL HEADER, with the
16185029Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17185029Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18185029Spjd *
19185029Spjd * CDDL HEADER END
20185029Spjd */
21185029Spjd/*
22185029Spjd * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23185029Spjd * Use is subject to license terms.
24185029Spjd */
25185029Spjd
26185029Spjd/*#pragma ident	"%Z%%M%	%I%	%E% SMI"*/
27185029Spjd
28185029Spjdstatic void
29185029Spjdfletcher_2_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
30185029Spjd{
31185029Spjd	const uint64_t *ip = buf;
32185029Spjd	const uint64_t *ipend = ip + (size / sizeof (uint64_t));
33185029Spjd	uint64_t a0, b0, a1, b1;
34185029Spjd
35185029Spjd	for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
36185029Spjd		a0 += ip[0];
37185029Spjd		a1 += ip[1];
38185029Spjd		b0 += a0;
39185029Spjd		b1 += a1;
40185029Spjd	}
41185029Spjd
42185029Spjd	ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
43185029Spjd}
44185029Spjd
45185029Spjdstatic void
46219089Spjdfletcher_2_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
47219089Spjd{
48219089Spjd	const uint64_t *ip = buf;
49219089Spjd	const uint64_t *ipend = ip + (size / sizeof (uint64_t));
50219089Spjd	uint64_t a0, b0, a1, b1;
51219089Spjd
52219089Spjd	for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
53219089Spjd		a0 += BSWAP_64(ip[0]);
54219089Spjd		a1 += BSWAP_64(ip[1]);
55219089Spjd		b0 += a0;
56219089Spjd		b1 += a1;
57219089Spjd	}
58219089Spjd
59219089Spjd	ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
60219089Spjd}
61219089Spjd
62219089Spjdstatic void
63185029Spjdfletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
64185029Spjd{
65185029Spjd	const uint32_t *ip = buf;
66185029Spjd	const uint32_t *ipend = ip + (size / sizeof (uint32_t));
67185029Spjd	uint64_t a, b, c, d;
68185029Spjd
69185029Spjd	for (a = b = c = d = 0; ip < ipend; ip++) {
70185029Spjd		a += ip[0];
71185029Spjd		b += a;
72185029Spjd		c += b;
73185029Spjd		d += c;
74185029Spjd	}
75185029Spjd
76185029Spjd	ZIO_SET_CHECKSUM(zcp, a, b, c, d);
77185029Spjd}
78219089Spjd
79219089Spjdstatic void
80219089Spjdfletcher_4_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
81219089Spjd{
82219089Spjd	const uint32_t *ip = buf;
83219089Spjd	const uint32_t *ipend = ip + (size / sizeof (uint32_t));
84219089Spjd	uint64_t a, b, c, d;
85219089Spjd
86219089Spjd	for (a = b = c = d = 0; ip < ipend; ip++) {
87219089Spjd		a += BSWAP_32(ip[0]);
88219089Spjd		b += a;
89219089Spjd		c += b;
90219089Spjd		d += c;
91219089Spjd	}
92219089Spjd
93219089Spjd	ZIO_SET_CHECKSUM(zcp, a, b, c, d);
94219089Spjd}
95