diff --git a/build.zig b/build.zig index bd36a12792..d4360476f4 100644 --- a/build.zig +++ b/build.zig @@ -14,32 +14,6 @@ pub fn build(b: *std.Build) void { const filter_test = b.option([]const u8, "filter-tests", "Filter tests by name"); const test_step = b.step("test", "Run library tests"); - // zimd - const zimd = b.addModule("zimd", CreateOptions{ - .root_source_file = .{ .path = "zig/zimd/zimd.zig" }, - .target = target, - .optimize = optimize, - .omit_frame_pointer = false, - .error_tracing = true, - .unwind_tables = true, - .strip = false, - }); - - // test zimd - const zimd_test = b.addTest(TestOptions{ - .root_source_file = .{ .path = "zig/zimd/zimd.zig" }, - .target = target, - .optimize = optimize, - .filter = filter_test, - .omit_frame_pointer = false, - .error_tracing = true, - .unwind_tables = true, - .strip = false, - }); - zimd_test.root_module.addImport("zimd", zimd); - const zimd_test_run = b.addRunArtifact(zimd_test); - test_step.dependOn(&zimd_test_run.step); - // C ABI types const c_abi_options = CreateOptions{ .root_source_file = .{ .path = "zig/c-abi/types.zig" }, @@ -68,7 +42,6 @@ pub fn build(b: *std.Build) void { .strip = false, }); codecz.addImport("abi", c_abi_types); - codecz.addImport("zimd", zimd); // test codecs const codecz_test = b.addTest(TestOptions{ @@ -84,7 +57,6 @@ pub fn build(b: *std.Build) void { }); codecz_test.root_module.addImport("codecz", codecz); codecz_test.root_module.addImport("abi", c_abi_types); - codecz_test.root_module.addImport("zimd", zimd); codecz_test.addIncludePath(.{ .path = "zig/c-abi/include" }); const codecz_test_run = b.addRunArtifact(codecz_test); test_step.dependOn(&codecz_test_run.step); @@ -105,7 +77,6 @@ pub fn build(b: *std.Build) void { }); lib_step.root_module.addImport("codecz", codecz); lib_step.root_module.addImport("abi", c_abi_types); - lib_step.root_module.addImport("zimd", zimd); lib_step.addIncludePath(.{ .path = "zig/c-abi/include" }); lib_step.root_module.c_std = std.Build.CStd.C11; lib_step.bundle_compiler_rt = true; diff --git a/zig/zimd/tblz.zig b/zig/zimd/tblz.zig deleted file mode 100644 index 124328599a..0000000000 --- a/zig/zimd/tblz.zig +++ /dev/null @@ -1,61 +0,0 @@ -/// TableLookupBytesOr0 -/// -/// returns bytes[indices[i]], or 0 if indices[i] & 0x80. -/// -/// Based on https://google.github.io/highway/en/master/quick_reference.html#blockwise -const builtin = @import("builtin"); -const std = @import("std"); -const zimd = @import("zimd.zig"); - -const TableLookupBytesOr0 = fn (bytes: @Vector(16, u8), indices: @Vector(16, i8)) callconv(.Inline) @Vector(16, u8); - -pub fn GetTableLookupBytesOr0(comptime cpu: std.Target.Cpu) TableLookupBytesOr0 { - if (comptime cpu.arch.isAARCH64() and std.Target.aarch64.featureSetHas(cpu.features, .neon)) { - return Aarch64_Neon; - } - if (comptime cpu.arch.isX86() and std.Target.x86.featureSetHas(cpu.features, .ssse3)) { - return X64_SSE3; - } - return Scalar; -} - -pub const tableLookupBytesOr0 = GetTableLookupBytesOr0(builtin.cpu); - -// For all vector widths; Arm anyway zeroes if >= 0x10. -inline fn Aarch64_Neon(bytes: @Vector(16, u8), indices: @Vector(16, i8)) @Vector(16, u8) { - return asm ("tbl.16b %[ret], { %[v0] }, %[v1]" - : [ret] "=w" (-> @Vector(16, u8)), - : [v0] "w" (bytes), - [v1] "w" (indices), - ); -} - -inline fn X64_SSE3(bytes: @Vector(16, u8), indices: @Vector(16, i8)) @Vector(16, u8) { - var result = bytes; - asm volatile ("pshufb %[indices], %[bytes]" - : [bytes] "+x" (result), - : [indices] "x" (indices), - ); - return result; -} - -inline fn Scalar(bytes: @Vector(16, u8), indices: @Vector(16, i8)) @Vector(16, u8) { - var result: @Vector(16, u8) = undefined; - inline for (0..16) |i| { - result[i] = if (indices[i] < 0) 0 else bytes[@intCast(indices[i])]; - } - return result; -} - -test "table lookup" { - const bytes: @Vector(16, u8) = .{ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 }; - const indices: @Vector(16, i8) = .{ 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, -1, -1, -1, -1 }; - - const expected: @Vector(16, u8) = .{ 0, 8, 16, 24, 2, 10, 18, 26, 4, 12, 20, 28, 0, 0, 0, 0 }; - - const nativeResult = tableLookupBytesOr0(bytes, indices); - try std.testing.expectEqual(expected, nativeResult); - - const scalarResult = GetTableLookupBytesOr0(zimd.baselineCpu)(bytes, indices); - try std.testing.expectEqual(expected, scalarResult); -} diff --git a/zig/zimd/zimd.zig b/zig/zimd/zimd.zig deleted file mode 100644 index dcf85b2f5b..0000000000 --- a/zig/zimd/zimd.zig +++ /dev/null @@ -1,6 +0,0 @@ -const builtin = @import("builtin"); -const std = @import("std"); - -pub const baselineCpu = std.Target.Cpu.baseline(builtin.cpu.arch); - -pub usingnamespace @import("tblz.zig");