Systemc

From babyworm/rtl-agent-team · View interactive version

Systemc is an AI agent skill from the GitHub repository babyworm/rtl-agent-team. systemc project conventions (loaded by writer agents; do not invoke).

How to use this skill

Skill file

<Purpose>

SystemC/TLM-2.0 project conventions for Reference Model (Phase 2) and BFM (Phase 3) code.

This skill covers project-specific rules only — TLM-2.0 mechanics (IEEE 1666-2011) are assumed known.

Language standard pins:

</Purpose>

<Use_When>

</Use_When>

<Do_Not_Use_When>

</Do_Not_Use_When>

<Execution_Policy>

PEQ (peq_with_cb_and_phase) and payload pooling (tlm_mm_interface + acquire()/release()).

LT (b_transport()) only for simple register access (APB/AXI-Lite) or when explicitly requested

targets; ACE ONLY when cache coherency is explicitly required

</Execution_Policy>

<Steps>

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:

Fixed-point rules:

// 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

RTL wrapper + optional DPI-C bridge to SV TB)

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:

Prohibited:

</Steps>

<Tool_Usage>

This skill is not executed directly. It is referenced by agents that generate SystemC code

(e.g., bfm-dev, ref-model-dev). Agents should follow the conventions defined here.

</Tool_Usage>

<Examples>

AT non-blocking BFM (MemoryManager, PEQ, AXI extension, 4-phase): examples/bfm-at-pattern.cpp.

LT register-access BFM: examples/bfm-pattern.cpp.

</Examples>

<Escalation_And_Stop_Conditions>

</Escalation_And_Stop_Conditions>

<Final_Checklist>

</Final_Checklist>

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.