| ... | ... | @@ -41,17 +41,6 @@ fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8) |
| 41 | 41 | \\ |
| 42 | 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 | ); |
| 56 | 45 | |
| 57 | 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 | 59 | \\const crc = @import("../crc.zig"); |
| 71 | 60 | \\ |
| 72 | 61 | \\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); |
| 77 | 66 | \\} |
| 78 | 67 | \\ |
| 79 | 68 | \\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); |
| 84 | 73 | \\} |
| 85 | 74 | \\ |
| 86 | 75 | \\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); |
| 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 | 125 | } |
| 148 | 126 | } |
| 149 | 127 | |
| 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 | } |
| 161 | 156 | |
| 162 | 157 | try test_writer.print( |
| 163 | 158 | \\ |