Overriding procedural assignments in synthesis

B

Bill Valores

Guest
Hello,

In Verilog, it's possible to write several (non-blocking) procedural
assignments in the same always statement. This will work in
simulations of course, with the last acted upon assignment giving the
final value. The question is if this is SAFE PRACTICE when writing
code for synthesis.

The example below works on the Xilinx XST synthesizer, but can I rely
on this to be portable? Is this coding style mainstream enough to use
with no worries?

always @(posedge clk)
begin
in_special_state <= 0; // Default value

case (state)
(...)
ST_special_state:
begin
state <= ST_next;
in_special_state <= 1;
end
(...)
endcase

if (now_special)
state <= ST_special_state;
end

Note that I did two things in the example above:
(1) Gave "in_special_state" a default value which is overridden by the
case statement only when it's a certain state. So the register goes
high only when explicitly set in the case statement, saving the need
to turn it off in the following state.
(2) Wrote an overriding rule for "state" after the case statement. You
may ask why not writing an "if" statement before the state machine.
This was necessary when "now_special" had the function of a reset
signal, which moves to the initial state, which in turn resets several
registers. Since the invocation of this state could be from the state
machine itself, these register resets had to be within the case
statement. Had I used an "if" statement for "now_special" and put the
case in that if's "else", then I'd have to repeat these register
resets in the "if (now_special)" clause. Code which has to be repeated
consistently = source for bugs.

Experiences and insights, anyone?

Thanks,
Bill
 
On Sat, 10 Apr 2010 09:53:51 -0700 (PDT), Bill Valores
<bill.valores@gmail.com> wrote:

Hello,

In Verilog, it's possible to write several (non-blocking) procedural
assignments in the same always statement. This will work in
simulations of course, with the last acted upon assignment giving the
final value. The question is if this is SAFE PRACTICE when writing
code for synthesis.
Absolutely. This is definitely legitimate RTL coding and supported by
synthesis so any non-broken synthesis tool will handle it correctly.
Of course in gates there are no multiple assignments as there is only
one real target register. So the synthesis tool will generate the
necessary priority logic to enable individual assignment paths and
connect the output to the register. If you come upon a synthesis tool
which can't do this, return it and ask for your money back.
--
Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Services

http://www.dspia.com
 
On Sat, 10 Apr 2010 15:02:24 -0700 (PDT), Stonerain <alicpp@gmail.com>
wrote:

On 10 Nisan, 22:05, Muzaffer Kal <k...@dspia.com> wrote:
On Sat, 10 Apr 2010 09:53:51 -0700 (PDT), Bill Valores

bill.valo...@gmail.com> wrote:
Hello,

In Verilog, it's possible to write several (non-blocking) procedural
assignments in the same always statement. This will work in
simulations of course, with the last acted upon assignment giving the
final value. The question is if this is SAFE PRACTICE when writing
code for synthesis.

Absolutely. This is definitely legitimate RTL coding and supported by
synthesis so any non-broken synthesis tool will handle it correctly.
Of course in gates there are no multiple assignments as there is only
one real target register. So the synthesis tool will generate the
necessary priority logic to enable individual assignment paths and
connect the output to the register. If you come upon a synthesis tool
which can't do this, return it and ask for your money back.
--
Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Services

http://www.dspia.com

Actually more anticipated question is that can I use blocking and non-
blocking
assignment in the same always block or should I use?
in my text book which is Pong Chu, says you shouldn't use but what if
I know what
I am doing? Would you mind if I asked you company is where Muzaffer
Kal?

Sto.
There is no reason for a blanket ban on mixing blocking and
non-blocking assignments in the same always block. Especially if you
use a local target (ie a reg defined in a labeled begin-end block)
this practice is perfectly safe.
You can get all information about DSPIA INC. at our web site.
--
Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Services

http://www.dspia.com
 
On 10 Nisan, 22:05, Muzaffer Kal <k...@dspia.com> wrote:
On Sat, 10 Apr 2010 09:53:51 -0700 (PDT), Bill Valores

bill.valo...@gmail.com> wrote:
Hello,

In Verilog, it's possible to write several (non-blocking) procedural
assignments in the same always statement. This will work in
simulations of course, with the last acted upon assignment giving the
final value. The question is if this is SAFE PRACTICE when writing
code for synthesis.

Absolutely. This is definitely legitimate RTL coding and supported by
synthesis so any non-broken synthesis tool will handle it correctly.
Of course in gates there are no multiple assignments as there is only
one real target register. So the synthesis tool will generate the
necessary priority logic to enable individual assignment paths and
connect the output to the register. If you come upon a synthesis tool
which can't do this, return it and ask for your money back.
--
Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Services

http://www.dspia.com
Actually more anticipated question is that can I use blocking and non-
blocking
assignment in the same always block or should I use?
in my text book which is Pong Chu, says you shouldn't use but what if
I know what
I am doing? Would you mind if I asked you company is where Muzaffer
Kal?

Sto.
 
Hello again.

Absolutely. This is definitely legitimate RTL coding and supported by
synthesis so any non-broken synthesis tool will handle it correctly.
I know that it's legitimate. Unfortunately, because of the peculiar
nature of the synthesizer, which has the nearly impossible task of
implementing logic which matches a simulation model, legitimate RTL
doesn't mean recommended RTL. I've seen my synthesizer do terribly
stupid things, including breaking the logic function because it had a
bug. A bug which I was first to bump into, because what I happened to
do wasn't all that common.

So when I'm coding, I'm always asking myself if a lot of other people
use exactly the same patterns. As long as I can say "if this wouldn't
work, nobody would use this synthesizer" I'm in the safe zone.

That's why I asked whether the presented pattern is considered
mainstream.
 

Welcome to EDABoard.com

Sponsor

Back
Top