fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

rand_int8_t with negative maximum can not be randomized #156

Closed XunChangqing closed 2 years ago

XunChangqing commented 2 years ago
import vsc
@vsc.randobj
class my_cls(object):
    def __init__(self):
        self.a = vsc.rand_int8_t()

    @vsc.constraint
    def a_c(self):
        self.a <= -100

myi = my_cls()
for i in range(10):
    myi.randomize()
    print(myi.a)

myi.a will always be -100. master e85daca. I think it is because of the code as below at 183 line in solvegroup_swizzler_partsel,py

            d_width = 0
            maxval = t_range[1]

            while maxval > 0:
                d_width += 1
                maxval >>= 1

No random constraint is added due to incorrect d_width.

BTW: Thanks a lot for you to open source this project. I can only find scv(using BDD), and CRAVE other than your project.

mballance commented 2 years ago

@XunChangqing, many thanks for highlighting this behavior! The testcase, and your analysis on the source of the problem, was very helpful in getting it resolved quickly. The 0.7.1 release contains a change that results in a reasonably-flat distribution of solutions across the reachable domain in this example.

Happy to know that you are finding the project useful!

-Matthew