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

Solve order is not working! #52

Closed aneels3 closed 3 years ago

aneels3 commented 3 years ago

Hi @mballance While checking the working of #38, I came across another issue where the solve order is not working.

I have created a test case to give you a better understanding of the issue.

import vsc 
from enum import IntEnum, auto

@vsc.randobj
class mem_region_t:
    def __init__(self, name = "", size_in_bytes = 0, xwr = 0): 
        self.name = name 
        self.size_in_bytes = vsc.uint32_t(i = size_in_bytes)
        self.xwr = vsc.uint8_t(i = xwr)

@vsc.randobj
class classA:
    def __init__(self):
        self.base = vsc.rand_int32_t()
        self.max_load_store_offset = vsc.rand_int32_t()
        self.max_data_page_id = vsc.int32_t()
        self.data_page = vsc.list_t(mem_region_t())
        self.data_page_id = vsc.rand_uint32_t()
        self.mem_region = vsc.list_t(mem_region_t())
        self.mem_region.extend([mem_region_t(name = "region_0", size_in_bytes = 4096, xwr = 8), 
                                mem_region_t(name = "region_1", size_in_bytes = 4096, xwr = 8)])

    def pre_randomize(self):
        print("[Pre] max_load_store_offset: ", self.max_load_store_offset)
        print("[Pre] Base: ", self.base)
        self.data_page.clear()
        self.data_page.extend(self.mem_region)
        self.max_data_page_id = len(self.data_page)

    def post_randomize(self):
        print("[Post] max_load_store_offset: ", self.max_load_store_offset)
        print("[Post] Base: ", self.base)

    @vsc.constraint
    def addr_c(self):
        vsc.solve_order(self.data_page_id, self.max_load_store_offset)
        vsc.solve_order(self.max_load_store_offset, self.base)
        self.data_page_id < self.max_data_page_id
        with vsc.foreach(self.data_page, idx = True) as i:
            with vsc.if_then(i == self.data_page_id):
                self.max_load_store_offset == self.data_page[i].size_in_bytes
        self.base in vsc.rangelist(vsc.rng(0, self.max_load_store_offset - 1))

obj = classA()
obj.randomize()

In the above test case the self.base is giving a large value instead of value between in vsc.rng(0,4095)

My output:-

-- push_constraint_stmt
-- push_constraint_stmt
[Pre] max_load_store_offset:  0
[Pre] Base:  0
[Post] max_load_store_offset:  4096
[Post] Base:  2494113924

Please let me know If I have missed something.

Regards, Anil

aneels3 commented 3 years ago

Hi @mballance anything on this issue?

mballance commented 3 years ago

Hi @aneels3, I was able to have an initial look at this. It seems there was a bug in the 'rng' construct when one side was an expression. I've corrected that bug and correct answers are now returned. Unfortunately, the results are not random at all. It seems related to the size of the variables (32-bit signed) vs the reachable size (0..4095). Would it make sense to change the size of some variables? For example 16-bit unsigned?

Thanks, Matthew

aneels3 commented 3 years ago

Hi @mballance Sorry for the late response on this. For now, it seems like it resolved the issue for this particular test case but I will need the size of the variable to be 32 bit signed later on.

mballance commented 3 years ago

Closing this for now