Many vendors offered Verification IP (VIP) modules that you could use in simulation to know that your interface matched the specification. These models would attach to your design, allowing you to then run tests on your design. When/if your design didn’t match what the protocol required, these commercial VIP modules would issue an error.
Indeed, it seems like the primary method of proving that an ASIC design would work prior to tape out is to feed the simulated design with random data and requests, over and over again, in order to get the design to fail. Several presentations discussed how to do this. Hardware was advertised that could help to make this happen. While I’ll admit that the level of effort discussed and presented goes well beyond my simple scripted test bench failures, it still only provides a small stochastic confidence that the design would work.
What a difference from formal!
When using formal methods, every path through the your logic is tested to determine if the design works. Every path.
This led me to wandering through the exhibit hall, asking vendor after vendor if they had any formal VIP. Perhaps 5-10% of the VIP available was available for proving something formally. While the reasons were mixed, the general consensus was that formal was more difficult to use, and so there wasn’t the same market for it. One vendor even declared that his tools were faster, better, and cheaper than formal, although less than formal in capability.
What?? Really? Is formal really all that difficult to use?
Let’s look at a simple example or two. Then, we can discuss how I go about getting started with formal on any new design, and what designs I apply formal methods to. Finally, we’ll attempt to address the question of whether formal methods really are all that hard.
into the new/updated dual
(I was starting with
If you aren’t familiar with a
cover statement, you can consider
it a challenge to the
tools to find some way to make the predicate
inside of the
cover statement–in this case
o_wb_ack–true. To do this,
tools needed to trace my
bus request, the address
passing to the
and the return value.
No extra logic was required!
I didn’t need to build a simulation, to tell the simulator to tick the clock, tell it how many clocks to tick, feed it with just the right input along the way–none of that. With one line I had an example trace through the important parts of my code.
Was that all that hard?
Ok, so it wasn’t perfect: the bus wires were being driven incoherently. However, with some additional assumptions, such as those we discussed for the Wishbone Bus, the traces greatly improved. (No, the controller isn’t finished yet …) Later, I added another cover statement to make certain I could keep the design loaded with one request after another.
Many of my designs use state machines that don’t completely cover all of the states bits available. For example, the “lite” versions of my serial port modules only use states 0-8 and 15. What if the design entered into any other state? Would such be possible? With just a simple assertion,
I can then use formal methods to tell me if my state machine will ever get out of bounds. Indeed, this concept is so useful, it’s worth discussing further in the next section.
Formal methods are
also very useful for making sure that dependencies between logic elements
are captured. Hence, if you have two variables,
B that must
have a dependent relationship,
formal methods are
very useful for making sure that dependent relationship is maintained.
For example, many designs depend upon a state machine that transitions at a speed much slower than the system clock. My own UART implementation makes a great example of this. In this design, as with many similar ones, there is often a counter used to determine when the next state change will be.
The problem with this approach is that within the state machine logic, I would
need to place tests for whether or not
counter == 0.
This test for zero can make the state transition logic unnecessarily complex, so I’ll often calculate it the clock prior with something like:
To determine if I got the logic right, I only need to formally verify that:
proof passes, I’ll know that these two dependent registers,
counter, are guaranteed to maintain their dependent relationship.
Hence, I can rely upon this dependency always being true within my
code–as I intended.
Certainly other internal code dependencies can exist as well–often more complex than this one. For example, a packet index or address might need to be zero any time the network is idle. As I recognize that I have such a dependency when writing my own code, I’ll often quickly write an assertion to capture it. Indeed, I do this so often that I’ll discuss how to go about this in the next section.
While writing code
Often, when I write RTL, I’ll come across a situation where I recognize some dependency within my code that must be hold true. Rather than write a fully defensive piece of code that handles any potential internal failure, it is often effective (and easier) to write a quick assertion to remind myself to come back later and place this into the list of formal properties at the end of the module.
Making sure I remember all of these dependencies later can be a hassle.
Here’s a method I’ve found useful for that purpose.
As I’m working on creating a module,
I’ll add any formal properties in line as I’m writing–but with the caveat that these ad-hoc properties are not indented like the rest of the code.
My development will then continue, returning to my original indentation scheme.
Some of my code, such as the dual I/O flash controller I mentioned above, depends upon the ability to peek at a bus request at certain times before accepting it. This requirement is easily captured by formal properties.
Knowing that I intend to use formal methods to verify a design helps to encourage me to write properties within my code as I write my code–even though I’ll place those at the end of the file later.
Some modules are just too critical not to use formal
Some interfaces I deal with are just too critical not to use formal methods to prove a design component before introducing it to hardware. For example, just one misbehaving bus component and the whole design will come crashing down.
Remember how this happened to me in my first Cyclone-V project? Before I got the formal properties of the Avalon bus just right, I had to deal with several cases of hardware lockup. It would seem as though a Cyclone-V can’t recover if my own logic fails to lower the wait request line, or equivalently if it returns random bus responses that don’t follow requests). In my case, only cycling power ever rescued my design, leaving me wondering what had happened.
If you’ve been reading this blog for a while, you may now recognize this purpose in the formal WB properties post. Bus control logic is just too sensitive to mess up. All it takes is one master missing a response to a request and your design may be locked up until a hard reset.
Cache controllers are another example, as they can be a real pain to get right. Worse, all it takes is one ugly caching error and you may be spending days (or weeks) looking in the wrong place to find the bug.
My recommendation, therefore, would be that you consider this principle for any portion of your design that, if it fails, will cause the whole design to fail while leaving you in FPGA Hell. Formally verify those components early in your design cycle, before ever placing them onto real hardware. Then verify them again any time you change them.
Some simple contracts
I’ve recently started looking at the designs I’m building as providing a service, and so when I start building the design I’ll often create a contract to describe the service that must be provided. These contracts are usually just a couple of lines of formal properties that describe outputs in relationship to the designs inputs. Such design contracts are often so fundamental that if the contract holds, the design will be 80% verified (or better).
Consider, for a moment, some simple peripherals from the standpoint of a “contract”.
Bus requests should always be followed by a bus response. There should be no more responses than there are requests.
An MMU should act as a bus bridge, between one set of addresses (the virtual ones) and another (the physical ones), while creating page misses for anything that doesn’t match.
The neat thing about these contracts is that they can help me prove that an item works–to include passing the induction step. Specifically, until the contract can be proven, the induction solver will keep presenting me with traces I need to examine. This helps me know how many properties I need to write.
Why do people think formal is hard?
After hearing that formal was too hard, I tried to gather all of the excuses I heard to see if there might be some merit to any of them.
Induction is harder than Bounded Model Checking (BMC)
Many of the simple examples I gave above would be perfect for bounded proofs. These proofs are only applicable for the first N steps (i.e the bound) following a reset. Bounded proofs are much easier than the full proofs, simply because in the case of a full proof you need to find ALL the internal dependencies. within your design and make them known to the formal engine via additional properties–whether they be assumptions or assertions. This can be a pain, and so I can understand that you might not wish to use induction at first. Even in this case, though, the bounded model check is still valuable–just not nearly as valuable as the full proof with induction.
Some modules are just too complex to prove using formal methods
This isn’t an excuse, nor should it be. It is just a reality.
While I’ve been able to prove all of the leaf modules of the ZipCPU, the complexity of the CPU as a whole has caused me to pause before diving into it. While I think I can formally prove that it works, the sheer complexity has caused me to pause.
The full System Verilog Assertions syntax can be confusing
If you’ve looked at the articles I’ve written so far regarding formal methods, you may notice that I haven’t used the full System Verilog Assertion (SVA) syntax. This is for two reasons.
First, the open source yosys synthesis tool that I’m using to get access to formal methods without re-mortgaging my home doesn’t understand this syntax (yet). Indeed, I’ve managed to formally verify many designs with only the subset that yosys supports. Since yosys is the tool I can afford, it’s the tool I’ve been using.
Second, I’m in the process of building a class in formal methods. This class includes a section on how to use the full SVA syntax: properties, sequences, clocking blocks, bind statements, and more. Since I’ve now been introduced to the full SVA syntax, my initial impressions are that it is very expressive, terse and compact, and as a result it is confusing to those who are not familiar with them. On the other hand, the
assumestatements I’ve used within always or initial blocks have been expressive enough for me, and simpler to understand.
It just happens that this simpler subset is also the set that yosys currently supports.
Fig 3. Just attaching VIP to a formal design doesn't usually work
What I mean by this is that attaching any vendor supplied Verification IP module to your design isn’t as simple as just instantiating the two components within the same design. The formal methods, and induction in particular, won’t work if you just plug and play related design pieces together such as Fig 3. attempts to show. This makes it more difficult to sell, purchase, or use vendor provided Verification IP with formal.
In order to connect an external set of formal properties, such as those from a piece of vendor supplied Verification IP, to the formal properties within your own design–relevant portions of the design need to be constrained to be properly dependent with the VIP. Success in this fashion is far more intrusive, and not nearly as simple as just purchasing someone else’s IP.
Perhaps a good example of this is my Wishbone bus arbiter. Internal to the Wishbone formal property IP modules are the counters necessary to insure that slaves will only respond to outstanding requests. This requires counting the number of requests, the number of acknowledgments, and then making certain that there are never more acknowledgments than requests. When I then try to use these properties within the bus arbiter to pass induction, the formal engine may set these counters to any initial value it wants. However, the arbiter is designed so that only one master can ever have access to the bus at a time. This means that the counters for the two slave inputs and the master output must be kept in sync. Doing this requires knowledge of the counters within the Wishbone propert module, enough so that I can assert that when one bus source has access to the bus, the other sources number of outstanding requests must remain at zero.
Even if your design doesn’t pass induction, (most big chip maker designs don’t) your formal properties may still be good enough to accomplish some purposes, since you can still find lots of bugs via a simple Bounded Model Check. You just can’t prove that your design will maintain those properties for all time.
Does it take a genius? Not really. Indeed, from my own experience, it just takes someone smart enough to write Verilog RTL in the first place.
Formal isn’t perfect
My thesis today is just that formal isn’t really any more difficult than normal RTL coding. Not only that, it fits nicely into the RTL coding process and even adds to it. Now that I’ve used it for a while, and now that I’ve found as many errors as I have using formal, I’m convinced from my own experience that it’s not really that hard. Indeed, if I had the choice today, I would find it difficult to start a project without the help formal methods provide.
While I was at the DVCon conference, I heard two fascinating comments regarding how valuable formal methods are, and many fascinating anecdotes. The first comment I scribbled down was that, “Without formal, 70% of the bugs in a design are found after the module is turned in. With formal, 80% of the bugs in a design are found before the module is turned in.” No, I’m not sure any more where these numbers came from, so if I can find the study I’d love to share it with you. The second comment was from one of the panelists who noted that a rough 80% of a verification engineer’s time is spent fixing the silly bugs. The implication in this statement was that, had only formal methods been used, the verification engineer wouldn’t need to be spending his time fixing the stupid mistakes.
Formal methods aren’t perfect. By that I mean that, in my own experience, I’ve still had to chase down bugs that “passed” a formal proof. These include problems with not constraining my design enough, with adding careless assumptions, and even misunderstood requirements.
However, I find formal methods easier to use than the alternative, and I also feel like I am finding more bugs by using them as part of my design process. As a result, I now use formal methods first, and then continue with simulation when I’m done.
Behold, I am the LORD, the God of all flesh: is there any thing too hard for me? (Jeremiah 32:27)