I recently added support for VHDL-2008 generic subprograms to NVC. As far as I know it’s the first open source VHDL simulator to support them and allows you to write type-generic functions and procedures like this:
function fact generic (type t; function "*"(l, r : t) return t is <>; function "-"(l, r : t) return t is <>; function "<"(l, r : t) return boolean is <>; one : t) (n : t) return t is begin if n < one then return one; else return n * fact(n - one); end if; end function;
And then make concrete instances of the generic function:
function fact_int is new fact generic map (t => integer, one => 1); function fact_real is new fact generic map (t => real, one => 1.0);
The is <>
syntax in the declaration above picks up the default *
, -
, and <
operators for that type from the context so there’s no need to specify them in the generic map.
assert fact_int(5) = 120; assert fact_real(4.0) = 24.0;