Download Arithmetic/Substractor/sub_64bit/testbench.v from chipagents/RTLLM-verified: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/chipagents/RTLLM-verified/resolve/main/Arithmetic/Substractor/sub_64bit/testbench.v
- Command line
-
hf download hf://datasets/chipagents/RTLLM-verified/Arithmetic/Substractor/sub_64bit/testbench.v
-
curl -L -o testbench.v https://huggingface.co/datasets/chipagents/RTLLM-verified/resolve/main/Arithmetic/Substractor/sub_64bit/testbench.v
2.1 kB
| module testbench; | |
| reg [63:0] A; // Input A (64 bits) | |
| reg [63:0] B; // Input B (64 bits) | |
| wire [63:0] result; // Subtraction result (64 bits) | |
| wire overflow; // Overflow signal | |
| integer i; // Loop variable | |
| integer error = 0; // Error count for failed tests | |
| reg [63:0] diff; // fix: expected A - B (64-bit) | |
| reg exp_ovf; // fix: expected overflow (sign rules of the spec) | |
| // Instantiate the verified_sub_64bit module | |
| sub_64bit uut ( | |
| .A(A), | |
| .B(B), | |
| .result(result), | |
| .overflow(overflow) | |
| ); | |
| // Randomize inputs and check output | |
| initial begin | |
| // fix: vectors 100..199 use full 64-bit operands so that overflow can occur | |
| for (i = 0; i < 200; i = i + 1) begin | |
| // Generate random 64-bit inputs | |
| if (i < 100) begin | |
| A = $random; | |
| B = $random; | |
| end | |
| else begin | |
| A = {$random, $random}; | |
| B = {$random, $random}; | |
| end | |
| // Wait for the operation to complete | |
| #10; | |
| // Calculate expected result using system task | |
| // $monitor("A = %d, B = %d, Expected Result = %d, Overflow = %b", A, B, A - B, overflow); | |
| // Check the result of the subtraction | |
| // fix: the old overflow term (unsigned A - B < 0) could never fire; overflow is now compared: | |
| // operands of different signs and a result whose sign differs from A's (zero operands not graded). | |
| diff = A - B; | |
| exp_ovf = (A[63] != B[63]) && (diff[63] != A[63]); | |
| if (result !== diff || (A != 0 && B != 0 && overflow !== exp_ovf)) begin | |
| error = error + 1; | |
| $display("Test failed: A = %d, B = %d, Expected Result = %d, Got = %d, Overflow = %b", A, B, A - B, result, overflow); | |
| end | |
| end | |
| // Final test result summary | |
| if (error == 0) begin | |
| $display("=========== Your Design Passed ==========="); | |
| end | |
| else begin | |
| $display("=========== Test completed with %d /200 failures ===========", error); | |
| end | |
| $finish; | |
| end | |
| endmodule |