1

I have a design that takes a few essential parameters. It needs to do some arithmetic (comparisons, additions etc.) on the given essential parameters, then initialize other parameters (or constants) based on the results. For instance, look at the code below,

module foo(a,b);

parameter wl_in = 8;
parameter sc_in = 3;
parameter wl_out = 9;
parameter sc_out = 2;

parameter big_wl = //to be determined...
parameter big_sc = //to be determined...

//some logic

endmodule

I want to determine which of the two wls is greater, then assign it to big_wl. Likewise for sc. I will then use these parameters to define arrays, define array boundaries etc.

I tried using if/else statements, but I've gotten errors with that approach.

How can I do this in Verilog-2001?

0

1 Answer 1

2

You can use the conditional operator a ? b : c for this

parameter big_wl = wl_in > wl_out ? wl_in : wl_out;

For more complex operations, you can use a constant function. That kind of function is restricted to having an output solely defined by its inputs, and no references to anything outside the function.

function integer max(integer v1,v2);
begin
  if (v1 > v2)
     max = v1;
  else
     max = v2;
end
endfunction

parameter big_wl = max(wl_in, wl_out);

In SystemVerilog, you can use the let construct

let max(v1,v2) = v1>v2 ? v1 : v2;

The benefit of this is the arguments are typeless, not fixed to an integer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.