Merge pull request #22242 from Rexicon226/moar-branch-hint

utilize `@branchHint` more
This commit is contained in:
Andrew Kelley 2024-12-16 07:27:20 -05:00 committed by GitHub
commit d12c0bf909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 13 deletions

View File

@ -593,7 +593,7 @@ pub const XxHash3 = struct {
}
fn hash3(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
@branchHint(.cold);
@branchHint(.unlikely);
std.debug.assert(input.len > 0 and input.len < 4);
const flip: [2]u32 = @bitCast(secret[0..8].*);
@ -625,7 +625,7 @@ pub const XxHash3 = struct {
}
fn hash16(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
@branchHint(.cold);
@branchHint(.unlikely);
std.debug.assert(input.len > 8 and input.len <= 16);
const flip: [4]u64 = @bitCast(secret[24..56].*);
@ -641,7 +641,7 @@ pub const XxHash3 = struct {
}
fn hash128(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
@branchHint(.cold);
@branchHint(.unlikely);
std.debug.assert(input.len > 16 and input.len <= 128);
var acc = XxHash64.prime_1 *% @as(u64, input.len);
@ -657,7 +657,7 @@ pub const XxHash3 = struct {
}
fn hash240(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
@branchHint(.cold);
@branchHint(.unlikely);
std.debug.assert(input.len > 128 and input.len <= 240);
var acc = XxHash64.prime_1 *% @as(u64, input.len);
@ -676,7 +676,7 @@ pub const XxHash3 = struct {
}
noinline fn hashLong(seed: u64, input: []const u8) u64 {
@branchHint(.cold);
@branchHint(.unlikely);
std.debug.assert(input.len >= 240);
const block_count = ((input.len - 1) / @sizeOf(Block)) * @sizeOf(Block);

View File

@ -1187,17 +1187,13 @@ pub fn HashMapUnmanaged(
}
/// Find the index containing the data for the given key.
/// Whether this function returns null is almost always
/// branched on after this function returns, and this function
/// returns null/not null from separate code paths. We
/// want the optimizer to remove that branch and instead directly
/// fuse the basic blocks after the branch to the basic blocks
/// from this function. To encourage that, this function is
/// marked as inline.
inline fn getIndex(self: Self, key: anytype, ctx: anytype) ?usize {
fn getIndex(self: Self, key: anytype, ctx: anytype) ?usize {
comptime verifyContext(@TypeOf(ctx), @TypeOf(key), K, Hash, false);
if (self.size == 0) {
// We use cold instead of unlikely to force a jump to this case,
// no matter the weight of the opposing side.
@branchHint(.cold);
return null;
}