Local Variables

SystemVerilog Assertions and Functional Coverage From Scratch Local Variables and Endpoint Sequence Methods
26 minutes
Share the link to this page
You need to have access to the item to view this lesson.
One-time Fee
List Price:  $149.95
You save:  $110
List Price:  ₹9,995
You save:  ₹8,515
List Price:  €137.82
You save:  €101.10
List Price:  £118.03
You save:  £86.58
List Price:  CA$204.16
You save:  CA$149.77
List Price:  A$223.77
You save:  A$164.15
List Price:  S$201.83
You save:  S$148.06
List Price:  HK$1,170
You save:  HK$858.29
CHF 36.31
List Price:  CHF 136.30
You save:  CHF 99.99
NOK kr429.08
List Price:  NOK kr1,610.56
You save:  NOK kr1,181.47
DKK kr274.24
List Price:  DKK kr1,029.34
You save:  DKK kr755.10
List Price:  NZ$244.43
You save:  NZ$179.31
List Price:  د.إ550.76
You save:  د.إ404.03
List Price:  ৳17,557.85
You save:  ৳12,880.05
List Price:  RM702.89
You save:  RM515.62
List Price:  ₦220,426.50
You save:  ₦161,700
List Price:  ₨41,549.55
You save:  ₨30,479.83
List Price:  ฿5,435.38
You save:  ฿3,987.27
List Price:  ₺4,834.89
You save:  ₺3,546.77
List Price:  B$765.43
You save:  B$561.50
List Price:  R2,710.25
You save:  R1,988.18
List Price:  Лв269.73
You save:  Лв197.87
List Price:  ₩203,090.78
You save:  ₩148,982.90
List Price:  ₪555.49
You save:  ₪407.50
List Price:  ₱8,654.43
You save:  ₱6,348.70
List Price:  ¥23,343.46
You save:  ¥17,124.25
List Price:  MX$2,490.45
You save:  MX$1,826.94
List Price:  QR544
You save:  QR399.07
List Price:  P2,031.63
You save:  P1,490.35
List Price:  KSh19,643.45
You save:  KSh14,410
List Price:  E£7,034.15
You save:  E£5,160.10
List Price:  ብር8,589.13
You save:  ብር6,300.80
List Price:  Kz127,070.17
You save:  Kz93,215.87
List Price:  CLP$134,129.93
You save:  CLP$98,394.75
List Price:  CN¥1,083.11
You save:  CN¥794.55
List Price:  RD$8,737.85
You save:  RD$6,409.89
List Price:  DA20,149.35
You save:  DA14,781.11
List Price:  FJ$334.11
You save:  FJ$245.10
List Price:  Q1,164.94
You save:  Q854.57
List Price:  GY$31,369.50
You save:  GY$23,011.97
ISK kr5,524.68
List Price:  ISK kr20,736.58
You save:  ISK kr15,211.90
List Price:  DH1,485.15
You save:  DH1,089.48
List Price:  L2,639.39
You save:  L1,936.19
List Price:  ден8,479.80
You save:  ден6,220.59
List Price:  MOP$1,204.99
You save:  MOP$883.95
List Price:  N$2,729.04
You save:  N$2,001.96
List Price:  C$5,510.66
You save:  C$4,042.50
List Price:  रु19,989.41
You save:  रु14,663.79
List Price:  S/557.05
You save:  S/408.64
List Price:  K581.88
You save:  K426.85
List Price:  SAR562.31
You save:  SAR412.50
List Price:  ZK3,807.41
You save:  ZK2,793.03
List Price:  L686.20
You save:  L503.38
List Price:  Kč3,406.56
You save:  Kč2,498.98
List Price:  Ft53,402.36
You save:  Ft39,174.79
SEK kr428.14
List Price:  SEK kr1,607.01
You save:  SEK kr1,178.86
List Price:  ARS$132,968.16
You save:  ARS$97,542.50
List Price:  Bs1,036.01
You save:  Bs759.99
List Price:  COP$570,884.85
You save:  COP$418,788.49
List Price:  ₡76,736.73
You save:  ₡56,292.37
List Price:  L3,693.32
You save:  L2,709.33
List Price:  ₲1,123,433.84
You save:  ₲824,126.19
List Price:  $U5,778.89
You save:  $U4,239.27
List Price:  zł587.88
You save:  zł431.25
per week
Payment Plan
per week
4 payments
Already have an account? Log In


Hello and welcome to lecture number 17. on local variables. local variable is a feature you're most likely to use very often. They can be used both in a sequence and a property. As the name suggests, and they are called local because they are indeed local to a sequence or a property and are not visible or available to other sequences or properties. But of course, there is a solution to this restriction which we will study further into the section. Figure 9.1 points out actually the most important element of a local var, which is that it allows multi threaded application and creates a new copy of the local variable with every instance of the sequence in which it is used.

In other words, the user does not know to worry about creating copies of local variables with each invocation of the sequence. Okay, let's look at this simple application here. And see what we mean by a local variables create a new copy of itself with every instance of the sequence or a property. And it's because of this reason that they are called dynamic variables compared to static variables. And in this application, at bondage of claw, every dried is high, it implies that we should hold the project. Now, sequence data check has a local variable called local data of type int declared and what we are doing in the sequences Based on the completion or based on the trueness of RTC, and RTC is another sequence.

If RTC holds which RTC basically says that within one to five clocks, after READ WRITE is asserted, that read is done on the completion of the sequence and if the sequence passes what we are doing is we are taking the read data because the read is done and assigning that read data or storing that read data into local data local data again being the local variable. And five talks later. After we do a write data, the data that we read we are writing out but we want to make sure that the right data is equal to read data which was stored in local data. Right data is equal to read data or local data plus hex FF. Now, Okay, so far it looks very straightforward. But now let's assume that before read is done, or when we are waiting for five clocks.

To check for the right data readwrite arrives again, it's pipelined behavior of read, write, read, write can keep coming to read data, while not waiting for the right data to go out. So let's read write arrives again and it being high, it means read. And we are still, let's say wait for a rating for the five clocks. What the local variable does it being a dynamic variable, it's simply going to create another copy of local data. So we are waiting for this but a new thread will start based on the completion of RTC and new read data. That we just got from the second thread of RDC that read data will be assigned to a new copy of local data.

So the first thread is continuing and to wait and check for write data. Second thread starts in what I call in a pipeline fashion when the first third is still executing, and more importantly, we don't need to worry about creating explicitly a copy of the local data. And so, the next read will also start a second thread, wait for five o'clock and compare right data. Now, this is a very important point. And without this facility what we used to do or all of us used to do in earlier days without such what I call pipeline, multi threaded behavior that is supported by the language, we will detect that we have When completed the first raid, then we will create an array of local data, for example, and each element of the array, we will explicitly be meaning the user, the coder, the programmer will create a new copy of local data, and then so on and so forth.

Here, you don't need to worry about that at all. So let's look at some more features. And it will become clear to you the semantic of this particular statement that you see here. So, as I just said, it's a new copy of local data that is created every instance of a project. few basic points that you need to know first of all, the local data can be initialized. Which makes sense.

But another point that you need to carefully understand is that if you notice, this is a repeat of the last Page. Before we assign anything to the local data, it must be assigned to an expressions as an expression or a sequence. Without this attachment, you cannot assign anything to the local data. assignment to local data must be attached to an expression or a sequence. And that was the reason why we had RDC. And I will show you well what if I don't have RDC?

I don't have any sequence of expression, then how do I assign local data and I'll show you that in just a second. So, do a repeat if you simply do this local data equal to read data without assigning it to or without attaching it to another sequence of expression, it will give you a compile time error and Another thing that may be confusing to many people is that when you compare the data, like in this case, right data needs to be equal to local data plus hex FF, it should not be attached to an expression. Rather, I shouldn't call is strange, but rather difficult to remember. Well, so that will give you an error. Now, that doesn't make me happy. So what is the solution?

How do we solve this problem? This is, this is what I want to do, but the language doesn't support it. So what we are going to do is, and this is something you'll probably use more or more very often. I don't have an expression or a sequence here, but I still want to assign the local data. All I'm going to do is use a one take B one, which is an expression, and it's always true. So every time we enter data, check sequence, these being always true.

We will ask Find a local data with read data. And then the language itself will create a new copy of local data and do a fork of a second threat. So we don't need to worry about an explosion, the expression or sequence, if you do have it fine and good use that here and the title local data to it. Just like in our example, we had RDC. And now what about this roller where we cannot attach I want to check write data only on the completion of read RDC. So the simple solution to that is little pom pom file the advocate that's a requirement, we're simply going to say RDC and without advancing time, we are going to check for it.

This will do exactly what you were trying to do here. But if you do it this way, language won't accept it. If you do it this way, language up in that way. Be happy with it. So this particular RDC found ground zero, right data is equivalent to what you are trying to do here. Okay, let's see some more basic points.

So I think as I just said earlier, the local variables can be used both in sequence and property. In the property, you can have any implication operator. So what I'm showing here is, is the same example I'm waiting for one clock and I'm checking for raw data here I'm implying non overlapping, meaning the next clock check for the right data. This is rather straightforward. Let's look at some other finer points. If you're going to use local data as a formal in your sequence, then you cannot declare it as local In other words, if you have a local data, you cannot use it as form.

So that's the rule you need to remember. Now let's look at this particular rule that I mentioned earlier is that local variables declared in one sequence are not visible in the sequence where it gets instantiated. What does that mean? Let's look at this example. What we are doing here is we have a lower sequence I call l sequence, in that I have local variable data is a local variable, lb underscore data of type int. And I'm going to use the same RDC sequence and assign it read data.

Now, there is a higher sequence and I have some temporal domain associated with associativity here, and what I'm doing is I'm calling this L sequence which as you know, we can do you You can have a sequence use another sequence as a subsequence. And then since we are calling a sequence, we may think that I can use this lb data from the L sequence because I'm instantiating, that with everything that's in this sequence is visible in the higher sequence. Well, that's not quite true, because as we know, local data is local. It's not visible to a higher sequence. But what if I indeed want to do what I just showed here and not get a compiler? So what I've done number one, I have you I have created a form and as I just say, you cannot have a formal as local variable.

So I do not declare l data as a local variable. This is something I just showed you in the previous Slide. Now what I'm going to do is, so this is L data is a formal of sequence, Eleanor's course sequence. From the higher sequence, I'm going to create a local data. C note here that in the previous example, we had local data in the L sequence. And we could not use lb data into the higher sequence.

And I'm trying to solve that problem. So first of all, I don't declare it in the lower sequence because that's against the rule, but I declared it in the highest sequence. Now what I'm going to do is, I'm going to call l sequence with h data as the actual that gets assigned to or that gets equated to a data. And now I'm going to use h data when when l sequences instantiated here a data will be assigned to L data. We will go ahead and wait for our DC l data will get will be will store our data And this L data will be now assigned to the actual h data. So now we can compare right data equal to h data.

So there's a solution to this problem we had. Let's look at some more ways of using local data. So first of all, you can have multiple local data assignments you don't is not restricted to just one local data assignment, which is what we have seen so far. So on the completion of RDC, again, is the same sequence. What I'm going to do is I'm going to assign two local data and data one and data two to two different data. It could be anything.

Now I'm going to wait for five clocks. And there's another thing you can do is whatever data that you are assigning for example, data to guess retry data, you can increment or decrement, or you can use it in another expression in you can change the local data before you use it. And if you try to do right data equal to L data one, or compare right data for a data one and compare write retry data equal to add data to well, you cannot do multiple checks in the same sub expression. So this will give me an error, but assignment will not give you an error. And what we are doing here is, if this is a problem, just like I showed you in an earlier example, what if I do want to do multiple checks in a sub expression, I'm simply going to divide those with a bond bond zero meaning do not advance the time.

Just compare right data without data one right retry data with no data to This particular code will accomplish this exact thing. But this thing, this particular sub expression will give you an error. So let's look look at a very typical application, which I'm sure you will come across in your project. So the spec says that once a read has been issued, another read from the same read ID cannot be the issue until a read act with the same ID has returned. So once the read is issue, we wait for the read, redact. And if another read from the same read ID occurs again, then it's a problem and we need to catch it and the session should fail.

So let's start from the bottom. Here we are saying a cert property check read which is here. If it passes, don't do anything if it fails at this point. Right that it has failed. Let's look at chapter eight. In the property check rate, we declare a local variable called local ID.

Now we are saying once a read has been issued, and I have said this many times, choose your antecedent wisely. So here we're saying dollar rows read. Once read as an issue. What I'm going to do is I'm going to assign that read ID that is a show associated with this raid, and I'm going to store it in local ID. Now, let's look at this carefully. Just for the sake of argument for now put aside not once the rose dollar rose Reed has arrived, it implies starting next clock.

The rows re should remain high. And the read ID should remain the same as the read ID that we got when dollar rolls read right if this does not hold and then should hold forever, continuously in the positive reputation semantics until you get the reader for the dollar rose read and it has the same redact the reader ID is the same as the read ID which is stored in local ID. If this does not happen, it is when we are waiting for the read with the same read ID until we get the read. If this does not happen, then we do or not have it, meaning fail if you indeed got a read with the same read ID and hence there is a knot here. So, again, the idea is you'll get continual or continuous reads. And with every invocation or check read.

We are going to create a new copy of local ID and store A new copy of read ID. So you can reverse rate read ID equal to one secondary to read ID equal to two, so on and so forth. And you don't need to worry about that. It's it's the nature of dynamic nature of local ID allows you what I call pipeline, multi threaded behavior. So carefully study this application. And it's, it's a very typical real life application that you may be directly able to use.

Now, I want to go back to this problem that I had posed in a previous lecture with delay range. Let me refresh your memory. So here's a property and we are saying that at pauses of clock, if ready is high, it implies that within the next five clause, block radius should arrive. Very straightforward. And here's the timing diagram for it. So let's say s one Which is the force ready?

First ready? starts here at S 112344 rocks later radio arrives, and everybody's happy because this thread has met its requirement. But let's say the very next clock radio arrives, okay? what's gonna happen is this radio is also going to wait from within one to five clocks, it waits for one to three sees the same radio that the first radio saw and said, Hey, I'm happy, I have already is going to also pass the simulator is going to give you only one pass indication. So you don't know if the radio arrived for the secondary or for the first three. What if radio never arrived for the secondary, you would not know.

And that's what I call a false positive. So let's look at this simulation log and after simulating the paper property. Here's the first already arrives. Then the secondary arrives at time 70. See what happens at time 90. Both these radio detects both readies and the property passes.

Again, you don't know this ready, right for the second ready or the first ready, and that's not good. You need to have a radio for each ready to make sure that the logic works. So this is what we are going to do we are going to use a local variable in your test bench. What you do is we have less than a sequence called ready actor. And we have declared a local variable called local data or type byte. And again, as I said, if you don't have any condition expression here, simply say it's always true.

What we are going to do is when the first Ready arrives, we are going to take the ready now and you assign the right in Amira testbench, we take the first ready name associated with the first ready and store it in local data. I just also want to point out that you can attach a sub routine like we have seen it many times before. And I use this idea of attaching a sub retain by displaying what's going on. And please use this little technique, which will tremendously help you in your debug process. So what I'm saying is, when this happens, enter a sequence. I have just ended the sequence and of assigning local data or local readiness equal to local data, which is basically a local array num readiness equal to readiness.

Then I'm going to wait for one to five clocks as required. Then when the radio arrives, I want I'm doing a logical and Meaning when ready act arrives, the ready act now should be equal to local data, which we had stored here with readiness. That means the force ready EQ corresponds to the first readiness. And then again, I attach a sub routine and I display the ready down ready economic zone and so forth, to help me with debug, as you will see in the log file, next page. So basically, for every ready that comes, we assign a readiness test by storing it here and then every time we're ready atoms, we make sure that this radio corresponds to the ready num that was stored. In the local data, let's look at the simulation log to solidify this behavior of the sequence.

So, at dine 50, we enter local sequence How do I know that again, because I would our display here the first already memorize first ready arrived, sorry first radio arrives and I assigned that ready num corresponding to the first ready for the one then I time 70 the the sequence or the property passes, because when the ready EQ arrives, the sequence checks to see that it's ready assigned in the Test Range corresponds to the first readiness as we just saw in the previous cycle page. So what we have made sure is that the ready yet that arrives, does indeed correspond to the ready, the first ready. So this radio is for the first ready. Now we move forward unless a second radio arrives. The second radio arrives before And it also says the radio check that game for the first ready. Okay, and local data is assigned the second ready now.

Now let's see what happens. It's a bit you may find this confusing, but study the law carefully and you will you will notice a behavior. Now when the radio arrives a sequence check to see that is right in that acronym corresponds to the second readiness. In other words we have made sure that every radiate that arrives is for a given ready again to emphasize in this example, without the local variable, we do not know that this radio is either for ready number two, already number one, as we saw in this particular law point, but with a local variable, we will create a new thread for every read We will create a new local data for every ready. And then when ready arise, we make sure with the local data that's stored ready numb that the radio corresponds to the ready that game before the radical right.

And that's what this log shows. This really shows you the power of local variable with this particular solution here again, you will not get a false positive as you would get here if you did not use the local variable. So that's pretty much it for the for the local variables. local variables are again dynamic in nature, and with every instance of a given sequence or a property, a new copy of the local variable is created. And that allows you what I call from a hardware point of view pipelined, multi threaded behavior. Thank you so much for attending this lecture and I will see you in the next lecture soon.

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.