delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2012/02/20/12:52:30

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Message-ID: <4F428825.7030605@icarus.com>
Date: Mon, 20 Feb 2012 09:51:33 -0800
From: Stephen Williams <steve AT icarus DOT com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-Version: 1.0
To: geda-user AT delorie DOT com
Subject: Re: [geda-user] verilog question - blocking/non-blocking
References: <4F41CB0A DOT 2020902 AT optonline DOT net>
In-Reply-To: <4F41CB0A.2020902@optonline.net>
X-Enigmail-Version: 1.3.3
Reply-To: geda-user AT delorie DOT com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Typical synthesizers will synthesize your two examples identically,
and that will cause you trouble.

On 02/19/2012 08:24 PM, gene glick wrote:
> consider this code:
> 
> always @(posedge clk) begin count = count + 1;    // blocking
> method if (count == 0) do_something end

Ack! Bad! in two ways: Screaming opportunities for races within
your verilog, and almost certainly your hardware and simulation
will differ.

As a rule, assignments to clocked signals ("count" in this case)
should use non-blocking assignment as below. The other rule is
that "always" blocks that model combinational logic should use
blocking assignments instead.
> 
> then this way . . .
> 
> 
> always @(posedge clk) begin count <= count + 1;   // non-blocking
> method if (count == 0) do_something end

Better. This will act more like your hardware. The scheduling
of processing in response to your clk will work differently.

Remember, Verilog is a modeling language, and an imperfect one at
that. It does pretty well, but it does not exactly capture all the
subtleties of real hardware. That normally doesn't matter, but you
can mess with your own head if you are not careful. The rules of
thumb above help make the scheduler work in your favor to give a
good simulation of the real hardware.

- -- 
Steve Williams                "The woods are lovely, dark and deep.
steve at icarus.com           But I have promises to keep,
http://www.icarus.com         and lines to code before I sleep,
http://www.picturel.com       And lines to code before I sleep."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9CiCUACgkQrPt1Sc2b3in6UQCgna8ugb/5kPiaZGHOUzN01UTu
lbEAnj9u7h/n+J7R6oNHebxTAztCDf/P
=wkFg
-----END PGP SIGNATURE-----

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019