Coding Practices for Combinational and Sequential circuits

This is a discussion on Coding Practices for Combinational and Sequential circuits within the verilog forums in Programming Languages category; Hi, I have been always been taught so and try to strictly follow the practice of splitting my design into combinational and sequential blocks (see example below). However, I have been asked to look at somebody's design at my workplace that does not do so, and I do not know whether I should ignore his style or bring it to the notice of the manager. I am looking for the most convincing explanation as to why the second style is not good. ----------My style---------------------- Sequential --------------- always @(posedge clock) data_out <= data_out_comb; Combinational --------------------- always @(reset_n or data_a or data_b) ...

Go Back   Application Development Forum > Programming Languages > verilog

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 02:32 PM
kb33
Guest
 
Default Coding Practices for Combinational and Sequential circuits

Hi,

I have been always been taught so and try to strictly follow the
practice of splitting my design into combinational and sequential
blocks (see example below). However, I have been asked to look at
somebody's design at my workplace that does not do so, and I do not
know whether I should ignore his style or bring it to the notice of
the manager. I am looking for the most convincing explanation as to
why the second style is not good.

----------My style----------------------

Sequential
---------------

always @(posedge clock)
data_out <= data_out_comb;

Combinational
---------------------

always @(reset_n or data_a or data_b)
if (~reset_n)
data_out_comb = 0;
else
data_out_comb = data_a + data_b;




-------Mixed sequential and combinational design----------------

always @ (posedge clock or negedge reset_n)
begin
if(~reset_n)
data_out <= 0;
else
data_out <= data_a + data_b;
end



P.S The second coding style doesn't even have the signals data_a and
data_b in the sensitivity list.


Thanks
kb33



Reply With Quote
  #2  
Old 08-27-2008, 02:47 PM
Mike Lewis
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits


"kb33" <kanchan.devarakonda@gmail.com> wrote in message
news:148cf446-25ee-40e1-996c-a25671a4dab1@j22g2000hsf.googlegroups.com...
> Hi,
>
> I have been always been taught so and try to strictly follow the
> practice of splitting my design into combinational and sequential
> blocks (see example below). However, I have been asked to look at
> somebody's design at my workplace that does not do so, and I do not
> know whether I should ignore his style or bring it to the notice of
> the manager. I am looking for the most convincing explanation as to
> why the second style is not good.
>
> ----------My style----------------------
>
> Sequential
> ---------------
>
> always @(posedge clock)
> data_out <= data_out_comb;
>
> Combinational
> ---------------------
>
> always @(reset_n or data_a or data_b)
> if (~reset_n)
> data_out_comb = 0;
> else
> data_out_comb = data_a + data_b;
>
>
>
>
> -------Mixed sequential and combinational design----------------
>
> always @ (posedge clock or negedge reset_n)
> begin
> if(~reset_n)
> data_out <= 0;
> else
> data_out <= data_a + data_b;
> end
>
>
>
> P.S The second coding style doesn't even have the signals data_a and
> data_b in the sensitivity list.
>
>
> Thanks
> kb33
>
>
>


There is nothing wrong with either style. They both synthesize, simulate and
read. It is style and there are many different syles that people have. It's
personal preference.

Mike


Reply With Quote
  #3  
Old 08-27-2008, 05:36 PM
jprovidenza@yahoo.com
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

On Aug 27, 11:32*am, kb33 <kanchan.devarako...@gmail.com> wrote:
> Hi,
>
> I have been always been taught so and try to strictly follow the
> practice of splitting my design into combinational and sequential
> blocks (see example below). However, I have been asked to look at
> somebody's design at my workplace that does not do so, and I do not
> know whether I should ignore his style or bring it to the notice of
> the manager. I am looking for the most convincing explanation as to
> why the second style is not good.
>
> ----------My style----------------------
>
> Sequential
> ---------------
>
> always @(posedge clock)
> * *data_out <= data_out_comb;
>
> Combinational
> ---------------------
>
> always @(reset_n or data_a or data_b)
> * *if (~reset_n)
> * * * data_out_comb = 0;
> * *else
> * * * data_out_comb = data_a + data_b;
>
> -------Mixed sequential and combinational design----------------
>
> always @ (posedge clock or negedge reset_n)
> * *begin
> * * * if(~reset_n)
> * * * * *data_out <= 0;
> * * * else
> * * * * *data_out <= data_a + data_b;
> * *end
>
> P.S The second coding style doesn't even have the signals data_a and
> data_b in the sensitivity list.
>
> Thanks
> kb33


There is nothing wrong with the second example. In fact, it is my
preferred
style. More concise, less prone to typos.


John Providenza
Reply With Quote
  #4  
Old 08-28-2008, 12:26 AM
Chris F Clark
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

kb33 <kanchan.devarakonda@gmail.com> writes:

> -------Mixed sequential and combinational design----------------
>
> always @ (posedge clock or negedge reset_n)
> begin
> if(~reset_n)
> data_out <= 0;
> else
> data_out <= data_a + data_b;
> end
>
>
>
> P.S The second coding style doesn't even have the signals data_a and
> data_b in the sensitivity list.


And, it *should not*. The logic is not sensitive to changes in those
signals. It merely samples those signals when the appropriate edges
occur. If you add the data_a or data_b signals to the sensitivity
list, you will get something that doesn't behave properly. It will
change at non edges of the clock and reset signals.

Hope this helps,
Chris
Reply With Quote
  #5  
Old 08-28-2008, 09:37 AM
Andy
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

On Aug 27, 11:26*pm, Chris F Clark <c...@shell01.TheWorld.com> wrote:
> kb33 <kanchan.devarako...@gmail.com> writes:
> > -------Mixed sequential and combinational design----------------

>
> > always @ (posedge clock or negedge reset_n)
> > * *begin
> > * * * if(~reset_n)
> > * * * * *data_out <= 0;
> > * * * else
> > * * * * *data_out <= data_a + data_b;
> > * *end

>
> > P.S The second coding style doesn't even have the signals data_a and
> > data_b in the sensitivity list.

>
> And, it *should not*. *The logic is not sensitive to changes in those
> signals. *It merely samples those signals when the appropriate edges
> occur. *If you add the data_a or data_b signals to the sensitivity
> list, you will get something that doesn't behave properly. *It will
> change at non edges of the clock and reset signals.
>
> Hope this helps,
> Chris


The second style requires half the always blocks, half the signal
declarations, and does not require all of the inputs to be listed in
the sensitivity list.

What's not to like?

Many simulators also merge multiple always blocks with the same
sensitivity lists into one for execution, reducing scheduling
overhead. The second style is more amenable to this optimization,
since only the clock and reset are ever used in the sensitivity lists.
Having a lot of processes in the first style with more or less random
sensitivity lists defeats the optimization.

Andy
Reply With Quote
  #6  
Old 08-28-2008, 10:30 AM
jprovidenza@yahoo.com
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

On Aug 28, 6:37*am, Andy <jonesa...@comcast.net> wrote:
> On Aug 27, 11:26*pm, Chris F Clark <c...@shell01.TheWorld.com> wrote:
>
>
>
> > kb33 <kanchan.devarako...@gmail.com> writes:
> > > -------Mixed sequential and combinational design----------------

>
> > > always @ (posedge clock or negedge reset_n)
> > > * *begin
> > > * * * if(~reset_n)
> > > * * * * *data_out <= 0;
> > > * * * else
> > > * * * * *data_out <= data_a + data_b;
> > > * *end

>
> > > P.S The second coding style doesn't even have the signals data_a and
> > > data_b in the sensitivity list.

>
> > And, it *should not*. *The logic is not sensitive to changes in those
> > signals. *It merely samples those signals when the appropriate edges
> > occur. *If you add the data_a or data_b signals to the sensitivity
> > list, you will get something that doesn't behave properly. *It will
> > change at non edges of the clock and reset signals.

>
> > Hope this helps,
> > Chris

>
> The second style requires half the always blocks, half the signal
> declarations, and does not require all of the inputs to be listed in
> the sensitivity list.
>
> What's not to like?
>
> Many simulators also merge multiple always blocks with the same
> sensitivity lists into one for execution, reducing scheduling
> overhead. The second style is more amenable to this optimization,
> since only the clock and reset are ever used in the sensitivity lists.
> Having a lot of processes in the first style with more or less random
> sensitivity lists defeats the optimization.
>
> Andy


I have seen people that like to separate the next state logic from
the
clocked logic in state machines. This potentially makes decoding
outputs
for a Mealy state machine more concise to code. Thus you end up with
a
structure similar to the "officially sanctioned" organizations desired
by
the OP.

John Providenza
Reply With Quote
  #7  
Old 08-28-2008, 10:43 AM
gabor
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

On Aug 27, 2:32 pm, kb33 <kanchan.devarako...@gmail.com> wrote:
> Hi,
>
> I have been always been taught so and try to strictly follow the
> practice of splitting my design into combinational and sequential
> blocks (see example below). However, I have been asked to look at
> somebody's design at my workplace that does not do so, and I do not
> know whether I should ignore his style or bring it to the notice of
> the manager. I am looking for the most convincing explanation as to
> why the second style is not good.
>
> ----------My style----------------------
>
> Sequential
> ---------------
>
> always @(posedge clock)
> data_out <= data_out_comb;
>
> Combinational
> ---------------------
>
> always @(reset_n or data_a or data_b)
> if (~reset_n)
> data_out_comb = 0;
> else
> data_out_comb = data_a + data_b;
>
> -------Mixed sequential and combinational design----------------
>
> always @ (posedge clock or negedge reset_n)
> begin
> if(~reset_n)
> data_out <= 0;
> else
> data_out <= data_a + data_b;
> end
>
> P.S The second coding style doesn't even have the signals data_a and
> data_b in the sensitivity list.
>
> Thanks
> kb33


If you want to synthesize this code, you may find that your
version doesn't work (at least XST won't take it) BECAUSE
it has assignments to the same register in more than one
always block.
Reply With Quote
  #8  
Old 08-28-2008, 11:45 AM
Muzaffer Kal
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

On Thu, 28 Aug 2008 07:43:54 -0700 (PDT), gabor <gabor@alacron.com>
wrote:

>On Aug 27, 2:32 pm, kb33 <kanchan.devarako...@gmail.com> wrote:
>> Hi,
>>
>> I have been always been taught so and try to strictly follow the
>> practice of splitting my design into combinational and sequential
>> blocks (see example below). However, I have been asked to look at
>> somebody's design at my workplace that does not do so, and I do not
>> know whether I should ignore his style or bring it to the notice of
>> the manager. I am looking for the most convincing explanation as to
>> why the second style is not good.
>>
>> ----------My style----------------------
>>
>> Sequential
>> ---------------
>>
>> always @(posedge clock)
>> data_out <= data_out_comb;
>>
>> Combinational
>> ---------------------
>>
>> always @(reset_n or data_a or data_b)
>> if (~reset_n)
>> data_out_comb = 0;
>> else
>> data_out_comb = data_a + data_b;
>>
>> -------Mixed sequential and combinational design----------------
>>
>> always @ (posedge clock or negedge reset_n)
>> begin
>> if(~reset_n)
>> data_out <= 0;
>> else
>> data_out <= data_a + data_b;
>> end
>>
>> P.S The second coding style doesn't even have the signals data_a and
>> data_b in the sensitivity list.
>>
>> Thanks
>> kb33

>
>If you want to synthesize this code, you may find that your
>version doesn't work (at least XST won't take it) BECAUSE
>it has assignments to the same register in more than one
>always block.


The OP was just showing two examples of the same design. The first two
always blocks is one implementation and the third always is the second
implementation. They are not meant to be used together.
Reply With Quote
  #9  
Old 08-28-2008, 01:28 PM
Mike Treseler
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

jprovidenza@yahoo.com wrote:

> I have seen people that like to separate the next state logic from
> the
> clocked logic in state machines. This potentially makes decoding
> outputs
> for a Mealy state machine more concise to code. Thus you end up with
> a
> structure similar to the "officially sanctioned" organizations desired
> by
> the OP.


The OP said nothing about Mealy machines or
"officially sanctioned" organizations.

He asked if he should "bring it to the notice of the manager"
I have found that this is almost always a bad idea.

Looks to me like the reviewee has
more language savvy than the reviewer,
and bringing the boss into the loop won't help.

-- Mike Treseler
Reply With Quote
  #10  
Old 08-28-2008, 02:16 PM
kb33
Guest
 
Default Re: Coding Practices for Combinational and Sequential circuits

On Aug 28, 1:28 pm, Mike Treseler <mtrese...@gmail.com> wrote:
> jprovide...@yahoo.com wrote:
> > I have seen people that like to separate the next state logic from
> > the
> > clocked logic in state machines. This potentially makes decoding
> > outputs
> > for a Mealy state machine more concise to code. Thus you end up with
> > a
> > structure similar to the "officially sanctioned" organizations desired
> > by
> > the OP.

>
> The OP said nothing about Mealy machines or
> "officially sanctioned" organizations.
>
> He asked if he should "bring it to the notice of the manager"
> I have found that this is almost always a bad idea.
>
> Looks to me like the reviewee has
> more language savvy than the reviewer,
> and bringing the boss into the loop won't help.
>
> -- Mike Treseler


Thanks for all the help, everybody! I must say this discussion has
forced me to think whether all that I learnt the text book way is
actually the best thing. In fact, I did a small experiment - I
synthesized a piece of Verilog code (from the same guy whose code I
am looking at). First I synthesized it as is, and then I split the
code into sequential and combinational blocks and re-synthesized. The
synthesis results were better for the original. Splitting the design
into two always blocks used up more Logic cells (I was targetting an
Altera FPGA)

ANother strange observation that I made - when the sensitivity list
has only the clock and reset, it doesn't complain about or generate
latches for missing assignments (let's say a missing "else" part to an
"if" and so on). However, the moment the design was spilt into
sequential and combinational, every bit of every signal had to be
assigned a default value, and all "if" statements had to be matched
with "else", otherwise (obviously), latches were generated.


So my next questions are as follows:

1. Assuming that having everything in one always block with just the
reset and clock in the sensitivity list is better, why doesn't the
synthesis tool complain about any missing "else" statements or missing
bit assignments? And why does it not generate latches?

2. I am totally confused as to which style should be adopted. Is it
that one is better for ASICs and the other better for FPGAs?

3. My company RTL coding guidelines still state that I should have
different combinational and sequential blocks (which I already
follow), but at the same time my current project requires that I use
as less resources on my FPGA as possible. So maybe if I were to use
just one always block, I might save Logic cells on the FPGA.


Please advise!

Thanks
kb33
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:16 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.