-2

I am asking about standard Verilog 2001 and not System Verilog extensions. I was sure it was listed as an advantage of tasks, over a function. However, I have this syntax working and it seems to at least simulate well.

{index, value} = sample(val1, val2, operation);

It seems the single bus is not a limitation if it is unpacked to multiple wires? The function needs a similar sample = {fIndex, fValue}; to construct the multiple values. Will synthesis tools have an issue with this?

3
  • Just to make a point that verilog allows multiple wires to be concatenated. So, a function 'single return value' is not much of a practical limitation. I think the minimum/maximum vector/net size is 2kb or something along those lines. I found different statements on the Internet to say it was a limitation of functions; practically it is not. The concatenation can function like a tuple. So, functions that return x,y,z, r,theta, real,imaginary are possible. Commented Jun 10 at 12:06
  • Although it’s technically possible, I would argue that it’s not practical. It’s extremely unsafe because there’s no type-checking of the layout of the bits returned by the function against the layout of the bits you’re targeting for assignment. And to do this for reals requires you to convert the real numbers to bits, concatenate them in the single return value vector. Unpack them in the LHS assignment, then convert each unpacked value from bits back to a real number. Commented Jun 10 at 15:20
  • In those examples I was expecting fixed point. I never use floats for any synthesis code. It is true that there is no type checking. Different tools will complain if the bit sizes do not match. So, inverting concatenation and signed can be issues. Commented Jun 10 at 16:57

1 Answer 1

1

The return type of a Verilog function must be a single type, and one of those types can be an integral range (a vector). This function can be used in any expression, including the right-hand side of an assignment. The left-hand side of an integral assignment can be a concatenation of multiple integral variables or nets. Consequently, the result of any integral expression, including a function call, can be unpacked into multiple variables or nets.

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.