authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-26 16:07:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-26 16:13:19-07:00
log072534bb2ab27addea2c8ffa2574e5c267b9de44
tree3051a6620187664c84f205211eaff8cdefbfd59d
parentc646f0e182d0161946be607a1c310767291f0722

std.hash.crc: restore auto-generated status


3 files changed, 62 insertions(+), 67 deletions(-)

lib/std/hash/crc.zig+11-11
......@@ -2,17 +2,6 @@
22
33const builtin = @import("builtin");
44
5pub const @"CRC-32/ISCSI" = if (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 }))
6 @import("crc/Crc32c.zig")
7else
8 Generic(u32, .{
9 .polynomial = 0x1edc6f41,
10 .initial = 0xffffffff,
11 .reflect_input = true,
12 .reflect_output = true,
13 .xor_output = 0xffffffff,
14 });
15
165pub const @"CRC-3/GSM" = Generic(u3, .{
176 .polynomial = 0x3,
187 .initial = 0x0,
......@@ -797,6 +786,17 @@ pub const @"CRC-32/CKSUM" = Generic(u32, .{
797786 .xor_output = 0xffffffff,
798787});
799788
789pub const @"CRC-32/ISCSI" = if (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 }))
790 @import("crc/Crc32c.zig")
791else
792 Generic(u32, .{
793 .polynomial = 0x1edc6f41,
794 .initial = 0xffffffff,
795 .reflect_input = true,
796 .reflect_output = true,
797 .xor_output = 0xffffffff,
798 });
799
800800pub const @"CRC-32/ISO-HDLC" = Generic(u32, .{
801801 .polynomial = 0x04c11db7,
802802 .initial = 0xffffffff,
lib/std/hash/crc/test.zig+11-11
......@@ -26,17 +26,6 @@ test "crc32 koopman regression" {
2626 try testing.expectEqual(Crc.hash("abc"), 0xba2322ac);
2727}
2828
29test "CRC-32/ISCSI" {
30 const Crc = crc.@"CRC-32/ISCSI";
31
32 try testing.expectEqual(@as(u32, 0xe3069283), Crc.hash("123456789"));
33
34 var c = Crc.init();
35 c.update("1234");
36 c.update("56789");
37 try testing.expectEqual(@as(u32, 0xe3069283), c.final());
38}
39
4029test "CRC-3/GSM" {
4130 const Crc = crc.@"CRC-3/GSM";
4231
......@@ -1115,6 +1104,17 @@ test "CRC-32/CKSUM" {
11151104 try testing.expectEqual(@as(u32, 0x765e7680), c.final());
11161105}
11171106
1107test "CRC-32/ISCSI" {
1108 const Crc = crc.@"CRC-32/ISCSI";
1109
1110 try testing.expectEqual(@as(u32, 0xe3069283), Crc.hash("123456789"));
1111
1112 var c = Crc.init();
1113 c.update("1234");
1114 c.update("56789");
1115 try testing.expectEqual(@as(u32, 0xe3069283), c.final());
1116}
1117
11181118test "CRC-32/ISO-HDLC" {
11191119 const Crc = crc.@"CRC-32/ISO-HDLC";
11201120
tools/update_crc_catalog.zig+40-45
......@@ -41,17 +41,6 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
4141 \\
4242 \\const builtin = @import("builtin");
4343 \\
44 \\pub const Crc32Iscsi = if (builtin.cpu.hasAll(.x86, &.{ .@"64bit", .crc32 }))
45 \\ @import("crc/Crc32c.zig")
46 \\else
47 \\ Generic(u32, .{
48 \\ .polynomial = 0x1edc6f41,
49 \\ .initial = 0xffffffff,
50 \\ .reflect_input = true,
51 \\ .reflect_output = true,
52 \\ .xor_output = 0xffffffff,
53 \\ });
54 \\
5544 );
5645
5746 var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{});
......@@ -70,35 +59,24 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
7059 \\const crc = @import("../crc.zig");
7160 \\
7261 \\test "crc32 ieee regression" {
73 \\ const crc32 = crc.Crc32IsoHdlc;
74 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);
75 \\ try testing.expectEqual(crc32.hash("a"), 0xe8b7be43);
76 \\ try testing.expectEqual(crc32.hash("abc"), 0x352441c2);
62 \\ const Crc = crc.@"CRC-32/ISO-HDLC";
63 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
64 \\ try testing.expectEqual(Crc.hash("a"), 0xe8b7be43);
65 \\ try testing.expectEqual(Crc.hash("abc"), 0x352441c2);
7766 \\}
7867 \\
7968 \\test "crc32 castagnoli regression" {
80 \\ const crc32 = crc.Crc32Iscsi;
81 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);
82 \\ try testing.expectEqual(crc32.hash("a"), 0xc1d04330);
83 \\ try testing.expectEqual(crc32.hash("abc"), 0x364b3fb7);
69 \\ const Crc = crc.@"CRC-32/ISCSI";
70 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
71 \\ try testing.expectEqual(Crc.hash("a"), 0xc1d04330);
72 \\ try testing.expectEqual(Crc.hash("abc"), 0x364b3fb7);
8473 \\}
8574 \\
8675 \\test "crc32 koopman regression" {
87 \\ const crc32 = crc.Crc32Koopman;
88 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);
89 \\ try testing.expectEqual(crc32.hash("a"), 0x0da2aa8a);
90 \\ try testing.expectEqual(crc32.hash("abc"), 0xba2322ac);
91 \\}
92 \\
93 \\test "CRC-32/ISCSI" {
94 \\ const Crc32Iscsi = crc.Crc32Iscsi;
95 \\
96 \\ try testing.expectEqual(@as(u32, 0xe3069283), Crc32Iscsi.hash("123456789"));
97 \\
98 \\ var c = Crc32Iscsi.init();
99 \\ c.update("1234");
100 \\ c.update("56789");
101 \\ try testing.expectEqual(@as(u32, 0xe3069283), c.final());
76 \\ const Crc = crc.@"CRC-32/KOOPMAN";
77 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
78 \\ try testing.expectEqual(Crc.hash("a"), 0x0da2aa8a);
79 \\ try testing.expectEqual(Crc.hash("abc"), 0xba2322ac);
10280 \\}
10381 \\
10482 );
......@@ -147,17 +125,34 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
147125 }
148126 }
149127
150 try code_writer.print(
151 \\
152 \\pub const {f} = Generic(u{s}, .{{
153 \\ .polynomial = {s},
154 \\ .initial = {s},
155 \\ .reflect_input = {s},
156 \\ .reflect_output = {s},
157 \\ .xor_output = {s},
158 \\}});
159 \\
160 , .{ std.zig.fmtId(name), width, poly, init, refin, refout, xorout });
128 if (mem.eql(u8, name, "CRC-32/ISCSI")) {
129 try code_writer.print(
130 \\
131 \\pub const {f} = if (builtin.cpu.hasAll(.x86, &.{{ .@"64bit", .crc32 }}))
132 \\ @import("crc/Crc32c.zig")
133 \\else
134 \\ Generic(u{s}, .{{
135 \\ .polynomial = {s},
136 \\ .initial = {s},
137 \\ .reflect_input = {s},
138 \\ .reflect_output = {s},
139 \\ .xor_output = {s},
140 \\ }});
141 \\
142 , .{ std.zig.fmtId(name), width, poly, init, refin, refout, xorout });
143 } else {
144 try code_writer.print(
145 \\
146 \\pub const {f} = Generic(u{s}, .{{
147 \\ .polynomial = {s},
148 \\ .initial = {s},
149 \\ .reflect_input = {s},
150 \\ .reflect_output = {s},
151 \\ .xor_output = {s},
152 \\}});
153 \\
154 , .{ std.zig.fmtId(name), width, poly, init, refin, refout, xorout });
155 }
161156
162157 try test_writer.print(
163158 \\