• 沒有找到結果。

Unified Hardware Design, Specification, and Verification Language

3. Design and verification building blocks

3.14 Simulation time units and precision

An important aspect of simulation is time. The term simulation time is used to refer to the time value maintained by the simulator to model the actual time it would take for the system description being simulated. The term time is used interchangeably with simulation time.

Time values are used in design elements to represent propagation delays and the amount of simulation time between when procedural statements execute. Time values have two components, a time unit and a time precision.

The time unit represents the unit of measurement for times and delays, and can be specified in units ranging from 100 second units down to 1 femtosecond units.

The time precision specifies the degree of accuracy for delays.

Both the time units and time precision are represented using one of the character strings: s, ms, us, ns, ps, and fs with an order of magnitude of 1, 10, or 100. The definition of these character strings is given in Table 3-1.

Table 3-1—Time unit strings Character string Unit of measurement

s seconds

ms milliseconds

us microseconds

ns nanoseconds

ps picoseconds

fs femtoseconds

VERIFICATION LANGUAGE

NOTE—While s, ms, ns, ps, and fs are the usual SI unit symbols for second, millisecond, nanosecond, picosecond, and femtosecond, due to lack of the Greek letter (mu) in coding character sets, “us” represents the SI unit symbol for microsecond, properly .

The time precision of a design element shall be at least as precise as the time unit; it cannot be a longer unit of time than the time unit.

3.14.1 Time value rounding

Within a design element, such as a module, program or interface, the time precision specifies how delay values are rounded before being used in simulation.

The time precision is relative to the time units. If the precision is the same as the time units, then delay values are rounded off to whole numbers (integers). If the precision is one order of magnitude smaller than the time units, then delay values are rounded off to one decimal place. For example, if the time unit specified is 1ns and the precision is 100ps, then delay values are rounded off to one decimal place (100ps is equivalent to 0.1ns). Thus, a delay of 2.75ns would be rounded off to 2.8ns.

The time values in a design element are accurate to within the unit of time precision specified for that design element, even if there is a smaller time precision specified elsewhere in the design.

3.14.2 Specifying time units and precision

The time unit and time precision can be specified in the following two ways:

— Using the compiler directive `timescale

— Using the keywords timeunit and timeprecision 3.14.2.1 The `timescale compiler directive

The `timescale compiler directive specifies the default time unit and precision for all design elements that follow this directive and that do not have timeunit and timeprecision constructs specified within the design element. The `timescale directive remains in effect from when it is encountered in the source code until another `timescale compiler directive is read. The `timescale directive only affects the current compilation unit; it does not span multiple compilation units (see 3.12.1).

The general syntax for the `timescale directive is (see 22.7 for more details):

`timescale time_unit / time_precision

The following example specifies a time unit of 1 ns with a precision of 10 ps (2 decimal places of accuracy).

The compiler directive affects both module A and B. A second `timescale directive replaces the first directive, specifying a time unit of 1 ps and precision of 1 ps (zero decimal places of accuracy) for module C.

`timescale 1ns / 10ps module A (...);

...

endmodule module B (...);

...

endmodule

`timescale 1ps/1ps module C (...);

μs μ

...

endmodule

The `timescale directive can result in file order dependency problems. If the three modules above were compiled in the order of A, B, C (as shown) then module B would simulate with time units in nanoseconds. If the same three files were compiled in the order of C, B, A then module would simulate with time units in picoseconds. This could cause very different simulation results, depending on the time values specified in module B.

3.14.2.2 The timeunit and timeprecision keywords

The time unit and precision can be declared by the timeunit and timeprecision keywords, respectively, and set to a time literal (see 5.8). The time precision may also be declared using an optional second argument to the timeunit keyword using the slash separator. For example:

module D (...);

timeunit 100ps;

timeprecision 10fs;

...

endmodule module E (...);

timeunit 100ps / 10fs; // timeunit with optional second argument ...

endmodule

Defining the timeunit and timeprecision constructs within the design element removes the file order dependency problems with compiler directives.

There shall be at most one time unit and one time precision for any module, program, package, or interface definition or in any compilation-unit scope. This shall define a time scope. If specified, the timeunit and timeprecision declarations shall precede any other items in the current time scope. The timeunit and timeprecision declarations can be repeated as later items, but must match the previous declaration within the current time scope.

3.14.2.3 Precedence of timeunit, timeprecision, and `timescale

If a timeunit is not specified within a module, program, package, or interface definition, then the time unit shall be determined using the following rules of precedence:

a) If the module or interface definition is nested, then the time unit shall be inherited from the enclosing module or interface (programs and packages cannot be nested).

b) Else, if a `timescale directive has been previously specified (within the compilation unit), then the time unit shall be set to the units of the last `timescale directive.

c) Else, if the compilation-unit scope specifies a time unit (outside all other declarations), then the time unit shall be set to the time units of the compilation unit.

d) Else, the default time unit shall be used.

The time unit of the compilation-unit scope can only be set by a timeunit declaration, not a `timescale directive. If it is not specified, then the default time unit shall be used.

If a timeprecision is not specified in the current time scope, then the time precision shall be determined following the same precedence as with time units.

The default time unit and precision are implementation-specific.

VERIFICATION LANGUAGE

It shall be an error if some design elements have a time unit and precision specified and others do not.

3.14.3 Simulation time unit

The global time precision, also called the simulation time unit, is the minimum of all the timeprecision statements, all the time precision arguments to timeunit declarations, and the smallest time precision argument of all the `timescale compiler directives in the design.

The step time unit is equal to the global time precision. Unlike other time units, which represent physical units, a step cannot be used to set or modify either the precision or the time unit.