Skip to content

Commit f86be77

Browse files
committed
add build options for lookup tablles
1 parent 534c19a commit f86be77

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

build.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX: Apache-2.0
22
// This file is part of zigpak.
33
const std = @import("std");
4+
const budopts = @import("./src/budopts.zig");
45

56
// Although this function looks imperative, note that its job is to
67
// declaratively construct a build graph that will be executed by an external
@@ -25,15 +26,30 @@ pub fn build(b: *std.Build) void {
2526

2627
const kcov = b.option([]const []const u8, "kcov", "Arguments for kcov in testing (default: null = disabled)");
2728

29+
const lookupTableOptimize: budopts.LookupTableOptimize = b.option(
30+
budopts.LookupTableOptimize,
31+
"lookup-table",
32+
"Lookup table optimization (default: all; small under ReleaseSmall)",
33+
) orelse switch (optimize) {
34+
.ReleaseSmall => .small,
35+
else => .all,
36+
};
37+
38+
const instRewriter = b.option(bool, "install-rewriter", "Install rewriter (default: false)") orelse false;
39+
2840
const stepCheck = b.step("check", "Build but don't install");
2941
const stepTest = b.step("test", "Run library tests");
3042
const stepCompatTest = b.step("test-compat", "Run compatibility tests");
3143

44+
const bopts = b.addOptions();
45+
bopts.addOption(budopts.LookupTableOptimize, "lookupTable", lookupTableOptimize);
46+
3247
const core = b.addModule("zigpak", .{
3348
.root_source_file = b.path("src/root.zig"),
3449
.optimize = optimize,
3550
.target = target,
3651
});
52+
core.addOptions("budopts", bopts);
3753

3854
{ // Docs for the module
3955
const docs = b.addStaticLibrary(.{
@@ -119,6 +135,10 @@ pub fn build(b: *std.Build) void {
119135
runCompatTest.addArtifactArg(rewriter);
120136
stepCompatTest.dependOn(&runCompatTest.step);
121137
}
138+
139+
if (instRewriter) {
140+
b.installArtifact(rewriter);
141+
}
122142
}
123143

124144
{

src/budopts.zig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// The lookup table optimization target.
2+
///
3+
/// Use lookup table to workaround some performance issues,
4+
/// like the mispredict problem, in exchange of program size.
5+
///
6+
/// Please be adviced that lookup tables do not always boost
7+
/// performance.
8+
pub const LookupTableOptimize = enum {
9+
/// Don't use lookup table if possible.
10+
///
11+
/// This option emits smallest object.
12+
none,
13+
/// Use small lookup tables (<= 64 bytes each).
14+
///
15+
/// This may boost performance for certain
16+
/// platforms.
17+
small,
18+
/// Emit all lookup tables.
19+
///
20+
/// This option emits all implemented lookup tables.
21+
/// This may boost performance for certain
22+
/// platforms.
23+
all,
24+
};

0 commit comments

Comments
 (0)