syn_encoding VHDL Synthesis Attribute
A VHDL synthesis attribute that specifies encodings for the
states modeled by an enumeration type. The attribute takes a string
value that consists of an encoding style, such as "sequential"
or
"one-hot"
, or a
space-separated list of bit strings to be used as an encoding. It
can also take the value "safe"
, which
directs the
Quartus® Prime software to add extra logic to recover
from illegal states. You may combine the "safe"
value
with an encoding style by separating the values with a comma, for
example, "safe,
one-hot"
.
syn_encoding
synthesis attribute is not the same as the
enum_encoding
synthesis attribute, which should be used to specify
encodings for enumeration types that do not represent the states of a state
machine.
To use the syn_encoding
attribute in a VHDL Design File (.vhd) Definition,
you must first declare the attribute in the local scope or import
its declaration from the altera_syn_attributes package in the
altera library. You can
then use the attribute specification to associate the attribute
with an enumeration type. The syn_encoding
attribute must follow the enumeration type definition but precede
its use.
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, the syn_encoding
attribute specifies an arbitrary user encoding for the enumeration
type state_t
in the
following code sample:
type state_t
is (S0, S1, S2, S3);
attribute syn_encoding : string;
attribute syn_encoding of state_t : type is "11 01 10
00";
In this example, the states are encoded as follows:
S0
= "11"
S1 = "01"
S2 = "10"
S3 = "00"
If an enumeration type has a large number of states, it may be cumbersome to specify manual encodings for all states. For convenience, the Quartus® Prime software accepts six encoding styles:
"
default
"
— Choose an encoding based on the number of states in the enumeration type. If there are fewer than five states, use the"sequential"
encoding. If there are more than five but fewer than 50 states, use a"one-hot"
encoding. Otherwise, use a"gray"
encoding."
one-hot
"
— The default encoding style requiring N bits, where N is the number of states in the enumeration type."
sequential
"
— Use a binary encoding in which the first state in the enumeration type has encoding 0, the second 1, and so on."gray"
— Use an M-bit encoding in which the encodings for adjacent states differ by exactly one bit. An M-bit"gray"
code can represent 2M states."
johnson
"
—Use an M-bit encoding in which the encodings for adjacent states differ by exactly one bit. An M-bit"johnson"
code can represent at most 2 times M states but requires less logic than a"gray"
encoding."
compact
"
— Use an encoding with fewest bits.
In the previous example, the syn_encoding
attribute manually specified a "gray"
encoding
for the enumeration type state_t
. This
example could be written more concisely by specifying the
"gray"
encoding
style instead of a manual encoding:
type state_t is (apple, orange, pear, mango); attribute syn_encoding : string; attribute syn_encoding of state_t : type is "gray";
The
keyword "safe"
indicates that the
Quartus® Prime software should insert extra
logic to detect an illegal state (an unreachable state) and force
the state machine into the reset state. You cannot implement a safe
state machine by specifying manual recovery logic in your HDL
source; the
Quartus® Prime software eliminates this logic while
optimizing your design.
-- The "safe" option can be used alone attribute syn_encoding of state_t : type is "safe"; -- or with an encoding style attribute syn_encoding of state_t : type is "sequential, safe";