Is it possible to use parameter with function?

P

Peng Yu

Guest
Hi,
We can use parameter with module. Can we use parameter with
function? I've searched some books. No book says we can use it with
function. But this doesn't mean it's impossible, since these books
maybe skip this point.
Do somebody know that? Thanks!
Peng
 
Hi Peng,
Yes you can, just like the way you would use parameter for reg
declaration. Here is a trivial example:

module param_fn ();
parameter width = 4;
reg [width - 1 : 0] abcd;
initial
begin
abcd = 1;
abcd = print(abcd);
abcd = 2;
abcd = print(abcd);
end

function print (input [width-1 : 0] abcd);
begin
$display ("width %d abcd %h ", width, abcd);
end
endfunction // print
endmodule // param_fn


Not sure if this is what you need or more!

HTH,
Ajeetha
http://www.noveldv.com

yupeng_@hotmail.com (Peng Yu) wrote in message news:<d7b3726c.0308052044.793ddcf9@posting.google.com>...
Hi,
We can use parameter with module. Can we use parameter with
function? I've searched some books. No book says we can use it with
function. But this doesn't mean it's impossible, since these books
maybe skip this point.
Do somebody know that? Thanks!
Peng
 
You don't need to define multiple functions (by hand). You simply put
the functions in modules that you parameterize and invoke the function
from the module instantiated with the correct parameters. The
*module* is the unit of parameterization in Verilog. A mdoule does
not have to have any wires, regs, always blocks, or any other
construct to be legal, so it is valid to create modules that exist
only to parameterize functions. So, while you cannot parameterize
functions "directly", you can paramterize them, by placing them in
parameterized modules.

Hope this helps,
-Chris

*****************************************************************************
Chris Clark Internet : compres@world.std.com
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
19 Bronte Way #33M voice : (508) 435-5016
Marlboro, MA 01752 USA fax : (508) 251-2347 (24 hours)
------------------------------------------------------------------------------
 
You can use arguments instead of parameters.

Jim Wu
jimwu88NOOOOSPAM@yahoo.com


"Peng Yu" <yupeng_@hotmail.com> wrote in message
news:d7b3726c.0308061427.63b86e38@posting.google.com...
Hi,
So I can't override the parameter of a function. And I have to
define a few of functions, even if the only difference between them is
the parameter. Is that right?
I wonder why the verilog-2001 doesn't provide the ability to modify
the parameter of a function as it does for "module".
Peng

sharp@cadence.com (Steven Sharp) wrote in message
news:<3a8e124e.0308061102.57442572@posting.google.com>...
yupeng_@hotmail.com (Peng Yu) wrote in message
news:<d7b3726c.0308052044.793ddcf9@posting.google.com>...
Hi,
We can use parameter with module. Can we use parameter with
function?

That depends on what you mean by "use parameter". A function
can use a parameter that was defined in a module. However,
you cannot provide a parameter override for an individual
function call to get a different parameter value for the function
for that call. Each call to a function in a module instance
is calling the same instance of the function, which uses the
parameter values that were set for the instance during
compilation.

If this does not answer your question, you will need to
be more specific about what you are trying to do.
 
"Jim Wu" <jimwu88NOOOOSPAM@yahoo.com> wrote in message news:<1PAYa.237$sb4.83@nwrdny01.gnilink.net>...
You can use arguments instead of parameters.
What do you mean by "use arguments instead of parameters"? Could you
give an example? Thanks.
 
"Jim Wu" <jimwu88NOOOOSPAM@yahoo.com> wrote in message news:<pcMYa.3506$014.2681@nwrdny02.gnilink.net>...
Instead of overriding the parameter, you pass different values to the
function. However, be warned there are some limitations you have to get
around.
In particular, only parameters can be used to change structural things
about the function (for example, how wide the inputs and return value
are). That is because this information must be known at compile time,
not at run time. And that is also why an individual function call cannot
override parameter values. Structural information must be known when
the function is compiled, in order to compile it, and cannot be changed
at runtime.

If each function call instantiated a different instance of the function
to be called from there, then this would be possible. But that is not
how the language is defined, and there are good reasons for it.
 

Welcome to EDABoard.com

Sponsor

Back
Top