Download Arithmetic/Other/fixed_point_adder/testbench.v from chipagents/RTLLM-verified: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/datasets/chipagents/RTLLM-verified/resolve/main/Arithmetic/Other/fixed_point_adder/testbench.v
- Command line
-
hf download hf://datasets/chipagents/RTLLM-verified/Arithmetic/Other/fixed_point_adder/testbench.v
-
curl -L -o testbench.v https://huggingface.co/datasets/chipagents/RTLLM-verified/resolve/main/Arithmetic/Other/fixed_point_adder/testbench.v
1.98 kB
| module testbench; | |
| // Parameters | |
| parameter Q = 15; | |
| parameter N = 32; | |
| // Inputs | |
| reg [N-1:0] a; | |
| reg [N-1:0] b; | |
| // Output | |
| wire [N-1:0] c; | |
| reg [N-1:0] expected_result; | |
| integer error = 0; | |
| fixed_point_adder #(.Q(Q), .N(N)) fp_adder ( | |
| .a(a), | |
| .b(b), | |
| .c(c) | |
| ); | |
| initial begin | |
| for (integer i = 0; i < 100; i = i + 1) begin | |
| // fix: `$random % (1 << N)` is X for N=32 (1<<32 == 0); use real operands. | |
| // Sign-magnitude operands; bit N-2 cleared so |a|+|b| fits in N-1 bits (overflow is not graded). | |
| a = $random; | |
| b = $random; | |
| a[N-2] = 1'b0; | |
| b[N-2] = 1'b0; | |
| #10; | |
| // fix: sign-magnitude model of the spec: same signs -> magnitudes added, common sign; | |
| // different signs -> larger magnitude minus smaller, sign of the larger-magnitude operand (0 if zero). | |
| if (a[N-1] == b[N-1]) begin | |
| expected_result = {a[N-1], a[N-2:0] + b[N-2:0]}; | |
| end | |
| else if (a[N-2:0] > b[N-2:0]) begin | |
| expected_result = {a[N-1], a[N-2:0] - b[N-2:0]}; | |
| end | |
| else if (b[N-2:0] > a[N-2:0]) begin | |
| expected_result = {b[N-1], b[N-2:0] - a[N-2:0]}; | |
| end | |
| else begin | |
| expected_result = {N{1'b0}}; | |
| end | |
| if (c !== expected_result) begin | |
| error = error + 1; | |
| $display("Test failed: a = %b, b = %b, c = %b, expected_result = %b", a, b, c, expected_result); | |
| end | |
| end | |
| // Final test result summary | |
| if (error == 0) begin | |
| $display("=========== Your Design Passed ==========="); | |
| end | |
| else begin | |
| $display("=========== Test completed with %d /100 failures ===========", error); | |
| end | |
| // End simulation | |
| $finish; | |
| end | |
| endmodule |