• 沒有找到結果。

Unified Hardware Design, Specification, and Verification Language

6. Data types

6.18 User-defined types

6.20.2 Value parameters

...

endmodule

In the declaration of a parameter in a parameter port list, the specification for its default value may be omitted, in which case the parameter shall have no default value. If no default value is specified for a parameter of a design element, then an overriding parameter value shall be specified in every instantiation of that design element (see 23.10). Also, if no default value is specified for a parameter of a design element, then a tool shall not implicitly instantiate that design element (see 23.3, 23.4, and 24.3). If no default value is specified for a parameter of a class, then an overriding parameter value shall be specified in every specialization of that class (see 8.25).

class Mem #(type T, int size);

T words[size];

...

endclass

typedef Mem#(byte, 1024) Kbyte;

6.20.2 Value parameters

A parameter constant can have a type specification and a range specification. The type and range of parameters shall be in accordance with the following rules:

— A parameter declaration with no type or range specification shall default to the type and range of the final value assigned to the parameter, after any value overrides have been applied. If the expression is real, the parameter is real. If the expression is integral, the parameter is a logic vector of the same size with range [size-1:0].

— A parameter with a range specification, but with no type specification, shall have the range of the parameter declaration and shall be unsigned. The sign and range shall not be affected by value overrides.

— A parameter with a type specification, but with no range specification, shall be of the type specified.

A signed parameter shall default to the range of the final value assigned to the parameter, after any value overrides have been applied.

— A parameter with a signed type specification and with a range specification shall be signed and shall have the range of its declaration. The sign and range shall not be affected by value overrides.

— A parameter with no range specification and with either a signed type specification or no type speci-fication shall have an implied range with an lsb equal to 0 and an msb equal to one less than the size of the final value assigned to the parameter.

— A parameter with no range specification, with either a signed type specification or no type specifica-tion, and for which the final value assigned to it is unsized shall have an implied range with an lsb equal to 0 and an msb equal to an implementation-dependent value of at least 31.

In an assignment to, or override of, a parameter with an explicit type declaration, the type of the right-hand expression shall be assignment compatible with the declared type (see 6.22.3).

The conversion rules between real and integer values described in 6.12.2 apply to parameters as well.

Bit-selects and part-selects of parameters that are of integral types shall be allowed (see 6.11.1).

VERIFICATION LANGUAGE

A value parameter (parameter, localparam, or specparam) can only be set to an expression of literals, value parameters or local parameters, genvars, enumerated names, or a constant function of these. Package references are allowed. Hierarchical names are not allowed. A specparam can also be set to an expression containing one or more specparams.

Examples:

parameter msb = 7; // defines msb as a constant value 7 parameter e = 25, f = 9; // defines two constant numbers parameter r = 5.7; // declares r as a real parameter parameter byte_size = 8,

byte_mask = byte_size - 1;

parameter average_delay = (r + f) / 2;

parameter signed [3:0] mux_selector = 0;

parameter real r1 = 3.5e17;

parameter p1 = 13'h7e;

parameter [31:0] dec_const = 1'b1; // value converted to 32 bits parameter newconst = 3'h4; // implied range of [2:0]

parameter newconst = 4; // implied range of at least [31:0]

A parameter can also be declared as an aggregate type, such as an unpacked array or an unpacked structure.

An aggregate parameter must be assigned to or overridden as a whole; individual members of an aggregate parameter may not be assigned or overridden separately. However, an individual member of an aggregate parameter may be used in an expression. For example:

parameter logic [31:0] P1 [3:0] = '{ 1, 2, 3, 4 } ; // unpacked array // parameter declaration initial begin

if ( P1[2][7:0] ) ... // use part-select of individual element of the array 6.20.2.1 $ as a parameter value

The value $ can be assigned to parameters of integer types. A parameter to which $ is assigned shall only be used wherever $ can be specified as a literal constant.

For example, $ represents unbounded range specification, where the upper index can be any integer.

parameter r2 = $;

property inq1(r1,r2);

@(posedge clk) a ##[r1:r2] b ##1 c |=> d;

endproperty assert inq1(3);

A system function is provided to test whether a constant is a $. The syntax of the system function is

$isunbounded(constant_expression);

$isunbounded returns true if constant_expression is unbounded. Typically, $isunbounded would be used as a condition in the generate statement.

The following example illustrates the benefit of using $ in writing properties concisely where the range is parameterized. The checker in the example verifies that a bus driven by signal en remains 0, i.e, quiet for the specified minimum (min_quiet) and maximum (max_quiet) quiet time.

NOTE—The function $isunbounded is used for checking the validity of the actual arguments.

interface quiet_time_checker #(parameter min_quiet = 0, parameter max_quiet = 0)

(input logic clk, reset_n, logic [1:0]en);

generate

if ( max_quiet == 0) begin property quiet_time;

@(posedge clk) reset_n |-> ($countones(en) == 1);

endproperty

(reset_n && ($past(en) != 0) && en == 0)

|->(en == 0)[*min_quiet:max_quiet]

##1 ($countones(en) == 1);

endproperty

a1: assert property (quiet_time);

end

if ((min_quiet == 0) && ($isunbounded(max_quiet))

$display(warning_msg);

endgenerate endinterface

quiet_time_checker #(0, 0) quiet_never (clk,1,enables);

quiet_time_checker #(2, 4) quiet_in_window (clk,1,enables);

quiet_time_checker #(0, $) quiet_any (clk,1,enables);

Another example below illustrates that by testing for $, a property can be configured according to the requirements. When parameter max_cks is unbounded, it is not required to test for expr to become false.

interface width_checker #(parameter min_cks = 1, parameter max_cks = 1) (input logic clk, reset_n, expr);

generate

if ($isunbounded(max_cks)) begin property width;

@(posedge clk)

(reset_n && $rose(expr)) |-> (expr [* min_cks]);

endproperty

(reset_n && $rose(expr)) |-> (expr[* min_cks:max_cks])

##1 (!expr);

width_checker #(3, $) max_width_unspecified (clk,1,enables);

width_checker #(2, 4) width_specified (clk,1,enables);

VERIFICATION LANGUAGE