- 184.108.40.206. Reducing Opening a Project, Creating Design Partitions, andPerforming an Initial Compilation
- 220.127.116.11. Specifying a Destination Library Name in the Intel® Quartus® Prime Settings File or with Tcl
18.104.22.168. Manually Specifying Enumerated Types Using the enum_encoding Attribute
Specifying an Arbitrary User Encoding for Enumerated Type
By default, the Intel® Quartus® Prime software one-hot encodes all enumerated types you defined. With the enum_encoding attribute, you can specify the logic encoding for an enumerated type and override the default one-hot encoding to improve the logic efficiency.
To use the enum_encoding attribute in a VHDL design file, associate the attribute with the enumeration type whose encoding you want to control. The enum_encoding attribute must follow the enumeration type definition, but precede its use. In addition, the attribute value should be a string literal that specifies either an arbitrary user encoding or an encoding style of "default", "sequential", "gray", "johnson", or "one-hot".
An arbitrary user encoding consists of a space-delimited list of encodings. The list must contain as many encodings as the number of enumeration literals in your enumeration type. In addition, the encodings should have the same length, and each encoding must consist solely of values from the std_ulogic type declared by the std_logic_1164 package in the IEEE library.
In this example, the enum_encoding attribute specifies an arbitrary user encoding for the enumeration type fruit.
type fruit is (apple, orange, pear, mango); attribute enum_encoding : string; attribute enum_encoding of fruit : type is "11 01 10 00";
Encoded Enumeration Literals
This example shows the encoded enumeration literals:
apple = "11" orange = "01" pear = "10" mango = "00"
Specifying the “gray” Encoding Style or Enumeration Type
Altera recommends that you specify an encoding style, rather than a manual user encoding, especially when the enumeration type has a large number of enumeration literals. The Intel® Quartus® Prime software can implement Enumeration Types with the different encoding styles, as shown in this table.
|Attribute Value||Enumeration Types|
|"default"||Use an encoding based on the number of enumeration literals in the enumeration type. If the number of literals are fewer than five, use the "sequential" encoding. If the number of literals are more than five, but fewer than 50 literals, use a "one-hot" encoding. Otherwise, use a "gray" encoding.|
|"sequential"||Use a binary encoding in which the first enumeration literal in the enumeration type has encoding 0 and the second 1.|
|"gray"||Use an encoding in which the encodings for adjacent enumeration literals differ by exactly one bit. An N-bit gray code can represent 2N values.|
|"johnson"||Use an encoding similar to a gray code. An N-bit Johnson code can represent at most 2N states, but requires less logic than a gray encoding.|
|"one-hot"||The default encoding style requiring N bits, in which N is the number of enumeration literals in the enumeration type.|
In Specifying an Arbitrary User Encoding for Enumerated Type, the enum_encoding attribute manually specified a gray encoding for the enumeration type fruit. You can also concisely write this example by specifying the "gray" encoding style instead of a manual encoding, as shown in the following example:
type fruit is (apple, orange, pear, mango); attribute enum_encoding : string; attribute enum_encoding of fruit : type is "gray";
Did you find the information on this page useful?