Reply To: OSVVM 2015.03 problem pure function GenRandSeed calls impure procedure Alert
Why OSVVM™? › Forums › OSVVM › OSVVM 2015.03 problem pure function GenRandSeed calls impure procedure Alert › Reply To: OSVVM 2015.03 problem pure function GenRandSeed calls impure procedure Alert
Unfortunately VHDL already breaks referential transparency of pure functions by allowing reports in them. Still compilers might be able to optimize pure functions which do not contain any report statements or calls to other pure function containing report statements.
Consider the following code:
entity test is
architecture a of test is
function expensive_function_returning_false return boolean is
report “This cost much”;
main : process
assert (not (expensive_function_returning_false or expensive_function_returning_false));
This cannot and is not optimized by at least Modelsim and GHDL.
Modelsim outputs this “This cost much” twice as does GHDL. NVC which is another open source VHDL simulator will print nothing. It is likely it performs a static constant folding removing the assert entirely falsely believing it can optimize pure functions in this way.
It is not easy to determine if GHDL or Modelsim would have performed constant folding and optimized away the assert if there were no report statement without deep knowledge of their binary formats and a binary viewer.