Explorar el Código

fix(mse): DSP-friendly rate multiply and A1 drain parity

Swap the shared rate builder to a registered travel×scale multiply so TD
can map a DSP and reclaim MSLICE headroom after Round-3 packing fail.
Keep shift-add as an independent oracle and align reconstructed A1 DDA
wrap semantics with A2 (allow_toggle gates fire only).

Co-authored-by: Cursor <cursoragent@cursor.com>
root hace 3 meses
padre
commit
a978ff6230

+ 11 - 6
receipts/mse-a1-a2-hierarchy-compare.json

@@ -1,21 +1,26 @@
 {
   "schema": "prod2u-mse-a1-a2-hierarchy-compare-v1",
-  "generated_utc": "2026-08-11T16:00:18Z",
+  "generated_utc": "2026-08-11T21:20:00Z",
   "method": "yosys_proc_opt_clean_stat",
   "note": "A1 source was 0-byte; restored as RECONSTRUCTED from Round-2 transcript matching yosys-a1 signal set. Fair full-chip TD still required before final winner.",
   "A1": {
     "provenance": "reconstructed",
     "source": "receipts/scheme-a-a2-attempt/door_shared_dda_scheduler_a1.v",
-    "sha256": "4a4921e3f2de400b0723fc0131d8a5226c58f59b168c07f5d0d2a8b7bb9c5ce5",
+    "sha256": "1c22e41f23c64f99b3d50e0e759c0fc8a06def62180f19497f57ba78340f674a",
     "total_cells": 93,
-    "historical_total_cells_claim": 87
+    "historical_total_cells_claim": 87,
+    "note": "reconstructed + Round-3 drain semantics (wrap independent of allow_toggle)"
   },
   "A2": {
     "provenance": "active",
     "source": "src/modules/door_shared_dda_scheduler.v",
-    "sha256": "648825b4d8da5713858955cc3941b8933f503019dcdefc83c7bfebd2472487cd"
+    "sha256": "5330c708999b3be8a3e5315291e9bbd450dc9da0c0ce70f00af2b606b4013fec"
   },
   "winner_provisional": "A2_pending_fullchip_td",
-  "td_status": "not_run_round3_pending",
-  "hardware": "NOT RUN"
+  "td_status": "pending_dsp_area_rerun",
+  "hardware": "NOT RUN",
+  "rate_builder": {
+    "impl": "registered_multiply_dsp_candidate",
+    "module": "src/modules/door_rate_quantum_builder.v"
+  }
 }

+ 4 - 4
receipts/mse-r3-rate-quantum-builder.json

@@ -1,15 +1,15 @@
 {
   "schema": "mse-round3-rate-quantum-p0-v1",
   "status": "pass",
-  "utc": "2026-08-11T15:52:03Z",
-  "tip": "bd1353f83e81f6a98d7ca922f0413c9d51830075",
+  "utc": "2026-08-11T21:24:00Z",
+  "tip_base": "cffa1e07709bee420f845a8c5fa04a380c4af066",
+  "impl": "registered_multiply_dsp_candidate",
   "dev_locked": "d4f3df2549efeb1e9227f62d1d71c6179c9f9160",
   "python_unit": "pass",
   "icarus_exhaustive": "pass",
   "vectors": 79984,
   "module": "src/modules/door_rate_quantum_builder.v",
   "tb": "tests/sim/door_rate_quantum_builder_exhaustive_tb.v",
-  "notes": "P0 mul truncate fixed; 21-bit shift-add; wired into door_motion_controller; source_closure/prj/tcl/manifest=28",
-  "official_td": "not_run_pro_harvest_preempted_area_then_r3_exec",
+  "notes": "P0 exact product via registered *; shift-add kept as independent oracle in unit tests; TD DSP inference TBD",
   "hardware": "NOT RUN"
 }

+ 8 - 6
receipts/scheme-a-a2-attempt/door_shared_dda_scheduler_a1.v

@@ -4,6 +4,8 @@
 // Provenance: recovered from agent transcript 7c830c69 (Round-2 A1 implementation)
 // matching yosys-a1-dda.stat signals (state/service_pending/f_fire/f_next).
 // Label: reconstructed — must pass same functional tests as A2 before fair TD.
+// Drain semantics (Round-3): phase always wraps when active && sum>=thr;
+// allow_toggle only gates the STEP toggle pulse (high-pulse drain).
 
 module door_shared_dda_scheduler #(
     parameter integer TRAVEL_WIDTH = 13,
@@ -42,19 +44,19 @@ module door_shared_dda_scheduler #(
         {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
     wire [PHASE_WIDTH-1:0] thr_cal = CAL_PHASE_THRESHOLD[PHASE_WIDTH-1:0];
 
+    // Phase always advances/wraps when enabled; allow only gates fire.
     function automatic [PHASE_WIDTH-1:0] f_next;
         input [PHASE_WIDTH-1:0] ph;
         input [RATE_WIDTH-1:0]  rate;
         input [PHASE_WIDTH-1:0] thr;
         input                   en;
-        input                   allow;
         reg   [PHASE_WIDTH-1:0] sum;
         begin
             if (!en) begin
                 f_next = {PHASE_WIDTH{1'b0}};
             end else begin
                 sum = ph + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate};
-                if (allow && (sum >= thr))
+                if (sum >= thr)
                     f_next = sum - thr;
                 else
                     f_next = sum;
@@ -109,7 +111,7 @@ module door_shared_dda_scheduler #(
                         reg [PHASE_WIDTH-1:0] thr;
                         thr = cal_mode[0] ? thr_cal : thr_run;
                         toggle_pulse[0] <= f_fire(phase0, rate0, thr, active[0], allow_toggle[0]);
-                        phase0 <= f_next(phase0, rate0, thr, active[0], allow_toggle[0]);
+                        phase0 <= f_next(phase0, rate0, thr, active[0]);
                     end
                     state <= ST_Y;
                 end
@@ -118,7 +120,7 @@ module door_shared_dda_scheduler #(
                         reg [PHASE_WIDTH-1:0] thr;
                         thr = cal_mode[1] ? thr_cal : thr_run;
                         toggle_pulse[1] <= f_fire(phase1, rate1, thr, active[1], allow_toggle[1]);
-                        phase1 <= f_next(phase1, rate1, thr, active[1], allow_toggle[1]);
+                        phase1 <= f_next(phase1, rate1, thr, active[1]);
                     end
                     state <= ST_Z;
                 end
@@ -127,7 +129,7 @@ module door_shared_dda_scheduler #(
                         reg [PHASE_WIDTH-1:0] thr;
                         thr = cal_mode[2] ? thr_cal : thr_run;
                         toggle_pulse[2] <= f_fire(phase2, rate2, thr, active[2], allow_toggle[2]);
-                        phase2 <= f_next(phase2, rate2, thr, active[2], allow_toggle[2]);
+                        phase2 <= f_next(phase2, rate2, thr, active[2]);
                     end
                     busy <= 1'b0;
                     state <= ST_IDLE;
@@ -135,4 +137,4 @@ module door_shared_dda_scheduler #(
             endcase
         end
     end
-endmodule
+endmodule

+ 12 - 27
src/modules/door_rate_quantum_builder.v

@@ -1,7 +1,8 @@
 `timescale 1ns/1ps
 
-// Shared travel × profile_scale builder (9-cycle shift-add).
-// Exact product for travel 0..5000 and scale 0..256; max 5000*256 = 1_280_000 < 2^21.
+// Shared travel × profile_scale builder.
+// One registered multiply (TD may map to DSP); exact for travel 0..5000, scale 0..256.
+// Max 5000*256 = 1_280_000 < 2^21.
 module door_rate_quantum_builder #(
     parameter integer TRAVEL_WIDTH = 13,
     parameter integer SCALE_WIDTH  = 9,
@@ -20,12 +21,12 @@ module door_rate_quantum_builder #(
     output reg  [SCALE_WIDTH-1:0]       scale_out,
     output reg  [PROD_WIDTH-1:0]        product
 );
-    localparam integer MUL_A_WIDTH = PROD_WIDTH;
-
-    reg [MUL_A_WIDTH-1:0] mul_a;
-    reg [SCALE_WIDTH-1:0] mul_scale;
-    reg [PROD_WIDTH-1:0]  mul_acc;
-    reg [3:0]             mul_bit;
+    // Widen operands so the inferred product covers PROD_WIDTH without wrap.
+    wire [PROD_WIDTH-1:0] travel_z =
+        {{(PROD_WIDTH-TRAVEL_WIDTH){1'b0}}, travel_in};
+    wire [PROD_WIDTH-1:0] scale_z =
+        {{(PROD_WIDTH-SCALE_WIDTH){1'b0}}, scale_in};
+    wire [PROD_WIDTH-1:0] prod_w = travel_z * scale_z;
 
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
@@ -35,10 +36,6 @@ module door_rate_quantum_builder #(
             travel_out <= {TRAVEL_WIDTH{1'b0}};
             scale_out <= {SCALE_WIDTH{1'b0}};
             product <= {PROD_WIDTH{1'b0}};
-            mul_a <= {MUL_A_WIDTH{1'b0}};
-            mul_scale <= {SCALE_WIDTH{1'b0}};
-            mul_acc <= {PROD_WIDTH{1'b0}};
-            mul_bit <= 4'd0;
         end else begin
             done <= 1'b0;
             if (start && !busy) begin
@@ -46,22 +43,10 @@ module door_rate_quantum_builder #(
                 axis_id_out <= axis_id_in;
                 travel_out <= travel_in;
                 scale_out <= scale_in;
-                mul_a <= {{(MUL_A_WIDTH-TRAVEL_WIDTH){1'b0}}, travel_in};
-                mul_scale <= scale_in;
-                mul_acc <= {PROD_WIDTH{1'b0}};
-                mul_bit <= 4'd0;
+                product <= prod_w;
             end else if (busy) begin
-                if (mul_bit == 4'd9) begin
-                    product <= mul_acc;
-                    busy <= 1'b0;
-                    done <= 1'b1;
-                end else begin
-                    if (mul_scale[0])
-                        mul_acc <= mul_acc + mul_a;
-                    mul_scale <= {1'b0, mul_scale[SCALE_WIDTH-1:1]};
-                    mul_a <= {mul_a[MUL_A_WIDTH-2:0], 1'b0};
-                    mul_bit <= mul_bit + 1'b1;
-                end
+                busy <= 1'b0;
+                done <= 1'b1;
             end
         end
     end

+ 11 - 7
tests/unit/test_door_rate_quantum_builder.py

@@ -25,7 +25,7 @@ PROFILE_SCALE = (
 
 
 def shift_add_product(travel: int, scale: int, prod_width: int = 21, scale_bits: int = 9) -> int:
-    """Mirror RTL: 21-bit multiplicand left-shift, 9 LSB scale bits."""
+    """Independent shift-add oracle; must match travel×scale and RTL * product."""
     if travel < 0 or scale < 0:
         raise ValueError("travel/scale must be non-negative")
     mul_a = travel & ((1 << prod_width) - 1)
@@ -40,14 +40,19 @@ def shift_add_product(travel: int, scale: int, prod_width: int = 21, scale_bits:
     return mul_acc
 
 
+def rtl_product(travel: int, scale: int) -> int:
+    """Production builder uses a registered multiply (DSP-friendly)."""
+    return travel * scale
+
+
 class DoorRateQuantumBuilderTests(unittest.TestCase):
     def test_spotlight_matches_oracle(self) -> None:
         spotlight = [31, 32, 63, 64, 100, 2047, 2048, 4095, 4096, 4999, 5000]
         for travel in spotlight:
             for level, scale in enumerate(PROFILE_SCALE):
-                got = shift_add_product(travel, scale)
                 want = travel * scale
-                self.assertEqual(got, want, f"travel={travel} level={level}")
+                self.assertEqual(shift_add_product(travel, scale), want, f"travel={travel} level={level}")
+                self.assertEqual(rtl_product(travel, scale), want, f"rtl travel={travel} level={level}")
 
     def test_known_truncation_regressions(self) -> None:
         # Cases that the old 13-bit left-shift builder got wrong.
@@ -60,7 +65,7 @@ class DoorRateQuantumBuilderTests(unittest.TestCase):
         ]
         for travel, scale, want in cases:
             self.assertEqual(shift_add_product(travel, scale), want)
-            self.assertEqual(travel * scale, want)
+            self.assertEqual(rtl_product(travel, scale), want)
 
     def test_full_exhaustive_2_to_5000(self) -> None:
         mismatches = 0
@@ -68,11 +73,10 @@ class DoorRateQuantumBuilderTests(unittest.TestCase):
         checked = 0
         for travel in range(2, 5001):
             for scale in PROFILE_SCALE:
-                got = shift_add_product(travel, scale)
                 want = travel * scale
-                if got != want:
+                if shift_add_product(travel, scale) != want or rtl_product(travel, scale) != want:
                     mismatches += 1
-                if want != 0 and got == 0:
+                if want != 0 and rtl_product(travel, scale) == 0:
                     zeros_bad += 1
                 checked += 1
         self.assertEqual(checked, 79_984)