lec4_HighLevelModel

download lec4_HighLevelModel

of 39

Transcript of lec4_HighLevelModel

  • 8/10/2019 lec4_HighLevelModel

    1/39

    High-Level Modeling

    Lecture 4

    Introduction to Verification1

  • 8/10/2019 lec4_HighLevelModel

    2/39

    Outline

    RTL-Thinking vs High-Level Thinking Structure of High-Level Code

    Object-Oriented Programming

    Parallel Simulation Engine Simulation Cycle

    Introduction to Verification2

  • 8/10/2019 lec4_HighLevelModel

    3/39

    RTL-Thinking vs High-Level Thinking

    Why verification engineer must break the RTL Mindset?

    Insufficient in writing testbenches that was never intended to implement

    in hardware

    Numerous guidelines have been imposed to obtain efficient

    implementation If RTL mindset is keptverification task becomes tedious and complicated

    Introduction to Verification3

  • 8/10/2019 lec4_HighLevelModel

    4/39

    RTL-Thinking vs High-Level Thinking

    To avoidlatches

    set all outputs ofcombinatorial blocksto default values at

    the beginning of theblock

    To avoidinternal buses

    do not assignregistersfrom

    two separate alwaysblocks

    To avoid tri-state buffers

    do not assign thevalue Z (VHDL) or1bz(Verilog)

    Introduction to Verification4

    RTL Guidelines: Avoiding Undesirable Hardware Structures

  • 8/10/2019 lec4_HighLevelModel

    5/39

    RTL-Thinking vs High-Level Thinking

    Introduction to Verification5

    All inputs must be listed in the sensitivity list of acombinatorial block

    The clock and synchronous reset must be in thesensitivity list of a sequential block

    Use a nonblocking assignment when assigning to a regintended to be inferred as a flip-flop

    RTL Guidelines: Maintaining the Simulation Behavior

  • 8/10/2019 lec4_HighLevelModel

    6/39

    RTL-Thinking vs High-Level Thinking

    Introduction to Verification6

    The example above shows a simple handshaking protocol

    Example:

  • 8/10/2019 lec4_HighLevelModel

    7/39

    RTL-Thinking vs High-Level Thinking

    Introduction to Verification7

    enum {,MAKE_REQ,

    RELEASE, }state, next_state;

    always_comb

    begin

    next_state

  • 8/10/2019 lec4_HighLevelModel

    8/39

    Synthesizable subset puts several constraints on your coding style

    With no restrictions in high-level modeling, unmaintainable, fragile

    and not portable code is easy to achieve

    Must have disciplinecode will need to be modified

    Assume an inexperienced audience

    Introduction to Verification8

    Coding Style

  • 8/10/2019 lec4_HighLevelModel

    9/39

    Structure of High-Level Code

    Structuring code is the process of allocating portions of thefunctionality to different modules or entities

    For maintainability reasons, high-level code is structured according to

    functionality or need

    Introduction to Verification9

  • 8/10/2019 lec4_HighLevelModel

    10/39

  • 8/10/2019 lec4_HighLevelModel

    11/39

    Structure of High-Level Code

    Introduction to Verification11

    Application of structuring principlethat enables to hide implementationdetails and decouple the usage of afunction from its implementation

    A technique for minimizinginterdependencies among modules by

    defining a strict externalcommunication

    internal coding can be changedwithout affecting the communication,so long as the new implementationsupports the same (or upwardscompatible) external communication

    Prevents a program from becoming sointerdependent that a small change

    has massive ripple effects

    Encapsulation

  • 8/10/2019 lec4_HighLevelModel

    12/39

  • 8/10/2019 lec4_HighLevelModel

    13/39

    Encapsulation

    SystemVerilog tasks andfunctions can contain local variables

    task send(input [7:0] data);

    reg parity;

    ...

    endtask

    function [31:0] average (input [31:0] val1,

    input [31:0] val2);

    reg [32:0] sum;

    sum = val1 + val2;

    average = sum / 2;

    endfunction

    Introduction to Verification13

  • 8/10/2019 lec4_HighLevelModel

    14/39

    Encapsulation

    Local variables can be created while minimizing their scope and

    potential undesirable interaction.

    function bit eth_frame::compare(eth_frame to);

    compare = 0;...if (this.data_len !== to.data_len) return;begin

    int i;for (i = 0; i < this.data_len; i++) begin

    if (this.data[i] !== to.data[i])

    return;end

    end

    ...compare = 1;endfunction: compare

    Introduction to Verification14

  • 8/10/2019 lec4_HighLevelModel

    15/39

    Encapsulation

    The scope of variables used solely as for-loop iterators can be further

    reduced by declaring them within the loop statement, ofteneliminating the need for a begin/end block

    function bit eth_frame::compare(eth_frame to);

    compare = 0;

    ...if (this.data_len !== to.data_len) return;

    for (int i = 0; i < this.data_len; i++) begin

    if (this.data[i] !== to.data[i])

    return;

    end

    ...

    compare = 1;

    endfunction: compare

    Introduction to Verification15

  • 8/10/2019 lec4_HighLevelModel

    16/39

    SystemVerilog has classes, modules, programs, interfaces andpackages to encapsulate any declaration used in more than one

    partition.

    Functions should be packaged in a class and used via a local instance

    - It is preferable to use classes to encapsulate shared declarations.

    - The encapsulating class will be added to the $root name spaceand thusshould be carefully named to avoid collisions.

    - Classes unlike modules, must be explicitly instantiated using the new

    constructor.

    static variables can replace global variables

    Introduction to Verification16

    Encapsulation: Useful Subprograms

  • 8/10/2019 lec4_HighLevelModel

    17/39

    Introduction to Verification17

    Encapsulation: Bus-Functional Models

    Stimulus applied to the design under verification via complex waveforms andprotocols can be implemented using tasks, called bus-functional models.

    drives and

    samples low-level

    signals accordingto a predefined

    protocol

    tasks are available

    to initiate a

    transaction withthe specified data

    values

  • 8/10/2019 lec4_HighLevelModel

    18/39

    Encapsulation By default, SystemVerilog arguments are passed by value when the task is called

    and when it returns. At no other time can a value flow into or out of a task via itsinterface.

    Introduction to Verification18

    class arbiter;

    task request(ref output logic

    bus_rq,ref input logic bus_gt);

    // The new value will "flow" out

    bus_rq

  • 8/10/2019 lec4_HighLevelModel

    19/39

    Object-oriented Programming (OOP)

    The next evolutionary step in language design after structured

    programming

    Used to identify a methodology that makes use of (and a language that

    supports) classes, inheritance and polymorphism

    SystemVerilog is object-oriented

    Introduction to Verification19

  • 8/10/2019 lec4_HighLevelModel

    20/39

    OOP: Class

    A user-defined data type

    A collection of variables and subprograms that create object types

    Consists of:

    o data members (class properties)

    o tasks and functions to access the data (methods)

    Introduction to Verification20

  • 8/10/2019 lec4_HighLevelModel

    21/39

  • 8/10/2019 lec4_HighLevelModel

    22/39

    OOP: Class

    Introduction to Verification22

    Data Members

    consume memory

    each data member is local to

    each object instance can be global as well

    Methods do not consume memory

    are global to the class

    f

  • 8/10/2019 lec4_HighLevelModel

    23/39

    OOP: Class

    A simple class declaration:

    class C;

    int x;

    task set (int i);

    x = i;endtask

    function int get;

    return x;

    endfunction

    endclass

    Introduction to Verification23

    data member

    methods

    d i ifi i24

  • 8/10/2019 lec4_HighLevelModel

    24/39

    OOP: Class

    An object must be created to use the class:

    C c1; or C c1 = new;c1 = new;

    Having created a class object, we can use the class methods to assign andlook at the data value, x:

    initial

    begin

    c1.set(3);$display("c1.x is %d", c1.get());

    end

    Introduction to Verification24

    I d i V ifi i25

  • 8/10/2019 lec4_HighLevelModel

    25/39

    OOP: Class

    Not objects:

    o Modules & interfaces

    are hierarchical constructs, not data structures

    cannot be assigned nor passed to tasks or functions as arguments

    cannot be compared or used in expressions

    o Packages- cannot be instantiated

    Introduction to Verification25

  • 8/10/2019 lec4_HighLevelModel

    26/39

    I t d ti t V ifi ti27

  • 8/10/2019 lec4_HighLevelModel

    27/39

    OOP: Inheritance

    parent or base classoriginal class

    derived class

    o the new class inheriting from the base

    o inherits the properties and methods of its parent or base class

    o may add new properties and methods, or modify the inherited propertiesand methods

    In SystemVerilog the syntax for deriving or inheriting one class from

    another is this:

    class Derived extends BaseClass;

    // New and overridden property and method declarations

    endclass

    Introduction to Verification27

    Introduction to Verification28

  • 8/10/2019 lec4_HighLevelModel

    28/39

    OOP: Inheritance

    Consider the example of the class Register:

    class ShiftRegister extends Register;

    task shiftleft; data = data > 1; endtask

    endclass

    Introduction to Verification28

    Introduction to Verification29

  • 8/10/2019 lec4_HighLevelModel

    29/39

    OOP: Polymorphism

    polymorphism means to have many forms

    classes on different branches can be treated as if they were the same

    class, when viewed as a common base class

    the ability to request that the same operations be performed by a

    wide range of different types of things

    o you can ask many different objects to perform the same action allows the redefining of methods for derived classes while enforcing a

    common interface

    o the 'virtual' identifier must be used when defining the base class and

    method(s) within that class

    Introduction to Verification29

  • 8/10/2019 lec4_HighLevelModel

    30/39

  • 8/10/2019 lec4_HighLevelModel

    31/39

    Introduction to Verification32

  • 8/10/2019 lec4_HighLevelModel

    32/39

    Connectivity, Time, and Concurrency

    Randomization, Constrainability,

    Functional coverage measurement

    Introduction to Verification32

    Parallel Simulation Engine

    C

    C++

    Why hasnt C/C++ been used as a hardware description language

    lacks three fundamental concepts for hardware designs modeling

    lacks three necessary features to support the verification productivity cycle

    Introduction to Verification33

  • 8/10/2019 lec4_HighLevelModel

    33/39

    Features necessary to support the verification productivity cycle

    Randomization

    Constrainability

    Introduction to Verification33

    - increases the probability that youll take a different path in

    each test case

    - creates several constraints to ensure the correctness of your

    random stimulus, known as valid constraints

    - define the boundaries within which the randomization feature works- You can add weights so that certain sets of stimuli occur more often than

    others, that is you can change the distribution function, and

    - you can use the current state of the design to change these weights and

    consequently the constraints for the next state

    - complements the traditional code coverage by making sure all the

    functionalities of the chip or system are fully verified- Coverage objects to make sure that the chip or system perform

    defined coverage goals

    Parallel Simulation Engine

    Functional coveragemeasurement

    Introduction to Verification34

  • 8/10/2019 lec4_HighLevelModel

    34/39

    Fundamental concepts necessary to model hardware designs:

    Connectivity

    Time

    Concurrency

    Introduction to Verification34

    - the ability to describe a design using simple blocks thenconnecting them together.

    - implemented by directly instantiating modules and interfaces

    within modules, and connecting the pins of the modules and

    interfaces to wires or registers

    - the ability to represent how the internal state of a design

    evolves over time and to control its progression and rate

    - implemented by using timing control statements such as @

    and wait

    - the ability to describe actions that occur at the same time,independently of each other

    - implemented through separate alwaysand initialblocks

    Parallel Simulation Engine

    Introduction to Verification35

  • 8/10/2019 lec4_HighLevelModel

    35/39

    Introduction to Verification35

    The Problems with Concurrency:

    Concurrent systems are difficult

    to describe

    Concurrent systems are described

    using a hybrid approach

    they proved much more difficult toprogram

    difficulty may originate from the

    mindset imposed by the early Von

    Neumann architecture still used in

    todays processors, or by an innate

    limitation of our intellect

    human beings are adept atperforming relatively complex tasks

    in parallel

    Parallel Simulation Engine

    Introduction to Verification36

  • 8/10/2019 lec4_HighLevelModel

    36/39

    Emulating Parallelism on a Sequential Processor

    Concurrent threads must be executed on single processor machines

    Multi-tasking operating systems are like simulators.

    Simulators are time-sharing machine

    Simulator do not have time slice limits

    Processes simulate until they execute a timing statement

    Introduction to Verification36

    Parallel Simulation Engine

  • 8/10/2019 lec4_HighLevelModel

    37/39

    Introduction to Verification38

  • 8/10/2019 lec4_HighLevelModel

    38/39

    Introduction to Verification38

    The Simulation Cycle

    Advance Time

    Sampleclocking blocks

    Execute module

    threads

    Assign zero-delay

    nonblocking values

    Evaluate

    assertions

    Execute program

    threads

    1

    2

    3

    If there is nothing left to be done at the current time,

    there must be either:

    1. A thread waiting for a specific amount of time

    2. A nonblocking value to be assigned after a non-zero

    delay

    Introduction to Verification39

  • 8/10/2019 lec4_HighLevelModel

    39/39

    Summary

    RTL mindset leads to tedious and complicated verification task.

    Coding Style- Always strive for maintainability.

    High-level code is structured according to functionality or need for

    maintainability reasons.

    Object-oriented Programming (OOP) - define data type of a data structure and

    types of operations (functions) that can be applied to the data structure.

    Parallel Simulation Enginerandomization, constrainability, functional

    coverage measurement,connectivity, time and concurrency.

    Simulation Cycle

    oModule threads -model the design.

    oProgram threads-model the test bench.

    39