• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Can queues be used to drive RTL?

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 65
  • Views 7661
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can queues be used to drive RTL?

shareefj
shareefj over 2 years ago

This may well be a case of my not being able to see the wood for the trees or generally doing something stupid, but I thought I'd ask anyway.

I'm trying to interface a bus driver with some DPI code and thought that using a queue would be the best way.  What I have on the DPI side is a function that is called when new data is available to be pushed onto the queue.  On the RTL side, I've got a module with a FIFO interface and data is popped off the queue as it is loaded into the receiving downstream flop.  So something like the following:

bit [31:0] queue[$];

function push_back;
  input bit [31:0] value;
  queue.push_back(value);
endfunction

always_ff@(posedge clk) begin
  if(fifo_pop)
    queue.pop_front();
end

assign din = queue[0];

always_ff@(posedge clk) begin
  if (fifo_pop)
    capture_r <= din;
end

What I'm seeing is that the queue is updated before din has been captured in the receiving flop.  Is that expected and if so, what should I be doing here?  I've not done a load of DPI work before and haven't seen too many examples of how to cleanly drive an interface like this.

Thanks.

  • Cancel
  • shareefj
    shareefj over 2 years ago

    Just as a side note, modifying the above example such that the pop and assignment happen on the same line in the same always block works.  I just can't do that in my real code due to hierarchy.  Putting in a simple one entry FIFO that bridges between DPI and RTL seems to work though.

    always_ff @(posedge clk) begin
      if (fifo_pop)
        capture_r <= queue.pop_front();
    end
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 2 years ago

    At a glance, I think this is mainly due to a race between your two clocked processes and you might even find the behaviour changes if you swap the declaration order of those.

    It's a little unusual to use queue.pop_front() without using the popped value, so I think your later post where you assign the popped value to capture_r is more "normal" use of the construct. Note also that the pop_front() is a blocking action, just like a blocking assignment that you would use in combinational logic, so by using it directly in a clocked process in your first example, you're making a blocking assignment in a clocked process. The normal rules for coding a clocked process are that you must only use non-blocking assignments, to avoid races with combinational logic that uses only blocking assignments.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • shareefj
    shareefj over 2 years ago in reply to StephenH

    A little unusual is a good description.  Given the rest of your comment, is there any other way I can drive a combinational net/bus from a queue?  Or is that just bad practice and I should always be popping into some sequential logic that handles driving?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 2 years ago in reply to shareefj

    Most testbenches would be driving the wires from a clocked process using either a clocking block or a non-blocking assignment, I don't think I've ever seen someone connecting a queue element directly to a signal until now. Whether this counts as bad practice, I'm not sure - SV provides an almost infinite number of ways to do anything, you just have to be really careful about the scheduling semantics if you deviate from the conventional sequential / combinational driver patterns.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • shareefj
    shareefj over 2 years ago in reply to StephenH

    Thanks Stephen.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information