Files
mlkem-sync/.trellis/tasks/archive/2026-06/06-25-fix-tb-failures/prd.md

40 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 修复 7 个失败的 testbench
## Goal
修复在 Vivado 2019.2 上运行失败的 7 个 testbenchcomp_decomp, storage, sha3_chain, ntt, poly_mul, sample_cbd, sample_ntt。
## Root Causes
### 1. TCL 变量缺失 (sha3_chain, sample_cbd, sample_ntt)
`run_tb.sh` 只提取 `set SRC_DIR/TB_DIR/COMMON_DIR`,但这些 TCL 还定义了 `SHA3_DIR` 等变量用于引用 sha3 依赖。
### 2. Verilog part-select 非常量 (ntt, poly_mul)
```verilog
t_coeffs[ci] = vector_mem[idx][(255-ci)*12+11 : (255-ci)*12];
```
Vivado 2019.2 要求 part-select 的边界必须是常量表达式,`ci` 是变量导致编译失败。需要改用 `+:``for` 循环 + `case`
### 3. BRAM 读延迟未对齐 (storage)
s_bram/sd_bram 有 1 周期读延迟assert rd_addr 后,下一周期 rd_data 才有效。TB 在同一周期检查 rd_data。
### 4. comp_decomp 位宽边界 (comp_decomp)
d=12 时 compress 输出需要 12 位2^12=4096期望值 4095 正确但 DUT 的 `coeff_out` 只有 12 位。实际问题是 compress mod 2^d 在边界处产生 0因为 4095+1 进位溢出)。需要检查 gen_vectors.py 的期望值生成逻辑。
## Requirements
* sha3_chain, sample_cbd, sample_ntt: 修复 xsim_run.tcl 中缺失的变量定义
* ntt, poly_mul: 修复 part-select 为非变量形式
* storage: 修复读延迟(插入 1 个时钟周期等待)
* comp_decomp: 修复期望值或 TB 比较逻辑
* 所有 10 个 TB 在 Vivado 2019.2 上 PASS
## Decisions Made
* 直接修复现有 TB 文件,不重新生成
* 遵循 Vivado 2019.2 SystemVerilog 约束
## Out of Scope
* RTL 修改