TWiki
>
P1076 Web
>
Vhdl2019CollectedRequirements
>
AnonymousTypes
(2020-02-17,
JimLewis
)
(raw view)
E
dit
A
ttach
---+ Anonymous Types on Interfaces %TOC% ---++ Proposal Editing Information * Who Updates: Main.JimLewis, <Add YourName >, ... * Date Proposed: 2012-08-18 * Date Last Updated: 2012-08-18 * Priority: * Complexity: * Focus: Testbench ---++ Requirement Summary Currently interfaces (subprograms and entities) allow unconstrained arrays on interfaces. Anonymous types generalize this capability for interfaces where knowing the type is not important. ---++ Related and/or Competing Issues: None ---++ Current Status With a formal generic type on the interface of a subprogram, we can do the following: <verbatim>function Mux4Gen generic (type AType) ; parameter ( Sel : std_logic_vector (1 downto 0) ; A, B, C, D : AType ) return AType is variable X : A'Subtype ; -- value = AType'left begin case Sel is when "00" => X := A ; when "01" => X := B ; when "10" => X := C ; when "11" => X := D ; when others => null ; end case ; return X ; end function Mux4Gen ; </verbatim> To use the subprogram, we first must create a subprogram instance, and then we can call it: <verbatim> architecture a of e is function Mux4 is new Mux4Gen generic map (AType => std_logic_vector) ; signal S : std_logic_vector(1 downto 0) ; signal Y, A1, A2, A3, A4 : std_logic_vector(7 downto 0) ; begin Y <= Mux4(S, A1, A2, A3, A4) ; ....</verbatim> ---++ Use Model 1: Mux4 The idea behind anonymous types is to simplify this process. <verbatim>function Mux4 parameter ( Sel : std_logic_vector (1 downto 0) ; A, B, C, D : anonymous -- restriction all must be same subtype ) return A'Subtype is variable X : A'Subtype ; begin case Sel is when "00" => X := A ; when "01" => X := B ; when "10" => X := C ; when "11" => X := D ; when others => null ; -- result := A'SubType'initial ; end case ; return X ; end function Mux4 ; </verbatim> The subtype is determined when the subprogram is called (elaborated): <verbatim> architecture a of e is signal S : std_logic_vector(1 downto 0) ; signal Y, A1, A2, A3, A4 : std_logic_vector(7 downto 0) ; begin Y <= Mux4(S, A1, A2, A3, A4) ; ....</verbatim> An alternative to declaring anonymous parameters together - A, B, C, D above - is to use 'Subtype in a interface list: <verbatim>function Mux4 parameter ( Sel : std_logic_vector (1 downto 0) ; A : anonymous ; B, C, D : A'Subtype -- making B,C,D same subtype as A ) return A'Subtype is variable X : A'Subtype ; begin</verbatim> ---++ Use Model 2: Condition A condition operation for all types whose first parameter is boolean could be defined as follows: <verbatim>function condition ( cond : boolean ; A : anonymous ; B : A'Subtype ) return A'Subtype is begin -- return A when Cond else B ; if cond then return A ; else return B ; end if ; end function condition ; --Usage in a declaration: constant a : integer := condition (FAST_SIM, 100, 10000) ;</verbatim> ---++ Questions Does the type need to be visible to the package that defines the subprogram? For anonymous types to be useful, the type would not necessarily be known to the package, but instead is only known at the point of the call. Alternately stated, for this to be a library package, the package would not necessarily be able to see new types defined by the project. - How does one perform type checking? Losing type checking on function calls would not seem to be the way that VHDL does things. - If this proposal is accepted, then would there be any need to define data types for any of the parameters? - Function overloading might be another casualty. "A, B, C, D : anonymous" just says that there are four parameters and each can be any type whatsoever, but one might want different behavior based on the parameters having different types. "A : anonymous ; B, C, D : A'Subtype" (currently not legal, but addressed by proposal [[http://www.eda-twiki.org/cgi-bin/view.cgi/P1076/OrderingAllInterfaceLists][<b>OrderingAllInterfaceLists</b>]] at least constrains the four parameters to be the same type. This might be safe enough to allow since it is probably not likely that current function overloads are performing anything any differently, just using a different data types. -- Main.KevinJennings - 2016-10-12 ---++ Proposal ---++ General Comments This is useful for RTL, not just for testbenches. -- Main.JonnyDoin - 2013-01-03 This appears to the address same issue as [[P1076.MapSubprogramGenericOnCall][Map Subprogram Generics on Call]]. -- Main.ErnstChristen - 2015-01-27 ---++ Supporters -- Main.MartinThompson - 2012-09-14 -- [[Main.BrentHahoe][Brent Hayhoe]] - 2012-10-09 -- Main.JonnyDoin - 2013-01-03 -- Main.KevinJennings - 2013-04-04 -- Main.DanielKho - 2013-09-10 -- Main.MortenZilmer - 2014-01-27 _Add your signature here to indicate your support for the proposal_</verbatim>
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r13
<
r12
<
r11
<
r10
<
r9
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r13 - 2020-02-17 - 15:34:25 -
JimLewis
P1076
Log In
or
Register
P1076 Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
Webs
Main
P1076
Ballots
LCS2016_080
P10761
P1647
P16661
P1685
P1734
P1735
P1778
P1800
P1801
Sandbox
TWiki
VIP
VerilogAMS
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback