FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-12-2007, 06:50 PM
kb33
Guest
 
Posts: n/a
Default "Latch generated" warning from Synplicity

Hi,

I have matched all the if-else statements in the following code, but
cannot get rid of the warnings for all the array elements:

"Latch generated from always block for signal array1_comb[1][15][7:0],
probably caused by a missing assignment in an if or case stmt"
....and so on for the others as well.

The code (with some missing I/O definitions) is:




reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
array1_comb [0:`NUM_RSRC-1]
[0:`NUM_ATTRIB-1];



always @(posedge sys_clk)
begin
for (i = 0; i < `NUM_RSRC; i = i+1)
for (j=0; j < `NUM_ATTRIB; j=j+1)
array1 [i][j] <= #1 array1_comb [i][j];
end


//array1_comb...
always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
begin
if (~reset_n)
for (k = 0; k < `NUM_RSRC; k = k+1)
for (l=0; l < `NUM_ATTRIB; l=l+1)
array1_comb [k][l] <= 0;

else if (match_state == `RECORD_RSRC)
begin
for (k = 0; k < `NUM_RSRC; k = k+1)
if (k == rsrc_id)
for (l=0; l < `NUM_ATTRIB; l=l+1)
if (l == curr_attrib)
array1_comb [k][l] <= data_in;
else
array1_comb [k][l] <= array1 [k][l];
else
array1_comb [k][l] <= array1 [k][l];
end

else
for (k = 0; k < `NUM_RSRC; k = k+1)
for (l=0; l < `NUM_ATTRIB; l=l+1)
array1_comb [k][l] <= array1 [k][l];
end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
data_in)

Reply With Quote
  #2 (permalink)  
Old 09-12-2007, 08:17 PM
johnp
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity

On Sep 12, 10:50 am, kb33 <[email protected]> wrote:
> Hi,
>
> I have matched all the if-else statements in the following code, but
> cannot get rid of the warnings for all the array elements:
>
> "Latch generated from always block for signal array1_comb[1][15][7:0],
> probably caused by a missing assignment in an if or case stmt"
> ...and so on for the others as well.
>
> The code (with some missing I/O definitions) is:
>
> reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
> array1_comb [0:`NUM_RSRC-1]
> [0:`NUM_ATTRIB-1];
>
> always @(posedge sys_clk)
> begin
> for (i = 0; i < `NUM_RSRC; i = i+1)
> for (j=0; j < `NUM_ATTRIB; j=j+1)
> array1 [i][j] <= #1 array1_comb [i][j];
> end
>
> //array1_comb...
> always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
> begin
> if (~reset_n)
> for (k = 0; k < `NUM_RSRC; k = k+1)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> array1_comb [k][l] <= 0;
>
> else if (match_state == `RECORD_RSRC)
> begin
> for (k = 0; k < `NUM_RSRC; k = k+1)
> if (k == rsrc_id)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> if (l == curr_attrib)
> array1_comb [k][l] <= data_in;
> else
> array1_comb [k][l] <= array1 [k][l];
> else
> array1_comb [k][l] <= array1 [k][l];
> end
>
> else
> for (k = 0; k < `NUM_RSRC; k = k+1)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> array1_comb [k][l] <= array1 [k][l];
> end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
> data_in)


Since arrayl is not in the sensitivity list, I suspect this may be
causing the
latch warning.

John Providenza

Reply With Quote
  #3 (permalink)  
Old 09-12-2007, 09:12 PM
Mike Lewis
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity


"kb33" <[email protected]> wrote in message
news:[email protected] ups.com...
> Hi,
>
> I have matched all the if-else statements in the following code, but
> cannot get rid of the warnings for all the array elements:
>
> "Latch generated from always block for signal array1_comb[1][15][7:0],
> probably caused by a missing assignment in an if or case stmt"
> ...and so on for the others as well.
>
> The code (with some missing I/O definitions) is:
>
>
>
>
> reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
> array1_comb [0:`NUM_RSRC-1]
> [0:`NUM_ATTRIB-1];
>
>
>
> always @(posedge sys_clk)
> begin
> for (i = 0; i < `NUM_RSRC; i = i+1)
> for (j=0; j < `NUM_ATTRIB; j=j+1)
> array1 [i][j] <= #1 array1_comb [i][j];
> end
>
>
> //array1_comb...
> always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
> begin
> if (~reset_n)
> for (k = 0; k < `NUM_RSRC; k = k+1)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> array1_comb [k][l] <= 0;
>
> else if (match_state == `RECORD_RSRC)
> begin
> for (k = 0; k < `NUM_RSRC; k = k+1)
> if (k == rsrc_id)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> if (l == curr_attrib)
> array1_comb [k][l] <= data_in;
> else
> array1_comb [k][l] <= array1 [k][l];
> else
> array1_comb [k][l] <= array1 [k][l];
> end
>
> else
> for (k = 0; k < `NUM_RSRC; k = k+1)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> array1_comb [k][l] <= array1 [k][l];
> end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
> data_in)
>


I don't see a"default" setting for array1_comb.

Also .. its a combinatorial always block .. so I'm not liking the <= part ..
this won't cause your latch though.

The most likely reason for a latch in a combinatorial always block is a
missing default condition.

Mike


Reply With Quote
  #4 (permalink)  
Old 09-12-2007, 09:51 PM
devices
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity


"kb33" <[email protected]> wrote in message
news:[email protected] ups.com...
> Hi,
>
> I have matched all the if-else statements in the following code, but
> cannot get rid of the warnings for all the array elements:
>
> "Latch generated from always block for signal array1_comb[1][15][7:0],
> probably caused by a missing assignment in an if or case stmt"
> ...and so on for the others as well.
>
> The code (with some missing I/O definitions) is:
>
>
>
>
> reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
> array1_comb [0:`NUM_RSRC-1]
> [0:`NUM_ATTRIB-1];
>
>
>
> always @(posedge sys_clk)
> begin
> for (i = 0; i < `NUM_RSRC; i = i+1)
> for (j=0; j < `NUM_ATTRIB; j=j+1)
> array1 [i][j] <= #1 array1_comb [i][j];
> end
>
>
> //array1_comb...
> always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
> begin
> if (~reset_n)
> for (k = 0; k < `NUM_RSRC; k = k+1)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> array1_comb [k][l] <= 0;
>
> else if (match_state == `RECORD_RSRC)
> begin
> for (k = 0; k < `NUM_RSRC; k = k+1)
> if (k == rsrc_id)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> if (l == curr_attrib)
> array1_comb [k][l] <= data_in;
> else
> array1_comb [k][l] <= array1 [k][l];
> else
> array1_comb [k][l] <= array1 [k][l];
> end
>
> else
> for (k = 0; k < `NUM_RSRC; k = k+1)
> for (l=0; l < `NUM_ATTRIB; l=l+1)
> array1_comb [k][l] <= array1 [k][l];
> end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
> data_in)
>


When "k is not rsrc_id", the line:

array1_comb[k][l] <= array1[k][l];

skips a lot of assignments as there isn't any inner
loop that scans the row by changing l.





Reply With Quote
  #5 (permalink)  
Old 09-13-2007, 04:18 AM
kb33
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity

On Sep 12, 4:12 pm, "Mike Lewis" <[email protected]> wrote:
> "kb33" <[email protected]> wrote in message
>
> news:[email protected] ups.com...
>
>
>
> > Hi,

>
> > I have matched all the if-else statements in the following code, but
> > cannot get rid of the warnings for all the array elements:

>
> > "Latch generated from always block for signal array1_comb[1][15][7:0],
> > probably caused by a missing assignment in an if or case stmt"
> > ...and so on for the others as well.

>
> > The code (with some missing I/O definitions) is:

>
> > reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
> > array1_comb [0:`NUM_RSRC-1]
> > [0:`NUM_ATTRIB-1];

>
> > always @(posedge sys_clk)
> > begin
> > for (i = 0; i < `NUM_RSRC; i = i+1)
> > for (j=0; j < `NUM_ATTRIB; j=j+1)
> > array1 [i][j] <= #1 array1_comb [i][j];
> > end

>
> > //array1_comb...
> > always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
> > begin
> > if (~reset_n)
> > for (k = 0; k < `NUM_RSRC; k = k+1)
> > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > array1_comb [k][l] <= 0;

>
> > else if (match_state == `RECORD_RSRC)
> > begin
> > for (k = 0; k < `NUM_RSRC; k = k+1)
> > if (k == rsrc_id)
> > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > if (l == curr_attrib)
> > array1_comb [k][l] <= data_in;
> > else
> > array1_comb [k][l] <= array1 [k][l];
> > else
> > array1_comb [k][l] <= array1 [k][l];
> > end

>
> > else
> > for (k = 0; k < `NUM_RSRC; k = k+1)
> > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > array1_comb [k][l] <= array1 [k][l];
> > end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
> > data_in)

>
> I don't see a"default" setting for array1_comb.
>
> Also .. its a combinatorial always block .. so I'm not liking the <= part ..
> this won't cause your latch though.
>
> The most likely reason for a latch in a combinatorial always block is a
> missing default condition.
>
> Mike


Hi,
The last "else" denotes the default condition for the array1_comb
array. Also, if you see closely, the first always block is the
sequential logic, and the second always block is the combinational
block. I prefer to always keep the two apart, hence all the
combinational signals have a suffix of "comb". Moreover, I use non-
blocking assignments in all places to avoid issues after synthesis (my
logic is usually designed accordingly). Interestingly, I am getting
the same type of warning when I use a case statement that has the
default condition explicitly included. I am still confused. In
response to John's reply about not including the array1 signal in the
sensitivity list, I really don't know how to include that. I have
posed this question about including arrays in the sensitivity list in
this forum, but have yet to receive a convincing reply!

Thanks
Kanchan

Reply With Quote
  #6 (permalink)  
Old 09-14-2007, 01:28 PM
devices
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity


"kb33" <[email protected]> wrote in message
news:[email protected] oups.com...
> On Sep 12, 4:12 pm, "Mike Lewis" <[email protected]> wrote:
> > "kb33" <[email protected]> wrote in message
> >
> > news:[email protected] ups.com...
> >
> >
> >
> > > Hi,

> >
> > > I have matched all the if-else statements in the following code, but
> > > cannot get rid of the warnings for all the array elements:

> >
> > > "Latch generated from always block for signal array1_comb[1][15][7:0],
> > > probably caused by a missing assignment in an if or case stmt"
> > > ...and so on for the others as well.

> >
> > > The code (with some missing I/O definitions) is:

> >
> > > reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
> > > array1_comb [0:`NUM_RSRC-1]
> > > [0:`NUM_ATTRIB-1];

> >
> > > always @(posedge sys_clk)
> > > begin
> > > for (i = 0; i < `NUM_RSRC; i = i+1)
> > > for (j=0; j < `NUM_ATTRIB; j=j+1)
> > > array1 [i][j] <= #1 array1_comb [i][j];
> > > end

> >
> > > //array1_comb...
> > > always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
> > > begin
> > > if (~reset_n)
> > > for (k = 0; k < `NUM_RSRC; k = k+1)
> > > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > > array1_comb [k][l] <= 0;

> >
> > > else if (match_state == `RECORD_RSRC)
> > > begin
> > > for (k = 0; k < `NUM_RSRC; k = k+1)
> > > if (k == rsrc_id)
> > > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > > if (l == curr_attrib)
> > > array1_comb [k][l] <= data_in;
> > > else
> > > array1_comb [k][l] <= array1 [k][l];
> > > else
> > > array1_comb [k][l] <= array1 [k][l];
> > > end

> >
> > > else
> > > for (k = 0; k < `NUM_RSRC; k = k+1)
> > > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > > array1_comb [k][l] <= array1 [k][l];
> > > end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
> > > data_in)

> >
> > I don't see a"default" setting for array1_comb.
> >
> > Also .. its a combinatorial always block .. so I'm not liking the <=

part ..
> > this won't cause your latch though.
> >
> > The most likely reason for a latch in a combinatorial always block is a
> > missing default condition.
> >
> > Mike




> The last "else" denotes the default condition for the array1_comb
> array.


The "else" you talk about won't save you from latches.

Perhaps the concept behind "default condition" is better
expressed by "default assignment" or "default settings"
like Mike Lewis said.

If the "else" branch that you thought as default is never
executed whatever branch is executed in its place will find
no default assignment at all.


Reply With Quote
  #7 (permalink)  
Old 09-14-2007, 03:43 PM
kb33
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity

On Sep 14, 8:28 am, "devices" <me@home> wrote:
> "kb33" <[email protected]> wrote in message
>
> news:[email protected] oups.com...
>
>
>
> > On Sep 12, 4:12 pm, "Mike Lewis" <[email protected]> wrote:
> > > "kb33" <[email protected]> wrote in message

>
> > >news:[email protected] oups.com...

>
> > > > Hi,

>
> > > > I have matched all the if-else statements in the following code, but
> > > > cannot get rid of the warnings for all the array elements:

>
> > > > "Latch generated from always block for signal array1_comb[1][15][7:0],
> > > > probably caused by a missing assignment in an if or case stmt"
> > > > ...and so on for the others as well.

>
> > > > The code (with some missing I/O definitions) is:

>
> > > > reg [`DATA_SZ-1:0] array1 [0:`NUM_RSRC-1][0:`NUM_ATTRIB-1],
> > > > array1_comb [0:`NUM_RSRC-1]
> > > > [0:`NUM_ATTRIB-1];

>
> > > > always @(posedge sys_clk)
> > > > begin
> > > > for (i = 0; i < `NUM_RSRC; i = i+1)
> > > > for (j=0; j < `NUM_ATTRIB; j=j+1)
> > > > array1 [i][j] <= #1 array1_comb [i][j];
> > > > end

>
> > > > //array1_comb...
> > > > always @(reset_n, match_state, curr_attrib, rsrc_id, data_in)
> > > > begin
> > > > if (~reset_n)
> > > > for (k = 0; k < `NUM_RSRC; k = k+1)
> > > > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > > > array1_comb [k][l] <= 0;

>
> > > > else if (match_state == `RECORD_RSRC)
> > > > begin
> > > > for (k = 0; k < `NUM_RSRC; k = k+1)
> > > > if (k == rsrc_id)
> > > > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > > > if (l == curr_attrib)
> > > > array1_comb [k][l] <= data_in;
> > > > else
> > > > array1_comb [k][l] <= array1 [k][l];
> > > > else
> > > > array1_comb [k][l] <= array1 [k][l];
> > > > end

>
> > > > else
> > > > for (k = 0; k < `NUM_RSRC; k = k+1)
> > > > for (l=0; l < `NUM_ATTRIB; l=l+1)
> > > > array1_comb [k][l] <= array1 [k][l];
> > > > end // always @ (reset_n, match_state, curr_attrib, rsrc_id,
> > > > data_in)

>
> > > I don't see a"default" setting for array1_comb.

>
> > > Also .. its a combinatorial always block .. so I'm not liking the <=

> part ..
> > > this won't cause your latch though.

>
> > > The most likely reason for a latch in a combinatorial always block is a
> > > missing default condition.

>
> > > Mike

> > The last "else" denotes the default condition for the array1_comb
> > array.

>
> The "else" you talk about won't save you from latches.
>
> Perhaps the concept behind "default condition" is better
> expressed by "default assignment" or "default settings"
> like Mike Lewis said.
>
> If the "else" branch that you thought as default is never
> executed whatever branch is executed in its place will find
> no default assignment at all.


I am not sure I understand your point syntactically speaking, though
conceptually I see what you mean. All the array elements do have non-
ambiguous values, so why shouldn't an else statement at the end take
care of all other conditions? As I mentioned earlier, even an explicit
default statement in a case statement doesn't seem to solve the
problem. Also, I have observed that this situation arises when there
are loops involved (I may not be 100% correct, but it is my hunch..)

Thanks,
Kanchan

Reply With Quote
  #8 (permalink)  
Old 09-14-2007, 04:10 PM
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity

On Sep 14, 7:43 am, kb33 <[email protected]> wrote:
> On Sep 14, 8:28 am, "devices" <me@home> wrote:


> > If the "else" branch that you thought as default is never
> > executed whatever branch is executed in its place will find
> > no default assignment at all.

>
> ...
> All the array elements do have non-ambiguous values, so why
> shouldn't an else statement at the end take
> care of all other conditions?
> ...


Kanchan - this is the problem - you THINK that you've unambiguously
assigned
all bits of array1_comb in all cases but you haven't. The synthesis
tool sees this, and is forced to generate a latch.

As "devices" mentioned in the other thread - you're missing
the "for 'l' loop" in the if( k != rsrc_id ) sub-clause.

Some coding style to insure you've always got a default condition
would be to first assign the default at the beginning of the loop
like below (and you should pay attention to Mike's comment on
blocking
assignment for combinational logic)

always @*
begin
for (k = 0; k < `NUM_RSRC; k = k+1)
for (l=0; l < `NUM_ATTRIB; l=l+1)
array1_comb = array1 [k][l];

// insert the reset of your logic here.
end

This way, you REALLY are unambiguously assigning to array1_comb in
every case. (Well, you'd need to insure you don't mess up the
for loop limits). You overwrite the default in your decode, but the
default is set up front.

The downside - the bug in your code (there is one!) would
need to be found through simulation - instead of this nice friendly
warning from your synthesis tool.

Regards,

Mark


Reply With Quote
  #9 (permalink)  
Old 09-14-2007, 07:27 PM
kb33
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity


Hi,
>
> As "devices" mentioned in the other thread - you're missing
> the "for 'l' loop" in the if( k != rsrc_id ) sub-clause.
>


Thanks to "devices" and Mark...the culprit (for most of the cases
where I was getting the Latch warning) was the missing 'l' loop in the
if( k != rsrc_id ) sub-clause.

However, this discussion has raised some other questions for me:
1. Mike and Mark commented upon the use of non-blocking statements in
combinational blocks...is it wrong to do so? Wouldn't Synthesis
complain if I used blocking and non-blocking in the same verilog file?
Aren't the blocking-nonblocking issues governed more by how you want
the signals to behave rather than whether they are sequential or
combinational?


> The downside - the bug in your code (there is one!) would
> need to be found through simulation - instead of this nice friendly
> warning from your synthesis tool.
>


2. Mark, is this a specific bug you are talking about in the code, or
is it related to the style of coding? The simulations seem to be fine,
though.

Thanks,
Kanchan

Reply With Quote
  #10 (permalink)  
Old 09-14-2007, 08:55 PM
Guest
 
Posts: n/a
Default Re: "Latch generated" warning from Synplicity

On Sep 14, 11:27 am, kb33 <[email protected]> wrote:
>
> However, this discussion has raised some other questions for me:
> 1. Mike and Mark commented upon the use of non-blocking statements in
> combinational blocks...is it wrong to do so? Wouldn't Synthesis
> complain if I used blocking and non-blocking in the same verilog file?
> Aren't the blocking-nonblocking issues governed more by how you want
> the signals to behave rather than whether they are sequential or
> combinational?


Thankfully, we've got a very good reference here.
Google: "Nonblocking Assignments in Verilog Synthesis, Coding
Styles That Kill" by Cliff Cummings.

Your answers to the above questions are answered in Cliff's
paper. If you want to deviate from Cliff's guidelines here
(which your code DOES), then you should do it with eyes
fully open as to the consequences. These specific guidelines
from Cliff are pretty much industry standard. Some folks
don't follow them but they do so in one of two cases:

1. They're a guru with detailed understanding of the
verilog stratified event queue, and have some kind
of other method of avoiding the pitfalls.
2. They're unaware, and are asking for trouble.

> > The downside - the bug in your code (there is one!) would
> > need to be found through simulation - instead of this nice friendly
> > warning from your synthesis tool.

>
> 2. Mark, is this a specific bug you are talking about in the code, or
> is it related to the style of coding? The simulations seem to be fine,
> though.


I was referring to your missing "for" loop as the bug. The synthesis
tool told you about the bug with the "latch generated" warning.
If your simulation seemed fine with the bug, then your simulations
were probably inadequate. Well, you'd likely have a gate vs. rtl
mismatch,
since the latching logic generated would be highly weird, and not
explicity
matching the RTL behavior, I believe.

Regards,

Mark


Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is a "bug", and what is "good code"? (or: more default_nettype) Evan Lavelle Verilog 2 07-26-2007 03:03 PM
Include file extension: ".v" vs ".vh"? Andreas Ehliar Verilog 4 05-04-2007 09:58 PM
how to represent "inout" data type in testbenches in "verilog" linuxczar Verilog 2 03-21-2007 06:28 PM
Why do we need "check" "call" "misc" in PLI? Lee Verilog 1 05-17-2004 03:42 PM
SystemVerilog: "logic" or "ulogic?" Cliff Cummings Verilog 1 09-20-2003 11:55 PM


All times are GMT +1. The time now is 12:26 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved