Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

43
Formal Methods in Hardware Design Mary Sheeran, Chalmers www.cs.chalmers.se/~ms

Transcript of Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Page 1: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Formal Methods in Hardware Design

Mary Sheeran, Chalmers

www.cs.chalmers.se/~ms

Page 2: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Formal Methods

• Mathematical and logical methods used in system development

• Aim to increase confidence in riktighet of system

• Apply to both hardware and software

Page 3: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Formal methods

• Complement other analysis methods

• Are good at finding bugs

• Reduce development (and test) time

• Should ideally be automatic

Page 4: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

The main point is NOT

• correctness proof of entire systems

• replacing test entirely

Page 5: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

BUT

• one proof can replace many test cases

• formal methods can be used in automatic test case generation

Page 6: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Successful formal methods

• Integrated in the design flow

• Avoid new demands on the user

• Work at large scale

• Save time or money in getting a good quality product out

Page 7: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Some fundamental facts

Low level of abstraction, Finite state systems

=> automatic proofs possible

High level of abstraction, Fancy data types, general programs

=> automatic proofs IMPOSSIBLE

Page 8: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Two main approaches

• Squeeze the problem down into one that can be handled automatically– industrial success of model checkers– automatic proof-based methods very hot

• Use powerful interactive theorem provers and highly trained staff– for example Harrison’s work at Intel on floating

point algorithms

Page 9: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Model Checking

MC

G(p -> F q)yes

nop

q

p

q

property

finite-state model

algorithm

counterexample

(Ken McMillan)

Page 10: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Model checkers usually based on BDDs

• Binary Decision Diagrams

• Data structure for representing and manipulating boolean functions

• More later...

Page 11: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Proof-based method

High levelrequirements

High leveldesign

Logicalformula

Logicalformula

Compilation

Proof

Compilation

Page 12: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Interactive theorem proving

• Formalise system and requirements in a suitable logical language

• Gradually construct a proof that the system meets the requirements– Computer checks all steps

• Slow, expensive, divorced from production

• Sometimes the only way!

• HOL, PVS, Coq, Isabelle ....

Page 13: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Refinement

• Formal method used during design

• Start with abstract specification

• Decompose into communicating parts

• Refine parts, adding details, and check each step (proofs)

• stop at components that are already implemented

• B method (Paris Metro driverless train)

Page 14: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Concentrate on hardware

• An easier application for formal methods

• Price of getting it wrong is high!

• Stronger tradition of analysis methods (e.g. use of boolean algebra in synthesis, need to do ATPG)

Page 15: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Nov. ’94 Intel FPU bug

• 824633702441.0 times (1/824633702441.0) = 0.99999999274709702

• Fault in look-up table

• COST $475.000.000

Page 16: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

$15 per transistor!!

• Answer ?? IP blocks and system level design language

• ”We are heading for a brick wall”

• ”We can’t fill the fabs”

• ”A first requirement is a formal semantics”

Page 17: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Interactive methods

• Hawk (Haskell in top level design of pipelined superscalar processors, OGI/Intel)

• IBM and AMD both do processor verification using the interactive theorem prover ACL2

Page 18: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Automatic methods

• Finite state

• BDD based verification widespread

– emphasison cost saving– not on guaranteed correctness– used in production 50% verification engineers

Page 19: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Binary Decision Diagrams

• Idea from 70s (maybe earlier)• Adapted by Bryant ’86• Take a formula• Make decision tree for fixed variable order• Reduction rules

– merge duplicate nodes– both children point to same node -- remove

redundant node

Page 20: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Plus points

• Efficient algorithms exits (and, or, not, exists, forall …)

• For given variable order, BDD is canonical

• Many common functions have small BDDs

Page 21: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Minus points

• Some functions are exponential (independent of variable ordering)– multipliers 16 by 16 bit around 3.300 Mbytes

• Variable order essential– change order : linear to exponential– packages use dynamic reordering

• Injecting error can cause BDD to explode

Page 22: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Exercise

• Make BDD for x xor y xor z

Page 23: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Rest of lecture

• Some selected BDD based methods (Alan Hu paper)

• What actually happens at Intel

• A glimpse of our research

Page 24: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Combinational equivalence checking

• Build BDDs of outputs in terms of (same) primary inputs. Build up gradually and just compare

• Even for suitable circuits, limit is a few hundred primary inputs -- need tricks

Page 25: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Symbolic simulation

– Constants 1 0– unknown X– symbolic values a,b,c…

• Adapt logic simulation to represent values on wires

• BDDs represent functions of symbolic values

Page 26: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

• X halves # simulation runs but loses info.

• a halves # runs but makes BDDs bigger

• Tradeoff

• See also Lava, ACL2 (Rockwell)

Page 27: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Sequential equivalence checking• Compare sequential circuits by symbolic

simulation (regard as finite state machines)

• Is out always high (safety property) for all reachable states?

=

=

&out

Page 28: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Compute reachable states

1 Set of states as BDD– ex. 3 bool vars (one per latch)– a + b represents {100,101,110,111,010,011}– T represents all 8 states

2 Image (applying the transition relation R)– AND (BDDs for present state and R)– Existentially quantify out vars for primary

inputs and present state

Page 29: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

• Fixed point iteration– R0 = BDD for reset state– R1 = R0 + Image(R0)– …– R(i+1) = Ri + Image(Ri)

• Ri set of states reachable in i or fewer clock ticks• Eventually Ri = R(i+1)• Copes with ~200 latches

Page 30: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Model checking

• Clarke/Emerson/Sistla et al ’83

• Express properties in temporal logic

• Check if state machine satisfies property– AG EF (reset) – AG (req => AF ack)

• Generalisation of reachability analysis

• Same limits

Page 31: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Symbolic Trajectory Evaluation• Symbolic simulation + temporal stuff

• Limit expressiveness >> automation

• Trajectory formula– can specify values of circuit nodes for bounded

# of events into the future– no negation or disjunction

• Unique symbolic simulation vector captures all behaviours satifying formula >> one run gives verification

Page 32: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

• Problem is writing down the necessary specifications in this funny language

• Too many symbolic variables >> BDD blowup

• Can instead use a SAT solver (e.g. Recent work at Compaq by Bjesse from our group)

Page 33: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

General problem

• BDD blowup– verify subsystems (eg Ericsson)– use abstractions (ie verify a simplified and

smaller version)

• Still, BDD based verification very successful!

• Alternative is SAT based methods (our speciality) or combinations of methods

Page 34: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Large scale hardware verification at Intel

• Formal verification methodology for datapath-dominated hardware

• Algorithmic developments in basic tools not enough

• Need a systematic approach to organising activities in large scale verification

Page 35: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Forte: a formal verification environment

• Efficient model checker (STE)

• Lightweight theorem prover

• Interfaced to and tightly integrated with FL, a general purpose functional programming language

• FL is both specification language and scripting language

Page 36: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Phases

1 Understanding the circuit and its operating environment– FL circuit description (API)

2 Simple checking of circuit against specification– functional spec., improved circuit API, concrete

test vectors for regression testing

Page 37: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Phases

3 STE– improved specification, detailed info. for model

checker, characterisation of parts of input space for which MC works

– all of the above are FL programs– most bugs found in this phase

Page 38: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Theorem proving

4 Check correctness of specification and soundness of decomposition into MC cases– Final functional specification, perhaps proofs of

properties of the specification– top-level correctness statement, collection of

MC runs and a mechanized proof conneting these two

Page 39: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Results

• Used in production (large scale)

• Use of a functional language vital

• Stresses usability (but more work needed)

• Aims at reuse of proofs

• Similar methods used at Motorola

Page 40: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Formal methods at Chalmers

• Lava: an FPGA design system based on the functional progamming language Haskell– state of the art formal verification methods

combined with advanced programming language features

– Haskell used as scripting language

– a version that gives fine control of layout developed and used at Xilinx Inc.

– interesting for prototyping on FPGA

Page 41: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Butterfly Layout on an FPGA

Page 42: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Shameless advertising

• Course in LP4

• Hardware description and verification– What is a HDL?– VHDL + model checking– Lava (Haskell plus automatic verification)

Page 43: Formal Methods in Hardware Design Mary Sheeran, Chalmers ms.

Future Trends

• Design methods and coding rules that make necessary proofs easier

• Combining automatic verification methods using simple theorem provers

• Combining test and formal verification