Functions in Constraints

In reply to adityatumsare:

A couple of problems with your code:

s_addr is unsigned—it can never be less than 0.

e_addr is the same bit width as
s_addr
. When you multiply it by 2 (same as shift left by 1), you lose the MSB. Make e_addr one bit wider for this function.

  • You don’t test the return value of randomize() for success. It’s very easy to get a randomization failure when using functions in constraints. If you were to add another constraint on
    end_addr
    , the solver does not backtrack through a user defined function to find the proper inputs.