Use $value$plusargs and +name=value, +define+name=value, and -gname=value/-Gname=value to change Verilog RTL and testbench behavior in simulation compile or run time

Make it to the Right and Larger Audience


Use $value$plusargs and +name=value, +define+name=value, and -gname=value/-Gname=value to change Verilog RTL and testbench behavior in simulation compile or run time

Let’s take a look of an example of how to use $value$plusargs to change test bench behavior. In Verilog you may have something like

Then you can use below run command to pass clk frequency to test bench.

For example, if you use modelsim, you can do
>vsim +CLKFREQ=5

If you use VCS, you can do
>simv +CLKFREQ=5

As you can see, $value#plusargs is a runtime switch and not a compile time switch. In other words,
>vlog +CLKFREQ=5
will not work. In $value$plusargs, the format strings are the same as the $display system task:

%b – binary conversion
%d – decimal conversion
%e – real exponential conversion
%f – real decimal conversion
%g – real decimal or exponential conversion
%h – hexadecimal conversion
%o – octal conversion
%s – string (no conversion)
%x – (undergound equivalent for %h)

Some other examples. To pass a string as a filename,

in verilog file:

in command line:
>vsim +filename=indata.v

To pass an integer, in verilog file

If you want a compile time switch, you can use the 2nd method of +define+.

Let’s say in your RTL code, you have

At compile time, you can do
>vlog +define+CLKFREQ=5
to pass CLKFREQ to test bench and run time command is just

Another example, verilog file

At compile, you can do
>vlog +define+PARAMFILE=”myparam.v”

A third way to pass parameters into simulation is to use -g or -G switch to set verilog parameters. Let’s take a look of an example. verilog file:

At run time, you can do
>vsim -gtpd=20ns
to pass 20ns to verilog parameter tpd.

Here is how -g works from Modelsim user manual.

Assigns a value to all specified VHDL generics and Verilog parameters that have not received explicit values in generic maps, instantiations, or via defparams (such as toplevel generics/parameters and generics/parameters that would otherwise receive their default values). Optional. Note there is no space between -g and =.

“Name” is the name of the generic/parameter, exactly as it appears in the VHDL source (case is ignored) or Verilog source. “Value” is an appropriate value for the declared data type of a VHDL generic or any legal value for a Verilog parameter. Make sure the Value you specify for a VHDL generic is appropriate for VHDL declared data types. VHDL type mismatches will cause the specification to be ignored (including no error messages).

No spaces are allowed anywhere in the specification, except within quotes when specifying a string value. Multiple -g options are allowed, one for each generic/ parameter.

Name may be prefixed with a relative or absolute hierarchical path to select generics in an instance-specific manner. For example,
Specifying -g/top/u1/tpd=20ns on the command line would affect only the tpd generic on the /top/u1 instance, assigning it a value of 20ns.
Specifying -gu1/tpd=20ns affects the tpd generic on all instances named u1.
Specifying -gtpd=20ns affects all generics named tpd.

If more than one -g option selects a given generic the most explicit specification takes precedence. For example,
vsim -g/top/ram/u1/tpd_hl=10ns -gtpd_hl=15ns top
This command sets tpd_hl to 10ns for the /top/ram/u1 instance. However, all other tpd_hl generics on other instances will be set to 15ns.

Limitation: In general, generics/parameters of composite type (arrays and records) cannot be set from the command line. However, you can set string arrays, std_logic vectors, and bit vectors if they can be set using a quoted string. For example,
-gstrgen=”This is a string”

The quotation marks must make it into vsim as part of the string because the type of the value must be determinable outside of any context. Therefore, when entering this command from a shell, put a forward tick around the string. For example:
-gstrgen=’”This is a string”’

If working within the ModelSim GUI, you would enter the command as follows:
{-gstrgen=”This is a string”}

Same as -g (see above) except that it will also override generics/parameters that received
explicit values in generic maps, instantiations, or via defparams. Optional. Note there is
no space between -G and =.

So -g or -G is a runtime switch as $value$plusargs.

Author brief is empty

1 Comment

Contact Us

Thanks for helping us better serve the community. You can make a suggestion, report a bug, a misconduct, or any other issue. We'll get back to you using your private message ASAP.



Forgot your details?