FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2003, 06:44 AM
Peng Yu
Guest
 
Posts: n/a
Default Is it possible to use parameter with function?

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
Reply With Quote
  #2 (permalink)  
Old 08-06-2003, 05:38 PM
Ajeetha Kumari
Guest
 
Posts: n/a
Default Re: Is it possible to use parameter with function?

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

[email protected] (Peng Yu) wrote in message news:<[email protected] 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

Reply With Quote
  #3 (permalink)  
Old 08-07-2003, 07:51 PM
Chris F Clark
Guest
 
Posts: n/a
Default Re: Is it possible to use parameter with function?

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 : [email protected]
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)
------------------------------------------------------------------------------

Reply With Quote
  #4 (permalink)  
Old 08-08-2003, 12:57 AM
Jim Wu
Guest
 
Posts: n/a
Default Re: Is it possible to use parameter with function?

You can use arguments instead of parameters.

Jim Wu
[email protected]


"Peng Yu" <[email protected]> wrote in message
news:[email protected] om...
> 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
>
> [email protected] (Steven Sharp) wrote in message

news:<[email protected] com>...
> > [email protected] (Peng Yu) wrote in message

news:<[email protected] 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.



Reply With Quote
  #5 (permalink)  
Old 08-08-2003, 06:13 AM
Peng Yu
Guest
 
Posts: n/a
Default Re: Is it possible to use parameter with function?

"Jim Wu" <[email protected]> wrote in message news:<[email protected]>...
> You can use arguments instead of parameters.

What do you mean by "use arguments instead of parameters"? Could you
give an example? Thanks.
Reply With Quote
  #6 (permalink)  
Old 08-08-2003, 08:22 PM
Steven Sharp
Guest
 
Posts: n/a
Default Re: Is it possible to use parameter with function?

"Jim Wu" <[email protected]> wrote in message news:<pcMYa.3506$014.2681[email protected]>...
>
> 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.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:19 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved