Files
mlkem-sync/run_enc.sh
FallenSigh 4fee8bded3 fix(enc): compile comp_decomp_sync + pipeline_reg in KeyGen tcl
mlkem_top now instantiates comp_decomp_sync (E5), so the shared
xsim_run.tcl must compile it (+ its pipeline_reg dep) before mlkem_top.
This unbreaks 'run_tb.sh top' which failed elaboration with
'Module comp_decomp_sync not found'. run_enc.sh simplified to reuse the
tcl's now-complete compile list (drops its duplicate leaf block).
2026-06-29 03:06:11 +08:00

45 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# run_enc.sh - Run Vivado XSIM for the ML-KEM Encaps testbench (tb_mlkem_enc_katK).
#
# Usage: ./run_enc.sh [K] [CASE]
# ./run_enc.sh # K=2 CASE=0
# ./run_enc.sh 3 1 # K=3 CASE=1
#
# Compiles the same RTL as the KeyGen tcl (mlkem_top + leaves), elaborates the
# encaps TB for the requested K, and runs the requested CASE.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
VIVADO_SETTINGS="/opt/Xilinx/Vivado/2019.2/settings64.sh"
SEL_K="${1:-2}"
SEL_CASE="${2:-0}"
source "$VIVADO_SETTINGS"
export LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}/usr/lib64/libtinfo.so.5"
cd "$SCRIPT_DIR"
rm -rf xsim.dir .Xil
# Compile every xvlog RTL line from the KeyGen tcl (same datapath, now incl.
# pipeline_reg + comp_decomp_sync + mlkem_top), skipping only the KeyGen TB.
TCL="sync_rtl/top/TB/xsim_run.tcl"
while read -r cmd; do
[[ "$cmd" == *tb_mlkem_kg_katK* ]] && continue # skip the KeyGen TB
echo " $cmd"
eval "$cmd" || { echo "COMPILE FAILED: $cmd"; exit 1; }
done < <(grep -E '^xvlog ' "$TCL")
# Compile the encaps TB
echo " xvlog -sv --relax sync_rtl/top/TB/tb_mlkem_enc_katK_xsim.v"
xvlog -sv --relax sync_rtl/top/TB/tb_mlkem_enc_katK_xsim.v \
|| { echo "TB COMPILE FAILED"; exit 1; }
echo " xelab tb_mlkem_enc_katK_xsim -generic_top KP=$SEL_K -s mlkem_enc_k$SEL_K --timescale 1ns/1ps"
xelab tb_mlkem_enc_katK_xsim -generic_top KP=$SEL_K -s mlkem_enc_k$SEL_K --timescale 1ns/1ps \
|| { echo "ELAB FAILED for K=$SEL_K"; exit 1; }
LOG="/tmp/run_enc_k${SEL_K}_c${SEL_CASE}.log"
echo " xsim mlkem_enc_k$SEL_K -R -testplusarg CASE=$SEL_CASE"
xsim "mlkem_enc_k$SEL_K" -R -testplusarg "CASE=$SEL_CASE" 2>&1 | tee "$LOG"