enum_encoding VHDL Synthesis Attribute


A VHDL synthesis attribute that specifies the logic encoding for an Enumeration Type. By default, the Quartus II software "one-hot" encodes all user-defined Enumeration Types. With this attribute, you can override this default "one-hot" encoding to improve the efficiency of the logic Quartus II synthesizes for your Enumeration Type.


Note: If an Enumeration Type represents the states of a state machine, using the enum_encoding attribute to specify a manual state encoding prevents the Compiler from recognizing state machines based on the Enumeration Type. Instead, the Compiler processes these state machines as "regular" logic using the encoding specified by the attribute, and they are not listed as state machines in the Report window for the project. If you wish to control the encoding for a recognized state machine, use the State Machine Processing logic option or the syn_encoding attribute. For more information on properly implementing state machines in VHDL, refer to Implementing State Machines.


To use the enum_encoding attribute in a VHDL Design File (.vhd), first declare the attribute with a string type using an Attribute Declaration. Then, associate the attribute with the Enumeration Type whose encoding you wish to control. The enum_encoding attribute must follow the Enumeration Type Definition but precede its use. In addition, the attribute value must 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 there are enumeration literals in your Enumeration Type. In addition, the encodings must all 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. For example, in the following code fragment, 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";

In this example, the enumeration literals are encoded as follows:

apple   = "11"
orange  = "01"
pear    = "10"
mango   = "00"

Sometimes you wish to specify an encoding style, rather than a manual user encoding, especially when the Enumeration Type has a large number of enumeration literals. The Quartus II software can implement Enumeration Types with four different encoding styles:

Observe that in the previous example, the enum_encoding attribute manually specified a "gray" encoding for the Enumeration Type fruit. This example could be written more concisely by specifying the "gray" encoding style instead of a manual encoding:

type fruit is (apple, orange, pear, mango);
attribute enum_encoding : string;
attribute enum_encoding of fruit : type is "gray";



Rate This Page