127 lines
5.5 KiB
Python
127 lines
5.5 KiB
Python
"""The opentitan positions every perf phase measures, resolved at run time.
|
||
|
||
Nothing here is a hard-coded line number: each site names the *text* it wants
|
||
and `lspclient.find_position` locates it when the phase runs, so a corpus that
|
||
moves by a line measures the same token rather than a silent neighbour. The
|
||
0-based positions in `docs/performance_take4.md` are what these resolve to on
|
||
opentitan `0098135264`.
|
||
|
||
`ROOT` is overridden by `bench.py --opentitan`; every path below hangs off it.
|
||
"""
|
||
|
||
import os
|
||
|
||
ROOT = os.environ.get("OPENTITAN", "/Users/guoliangchen/repo/opentitan")
|
||
|
||
|
||
def path(relative):
|
||
return os.path.join(ROOT, relative)
|
||
|
||
|
||
# -- the take-3 scenario files ---------------------------------------------
|
||
|
||
TB = "hw/ip/aes/dv/tb/tb.sv"
|
||
AES = "hw/ip/aes/rtl/aes.sv"
|
||
AES_CORE = "hw/ip/aes/rtl/aes_core.sv"
|
||
AES_WRAP = "hw/ip/aes/rtl/aes_wrap.sv"
|
||
AON_TIMER = "hw/ip/aon_timer/rtl/aon_timer.sv"
|
||
KMAC = "hw/ip/kmac/rtl/kmac.sv"
|
||
HMAC = "hw/ip/hmac/rtl/hmac.sv"
|
||
SPI_DEVICE = "hw/ip/spi_device/rtl/spi_device.sv"
|
||
PINMUX_REG_TOP = "hw/top_darjeeling/ip_autogen/pinmux/rtl/pinmux_reg_top.sv"
|
||
AES_BIND = "hw/ip/aes/dv/sva/aes_bind.sv"
|
||
ENTROPY_SRC_CORE = "hw/ip/entropy_src/rtl/entropy_src_core.sv"
|
||
ENTROPY_SRC_SM = "hw/ip/entropy_src/rtl/entropy_src_main_sm.sv"
|
||
SHA3_FPV = "hw/ip/kmac/fpv/tb/sha3_fpv.sv"
|
||
AES_SBOX_MASKED = "hw/ip/aes/rtl/aes_sbox_canright_masked.sv"
|
||
# Take 5 §P2a: `rstmgr_por` is declared in four files, so a use of it is an
|
||
# ambiguous reference — the one shape that trips the rename fan-out's
|
||
# all-sources escape hatch.
|
||
RSTMGR = "hw/top_darjeeling/ip_autogen/rstmgr/rtl/rstmgr.sv"
|
||
|
||
# The take-3 `codeAction` cursors:
|
||
# (label, file, needle, occurrence, fan-out, cursor offset into the needle).
|
||
# The cursor lands on the module name. The fan-out is
|
||
# `grep -rlE '^\s*<module>( |#|$)' --include='*.sv'` over the corpus,
|
||
# re-derived for take 4 and identical to take 3's (1 / 6 / 42 / 67 / 128).
|
||
# The fan-out is `grep -rlE '^\s*<module>( |#|$)' --include='*.sv'` over the
|
||
# tree, re-derived for take 4 and identical to take 3's (1 / 6 / 42 / 67 / 128).
|
||
FANOUT_CURSORS = [
|
||
("aes_reg_top", AES, "aes_reg_top u_reg (", 1, 1, 0),
|
||
("aes", TB, " aes #(", 1, 6, 2),
|
||
("prim_lc_sync", AES, "prim_lc_sync #(", 1, 42, 0),
|
||
("prim_alert_sender", AES, "prim_alert_sender #(", 1, 67, 0),
|
||
("prim_flop_2sync", AON_TIMER, "prim_flop_2sync #(", 1, 128, 0),
|
||
]
|
||
|
||
# The scope replies handed back to `workspace/configuration`, by name.
|
||
SCOPES = {
|
||
"default": {},
|
||
"empty-index": {"index": {}},
|
||
"depth0": {"index": {"scopeDepth": 0}},
|
||
"workspace": {"index": {"scope": "workspace"}},
|
||
}
|
||
|
||
# Files opened one at a time in the widen phases (§5), with their sizes.
|
||
WIDEN_FILES = [AES, KMAC, HMAC, SPI_DEVICE]
|
||
|
||
# §46's didOpen → next-request files, the perf README's 2026-09-05 set.
|
||
DIDOPEN_FILES = [AES, AES_CORE, SPI_DEVICE, PINMUX_REG_TOP]
|
||
|
||
# The five refactoring offer sites 0.44–0.49 added, each a real opentitan
|
||
# position. `kind` names the action the site is meant to raise; the phase
|
||
# records what is actually offered, which is the point of measuring it.
|
||
# Each site was found by sweeping every instantiation-shaped and `import` line
|
||
# in a set of RTL files and keeping the positions that actually offer (the
|
||
# sweep is `bench.py probe`, one cursor at a time). The 0-based positions these
|
||
# resolve to on opentitan `0098135264` are named in `docs/performance_take4.md`
|
||
# §6b. There is **no** `convert to ANSI` site: opentitan has zero non-ANSI
|
||
# module headers (§6b), so the last row measures an ANSI header, where the
|
||
# action is correctly not offered.
|
||
REFACTOR_SITES = [
|
||
# A wildcard connection: `sha3 #(.EnMasking(...)) u_sha3 ( .* );` → 54:4.
|
||
("expand-wildcard", SHA3_FPV, " ) u_sha3 (", 1, 4),
|
||
# Two imports, one unused and one out of order → 42:2.
|
||
("organize-imports", AES_SBOX_MASKED, " import aes_pkg::*;", 1, 2),
|
||
# A separate-file instance written with named connections → 66:2.
|
||
("inline-module", AES_WRAP, " tlul_cmd_intg_gen tlul_cmd_intg_gen (", 1, 2),
|
||
# The take-3 offer site, still the one port-refactoring cursor found → 78:2.
|
||
("port-actions", AES_WRAP, " aes #(", 1, 2),
|
||
# An ANSI module header: the contrast row for `convert to ANSI` → 8:0.
|
||
("ansi-header (no offer expected)", AES, "module aes", 1, 0),
|
||
]
|
||
|
||
# The `extract module` site is a *selection*, not a point: three contiguous
|
||
# whole module items — `aes.sv`'s three status `assign`s. The span runs from
|
||
# the first needle's start to the end of the second needle.
|
||
EXTRACT_SELECTION = (
|
||
AES,
|
||
" assign idle_o", 1,
|
||
" assign input_ready_o = reg2hw.status.input_ready.q;", 1,
|
||
)
|
||
|
||
# §49's hierarchical tail. `entropy_src_main_sm.sv` declares `state_q` — a
|
||
# variable, not a port, so only the *hierarchical* surface reaches it — and
|
||
# `entropy_src_core.sv` instantiates that module as `u_entropy_src_main_sm`
|
||
# and names `u_entropy_src_main_sm.state_q`. The rename is issued at the
|
||
# declaration; the row records whether the tail's file joins the edit set,
|
||
# which is exactly what §49 changed.
|
||
TAIL_RENAME = (ENTROPY_SRC_SM, "state_d, state_q;", 1, len("state_d, "))
|
||
TAIL_TAIL_FILE = ENTROPY_SRC_CORE
|
||
TAIL_HEAD_COMPLETION = (
|
||
ENTROPY_SRC_CORE,
|
||
"u_entropy_src_main_sm.state_q", 1, len("u_entropy_src_main_sm."),
|
||
)
|
||
|
||
# The completion prefixes of take 3 §6d, typed at a fresh line in `tb.sv`.
|
||
COMPLETION_PREFIXES = ["", "a", "ae", "aes", "aes_", "prim_", "clk", "aes_reg", "zzzz"]
|
||
|
||
# The five CLI sweep trees (`sweep.sh` reads the same list).
|
||
TREES = [
|
||
"hw/ip",
|
||
"hw/top_earlgrey/ip",
|
||
"hw/top_darjeeling/ip",
|
||
"hw/dv",
|
||
"hw/vendor",
|
||
]
|