Writing Testbenches
Using SystemVerilog
Home  |  Contents  |  Reviews  |  Ask  |  Errata  |  Resources  |  Guild  |  Order
 
 
 

Ask the Author

  Even at 400 pages, some explanations may be too terse or make some important leaps of logic that are difficult to follow. Or my writing may be at time just plain obscure.

If you need more explanations or details about a concept presented in the book, don't be shy about sending an email to me. I get them all the time.

I will keep a list of answers to questions I think others may be asking themselves on this page. They will be listed in page order.

However, you may be staring at an error in the book. Therefore, it may also be a good idea to check out the errata page.

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

p.254, Example 5-70

Shouldn't the order of -> this.ready; and @ (this.fetch); be inverted in the task fetch()?

The code is correct. Here's what happens:

  1. monitor_thread() blocks waiting for negedge of AS.
  2. fetch() is called, emits ready (which goes unnoticed) and waits for fetch
  3. AS falls, monitor_thread() emits fetch (caught by fetch()) and waits for ready
  4. fetch() returns. User provides opcode based on address and immediately calls fetch() again, emitting ready then waiting for fetch
  5. monitor_thread() unblocks then goes back to Step 1.

That's how a stand-by task works.

Chapter 6

p.319, Example 6-42

Firstly, my difficulty with this example is that there is nothing that constrains or directly sets the length of the randomized_cells[] array to the length of the longest sequence as you state in the text. In fact, aren’t you saying that the array should in fact be a static array declared as long as the longest sequence?

Secondly, isn’t the length variable redundant anyway in this class? Would something like

   `define MAX_LENGTH 100 
   class atm_cell_seq
      rand atm_cell randomized_cells[];

      constraint random_length {
         randomized_cells.size()  > 0;
         randomized_cells.size() <= `MAX_LENGTH;
      }
   endclass: atm_cell_seq
                     
Not do the job just as well?

Setting the length and allocating content of the randomized_cells[] array is something that should be done in pre_randomize(). A static array should not be used because you do not know a priori how long a sequence can be. That is something up to the testcase to decide. Unless you want to hardcode a maximum length.

Using the length variable instead of the array size itself avoids having the array repeatedly lenthened and truncated at each randomization attempt. Better to allocate for the longest one, then simply use a subrange of the array and avoid memory/garbage collection issues. It also conveniently avoids the issue of what to put into the array if it is an array of class references and randomized to be longer. Note that the LRM does the same by only showing arrays of scalars which do not require additional memory allocation :-)

This is a gray area in the LRM and I wanted to avoid tool-specific issues and went for an approach that should be portable. If you are a VCS user, there is additional functionality/details I can describe.

Chapter 7