aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-07-16 06:27:56 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2024-07-16 06:28:41 -0400
commit9d1820d20635ade6cb2dbfc36744353715653670 (patch)
treec4efb8a3cf8a31153af696120b2a6a39202336f9
parentb0fe7eef54dcaab8f7f0c18be042bf1876274ca4 (diff)
downloadzig-9d1820d20635ade6cb2dbfc36744353715653670.tar.gz
zig-9d1820d20635ade6cb2dbfc36744353715653670.zip
InternPool: reduce max tid width by one bit
@mlugg keeps stealing my bits!
-rw-r--r--src/InternPool.zig11
-rw-r--r--src/Zcu/PerThread.zig3
-rw-r--r--src/main.zig6
3 files changed, 12 insertions, 8 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index c20009f194..cfd6ecbfb0 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -10,6 +10,8 @@ shards: []Shard = &.{},
global_error_set: GlobalErrorSet = GlobalErrorSet.empty,
/// Cached number of active bits in a `tid`.
tid_width: if (single_threaded) u0 else std.math.Log2Int(u32) = 0,
+/// Cached shift amount to put a `tid` in the top bits of a 30-bit value.
+tid_shift_30: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,
/// Cached shift amount to put a `tid` in the top bits of a 31-bit value.
tid_shift_31: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,
/// Cached shift amount to put a `tid` in the top bits of a 32-bit value.
@@ -4091,8 +4093,8 @@ pub const Index = enum(u32) {
fn wrap(unwrapped: Unwrapped, ip: *const InternPool) Index {
assert(@intFromEnum(unwrapped.tid) <= ip.getTidMask());
- assert(unwrapped.index <= ip.getIndexMask(u31));
- return @enumFromInt(@as(u32, @intFromEnum(unwrapped.tid)) << ip.tid_shift_31 | unwrapped.index);
+ assert(unwrapped.index <= ip.getIndexMask(u30));
+ return @enumFromInt(@as(u32, @intFromEnum(unwrapped.tid)) << ip.tid_shift_30 | unwrapped.index);
}
pub fn getExtra(unwrapped: Unwrapped, ip: *const InternPool) Local.Extra {
@@ -4131,8 +4133,8 @@ pub const Index = enum(u32) {
.tid = .main,
.index = @intFromEnum(index),
} else .{
- .tid = @enumFromInt(@intFromEnum(index) >> ip.tid_shift_31 & ip.getTidMask()),
- .index = @intFromEnum(index) & ip.getIndexMask(u31),
+ .tid = @enumFromInt(@intFromEnum(index) >> ip.tid_shift_30 & ip.getTidMask()),
+ .index = @intFromEnum(index) & ip.getIndexMask(u30),
};
}
@@ -5822,6 +5824,7 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
});
ip.tid_width = @intCast(std.math.log2_int_ceil(usize, used_threads));
+ ip.tid_shift_30 = if (single_threaded) 0 else 30 - ip.tid_width;
ip.tid_shift_31 = if (single_threaded) 0 else 31 - ip.tid_width;
ip.tid_shift_32 = if (single_threaded) 0 else ip.tid_shift_31 +| 1;
ip.shards = try gpa.alloc(Shard, @as(usize, 1) << ip.tid_width);
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig
index c3f569cc7d..ce6b1cb7a9 100644
--- a/src/Zcu/PerThread.zig
+++ b/src/Zcu/PerThread.zig
@@ -3,7 +3,8 @@ zcu: *Zcu,
/// Dense, per-thread unique index.
tid: Id,
-pub const Id = if (InternPool.single_threaded) enum { main } else enum(u8) { main, _ };
+pub const IdBacking = u7;
+pub const Id = if (InternPool.single_threaded) enum { main } else enum(IdBacking) { main, _ };
pub fn destroyDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) void {
const zcu = pt.zcu;
diff --git a/src/main.zig b/src/main.zig
index 2b36c31865..15e3a212a1 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -3110,7 +3110,7 @@ fn buildOutputType(
var thread_pool: ThreadPool = undefined;
try thread_pool.init(.{
.allocator = gpa,
- .n_jobs = @min(@max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1), std.math.maxInt(u8)),
+ .n_jobs = @min(@max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1), std.math.maxInt(Zcu.PerThread.IdBacking)),
.track_ids = true,
});
defer thread_pool.deinit();
@@ -4961,7 +4961,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
var thread_pool: ThreadPool = undefined;
try thread_pool.init(.{
.allocator = gpa,
- .n_jobs = @min(@max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1), std.math.maxInt(u8)),
+ .n_jobs = @min(@max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1), std.math.maxInt(Zcu.PerThread.IdBacking)),
.track_ids = true,
});
defer thread_pool.deinit();
@@ -5399,7 +5399,7 @@ fn jitCmd(
var thread_pool: ThreadPool = undefined;
try thread_pool.init(.{
.allocator = gpa,
- .n_jobs = @min(@max(std.Thread.getCpuCount() catch 1, 1), std.math.maxInt(u8)),
+ .n_jobs = @min(@max(std.Thread.getCpuCount() catch 1, 1), std.math.maxInt(Zcu.PerThread.IdBacking)),
.track_ids = true,
});
defer thread_pool.deinit();