Prerequisites
docs/phase-1-research/iron-requirements.json present with REQ-F-* items.
- JM 19.0 (H.264) or HM 16.20 (H.265) installed and on
PATH.
If missing: WARNING — proceed with available artifacts; feature coverage step will note absent requirements file.
Apply steps 1-9 to every algorithm unit requested — do not stop after the first.
Task(subagent_type="rtl-agent-team:ref-model-dev",
prompt="Implement C functional reference model at refc/. Must be bitexact vs JM. "
"No clock/reset — pure functional. I/O as function args. Internal memory as arrays/struct. "
"External memory via ext_mem_read/write. PARALLEL_LANES parameterizable. "
"C11, DPI-C compatible (no C++ features). Use templates/ scaffolding.")
Task(subagent_type="rtl-agent-team:ref-model-reviewer",
prompt="Review refc/ model quality. Check algorithm fidelity, fixed-point/bit-width correctness, "
"build warnings, UB risks, and I/O format compatibility. "
"Save report to reviews/phase-2-architecture/ref-model-review.md with PASS/FAIL verdict.")
</Tool_Usage>
<Examples>
<example index="1">
<scenario>New CABAC entropy coder; Phase 1 complete; JM 19.0 available.</scenario>
<expected_output>refc/cabac_encoder.c compiled clean; 500 ITU-T vectors pass bitexact vs JM 19.0; bandwidth_report.json shows 2.3 MB/frame reads; all REQ-F-* mapped; ref-model-reviewer issues PASS.</expected_output>
</example>
<example index="2">
<scenario>Spec change adds intra 8×8 prediction; existing ref model misses REQ-F-042.</scenario>
<expected_output>ref-model-dev adds intra_predict_8x8(); feature-coverage.md updated; re-run confirms bitexact match; conformance_report.json refreshed.</expected_output>
</example>
<example index="3">
<scenario>Datapath width exploration: choose between PARALLEL_LANES=4 and PARALLEL_LANES=8.</scenario>
<expected_output>bandwidth_report.json generated for both configs; estimated_read_cycles compared; architect selects PARALLEL_LANES=4 based on memory bandwidth budget.</expected_output>
</example>
</Examples>
<Escalation_And_Stop_Conditions>
- Bitexact mismatch persists after 3 fix iterations → report failing vectors with diff to user.
- JM/HM not available → halt; instruct user to install before proceeding.
- Feature coverage < 100% and user declines to implement missing feature → record ADR with impact estimate; proceed only with explicit approval.
- External memory bandwidth exceeds technology limits → escalate to arch-designer for block restructuring.
</Escalation_And_Stop_Conditions>
## Output
- `refc/*.c`, `refc/include/*.h` — C11 functional reference model.
- `conformance_report.json` — per-vector bitexact results with JM/HM version.
- `bandwidth_report.json` — external memory access statistics per block.
- `reviews/phase-2-architecture/ref-model-feature-coverage.md` — REQ-F-* mapping table.
- `reviews/phase-2-architecture/ref-model-review.md` — reviewer verdict.
<Final_Checklist>
- [ ] `refc/*.c` compiles with `gcc -std=c11 -Wall -Wextra -Werror`.
- [ ] No C++ features — DPI-C compatible pure C.
- [ ] No clock/reset — pure functional model.
- [ ] External memory uses `ext_mem_read`/`ext_mem_write` abstraction.
- [ ] `PARALLEL_LANES` parameterizable.
- [ ] All test vectors pass bitexact comparison vs JM/HM.
- [ ] `make sanitize` passes clean (`-fsanitize=address,undefined`).
- [ ] All `REQ-F-*` items mapped to code paths; `ref-model-feature-coverage.md` saved.
- [ ] Missing features escalated; user-approved omissions have ADR.
- [ ] `ref-model-reviewer` report saved with PASS verdict.
- [ ] `conformance_report.json` and `bandwidth_report.json` written.
</Final_Checklist>
1---2name: ref-model3description: Builds Phase 2 golden C reference model with bitexact conformance and bandwidth estimation. Use for 'build reference model', 'C ref model', 'golden model'.4---56<Purpose>7Build a golden C functional reference model (Phase 2) that validates algorithm correctness and estimates external memory bandwidth. Outputs: `refc/*.c`, `refc/include/*.h`, `conformance_report.json`, `bandwidth_report.json`, and `reviews/phase-2-architecture/ref-model-feature-coverage.md`.8</Purpose>910<Use_When>11- Phase 1 artifacts are complete and a reference model does not yet exist.12- Reference model needs updating after a spec change.13- A conformance baseline is needed before RTL verification can begin.14- Bandwidth or datapath-width exploration is required.15- An independent quality gate is needed before declaring the model a verification oracle.16</Use_When>1718<Do_Not_Use_When>19- Reference model already exists and `conformance_report.json` is current — avoid regenerating.20- Only a quick algorithm question is needed → use `domain-consult` instead.21</Do_Not_Use_When>2223<Why_This_Exists>24Writing the reference model before RTL forces algorithm understanding and exposes spec ambiguities before silicon commitment. Bitexact match against JM/HM is the industry-standard acceptance criterion. The model doubles as a bandwidth analysis tool by routing all external memory traffic through `ext_mem_read`/`ext_mem_write`, enabling memory-bandwidth estimation without RTL.25</Why_This_Exists>2627## Prerequisites2829- `docs/phase-1-research/iron-requirements.json` present with `REQ-F-*` items.30- JM 19.0 (H.264) or HM 16.20 (H.265) installed and on `PATH`.3132If missing: WARNING — proceed with available artifacts; feature coverage step will note absent requirements file.3334<Assets>35| Path | Role |36|------|------|37| `templates/Makefile` | Build + test + bandwidth targets (`build`, `test`, `bandwidth`, `sanitize`). |38| `templates/ref_model_main.c` | Scaffold with `ext_mem_read/write` stubs and `PARALLEL_LANES` define. |39| `templates/ref_model_header.h` | Struct typedefs: `input_t`, `output_t`, `context_t`, `ext_mem_stats_t`. |40| `templates/dpi_wrapper.h` | DPI-C export declarations for SV testbench linkage. |41| `scripts/run_ref_model.py` | Build-and-run wrapper: locates `refc/`, builds via Makefile (direct `cc -std=c11` fallback), runs the model with `--input`/`--output`/`--args` pass-through, writes a JSON run report. |42| `references/ref-model-conventions.md` | C11/DPI-C rules, output schemas, anti-patterns. |43| `examples/sat_add/` | Worked example: self-testing saturating-adder ref model + committed `expected_run_report.json` (regeneration-checked in CI). |44</Assets>4546<Responsibility_Boundary>47- **Scripts** handle build, bitexact comparison, and bandwidth measurement via `Makefile` targets.48- **LLM** handles algorithm implementation, feature-coverage mapping, and spec-gap escalation.49- Contract surface: `ext_mem_read/write` abstraction layer + `REQ-F-*` coverage table.50</Responsibility_Boundary>5152<Execution>531. Spawn domain expert for algorithm pseudocode and edge-case table (see Tool_Usage).542. Spawn `ref-model-dev` to implement `refc/*.c` — pure C11, no clock/reset, I/O as function args, internal state as arrays/struct members, external memory via `ext_mem_read/write`, `PARALLEL_LANES` parameterizable, no C++ features.553. Build: `cd refc && make build` (must compile with `-Wall -Wextra -Werror`).564. Test: `cd refc && make test` — bitexact comparison against JM/HM; fix mismatches and iterate.57 For a single build+run cycle with a machine-readable result, use58 `python3 {plugin_root}/skills/ref-model/scripts/run_ref_model.py --refc-dir refc --report refc_run_report.json`59 (`{plugin_root}` resolved from `.rat/state/spawn-context.json`) — exit 0 = model ran clean, 1 = build/run failure (report written), 2 = environment error.605. Bandwidth: `cd refc && make bandwidth` — captures `ext_mem_stats_t`; write `bandwidth_report.json`.616. Feature coverage: read `iron-requirements.json`, map every `REQ-F-*` to a real code path (structural check — not just bitexact coverage); save `reviews/phase-2-architecture/ref-model-feature-coverage.md`. Escalate any unmapped feature to the user before proceeding.627. Spawn `ref-model-reviewer` for algorithm fidelity, numeric precision, and UB/memory-safety review.638. Write `conformance_report.json` with JM/HM version and per-vector pass/fail.649. Sanitize: `cd refc && make sanitize` (`-fsanitize=address,undefined`) — must pass clean.6566Apply steps 1-9 to every algorithm unit requested — do not stop after the first.67</Execution>6869<Tool_Usage>70```71Task(subagent_type="rtl-agent-team:vcodec-syntax-entropy-expert",72 prompt="Provide algorithm pseudocode and edge case table for CABAC entropy coding per H.264 spec §9.3.")7374Task(subagent_type="rtl-agent-team:ref-model-dev",75 prompt="Implement C functional reference model at refc/. Must be bitexact vs JM. "76 "No clock/reset — pure functional. I/O as function args. Internal memory as arrays/struct. "77 "External memory via ext_mem_read/write. PARALLEL_LANES parameterizable. "78 "C11, DPI-C compatible (no C++ features). Use templates/ scaffolding.")7980Task(subagent_type="rtl-agent-team:ref-model-reviewer",81 prompt="Review refc/ model quality. Check algorithm fidelity, fixed-point/bit-width correctness, "82 "build warnings, UB risks, and I/O format compatibility. "83 "Save report to reviews/phase-2-architecture/ref-model-review.md with PASS/FAIL verdict.")84```85</Tool_Usage>8687<Examples>88<example index="1">89<scenario>New CABAC entropy coder; Phase 1 complete; JM 19.0 available.</scenario>90<expected_output>refc/cabac_encoder.c compiled clean; 500 ITU-T vectors pass bitexact vs JM 19.0; bandwidth_report.json shows 2.3 MB/frame reads; all REQ-F-* mapped; ref-model-reviewer issues PASS.</expected_output>91</example>9293<example index="2">94<scenario>Spec change adds intra 8×8 prediction; existing ref model misses REQ-F-042.</scenario>95<expected_output>ref-model-dev adds intra_predict_8x8(); feature-coverage.md updated; re-run confirms bitexact match; conformance_report.json refreshed.</expected_output>96</example>9798<example index="3">99<scenario>Datapath width exploration: choose between PARALLEL_LANES=4 and PARALLEL_LANES=8.</scenario>100<expected_output>bandwidth_report.json generated for both configs; estimated_read_cycles compared; architect selects PARALLEL_LANES=4 based on memory bandwidth budget.</expected_output>101</example>102</Examples>103104<Escalation_And_Stop_Conditions>105- Bitexact mismatch persists after 3 fix iterations → report failing vectors with diff to user.106- JM/HM not available → halt; instruct user to install before proceeding.107- Feature coverage < 100% and user declines to implement missing feature → record ADR with impact estimate; proceed only with explicit approval.108- External memory bandwidth exceeds technology limits → escalate to arch-designer for block restructuring.109</Escalation_And_Stop_Conditions>110111## Output112113- `refc/*.c`, `refc/include/*.h` — C11 functional reference model.114- `conformance_report.json` — per-vector bitexact results with JM/HM version.115- `bandwidth_report.json` — external memory access statistics per block.116- `reviews/phase-2-architecture/ref-model-feature-coverage.md` — REQ-F-* mapping table.117- `reviews/phase-2-architecture/ref-model-review.md` — reviewer verdict.118119<Final_Checklist>120- [ ] `refc/*.c` compiles with `gcc -std=c11 -Wall -Wextra -Werror`.121- [ ] No C++ features — DPI-C compatible pure C.122- [ ] No clock/reset — pure functional model.123- [ ] External memory uses `ext_mem_read`/`ext_mem_write` abstraction.124- [ ] `PARALLEL_LANES` parameterizable.125- [ ] All test vectors pass bitexact comparison vs JM/HM.126- [ ] `make sanitize` passes clean (`-fsanitize=address,undefined`).127- [ ] All `REQ-F-*` items mapped to code paths; `ref-model-feature-coverage.md` saved.128- [ ] Missing features escalated; user-approved omissions have ADR.129- [ ] `ref-model-reviewer` report saved with PASS verdict.130- [ ] `conformance_report.json` and `bandwidth_report.json` written.131</Final_Checklist>