forked from verilator/verilator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support basic constrained queue randomization (verilator#5413)
Signed-off-by: Arkadiusz Kozdra <[email protected]>
- Loading branch information
Showing
6 changed files
with
190 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python3 | ||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition | ||
# | ||
# Copyright 2024 by Wilson Snyder. This program is free software; you | ||
# can redistribute it and/or modify it under the terms of either the GNU | ||
# Lesser General Public License Version 3 or the Perl Artistic License | ||
# Version 2.0. | ||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 | ||
|
||
import vltest_bootstrap | ||
|
||
test.scenarios('simulator') | ||
|
||
if not test.have_solver: | ||
test.skip("No constraint solver installed") | ||
|
||
test.compile() | ||
|
||
test.execute() | ||
|
||
test.passes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// DESCRIPTION: Verilator: Verilog Test module | ||
// | ||
// This file ONLY is placed under the Creative Commons Public Domain, for | ||
// any use, without warranty, 2024 by Antmicro Ltd. | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
`define check_rand(cl, field, cond) \ | ||
begin \ | ||
longint prev_result; \ | ||
int ok = 0; \ | ||
for (int i = 0; i < 10; i++) begin \ | ||
longint result; \ | ||
if (!bit'(cl.randomize())) $stop; \ | ||
result = longint'(field); \ | ||
if (!(cond)) $stop; \ | ||
if (i > 0 && result != prev_result) ok = 1; \ | ||
prev_result = result; \ | ||
end \ | ||
if (ok != 1) $stop; \ | ||
end | ||
|
||
class Foo; | ||
rand int m_intQueue[$]; | ||
rand int m_idx; | ||
|
||
function new; | ||
m_intQueue = '{10{0}}; | ||
endfunction | ||
|
||
constraint int_queue_c { | ||
m_idx inside {[0:9]}; | ||
m_intQueue[m_idx] == m_idx + 1; | ||
foreach (m_intQueue[i]) { | ||
m_intQueue[i] inside {[0:127]}; | ||
} | ||
} | ||
endclass | ||
|
||
module t_randomize_queue_constraints; | ||
initial begin | ||
Foo foo = new; | ||
|
||
`check_rand(foo, foo.m_idx, foo.m_idx inside {[0:9]} && foo.m_intQueue[foo.m_idx] == foo.m_idx + 1); | ||
$display("Queue: %p", foo.m_intQueue); | ||
`check_rand(foo, foo.m_intQueue[3], foo.m_intQueue[5] inside {[0:127]}); | ||
$display("Queue: %p", foo.m_intQueue); | ||
$write("*-* All Finished *-*\n"); | ||
$finish; | ||
end | ||
endmodule |