inline byte hashing around type indices

This commit is contained in:
Nikita Smith
2026-02-16 13:39:49 -08:00
parent 3e5c8ab9f6
commit 442f41b51a
2 changed files with 27 additions and 25 deletions
+26 -24
View File
@@ -1144,8 +1144,7 @@ skip_type_index_compare:;
#endif #endif
internal U64 internal U64
lnk_hash_cv_leaf(Arena *arena, lnk_hash_cv_leaf(LNK_CodeViewInput *input,
LNK_CodeViewInput *input,
LNK_LeafHashes *hashes, LNK_LeafHashes *hashes,
LNK_LeafLocType loc_type, LNK_LeafLocType loc_type,
U32 loc_idx, U32 loc_idx,
@@ -1157,24 +1156,32 @@ lnk_hash_cv_leaf(Arena *arena,
// init hasher // init hasher
blake3_hasher hasher; blake3_hasher_init(&hasher); blake3_hasher hasher; blake3_hasher_init(&hasher);
// hash leaf size // hash leaf header
blake3_hasher_update(&hasher, &leaf.data.size, sizeof leaf.data.size); {
CV_LeafHeader header;
// hash leaf kind header.size = (U16)leaf.data.size;
blake3_hasher_update(&hasher, &leaf.kind, sizeof leaf.kind); header.kind = leaf.kind;
blake3_hasher_update(&hasher, &header, sizeof(header));
}
// hash bytes around indices // hash bytes around indices
{ {
Temp temp = temp_begin(arena); U64 last_ti_off = 0;
String8Array raw_data_arr = cv_get_data_around_type_indices(temp.arena, ti_info_list, leaf.data); for EachNode(ti_info, CV_TypeIndexInfo, ti_info_list.first) {
for (U64 i = 0; i < raw_data_arr.count; ++i) { U8 *bytes = leaf.data.str + last_ti_off;
blake3_hasher_update(&hasher, raw_data_arr.v[i].str, raw_data_arr.v[i].size); U64 size = ti_info->offset - last_ti_off;
blake3_hasher_update(&hasher, bytes, size);
last_ti_off = ti_info->offset + sizeof(CV_TypeIndex);
} }
temp_end(temp);
Assert(leaf.data.size >= last_ti_off);
U8 *bytes = leaf.data.str + last_ti_off;
U64 size = leaf.data.size - last_ti_off;
blake3_hasher_update(&hasher, bytes, size);
} }
// mix-in sub leaf hashes // mix-in sub leaf hashes
for (CV_TypeIndexInfo *ti_n = ti_info_list.first; ti_n != 0; ti_n = ti_n->next) { for EachNode(ti_n, CV_TypeIndexInfo, ti_info_list.first) {
CV_TypeIndex sub_ti = memory_read32(leaf.data.str + ti_n->offset); CV_TypeIndex sub_ti = memory_read32(leaf.data.str + ti_n->offset);
// is type index complex? // is type index complex?
@@ -1209,7 +1216,7 @@ lnk_hash_cv_leaf(Arena *arena,
Assert(sub_hash != 0); Assert(sub_hash != 0);
// mix-in sub hash // mix-in sub hash
blake3_hasher_update(&hasher, &sub_hash, sizeof sub_hash); blake3_hasher_update(&hasher, &sub_hash, sizeof(sub_hash));
} else { } else {
Temp scratch = scratch_begin(0,0); Temp scratch = scratch_begin(0,0);
String8 leaf_kind_str = cv_string_from_leaf_kind(leaf.kind); String8 leaf_kind_str = cv_string_from_leaf_kind(leaf.kind);
@@ -1226,12 +1233,12 @@ lnk_hash_cv_leaf(Arena *arena,
} }
// simple indices are stable across compile units // simple indices are stable across compile units
else { else {
blake3_hasher_update(&hasher, &sub_ti, sizeof sub_ti); blake3_hasher_update(&hasher, &sub_ti, sizeof(sub_ti));
} }
} }
U64 hash; U64 hash;
blake3_hasher_finalize(&hasher, (U8 *) &hash, sizeof hash); blake3_hasher_finalize(&hasher, (U8 *) &hash, sizeof(hash));
return hash; return hash;
} }
@@ -1312,8 +1319,7 @@ lnk_hash_cv_leaf_deep(Arena *arena,
SLLStackPush(stack, frame); SLLStackPush(stack, frame);
break; break;
} else { } else {
curr_hashes[curr_ti_info->source][ti_idx] = lnk_hash_cv_leaf(temp.arena, curr_hashes[curr_ti_info->source][ti_idx] = lnk_hash_cv_leaf(input,
input,
hashes, hashes,
loc_type, loc_type,
loc_idx, loc_idx,
@@ -1331,10 +1337,8 @@ lnk_hash_cv_leaf_deep(Arena *arena,
if (stack != root_frame) { if (stack != root_frame) {
// sub leaves are hashed we can now hash parent leaf // sub leaves are hashed we can now hash parent leaf
Temp temp2 = temp_begin(temp.arena);
U64 leaf_idx = stack->ti - ti_ranges[stack->ti_source].min; U64 leaf_idx = stack->ti - ti_ranges[stack->ti_source].min;
curr_hashes[stack->ti_source][leaf_idx] = lnk_hash_cv_leaf(temp2.arena, curr_hashes[stack->ti_source][leaf_idx] = lnk_hash_cv_leaf(input,
input,
hashes, hashes,
loc_type, loc_type,
loc_idx, loc_idx,
@@ -1342,7 +1346,6 @@ lnk_hash_cv_leaf_deep(Arena *arena,
CV_TypeIndex_Max, CV_TypeIndex_Max,
stack->leaf, stack->leaf,
stack->ti_info_list); stack->ti_info_list);
temp_end(temp2);
} }
SLLStackPop(stack); SLLStackPop(stack);
@@ -1487,8 +1490,7 @@ THREAD_POOL_TASK_FUNC(lnk_hash_debug_t_task)
CV_Leaf leaf = cv_debug_t_get_leaf(debug_t, leaf_idx); CV_Leaf leaf = cv_debug_t_get_leaf(debug_t, leaf_idx);
CV_TypeIndexInfoList ti_info_list = cv_get_leaf_type_index_offsets(temp.arena, leaf.kind, leaf.data); CV_TypeIndexInfoList ti_info_list = cv_get_leaf_type_index_offsets(temp.arena, leaf.kind, leaf.data);
out_hashes[leaf_idx] = lnk_hash_cv_leaf(temp.arena, out_hashes[leaf_idx] = lnk_hash_cv_leaf(task->input,
task->input,
task->hashes, task->hashes,
LNK_LeafLocType_Internal, LNK_LeafLocType_Internal,
obj_idx, obj_idx,
+1 -1
View File
@@ -468,7 +468,7 @@ internal LNK_LeafRef lnk_leaf_ref_from_loc_idx_and_ti(LNK_CodeViewInput *in
internal B32 lnk_match_leaf_ref (LNK_CodeViewInput *input, LNK_LeafHashes *hashes, LNK_LeafRef a, LNK_LeafRef b); internal B32 lnk_match_leaf_ref (LNK_CodeViewInput *input, LNK_LeafHashes *hashes, LNK_LeafRef a, LNK_LeafRef b);
// leaf hashing // leaf hashing
internal U64 lnk_hash_cv_leaf (Arena *arena, LNK_CodeViewInput *input, LNK_LeafHashes *hashes, LNK_LeafLocType loc_type, U32 loc_idx, Rng1U64 *ti_ranges, CV_TypeIndex curr_ti, CV_Leaf leaf, CV_TypeIndexInfoList ti_info_list); internal U64 lnk_hash_cv_leaf (LNK_CodeViewInput *input, LNK_LeafHashes *hashes, LNK_LeafLocType loc_type, U32 loc_idx, Rng1U64 *ti_ranges, CV_TypeIndex curr_ti, CV_Leaf leaf, CV_TypeIndexInfoList ti_info_list);
internal void lnk_hash_cv_leaf_deep(Arena *arena, LNK_CodeViewInput *input, Rng1U64 *ti_ranges, CV_DebugT *leaves, LNK_LeafHashes *hashes, LNK_LeafLocType loc_type, U32 loc_idx, CV_TypeIndexInfoList ti_info_list, String8 data); internal void lnk_hash_cv_leaf_deep(Arena *arena, LNK_CodeViewInput *input, Rng1U64 *ti_ranges, CV_DebugT *leaves, LNK_LeafHashes *hashes, LNK_LeafLocType loc_type, U32 loc_idx, CV_TypeIndexInfoList ti_info_list, String8 data);
internal U64 lnk_hash_from_leaf_ref(LNK_LeafHashes *hashes, LNK_LeafRef leaf_ref); internal U64 lnk_hash_from_leaf_ref(LNK_LeafHashes *hashes, LNK_LeafRef leaf_ref);