| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- `timescale 1ns/1ps
- // Exhaustive: travel 2..5000 × level 0..15 = 79_984 vectors vs travel×scale oracle.
- module door_rate_quantum_builder_exhaustive_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg start = 1'b0;
- reg [1:0] axis_id_in = 2'd0;
- reg [12:0] travel_in = 13'd0;
- reg [8:0] scale_in = 9'd0;
- wire busy;
- wire done;
- wire [1:0] axis_id_out;
- wire [12:0] travel_out;
- wire [8:0] scale_out;
- wire [20:0] product;
- always #1 clk = ~clk;
- door_rate_quantum_builder dut (
- .clk(clk), .rst_n(rst_n),
- .start(start),
- .axis_id_in(axis_id_in),
- .travel_in(travel_in),
- .scale_in(scale_in),
- .busy(busy), .done(done),
- .axis_id_out(axis_id_out),
- .travel_out(travel_out),
- .scale_out(scale_out),
- .product(product)
- );
- function [8:0] f_profile_scale;
- input [3:0] level;
- begin
- case (level)
- 4'd0: f_profile_scale = 9'd64;
- 4'd1: f_profile_scale = 9'd66;
- 4'd2: f_profile_scale = 9'd73;
- 4'd3: f_profile_scale = 9'd84;
- 4'd4: f_profile_scale = 9'd98;
- 4'd5: f_profile_scale = 9'd114;
- 4'd6: f_profile_scale = 9'd132;
- 4'd7: f_profile_scale = 9'd150;
- 4'd8: f_profile_scale = 9'd170;
- 4'd9: f_profile_scale = 9'd188;
- 4'd10: f_profile_scale = 9'd206;
- 4'd11: f_profile_scale = 9'd222;
- 4'd12: f_profile_scale = 9'd236;
- 4'd13: f_profile_scale = 9'd247;
- 4'd14: f_profile_scale = 9'd254;
- default: f_profile_scale = 9'd256;
- endcase
- end
- endfunction
- integer mismatches;
- integer zeros_bad;
- integer checked;
- integer guard;
- integer ti;
- integer li;
- integer si;
- reg [12:0] spotlight [0:10];
- reg [8:0] scale_tmp;
- reg [20:0] expect_tmp;
- reg [12:0] travel_tmp;
- reg [3:0] level_tmp;
- reg [1:0] axis_tmp;
- task run_one;
- begin
- scale_tmp = f_profile_scale(level_tmp);
- expect_tmp = travel_tmp * scale_tmp;
- @(negedge clk);
- travel_in = travel_tmp;
- scale_in = scale_tmp;
- axis_id_in = axis_tmp;
- start = 1'b1;
- @(negedge clk);
- start = 1'b0;
- guard = 0;
- while (!done) begin
- @(negedge clk);
- guard = guard + 1;
- if (guard > 64)
- $fatal(1, "timeout travel=%0d level=%0d", travel_tmp, level_tmp);
- end
- if (product !== expect_tmp) begin
- mismatches = mismatches + 1;
- if (mismatches <= 16)
- $display("MISMATCH travel=%0d level=%0d scale=%0d got=%0d want=%0d",
- travel_tmp, level_tmp, scale_tmp, product, expect_tmp);
- end
- if (expect_tmp != 0 && product == 0)
- zeros_bad = zeros_bad + 1;
- if (axis_id_out !== axis_tmp || travel_out !== travel_tmp || scale_out !== scale_tmp)
- $fatal(1, "identity mismatch travel=%0d level=%0d", travel_tmp, level_tmp);
- checked = checked + 1;
- @(negedge clk);
- end
- endtask
- initial begin
- #2_000_000_000 $fatal(1, "door_rate_quantum_builder_exhaustive_tb timeout");
- end
- initial begin
- mismatches = 0;
- zeros_bad = 0;
- checked = 0;
- spotlight[0] = 13'd31;
- spotlight[1] = 13'd32;
- spotlight[2] = 13'd63;
- spotlight[3] = 13'd64;
- spotlight[4] = 13'd100;
- spotlight[5] = 13'd2047;
- spotlight[6] = 13'd2048;
- spotlight[7] = 13'd4095;
- spotlight[8] = 13'd4096;
- spotlight[9] = 13'd4999;
- spotlight[10] = 13'd5000;
- repeat (4) @(posedge clk);
- rst_n = 1'b1;
- @(negedge clk);
- // Spotlight vectors first (all levels) — diagnostic only.
- for (si = 0; si < 11; si = si + 1) begin
- for (li = 0; li < 16; li = li + 1) begin
- travel_tmp = spotlight[si];
- level_tmp = li[3:0];
- axis_tmp = 2'd1;
- run_one;
- end
- end
- if (mismatches != 0 || zeros_bad != 0)
- $fatal(1, "spotlight FAIL mismatches=%0d zeros_bad=%0d", mismatches, zeros_bad);
- $display("spotlight PASS vectors=%0d", checked);
- mismatches = 0;
- zeros_bad = 0;
- checked = 0;
- // Full exhaustive 2..5000 × 0..15 = 79984
- for (ti = 2; ti <= 5000; ti = ti + 1) begin
- for (li = 0; li < 16; li = li + 1) begin
- travel_tmp = ti[12:0];
- level_tmp = li[3:0];
- axis_tmp = ti[1:0];
- run_one;
- end
- if ((ti % 500) == 0)
- $display("progress travel=%0d checked=%0d mismatches=%0d", ti, checked, mismatches);
- end
- if (mismatches != 0 || zeros_bad != 0)
- $fatal(1, "FAIL mismatches=%0d zeros_bad=%0d checked=%0d",
- mismatches, zeros_bad, checked);
- if (checked != 79984)
- $fatal(1, "unexpected checked=%0d want 79984", checked);
- $display("door_rate_quantum_builder_exhaustive_tb PASS checked=%0d", checked);
- $finish;
- end
- endmodule
|