]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
22 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | |
23 | * Use is subject to license terms. | |
24 | */ | |
25 | ||
b128c09f | 26 | #pragma ident "%Z%%M% %I% %E% SMI" |
34dc7c2f BB |
27 | |
28 | #include <sys/types.h> | |
29 | #include <sys/sysmacros.h> | |
30 | #include <sys/byteorder.h> | |
31 | #include <sys/spa.h> | |
32 | ||
33 | void | |
34 | fletcher_2_native(const void *buf, uint64_t size, zio_cksum_t *zcp) | |
35 | { | |
36 | const uint64_t *ip = buf; | |
37 | const uint64_t *ipend = ip + (size / sizeof (uint64_t)); | |
38 | uint64_t a0, b0, a1, b1; | |
39 | ||
40 | for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) { | |
41 | a0 += ip[0]; | |
42 | a1 += ip[1]; | |
43 | b0 += a0; | |
44 | b1 += a1; | |
45 | } | |
46 | ||
47 | ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1); | |
48 | } | |
49 | ||
50 | void | |
51 | fletcher_2_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp) | |
52 | { | |
53 | const uint64_t *ip = buf; | |
54 | const uint64_t *ipend = ip + (size / sizeof (uint64_t)); | |
55 | uint64_t a0, b0, a1, b1; | |
56 | ||
57 | for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) { | |
58 | a0 += BSWAP_64(ip[0]); | |
59 | a1 += BSWAP_64(ip[1]); | |
60 | b0 += a0; | |
61 | b1 += a1; | |
62 | } | |
63 | ||
64 | ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1); | |
65 | } | |
66 | ||
67 | void | |
68 | fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp) | |
69 | { | |
70 | const uint32_t *ip = buf; | |
71 | const uint32_t *ipend = ip + (size / sizeof (uint32_t)); | |
72 | uint64_t a, b, c, d; | |
73 | ||
74 | for (a = b = c = d = 0; ip < ipend; ip++) { | |
75 | a += ip[0]; | |
76 | b += a; | |
77 | c += b; | |
78 | d += c; | |
79 | } | |
80 | ||
81 | ZIO_SET_CHECKSUM(zcp, a, b, c, d); | |
82 | } | |
83 | ||
84 | void | |
85 | fletcher_4_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp) | |
86 | { | |
87 | const uint32_t *ip = buf; | |
88 | const uint32_t *ipend = ip + (size / sizeof (uint32_t)); | |
89 | uint64_t a, b, c, d; | |
90 | ||
91 | for (a = b = c = d = 0; ip < ipend; ip++) { | |
92 | a += BSWAP_32(ip[0]); | |
93 | b += a; | |
94 | c += b; | |
95 | d += c; | |
96 | } | |
97 | ||
98 | ZIO_SET_CHECKSUM(zcp, a, b, c, d); | |
99 | } | |
100 | ||
101 | void | |
102 | fletcher_4_incremental_native(const void *buf, uint64_t size, | |
103 | zio_cksum_t *zcp) | |
104 | { | |
105 | const uint32_t *ip = buf; | |
106 | const uint32_t *ipend = ip + (size / sizeof (uint32_t)); | |
107 | uint64_t a, b, c, d; | |
108 | ||
109 | a = zcp->zc_word[0]; | |
110 | b = zcp->zc_word[1]; | |
111 | c = zcp->zc_word[2]; | |
112 | d = zcp->zc_word[3]; | |
113 | ||
114 | for (; ip < ipend; ip++) { | |
115 | a += ip[0]; | |
116 | b += a; | |
117 | c += b; | |
118 | d += c; | |
119 | } | |
120 | ||
121 | ZIO_SET_CHECKSUM(zcp, a, b, c, d); | |
122 | } | |
123 | ||
124 | void | |
125 | fletcher_4_incremental_byteswap(const void *buf, uint64_t size, | |
126 | zio_cksum_t *zcp) | |
127 | { | |
128 | const uint32_t *ip = buf; | |
129 | const uint32_t *ipend = ip + (size / sizeof (uint32_t)); | |
130 | uint64_t a, b, c, d; | |
131 | ||
132 | a = zcp->zc_word[0]; | |
133 | b = zcp->zc_word[1]; | |
134 | c = zcp->zc_word[2]; | |
135 | d = zcp->zc_word[3]; | |
136 | ||
137 | for (; ip < ipend; ip++) { | |
138 | a += BSWAP_32(ip[0]); | |
139 | b += a; | |
140 | c += b; | |
141 | d += c; | |
142 | } | |
143 | ||
144 | ZIO_SET_CHECKSUM(zcp, a, b, c, d); | |
145 | } |