Support packed and unpacked array unconstrained randomization (#5414)
Hello,
A patch to support unconstrained randomization for unpacked/packed arrays has been implemented. I'm also working on adding randomization support for other types of arrays. Additionally, I have included a corresponding test for this patch.
If there is any extra need, please tell me. :)
#5414 Solution to this issue.
Hello, @kozdra just in case you missed my previous message, I'm pinning this again. Alternatively, I think we can go ahead and merge it now, and you can open a new PR later to implement your suggestions for astforeach. Both are fine for me.
Sorry, @YilouWang I cannot see any other message from you, except for the commits. Maybe the GitHub UI set your comments as pending, if so you need to submit them.
If you meant to use AstForeach, it can be created like in verilog.y. I do not oppose to merging this for now, as it is still an improvement, but the loop unrolling currently done is in my opinion suboptimal.
Oh, I see it now, the message is pending, sorry about that. In the message I intended to send you last Thursday, I wanted to say that I think the idea of astforeach is great, but while using it, I wasn't sure how to put a piece of logic in stmtsp. I wanted to ask if there are any related examples. I will check the verilog.y. Thank you!
Hello, @kozdra @wsnyder
Sorry to align with you this late. I tried to solve the problem using astforeach, and it works fine in 1 dimension.
However, when using nested astforeach, the following issue occurred:
V3Ast.cpp:1368: Dumping foreach_iterative_constraints_test-sim/foreach_iterative_constraints_test_045_task.tree.json
%Error: Internal Error: ../foreach_iterative_constraints_test.sv:13:30: ../V3Broken.cpp:168: Broken link in node (or something without maybePointedTo): 'm_varp && !m_varp->brokeExists()' @ ./V3Ast__gen_impl.h:5720
: ... note: In instance '$unit.ForeachConstraintTest'
-node: VARSCOPE 0xeaa850 <e2038> {d13be} @dt=0xe6a2a0@(G/sw32) TOP.__024unit.ForeachConstraintTest->j [T] [scopep=0xeae930] -> VAR 0xe71000 <e2293> {d13be} @dt=0xe6a2a0@(G/sw32) j [LOOP] [VAUTOM] MEMBER
It is worth mentioning that when I use constraint foreach, for example, if my testcase is like this:
constraint C {
foreach (array[i])
foreach (array[i][j])
......
}
Or like this:
constraint C {
foreach (array[i, j ,k...])
......
}
The same issue occurs after the same 45task. I tried to debug, but didn't find any clues.
Do you have any ideas on this?
@YilouWang This probably means that multi-dimensional arrays do not work properly. You can stick to one-dimensional arrays for the time being, and leave the multiple dimensions for some next PR (maybe flagging them as unsupported if that is doable sensibly). Also note that constraining array contents is not yet supported on master (although #5413 is probably fine), and for unconstrained array randomization there is probably no strict need for foreach constraints. They surely need more attention, as there are currently some other bugs there, e.g. #5442 (which looks closely related to what you report about multiple dimensions).
Note before this can be merged please merge in master, and all tests need to convert to Python, thanks.
Hello, @wsnyder @kozdra
Apologies for the delay in updating. I got stuck on the Z3-solver parsing issue with packed arrays. Regarding @kozdra 's suggestion to use a foreach loop to optimize array unconstrained randomization (thanks for the suggestion), we have implemented it. In addition, we have also added support for dynamic arrays (Thanks to Udaya's help @udayaa-init).
So, with this patch, we now have unconstrained randomization support for packed/unpacked arrays and dynamic arrays.
Thank you for your patience.
BR, Yilou
I think some of the "//TODO issue-4625" commented-out lines in test_regress/t/t_uvm_pkg_todo.vh can commented in with this fix, can you please see which ones? If some/all still don't work, it's ok to leave them commented out, but if this test now gets us even one line closer to UVM I'd like to credit it in the tests. Thanks.
Following the suggestion, I reformat the code and test struct containing array and struct array. The former works while struct array is not supported (I describe this in issue #5455). Currently I report this as an unsupported warning message.