User:Dock3230/sandbox

Maia is a compiled Hardware verification language, and is designed specifically to verify designs written in the Verilog and VHDL Hardware description languages.

The language provides facilities to communicate with a DUT, and to automatically drive DUT inputs, sample and test DUT outputs, and advance time. Overall control is provided by a set of procedural imperative constructs, which are designed to be familiar (and in many cases identical) to those provided by C and related languages.

The compiler (or 'transpiler') produces Verilog output which is, in most cases, a stand-alone self-checking testbench. This must be run on an HDL simulator either under the simulator GUI or, more commonly, as a batch-mode command-line simulation.

Maia is generally used for running large sets of automated tests (unit, regression, or acceptance tests, for example). A Tcl test environment is provided with the compiler for automating test runs.

The language was created in the early 2000s by Evan Lavelle, as a means to eliminate the low-level and detailed VHDL and Verilog coding which was required to verify HDL modules, and to automate the creation of reusable self-checking testbenches.

Overview
HDL designs are normally verified directly in the language they are written in (Verilog or VHDL), but this requires a great deal of low-level detailed coding. This code is not directly related to the functionality of the DUT, and instead handles the language-specific details which are required to run a simulation, including:


 * Writing clock and reset generators
 * Defining and driving device inputs at the correct times
 * Recording device outputs at the correct times and comparing them to expected (static or dynamic) values
 * Pipeline setup and flush
 * Forcing internal signals
 * Avoiding race conditions
 * File I/O to read test stimulus, or expected output values

This coding becomes significantly more complex if the DUT includes timing information (as a back-annotated netlist, for example) and the testbench must be written to exercise and verify the worst-case DUT timing.

This complexity means that verifying a hardware module can be significantly more difficult than actually writing it. The skills required to write a Verilog or VHDL testbench also differ from those required to code the hardware to be tested, since they are essentially Software engineering, rather than Electronic engineering. It is common for Electronic Engineers to be proficient only in the 'synthesizable subset' of their preferred HDL, and this subset does not include the language features required to write a testbench. This means that, in many cases (particularly in FPGA design), hardware is poorly verified, and verification is replaced with lab testing, which can greatly increase development times.

Maia addresses these issues by generating self-checking testbenches, with no requirement for low-level coding, primarily through the use of drive statements. Information about the DUT must be provided in a 'DUT section', which includes a declaration of the module and any internal signals to be tested, along with the required clocks and, if required, signal timing information.

The language is intended to be used by RTL engineers to verify their own designs or, for example, by technical authors, who do not have the detailed VHDL or Verilog knowledge required to exercise a DUT.

Drive statements
Drive statements provide a mechanism to drive a defined subset of the DUT inputs, and to test the resulting outputs. In the simplest case, static values are applied to the inputs, and the output is tested against another static value at some later time. This code, for example, is a complete test for a single 2-input AND gate:

If this code is saved in file, and file   contains an implementation of an AND gate, then that implementation can be tested as follows:

If the gate implementation is correct, the simulation output is as follows:

The compiler produces Verilog output, which is run in a batch-mode simulation by the  driver. is not an HDL simulator: it simply runs the simulation on a pre-installed Verilog simulator (which must support IEEE 1364-2005, and which must be a dual-language simulator if the test module is coded in VHDL).

Drive statements can contain directives as well as values to drive or test against. The  directive, for example, instructs the testbench to drive a clock waveform on a given DUT input, or to respond to a clock signal on a DUT output. The clock must be declared in the DUT section with a  statement, which allows the compiler to identify the relevant DUT pin, and the clock waveform.

A program which is entered in this form is known as a test vector program, and can contain only a DUT section, and a list of test vectors. These vectors can contain only constant values for input driving and output testing (the signals on the left and right of the drive statement are generally referred to as DUT 'inputs' and 'outputs', respectively, but the only requirement is that the relevant signal can be driven or read, and a bidirectional signal may appear on both sides of the statement). This simple test vector form was influenced by ABEL test vectors. ABEL is now obsolete, but was historically used for the definition and test of PAL devices.

The test vector form is generally of limited value, and tests are normally written in an alternative procedural form. In this second form, the program must contain at least one function, which is named. Drive statements must now appear inside a function, and can contain arbitrary expressions, rather than just constant values. The use of control flow constructs in a function allows tests to be 'reactive' (in other words, to respond to the current state of the DUT), while the use of expressions in the drive statement allows DUT inputs and expected outputs to be derived algorithmically.

Device timing parameters may be entered in the DUT section as input setup and hold times, and output hold and delay times, for both program forms. If timing parameters are present, the drive statement drives the relevant inputs with worst-case timing, and tests the relevant outputs to confirm that they are valid (and do not glitch) throughout the 'stability window' defined by the output hold and delay parameters.

If timing parameters are not present, the simulation is carried out as a unit-delay simulation. In this context, 'unit delay' means that, for synchronous logic (in other words, for a drive statement for which a relevant  declaration can be found), the inputs are driven 'just before' the clock edge, and the outputs are tested 'just after' the clock edge. For combinatorial logic, the compiler defines a pseudo-'cycle time', and chooses a point in the cycle at which to drive the inputs, and tests outputs 'just after' this time.

Logic system
Maia uses a two-value ( and  ) logic system for   objects, and a 4-value logic system (,  ,  , and  ) for   objects. The 4-value system is the same as Verilog's 4-value system; X denotes an unknown value, while Z denotes tri-state.

The AND gate example above can be extended to confirm X-propagation through the gate by adding these vectors:

Procedural language
There are a number of language features which are specifically related to accessing the DUT, concurrency, and advancing time. The remaining constructs form a simple imperative procedural language which is intended to be familiar to users of C and related languages. This is both statically and dynamically typed, and lexically scoped.

A program consists of a sequence of external declarations, which are either declarations or function definitions. The program has a  entry point. The language has a full set of control flow primitives:,  ,  ,  ,  , and.

The expression syntax is almost identical to C, although Maia adds a number of operators. Scoping is, for all practical purposes, identical to C scoping (within a given source file).

The main changes and simplifications are as follows:


 * 1) An entire program must be compiled at the same time, as a single compilation unit (in the same way as Verilog or Pascal, for example); there is no provision to link separately-compiled units
 * 2) There are no pointers. However, parameters can be  passed by reference to functions (in the same way as C++)
 * 3) There is no standard library, although a small number of functions (,  ,  , and so on) are built into the language
 * 4) The primary difference between Maia and C is in the handling of 'data' types. Maia has three basic data types:
 * 5)   is a 2-state signed 'small' integer with a fixed width (which defaults to 32 bits). This type is of little value in hardware description or verification, but is useful for general software 'housekeeping': loop indexing, counting, and so on
 * 6)   is a 2-state data type; the n denotes the number of bits in the type (a , for example, is a 192-bit 2-state type)
 * 7)   is a 4-state data type; the n denotes the number of bits in the type. The 4 states are the same as the Verilog states: ,  ,  , and
 * 8) In addition to the data types, there is a boolean type, a structure type , a stream type , and an array type
 * 9) Arrays are first-class objects, and are declared using a Java-style syntax (which is a superset of C syntax). Both   and   are supported, for example, although the latter is preferred since it can be used to declare functions which return arrays. Multi-dimensional arrays can be declared with either Algol-style or C-style syntax (  is equivalent to  ). The latter style is more familiar to VHDL programmers, and more convenient when accessing arrays with several dimensions (these include Karnaugh maps, for example, which can be declared and manipulated directly in Maia)
 * 10) Concurrency is built into the language. The   statement creates a new thread, and initiates execution of a function in that thread. This is particularly useful for DUTs which have multiple asynchronous clocks, or which have an interface which produces data at times which cannot easily be predicted

The data type specialisations include  and , which are unconstrained   and   types. These have no predefined size, and take their size from the context. This program, for example, declares 8 variables with sizes ranging from 1 to 8 bits, and checks the parity of each variable:

When run, this (complete) program produces the output, confirming that 8 assertions were executed, with no failures. This program uses a number of other language features:


 * is a predefined variable, and the current value of  is returned in the absence of an explicit  . In this case,   is of type , and so automatically initialises to  . However, it is common to explicitly initialise variables, for clarity
 * uses the bitslice operator to select a single bit in . The selection is dynamic in this case, and so cannot be checked for correctness during compilation. The index is instead checked at runtime, and a runtime error is raised if it is out of range
 * is the attribute operator;  returns the number of bits in
 * The level of type checking is set by a, and defaults to approximately C-like. In this case, this means that each bit of   can be XORed with a boolean value
 * The language has a number of predefined variables which have a leading  in their name. These are normally used for reporting test results
 * It is not necessary to declare  before its use in this program. A compiler pre-pass finds external objects and allows them to be forward-referenced
 * There is no requirement to include any 'standard header files'

Operators
A hardware register is likely to contain a data pattern which can be interpreted in many different ways at different times. It might, for example, contain a 2's-complement integer, or a block floating-point value, or a fixed-point value. The normal software approach to modelling this complexity is to create a specific type which can be used to represent the current data interpretation. In this simple case, we require three types: one for signed integers, one for block floating-point, and one for fixed-point. We can then define an operator, such as a multiplication operator, for objects of these types. A single  operator, for example, might be defined to carry out all of signed integer multiplication, block floating-point multiplication, and fixed-point multiplication. This is the essence of Object-oriented programming. In OOP, the object is central. Objects have a specific type, and the type has multiple properties which define what can be done with objects of that type, and how.

While this is a proven paradigm for general-purpose high-level programming, it is a poor fit for the description and verification of electronic hardware. A register is simply a register, and holds a binary data value. At different times, the register may be connected to function units which carry out two's complement multiplication, block floating-point multiplication, or fixed-point multiplication. In this paradigm, complexity is provided by operators (the function units), and not by objects (the registers or memory locations).

Maia takes this second approach, and models hardware in much the same way that it would appear on a schematic. Data objects have no properties apart from their size, and whether they represent 2-state or 4-state data. These objects are therefore not 'signed', or 'unsigned', or 'floating point': they are simply data. Complexity is provided by operators, rather than types.

The operators in Maia are generally identical to those in C, except that Maia adds bitslice and rotate operators, and some attribute operators. None of the C operators related to pointers are supported. Where the operators are identical, Maia and C have identical precedence and associativity. The basic operator symbol is followed by, in order:


 * 1) An optional   character, which represents a 'signed' operator
 * 2) An optional , where n represents the operator size

A signed operator is identical to a default 'unsigned' operator, except that:


 * 1) It sign-extends the inputs (which are expected to be 2's complement) if necessary
 * 2) It may have a different behaviour from its unsigned counterpart (signed and unsigned comparisons have different behaviour, for example)

Some examples of operators are:

Operators generally precisely specify the required operation, rather than relying on the compiler to deduce the programmer's intent from the surrounding context. However, in some circumstances it would be tedious to continuously write, for example, where a datapath is known to be exclusively 96-bit. Maia does therefore deduce the required operator size when a base unsized integer or logic operator is used. The procedure used is the normal one: for binary operators, for example, an unsized operator is assumed to be the same size as the larger of the two operands. On assignment, the result is truncated if necessary. If the result has to be extended on assignment, then it is zero-extended for a plain assignment, and sign-extended for a signed assignment.

Hello World
Maia's character set is UTF-8. However, the underlying simulator may support only the printable ASCII character set, in which case this program will display incorrectly (although UTF-8 may be used in variable names and comments without problems). Note that there is no DUT section in this program: this is only required when it is necessary to instantiate and access a DUT.

MAC module test
This program verifies a DUT which implements a configurable MAC. The DUT has two 4-bit inputs, and a 10-bit output; it has a configurable pipeline depth, which is set by the  parameter. The DUT is tested by cycling through all combinations of the two 4-bit inputs, and checking the resulting 10-bit output at each step (after the appropriate pipeline delay). The module declaration in the DUT section is translated into a module instantiation in the compiled output, and the  parameter is set to the defined value of , thus setting the pipeline depth:

If the HDL module is correctly coded, the testbench reports:

Note that the testbench runs for 260 cycles (at the default period of 10ns), rather than the 258 cycles which might be expected for the 258 test operations. The additional 2 cycles are required to flush the pipeline, and extract the final two values for testing. The pipeline load and flush are handled automatically by the compiler.

The  construct can be used to simplify loops over the range of a 'small' variable. The loop above can be replaced with:

Transpiler limitations
The reference compiler currently produces 'vanilla' Verilog (which conforms to IEEE 1364-2005 ). 1364-2005 was the last release of the original Verilog language. This ensures maximum compatibility with free simulators, and may also allow the use of cheaper versions of commercial SystemVerilog simulators. However, Verilog has significant limitations, in areas including memory management, the implementation of fully automatic functions, and access to the underlying hardware. These limitations are reflected in a number of restrictions and lack of functionality in the current compiler output, which are:


 * 1) Recursive functions are not supported; the compiler raises an error when a function attempts to call itself
 * 2) There is no string data type, and string manipulation is not supported
 * 3) There are no managed list objects (associative arrays, and so on)
 * 4) Floating-point arithmetic is restricted to double precision, with no ability to set up the hardware FPU
 * 5) Maia's   output uses C   syntax. Verilog has equivalent functionality, but it is poorly defined, and there are implementation differences between different simulators.   output is therefore not guaranteed to display identically when running with different simulators.

Resources
A free ('gratis') compiler can be downloaded from the, together with the Language Reference Manual.