1199767f8SToomas Soome /*
2199767f8SToomas Soome * CDDL HEADER START
3199767f8SToomas Soome *
4199767f8SToomas Soome * The contents of this file are subject to the terms of the
5199767f8SToomas Soome * Common Development and Distribution License (the "License").
6199767f8SToomas Soome * You may not use this file except in compliance with the License.
7199767f8SToomas Soome *
8199767f8SToomas Soome * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9199767f8SToomas Soome * or http://www.opensolaris.org/os/licensing.
10199767f8SToomas Soome * See the License for the specific language governing permissions
11199767f8SToomas Soome * and limitations under the License.
12199767f8SToomas Soome *
13199767f8SToomas Soome * When distributing Covered Code, include this CDDL HEADER in each
14199767f8SToomas Soome * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15199767f8SToomas Soome * If applicable, add the following below this CDDL HEADER, with the
16199767f8SToomas Soome * fields enclosed by brackets "[]" replaced with your own identifying
17199767f8SToomas Soome * information: Portions Copyright [yyyy] [name of copyright owner]
18199767f8SToomas Soome *
19199767f8SToomas Soome * CDDL HEADER END
20199767f8SToomas Soome */
21199767f8SToomas Soome /*
22199767f8SToomas Soome * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23199767f8SToomas Soome * Use is subject to license terms.
24199767f8SToomas Soome */
25199767f8SToomas Soome
26199767f8SToomas Soome static void
fletcher_2_native(const void * buf,uint64_t size,const void * ctx_template __unused,zio_cksum_t * zcp)27199767f8SToomas Soome fletcher_2_native(const void *buf, uint64_t size,
28*8eef2ab6SToomas Soome const void *ctx_template __unused, zio_cksum_t *zcp)
29199767f8SToomas Soome {
30199767f8SToomas Soome const uint64_t *ip = buf;
31199767f8SToomas Soome const uint64_t *ipend = ip + (size / sizeof (uint64_t));
32199767f8SToomas Soome uint64_t a0, b0, a1, b1;
33199767f8SToomas Soome
34199767f8SToomas Soome for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
35199767f8SToomas Soome a0 += ip[0];
36199767f8SToomas Soome a1 += ip[1];
37199767f8SToomas Soome b0 += a0;
38199767f8SToomas Soome b1 += a1;
39199767f8SToomas Soome }
40199767f8SToomas Soome
41199767f8SToomas Soome ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
42199767f8SToomas Soome }
43199767f8SToomas Soome
44199767f8SToomas Soome static void
fletcher_2_byteswap(const void * buf,uint64_t size,const void * ctx_template __unused,zio_cksum_t * zcp)45199767f8SToomas Soome fletcher_2_byteswap(const void *buf, uint64_t size,
46*8eef2ab6SToomas Soome const void *ctx_template __unused, zio_cksum_t *zcp)
47199767f8SToomas Soome {
48199767f8SToomas Soome const uint64_t *ip = buf;
49199767f8SToomas Soome const uint64_t *ipend = ip + (size / sizeof (uint64_t));
50199767f8SToomas Soome uint64_t a0, b0, a1, b1;
51199767f8SToomas Soome
52199767f8SToomas Soome for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
53199767f8SToomas Soome a0 += BSWAP_64(ip[0]);
54199767f8SToomas Soome a1 += BSWAP_64(ip[1]);
55199767f8SToomas Soome b0 += a0;
56199767f8SToomas Soome b1 += a1;
57199767f8SToomas Soome }
58199767f8SToomas Soome
59199767f8SToomas Soome ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
60199767f8SToomas Soome }
61199767f8SToomas Soome
62199767f8SToomas Soome static void
fletcher_4_native(const void * buf,uint64_t size,const void * ctx_template __unused,zio_cksum_t * zcp)63199767f8SToomas Soome fletcher_4_native(const void *buf, uint64_t size,
64*8eef2ab6SToomas Soome const void *ctx_template __unused, zio_cksum_t *zcp)
65199767f8SToomas Soome {
66199767f8SToomas Soome const uint32_t *ip = buf;
67199767f8SToomas Soome const uint32_t *ipend = ip + (size / sizeof (uint32_t));
68199767f8SToomas Soome uint64_t a, b, c, d;
69199767f8SToomas Soome
70199767f8SToomas Soome for (a = b = c = d = 0; ip < ipend; ip++) {
71199767f8SToomas Soome a += ip[0];
72199767f8SToomas Soome b += a;
73199767f8SToomas Soome c += b;
74199767f8SToomas Soome d += c;
75199767f8SToomas Soome }
76199767f8SToomas Soome
77199767f8SToomas Soome ZIO_SET_CHECKSUM(zcp, a, b, c, d);
78199767f8SToomas Soome }
79199767f8SToomas Soome
80199767f8SToomas Soome static void
fletcher_4_byteswap(const void * buf,uint64_t size,const void * ctx_template __unused,zio_cksum_t * zcp)81199767f8SToomas Soome fletcher_4_byteswap(const void *buf, uint64_t size,
82*8eef2ab6SToomas Soome const void *ctx_template __unused, zio_cksum_t *zcp)
83199767f8SToomas Soome {
84199767f8SToomas Soome const uint32_t *ip = buf;
85199767f8SToomas Soome const uint32_t *ipend = ip + (size / sizeof (uint32_t));
86199767f8SToomas Soome uint64_t a, b, c, d;
87199767f8SToomas Soome
88199767f8SToomas Soome for (a = b = c = d = 0; ip < ipend; ip++) {
89199767f8SToomas Soome a += BSWAP_32(ip[0]);
90199767f8SToomas Soome b += a;
91199767f8SToomas Soome c += b;
92199767f8SToomas Soome d += c;
93199767f8SToomas Soome }
94199767f8SToomas Soome
95199767f8SToomas Soome ZIO_SET_CHECKSUM(zcp, a, b, c, d);
96199767f8SToomas Soome }
97