Skip to content

VHDL · Chapter 12.5 · Generics

Constant and Type Generics

A generic does not have to be an integer width. Most usefully, a constant generic of a richer type carries configuration, such as a reset value as a vector, a boolean mode flag that selects behaviour, real filter coefficients, or even a whole configuration record bundling many settings into one generic. VHDL-2008 also adds type generics, a generic that is itself a type, so a single FIFO, register, or pipeline can be parameterized over its element type and reused for a vector, a record, or any type the user supplies. Together these turn generics from a simple width knob into a full configuration interface for a component. This lesson covers constant generics of arbitrary types and the 2008 type generics, broadening parameterization from size alone into configuration and type.

Foundation14 min readVHDLGenericsType GenericsConfigurationVHDL-2008Reuse

1. Engineering intuition — configuration, not just size

Width is only one thing you want to vary per instance. You also want to set a block's reset value, choose between modes (registered or not, MSB- or LSB-first), supply coefficients, or pick the type of data it carries. All of these are per-instance configuration, and all of them can be generics. A generic can be any constant — a vector, a boolean, a real, an array, a record — and in VHDL-2008 it can even be a type. So the right way to think about generics is as a component's configuration interface: every setting that should be fixed at build time, exposed as a generic, set once at instantiation.

2. Formal explanation — constant generics of any type, and type generics

rich_generics.vhd
Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
-- CONSTANT generics of richer types carry configuration, not just size.
entity reg is
  generic ( WIDTH       : positive := 8;
            RESET_VALUE : std_logic_vector;              -- a vector constant (init value)
            REG_OUT     : boolean := true;               -- a mode flag
            GAIN        : real := 1.0 );                 -- a real coefficient (sim/models)
  port ( clk, rst : in std_logic;
         d : in  std_logic_vector(WIDTH-1 downto 0);
         q : out std_logic_vector(WIDTH-1 downto 0) );
end entity;
 
-- A whole CONFIG RECORD as one generic (bundle many settings):
--   type cfg_t is record width : positive; use_reg : boolean; ... end record;
--   generic ( CFG : cfg_t );
 
-- VHDL-2008 TYPE generic: parameterize over the ELEMENT TYPE itself.
entity fifo is
  generic ( type element_t;                              -- the data type is a parameter (2008)
            DEPTH : positive := 16 );
  port ( clk : in std_logic; din : in element_t; dout : out element_t );
end entity;

A constant generic may be of any type — std_logic_vector, boolean, real, arrays, records — letting one generic carry a reset value, a mode, coefficients, or a bundled configuration. A type generic (VHDL-2008) makes the type a parameter, so the entity is generic over the kind of data it handles.

3. Production usage — a reset value, a mode, and a type-generic FIFO

config_in_use.vhd
Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
-- Constant generics configure behaviour per instance.
u_ctrl : entity work.reg
  generic map ( WIDTH => 8, RESET_VALUE => x"FF", REG_OUT => false )   -- preset reset + mode
  port map ( clk => clk, rst => rst, d => d, q => q );
 
-- Inside reg: use the configuration generics directly.
--   if rst = '1' then q <= RESET_VALUE;            -- the per-instance reset value
--   gen: if REG_OUT generate ...                   -- mode chooses structure (12.4)
 
-- VHDL-2008 type-generic FIFO reused for different element types:
u_bytes : entity work.fifo generic map ( element_t => std_logic_vector(7 downto 0), DEPTH => 32 )
                           port map ( /* ... */ );
u_txn   : entity work.fifo generic map ( element_t => transaction_t, DEPTH => 8 )  -- same FIFO, record type
                           port map ( /* ... */ );

What hardware does this become? Constant generics fold into the design at elaboration: RESET_VALUE => x"FF" makes the reset logic load 0xFF, REG_OUT => false (with an if-generate) drops the output register. A type-generic FIFO elaborates to storage sized for whatever element_t resolves to — bytes in one instance, a record in another — the same control logic over different element widths. So rich generics configure both the constants baked into logic and, with type generics, the very type of the data path.

4. Structural interpretation — generics as a configuration interface

generics carrying configuration: constant generics and a type generic feeding one entityconfigureparameterize typeconstant genericsRESET_VALUE, MODE,coefficients, config recordtype generic (2008)element_t — data type as aparameterconfigurable entityone source, manyconfigurations12
Generics form a component's configuration interface, well beyond integer widths. Constant generics of richer types carry a reset value (std_logic_vector), a mode flag (boolean), coefficients (real), or a bundled config record. A VHDL-2008 type generic makes the element type itself a parameter, so one FIFO or register serves std_logic_vector, a record, or any supplied type. All are set per instance and resolved at elaboration into concrete configured hardware. This is a configuration structure — what settings parameterize the entity — captured by a diagram rather than a waveform.

5. Why this is structural, not timing

Constant and type generics are configuration fixed at elaboration, like all generics — they set reset values, modes, coefficients, and even the data type before any hardware runs — so a configuration diagram, not a waveform, captures them. The resulting circuit then behaves like the concrete, configured design it produces (a register that resets to 0xFF, a FIFO of records), with timing you have already seen. Nothing here varies during operation; the richness is in what can be parameterized, which is a static, structural property.

6. Debugging example — the unconstrained or mismatched generic

Expected: a configured component (right reset value, right element type). Observed: a type mismatch on a generic value, an unconstrained std_logic_vector generic whose width is unclear, or (pre-2008) a tool rejecting a type generic. Root cause: a constant generic was given a value of the wrong type or wrong width (e.g. RESET_VALUE not matching WIDTH), an unconstrained generic was not pinned to a concrete width at instantiation, or type generics were used on a tool/standard set to an older VHDL revision. Fix: match each generic value's type/width to its declaration (size RESET_VALUE to WIDTH), constrain generics where needed, and ensure VHDL-2008 is enabled before using type generics. Engineering takeaway: rich generics still obey type/width rules — match the value to the generic, pin unconstrained sizes, and enable VHDL-2008 for type generics.

match_the_generic.vhd
Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
-- BUG: reset value width doesn't match WIDTH.
-- generic map (WIDTH => 8, RESET_VALUE => x"FFFF")   -- 16-bit value for an 8-bit reg
-- FIX: size the constant generic to the configured width.
generic map (WIDTH => 8, RESET_VALUE => x"FF")        -- 8-bit value matches WIDTH=8

7. Common mistakes & what to watch for

  • Mismatched constant-generic type/width. A std_logic_vector generic must match the configured width; size RESET_VALUE to WIDTH.
  • Unconstrained generics left unpinned. An unconstrained vector/array generic needs its size fixed at instantiation.
  • Using type generics without VHDL-2008. Type generics are a 2008 feature; enable it or fall back to per-type entities.
  • Overstuffing a config record. Bundle genuinely related settings; do not hide unrelated knobs in one record generic.
  • real generics in synthesizable paths. real coefficients suit models/sim; for synthesis, quantize to fixed-point/integer generics.

8. Engineering insight & continuity

Generics are a full configuration interface, not just a width knob: constant generics of any type carry reset values, mode flags, coefficients, and bundled config records, while VHDL-2008 type generics parameterize the entity over its data type — so one source serves many configurations and many element types. With size, structure, configuration, and type all parameterizable, you have the complete toolkit to build truly reusable blocks. The next lessons apply it to the canonical reusable components: Parameterized Memories and FIFOs — storage whose width, depth, and behaviour are all generics.