Coder Social home page Coder Social logo

Comments (6)

martinwhitaker avatar martinwhitaker commented on August 24, 2024 1

You have a race in your code. At time 105 there are two processes (threads) waiting for the rising edge of MPC_LCLK. One is the task foo, the other is the always block that assigns to addr. A simulator can legitimately choose either of these to execute first. In this case Icarus is choosing the task, which proceeds to assign to mpc_address, MPC_LA, and MPC_LALE before relinquishing control to wait for the next clock edge. Icarus then executes the always block, which samples the current state of MPC_LA. Because you used blocking assignments in the task, MPC_LA has already been updated with the new value. Change the blocking assignments to non-blocking assignments, and you will get the behaviour you expect.

Closing as invalid.

from iverilog.

steveicarus avatar steveicarus commented on August 24, 2024 1

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

Martin is 100% correct, your example had a race and it is not
a problem with Icarus Verilog. Whenever you mix blocking and
non-blocking assignments in synchronous logic, you run the risk
of races. The offending assignments in your example are in the
"foo" task. Rework that code to use non-blocking assignments,
and you should see better results.

On 07/08/2015 02:26 AM, Simuc wrote:

I show an example, it's a loop-left shifter.

|reg [7:0] q; always @(posedge clk) q <= {q[6:0], q[7]}; |

As you know, q[i] change after the clk event, and get a value which
was the data from q[i-1] at the time BEFORE the clk event.

I hope that you can understand what I mean.

— Reply to this email directly or view it on GitHub
#74 (comment).


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

iEYEARECAAYFAlWdOk4ACgkQrPt1Sc2b3ikxRgCgq2ucVS6zmFzM3BEGs3aHCk2c
9mQAoIqX43urnhSxbav7h7SpKRnkX6Hf
=vVxA
-----END PGP SIGNATURE-----

from iverilog.

balanx avatar balanx commented on August 24, 2024

Maybe you miss a understanding.
For circuit simulation, generally "non-blocking assignments" is used for synchrous simulation. e.g. always @(posedge clk) q <= d; it means q got value d BEFORE events, i.e. setup time is 0 before posedge clk.

Generally "blocking assignments" is used for Asynchrous simulation. e.g. @(posedge clk) q = d; it means q got value d AFTER events, i.e. firstly event 'posedge clk', then do 'q = d'.

One is before evnet, and the other is after event. So that is a accurary behaviorial description, simulator can NOT choose at random !!

from iverilog.

martinwhitaker avatar martinwhitaker commented on August 24, 2024

No, your understanding is wrong. "@(event) statement;" means wait for "event" then execute "statement", regardless of what "statement" is. So if you write

always @(posedge clk) statement1;
always @(posedge clk) statement2;

a simulator can choose to execute either statement1 or statement2 first (and can choose differently each time the event occurs).

If the statement is a non-blocking assignment, the RHS expression is evaluated after waiting for the event, not before.

For a more thorough explanation, try Cliff Cumming's paper: http://www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA.pdf

from iverilog.

balanx avatar balanx commented on August 24, 2024

I show an example, it's a loop-left shifter.

reg [7:0] q;
always @(posedge clk) q <= {q[6:0], q[7]};

As you know, q[i] change after the clk event, and get a value which was the data from q[i-1] at the time BEFORE the clk event.

I hope that you can understand what I mean 'before'.

from iverilog.

martinwhitaker avatar martinwhitaker commented on August 24, 2024

By 'before' you mean before any updates caused by non-blocking assignments triggered by that event. This is correct. But the problem in your original test case is that you used a blocking assignment which causes an immediate update, creating a timing race. This is equivalent to a hold-time violation in a real circuit.

If you don't understand this, read the Cliff Cummings paper.

from iverilog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.