authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-26 15:25:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-26 16:07:53-07:00
log3a11c86837562dd6caf143e21ca8562a8374b08a
tree06db7adfba7cc3878636b2b3ab9ab4b3b6dc833c
parent32b44497e228c676de17d6c2a2ce78cf145a97c9

std.hash.crc: fix namespace issues

in accordance with the style guide in the langref

5 files changed, 220 insertions(+), 237 deletions(-)

lib/std/debug/ElfFile.zig+1-1
...@@ -455,7 +455,7 @@ fn loadInner(...@@ -455,7 +455,7 @@ fn loadInner(
455 };455 };
456456
457 if (opt_crc) |crc| {457 if (opt_crc) |crc| {
458 if (std.hash.crc.Crc32.hash(mapped_mem) != crc) {458 if (std.hash.Crc32.hash(mapped_mem) != crc) {
459 return error.CrcMismatch;459 return error.CrcMismatch;
460 }460 }
461 }461 }
lib/std/hash.zig+1-2
...@@ -5,9 +5,8 @@ pub const autoHash = auto_hash.autoHash;...@@ -5,9 +5,8 @@ pub const autoHash = auto_hash.autoHash;
5pub const autoHashStrat = auto_hash.hash;5pub const autoHashStrat = auto_hash.hash;
6pub const Strategy = auto_hash.HashStrategy;6pub const Strategy = auto_hash.HashStrategy;
77
8// pub for polynomials + generic crc32 construction
9pub const crc = @import("hash/crc.zig");8pub const crc = @import("hash/crc.zig");
10pub const Crc32 = crc.Crc32;9pub const Crc32 = crc.Crc32IsoHdlc;
1110
12const fnv = @import("hash/fnv.zig");11const fnv = @import("hash/fnv.zig");
13pub const Fnv1a_32 = fnv.Fnv1a_32;12pub const Fnv1a_32 = fnv.Fnv1a_32;
lib/std/hash/benchmark.zig+1-1
...@@ -61,7 +61,7 @@ const hashes = [_]Hash{...@@ -61,7 +61,7 @@ const hashes = [_]Hash{
61 .init_default = true,61 .init_default = true,
62 },62 },
63 Hash{63 Hash{
64 .ty = hash.crc.Crc32,64 .ty = hash.Crc32,
65 .name = "crc32",65 .name = "crc32",
66 },66 },
67 Hash{67 Hash{
lib/std/hash/crc.zig+217-130
...@@ -1,31 +1,19 @@...@@ -1,31 +1,19 @@
1//! This file is auto-generated by tools/update_crc_catalog.zig.1//! This file is maintained with the help of tools/update_crc_catalog.zig.
22
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const impl = @import("crc/impl.zig");
54
6pub const Crc = impl.Crc;5pub const Crc32Iscsi = if (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 }))
7pub const Polynomial = impl.Polynomial;6 @import("crc/Crc32c.zig")
8pub const Crc32WithPoly = impl.Crc32WithPoly;7else
9pub const Crc32SmallWithPoly = impl.Crc32SmallWithPoly;8 Generic(u32, .{
10
11pub const Crc32 = Crc32IsoHdlc;
12
13test {
14 _ = @import("crc/test.zig");
15}
16
17pub const Crc32Iscsi = switch (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 })) {
18 true => @import("crc/Crc32c.zig"),
19 else => Crc(u32, .{
20 .polynomial = 0x1edc6f41,9 .polynomial = 0x1edc6f41,
21 .initial = 0xffffffff,10 .initial = 0xffffffff,
22 .reflect_input = true,11 .reflect_input = true,
23 .reflect_output = true,12 .reflect_output = true,
24 .xor_output = 0xffffffff,13 .xor_output = 0xffffffff,
25 }),14 });
26};
2715
28pub const Crc3Gsm = Crc(u3, .{16pub const Crc3Gsm = Generic(u3, .{
29 .polynomial = 0x3,17 .polynomial = 0x3,
30 .initial = 0x0,18 .initial = 0x0,
31 .reflect_input = false,19 .reflect_input = false,
...@@ -33,7 +21,7 @@ pub const Crc3Gsm = Crc(u3, .{...@@ -33,7 +21,7 @@ pub const Crc3Gsm = Crc(u3, .{
33 .xor_output = 0x7,21 .xor_output = 0x7,
34});22});
3523
36pub const Crc3Rohc = Crc(u3, .{24pub const Crc3Rohc = Generic(u3, .{
37 .polynomial = 0x3,25 .polynomial = 0x3,
38 .initial = 0x7,26 .initial = 0x7,
39 .reflect_input = true,27 .reflect_input = true,
...@@ -41,7 +29,7 @@ pub const Crc3Rohc = Crc(u3, .{...@@ -41,7 +29,7 @@ pub const Crc3Rohc = Crc(u3, .{
41 .xor_output = 0x0,29 .xor_output = 0x0,
42});30});
4331
44pub const Crc4G704 = Crc(u4, .{32pub const Crc4G704 = Generic(u4, .{
45 .polynomial = 0x3,33 .polynomial = 0x3,
46 .initial = 0x0,34 .initial = 0x0,
47 .reflect_input = true,35 .reflect_input = true,
...@@ -49,7 +37,7 @@ pub const Crc4G704 = Crc(u4, .{...@@ -49,7 +37,7 @@ pub const Crc4G704 = Crc(u4, .{
49 .xor_output = 0x0,37 .xor_output = 0x0,
50});38});
5139
52pub const Crc4Interlaken = Crc(u4, .{40pub const Crc4Interlaken = Generic(u4, .{
53 .polynomial = 0x3,41 .polynomial = 0x3,
54 .initial = 0xf,42 .initial = 0xf,
55 .reflect_input = false,43 .reflect_input = false,
...@@ -57,7 +45,7 @@ pub const Crc4Interlaken = Crc(u4, .{...@@ -57,7 +45,7 @@ pub const Crc4Interlaken = Crc(u4, .{
57 .xor_output = 0xf,45 .xor_output = 0xf,
58});46});
5947
60pub const Crc5EpcC1g2 = Crc(u5, .{48pub const Crc5EpcC1g2 = Generic(u5, .{
61 .polynomial = 0x09,49 .polynomial = 0x09,
62 .initial = 0x09,50 .initial = 0x09,
63 .reflect_input = false,51 .reflect_input = false,
...@@ -65,7 +53,7 @@ pub const Crc5EpcC1g2 = Crc(u5, .{...@@ -65,7 +53,7 @@ pub const Crc5EpcC1g2 = Crc(u5, .{
65 .xor_output = 0x00,53 .xor_output = 0x00,
66});54});
6755
68pub const Crc5G704 = Crc(u5, .{56pub const Crc5G704 = Generic(u5, .{
69 .polynomial = 0x15,57 .polynomial = 0x15,
70 .initial = 0x00,58 .initial = 0x00,
71 .reflect_input = true,59 .reflect_input = true,
...@@ -73,7 +61,7 @@ pub const Crc5G704 = Crc(u5, .{...@@ -73,7 +61,7 @@ pub const Crc5G704 = Crc(u5, .{
73 .xor_output = 0x00,61 .xor_output = 0x00,
74});62});
7563
76pub const Crc5Usb = Crc(u5, .{64pub const Crc5Usb = Generic(u5, .{
77 .polynomial = 0x05,65 .polynomial = 0x05,
78 .initial = 0x1f,66 .initial = 0x1f,
79 .reflect_input = true,67 .reflect_input = true,
...@@ -81,7 +69,7 @@ pub const Crc5Usb = Crc(u5, .{...@@ -81,7 +69,7 @@ pub const Crc5Usb = Crc(u5, .{
81 .xor_output = 0x1f,69 .xor_output = 0x1f,
82});70});
8371
84pub const Crc6Cdma2000A = Crc(u6, .{72pub const Crc6Cdma2000A = Generic(u6, .{
85 .polynomial = 0x27,73 .polynomial = 0x27,
86 .initial = 0x3f,74 .initial = 0x3f,
87 .reflect_input = false,75 .reflect_input = false,
...@@ -89,7 +77,7 @@ pub const Crc6Cdma2000A = Crc(u6, .{...@@ -89,7 +77,7 @@ pub const Crc6Cdma2000A = Crc(u6, .{
89 .xor_output = 0x00,77 .xor_output = 0x00,
90});78});
9179
92pub const Crc6Cdma2000B = Crc(u6, .{80pub const Crc6Cdma2000B = Generic(u6, .{
93 .polynomial = 0x07,81 .polynomial = 0x07,
94 .initial = 0x3f,82 .initial = 0x3f,
95 .reflect_input = false,83 .reflect_input = false,
...@@ -97,7 +85,7 @@ pub const Crc6Cdma2000B = Crc(u6, .{...@@ -97,7 +85,7 @@ pub const Crc6Cdma2000B = Crc(u6, .{
97 .xor_output = 0x00,85 .xor_output = 0x00,
98});86});
9987
100pub const Crc6Darc = Crc(u6, .{88pub const Crc6Darc = Generic(u6, .{
101 .polynomial = 0x19,89 .polynomial = 0x19,
102 .initial = 0x00,90 .initial = 0x00,
103 .reflect_input = true,91 .reflect_input = true,
...@@ -105,7 +93,7 @@ pub const Crc6Darc = Crc(u6, .{...@@ -105,7 +93,7 @@ pub const Crc6Darc = Crc(u6, .{
105 .xor_output = 0x00,93 .xor_output = 0x00,
106});94});
10795
108pub const Crc6G704 = Crc(u6, .{96pub const Crc6G704 = Generic(u6, .{
109 .polynomial = 0x03,97 .polynomial = 0x03,
110 .initial = 0x00,98 .initial = 0x00,
111 .reflect_input = true,99 .reflect_input = true,
...@@ -113,7 +101,7 @@ pub const Crc6G704 = Crc(u6, .{...@@ -113,7 +101,7 @@ pub const Crc6G704 = Crc(u6, .{
113 .xor_output = 0x00,101 .xor_output = 0x00,
114});102});
115103
116pub const Crc6Gsm = Crc(u6, .{104pub const Crc6Gsm = Generic(u6, .{
117 .polynomial = 0x2f,105 .polynomial = 0x2f,
118 .initial = 0x00,106 .initial = 0x00,
119 .reflect_input = false,107 .reflect_input = false,
...@@ -121,7 +109,7 @@ pub const Crc6Gsm = Crc(u6, .{...@@ -121,7 +109,7 @@ pub const Crc6Gsm = Crc(u6, .{
121 .xor_output = 0x3f,109 .xor_output = 0x3f,
122});110});
123111
124pub const Crc7Mmc = Crc(u7, .{112pub const Crc7Mmc = Generic(u7, .{
125 .polynomial = 0x09,113 .polynomial = 0x09,
126 .initial = 0x00,114 .initial = 0x00,
127 .reflect_input = false,115 .reflect_input = false,
...@@ -129,7 +117,7 @@ pub const Crc7Mmc = Crc(u7, .{...@@ -129,7 +117,7 @@ pub const Crc7Mmc = Crc(u7, .{
129 .xor_output = 0x00,117 .xor_output = 0x00,
130});118});
131119
132pub const Crc7Rohc = Crc(u7, .{120pub const Crc7Rohc = Generic(u7, .{
133 .polynomial = 0x4f,121 .polynomial = 0x4f,
134 .initial = 0x7f,122 .initial = 0x7f,
135 .reflect_input = true,123 .reflect_input = true,
...@@ -137,7 +125,7 @@ pub const Crc7Rohc = Crc(u7, .{...@@ -137,7 +125,7 @@ pub const Crc7Rohc = Crc(u7, .{
137 .xor_output = 0x00,125 .xor_output = 0x00,
138});126});
139127
140pub const Crc7Umts = Crc(u7, .{128pub const Crc7Umts = Generic(u7, .{
141 .polynomial = 0x45,129 .polynomial = 0x45,
142 .initial = 0x00,130 .initial = 0x00,
143 .reflect_input = false,131 .reflect_input = false,
...@@ -145,7 +133,7 @@ pub const Crc7Umts = Crc(u7, .{...@@ -145,7 +133,7 @@ pub const Crc7Umts = Crc(u7, .{
145 .xor_output = 0x00,133 .xor_output = 0x00,
146});134});
147135
148pub const Crc8Autosar = Crc(u8, .{136pub const Crc8Autosar = Generic(u8, .{
149 .polynomial = 0x2f,137 .polynomial = 0x2f,
150 .initial = 0xff,138 .initial = 0xff,
151 .reflect_input = false,139 .reflect_input = false,
...@@ -153,7 +141,7 @@ pub const Crc8Autosar = Crc(u8, .{...@@ -153,7 +141,7 @@ pub const Crc8Autosar = Crc(u8, .{
153 .xor_output = 0xff,141 .xor_output = 0xff,
154});142});
155143
156pub const Crc8Bluetooth = Crc(u8, .{144pub const Crc8Bluetooth = Generic(u8, .{
157 .polynomial = 0xa7,145 .polynomial = 0xa7,
158 .initial = 0x00,146 .initial = 0x00,
159 .reflect_input = true,147 .reflect_input = true,
...@@ -161,7 +149,7 @@ pub const Crc8Bluetooth = Crc(u8, .{...@@ -161,7 +149,7 @@ pub const Crc8Bluetooth = Crc(u8, .{
161 .xor_output = 0x00,149 .xor_output = 0x00,
162});150});
163151
164pub const Crc8Cdma2000 = Crc(u8, .{152pub const Crc8Cdma2000 = Generic(u8, .{
165 .polynomial = 0x9b,153 .polynomial = 0x9b,
166 .initial = 0xff,154 .initial = 0xff,
167 .reflect_input = false,155 .reflect_input = false,
...@@ -169,7 +157,7 @@ pub const Crc8Cdma2000 = Crc(u8, .{...@@ -169,7 +157,7 @@ pub const Crc8Cdma2000 = Crc(u8, .{
169 .xor_output = 0x00,157 .xor_output = 0x00,
170});158});
171159
172pub const Crc8Darc = Crc(u8, .{160pub const Crc8Darc = Generic(u8, .{
173 .polynomial = 0x39,161 .polynomial = 0x39,
174 .initial = 0x00,162 .initial = 0x00,
175 .reflect_input = true,163 .reflect_input = true,
...@@ -177,7 +165,7 @@ pub const Crc8Darc = Crc(u8, .{...@@ -177,7 +165,7 @@ pub const Crc8Darc = Crc(u8, .{
177 .xor_output = 0x00,165 .xor_output = 0x00,
178});166});
179167
180pub const Crc8DvbS2 = Crc(u8, .{168pub const Crc8DvbS2 = Generic(u8, .{
181 .polynomial = 0xd5,169 .polynomial = 0xd5,
182 .initial = 0x00,170 .initial = 0x00,
183 .reflect_input = false,171 .reflect_input = false,
...@@ -185,7 +173,7 @@ pub const Crc8DvbS2 = Crc(u8, .{...@@ -185,7 +173,7 @@ pub const Crc8DvbS2 = Crc(u8, .{
185 .xor_output = 0x00,173 .xor_output = 0x00,
186});174});
187175
188pub const Crc8GsmA = Crc(u8, .{176pub const Crc8GsmA = Generic(u8, .{
189 .polynomial = 0x1d,177 .polynomial = 0x1d,
190 .initial = 0x00,178 .initial = 0x00,
191 .reflect_input = false,179 .reflect_input = false,
...@@ -193,7 +181,7 @@ pub const Crc8GsmA = Crc(u8, .{...@@ -193,7 +181,7 @@ pub const Crc8GsmA = Crc(u8, .{
193 .xor_output = 0x00,181 .xor_output = 0x00,
194});182});
195183
196pub const Crc8GsmB = Crc(u8, .{184pub const Crc8GsmB = Generic(u8, .{
197 .polynomial = 0x49,185 .polynomial = 0x49,
198 .initial = 0x00,186 .initial = 0x00,
199 .reflect_input = false,187 .reflect_input = false,
...@@ -201,7 +189,7 @@ pub const Crc8GsmB = Crc(u8, .{...@@ -201,7 +189,7 @@ pub const Crc8GsmB = Crc(u8, .{
201 .xor_output = 0xff,189 .xor_output = 0xff,
202});190});
203191
204pub const Crc8Hitag = Crc(u8, .{192pub const Crc8Hitag = Generic(u8, .{
205 .polynomial = 0x1d,193 .polynomial = 0x1d,
206 .initial = 0xff,194 .initial = 0xff,
207 .reflect_input = false,195 .reflect_input = false,
...@@ -209,7 +197,7 @@ pub const Crc8Hitag = Crc(u8, .{...@@ -209,7 +197,7 @@ pub const Crc8Hitag = Crc(u8, .{
209 .xor_output = 0x00,197 .xor_output = 0x00,
210});198});
211199
212pub const Crc8I4321 = Crc(u8, .{200pub const Crc8I4321 = Generic(u8, .{
213 .polynomial = 0x07,201 .polynomial = 0x07,
214 .initial = 0x00,202 .initial = 0x00,
215 .reflect_input = false,203 .reflect_input = false,
...@@ -217,7 +205,7 @@ pub const Crc8I4321 = Crc(u8, .{...@@ -217,7 +205,7 @@ pub const Crc8I4321 = Crc(u8, .{
217 .xor_output = 0x55,205 .xor_output = 0x55,
218});206});
219207
220pub const Crc8ICode = Crc(u8, .{208pub const Crc8ICode = Generic(u8, .{
221 .polynomial = 0x1d,209 .polynomial = 0x1d,
222 .initial = 0xfd,210 .initial = 0xfd,
223 .reflect_input = false,211 .reflect_input = false,
...@@ -225,7 +213,7 @@ pub const Crc8ICode = Crc(u8, .{...@@ -225,7 +213,7 @@ pub const Crc8ICode = Crc(u8, .{
225 .xor_output = 0x00,213 .xor_output = 0x00,
226});214});
227215
228pub const Crc8Lte = Crc(u8, .{216pub const Crc8Lte = Generic(u8, .{
229 .polynomial = 0x9b,217 .polynomial = 0x9b,
230 .initial = 0x00,218 .initial = 0x00,
231 .reflect_input = false,219 .reflect_input = false,
...@@ -233,7 +221,7 @@ pub const Crc8Lte = Crc(u8, .{...@@ -233,7 +221,7 @@ pub const Crc8Lte = Crc(u8, .{
233 .xor_output = 0x00,221 .xor_output = 0x00,
234});222});
235223
236pub const Crc8MaximDow = Crc(u8, .{224pub const Crc8MaximDow = Generic(u8, .{
237 .polynomial = 0x31,225 .polynomial = 0x31,
238 .initial = 0x00,226 .initial = 0x00,
239 .reflect_input = true,227 .reflect_input = true,
...@@ -241,7 +229,7 @@ pub const Crc8MaximDow = Crc(u8, .{...@@ -241,7 +229,7 @@ pub const Crc8MaximDow = Crc(u8, .{
241 .xor_output = 0x00,229 .xor_output = 0x00,
242});230});
243231
244pub const Crc8MifareMad = Crc(u8, .{232pub const Crc8MifareMad = Generic(u8, .{
245 .polynomial = 0x1d,233 .polynomial = 0x1d,
246 .initial = 0xc7,234 .initial = 0xc7,
247 .reflect_input = false,235 .reflect_input = false,
...@@ -249,7 +237,7 @@ pub const Crc8MifareMad = Crc(u8, .{...@@ -249,7 +237,7 @@ pub const Crc8MifareMad = Crc(u8, .{
249 .xor_output = 0x00,237 .xor_output = 0x00,
250});238});
251239
252pub const Crc8Nrsc5 = Crc(u8, .{240pub const Crc8Nrsc5 = Generic(u8, .{
253 .polynomial = 0x31,241 .polynomial = 0x31,
254 .initial = 0xff,242 .initial = 0xff,
255 .reflect_input = false,243 .reflect_input = false,
...@@ -257,7 +245,7 @@ pub const Crc8Nrsc5 = Crc(u8, .{...@@ -257,7 +245,7 @@ pub const Crc8Nrsc5 = Crc(u8, .{
257 .xor_output = 0x00,245 .xor_output = 0x00,
258});246});
259247
260pub const Crc8Opensafety = Crc(u8, .{248pub const Crc8Opensafety = Generic(u8, .{
261 .polynomial = 0x2f,249 .polynomial = 0x2f,
262 .initial = 0x00,250 .initial = 0x00,
263 .reflect_input = false,251 .reflect_input = false,
...@@ -265,7 +253,7 @@ pub const Crc8Opensafety = Crc(u8, .{...@@ -265,7 +253,7 @@ pub const Crc8Opensafety = Crc(u8, .{
265 .xor_output = 0x00,253 .xor_output = 0x00,
266});254});
267255
268pub const Crc8Rohc = Crc(u8, .{256pub const Crc8Rohc = Generic(u8, .{
269 .polynomial = 0x07,257 .polynomial = 0x07,
270 .initial = 0xff,258 .initial = 0xff,
271 .reflect_input = true,259 .reflect_input = true,
...@@ -273,7 +261,7 @@ pub const Crc8Rohc = Crc(u8, .{...@@ -273,7 +261,7 @@ pub const Crc8Rohc = Crc(u8, .{
273 .xor_output = 0x00,261 .xor_output = 0x00,
274});262});
275263
276pub const Crc8SaeJ1850 = Crc(u8, .{264pub const Crc8SaeJ1850 = Generic(u8, .{
277 .polynomial = 0x1d,265 .polynomial = 0x1d,
278 .initial = 0xff,266 .initial = 0xff,
279 .reflect_input = false,267 .reflect_input = false,
...@@ -281,7 +269,7 @@ pub const Crc8SaeJ1850 = Crc(u8, .{...@@ -281,7 +269,7 @@ pub const Crc8SaeJ1850 = Crc(u8, .{
281 .xor_output = 0xff,269 .xor_output = 0xff,
282});270});
283271
284pub const Crc8Smbus = Crc(u8, .{272pub const Crc8Smbus = Generic(u8, .{
285 .polynomial = 0x07,273 .polynomial = 0x07,
286 .initial = 0x00,274 .initial = 0x00,
287 .reflect_input = false,275 .reflect_input = false,
...@@ -289,7 +277,7 @@ pub const Crc8Smbus = Crc(u8, .{...@@ -289,7 +277,7 @@ pub const Crc8Smbus = Crc(u8, .{
289 .xor_output = 0x00,277 .xor_output = 0x00,
290});278});
291279
292pub const Crc8Tech3250 = Crc(u8, .{280pub const Crc8Tech3250 = Generic(u8, .{
293 .polynomial = 0x1d,281 .polynomial = 0x1d,
294 .initial = 0xff,282 .initial = 0xff,
295 .reflect_input = true,283 .reflect_input = true,
...@@ -297,7 +285,7 @@ pub const Crc8Tech3250 = Crc(u8, .{...@@ -297,7 +285,7 @@ pub const Crc8Tech3250 = Crc(u8, .{
297 .xor_output = 0x00,285 .xor_output = 0x00,
298});286});
299287
300pub const Crc8Wcdma = Crc(u8, .{288pub const Crc8Wcdma = Generic(u8, .{
301 .polynomial = 0x9b,289 .polynomial = 0x9b,
302 .initial = 0x00,290 .initial = 0x00,
303 .reflect_input = true,291 .reflect_input = true,
...@@ -305,7 +293,7 @@ pub const Crc8Wcdma = Crc(u8, .{...@@ -305,7 +293,7 @@ pub const Crc8Wcdma = Crc(u8, .{
305 .xor_output = 0x00,293 .xor_output = 0x00,
306});294});
307295
308pub const Crc10Atm = Crc(u10, .{296pub const Crc10Atm = Generic(u10, .{
309 .polynomial = 0x233,297 .polynomial = 0x233,
310 .initial = 0x000,298 .initial = 0x000,
311 .reflect_input = false,299 .reflect_input = false,
...@@ -313,7 +301,7 @@ pub const Crc10Atm = Crc(u10, .{...@@ -313,7 +301,7 @@ pub const Crc10Atm = Crc(u10, .{
313 .xor_output = 0x000,301 .xor_output = 0x000,
314});302});
315303
316pub const Crc10Cdma2000 = Crc(u10, .{304pub const Crc10Cdma2000 = Generic(u10, .{
317 .polynomial = 0x3d9,305 .polynomial = 0x3d9,
318 .initial = 0x3ff,306 .initial = 0x3ff,
319 .reflect_input = false,307 .reflect_input = false,
...@@ -321,7 +309,7 @@ pub const Crc10Cdma2000 = Crc(u10, .{...@@ -321,7 +309,7 @@ pub const Crc10Cdma2000 = Crc(u10, .{
321 .xor_output = 0x000,309 .xor_output = 0x000,
322});310});
323311
324pub const Crc10Gsm = Crc(u10, .{312pub const Crc10Gsm = Generic(u10, .{
325 .polynomial = 0x175,313 .polynomial = 0x175,
326 .initial = 0x000,314 .initial = 0x000,
327 .reflect_input = false,315 .reflect_input = false,
...@@ -329,7 +317,7 @@ pub const Crc10Gsm = Crc(u10, .{...@@ -329,7 +317,7 @@ pub const Crc10Gsm = Crc(u10, .{
329 .xor_output = 0x3ff,317 .xor_output = 0x3ff,
330});318});
331319
332pub const Crc11Flexray = Crc(u11, .{320pub const Crc11Flexray = Generic(u11, .{
333 .polynomial = 0x385,321 .polynomial = 0x385,
334 .initial = 0x01a,322 .initial = 0x01a,
335 .reflect_input = false,323 .reflect_input = false,
...@@ -337,7 +325,7 @@ pub const Crc11Flexray = Crc(u11, .{...@@ -337,7 +325,7 @@ pub const Crc11Flexray = Crc(u11, .{
337 .xor_output = 0x000,325 .xor_output = 0x000,
338});326});
339327
340pub const Crc11Umts = Crc(u11, .{328pub const Crc11Umts = Generic(u11, .{
341 .polynomial = 0x307,329 .polynomial = 0x307,
342 .initial = 0x000,330 .initial = 0x000,
343 .reflect_input = false,331 .reflect_input = false,
...@@ -345,7 +333,7 @@ pub const Crc11Umts = Crc(u11, .{...@@ -345,7 +333,7 @@ pub const Crc11Umts = Crc(u11, .{
345 .xor_output = 0x000,333 .xor_output = 0x000,
346});334});
347335
348pub const Crc12Cdma2000 = Crc(u12, .{336pub const Crc12Cdma2000 = Generic(u12, .{
349 .polynomial = 0xf13,337 .polynomial = 0xf13,
350 .initial = 0xfff,338 .initial = 0xfff,
351 .reflect_input = false,339 .reflect_input = false,
...@@ -353,7 +341,7 @@ pub const Crc12Cdma2000 = Crc(u12, .{...@@ -353,7 +341,7 @@ pub const Crc12Cdma2000 = Crc(u12, .{
353 .xor_output = 0x000,341 .xor_output = 0x000,
354});342});
355343
356pub const Crc12Dect = Crc(u12, .{344pub const Crc12Dect = Generic(u12, .{
357 .polynomial = 0x80f,345 .polynomial = 0x80f,
358 .initial = 0x000,346 .initial = 0x000,
359 .reflect_input = false,347 .reflect_input = false,
...@@ -361,7 +349,7 @@ pub const Crc12Dect = Crc(u12, .{...@@ -361,7 +349,7 @@ pub const Crc12Dect = Crc(u12, .{
361 .xor_output = 0x000,349 .xor_output = 0x000,
362});350});
363351
364pub const Crc12Gsm = Crc(u12, .{352pub const Crc12Gsm = Generic(u12, .{
365 .polynomial = 0xd31,353 .polynomial = 0xd31,
366 .initial = 0x000,354 .initial = 0x000,
367 .reflect_input = false,355 .reflect_input = false,
...@@ -369,7 +357,7 @@ pub const Crc12Gsm = Crc(u12, .{...@@ -369,7 +357,7 @@ pub const Crc12Gsm = Crc(u12, .{
369 .xor_output = 0xfff,357 .xor_output = 0xfff,
370});358});
371359
372pub const Crc12Umts = Crc(u12, .{360pub const Crc12Umts = Generic(u12, .{
373 .polynomial = 0x80f,361 .polynomial = 0x80f,
374 .initial = 0x000,362 .initial = 0x000,
375 .reflect_input = false,363 .reflect_input = false,
...@@ -377,7 +365,7 @@ pub const Crc12Umts = Crc(u12, .{...@@ -377,7 +365,7 @@ pub const Crc12Umts = Crc(u12, .{
377 .xor_output = 0x000,365 .xor_output = 0x000,
378});366});
379367
380pub const Crc13Bbc = Crc(u13, .{368pub const Crc13Bbc = Generic(u13, .{
381 .polynomial = 0x1cf5,369 .polynomial = 0x1cf5,
382 .initial = 0x0000,370 .initial = 0x0000,
383 .reflect_input = false,371 .reflect_input = false,
...@@ -385,7 +373,7 @@ pub const Crc13Bbc = Crc(u13, .{...@@ -385,7 +373,7 @@ pub const Crc13Bbc = Crc(u13, .{
385 .xor_output = 0x0000,373 .xor_output = 0x0000,
386});374});
387375
388pub const Crc14Darc = Crc(u14, .{376pub const Crc14Darc = Generic(u14, .{
389 .polynomial = 0x0805,377 .polynomial = 0x0805,
390 .initial = 0x0000,378 .initial = 0x0000,
391 .reflect_input = true,379 .reflect_input = true,
...@@ -393,7 +381,7 @@ pub const Crc14Darc = Crc(u14, .{...@@ -393,7 +381,7 @@ pub const Crc14Darc = Crc(u14, .{
393 .xor_output = 0x0000,381 .xor_output = 0x0000,
394});382});
395383
396pub const Crc14Gsm = Crc(u14, .{384pub const Crc14Gsm = Generic(u14, .{
397 .polynomial = 0x202d,385 .polynomial = 0x202d,
398 .initial = 0x0000,386 .initial = 0x0000,
399 .reflect_input = false,387 .reflect_input = false,
...@@ -401,7 +389,7 @@ pub const Crc14Gsm = Crc(u14, .{...@@ -401,7 +389,7 @@ pub const Crc14Gsm = Crc(u14, .{
401 .xor_output = 0x3fff,389 .xor_output = 0x3fff,
402});390});
403391
404pub const Crc15Can = Crc(u15, .{392pub const Crc15Can = Generic(u15, .{
405 .polynomial = 0x4599,393 .polynomial = 0x4599,
406 .initial = 0x0000,394 .initial = 0x0000,
407 .reflect_input = false,395 .reflect_input = false,
...@@ -409,7 +397,7 @@ pub const Crc15Can = Crc(u15, .{...@@ -409,7 +397,7 @@ pub const Crc15Can = Crc(u15, .{
409 .xor_output = 0x0000,397 .xor_output = 0x0000,
410});398});
411399
412pub const Crc15Mpt1327 = Crc(u15, .{400pub const Crc15Mpt1327 = Generic(u15, .{
413 .polynomial = 0x6815,401 .polynomial = 0x6815,
414 .initial = 0x0000,402 .initial = 0x0000,
415 .reflect_input = false,403 .reflect_input = false,
...@@ -417,7 +405,7 @@ pub const Crc15Mpt1327 = Crc(u15, .{...@@ -417,7 +405,7 @@ pub const Crc15Mpt1327 = Crc(u15, .{
417 .xor_output = 0x0001,405 .xor_output = 0x0001,
418});406});
419407
420pub const Crc16Arc = Crc(u16, .{408pub const Crc16Arc = Generic(u16, .{
421 .polynomial = 0x8005,409 .polynomial = 0x8005,
422 .initial = 0x0000,410 .initial = 0x0000,
423 .reflect_input = true,411 .reflect_input = true,
...@@ -425,7 +413,7 @@ pub const Crc16Arc = Crc(u16, .{...@@ -425,7 +413,7 @@ pub const Crc16Arc = Crc(u16, .{
425 .xor_output = 0x0000,413 .xor_output = 0x0000,
426});414});
427415
428pub const Crc16Cdma2000 = Crc(u16, .{416pub const Crc16Cdma2000 = Generic(u16, .{
429 .polynomial = 0xc867,417 .polynomial = 0xc867,
430 .initial = 0xffff,418 .initial = 0xffff,
431 .reflect_input = false,419 .reflect_input = false,
...@@ -433,7 +421,7 @@ pub const Crc16Cdma2000 = Crc(u16, .{...@@ -433,7 +421,7 @@ pub const Crc16Cdma2000 = Crc(u16, .{
433 .xor_output = 0x0000,421 .xor_output = 0x0000,
434});422});
435423
436pub const Crc16Cms = Crc(u16, .{424pub const Crc16Cms = Generic(u16, .{
437 .polynomial = 0x8005,425 .polynomial = 0x8005,
438 .initial = 0xffff,426 .initial = 0xffff,
439 .reflect_input = false,427 .reflect_input = false,
...@@ -441,7 +429,7 @@ pub const Crc16Cms = Crc(u16, .{...@@ -441,7 +429,7 @@ pub const Crc16Cms = Crc(u16, .{
441 .xor_output = 0x0000,429 .xor_output = 0x0000,
442});430});
443431
444pub const Crc16Dds110 = Crc(u16, .{432pub const Crc16Dds110 = Generic(u16, .{
445 .polynomial = 0x8005,433 .polynomial = 0x8005,
446 .initial = 0x800d,434 .initial = 0x800d,
447 .reflect_input = false,435 .reflect_input = false,
...@@ -449,7 +437,7 @@ pub const Crc16Dds110 = Crc(u16, .{...@@ -449,7 +437,7 @@ pub const Crc16Dds110 = Crc(u16, .{
449 .xor_output = 0x0000,437 .xor_output = 0x0000,
450});438});
451439
452pub const Crc16DectR = Crc(u16, .{440pub const Crc16DectR = Generic(u16, .{
453 .polynomial = 0x0589,441 .polynomial = 0x0589,
454 .initial = 0x0000,442 .initial = 0x0000,
455 .reflect_input = false,443 .reflect_input = false,
...@@ -457,7 +445,7 @@ pub const Crc16DectR = Crc(u16, .{...@@ -457,7 +445,7 @@ pub const Crc16DectR = Crc(u16, .{
457 .xor_output = 0x0001,445 .xor_output = 0x0001,
458});446});
459447
460pub const Crc16DectX = Crc(u16, .{448pub const Crc16DectX = Generic(u16, .{
461 .polynomial = 0x0589,449 .polynomial = 0x0589,
462 .initial = 0x0000,450 .initial = 0x0000,
463 .reflect_input = false,451 .reflect_input = false,
...@@ -465,7 +453,7 @@ pub const Crc16DectX = Crc(u16, .{...@@ -465,7 +453,7 @@ pub const Crc16DectX = Crc(u16, .{
465 .xor_output = 0x0000,453 .xor_output = 0x0000,
466});454});
467455
468pub const Crc16Dnp = Crc(u16, .{456pub const Crc16Dnp = Generic(u16, .{
469 .polynomial = 0x3d65,457 .polynomial = 0x3d65,
470 .initial = 0x0000,458 .initial = 0x0000,
471 .reflect_input = true,459 .reflect_input = true,
...@@ -473,7 +461,7 @@ pub const Crc16Dnp = Crc(u16, .{...@@ -473,7 +461,7 @@ pub const Crc16Dnp = Crc(u16, .{
473 .xor_output = 0xffff,461 .xor_output = 0xffff,
474});462});
475463
476pub const Crc16En13757 = Crc(u16, .{464pub const Crc16En13757 = Generic(u16, .{
477 .polynomial = 0x3d65,465 .polynomial = 0x3d65,
478 .initial = 0x0000,466 .initial = 0x0000,
479 .reflect_input = false,467 .reflect_input = false,
...@@ -481,7 +469,7 @@ pub const Crc16En13757 = Crc(u16, .{...@@ -481,7 +469,7 @@ pub const Crc16En13757 = Crc(u16, .{
481 .xor_output = 0xffff,469 .xor_output = 0xffff,
482});470});
483471
484pub const Crc16Genibus = Crc(u16, .{472pub const Crc16Genibus = Generic(u16, .{
485 .polynomial = 0x1021,473 .polynomial = 0x1021,
486 .initial = 0xffff,474 .initial = 0xffff,
487 .reflect_input = false,475 .reflect_input = false,
...@@ -489,7 +477,7 @@ pub const Crc16Genibus = Crc(u16, .{...@@ -489,7 +477,7 @@ pub const Crc16Genibus = Crc(u16, .{
489 .xor_output = 0xffff,477 .xor_output = 0xffff,
490});478});
491479
492pub const Crc16Gsm = Crc(u16, .{480pub const Crc16Gsm = Generic(u16, .{
493 .polynomial = 0x1021,481 .polynomial = 0x1021,
494 .initial = 0x0000,482 .initial = 0x0000,
495 .reflect_input = false,483 .reflect_input = false,
...@@ -497,7 +485,7 @@ pub const Crc16Gsm = Crc(u16, .{...@@ -497,7 +485,7 @@ pub const Crc16Gsm = Crc(u16, .{
497 .xor_output = 0xffff,485 .xor_output = 0xffff,
498});486});
499487
500pub const Crc16Ibm3740 = Crc(u16, .{488pub const Crc16Ibm3740 = Generic(u16, .{
501 .polynomial = 0x1021,489 .polynomial = 0x1021,
502 .initial = 0xffff,490 .initial = 0xffff,
503 .reflect_input = false,491 .reflect_input = false,
...@@ -505,7 +493,7 @@ pub const Crc16Ibm3740 = Crc(u16, .{...@@ -505,7 +493,7 @@ pub const Crc16Ibm3740 = Crc(u16, .{
505 .xor_output = 0x0000,493 .xor_output = 0x0000,
506});494});
507495
508pub const Crc16IbmSdlc = Crc(u16, .{496pub const Crc16IbmSdlc = Generic(u16, .{
509 .polynomial = 0x1021,497 .polynomial = 0x1021,
510 .initial = 0xffff,498 .initial = 0xffff,
511 .reflect_input = true,499 .reflect_input = true,
...@@ -513,7 +501,7 @@ pub const Crc16IbmSdlc = Crc(u16, .{...@@ -513,7 +501,7 @@ pub const Crc16IbmSdlc = Crc(u16, .{
513 .xor_output = 0xffff,501 .xor_output = 0xffff,
514});502});
515503
516pub const Crc16IsoIec144433A = Crc(u16, .{504pub const Crc16IsoIec144433A = Generic(u16, .{
517 .polynomial = 0x1021,505 .polynomial = 0x1021,
518 .initial = 0xc6c6,506 .initial = 0xc6c6,
519 .reflect_input = true,507 .reflect_input = true,
...@@ -521,7 +509,7 @@ pub const Crc16IsoIec144433A = Crc(u16, .{...@@ -521,7 +509,7 @@ pub const Crc16IsoIec144433A = Crc(u16, .{
521 .xor_output = 0x0000,509 .xor_output = 0x0000,
522});510});
523511
524pub const Crc16Kermit = Crc(u16, .{512pub const Crc16Kermit = Generic(u16, .{
525 .polynomial = 0x1021,513 .polynomial = 0x1021,
526 .initial = 0x0000,514 .initial = 0x0000,
527 .reflect_input = true,515 .reflect_input = true,
...@@ -529,7 +517,7 @@ pub const Crc16Kermit = Crc(u16, .{...@@ -529,7 +517,7 @@ pub const Crc16Kermit = Crc(u16, .{
529 .xor_output = 0x0000,517 .xor_output = 0x0000,
530});518});
531519
532pub const Crc16Lj1200 = Crc(u16, .{520pub const Crc16Lj1200 = Generic(u16, .{
533 .polynomial = 0x6f63,521 .polynomial = 0x6f63,
534 .initial = 0x0000,522 .initial = 0x0000,
535 .reflect_input = false,523 .reflect_input = false,
...@@ -537,7 +525,7 @@ pub const Crc16Lj1200 = Crc(u16, .{...@@ -537,7 +525,7 @@ pub const Crc16Lj1200 = Crc(u16, .{
537 .xor_output = 0x0000,525 .xor_output = 0x0000,
538});526});
539527
540pub const Crc16M17 = Crc(u16, .{528pub const Crc16M17 = Generic(u16, .{
541 .polynomial = 0x5935,529 .polynomial = 0x5935,
542 .initial = 0xffff,530 .initial = 0xffff,
543 .reflect_input = false,531 .reflect_input = false,
...@@ -545,7 +533,7 @@ pub const Crc16M17 = Crc(u16, .{...@@ -545,7 +533,7 @@ pub const Crc16M17 = Crc(u16, .{
545 .xor_output = 0x0000,533 .xor_output = 0x0000,
546});534});
547535
548pub const Crc16MaximDow = Crc(u16, .{536pub const Crc16MaximDow = Generic(u16, .{
549 .polynomial = 0x8005,537 .polynomial = 0x8005,
550 .initial = 0x0000,538 .initial = 0x0000,
551 .reflect_input = true,539 .reflect_input = true,
...@@ -553,7 +541,7 @@ pub const Crc16MaximDow = Crc(u16, .{...@@ -553,7 +541,7 @@ pub const Crc16MaximDow = Crc(u16, .{
553 .xor_output = 0xffff,541 .xor_output = 0xffff,
554});542});
555543
556pub const Crc16Mcrf4xx = Crc(u16, .{544pub const Crc16Mcrf4xx = Generic(u16, .{
557 .polynomial = 0x1021,545 .polynomial = 0x1021,
558 .initial = 0xffff,546 .initial = 0xffff,
559 .reflect_input = true,547 .reflect_input = true,
...@@ -561,7 +549,7 @@ pub const Crc16Mcrf4xx = Crc(u16, .{...@@ -561,7 +549,7 @@ pub const Crc16Mcrf4xx = Crc(u16, .{
561 .xor_output = 0x0000,549 .xor_output = 0x0000,
562});550});
563551
564pub const Crc16Modbus = Crc(u16, .{552pub const Crc16Modbus = Generic(u16, .{
565 .polynomial = 0x8005,553 .polynomial = 0x8005,
566 .initial = 0xffff,554 .initial = 0xffff,
567 .reflect_input = true,555 .reflect_input = true,
...@@ -569,7 +557,7 @@ pub const Crc16Modbus = Crc(u16, .{...@@ -569,7 +557,7 @@ pub const Crc16Modbus = Crc(u16, .{
569 .xor_output = 0x0000,557 .xor_output = 0x0000,
570});558});
571559
572pub const Crc16Nrsc5 = Crc(u16, .{560pub const Crc16Nrsc5 = Generic(u16, .{
573 .polynomial = 0x080b,561 .polynomial = 0x080b,
574 .initial = 0xffff,562 .initial = 0xffff,
575 .reflect_input = true,563 .reflect_input = true,
...@@ -577,7 +565,7 @@ pub const Crc16Nrsc5 = Crc(u16, .{...@@ -577,7 +565,7 @@ pub const Crc16Nrsc5 = Crc(u16, .{
577 .xor_output = 0x0000,565 .xor_output = 0x0000,
578});566});
579567
580pub const Crc16OpensafetyA = Crc(u16, .{568pub const Crc16OpensafetyA = Generic(u16, .{
581 .polynomial = 0x5935,569 .polynomial = 0x5935,
582 .initial = 0x0000,570 .initial = 0x0000,
583 .reflect_input = false,571 .reflect_input = false,
...@@ -585,7 +573,7 @@ pub const Crc16OpensafetyA = Crc(u16, .{...@@ -585,7 +573,7 @@ pub const Crc16OpensafetyA = Crc(u16, .{
585 .xor_output = 0x0000,573 .xor_output = 0x0000,
586});574});
587575
588pub const Crc16OpensafetyB = Crc(u16, .{576pub const Crc16OpensafetyB = Generic(u16, .{
589 .polynomial = 0x755b,577 .polynomial = 0x755b,
590 .initial = 0x0000,578 .initial = 0x0000,
591 .reflect_input = false,579 .reflect_input = false,
...@@ -593,7 +581,7 @@ pub const Crc16OpensafetyB = Crc(u16, .{...@@ -593,7 +581,7 @@ pub const Crc16OpensafetyB = Crc(u16, .{
593 .xor_output = 0x0000,581 .xor_output = 0x0000,
594});582});
595583
596pub const Crc16Profibus = Crc(u16, .{584pub const Crc16Profibus = Generic(u16, .{
597 .polynomial = 0x1dcf,585 .polynomial = 0x1dcf,
598 .initial = 0xffff,586 .initial = 0xffff,
599 .reflect_input = false,587 .reflect_input = false,
...@@ -601,7 +589,7 @@ pub const Crc16Profibus = Crc(u16, .{...@@ -601,7 +589,7 @@ pub const Crc16Profibus = Crc(u16, .{
601 .xor_output = 0xffff,589 .xor_output = 0xffff,
602});590});
603591
604pub const Crc16Riello = Crc(u16, .{592pub const Crc16Riello = Generic(u16, .{
605 .polynomial = 0x1021,593 .polynomial = 0x1021,
606 .initial = 0xb2aa,594 .initial = 0xb2aa,
607 .reflect_input = true,595 .reflect_input = true,
...@@ -609,7 +597,7 @@ pub const Crc16Riello = Crc(u16, .{...@@ -609,7 +597,7 @@ pub const Crc16Riello = Crc(u16, .{
609 .xor_output = 0x0000,597 .xor_output = 0x0000,
610});598});
611599
612pub const Crc16SpiFujitsu = Crc(u16, .{600pub const Crc16SpiFujitsu = Generic(u16, .{
613 .polynomial = 0x1021,601 .polynomial = 0x1021,
614 .initial = 0x1d0f,602 .initial = 0x1d0f,
615 .reflect_input = false,603 .reflect_input = false,
...@@ -617,7 +605,7 @@ pub const Crc16SpiFujitsu = Crc(u16, .{...@@ -617,7 +605,7 @@ pub const Crc16SpiFujitsu = Crc(u16, .{
617 .xor_output = 0x0000,605 .xor_output = 0x0000,
618});606});
619607
620pub const Crc16T10Dif = Crc(u16, .{608pub const Crc16T10Dif = Generic(u16, .{
621 .polynomial = 0x8bb7,609 .polynomial = 0x8bb7,
622 .initial = 0x0000,610 .initial = 0x0000,
623 .reflect_input = false,611 .reflect_input = false,
...@@ -625,7 +613,7 @@ pub const Crc16T10Dif = Crc(u16, .{...@@ -625,7 +613,7 @@ pub const Crc16T10Dif = Crc(u16, .{
625 .xor_output = 0x0000,613 .xor_output = 0x0000,
626});614});
627615
628pub const Crc16Teledisk = Crc(u16, .{616pub const Crc16Teledisk = Generic(u16, .{
629 .polynomial = 0xa097,617 .polynomial = 0xa097,
630 .initial = 0x0000,618 .initial = 0x0000,
631 .reflect_input = false,619 .reflect_input = false,
...@@ -633,7 +621,7 @@ pub const Crc16Teledisk = Crc(u16, .{...@@ -633,7 +621,7 @@ pub const Crc16Teledisk = Crc(u16, .{
633 .xor_output = 0x0000,621 .xor_output = 0x0000,
634});622});
635623
636pub const Crc16Tms37157 = Crc(u16, .{624pub const Crc16Tms37157 = Generic(u16, .{
637 .polynomial = 0x1021,625 .polynomial = 0x1021,
638 .initial = 0x89ec,626 .initial = 0x89ec,
639 .reflect_input = true,627 .reflect_input = true,
...@@ -641,7 +629,7 @@ pub const Crc16Tms37157 = Crc(u16, .{...@@ -641,7 +629,7 @@ pub const Crc16Tms37157 = Crc(u16, .{
641 .xor_output = 0x0000,629 .xor_output = 0x0000,
642});630});
643631
644pub const Crc16Umts = Crc(u16, .{632pub const Crc16Umts = Generic(u16, .{
645 .polynomial = 0x8005,633 .polynomial = 0x8005,
646 .initial = 0x0000,634 .initial = 0x0000,
647 .reflect_input = false,635 .reflect_input = false,
...@@ -649,7 +637,7 @@ pub const Crc16Umts = Crc(u16, .{...@@ -649,7 +637,7 @@ pub const Crc16Umts = Crc(u16, .{
649 .xor_output = 0x0000,637 .xor_output = 0x0000,
650});638});
651639
652pub const Crc16Usb = Crc(u16, .{640pub const Crc16Usb = Generic(u16, .{
653 .polynomial = 0x8005,641 .polynomial = 0x8005,
654 .initial = 0xffff,642 .initial = 0xffff,
655 .reflect_input = true,643 .reflect_input = true,
...@@ -657,7 +645,7 @@ pub const Crc16Usb = Crc(u16, .{...@@ -657,7 +645,7 @@ pub const Crc16Usb = Crc(u16, .{
657 .xor_output = 0xffff,645 .xor_output = 0xffff,
658});646});
659647
660pub const Crc16Xmodem = Crc(u16, .{648pub const Crc16Xmodem = Generic(u16, .{
661 .polynomial = 0x1021,649 .polynomial = 0x1021,
662 .initial = 0x0000,650 .initial = 0x0000,
663 .reflect_input = false,651 .reflect_input = false,
...@@ -665,7 +653,7 @@ pub const Crc16Xmodem = Crc(u16, .{...@@ -665,7 +653,7 @@ pub const Crc16Xmodem = Crc(u16, .{
665 .xor_output = 0x0000,653 .xor_output = 0x0000,
666});654});
667655
668pub const Crc17CanFd = Crc(u17, .{656pub const Crc17CanFd = Generic(u17, .{
669 .polynomial = 0x1685b,657 .polynomial = 0x1685b,
670 .initial = 0x00000,658 .initial = 0x00000,
671 .reflect_input = false,659 .reflect_input = false,
...@@ -673,7 +661,7 @@ pub const Crc17CanFd = Crc(u17, .{...@@ -673,7 +661,7 @@ pub const Crc17CanFd = Crc(u17, .{
673 .xor_output = 0x00000,661 .xor_output = 0x00000,
674});662});
675663
676pub const Crc21CanFd = Crc(u21, .{664pub const Crc21CanFd = Generic(u21, .{
677 .polynomial = 0x102899,665 .polynomial = 0x102899,
678 .initial = 0x000000,666 .initial = 0x000000,
679 .reflect_input = false,667 .reflect_input = false,
...@@ -681,7 +669,7 @@ pub const Crc21CanFd = Crc(u21, .{...@@ -681,7 +669,7 @@ pub const Crc21CanFd = Crc(u21, .{
681 .xor_output = 0x000000,669 .xor_output = 0x000000,
682});670});
683671
684pub const Crc24Ble = Crc(u24, .{672pub const Crc24Ble = Generic(u24, .{
685 .polynomial = 0x00065b,673 .polynomial = 0x00065b,
686 .initial = 0x555555,674 .initial = 0x555555,
687 .reflect_input = true,675 .reflect_input = true,
...@@ -689,7 +677,7 @@ pub const Crc24Ble = Crc(u24, .{...@@ -689,7 +677,7 @@ pub const Crc24Ble = Crc(u24, .{
689 .xor_output = 0x000000,677 .xor_output = 0x000000,
690});678});
691679
692pub const Crc24FlexrayA = Crc(u24, .{680pub const Crc24FlexrayA = Generic(u24, .{
693 .polynomial = 0x5d6dcb,681 .polynomial = 0x5d6dcb,
694 .initial = 0xfedcba,682 .initial = 0xfedcba,
695 .reflect_input = false,683 .reflect_input = false,
...@@ -697,7 +685,7 @@ pub const Crc24FlexrayA = Crc(u24, .{...@@ -697,7 +685,7 @@ pub const Crc24FlexrayA = Crc(u24, .{
697 .xor_output = 0x000000,685 .xor_output = 0x000000,
698});686});
699687
700pub const Crc24FlexrayB = Crc(u24, .{688pub const Crc24FlexrayB = Generic(u24, .{
701 .polynomial = 0x5d6dcb,689 .polynomial = 0x5d6dcb,
702 .initial = 0xabcdef,690 .initial = 0xabcdef,
703 .reflect_input = false,691 .reflect_input = false,
...@@ -705,7 +693,7 @@ pub const Crc24FlexrayB = Crc(u24, .{...@@ -705,7 +693,7 @@ pub const Crc24FlexrayB = Crc(u24, .{
705 .xor_output = 0x000000,693 .xor_output = 0x000000,
706});694});
707695
708pub const Crc24Interlaken = Crc(u24, .{696pub const Crc24Interlaken = Generic(u24, .{
709 .polynomial = 0x328b63,697 .polynomial = 0x328b63,
710 .initial = 0xffffff,698 .initial = 0xffffff,
711 .reflect_input = false,699 .reflect_input = false,
...@@ -713,7 +701,7 @@ pub const Crc24Interlaken = Crc(u24, .{...@@ -713,7 +701,7 @@ pub const Crc24Interlaken = Crc(u24, .{
713 .xor_output = 0xffffff,701 .xor_output = 0xffffff,
714});702});
715703
716pub const Crc24LteA = Crc(u24, .{704pub const Crc24LteA = Generic(u24, .{
717 .polynomial = 0x864cfb,705 .polynomial = 0x864cfb,
718 .initial = 0x000000,706 .initial = 0x000000,
719 .reflect_input = false,707 .reflect_input = false,
...@@ -721,7 +709,7 @@ pub const Crc24LteA = Crc(u24, .{...@@ -721,7 +709,7 @@ pub const Crc24LteA = Crc(u24, .{
721 .xor_output = 0x000000,709 .xor_output = 0x000000,
722});710});
723711
724pub const Crc24LteB = Crc(u24, .{712pub const Crc24LteB = Generic(u24, .{
725 .polynomial = 0x800063,713 .polynomial = 0x800063,
726 .initial = 0x000000,714 .initial = 0x000000,
727 .reflect_input = false,715 .reflect_input = false,
...@@ -729,7 +717,7 @@ pub const Crc24LteB = Crc(u24, .{...@@ -729,7 +717,7 @@ pub const Crc24LteB = Crc(u24, .{
729 .xor_output = 0x000000,717 .xor_output = 0x000000,
730});718});
731719
732pub const Crc24Openpgp = Crc(u24, .{720pub const Crc24Openpgp = Generic(u24, .{
733 .polynomial = 0x864cfb,721 .polynomial = 0x864cfb,
734 .initial = 0xb704ce,722 .initial = 0xb704ce,
735 .reflect_input = false,723 .reflect_input = false,
...@@ -737,7 +725,7 @@ pub const Crc24Openpgp = Crc(u24, .{...@@ -737,7 +725,7 @@ pub const Crc24Openpgp = Crc(u24, .{
737 .xor_output = 0x000000,725 .xor_output = 0x000000,
738});726});
739727
740pub const Crc24Os9 = Crc(u24, .{728pub const Crc24Os9 = Generic(u24, .{
741 .polynomial = 0x800063,729 .polynomial = 0x800063,
742 .initial = 0xffffff,730 .initial = 0xffffff,
743 .reflect_input = false,731 .reflect_input = false,
...@@ -745,7 +733,7 @@ pub const Crc24Os9 = Crc(u24, .{...@@ -745,7 +733,7 @@ pub const Crc24Os9 = Crc(u24, .{
745 .xor_output = 0xffffff,733 .xor_output = 0xffffff,
746});734});
747735
748pub const Crc30Cdma = Crc(u30, .{736pub const Crc30Cdma = Generic(u30, .{
749 .polynomial = 0x2030b9c7,737 .polynomial = 0x2030b9c7,
750 .initial = 0x3fffffff,738 .initial = 0x3fffffff,
751 .reflect_input = false,739 .reflect_input = false,
...@@ -753,7 +741,7 @@ pub const Crc30Cdma = Crc(u30, .{...@@ -753,7 +741,7 @@ pub const Crc30Cdma = Crc(u30, .{
753 .xor_output = 0x3fffffff,741 .xor_output = 0x3fffffff,
754});742});
755743
756pub const Crc31Philips = Crc(u31, .{744pub const Crc31Philips = Generic(u31, .{
757 .polynomial = 0x04c11db7,745 .polynomial = 0x04c11db7,
758 .initial = 0x7fffffff,746 .initial = 0x7fffffff,
759 .reflect_input = false,747 .reflect_input = false,
...@@ -761,7 +749,7 @@ pub const Crc31Philips = Crc(u31, .{...@@ -761,7 +749,7 @@ pub const Crc31Philips = Crc(u31, .{
761 .xor_output = 0x7fffffff,749 .xor_output = 0x7fffffff,
762});750});
763751
764pub const Crc32Aixm = Crc(u32, .{752pub const Crc32Aixm = Generic(u32, .{
765 .polynomial = 0x814141ab,753 .polynomial = 0x814141ab,
766 .initial = 0x00000000,754 .initial = 0x00000000,
767 .reflect_input = false,755 .reflect_input = false,
...@@ -769,7 +757,7 @@ pub const Crc32Aixm = Crc(u32, .{...@@ -769,7 +757,7 @@ pub const Crc32Aixm = Crc(u32, .{
769 .xor_output = 0x00000000,757 .xor_output = 0x00000000,
770});758});
771759
772pub const Crc32Autosar = Crc(u32, .{760pub const Crc32Autosar = Generic(u32, .{
773 .polynomial = 0xf4acfb13,761 .polynomial = 0xf4acfb13,
774 .initial = 0xffffffff,762 .initial = 0xffffffff,
775 .reflect_input = true,763 .reflect_input = true,
...@@ -777,7 +765,7 @@ pub const Crc32Autosar = Crc(u32, .{...@@ -777,7 +765,7 @@ pub const Crc32Autosar = Crc(u32, .{
777 .xor_output = 0xffffffff,765 .xor_output = 0xffffffff,
778});766});
779767
780pub const Crc32Base91D = Crc(u32, .{768pub const Crc32Base91D = Generic(u32, .{
781 .polynomial = 0xa833982b,769 .polynomial = 0xa833982b,
782 .initial = 0xffffffff,770 .initial = 0xffffffff,
783 .reflect_input = true,771 .reflect_input = true,
...@@ -785,7 +773,7 @@ pub const Crc32Base91D = Crc(u32, .{...@@ -785,7 +773,7 @@ pub const Crc32Base91D = Crc(u32, .{
785 .xor_output = 0xffffffff,773 .xor_output = 0xffffffff,
786});774});
787775
788pub const Crc32Bzip2 = Crc(u32, .{776pub const Crc32Bzip2 = Generic(u32, .{
789 .polynomial = 0x04c11db7,777 .polynomial = 0x04c11db7,
790 .initial = 0xffffffff,778 .initial = 0xffffffff,
791 .reflect_input = false,779 .reflect_input = false,
...@@ -793,7 +781,7 @@ pub const Crc32Bzip2 = Crc(u32, .{...@@ -793,7 +781,7 @@ pub const Crc32Bzip2 = Crc(u32, .{
793 .xor_output = 0xffffffff,781 .xor_output = 0xffffffff,
794});782});
795783
796pub const Crc32CdRomEdc = Crc(u32, .{784pub const Crc32CdRomEdc = Generic(u32, .{
797 .polynomial = 0x8001801b,785 .polynomial = 0x8001801b,
798 .initial = 0x00000000,786 .initial = 0x00000000,
799 .reflect_input = true,787 .reflect_input = true,
...@@ -801,7 +789,7 @@ pub const Crc32CdRomEdc = Crc(u32, .{...@@ -801,7 +789,7 @@ pub const Crc32CdRomEdc = Crc(u32, .{
801 .xor_output = 0x00000000,789 .xor_output = 0x00000000,
802});790});
803791
804pub const Crc32Cksum = Crc(u32, .{792pub const Crc32Cksum = Generic(u32, .{
805 .polynomial = 0x04c11db7,793 .polynomial = 0x04c11db7,
806 .initial = 0x00000000,794 .initial = 0x00000000,
807 .reflect_input = false,795 .reflect_input = false,
...@@ -809,7 +797,7 @@ pub const Crc32Cksum = Crc(u32, .{...@@ -809,7 +797,7 @@ pub const Crc32Cksum = Crc(u32, .{
809 .xor_output = 0xffffffff,797 .xor_output = 0xffffffff,
810});798});
811799
812pub const Crc32IsoHdlc = Crc(u32, .{800pub const Crc32IsoHdlc = Generic(u32, .{
813 .polynomial = 0x04c11db7,801 .polynomial = 0x04c11db7,
814 .initial = 0xffffffff,802 .initial = 0xffffffff,
815 .reflect_input = true,803 .reflect_input = true,
...@@ -817,7 +805,7 @@ pub const Crc32IsoHdlc = Crc(u32, .{...@@ -817,7 +805,7 @@ pub const Crc32IsoHdlc = Crc(u32, .{
817 .xor_output = 0xffffffff,805 .xor_output = 0xffffffff,
818});806});
819807
820pub const Crc32Jamcrc = Crc(u32, .{808pub const Crc32Jamcrc = Generic(u32, .{
821 .polynomial = 0x04c11db7,809 .polynomial = 0x04c11db7,
822 .initial = 0xffffffff,810 .initial = 0xffffffff,
823 .reflect_input = true,811 .reflect_input = true,
...@@ -825,7 +813,7 @@ pub const Crc32Jamcrc = Crc(u32, .{...@@ -825,7 +813,7 @@ pub const Crc32Jamcrc = Crc(u32, .{
825 .xor_output = 0x00000000,813 .xor_output = 0x00000000,
826});814});
827815
828pub const Crc32Koopman = Crc(u32, .{816pub const Crc32Koopman = Generic(u32, .{
829 .polynomial = 0x741b8cd7,817 .polynomial = 0x741b8cd7,
830 .initial = 0xffffffff,818 .initial = 0xffffffff,
831 .reflect_input = true,819 .reflect_input = true,
...@@ -833,7 +821,7 @@ pub const Crc32Koopman = Crc(u32, .{...@@ -833,7 +821,7 @@ pub const Crc32Koopman = Crc(u32, .{
833 .xor_output = 0xffffffff,821 .xor_output = 0xffffffff,
834});822});
835823
836pub const Crc32Mef = Crc(u32, .{824pub const Crc32Mef = Generic(u32, .{
837 .polynomial = 0x741b8cd7,825 .polynomial = 0x741b8cd7,
838 .initial = 0xffffffff,826 .initial = 0xffffffff,
839 .reflect_input = true,827 .reflect_input = true,
...@@ -841,7 +829,7 @@ pub const Crc32Mef = Crc(u32, .{...@@ -841,7 +829,7 @@ pub const Crc32Mef = Crc(u32, .{
841 .xor_output = 0x00000000,829 .xor_output = 0x00000000,
842});830});
843831
844pub const Crc32Mpeg2 = Crc(u32, .{832pub const Crc32Mpeg2 = Generic(u32, .{
845 .polynomial = 0x04c11db7,833 .polynomial = 0x04c11db7,
846 .initial = 0xffffffff,834 .initial = 0xffffffff,
847 .reflect_input = false,835 .reflect_input = false,
...@@ -849,7 +837,7 @@ pub const Crc32Mpeg2 = Crc(u32, .{...@@ -849,7 +837,7 @@ pub const Crc32Mpeg2 = Crc(u32, .{
849 .xor_output = 0x00000000,837 .xor_output = 0x00000000,
850});838});
851839
852pub const Crc32Xfer = Crc(u32, .{840pub const Crc32Xfer = Generic(u32, .{
853 .polynomial = 0x000000af,841 .polynomial = 0x000000af,
854 .initial = 0x00000000,842 .initial = 0x00000000,
855 .reflect_input = false,843 .reflect_input = false,
...@@ -857,7 +845,7 @@ pub const Crc32Xfer = Crc(u32, .{...@@ -857,7 +845,7 @@ pub const Crc32Xfer = Crc(u32, .{
857 .xor_output = 0x00000000,845 .xor_output = 0x00000000,
858});846});
859847
860pub const Crc40Gsm = Crc(u40, .{848pub const Crc40Gsm = Generic(u40, .{
861 .polynomial = 0x0004820009,849 .polynomial = 0x0004820009,
862 .initial = 0x0000000000,850 .initial = 0x0000000000,
863 .reflect_input = false,851 .reflect_input = false,
...@@ -865,7 +853,7 @@ pub const Crc40Gsm = Crc(u40, .{...@@ -865,7 +853,7 @@ pub const Crc40Gsm = Crc(u40, .{
865 .xor_output = 0xffffffffff,853 .xor_output = 0xffffffffff,
866});854});
867855
868pub const Crc64Ecma182 = Crc(u64, .{856pub const Crc64Ecma182 = Generic(u64, .{
869 .polynomial = 0x42f0e1eba9ea3693,857 .polynomial = 0x42f0e1eba9ea3693,
870 .initial = 0x0000000000000000,858 .initial = 0x0000000000000000,
871 .reflect_input = false,859 .reflect_input = false,
...@@ -873,7 +861,7 @@ pub const Crc64Ecma182 = Crc(u64, .{...@@ -873,7 +861,7 @@ pub const Crc64Ecma182 = Crc(u64, .{
873 .xor_output = 0x0000000000000000,861 .xor_output = 0x0000000000000000,
874});862});
875863
876pub const Crc64GoIso = Crc(u64, .{864pub const Crc64GoIso = Generic(u64, .{
877 .polynomial = 0x000000000000001b,865 .polynomial = 0x000000000000001b,
878 .initial = 0xffffffffffffffff,866 .initial = 0xffffffffffffffff,
879 .reflect_input = true,867 .reflect_input = true,
...@@ -881,7 +869,7 @@ pub const Crc64GoIso = Crc(u64, .{...@@ -881,7 +869,7 @@ pub const Crc64GoIso = Crc(u64, .{
881 .xor_output = 0xffffffffffffffff,869 .xor_output = 0xffffffffffffffff,
882});870});
883871
884pub const Crc64Ms = Crc(u64, .{872pub const Crc64Ms = Generic(u64, .{
885 .polynomial = 0x259c84cba6426349,873 .polynomial = 0x259c84cba6426349,
886 .initial = 0xffffffffffffffff,874 .initial = 0xffffffffffffffff,
887 .reflect_input = true,875 .reflect_input = true,
...@@ -889,7 +877,7 @@ pub const Crc64Ms = Crc(u64, .{...@@ -889,7 +877,7 @@ pub const Crc64Ms = Crc(u64, .{
889 .xor_output = 0x0000000000000000,877 .xor_output = 0x0000000000000000,
890});878});
891879
892pub const Crc64Redis = Crc(u64, .{880pub const Crc64Redis = Generic(u64, .{
893 .polynomial = 0xad93d23594c935a9,881 .polynomial = 0xad93d23594c935a9,
894 .initial = 0x0000000000000000,882 .initial = 0x0000000000000000,
895 .reflect_input = true,883 .reflect_input = true,
...@@ -897,7 +885,7 @@ pub const Crc64Redis = Crc(u64, .{...@@ -897,7 +885,7 @@ pub const Crc64Redis = Crc(u64, .{
897 .xor_output = 0x0000000000000000,885 .xor_output = 0x0000000000000000,
898});886});
899887
900pub const Crc64We = Crc(u64, .{888pub const Crc64We = Generic(u64, .{
901 .polynomial = 0x42f0e1eba9ea3693,889 .polynomial = 0x42f0e1eba9ea3693,
902 .initial = 0xffffffffffffffff,890 .initial = 0xffffffffffffffff,
903 .reflect_input = false,891 .reflect_input = false,
...@@ -905,7 +893,7 @@ pub const Crc64We = Crc(u64, .{...@@ -905,7 +893,7 @@ pub const Crc64We = Crc(u64, .{
905 .xor_output = 0xffffffffffffffff,893 .xor_output = 0xffffffffffffffff,
906});894});
907895
908pub const Crc64Xz = Crc(u64, .{896pub const Crc64Xz = Generic(u64, .{
909 .polynomial = 0x42f0e1eba9ea3693,897 .polynomial = 0x42f0e1eba9ea3693,
910 .initial = 0xffffffffffffffff,898 .initial = 0xffffffffffffffff,
911 .reflect_input = true,899 .reflect_input = true,
...@@ -913,10 +901,109 @@ pub const Crc64Xz = Crc(u64, .{...@@ -913,10 +901,109 @@ pub const Crc64Xz = Crc(u64, .{
913 .xor_output = 0xffffffffffffffff,901 .xor_output = 0xffffffffffffffff,
914});902});
915903
916pub const Crc82Darc = Crc(u82, .{904pub const Crc82Darc = Generic(u82, .{
917 .polynomial = 0x0308c0111011401440411,905 .polynomial = 0x0308c0111011401440411,
918 .initial = 0x000000000000000000000,906 .initial = 0x000000000000000000000,
919 .reflect_input = true,907 .reflect_input = true,
920 .reflect_output = true,908 .reflect_output = true,
921 .xor_output = 0x000000000000000000000,909 .xor_output = 0x000000000000000000000,
922});910});
911
912pub fn Algorithm(comptime W: type) type {
913 return struct {
914 polynomial: W,
915 initial: W,
916 reflect_input: bool,
917 reflect_output: bool,
918 xor_output: W,
919 };
920}
921
922pub fn Generic(comptime W: type, comptime algorithm: Algorithm(W)) type {
923 return struct {
924 const Self = @This();
925 const I = if (@bitSizeOf(W) < 8) u8 else W;
926 const lookup_table = blk: {
927 @setEvalBranchQuota(2500);
928 const poly = reflect(algorithm.polynomial);
929 var table: [256]I = undefined;
930 for (&table, 0..) |*e, i| {
931 var crc: I = i;
932 if (algorithm.reflect_input) {
933 var j: usize = 0;
934 while (j < 8) : (j += 1) {
935 crc = (crc >> 1) ^ ((crc & 1) * poly);
936 }
937 } else {
938 crc <<= @bitSizeOf(I) - 8;
939 var j: usize = 0;
940 while (j < 8) : (j += 1) {
941 crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
942 }
943 }
944 e.* = crc;
945 }
946 break :blk table;
947 };
948
949 crc: I,
950
951 pub fn init() Self {
952 const initial = reflect(algorithm.initial);
953 return .{ .crc = initial };
954 }
955
956 inline fn tableEntry(index: I) I {
957 const short: u8 = @truncate(index);
958 return lookup_table[short];
959 }
960
961 pub fn update(self: *Self, bytes: []const u8) void {
962 var i: usize = 0;
963 if (@bitSizeOf(I) <= 8) {
964 while (i < bytes.len) : (i += 1) {
965 self.crc = tableEntry(self.crc ^ bytes[i]);
966 }
967 } else if (algorithm.reflect_input) {
968 while (i < bytes.len) : (i += 1) {
969 const table_index = self.crc ^ bytes[i];
970 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
971 }
972 } else {
973 while (i < bytes.len) : (i += 1) {
974 const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
975 self.crc = tableEntry(table_index) ^ (self.crc << 8);
976 }
977 }
978 }
979
980 pub fn final(self: Self) W {
981 var c = self.crc;
982 if (algorithm.reflect_input != algorithm.reflect_output) {
983 c = @bitReverse(c);
984 }
985 if (!algorithm.reflect_output) {
986 c >>= @bitSizeOf(I) - @bitSizeOf(W);
987 }
988 return @intCast(c ^ algorithm.xor_output);
989 }
990
991 pub fn hash(bytes: []const u8) W {
992 var c = Self.init();
993 c.update(bytes);
994 return c.final();
995 }
996
997 fn reflect(x: I) I {
998 const offset = @bitSizeOf(I) - @bitSizeOf(W);
999 if (algorithm.reflect_input)
1000 return @bitReverse(x) >> offset
1001 else
1002 return x << offset;
1003 }
1004 };
1005}
1006
1007test {
1008 _ = @import("crc/test.zig");
1009}
lib/std/hash/crc/impl.zig deleted-103
...@@ -1,103 +0,0 @@
1// There is a generic CRC implementation "Crc()" which can be parameterized via
2// the Algorithm struct for a plethora of uses.
3//
4// The primary interface for all of the standard CRC algorithms is the
5// generated file "crc.zig", which uses the implementation code here to define
6// many standard CRCs.
7
8const std = @import("std");
9
10pub fn Algorithm(comptime W: type) type {
11 return struct {
12 polynomial: W,
13 initial: W,
14 reflect_input: bool,
15 reflect_output: bool,
16 xor_output: W,
17 };
18}
19
20pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
21 return struct {
22 const Self = @This();
23 const I = if (@bitSizeOf(W) < 8) u8 else W;
24 const lookup_table = blk: {
25 @setEvalBranchQuota(2500);
26 const poly = reflect(algorithm.polynomial);
27 var table: [256]I = undefined;
28 for (&table, 0..) |*e, i| {
29 var crc: I = i;
30 if (algorithm.reflect_input) {
31 var j: usize = 0;
32 while (j < 8) : (j += 1) {
33 crc = (crc >> 1) ^ ((crc & 1) * poly);
34 }
35 } else {
36 crc <<= @bitSizeOf(I) - 8;
37 var j: usize = 0;
38 while (j < 8) : (j += 1) {
39 crc = (crc << 1) ^ (((crc >> (@bitSizeOf(I) - 1)) & 1) * poly);
40 }
41 }
42 e.* = crc;
43 }
44 break :blk table;
45 };
46
47 crc: I,
48
49 pub fn init() Self {
50 const initial = reflect(algorithm.initial);
51 return .{ .crc = initial };
52 }
53
54 inline fn tableEntry(index: I) I {
55 const short: u8 = @truncate(index);
56 return lookup_table[short];
57 }
58
59 pub fn update(self: *Self, bytes: []const u8) void {
60 var i: usize = 0;
61 if (@bitSizeOf(I) <= 8) {
62 while (i < bytes.len) : (i += 1) {
63 self.crc = tableEntry(self.crc ^ bytes[i]);
64 }
65 } else if (algorithm.reflect_input) {
66 while (i < bytes.len) : (i += 1) {
67 const table_index = self.crc ^ bytes[i];
68 self.crc = tableEntry(table_index) ^ (self.crc >> 8);
69 }
70 } else {
71 while (i < bytes.len) : (i += 1) {
72 const table_index = (self.crc >> (@bitSizeOf(I) - 8)) ^ bytes[i];
73 self.crc = tableEntry(table_index) ^ (self.crc << 8);
74 }
75 }
76 }
77
78 pub fn final(self: Self) W {
79 var c = self.crc;
80 if (algorithm.reflect_input != algorithm.reflect_output) {
81 c = @bitReverse(c);
82 }
83 if (!algorithm.reflect_output) {
84 c >>= @bitSizeOf(I) - @bitSizeOf(W);
85 }
86 return @intCast(c ^ algorithm.xor_output);
87 }
88
89 pub fn hash(bytes: []const u8) W {
90 var c = Self.init();
91 c.update(bytes);
92 return c.final();
93 }
94
95 fn reflect(x: I) I {
96 const offset = @bitSizeOf(I) - @bitSizeOf(W);
97 if (algorithm.reflect_input)
98 return @bitReverse(x) >> offset
99 else
100 return x << offset;
101 }
102 };
103}