Language standard pins:
- Reference Model: C11 (
-std=c11), pure C, standalone — compilable without SystemC
- BFM/SystemC: C++17 (
-std=c++17); C++20 features (concepts, ranges, coroutines, modules) forbidden
1. Naming Conventions
1.1 Filenames
| Type |
Pattern |
Example |
| Reference Model |
ref_{module}.c / .h |
ref_cabac.c |
| BFM |
bfm_{module}.cpp / .h |
bfm_axi_master.cpp |
| TLM Adapter |
tlm_{module}_adapter.cpp |
tlm_cabac_adapter.cpp |
| Memory Manager |
memory_manager.h |
memory_manager.h |
| DPI-C Interface |
dpi_{module}.cpp / .h |
dpi_interface.cpp |
| Testbench Top |
tb_{module}_top.cpp |
tb_cabac_top.cpp |
| Package (shared types) |
{module}_types.h |
cabac_types.h |
1.2 Class/Module Naming
| Target |
Rule |
Example |
| SC_MODULE |
snake_case |
cabac_encoder_bfm |
| Reference Model class |
{module}_ref_model |
cabac_ref_model |
| BFM class |
{module}_bfm |
axi_master_bfm |
| TLM Socket |
{role}_{protocol}_socket |
init_axi_socket, targ_mem_socket |
| Member variables |
m_ prefix |
m_state, m_ctx_table |
| Constants |
UPPER_SNAKE_CASE |
MAX_CTX_ENTRIES |
1.3 Port Naming (RTL Matching)
SystemC ports use the same names as their RTL counterparts:
sc_in<sc_uint<8>> i_data{"i_data"};
sc_out<bool> o_valid{"o_valid"};
sc_in<bool> sys_clk{"sys_clk"}; // clock: no i_/o_ prefix
sc_in<bool> sys_rst_n{"sys_rst_n"}; // reset: no i_/o_ prefix
2. Bit-Exactness Rules (Reference Model)
Core principles:
- Bit-accurate: must guarantee identical bit-level results as the RTL
- Cycle-agnostic: implements only the algorithm, no timing concepts
- Deterministic: same input → same output (no random, no float)
- Standalone: compilable as pure C without SystemC
Fixed-point rules:
- Fixed-width integers only (
int16_t, uint32_t); no int (platform-dependent width), no float/double
- Explicitly specify overflow behavior: saturate vs wrap
// CORRECT: bit-exact fixed-point multiply
int32_t fixed_mul(int16_t a, int16_t b) {
return static_cast<int32_t>(a) * static_cast<int32_t>(b);
}
// WRONG: 'int result = a * b;' — implicit promotion may differ from RTL
3. BFM Rules
- Cycle-accurate: produce results in the same number of cycles as RTL
- AT non-blocking by default; LT only when explicitly requested (see Execution_Policy)
- Separate pin-adapter: keep TLM abstraction separate from the pin-level interface (sc_signal
RTL wrapper + optional DPI-C bridge to SV TB)
- Timing values derive from
timing_constraints.json — no magic wait(2.0, SC_NS) numbers
- Every model needs an
sc_main testbench; always call set_response_status() before returning
4. Build Rules
# Reference Model (standalone C, no SystemC)
gcc -std=c11 -O2 -Wall -Wextra -Werror -shared -fPIC -o ref_cabac.so ref_cabac.c
# BFM (SystemC required)
g++ -std=c++17 -O2 -Wall -Wextra \
-I${SYSTEMC_HOME}/include -L${SYSTEMC_HOME}/lib-linux64 -lsystemc \
-o tb_cabac tb_cabac_top.cpp bfm_cabac.cpp
# cocotb integration (shared library, C ref model)
gcc -std=c11 -shared -fPIC -o ref_cabac.so ref_cabac.c
cocotb integration:
import ctypes
lib = ctypes.CDLL("./ref_cabac.so")
lib.encode_bin.restype = ctypes.c_uint32
lib.encode_bin.argtypes = [ctypes.c_uint16, ctypes.c_bool]
expected = lib.encode_bin(ctx_addr, bin_val)
5. Coding Style
Mandatory:
- C++17 (not C++20), fixed-width integers (
<cstdint>), RAII, const, header guard
- AT models: MemoryManager (payload pooling via
tlm_mm_interface, p->reset() in free()) + PEQ
Prohibited:
float/double in bit-exact models; platform-dependent int
malloc/free (use RAII); using namespace std; in headers
- LT
b_transport in performance BFMs (use AT); missing AT phase transitions (implement all 4 phases with PEQ)
- Blocking DPI calls that deadlock (queue to SC_THREAD for async handling)
1---2name: systemc3description: systemc project conventions (loaded by writer agents; do not invoke).4---56<Purpose>7SystemC/TLM-2.0 project conventions for Reference Model (Phase 2) and BFM (Phase 3) code.8This skill covers project-specific rules only — TLM-2.0 mechanics (IEEE 1666-2011) are assumed known.910Language standard pins:11- Reference Model: **C11** (`-std=c11`), pure C, standalone — compilable without SystemC12- BFM/SystemC: **C++17** (`-std=c++17`); C++20 features (concepts, ranges, coroutines, modules) forbidden13</Purpose>1415<Use_When>16- Writing .cpp/.h in a SystemC/TLM-2.0 context (Phase 2 Reference Model, Phase 3 BFM)17- Agents: bfm-dev, ref-model-dev18</Use_When>1920<Do_Not_Use_When>21- SystemVerilog code → `systemverilog` skill; Python cocotb → `rtl-p5s-func-verify` skill; non-SystemC C/C++ utilities22</Do_Not_Use_When>2324<Execution_Policy>25- **AT (Approximately Timed) non-blocking is the default BFM style**: `nb_transport_fw/bw()` with26 PEQ (`peq_with_cb_and_phase`) and payload pooling (`tlm_mm_interface` + `acquire()`/`release()`).27 LT (`b_transport()`) only for simple register access (APB/AXI-Lite) or when explicitly requested28- **AXI is the default protocol** (amba_pv extensions); AHB/APB only for legacy/low-bandwidth29 targets; ACE ONLY when cache coherency is explicitly required30- New module scaffold: `templates/tlm2-module-template.cpp`31- AT pattern incl. MemoryManager + PEQ + 4-phase handling: `examples/bfm-at-pattern.cpp`32- LT pattern (simple register access): `examples/bfm-pattern.cpp`33</Execution_Policy>3435<Steps>3637## 1. Naming Conventions3839### 1.1 Filenames40| Type | Pattern | Example |41|------|---------|---------|42| Reference Model | `ref_{module}.c / .h` | `ref_cabac.c` |43| BFM | `bfm_{module}.cpp / .h` | `bfm_axi_master.cpp` |44| TLM Adapter | `tlm_{module}_adapter.cpp` | `tlm_cabac_adapter.cpp` |45| Memory Manager | `memory_manager.h` | `memory_manager.h` |46| DPI-C Interface | `dpi_{module}.cpp / .h` | `dpi_interface.cpp` |47| Testbench Top | `tb_{module}_top.cpp` | `tb_cabac_top.cpp` |48| Package (shared types) | `{module}_types.h` | `cabac_types.h` |4950### 1.2 Class/Module Naming51| Target | Rule | Example |52|--------|------|---------|53| SC_MODULE | `snake_case` | `cabac_encoder_bfm` |54| Reference Model class | `{module}_ref_model` | `cabac_ref_model` |55| BFM class | `{module}_bfm` | `axi_master_bfm` |56| TLM Socket | `{role}_{protocol}_socket` | `init_axi_socket`, `targ_mem_socket` |57| Member variables | `m_` prefix | `m_state`, `m_ctx_table` |58| Constants | `UPPER_SNAKE_CASE` | `MAX_CTX_ENTRIES` |5960### 1.3 Port Naming (RTL Matching)61SystemC ports use the same names as their RTL counterparts:62```cpp63sc_in<sc_uint<8>> i_data{"i_data"};64sc_out<bool> o_valid{"o_valid"};65sc_in<bool> sys_clk{"sys_clk"}; // clock: no i_/o_ prefix66sc_in<bool> sys_rst_n{"sys_rst_n"}; // reset: no i_/o_ prefix67```6869## 2. Bit-Exactness Rules (Reference Model)7071Core principles:72- **Bit-accurate**: must guarantee identical bit-level results as the RTL73- **Cycle-agnostic**: implements only the algorithm, no timing concepts74- **Deterministic**: same input → same output (no random, no float)75- **Standalone**: compilable as pure C without SystemC7677Fixed-point rules:78- Fixed-width integers only (`int16_t`, `uint32_t`); no `int` (platform-dependent width), no `float`/`double`79- Explicitly specify overflow behavior: saturate vs wrap80```cpp81// CORRECT: bit-exact fixed-point multiply82int32_t fixed_mul(int16_t a, int16_t b) {83 return static_cast<int32_t>(a) * static_cast<int32_t>(b);84}85// WRONG: 'int result = a * b;' — implicit promotion may differ from RTL86```8788## 3. BFM Rules8990- **Cycle-accurate**: produce results in the same number of cycles as RTL91- **AT non-blocking by default**; LT only when explicitly requested (see Execution_Policy)92- **Separate pin-adapter**: keep TLM abstraction separate from the pin-level interface (sc_signal93 RTL wrapper + optional DPI-C bridge to SV TB)94- Timing values derive from `timing_constraints.json` — no magic `wait(2.0, SC_NS)` numbers95- Every model needs an `sc_main` testbench; always call `set_response_status()` before returning9697## 4. Build Rules9899```bash100# Reference Model (standalone C, no SystemC)101gcc -std=c11 -O2 -Wall -Wextra -Werror -shared -fPIC -o ref_cabac.so ref_cabac.c102103# BFM (SystemC required)104g++ -std=c++17 -O2 -Wall -Wextra \105 -I${SYSTEMC_HOME}/include -L${SYSTEMC_HOME}/lib-linux64 -lsystemc \106 -o tb_cabac tb_cabac_top.cpp bfm_cabac.cpp107108# cocotb integration (shared library, C ref model)109gcc -std=c11 -shared -fPIC -o ref_cabac.so ref_cabac.c110```111112cocotb integration:113```python114import ctypes115lib = ctypes.CDLL("./ref_cabac.so")116lib.encode_bin.restype = ctypes.c_uint32117lib.encode_bin.argtypes = [ctypes.c_uint16, ctypes.c_bool]118expected = lib.encode_bin(ctx_addr, bin_val)119```120121## 5. Coding Style122123Mandatory:124- C++17 (not C++20), fixed-width integers (`<cstdint>`), RAII, `const`, header guard125- AT models: MemoryManager (payload pooling via `tlm_mm_interface`, `p->reset()` in `free()`) + PEQ126127Prohibited:128- `float`/`double` in bit-exact models; platform-dependent `int`129- `malloc`/`free` (use RAII); `using namespace std;` in headers130- LT `b_transport` in performance BFMs (use AT); missing AT phase transitions (implement all 4 phases with PEQ)131- Blocking DPI calls that deadlock (queue to SC_THREAD for async handling)132133</Steps>134135<Tool_Usage>136This skill is not executed directly. It is referenced by agents that generate SystemC code137(e.g., bfm-dev, ref-model-dev). Agents should follow the conventions defined here.138</Tool_Usage>139140<Examples>141AT non-blocking BFM (MemoryManager, PEQ, AXI extension, 4-phase): `examples/bfm-at-pattern.cpp`.142LT register-access BFM: `examples/bfm-pattern.cpp`.143</Examples>144145<Escalation_And_Stop_Conditions>146- Bit mismatch between Ref Model and RTL → report discrepancy to func-verifier147- TLM-2.0 socket connection error → request review from bfm-dev148- Fixed-point overflow behavior unclear → request spec clarification from spec-analyst149- AMBA-PV headers not installed → guide user to install the ARM AMBA-PV library150</Escalation_And_Stop_Conditions>151152<Final_Checklist>153- [ ] Filename convention: `ref_` / `bfm_` / `tlm_` / `dpi_` prefix154- [ ] Use fixed-width integers only (`int32_t` etc., no `int`/`float`)155- [ ] Reference Model: cycle-agnostic, deterministic156- [ ] BFM: AT non-blocking by default, 4-phase protocol157- [ ] BFM: use Memory Manager + PEQ158- [ ] AMBA extension configured (AXI burst/cache/prot)159- [ ] Port names match RTL port names (`i_data`, `o_valid`, `sys_clk`)160- [ ] Shared library buildable for cocotb integration161- [ ] `m_` prefix for member variables162- [ ] Header guard present163</Final_Checklist>