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 @@...@@ -2,17 +2,6 @@
22
3const builtin = @import("builtin");3const 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
16pub const @"CRC-3/GSM" = Generic(u3, .{5pub const @"CRC-3/GSM" = Generic(u3, .{
17 .polynomial = 0x3,6 .polynomial = 0x3,
18 .initial = 0x0,7 .initial = 0x0,
...@@ -797,6 +786,17 @@ pub const @"CRC-32/CKSUM" = Generic(u32, .{...@@ -797,6 +786,17 @@ pub const @"CRC-32/CKSUM" = Generic(u32, .{
797 .xor_output = 0xffffffff,786 .xor_output = 0xffffffff,
798});787});
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
800pub const @"CRC-32/ISO-HDLC" = Generic(u32, .{800pub const @"CRC-32/ISO-HDLC" = Generic(u32, .{
801 .polynomial = 0x04c11db7,801 .polynomial = 0x04c11db7,
802 .initial = 0xffffffff,802 .initial = 0xffffffff,
lib/std/hash/crc/test.zig+11-11
...@@ -26,17 +26,6 @@ test "crc32 koopman regression" {...@@ -26,17 +26,6 @@ test "crc32 koopman regression" {
26 try testing.expectEqual(Crc.hash("abc"), 0xba2322ac);26 try testing.expectEqual(Crc.hash("abc"), 0xba2322ac);
27}27}
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
40test "CRC-3/GSM" {29test "CRC-3/GSM" {
41 const Crc = crc.@"CRC-3/GSM";30 const Crc = crc.@"CRC-3/GSM";
4231
...@@ -1115,6 +1104,17 @@ test "CRC-32/CKSUM" {...@@ -1115,6 +1104,17 @@ test "CRC-32/CKSUM" {
1115 try testing.expectEqual(@as(u32, 0x765e7680), c.final());1104 try testing.expectEqual(@as(u32, 0x765e7680), c.final());
1116}1105}
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
1118test "CRC-32/ISO-HDLC" {1118test "CRC-32/ISO-HDLC" {
1119 const Crc = crc.@"CRC-32/ISO-HDLC";1119 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)...@@ -41,17 +41,6 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
41 \\41 \\
42 \\const builtin = @import("builtin");42 \\const builtin = @import("builtin");
43 \\43 \\
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 \\
55 );44 );
5645
57 var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{});46 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)...@@ -70,35 +59,24 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
70 \\const crc = @import("../crc.zig");59 \\const crc = @import("../crc.zig");
71 \\60 \\
72 \\test "crc32 ieee regression" {61 \\test "crc32 ieee regression" {
73 \\ const crc32 = crc.Crc32IsoHdlc;62 \\ const Crc = crc.@"CRC-32/ISO-HDLC";
74 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);63 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
75 \\ try testing.expectEqual(crc32.hash("a"), 0xe8b7be43);64 \\ try testing.expectEqual(Crc.hash("a"), 0xe8b7be43);
76 \\ try testing.expectEqual(crc32.hash("abc"), 0x352441c2);65 \\ try testing.expectEqual(Crc.hash("abc"), 0x352441c2);
77 \\}66 \\}
78 \\67 \\
79 \\test "crc32 castagnoli regression" {68 \\test "crc32 castagnoli regression" {
80 \\ const crc32 = crc.Crc32Iscsi;69 \\ const Crc = crc.@"CRC-32/ISCSI";
81 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);70 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
82 \\ try testing.expectEqual(crc32.hash("a"), 0xc1d04330);71 \\ try testing.expectEqual(Crc.hash("a"), 0xc1d04330);
83 \\ try testing.expectEqual(crc32.hash("abc"), 0x364b3fb7);72 \\ try testing.expectEqual(Crc.hash("abc"), 0x364b3fb7);
84 \\}73 \\}
85 \\74 \\
86 \\test "crc32 koopman regression" {75 \\test "crc32 koopman regression" {
87 \\ const crc32 = crc.Crc32Koopman;76 \\ const Crc = crc.@"CRC-32/KOOPMAN";
88 \\ try testing.expectEqual(crc32.hash(""), 0x00000000);77 \\ try testing.expectEqual(Crc.hash(""), 0x00000000);
89 \\ try testing.expectEqual(crc32.hash("a"), 0x0da2aa8a);78 \\ try testing.expectEqual(Crc.hash("a"), 0x0da2aa8a);
90 \\ try testing.expectEqual(crc32.hash("abc"), 0xba2322ac);79 \\ try testing.expectEqual(Crc.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());
102 \\}80 \\}
103 \\81 \\
104 );82 );
...@@ -147,17 +125,34 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)...@@ -147,17 +125,34 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8)
147 }125 }
148 }126 }
149127
150 try code_writer.print(128 if (mem.eql(u8, name, "CRC-32/ISCSI")) {
151 \\129 try code_writer.print(
152 \\pub const {f} = Generic(u{s}, .{{130 \\
153 \\ .polynomial = {s},131 \\pub const {f} = if (builtin.cpu.hasAll(.x86, &.{{ .@"64bit", .crc32 }}))
154 \\ .initial = {s},132 \\ @import("crc/Crc32c.zig")
155 \\ .reflect_input = {s},133 \\else
156 \\ .reflect_output = {s},134 \\ Generic(u{s}, .{{
157 \\ .xor_output = {s},135 \\ .polynomial = {s},
158 \\}});136 \\ .initial = {s},
159 \\137 \\ .reflect_input = {s},
160 , .{ std.zig.fmtId(name), width, poly, init, refin, refout, xorout });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
162 try test_writer.print(157 try test_writer.print(
163 \\158 \\