Coding For Synthesis
Coding For Synthesis
module regwrite (
ctrl[3]
ctrl[2]
input reg rout,
ctrl[1]
input clk,
ctrl[0]
input [3:0] in,
in[3]
input [3:0] ctrl);
in[2]
SET
always @(posedge clk)
in[1]
Lowest priority
in[0]
D Q
rout if (ctrl[0]) rout<= in[0];
else if (ctrl[1]) rout<= in[1];
CLR Q
else if (ctrl[2]) rout<= in[2];
Highest priority
else if (ctrl[3]) rout<= in[3];
endmodule
- A bit will only be used to select the priority mux if all bits a head of it
(LSBs) are not set.
- If/else decisions should only be used when the decision tree has a
priority encoding.
D3
E3
SET
always @(posedge clk)
D Q rout
case(1)
in[2] D2
Priority E2
Logic in[1] D1 ctrl[0]: rout <= in[0];
in[0]
E1
D0
CLR Q ctrl[1]: rout <= in[1];
E0 ctrl[2]: rout <= in[2];
ctrl[3]: rout <= in[3];
endcase
endmodule
- Case structures used in circumstances where all conditions are
mutually exclusive.
- VHDL infers the parallel decision tree for ”case” statement.
- Verilog infers ”case” statement as a priority statement.
Navid Lashkarian, Ph.D. Verilog 4/21/2006 3 / 15
Decision Trees
Synthesis Directive
Inferring Latches
- The synthesis directive synopsis full case removes the latches for
missing case items.
- One of the most common ways to infer latch is to make assignments
to multiple outputs from a single case statement but neglect to assign
all outputs for each case item. Even adding the full case directive
to this type of case statement will NOT eliminate latches.