verilator/test_regress/t/t_force.v

127 lines
2.9 KiB
Systemverilog
Raw Normal View History

2021-12-31 21:17:16 +01:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2021 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0)
`define checkr(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got=%f exp=%f\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
2021-12-31 21:17:16 +01:00
module t(/*AUTOARG*/
// Inputs
clk
);
input clk;
integer cyc = 0;
reg [3:0] in;
tri [3:0] bus = in;
int never_driven;
int never_forced;
2023-02-05 02:37:36 +01:00
real r;
2021-12-31 21:17:16 +01:00
task force_bus;
force bus[1:0] = 2'b10;
endtask
task release_bus;
release bus;
endtask
// Test loop
always @ (posedge clk) begin
cyc <= cyc + 1;
if (cyc == 0) begin
in <= 4'b0101;
end
else if (cyc == 1) begin
`checkh(in, 4'b0101);
end
// Check forces with no driver
if (cyc == 1) begin
force never_driven = 32'h888;
end
else if (cyc == 2) begin
`checkh(never_driven, 32'h888);
end
2022-12-13 03:32:45 +01:00
//
2021-12-31 21:17:16 +01:00
// Check release with no force
else if (cyc == 10) begin
never_forced <= 5432;
end
else if (cyc == 11) begin
`checkh(never_forced, 5432);
end
else if (cyc == 12) begin
release never_forced; // no-op
end
else if (cyc == 13) begin
`checkh(never_forced, 5432);
end
//
// bus
2022-12-13 03:32:45 +01:00
else if (cyc == 20) begin
2021-12-31 21:17:16 +01:00
`checkh(bus, 4'b0101);
force bus = 4'b0111;
end
2022-12-13 03:32:45 +01:00
else if (cyc == 21) begin
2021-12-31 21:17:16 +01:00
`checkh(bus, 4'b0111);
force bus = 4'b1111;
end
2022-12-13 03:32:45 +01:00
else if (cyc == 22) begin
2021-12-31 21:17:16 +01:00
`checkh(bus, 4'b1111);
release bus;
end
2022-12-13 03:32:45 +01:00
else if (cyc == 23) begin
2021-12-31 21:17:16 +01:00
`checkh(bus, 4'b0101);
end
2022-12-13 03:32:45 +01:00
//
else if (cyc == 30) begin
2021-12-31 21:17:16 +01:00
force_bus();
end
2022-12-13 03:32:45 +01:00
else if (cyc == 31) begin
2021-12-31 21:17:16 +01:00
`checkh(bus, 4'b0110);
end
2022-12-13 03:32:45 +01:00
else if (cyc == 32) begin
2021-12-31 21:17:16 +01:00
release bus[0];
end
2022-12-13 03:32:45 +01:00
else if (cyc == 33) begin
2021-12-31 21:17:16 +01:00
`checkh(bus, 4'b0111);
release_bus();
end
2022-12-13 03:32:45 +01:00
else if (cyc == 34) begin
2021-12-31 21:17:16 +01:00
`checkh(in, 4'b0101);
`checkh(bus, 4'b0101);
end
//
2023-02-05 02:37:36 +01:00
else if (cyc == 40) begin
r <= 1.25;
end
else if (cyc == 41) begin
`checkr(r, 1.25);
end
else if (cyc == 42) begin
force r = 2.5;
end
else if (cyc == 43) begin
`checkr(r, 2.5);
end
else if (cyc == 44) begin
release r;
end
else if (cyc == 45) begin
Safely support non-overlapping blocking/non-blocking assignments (#6137) The manual for the BLKANDNBLK warning describes that it is safe to disable that error if the updated ranges are non-overlapping. This however was not true (see the added t_nba_mixed_update* tests). In this patch we change V3Delayed to use a new ShadowVarMasked scheme for variables that have mixed blocking and non-blocking updates (or the FlagUnique scheme for unpacked variables), which is in fact safe to use when the updated parts are non-overlapping. Furthermore, mixed assignments are safe as far as scheduling is concerned if either: - They are to independent parts (bits/members/etc) (with this patch) - Or if the blocking assignment is in clocked (or suspendable) logic. The risk in scheduling is a race between the Post scheduled NBA commit, and blocking assignments in combinational logic, which might order incorrectly. The second point highlights that we can handle stuff like this safely, which is sometimes used in testbenches: ```systemverilog always @(posedge clk) begin if ($time == 0) a = 0; end always @(posedge clk) begin if ($time > 0) a <= 2; end ```` The only dangerous case is: ```systemverilog always @(posedge clk) foo[idx] <= val; assign foo[0] = bar; ``` Whit this patch, this will still resolve fine at run-time if 'idx' is never zero, but might resolve incorrectly if 'idx' is zero. With the above in mind, the BLKANDNBLK warning is now only issued if: - We can't prove that the assignments are to non-overlapping bits - And the blocking assignment is in combinational logic These are the cases that genuinely require user attention to resolve. With this patch, there are no more BLKANDNBLK warnings in the RTLMeter designs. Fixes #6122.
2025-06-28 21:45:45 +02:00
`checkr(r, 2.5);
2023-02-05 02:37:36 +01:00
end
//
2021-12-31 21:17:16 +01:00
else if (cyc == 99) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule