feat(tb): add independent KG/EN/DE testbenches

- sync_rtl/kg/TB/tb_kg_xsim.v + xsim_run.tcl
- sync_rtl/en/TB/tb_en_xsim.v + xsim_run.tcl
- sync_rtl/de/TB/tb_de_xsim.v + xsim_run.tcl

Run individual tests:
  ./run_tb.sh kg   (KeyGen only, ~47K cycles)
  ./run_tb.sh en   (Encaps only)
  ./run_tb.sh de   (Decaps only)
This commit is contained in:
2026-06-27 02:27:22 +08:00
parent 6721c3c0c1
commit f211dc3c55
6 changed files with 1095 additions and 0 deletions

132
sync_rtl/en/TB/xsim_run.tcl Normal file
View File

@@ -0,0 +1,132 @@
# NOTE: On some systems, you may need:
# export LD_PRELOAD=/usr/lib64/libtinfo.so.5
# before running this script.
# xsim_run.tcl - Vivado xsim compilation and simulation for Encaps-only testbench
#
# Compiles ALL RTL dependencies for mlkem_top plus the Encaps-only testbench.
# Run from the project root: ~/Dev/mlkem/
#
# Prerequisites:
# source /opt/Xilinx/Vivado/2019.2/settings64.sh
#
# Usage:
# vivado -mode batch -source sync_rtl/en/TB/xsim_run.tcl
# ================================================================
# Configuration
# ================================================================
set COMMON_DIR sync_rtl/common
set SHA3_DIR sync_rtl/sha3
set SHA3C_DIR sync_rtl/sha3_chain
set RNG_DIR sync_rtl/rng
set NTT_DIR sync_rtl/ntt
set PA_DIR sync_rtl/poly_arith
set PM_DIR sync_rtl/poly_mul
set CBD_DIR sync_rtl/sample_cbd
set SNT_DIR sync_rtl/sample_ntt
set CD_DIR sync_rtl/comp_decomp
set MA_DIR sync_rtl/mod_add
set STOR_DIR sync_rtl/storage
set TOP_DIR sync_rtl/top
set TB_DIR sync_rtl/en/TB
# ================================================================
# Step 1: Compile common infrastructure
# ================================================================
puts "=== Compiling common infrastructure ==="
xvlog -sv -i . ${COMMON_DIR}/pipeline_reg.v
xvlog -sv -i . ${COMMON_DIR}/skid_buffer.v
# ================================================================
# Step 2: Compile SHA3 / Keccak core
# ================================================================
puts "=== Compiling SHA3/Keccak core ==="
xvlog -sv ${SHA3_DIR}/keccak_round.v
xvlog -sv ${SHA3_DIR}/keccak_core.v
xvlog -sv -i . ${SHA3_DIR}/sha3_top.v
# ================================================================
# Step 3: Compile SHA3 chain (G function)
# ================================================================
puts "=== Compiling SHA3 chain ==="
xvlog -sv -i . ${SHA3C_DIR}/sha3_chain_top_shared.v
# ================================================================
# Step 4: Compile RNG
# ================================================================
puts "=== Compiling RNG ==="
xvlog -sv ${RNG_DIR}/rng_sync.v
# ================================================================
# Step 5: Compile NTT core and dependencies
# ================================================================
puts "=== Compiling NTT core ==="
xvlog -sv ${NTT_DIR}/zeta_rom.v
xvlog -sv ${NTT_DIR}/barrett_mul.v
xvlog -sv ${NTT_DIR}/butterfly_unit.v
xvlog -sv -i . ${NTT_DIR}/ntt_core.v
# ================================================================
# Step 6: Compile polynomial arithmetic
# ================================================================
puts "=== Compiling polynomial arithmetic ==="
xvlog -sv ${PA_DIR}/poly_arith_sync.v
# ================================================================
# Step 7: Compile polynomial multiplication
# ================================================================
puts "=== Compiling polynomial multiplication ==="
xvlog -sv ${PM_DIR}/poly_mul_zeta_rom.v
xvlog -sv ${PM_DIR}/basecase_mul.v
xvlog -sv -i . ${PM_DIR}/poly_mul_sync.v
# ================================================================
# Step 8: Compile sampling modules
# ================================================================
puts "=== Compiling sampling modules ==="
xvlog -sv -i . ${CBD_DIR}/sample_cbd_sync_shared.v
xvlog -sv -i . ${SNT_DIR}/sample_ntt_sync_shared.v
# ================================================================
# Step 9: Compile compression and modular arithmetic
# ================================================================
puts "=== Compiling compression and modular arithmetic ==="
xvlog -sv ${CD_DIR}/comp_decomp_sync.v
xvlog -sv ${MA_DIR}/mod_add_sync.v
# ================================================================
# Step 10: Compile storage (BRAM)
# ================================================================
puts "=== Compiling storage BRAMs ==="
xvlog -sv ${STOR_DIR}/s_bram.v
xvlog -sv ${STOR_DIR}/sd_bram.v
# ================================================================
# Step 11: Compile top-level integration
# ================================================================
puts "=== Compiling top-level integration ==="
xvlog -sv -i . ${TOP_DIR}/keccak_arbiter.v
xvlog -sv -i . ${TOP_DIR}/mlkem_top.v
# ================================================================
# Step 12: Compile testbench
# ================================================================
puts "=== Compiling Encaps-only testbench ==="
xvlog -sv ${TB_DIR}/tb_en_xsim.v
# ================================================================
# Step 13: Elaborate snapshot (xelab)
# ================================================================
puts "=== Elaborating snapshot ==="
xelab tb_en_xsim -s tb_en_xsim --timescale 1ns/1ps
# ================================================================
# Step 14: Run simulation
# ================================================================
puts ""
puts "=== Running Encaps-only simulation ==="
xsim tb_en_xsim -R
puts ""
puts "=== Encaps simulation complete ==="