Skip to content

Add partial support for size constraints (#5582 partial) - #5611

Merged
wsnyder merged 19 commits into
verilator:masterfrom
antmicro:rrozak/handle-size-constraint
Nov 15, 2024
Merged

wsnyder merged 19 commits into
verilator:masterfrom
antmicro:rrozak/handle-size-constraint

Conversation

@RRozak

@RRozak RRozak commented Nov 15, 2024

Copy link
Copy Markdown
Member

It adds partial support for size constraints of queues and dynamic arrays.
I added it by replacing size() method with a normal rand variable. Then this variable is passed to the constraint solver and the array is resized before the unconstrained randomization.

Currently, it doesn't work when:

  • elements of the array are constrained, because in such a case the values found by the solver are assigned before the resizing (though it should work if the array before the call to randomize is not smaller than the size specified in the constraint),
  • the size constraint is in with clause of randomize, because in such a case, the unconstrained randomization is done before the constrained,
  • the array is an element of some other array or struct.

Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>

@wsnyder wsnyder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Please make sure you are up-to-date with master, and also add to this commit:

diff --git a/test_regress/t/uvm/uvm_pkg_todo.svh b/test_regress/t/uvm/uvm_pkg_todo.svh
index 0ef277ddb..65c2d0b3d 100644
--- a/test_regress/t/uvm/uvm_pkg_todo.svh
+++ b/test_regress/t/uvm/uvm_pkg_todo.svh
@@ -22444,9 +22444,7 @@ class uvm_reg_item extends uvm_sequence_item;
   uvm_elem_kind_e element_kind;
   uvm_object element;
   rand uvm_access_e kind;
-  //TODO issue-5582 - Rand constraint with .size
-  //TODO %Warning-CONSTRAINTIGN: t/t_uvm_pkg_todo.vh:#:#: Unsupported: randomizing this expression, treating as state
-  /*rand*/ uvm_reg_data_t value[];
+  rand uvm_reg_data_t value[];
   constraint max_values { value.size() > 0 && value.size() < 1000; }
   rand uvm_reg_addr_t offset;
   uvm_status_e status;
@@ -26866,9 +26864,7 @@ class uvm_reg_fifo extends uvm_reg;
     local uvm_reg_field value;
     local int m_set_cnt;
     local int unsigned m_size;
-    //TODO issue-5582 - Rand constraint with .size
-    //TODO %Warning-CONSTRAINTIGN: t/t_uvm_pkg_todo.vh:#:#: Unsupported: randomizing this expression, treating as state
-    /*rand*/ uvm_reg_data_t fifo[$];
+    rand uvm_reg_data_t fifo[$];
     constraint valid_fifo_size {
       fifo.size() <= m_size;
     }

Comment thread src/V3Randomize.cpp Outdated
Comment thread src/V3Randomize.cpp Outdated
Comment thread src/V3Randomize.cpp Outdated
Comment thread src/V3Randomize.cpp Outdated
Comment thread src/V3Randomize.cpp Outdated
RRozak and others added 4 commits November 15, 2024 14:11
Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org>
Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org>
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants