data-shards spike: memoized pure-function replay (capture/verify/replay + cycle-faithful credit)

- runtime/src/data_shards.c + include: read-before-write recorder fed from
  the memory chokepoints; byte-verified replay (kernel-bless pattern);
  recorded-cycle credit in slices through psx_advance_cycles +
  psx_check_interrupts_at; purity poisons (MMIO/DMA/thread-switch/budget);
  .dss persistence under the unified cache dir; TCP data_shards cmd.
- emitter: [data_shards] funcs -> psx_datashard_enter at entry +
  psx_datashard_ret at jr-$ra sites (rolls cg-hash).
- obs: phase_hot set=static keyed on new g_psx_last_fn_entry entry stamp
  (current_func dispatch stamp survives post-IRQ resumption and pooled 55%
  of static samples on kernel 0xF40); TCP starv_ring query for the
  always-on PC-sample ring.
- docs/DATA_SHARDS.md: design, soundness model, gates, FMV exclusion.
This commit is contained in:
Matthew Stanley
2026-07-10 22:22:47 -07:00
parent f88b8a510e
commit 12934ed2c5
15 changed files with 899 additions and 13 deletions
+18
View File
@@ -1700,6 +1700,12 @@ std::string CodeGenerator::translate_basic_block(
ss << config_.indent
<< "gte_ws_set_suppress(0); /* widescreen: end far-backdrop un-squash (8C) */\n";
}
if (config_.data_shard_funcs.count(cfg.function_start)) {
// Capture finalize: fires only when this is the armed
// function's own return (sp/ra checked runtime-side).
ss << config_.indent
<< "psx_datashard_ret(cpu); /* data-shard: finalize capture */\n";
}
if (ra_loaded_from_non_sp) {
ss << emit_interrupt_check_expr(delay_saved_target, config_.indent);
ss << config_.indent
@@ -2190,6 +2196,16 @@ GeneratedFunction CodeGenerator::generate_function(
body_ss << config_.indent
<< fmt::format("debug_server_log_call_entry(0x{:08X}u);\n",
func.start_addr);
if (config_.data_shard_funcs.count(func.start_addr)) {
// Data-shard hook (docs/DATA_SHARDS.md): on a verified shard hit the
// runtime applies the recorded effect, credits the recorded cycles,
// publishes pc=$ra and we return without executing the body. Otherwise
// it arms the capture recorder and the body runs natively.
body_ss << config_.indent
<< fmt::format("if (psx_datashard_enter(cpu, 0x{:08X}u)) return;"
" /* data-shard: replay or arm capture */\n",
func.start_addr);
}
if (config_.ws_sprite_tag_funcs.count(func.start_addr)) {
body_ss << config_.indent
<< "psx_ws_sprite_tag(cpu); /* widescreen: record prim ($a0) + anchor */\n";
@@ -2632,6 +2648,8 @@ std::string CodeGenerator::generate_file(
ss << "extern void cosim_block(uint32_t block_leader_phys);\n";
ss << "extern void cosim_instr(uint32_t pc);\n";
ss << "#endif\n";
ss << "extern int psx_datashard_enter(CPUState* cpu, uint32_t key); /* data-shard replay/capture (data_shards.c) */\n";
ss << "extern void psx_datashard_ret(CPUState* cpu); /* data-shard capture finalize */\n";
ss << "extern void psx_ws_sprite_tag(CPUState* cpu); /* widescreen prim tag (gpu.c) */\n";
ss << "extern void psx_ws_mmx6_bg_stage_init(void); /* ws 2D stage reveal invalidation (gpu.c) */\n";
ss << "extern int psx_ws_x_margin(void); /* widescreen cull-margin term (gpu.c) */\n";