Map Subprogram Generics on call

Proposal Editing Information

  • Who Updates: OPEN, JimLewis
  • Date Proposed: 2012-08-17
  • Date Last Updated: 2012-08-17
  • Priority:
  • Complexity:
  • Focus: Testbench


Generics on a subprogram require a subprogram instance before usage. For some subprograms that are called only infrequently this is inconvenient.

Suggested during 2012_MeetingJuly19

Related and/or Competing Issues: Yes

Anonymous types on subprograms - this could be an alternative to it.

Proposal Details


function Mux4
    generic ( type DataType ) 
    parameter (
      MuxSel :   in std_logic_vector(1 downto 0) ; 
      A, B, C, D :  in DataType
   ) return DataType is 
   . . . 
   end procedure Mux4; 

Usage of the function:

Mux4 generic map (integer) (MuxSel, D1, D2, D3, D4) ; 


General Comments

<Brent Hayhoe> 2014-03-27 - I think that this is a good idea, just slightly concerned that the usage syntax might seem a bit messy. Perhaps this might be a little clearer:

generic map (integer) Mux4 (MuxSel, D1, D2, D3, D4) ; 

It seems slightly more like a normal function call (to me). </Brent Hayhoe>

LievenLemiengre - 2016-03-11 - It is tricky to make this work with the type checker & overload resolution but it can be done. I don't like 'generic map' in expressions so I suggest you drop it completely.

  result := Mux4(integer)(MuxSel, D1, D2, D3, D4);
  result := Mux4(bit_vector)(MuxSel, D1, D2, D3, D4)(1); -- mux4, specialized for bit_vector, invoke it, take an element out of the array
  result := Mux4(integer)(MuxSelA, D1, D2, D3, D4) + Mux4(integer)(MuxSelB, D1, D2, D3, D4)


-- Brent Hayhoe - 2014-03-27

-- JimLewis - 2014-12-03

Add your signature here to indicate your support for the proposal

Topic revision: r5 - 2020-02-17 - 15:34:35 - JimLewis
Copyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback