r/FPGA • u/CardiologistOk3345 • 4d ago
Avoid impure SystemVerilog functions: simulation/synthesis mismatches and a Vivado synthesis bug
A function that reads a module-scope variable instead of taking it as an argument is legal SystemVerilog, but tools handle it inconsistently:
always_combre-evaluates when the hidden variable changes;always @*andassigndon't. In Icarus they stay stale, while Verilator matches the hardware.- Vivado 2025.1 synthesis drops the hidden input at the first of two call sites when the function is nested. AMD reproduced it in 2025.x and 2026.x and is filing a CR.
- Yosys 0.33 and 0.71 synthesize it correctly (checked by simulation and a formal equivalence proof).
Write-up: https://samehgalal.substack.com/p/systemverilog-keep-your-functions
Reproducer and Yosys cross-check: https://github.com/Tensorica/sv-impure-func
Run it in the browser: https://www.edaplayground.com/x/ssqh
4
Upvotes