Skip to content

Commit 2edb65b

Browse files
committed
fix remaining non-determinism in pdb -> rdi generation!
1 parent 9e6aa85 commit 2edb65b

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

src/lib_rdi_make/rdi_make.c

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13491349
{
13501350
// rjf: write each chunk node's array into original array, detect if there is size left to sort
13511351
RDI_U64 bucket_base_idx = write_idx;
1352-
RDI_U64 max_size_left_to_sort = 0;
1352+
RDI_U64 need_next_char_sort = 0;
13531353
for(RDIM_BakeStringChunkNode *n = buckets[bucket_idx].first; n != 0; n = n->next)
13541354
{
13551355
rdim_memcpy(t->v+write_idx, n->v, sizeof(n->v[0])*n->count);
@@ -1358,14 +1358,14 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13581358
{
13591359
if(n->v[idx].string.size > t->string_off+1)
13601360
{
1361-
max_size_left_to_sort = Max(max_size_left_to_sort, (n->v[idx].string.size - t->string_off+1));
1361+
need_next_char_sort = 1;
13621362
}
13631363
}
13641364
}
13651365

13661366
// rjf: if any bucket has >1 element & has some amount of size left to sort, push new task for this
13671367
// bucket's region in the array, and for remainder of keys
1368-
if(buckets[bucket_idx].total_count > 1 && max_size_left_to_sort > 0)
1368+
if(buckets[bucket_idx].total_count > 1 && need_next_char_sort)
13691369
{
13701370
SortTask *new_task = rdim_push_array(scratch.arena, SortTask, 1);
13711371
RDIM_SLLQueuePush(first_task, last_task, new_task);
@@ -1376,12 +1376,11 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13761376
}
13771377
}
13781378
}
1379-
scratch_end(scratch);
1379+
rdim_scratch_end(scratch);
13801380
}
13811381

1382-
//- rjf: iterate sorted chunk node, remove duplicates, count # to pop
1383-
RDI_U64 num_to_pop = 0;
1384-
RDI_U64 arena_pos_pre_pop = rdim_arena_pos(arena);
1382+
//- rjf: iterate sorted chunk node, remove duplicates, count # of duplicates
1383+
RDI_U64 num_duplicates = 0;
13851384
if(dst.first != 0)
13861385
{
13871386
RDI_U64 last_idx = 0;
@@ -1390,7 +1389,7 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13901389
if(rdim_str8_match(dst.first->v[last_idx].string, dst.first->v[idx].string, 0))
13911390
{
13921391
rdim_memzero_struct(&dst.first->v[idx]);
1393-
num_to_pop += 1;
1392+
num_duplicates += 1;
13941393
}
13951394
else
13961395
{
@@ -1400,32 +1399,33 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
14001399
}
14011400

14021401
//- rjf: iterate sorted chunk node, make non-empty elements contiguous
1403-
if(num_to_pop != 0)
1402+
if(num_duplicates != 0)
14041403
{
14051404
RDI_U64 last_idx = 0;
14061405
for(RDI_U64 idx = 1; idx < dst.first->count; idx += 1)
14071406
{
1408-
if(dst.first->v[idx].string.RDIM_String8_SizeMember == 0 &&
1407+
if(last_idx == 0 &&
1408+
dst.first->v[idx].string.RDIM_String8_SizeMember == 0 &&
14091409
dst.first->v[idx].hash == 0)
14101410
{
14111411
last_idx = idx;
14121412
}
1413-
else if(last_idx != 0 && last_idx != idx)
1413+
if(last_idx != 0 && dst.first->v[idx].string.RDIM_String8_SizeMember != 0)
14141414
{
14151415
rdim_memcpy_struct(&dst.first->v[last_idx], &dst.first->v[idx]);
14161416
rdim_memzero_struct(&dst.first->v[idx]);
1417-
idx = last_idx;
1418-
last_idx = 0;
1417+
last_idx += 1;
14191418
}
14201419
}
14211420

14221421
//- rjf: pop extras
1423-
if(num_to_pop != 0)
1422+
if(num_duplicates != 0)
14241423
{
1425-
rdim_arena_pop_to(arena, arena_pos_pre_pop - num_to_pop*sizeof(dst.first->v[0]));
1426-
dst.first->count -= num_to_pop;
1427-
dst.first->cap -= num_to_pop;
1428-
dst.total_count -= num_to_pop;
1424+
RDI_U64 arena_pos_pre_pop = rdim_arena_pos(arena);
1425+
rdim_arena_pop_to(arena, arena_pos_pre_pop - num_duplicates*sizeof(dst.first->v[0]));
1426+
dst.first->count -= num_duplicates;
1427+
dst.first->cap -= num_duplicates;
1428+
dst.total_count -= num_duplicates;
14291429
}
14301430
}
14311431

@@ -1446,31 +1446,34 @@ rdim_bake_string_map_loose_make(RDIM_Arena *arena, RDIM_BakeStringMapTopology *t
14461446
RDI_PROC void
14471447
rdim_bake_string_map_loose_insert(RDIM_Arena *arena, RDIM_BakeStringMapTopology *map_topology, RDIM_BakeStringMapLoose *map, RDI_U64 chunk_cap, RDIM_String8 string)
14481448
{
1449-
RDI_U64 hash = rdi_hash(string.RDIM_String8_BaseMember, string.RDIM_String8_SizeMember);
1450-
RDI_U64 slot_idx = hash%map_topology->slots_count;
1451-
RDIM_BakeStringChunkList *slot = map->slots[slot_idx];
1452-
if(slot == 0)
1453-
{
1454-
slot = map->slots[slot_idx] = rdim_push_array(arena, RDIM_BakeStringChunkList, 1);
1455-
}
1456-
RDI_S32 is_duplicate = 0;
1457-
for(RDIM_BakeStringChunkNode *n = slot->first; n != 0; n = n->next)
1449+
if(string.RDIM_String8_SizeMember != 0)
14581450
{
1459-
for(RDI_U64 idx = 0; idx < n->count; idx += 1)
1451+
RDI_U64 hash = rdi_hash(string.RDIM_String8_BaseMember, string.RDIM_String8_SizeMember);
1452+
RDI_U64 slot_idx = hash%map_topology->slots_count;
1453+
RDIM_BakeStringChunkList *slot = map->slots[slot_idx];
1454+
if(slot == 0)
1455+
{
1456+
slot = map->slots[slot_idx] = rdim_push_array(arena, RDIM_BakeStringChunkList, 1);
1457+
}
1458+
RDI_S32 is_duplicate = 0;
1459+
for(RDIM_BakeStringChunkNode *n = slot->first; n != 0; n = n->next)
14601460
{
1461-
if(rdim_str8_match(n->v[idx].string, string, 0))
1461+
for(RDI_U64 idx = 0; idx < n->count; idx += 1)
14621462
{
1463-
is_duplicate = 1;
1464-
goto break_all;
1463+
if(rdim_str8_match(n->v[idx].string, string, 0))
1464+
{
1465+
is_duplicate = 1;
1466+
goto break_all;
1467+
}
14651468
}
14661469
}
1467-
}
1468-
break_all:;
1469-
if(!is_duplicate)
1470-
{
1471-
RDIM_BakeString *bstr = rdim_bake_string_chunk_list_push(arena, slot, chunk_cap);
1472-
bstr->string = string;
1473-
bstr->hash = hash;
1470+
break_all:;
1471+
if(!is_duplicate)
1472+
{
1473+
RDIM_BakeString *bstr = rdim_bake_string_chunk_list_push(arena, slot, chunk_cap);
1474+
bstr->string = string;
1475+
bstr->hash = hash;
1476+
}
14741477
}
14751478
}
14761479

src/rdi_from_pdb/rdi_from_pdb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,7 +4639,7 @@ p2r_bake(Arena *arena, P2R_Convert2Bake *in)
46394639
{
46404640
for EachIndex(idx, n->count)
46414641
{
4642-
printf("string: \"%.*s\"\n", str8_varg(n->v[idx].string));
4642+
printf("slot[%I64u]: string: %.*s (hash 0x%I64x)\n", slot_idx, str8_varg(n->v[idx].string), n->v[idx].hash);
46434643
}
46444644
}
46454645
}
@@ -4703,7 +4703,7 @@ p2r_bake(Arena *arena, P2R_Convert2Bake *in)
47034703
{
47044704
for EachIndex(idx, n->count)
47054705
{
4706-
printf("string: %.*s\n", str8_varg(n->v[idx].string));
4706+
printf("slot[%I64u]: string: %.*s (hash 0x%I64x)\n", slot_idx, str8_varg(n->v[idx].string), n->v[idx].hash);
47074707
string_idx += 1;
47084708
}
47094709
}
@@ -4770,7 +4770,7 @@ p2r_bake(Arena *arena, P2R_Convert2Bake *in)
47704770
{
47714771
for EachIndex(idx, n->count)
47724772
{
4773-
printf("string: %.*s\n", str8_varg(n->v[idx].string));
4773+
printf("slot[%I64u]: string: %.*s (hash 0x%I64x)\n", slot_idx, str8_varg(n->v[idx].string), n->v[idx].hash);
47744774
string_idx += 1;
47754775
}
47764776
}

src/tester/tester_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ entry_point(CmdLine *cmdline)
4545
String8List out = {0};
4646
{
4747
name = str8_lit("pdb2rdi_determinism");
48-
U64 num_repeats_per_pdb = 16;
48+
U64 num_repeats_per_pdb = 32;
4949
String8 pdb_paths[] =
5050
{
5151
// str8_lit_comp("odintest/test.pdb"),

0 commit comments

Comments
 (0)