# 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 KeyGen-only testbench # # Compiles ALL RTL dependencies for mlkem_top plus the KeyGen-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/kg/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/kg/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 KeyGen-only testbench ===" xvlog -sv ${TB_DIR}/tb_kg_xsim.v # ================================================================ # Step 13: Elaborate snapshot (xelab) # ================================================================ puts "=== Elaborating snapshot ===" xelab tb_kg_xsim -s tb_kg_xsim --timescale 1ns/1ps # ================================================================ # Step 14: Run simulation # ================================================================ puts "" puts "=== Running KeyGen-only simulation ===" xsim tb_kg_xsim -R puts "" puts "=== KeyGen simulation complete ==="