From 55b05301a4d589789b546104fd8b3c825d82c406 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Wed, 3 Sep 2025 06:07:36 -0700 Subject: [PATCH] expand scope vmap sorting -> all vmaps; do final vmap bakes; do first pass of scope (1 scope -> many locals, many voffs) layout / baking --- src/base/base_math.c | 17 + src/base/base_math.h | 5 + src/base/base_thread_context.c | 14 - src/base/base_thread_context.h | 3 +- src/mule/mule_main.cpp | 11 + src/raddbg/raddbg_main.c | 2 + src/rdi_make/rdi_make_local_2.c | 531 +++++++++++++++++++++++++++++--- src/rdi_make/rdi_make_local_2.h | 22 +- 8 files changed, 543 insertions(+), 62 deletions(-) diff --git a/src/base/base_math.c b/src/base/base_math.c index b21a0a9e..b884937e 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -809,3 +809,20 @@ rng1s64_array_from_list(Arena *arena, Rng1S64List *list) } return arr; } + +//////////////////////////////// +//~ rjf: N -> M Element Subdivision + +internal Rng1U64 +m_range_from_n_idx_m_count(U64 n_idx, U64 n_count, U64 m_count) +{ + U64 main_idxes_per_lane = m_count/n_count; + U64 leftover_idxes_count = m_count - main_idxes_per_lane*n_count; + U64 leftover_idxes_before_this_lane_count = Min(n_idx, leftover_idxes_count); + U64 lane_base_idx = n_idx*main_idxes_per_lane + leftover_idxes_before_this_lane_count; + U64 lane_base_idx__clamped = Min(lane_base_idx, m_count); + U64 lane_opl_idx = lane_base_idx__clamped + main_idxes_per_lane + ((n_idx < leftover_idxes_count) ? 1 : 0); + U64 lane_opl_idx__clamped = Min(lane_opl_idx, m_count); + Rng1U64 result = r1u64(lane_base_idx__clamped, lane_opl_idx__clamped); + return result; +} diff --git a/src/base/base_math.h b/src/base/base_math.h index e9022690..7ea6e2ec 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -691,4 +691,9 @@ internal U64 rng_1u64_array_bsearch(Rng1U64Array arr, U64 value); internal void rng1s64_list_push(Arena *arena, Rng1S64List *list, Rng1S64 rng); internal Rng1S64Array rng1s64_array_from_list(Arena *arena, Rng1S64List *list); +//////////////////////////////// +//~ rjf: N -> M Element Subdivision + +internal Rng1U64 m_range_from_n_idx_m_count(U64 n_idx, U64 n_count, U64 m_count); + #endif //BASE_MATH_H diff --git a/src/base/base_thread_context.c b/src/base/base_thread_context.c index 7fade9d3..c13123fa 100644 --- a/src/base/base_thread_context.c +++ b/src/base/base_thread_context.c @@ -94,20 +94,6 @@ tctx_lane_barrier_wait(void) ProfEnd(); } -internal Rng1U64 -tctx_lane_idx_range_from_count(U64 count) -{ - U64 main_idxes_per_lane = count/lane_count(); - U64 leftover_idxes_count = count - main_idxes_per_lane*lane_count(); - U64 leftover_idxes_before_this_lane_count = Min(lane_idx(), leftover_idxes_count); - U64 lane_base_idx = lane_idx()*main_idxes_per_lane + leftover_idxes_before_this_lane_count; - U64 lane_base_idx__clamped = Min(lane_base_idx, count); - U64 lane_opl_idx = lane_base_idx__clamped + main_idxes_per_lane + ((lane_idx() < leftover_idxes_count) ? 1 : 0); - U64 lane_opl_idx__clamped = Min(lane_opl_idx, count); - Rng1U64 result = r1u64(lane_base_idx__clamped, lane_opl_idx__clamped); - return result; -} - //- rjf: thread names internal void diff --git a/src/base/base_thread_context.h b/src/base/base_thread_context.h index 2394b98b..0f6952aa 100644 --- a/src/base/base_thread_context.h +++ b/src/base/base_thread_context.h @@ -53,13 +53,12 @@ internal Arena *tctx_get_scratch(Arena **conflicts, U64 count); //- rjf: lane metadata internal LaneCtx tctx_set_lane_ctx(LaneCtx lane_ctx); internal void tctx_lane_barrier_wait(void); -internal Rng1U64 tctx_lane_idx_range_from_count(U64 count); #define lane_idx() (tctx_selected()->lane_ctx.lane_idx) #define lane_count() (tctx_selected()->lane_ctx.lane_count) #define lane_from_task_idx(idx) ((idx)%lane_count()) #define lane_ctx(ctx) tctx_set_lane_ctx((ctx)) #define lane_sync() tctx_lane_barrier_wait() -#define lane_range(count) tctx_lane_idx_range_from_count(count) +#define lane_range(count) m_range_from_n_idx_m_count(lane_idx(), lane_count(), (count)) //- rjf: thread names internal void tctx_set_thread_name(String8 name); diff --git a/src/mule/mule_main.cpp b/src/mule/mule_main.cpp index 203b6036..00a60072 100644 --- a/src/mule/mule_main.cpp +++ b/src/mule/mule_main.cpp @@ -345,6 +345,15 @@ enum{ Anonymous_D, }; +typedef uint32_t SizedKind; +enum SizedKindEnum +{ + SizedKind_A, + SizedKind_B, + SizedKind_C, + SizedKind_D, +}; + typedef Kind Alias1; typedef Flag Alias2; typedef Has_Enums Alias3; @@ -635,6 +644,8 @@ type_coverage_eval_tests(void) dynamic_array_vector.push_back(dynamic); dynamic_array_vector.push_back(dynamic); + SizedKind sized_kind = SizedKind_C; + int x = (int)(Anonymous_D); } diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index 374427dc..25e8221b 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -10,6 +10,8 @@ // [ ] hardware breakpoints regression (global eval in ctrl) // [ ] native filesystem dialog, resizing raddbg window -> crash! // [ ] stdout/stderr path target setting is now busted >:( +// [ ] target ui entry point should override built-in entry point +// [ ] list of all tabs in palette // //- memory view // [ ] have smaller visible range than entire memory diff --git a/src/rdi_make/rdi_make_local_2.c b/src/rdi_make/rdi_make_local_2.c index dd448635..79bae023 100644 --- a/src/rdi_make/rdi_make_local_2.c +++ b/src/rdi_make/rdi_make_local_2.c @@ -13,34 +13,13 @@ rdim2_bake(Arena *arena, RDIM_BakeParams *params) } lane_sync(); -#if 0 - { - ProfScope("bake all vmaps") - { - if(lane_idx() == lane_from_task_idx(0)) ProfScope("bake unit vmap") - { - rdim2_shared->baked_unit_vmap = rdim_bake_unit_vmap(arena, ¶ms->units); - } - if(lane_idx() == lane_from_task_idx(1)) ProfScope("bake scope vmap") - { - // rdim2_shared->baked_scope_vmap = rdim_bake_scope_vmap(arena, ¶ms->scopes); - } - if(lane_idx() == lane_from_task_idx(2)) ProfScope("bake global vmap") - { - rdim2_shared->baked_global_vmap = rdim_bake_global_vmap(arena, ¶ms->global_variables); - } - } - lane_sync(); - } -#endif - ////////////////////////////////////////////////////////////// - //- rjf: bake scope vmap + //- rjf: gather unsorted vmap keys/markers // - ProfScope("bake scope vmap") + ProfScope("gather unsorted vmap keys/markers") { - // rjf: set up - if(lane_idx() == 0) + //- rjf: gather scope vmap keys/markers + if(lane_idx() == lane_from_task_idx(0)) ProfScope("gather scope vmap keys/markers") { rdim2_shared->scope_vmap_count = params->scopes.scope_voff_count; rdim2_shared->scope_vmap_keys = push_array_no_zero(arena, RDIM_SortKey, rdim2_shared->scope_vmap_count); @@ -75,22 +54,183 @@ rdim2_bake(Arena *arena, RDIM_BakeParams *params) } } } + } + + //- rjf: gather unit vmap keys/markers + if(lane_idx() == lane_from_task_idx(1)) ProfScope("gather unit vmap keys/markers") + { + // rjf: count voff ranges + RDI_U64 voff_range_count = 0; + for(RDIM_UnitChunkNode *n = params->units.first; n != 0; n = n->next) + { + for(RDI_U64 idx = 0; idx < n->count; idx += 1) + { + RDIM_Unit *unit = &n->v[idx]; + voff_range_count += unit->voff_ranges.total_count; + } + } + + // rjf: count necessary markers + RDI_U64 marker_count = voff_range_count*2; + + // rjf: build keys/markers arrays + RDIM_SortKey *keys = rdim_push_array_no_zero(arena, RDIM_SortKey, marker_count); + RDIM_VMapMarker *markers = rdim_push_array_no_zero(arena, RDIM_VMapMarker, marker_count); + { + RDIM_SortKey *key_ptr = keys; + RDIM_VMapMarker *marker_ptr = markers; + RDI_U32 unit_idx = 1; + for(RDIM_UnitChunkNode *unit_chunk_n = params->units.first; + unit_chunk_n != 0; + unit_chunk_n = unit_chunk_n->next) + { + for(RDI_U64 idx = 0; idx < unit_chunk_n->count; idx += 1) + { + RDIM_Unit *unit = &unit_chunk_n->v[idx]; + for(RDIM_Rng1U64ChunkNode *n = unit->voff_ranges.first; n != 0; n = n->next) + { + for(RDI_U64 chunk_idx = 0; chunk_idx < n->count; chunk_idx += 1) + { + RDIM_Rng1U64 range = n->v[chunk_idx]; + if(range.min < range.max) + { + key_ptr->key = range.min; + key_ptr->val = marker_ptr; + marker_ptr->idx = unit_idx; + marker_ptr->begin_range = 1; + key_ptr += 1; + marker_ptr += 1; + + key_ptr->key = range.max; + key_ptr->val = marker_ptr; + marker_ptr->idx = unit_idx; + marker_ptr->begin_range = 0; + key_ptr += 1; + marker_ptr += 1; + } + } + } + unit_idx += 1; + } + } + } + + // rjf: store + rdim2_shared->unit_vmap_count = marker_count; + rdim2_shared->unit_vmap_keys = keys; + rdim2_shared->unit_vmap_keys__swap = push_array_no_zero(arena, RDIM_SortKey, marker_count); + rdim2_shared->unit_vmap_markers = markers; + } + + //- rjf: gather global vmap keys/markers + if(lane_idx() == lane_from_task_idx(2)) ProfScope("gather global vmap keys/markers") + { + //- rjf: allocate keys/markers + RDI_U64 marker_count = params->global_variables.total_count*2 + 2; + RDIM_SortKey *keys = rdim_push_array_no_zero(arena, RDIM_SortKey, marker_count); + RDIM_VMapMarker *markers = rdim_push_array_no_zero(arena, RDIM_VMapMarker, marker_count); + + //- rjf: fill + { + RDIM_SortKey *key_ptr = keys; + RDIM_VMapMarker *marker_ptr = markers; + + // rjf: fill actual globals + for(RDIM_SymbolChunkNode *n = params->global_variables.first; n != 0; n = n->next) + { + for(RDI_U64 chunk_idx = 0; chunk_idx < n->count; chunk_idx += 1) + { + RDIM_Symbol *global_var = &n->v[chunk_idx]; + RDI_U32 global_var_idx = (RDI_U32)rdim_idx_from_symbol(global_var); // TODO(rjf): @u64_to_u32 + RDI_U64 global_var_size = global_var->type ? global_var->type->byte_size : 1; + + RDI_U64 first = global_var->offset; + RDI_U64 opl = first + global_var_size; + + key_ptr->key = first; + key_ptr->val = marker_ptr; + marker_ptr->idx = global_var_idx; + marker_ptr->begin_range = 1; + key_ptr += 1; + marker_ptr += 1; + + key_ptr->key = opl; + key_ptr->val = marker_ptr; + marker_ptr->idx = global_var_idx; + marker_ptr->begin_range = 0; + key_ptr += 1; + marker_ptr += 1; + } + } + + // rjf: fill nil global + { + RDI_U32 global_idx = 0; + RDI_U64 first = 0; + RDI_U64 opl = 0xffffffffffffffffull; + key_ptr->key = first; + key_ptr->val = marker_ptr; + marker_ptr->idx = global_idx; + marker_ptr->begin_range = 1; + key_ptr += 1; + marker_ptr += 1; + key_ptr->key = opl; + key_ptr->val = marker_ptr; + marker_ptr->idx = global_idx; + marker_ptr->begin_range = 0; + key_ptr += 1; + marker_ptr += 1; + } + } + + //- rjf: store + rdim2_shared->global_vmap_count = marker_count; + rdim2_shared->global_vmap_keys = keys; + rdim2_shared->global_vmap_keys__swap = push_array_no_zero(arena, RDIM_SortKey, marker_count); + rdim2_shared->global_vmap_markers = markers; + } + } + lane_sync(); + + ////////////////////////////////////////////////////////////// + //- rjf: sort all vmap keys + // + ProfScope("sort all vmap keys") + { + // rjf: set up + if(lane_idx() == 0) + { rdim2_shared->lane_digit_counts = push_array(arena, U32 *, lane_count()); rdim2_shared->lane_digit_offsets = push_array(arena, U32 *, lane_count()); } lane_sync(); // rjf: sort - ProfScope("sort") + struct { + RDI_U64 vmap_count; + RDIM_SortKey *keys; + RDIM_SortKey *keys__swap; + } + sort_tasks[] = + { + {rdim2_shared->scope_vmap_count, rdim2_shared->scope_vmap_keys, rdim2_shared->scope_vmap_keys__swap}, + {rdim2_shared->unit_vmap_count, rdim2_shared->unit_vmap_keys, rdim2_shared->unit_vmap_keys__swap}, + {rdim2_shared->global_vmap_count, rdim2_shared->global_vmap_keys, rdim2_shared->global_vmap_keys__swap}, + }; + for EachElement(sort_task_idx, sort_tasks) ProfScope("sort %I64u", sort_task_idx) + { + RDI_U64 vmap_count = sort_tasks[sort_task_idx].vmap_count; + RDIM_SortKey *keys = sort_tasks[sort_task_idx].keys; + RDIM_SortKey *keys__swap = sort_tasks[sort_task_idx].keys__swap; U64 bits_per_digit = 8; U64 digits_count = 64 / bits_per_digit; U64 num_possible_values_per_digit = 1 << bits_per_digit; rdim2_shared->lane_digit_counts[lane_idx()] = push_array_no_zero(arena, U32, num_possible_values_per_digit); rdim2_shared->lane_digit_offsets[lane_idx()] = push_array_no_zero(arena, U32, num_possible_values_per_digit); - RDIM_SortKey *src = rdim2_shared->scope_vmap_keys; - RDIM_SortKey *dst = rdim2_shared->scope_vmap_keys__swap; - U64 element_count = rdim2_shared->scope_vmap_count; + RDIM_SortKey *src = keys; + RDIM_SortKey *dst = keys__swap; + U64 element_count = vmap_count; for EachIndex(digit_idx, digits_count) { // rjf: count digit value occurrences per-lane @@ -162,21 +302,193 @@ rdim2_bake(Arena *arena, RDIM_BakeParams *params) } } } - lane_sync(); - - // rjf: assert sortedness - { - RDIM_SortKey *dst = rdim2_shared->scope_vmap_keys; - U64 element_count = rdim2_shared->scope_vmap_count; - for EachIndex(idx, element_count) - { - if(idx > 0) - { - AssertAlways(dst[idx-1].key <= dst[idx].key); - } - } - } } + lane_sync(); + + ////////////////////////////////////////////////////////////// + //- rjf: bake all vmaps + // + ProfScope("bake all vmaps") + { + Temp scratch = scratch_begin(&arena, 1); + typedef struct VMapBakeTask VMapBakeTask; + struct VMapBakeTask + { + VMapBakeTask *next; + String8 name; + RDI_U64 count; + RDIM_SortKey *keys; + RDIM_VMapMarker *markers; + RDIM_BakeVMap *bake_vmap_out; + }; + VMapBakeTask *first_task = 0; + VMapBakeTask *last_task = 0; + if(lane_idx() == lane_from_task_idx(0)) + { + VMapBakeTask *task = push_array(scratch.arena, VMapBakeTask, 1); + task->name = str8_lit("scopes"); + task->count = rdim2_shared->scope_vmap_count; + task->keys = rdim2_shared->scope_vmap_keys; + task->markers = rdim2_shared->scope_vmap_markers; + task->bake_vmap_out = &rdim2_shared->baked_scope_vmap.vmap; + SLLQueuePush(first_task, last_task, task); + } + if(lane_idx() == lane_from_task_idx(1)) + { + VMapBakeTask *task = push_array(scratch.arena, VMapBakeTask, 1); + task->name = str8_lit("units"); + task->count = rdim2_shared->unit_vmap_count; + task->keys = rdim2_shared->unit_vmap_keys; + task->markers = rdim2_shared->unit_vmap_markers; + task->bake_vmap_out = &rdim2_shared->baked_unit_vmap.vmap; + SLLQueuePush(first_task, last_task, task); + } + if(lane_idx() == lane_from_task_idx(2)) + { + VMapBakeTask *task = push_array(scratch.arena, VMapBakeTask, 1); + task->name = str8_lit("globals"); + task->count = rdim2_shared->global_vmap_count; + task->keys = rdim2_shared->global_vmap_keys; + task->markers = rdim2_shared->global_vmap_markers; + task->bake_vmap_out = &rdim2_shared->baked_global_vmap.vmap; + SLLQueuePush(first_task, last_task, task); + } + for(VMapBakeTask *task = first_task; task != 0; task = task->next) ProfScope("vmap bake for %.*s", str8_varg(task->name)) + { + //- rjf: determine if an extra vmap entry for zero is needed + RDI_U32 extra_vmap_entry = 0; + if(task->count > 0 && task->keys[0].key != 0) + { + extra_vmap_entry = 1; + } + + //- rjf: fill output vmap entries + RDI_U32 vmap_count_raw = extra_vmap_entry + task->count; + RDI_VMapEntry *vmap = rdim_push_array(arena, RDI_VMapEntry, vmap_count_raw); + RDI_U32 vmap_entry_count_pass_1 = 0; + ProfScope("fill output vmap entries") + { + typedef struct RDIM_VMapRangeTracker RDIM_VMapRangeTracker; + struct RDIM_VMapRangeTracker + { + RDIM_VMapRangeTracker *next; + RDI_U32 idx; + }; + RDI_VMapEntry *vmap_ptr = vmap; + if(extra_vmap_entry) + { + vmap_ptr->voff = 0; + vmap_ptr->idx = 0; + vmap_ptr += 1; + } + RDIM_VMapRangeTracker *tracker_stack = 0; + RDIM_VMapRangeTracker *tracker_free = 0; + RDIM_SortKey *key_ptr = task->keys; + RDIM_SortKey *key_opl = task->keys + task->count; + for(;key_ptr < key_opl;) + { + // rjf: get initial map state from tracker stack + RDI_U32 initial_idx = (RDI_U32)0xffffffff; + if(tracker_stack != 0) + { + initial_idx = tracker_stack->idx; + } + + // rjf: update tracker stack + // + // * we must process _all_ of the changes that apply at this voff before moving on + // + RDI_U64 voff = key_ptr->key; + + for(;key_ptr < key_opl && key_ptr->key == voff; key_ptr += 1) + { + RDIM_VMapMarker *marker = (RDIM_VMapMarker*)key_ptr->val; + RDI_U32 idx = marker->idx; + + // rjf: range begin -> push to stack + if(marker->begin_range) + { + RDIM_VMapRangeTracker *new_tracker = tracker_free; + if(new_tracker != 0) + { + RDIM_SLLStackPop(tracker_free); + } + else + { + new_tracker = rdim_push_array(scratch.arena, RDIM_VMapRangeTracker, 1); + } + RDIM_SLLStackPush(tracker_stack, new_tracker); + new_tracker->idx = idx; + } + + // rjf: range ending -> pop matching node from stack (not always the top) + else + { + RDIM_VMapRangeTracker **ptr_in = &tracker_stack; + RDIM_VMapRangeTracker *match = 0; + for(RDIM_VMapRangeTracker *node = tracker_stack; node != 0;) + { + if(node->idx == idx) + { + match = node; + break; + } + ptr_in = &node->next; + node = node->next; + } + if(match != 0) + { + *ptr_in = match->next; + RDIM_SLLStackPush(tracker_free, match); + } + } + } + + // rjf: get final map state from tracker stack + RDI_U32 final_idx = 0; + if(tracker_stack != 0) + { + final_idx = tracker_stack->idx; + } + + // rjf: if final is different from initial - emit new vmap entry + if(final_idx != initial_idx) + { + vmap_ptr->voff = voff; + vmap_ptr->idx = final_idx; + vmap_ptr += 1; + } + } + + vmap_entry_count_pass_1 = (RDI_U32)(vmap_ptr - vmap); // TODO(rjf): @u64_to_u32 + } + + //- rjf: combine duplicate neighbors + RDI_U32 vmap_entry_count = 0; + ProfScope("combine duplicate neighbors") + { + RDI_VMapEntry *vmap_ptr = vmap; + RDI_VMapEntry *vmap_opl = vmap + vmap_entry_count_pass_1; + RDI_VMapEntry *vmap_out = vmap; + for(;vmap_ptr < vmap_opl;) + { + RDI_VMapEntry *vmap_range_first = vmap_ptr; + RDI_U64 idx = vmap_ptr->idx; + vmap_ptr += 1; + for(;vmap_ptr < vmap_opl && vmap_ptr->idx == idx;) vmap_ptr += 1; + rdim_memcpy_struct(vmap_out, vmap_range_first); + vmap_out += 1; + } + vmap_entry_count = (RDI_U32)(vmap_out - vmap); // TODO(rjf): @u64_to_u32 + } + + //- rjf: fill result + task->bake_vmap_out->vmap = vmap; + task->bake_vmap_out->count = vmap_entry_count; + } + scratch_end(scratch); + } + lane_sync(); ////////////////////////////////////////////////////////////// //- rjf: build interned path tree @@ -984,6 +1296,139 @@ rdim2_bake(Arena *arena, RDIM_BakeParams *params) } } } + lane_sync(); + RDIM_StringBakeResult baked_strings = rdim2_shared->baked_strings; + + ////////////////////////////////////////////////////////////// + //- rjf: compute layout for scope sub-lists (locals / voffs) + // + ProfScope("compute layout for scope sub-lists (locals / voffs)") + { + // rjf: set up + if(lane_idx() == 0) + { + rdim2_shared->scope_local_chunk_lane_counts = push_array(arena, RDI_U64, lane_count() * params->scopes.chunk_count); + rdim2_shared->scope_local_chunk_lane_offs = push_array(arena, RDI_U64, lane_count() * params->scopes.chunk_count); + rdim2_shared->scope_voff_chunk_lane_counts = push_array(arena, RDI_U64, lane_count() * params->scopes.chunk_count); + rdim2_shared->scope_voff_chunk_lane_offs = push_array(arena, RDI_U64, lane_count() * params->scopes.chunk_count); + } + lane_sync(); + + // rjf: count per-lane-chunk + { + U64 chunk_idx = 0; + for EachNode(n, RDIM_ScopeChunkNode, params->scopes.first) + { + U64 num_locals_in_this_lane_and_node = 0; + U64 num_voffs_in_this_lane_and_node = 0; + Rng1U64 range = lane_range(n->count); + for EachInRange(n_idx, range) + { + num_locals_in_this_lane_and_node += n->v[n_idx].local_count; + num_voffs_in_this_lane_and_node += n->v[n_idx].voff_ranges.count; + } + rdim2_shared->scope_local_chunk_lane_counts[lane_idx()*params->scopes.chunk_count + chunk_idx] = num_locals_in_this_lane_and_node; + rdim2_shared->scope_voff_chunk_lane_counts[lane_idx()*params->scopes.chunk_count + chunk_idx] = num_voffs_in_this_lane_and_node; + chunk_idx += 1; + } + } + lane_sync(); + + // rjf: lay out each lane's range + if(lane_idx() == 0) + { + U64 local_layout_off = 0; + U64 voff_layout_off = 0; + U64 chunk_idx = 0; + for EachNode(n, RDIM_ScopeChunkNode, params->scopes.first) + { + for EachIndex(l_idx, lane_count()) + { + U64 slot_idx = l_idx*params->scopes.chunk_count + chunk_idx; + rdim2_shared->scope_local_chunk_lane_offs[slot_idx] = local_layout_off; + rdim2_shared->scope_voff_chunk_lane_offs[slot_idx] = voff_layout_off; + local_layout_off += rdim2_shared->scope_local_chunk_lane_counts[slot_idx]; + voff_layout_off += rdim2_shared->scope_voff_chunk_lane_counts[slot_idx]; + } + chunk_idx += 1; + } + } + lane_sync(); + } + lane_sync(); + + ////////////////////////////////////////////////////////////// + //- rjf: bake scopes + // + ProfScope("bake scopes") + { + //- rjf: setup outputs + if(lane_idx() == lane_from_task_idx(0)) + { + rdim2_shared->baked_scopes.scopes_count = params->scopes.total_count+1; + rdim2_shared->baked_scopes.scopes = push_array(arena, RDI_Scope, rdim2_shared->baked_scopes.scopes_count); + } + if(lane_idx() == lane_from_task_idx(1)) + { + rdim2_shared->baked_scopes.scope_voffs_count = params->scopes.scope_voff_count+1; + rdim2_shared->baked_scopes.scope_voffs = push_array(arena, RDI_U64, rdim2_shared->baked_scopes.scope_voffs_count); + } + if(lane_idx() == lane_from_task_idx(2)) + { + rdim2_shared->baked_scopes.locals_count = params->scopes.local_count+1; + rdim2_shared->baked_scopes.locals = push_array(arena, RDI_Local, rdim2_shared->baked_scopes.locals_count); + } + lane_sync(); + + //- rjf: wide fill + { + U64 chunk_idx = 0; + for EachNode(n, RDIM_ScopeChunkNode, params->scopes.first) + { + Rng1U64 range = lane_range(n->count); + U64 chunk_lane_slot_idx = lane_idx()*params->scopes.chunk_count + chunk_idx; + U64 chunk_local_off = rdim2_shared->scope_local_chunk_lane_offs[chunk_lane_slot_idx]; + U64 chunk_voff_off = rdim2_shared->scope_voff_chunk_lane_offs[chunk_lane_slot_idx]; + for EachInRange(n_idx, range) + { + U64 dst_idx = 1 + n->base_idx + n_idx; + RDIM_Scope *src_scope = &n->v[n_idx]; + RDI_Scope *dst_scope = &rdim2_shared->baked_scopes.scopes[dst_idx]; + + //- rjf: fill voff ranges + U64 voff_idx_first = chunk_voff_off; + for EachNode(rng_n, RDIM_Rng1U64Node, src_scope->voff_ranges.first) + { + rdim2_shared->baked_scopes.scope_voffs[chunk_voff_off+0] = rng_n->v.min; + rdim2_shared->baked_scopes.scope_voffs[chunk_voff_off+1] = rng_n->v.max; + chunk_voff_off += 2; + } + U64 voff_idx_opl = chunk_voff_off; + + //- rjf: fill locals + U64 local_idx_first = chunk_local_off; + for EachNode(src_local, RDIM_Local, src_scope->first_local) + { + RDI_Local *dst_local = &rdim2_shared->baked_scopes.locals[chunk_local_off]; + chunk_local_off += 1; + } + U64 local_idx_opl = chunk_local_off; + + //- rjf: fill scope + dst_scope->proc_idx = (RDI_U32)rdim_idx_from_symbol(src_scope->symbol); // TODO(rjf): @u64_to_u32 + dst_scope->parent_scope_idx = (RDI_U32)rdim_idx_from_scope(src_scope->parent_scope); // TODO(rjf): @u64_to_u32 + dst_scope->first_child_scope_idx = (RDI_U32)rdim_idx_from_scope(src_scope->first_child); // TODO(rjf): @u64_to_u32 + dst_scope->next_sibling_scope_idx = (RDI_U32)rdim_idx_from_scope(src_scope->next_sibling); // TODO(rjf): @u64_to_u32 + dst_scope->voff_range_first = (RDI_U32)voff_idx_first; // TODO(rjf): @u64_to_u32 + dst_scope->voff_range_opl = (RDI_U32)voff_idx_opl; // TODO(rjf): @u64_to_u32 + dst_scope->local_first = (RDI_U32)local_idx_first; // TODO(rjf): @u64_to_u32 + dst_scope->local_count = (RDI_U32)(local_idx_opl - local_idx_first); // TODO(rjf): @u64_to_u32 + dst_scope->inline_site_idx = (RDI_U32)rdim_idx_from_inline_site(src_scope->inline_site); // TODO(rjf): @u64_to_u32 + } + chunk_idx += 1; + } + } + } ////////////////////////////////////////////////////////////// //- rjf: bake units, src files, symbols, types, UDTs diff --git a/src/rdi_make/rdi_make_local_2.h b/src/rdi_make/rdi_make_local_2.h index aaf07077..85649a9a 100644 --- a/src/rdi_make/rdi_make_local_2.h +++ b/src/rdi_make/rdi_make_local_2.h @@ -25,9 +25,21 @@ struct RDIM2_Shared RDIM_SortKey *scope_vmap_keys; RDIM_SortKey *scope_vmap_keys__swap; RDIM_VMapMarker *scope_vmap_markers; + RDI_U64 unit_vmap_count; + RDIM_SortKey *unit_vmap_keys; + RDIM_SortKey *unit_vmap_keys__swap; + RDIM_VMapMarker *unit_vmap_markers; + RDI_U64 global_vmap_count; + RDIM_SortKey *global_vmap_keys; + RDIM_SortKey *global_vmap_keys__swap; + RDIM_VMapMarker *global_vmap_markers; U32 **lane_digit_counts; U32 **lane_digit_offsets; + RDIM_ScopeVMapBakeResult baked_scope_vmap; + RDIM_UnitVMapBakeResult baked_unit_vmap; + RDIM_GlobalVMapBakeResult baked_global_vmap; + RDIM_BakePathTree *path_tree; RDI_U64 line_tables_count; @@ -56,6 +68,13 @@ struct RDIM2_Shared RDIM_StringBakeResult baked_strings; RDIM_IndexRunBakeResult baked_idx_runs; + RDI_U64 *scope_local_chunk_lane_counts; // [lane_count * scope_chunk_count] + RDI_U64 *scope_local_chunk_lane_offs; // [lane_count * scope_chunk_count] + RDI_U64 *scope_voff_chunk_lane_counts; // [lane_count * scope_chunk_count] + RDI_U64 *scope_voff_chunk_lane_offs; // [lane_count * scope_chunk_count] + + RDIM_ScopeBakeResult baked_scopes; + RDIM_UnitBakeResult baked_units; RDIM_SrcFileBakeResult baked_src_files; RDIM_TypeNodeBakeResult baked_type_nodes; @@ -70,9 +89,6 @@ struct RDIM2_Shared RDIM_TopLevelInfoBakeResult baked_top_level_info; RDIM_BinarySectionBakeResult baked_binary_sections; - RDIM_UnitVMapBakeResult baked_unit_vmap; - RDIM_ScopeVMapBakeResult baked_scope_vmap; - RDIM_GlobalVMapBakeResult baked_global_vmap; }; global RDIM2_Shared *rdim2_shared = 0;