door_rate_quantum_builder_exhaustive_tb.v 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. `timescale 1ns/1ps
  2. // Exhaustive: travel 2..5000 × level 0..15 = 79_984 vectors vs travel×scale oracle.
  3. module door_rate_quantum_builder_exhaustive_tb;
  4. reg clk = 1'b0;
  5. reg rst_n = 1'b0;
  6. reg start = 1'b0;
  7. reg [1:0] axis_id_in = 2'd0;
  8. reg [12:0] travel_in = 13'd0;
  9. reg [8:0] scale_in = 9'd0;
  10. wire busy;
  11. wire done;
  12. wire [1:0] axis_id_out;
  13. wire [12:0] travel_out;
  14. wire [8:0] scale_out;
  15. wire [20:0] product;
  16. always #1 clk = ~clk;
  17. door_rate_quantum_builder dut (
  18. .clk(clk), .rst_n(rst_n),
  19. .start(start),
  20. .axis_id_in(axis_id_in),
  21. .travel_in(travel_in),
  22. .scale_in(scale_in),
  23. .busy(busy), .done(done),
  24. .axis_id_out(axis_id_out),
  25. .travel_out(travel_out),
  26. .scale_out(scale_out),
  27. .product(product)
  28. );
  29. function [8:0] f_profile_scale;
  30. input [3:0] level;
  31. begin
  32. case (level)
  33. 4'd0: f_profile_scale = 9'd64;
  34. 4'd1: f_profile_scale = 9'd66;
  35. 4'd2: f_profile_scale = 9'd73;
  36. 4'd3: f_profile_scale = 9'd84;
  37. 4'd4: f_profile_scale = 9'd98;
  38. 4'd5: f_profile_scale = 9'd114;
  39. 4'd6: f_profile_scale = 9'd132;
  40. 4'd7: f_profile_scale = 9'd150;
  41. 4'd8: f_profile_scale = 9'd170;
  42. 4'd9: f_profile_scale = 9'd188;
  43. 4'd10: f_profile_scale = 9'd206;
  44. 4'd11: f_profile_scale = 9'd222;
  45. 4'd12: f_profile_scale = 9'd236;
  46. 4'd13: f_profile_scale = 9'd247;
  47. 4'd14: f_profile_scale = 9'd254;
  48. default: f_profile_scale = 9'd256;
  49. endcase
  50. end
  51. endfunction
  52. integer mismatches;
  53. integer zeros_bad;
  54. integer checked;
  55. integer guard;
  56. integer ti;
  57. integer li;
  58. integer si;
  59. reg [12:0] spotlight [0:10];
  60. reg [8:0] scale_tmp;
  61. reg [20:0] expect_tmp;
  62. reg [12:0] travel_tmp;
  63. reg [3:0] level_tmp;
  64. reg [1:0] axis_tmp;
  65. task run_one;
  66. begin
  67. scale_tmp = f_profile_scale(level_tmp);
  68. expect_tmp = travel_tmp * scale_tmp;
  69. @(negedge clk);
  70. travel_in = travel_tmp;
  71. scale_in = scale_tmp;
  72. axis_id_in = axis_tmp;
  73. start = 1'b1;
  74. @(negedge clk);
  75. start = 1'b0;
  76. guard = 0;
  77. while (!done) begin
  78. @(negedge clk);
  79. guard = guard + 1;
  80. if (guard > 64)
  81. $fatal(1, "timeout travel=%0d level=%0d", travel_tmp, level_tmp);
  82. end
  83. if (product !== expect_tmp) begin
  84. mismatches = mismatches + 1;
  85. if (mismatches <= 16)
  86. $display("MISMATCH travel=%0d level=%0d scale=%0d got=%0d want=%0d",
  87. travel_tmp, level_tmp, scale_tmp, product, expect_tmp);
  88. end
  89. if (expect_tmp != 0 && product == 0)
  90. zeros_bad = zeros_bad + 1;
  91. if (axis_id_out !== axis_tmp || travel_out !== travel_tmp || scale_out !== scale_tmp)
  92. $fatal(1, "identity mismatch travel=%0d level=%0d", travel_tmp, level_tmp);
  93. checked = checked + 1;
  94. @(negedge clk);
  95. end
  96. endtask
  97. initial begin
  98. #2_000_000_000 $fatal(1, "door_rate_quantum_builder_exhaustive_tb timeout");
  99. end
  100. initial begin
  101. mismatches = 0;
  102. zeros_bad = 0;
  103. checked = 0;
  104. spotlight[0] = 13'd31;
  105. spotlight[1] = 13'd32;
  106. spotlight[2] = 13'd63;
  107. spotlight[3] = 13'd64;
  108. spotlight[4] = 13'd100;
  109. spotlight[5] = 13'd2047;
  110. spotlight[6] = 13'd2048;
  111. spotlight[7] = 13'd4095;
  112. spotlight[8] = 13'd4096;
  113. spotlight[9] = 13'd4999;
  114. spotlight[10] = 13'd5000;
  115. repeat (4) @(posedge clk);
  116. rst_n = 1'b1;
  117. @(negedge clk);
  118. // Spotlight vectors first (all levels) — diagnostic only.
  119. for (si = 0; si < 11; si = si + 1) begin
  120. for (li = 0; li < 16; li = li + 1) begin
  121. travel_tmp = spotlight[si];
  122. level_tmp = li[3:0];
  123. axis_tmp = 2'd1;
  124. run_one;
  125. end
  126. end
  127. if (mismatches != 0 || zeros_bad != 0)
  128. $fatal(1, "spotlight FAIL mismatches=%0d zeros_bad=%0d", mismatches, zeros_bad);
  129. $display("spotlight PASS vectors=%0d", checked);
  130. mismatches = 0;
  131. zeros_bad = 0;
  132. checked = 0;
  133. // Full exhaustive 2..5000 × 0..15 = 79984
  134. for (ti = 2; ti <= 5000; ti = ti + 1) begin
  135. for (li = 0; li < 16; li = li + 1) begin
  136. travel_tmp = ti[12:0];
  137. level_tmp = li[3:0];
  138. axis_tmp = ti[1:0];
  139. run_one;
  140. end
  141. if ((ti % 500) == 0)
  142. $display("progress travel=%0d checked=%0d mismatches=%0d", ti, checked, mismatches);
  143. end
  144. if (mismatches != 0 || zeros_bad != 0)
  145. $fatal(1, "FAIL mismatches=%0d zeros_bad=%0d checked=%0d",
  146. mismatches, zeros_bad, checked);
  147. if (checked != 79984)
  148. $fatal(1, "unexpected checked=%0d want 79984", checked);
  149. $display("door_rate_quantum_builder_exhaustive_tb PASS checked=%0d", checked);
  150. $finish;
  151. end
  152. endmodule