Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17042 Discussions

How do I infer dffe instead of mux

Altera_Forum
Honored Contributor II
2,069 Views

Hi, 

I am having a problem getting quartus to synthesize part of my design as a dffe register when the output of the register is fed to another module.  

If I run the following code (without a sub-module) through analysis & synthesis, and then view the results in the RTL viewer, the result is a dffe as expect: 

 

module dffe_test ( input wire clk, input wire ctrl, input wire dat, output wire result ); reg dat_r; always @ ( posedge clk ) begin if ( ctrl ) begin dat_r <= dat; end end assign result = { &dat_r }; endmodule 

 

 

However, the following code uses muxes and a dff is less efficient: 

 

module dffe_test ( input wire clk, input wire ctrl, input wire dat, output wire result ); reg dat_r; always @ ( posedge clk ) begin if ( ctrl ) begin dat_r <= dat; end end widget widget_inst ( .clk ( clk ), .dat ( { dat_r } ), .result( result ) ); endmodule 

 

 

 

I have attached a screenshot of the TRL viewer output for both examples. 

 

How do I get the second example to use a dffe for register dat_r ?
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
1,058 Views

Hard to answer this without seeing the definition of widget.

0 Kudos
Altera_Forum
Honored Contributor II
1,058 Views

Widget is just an and gate: 

 

module widget ( input wire clk, input wire dat, output wire result ); assign result = { &dat }; endmodule
0 Kudos
Altera_Forum
Honored Contributor II
1,058 Views

It's just the RTL viewer being less than brilliant. You basically should be inferring a clock enable - from the if statement, but sometimes the RTL viewer misses this is instead draws a mux to make the clock enable. In reality due to the way logic blocks are structured it probably wouldn't make any performance difference, and when the fitter runs it will probably optimise to a clock enable. 

 

A better thing to look at would be the technology viewer, that will show how it is actually implemented.
0 Kudos
Altera_Forum
Honored Contributor II
1,058 Views

Thanks tcworld, you are right, the technology map viewer does show that is has not used any muxes. 

 

https://www.alteraforum.com/forum/attachment.php?attachmentid=10890  

 

But in a complex design it is not very human readable. :-( 

 

I recently taught myself Verilog after many years of using schematic entry, so I have been using the RLT viewer to check my coding to ensure it produced an efficient design. 

But then I wasn’t seeing what I expected and thought my coding was at fault. 

 

Thanks for your help.
0 Kudos
Altera_Forum
Honored Contributor II
1,058 Views

To make it most readable, you can create a module for a D-Flip-Flop which has clock, data, enable, and reset inputs. Then just use this module in place of the always block. In the RTL viewer you will then see it as a box. You can also add parameters to control the width of the data and output signals which would make it useful for wide buses as well as single bits. 

 

As the designs get larger and more complicated, the RTL viewer starts to be less and less helpful (it's good for some things, but other stuff gets obfuscated).
0 Kudos
Reply