r/chipdesign • • 4d ago

Avoid impure SystemVerilog functions: simulation/synthesis mismatches and a Vivado synthesis bug

SystemVerilog impure functions, which read a variable they weren't passed, are legal and look harmless. In practice they're a surprising mess: simulation can disagree with synthesis, and synthesis can get it wrong.

  • Icarus Verilog: matches the spec ✅ disagrees with synthesis ❌
  • Verilator: disagrees with the spec ❌ matches synthesis ✅
  • Vivado synthesis: wrong netlist for more complicated cases 🐞 (confirmed by AMD; change request filed)

The fix: Avoid them.

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

0 Upvotes

1 comment sorted by

1

u/alexforencich 4d ago

Who uses functions in synthesizable code in the first place?