Skip to content

Commit

Permalink
Add memsimd
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Dec 22, 2023
1 parent 0f830fd commit 1496956
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
18 changes: 18 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ const Libs = struct {
strip = true;
}

const memsimd = b.dependency("memsimd", .{
.target = target,
.optimize = optimize_mode,
});
const shared = b.addSharedLibrary(.{ .name = name, .root_source_file = .{ .path = path }, .target = target, .optimize = optimize_mode });
shared.strip = strip;
shared.force_pic = true;
shared.single_threaded = true;
shared.linker_allow_shlib_undefined = true;
shared.addModule("memsimd", memsimd.module("memsimd"));
if (target_info.target.os.tag != .macos) {
shared.want_lto = true;
}
Expand All @@ -27,6 +32,7 @@ const Libs = struct {
static.?.force_pic = true;
static.?.single_threaded = true;
static.?.linker_allow_shlib_undefined = true;
static.?.addModule("memsimd", memsimd.module("memsimd"));
if (target_info.target.os.tag != .macos) {
static.?.want_lto = true;
}
Expand All @@ -42,6 +48,12 @@ const Targets = struct {
fn create(b: *std.Build, name: []const u8, path: []const u8, target: std.zig.CrossTarget, target_info: std.zig.system.NativeTargetInfo, optimize_mode: std.builtin.Mode, with_static: bool) Targets {
const tests = b.addTest(.{ .root_source_file = .{ .path = path }, .target = target, .optimize = optimize_mode });

const memsimd = b.dependency("memsimd", .{
.target = target,
.optimize = optimize_mode,
});
tests.addModule("memsimd", memsimd.module("memsimd"));

return .{ .libs = Libs.create(b, name, path, target, target_info, optimize_mode, with_static), .tests = tests };
}
};
Expand Down Expand Up @@ -105,12 +117,18 @@ pub fn build(b: *std.Build) !void {
core_build_step.dependOn(&b.addInstallArtifact(core_targets.libs.shared, .{}).step);

// Defines modules
const memsimd = b.dependency("memsimd", .{
.target = target,
.optimize = optimize,
});
const kivi_mod = b.createModule(.{
.source_file = .{ .path = "src/core/Kivi.zig" },
});
const core_mod = b.createModule(.{
.source_file = .{ .path = "src/core/main.zig" },
});
try kivi_mod.dependencies.put("memsimd", memsimd.module("memsimd"));
try core_mod.dependencies.put("memsimd", memsimd.module("memsimd"));

// Compiles the JS driver
const drivers_build_step = b.step("drivers", "Builds all drivers");
Expand Down
12 changes: 12 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.{
.name = "kivi",
.version = "0.0.0",
.minimum_zig_version = "0.11.0",
.paths = .{ "src", "build.zig", "build.zig.zon" },
.dependencies = .{
.memsimd = .{
.url = "https://github.com/devraymondsh/memsimd/archive/refs/tags/v0.1.0.tar.gz",
.hash = "12208ce7ad284db242c305056b813b01213b74527310cc4c55523e09ff8db4ba5f9d",
},
},
}
5 changes: 2 additions & 3 deletions src/core/Hashmap.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const strcmp = @import("Strcmp.zig").strcmp;
const memsimd = @import("memsimd");

const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
Expand All @@ -12,8 +12,7 @@ pub const StringContext = struct {
}
pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
_ = self;
const x = strcmp(a, b);
return x;
return memsimd.avx.eql(u8, a, b);
}
};
pub fn StringHashMap(comptime V: type) type {
Expand Down
1 change: 0 additions & 1 deletion src/core/Kivi.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const MMap = @import("Mmap.zig");
const StringHashMap = @import("Hashmap.zig").StringHashMap;
const strcmp = @import("Strcmp.zig").strcmp;

pub const Config = extern struct {
maximum_elements: usize = 1_200_000,
Expand Down

0 comments on commit 1496956

Please sign in to comment.