const PackedPtr = enum(@Int(.unsigned, @bitSizeOf(usize) - 2)) 340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355 const PackedPtr = enum(@Int(.unsigned, @bitSizeOf(usize) - 2)) {
null = 0,
all_ones = std.math.maxInt(@Int(.unsigned, @bitSizeOf(usize) - 2)),
_,
const Split = packed struct(usize) { low: u2, high: PackedPtr };
fn pack(ptr: ?*Fiber) PackedPtr {
const split: Split = @bitCast(@intFromPtr(ptr));
assert(split.low == 0);
return split.high;
}
fn unpack(ptr: PackedPtr) ?*Fiber {
const split: Split = .{ .low = 0, .high = ptr };
return @ptrFromInt(@as(usize, @bitCast(split)));
}
}
Like a
*Fiber, but 2 bits smaller than a pointer (because the LSBs are always 0 due to alignment) so that those two bits can be used in apacked struct.