فهرست منبع

fix(mse): cut A2 area to device fit (incremental S-curve).

Replace per-axis 15-iter profile-level scan with O(1) climb/drop and
single-add DDA datapaths so gate LUT/MSLICE pack under EF2L45 limits.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 ماه پیش
والد
کامیت
bd1353f83e

+ 22 - 13
receipts/mse-round2-intermediate-summary.md

@@ -6,6 +6,14 @@
 - Hardware validation: **NOT RUN**
 - `dev` lock: `d4f3df2549efeb1e9227f62d1d71c6179c9f9160` (untouched)
 
+## Area opt1 (follow-up after 79a5cee)
+- Incremental S-curve level (replace 15-iter combinational scan) + single-add A2 DDA + drop dead `mul_level`
+- TD **FIT**: gate LUT **3916**/4480 (87.4%); phy LUT 4079; MSLICE **1030**/1120; motor LUT **2453**
+- Fmax **42.6 MHz**, SWNS **+16.5 ns** (meets 25 MHz; slower than R12/B-opt2)
+- vs 79a5cee: −626 gate LUT, −554 motor LUT, −170 MSLICE
+- vs B-opt2: −68 gate LUT; vs R12: still +1023 gate LUT
+- Evidence: `receipts/mse-td-a2-opt1-phy.json`, `/data/prod2u/td-runs/mse-opt1-a2-20260811T153714Z`
+
 ## Verification
 
 | Lane | Status | Notes |
@@ -13,21 +21,22 @@
 | Verilator lint | PASS | prior after lint fixes |
 | Cocotb UART e2e | **PASS** | `mse-r2-cocotb-fix-20260811T140948Z`; serial per-axis limit stimulus |
 | Formal full manifest | **PASS** | `mse-r2-formal-rerun-20260811T145145Z` after snapshot `.sby` A2 fix |
-| TD full A2 | **FAIL** packing | gate LUT 4542/4480; MSLICE 1200>1120; Fmax/SWNS not_run |
+| Icarus door focus (opt1) | PASS | profile/serial/overlap/travel; status_payload + planner_grant_once pre-existing fail on tip |
+| TD A2 @ 79a5cee | **FAIL** packing | gate 4542 / MSLICE 1200 |
+| TD A2 opt1 | **FIT** | gate 3916 / MSLICE 1030; manual dirty-WIP TD |
 
-## Resources vs Round-12 / B opt2
+## Resources vs Round-12 / B opt2 / A2
 
-| Metric | Round-12 | B opt2 | Full A2 (gate/pack) |
-|--------|----------|--------|---------------------|
-| LUT | 2893 | 3984 | **4542** |
-| Motor LUT | 1593 | 2555 | **3007** |
-| REG | 1233 | — | 1620 |
-| BRAM/DSP | 0/0 | — | 0/0 |
-| MSLICE | fit | fit | **1200 > 1120 FAIL** |
-| Fmax MHz | 67.1 | 61.7 | not_run |
-| SWNS ns | +25.1 | +23.8 | not_run |
+| Metric | Round-12 | B opt2 | A2 @79a5cee | A2 opt1 |
+|--------|----------|--------|-------------|---------|
+| LUT (gate) | 2893 | 3984 | **4542 FAIL** | **3916 FIT** |
+| Motor LUT | 1593 | 2555 | 3007 | 2453 |
+| MSLICE | fit | fit | **1200 FAIL** | **1030 FIT** |
+| Fmax MHz | 67.1 | 61.7 | not_run | 42.6 |
+| SWNS ns | +25.1 | +23.8 | not_run | +16.5 |
 
 ## Blockers for final
-1. Area fit (LUT/MSLICE) for A2
+1. ~~Area fit (LUT/MSLICE) for A2~~ — cleared by opt1 (pending official clean-tree `verify.sh --lane td`)
 2. Official clean-tree `verify.sh --lane td` after commit
-3. Five-audit closure after TD fit
+3. Pro reply / five-audit closure; still intermediate until Pro
+4. Fmax below R12/B-opt2 (optional further slice if Pro asks)

+ 57 - 0
receipts/mse-td-a2-opt1-phy.json

@@ -0,0 +1,57 @@
+{
+  "schema": "prod2u-mse-a2-opt1-td-phy-v1",
+  "generated_utc": "2026-08-11T15:39:07Z",
+  "status": "pass_fit",
+  "note": "Area opt1: incremental S-curve level (drop 15-iter unroll), single-add A2 DDA, drop dead mul_level. Manual TD (dirty WIP). Packing FIT.",
+  "td_work": "/data/prod2u/td-runs/mse-opt1-a2-20260811T153714Z",
+  "tool": "td2026",
+  "gate_lut": 3916,
+  "gate_lut_total": 4480,
+  "gate_lut_percent": 87.41,
+  "post_opt_total_luts": 3168,
+  "phy_lut": 4079,
+  "phy_lut_percent": 91.05,
+  "reg_used": 1659,
+  "bram_used": 0,
+  "dsp_used": 0,
+  "motor_lut": 2453,
+  "axis_luts": {
+    "x": 601,
+    "y": 631,
+    "z": 604
+  },
+  "dda_lut": 214,
+  "packing": {
+    "mslice": 1030,
+    "lslice": 1031,
+    "mslice_limit": 1120,
+    "fit": true
+  },
+  "fmax_mhz": 42.579,
+  "swns_ns": 16.514,
+  "compare": {
+    "baseline_79a5cee": {
+      "gate_lut": 4542,
+      "motor_lut": 3007,
+      "mslice": 1200,
+      "fit": false
+    },
+    "round12": {
+      "lut": 2893,
+      "motor_lut": 1593,
+      "fmax_mhz": 67.1,
+      "swns_ns": 25.1
+    },
+    "b_opt2": {
+      "lut": 3984,
+      "motor_lut": 2555,
+      "fmax_mhz": 61.709,
+      "swns_ns": 23.795
+    },
+    "delta_vs_79a5cee_gate_lut": -626,
+    "delta_vs_79a5cee_motor_lut": -554,
+    "delta_vs_79a5cee_mslice": -170
+  },
+  "hardware_validation": "NOT RUN",
+  "dev_lock": "d4f3df2549efeb1e9227f62d1d71c6179c9f9160"
+}

+ 32 - 28
src/modules/door_axis_controller.v

@@ -100,6 +100,8 @@ module door_axis_controller #(
     reg        wd_stopped;
     reg        open_limit_armed;
     reg        close_limit_armed;
+    // Cached L*unit for O(1) S-curve climb/drop (avoids 15-iter combo unroll).
+    reg [CNT_W-1:0] profile_level_thresh;
 
     assign calibrated = calibrated_r;
     assign faulted = (status_state == ST_FAULT);
@@ -124,32 +126,8 @@ module door_axis_controller #(
     // DDA only while producing/consuming half-cycles; DIR_SETUP clears phase via !active.
     assign axis_dda_run = (phase == PH_RUN) || (phase == PH_DRAIN_HIGH);
 
-    // level = min(15, floor(done/unit), floor((remaining-1)/unit)) via repeated add (no divider).
-    function automatic [3:0] f_profile_level;
-        input [CNT_W-1:0] done_i;
-        input [CNT_W-1:0] remaining_i;
-        input [CNT_W-1:0] unit_i;
-        integer L;
-        reg [CNT_W-1:0] thresh;
-        reg [CNT_W-1:0] rem_term_limit;
-        reg [3:0] best;
-        begin
-            best = 4'd0;
-            if (unit_i == {CNT_W{1'b0}}) begin
-                f_profile_level = 4'd0;
-            end else begin
-                rem_term_limit = (remaining_i < {{(CNT_W-1){1'b0}}, 1'b1}) ?
-                    {CNT_W{1'b0}} : (remaining_i - {{(CNT_W-1){1'b0}}, 1'b1});
-                thresh = {CNT_W{1'b0}};
-                for (L = 1; L <= 15; L = L + 1) begin
-                    thresh = thresh + unit_i;
-                    if ((done_i >= thresh) && (rem_term_limit >= thresh))
-                        best = L[3:0];
-                end
-                f_profile_level = best;
-            end
-        end
-    endfunction
+    // Incremental level matching min(15, floor(done/u), floor((rem-1)/u)).
+    // One add/compare per rise (no 15-iter combinational scan).
 
     function automatic [CNT_W-1:0] f_ramp_unit;
         input [CNT_W-1:0] distance_i;
@@ -282,6 +260,7 @@ module door_axis_controller #(
             open_limit_armed <= 1'b1;
             close_limit_armed <= 1'b1;
             profile_level <= 4'd0;
+            profile_level_thresh <= {CNT_W{1'b0}};
             profile_distance <= {CNT_W{1'b0}};
             profile_done_steps <= {CNT_W{1'b0}};
             profile_ramp_unit <= {{(CNT_W-1){1'b0}}, 1'b1};
@@ -337,14 +316,33 @@ module door_axis_controller #(
                         begin : sc_rise
                             reg [CNT_W-1:0] done_n;
                             reg [CNT_W-1:0] rem_n;
+                            reg [CNT_W-1:0] rem_term;
+                            reg [CNT_W-1:0] next_thr;
                             done_n = profile_done_steps + 1'b1;
                             rem_n = (profile_distance > done_n) ?
                                     (profile_distance - done_n) : {CNT_W{1'b0}};
+                            rem_term = (rem_n < {{(CNT_W-1){1'b0}}, 1'b1}) ?
+                                       {CNT_W{1'b0}} : (rem_n - {{(CNT_W-1){1'b0}}, 1'b1});
                             profile_done_steps <= done_n;
-                            profile_level <= f_profile_level(done_n, rem_n, profile_ramp_unit);
+                            if (profile_ramp_unit == {CNT_W{1'b0}}) begin
+                                profile_level <= 4'd0;
+                                profile_level_thresh <= {CNT_W{1'b0}};
+                            end else if ((profile_level != 4'd0) &&
+                                         (rem_term < profile_level_thresh)) begin
+                                profile_level <= profile_level - 4'd1;
+                                profile_level_thresh <=
+                                    profile_level_thresh - profile_ramp_unit;
+                            end else if (profile_level < 4'd15) begin
+                                next_thr = profile_level_thresh + profile_ramp_unit;
+                                if ((done_n >= next_thr) && (rem_term >= next_thr)) begin
+                                    profile_level <= profile_level + 4'd1;
+                                    profile_level_thresh <= next_thr;
+                                end
+                            end
                         end
                     end else if (moving && endpoint_mode) begin
                         profile_level <= 4'd0;
+                        profile_level_thresh <= {CNT_W{1'b0}};
                     end
                 end
             end
@@ -447,7 +445,9 @@ module door_axis_controller #(
                     profile_distance <= dist_n;
                     profile_ramp_unit <= unit_n;
                     profile_done_steps <= {CNT_W{1'b0}};
-                    profile_level <= f_profile_level({CNT_W{1'b0}}, dist_n, unit_n);
+                    // done==0 ⇒ level 0 (same as prior full scan).
+                    profile_level <= 4'd0;
+                    profile_level_thresh <= {CNT_W{1'b0}};
                 end
                 if (planner_result == effective_current_position) begin
                     status_state <= ST_IDLE;
@@ -479,6 +479,7 @@ module door_axis_controller #(
                     phase <= PH_DIR_SETUP;
                     moving <= 1'b1;
                     profile_level <= 4'd0;
+                    profile_level_thresh <= {CNT_W{1'b0}};
                     profile_done_steps <= {CNT_W{1'b0}};
                     profile_distance <= {CNT_W{1'b0}};
                     profile_ramp_unit <= CAL_RAMP_UNIT[CNT_W-1:0];
@@ -506,6 +507,7 @@ module door_axis_controller #(
                     moving <= 1'b1;
                     // Rebuild soft-start for measure-open (no S decelerate claimed).
                     profile_level <= 4'd0;
+                    profile_level_thresh <= {CNT_W{1'b0}};
                     profile_done_steps <= {CNT_W{1'b0}};
                     status_state <= ST_CAL_MEASURE_OPEN;
                 end else if (stop_after_budget && !gated_step && !step) begin
@@ -649,6 +651,7 @@ module door_axis_controller #(
                         need_planner <= 1'b0;
                         planner_req <= 1'b0;
                         profile_level <= 4'd0;
+                        profile_level_thresh <= {CNT_W{1'b0}};
                         profile_done_steps <= {CNT_W{1'b0}};
                         if (open_limit) begin
                             current_position <= {CNT_W{1'b0}};
@@ -674,6 +677,7 @@ module door_axis_controller #(
                         need_planner <= 1'b0;
                         planner_req <= 1'b0;
                         profile_level <= 4'd0;
+                        profile_level_thresh <= {CNT_W{1'b0}};
                         profile_done_steps <= {CNT_W{1'b0}};
                         if (close_limit) begin
                             current_position <= travel_steps;

+ 0 - 5
src/modules/door_motion_controller.v

@@ -102,7 +102,6 @@ module door_motion_controller #(
     reg [8:0]   mul_scale;
     reg [20:0]  mul_acc;
     reg [3:0]   mul_bit;
-    reg [3:0]   mul_level;
 
     function automatic [8:0] f_profile_scale;
         input [3:0] level;
@@ -253,7 +252,6 @@ module door_motion_controller #(
             mul_scale <= 9'd0;
             mul_acc <= 21'd0;
             mul_bit <= 4'd0;
-            mul_level <= 4'd0;
         end else begin
             rate_valid <= 1'b0;
             if (!rate_busy) begin
@@ -263,17 +261,14 @@ module door_motion_controller #(
                 mul_acc <= 21'd0;
                 case (rate_axis)
                     2'd0: begin
-                        mul_level <= crawl_x ? 4'd0 : lvl_x;
                         mul_travel <= in_cal_x ? 13'd1 : ((st_trav_x == 0) ? 13'd1 : st_trav_x);
                         mul_scale <= f_profile_scale(crawl_x ? 4'd0 : lvl_x);
                     end
                     2'd1: begin
-                        mul_level <= crawl_y ? 4'd0 : lvl_y;
                         mul_travel <= in_cal_y ? 13'd1 : ((st_trav_y == 0) ? 13'd1 : st_trav_y);
                         mul_scale <= f_profile_scale(crawl_y ? 4'd0 : lvl_y);
                     end
                     default: begin
-                        mul_level <= crawl_z ? 4'd0 : lvl_z;
                         mul_travel <= in_cal_z ? 13'd1 : ((st_trav_z == 0) ? 13'd1 : st_trav_z);
                         mul_scale <= f_profile_scale(crawl_z ? 4'd0 : lvl_z);
                     end

+ 35 - 39
src/modules/door_shared_dda_scheduler.v

@@ -1,7 +1,6 @@
 `timescale 1ns/1ps
 
-// Scheme A2 winner (provisional hierarchy): three parallel narrow DDA datapaths.
-// A1 sequential shared add/compare/sub archived under receipts/scheme-a-a2-attempt/.
+// Scheme A2: three parallel narrow DDA datapaths (one add/compare/sub each).
 // On each motion_service_ce, all active axes update in one clock.
 module door_shared_dda_scheduler #(
     parameter integer PHASE_WIDTH  = 26,
@@ -33,37 +32,6 @@ 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];
 
-    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;
-        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 (sum >= thr)
-                    f_next = sum - thr;
-                else
-                    f_next = sum;
-            end
-        end
-    endfunction
-
-    function automatic f_fire;
-        input [PHASE_WIDTH-1:0] ph;
-        input [RATE_WIDTH-1:0]  rate;
-        input [PHASE_WIDTH-1:0] thr;
-        input                   en;
-        reg   [PHASE_WIDTH-1:0] sum;
-        begin
-            sum = ph + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate};
-            f_fire = en && (sum >= thr);
-        end
-    endfunction
-
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
             phase0 <= {PHASE_WIDTH{1'b0}};
@@ -78,15 +46,43 @@ module door_shared_dda_scheduler #(
             if (service_ce) begin
                 begin : par
                     reg [PHASE_WIDTH-1:0] t0, t1, t2;
+                    reg [PHASE_WIDTH-1:0] s0, s1, s2;
                     t0 = cal_mode[0] ? thr_cal : thr_run;
                     t1 = cal_mode[1] ? thr_cal : thr_run;
                     t2 = cal_mode[2] ? thr_cal : thr_run;
-                    toggle_pulse[0] <= f_fire(phase0, rate0, t0, active[0]);
-                    toggle_pulse[1] <= f_fire(phase1, rate1, t1, active[1]);
-                    toggle_pulse[2] <= f_fire(phase2, rate2, t2, active[2]);
-                    phase0 <= f_next(phase0, rate0, t0, active[0]);
-                    phase1 <= f_next(phase1, rate1, t1, active[1]);
-                    phase2 <= f_next(phase2, rate2, t2, active[2]);
+                    if (active[0]) begin
+                        s0 = phase0 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate0};
+                        if (s0 >= t0) begin
+                            toggle_pulse[0] <= 1'b1;
+                            phase0 <= s0 - t0;
+                        end else begin
+                            phase0 <= s0;
+                        end
+                    end else begin
+                        phase0 <= {PHASE_WIDTH{1'b0}};
+                    end
+                    if (active[1]) begin
+                        s1 = phase1 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate1};
+                        if (s1 >= t1) begin
+                            toggle_pulse[1] <= 1'b1;
+                            phase1 <= s1 - t1;
+                        end else begin
+                            phase1 <= s1;
+                        end
+                    end else begin
+                        phase1 <= {PHASE_WIDTH{1'b0}};
+                    end
+                    if (active[2]) begin
+                        s2 = phase2 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate2};
+                        if (s2 >= t2) begin
+                            toggle_pulse[2] <= 1'b1;
+                            phase2 <= s2 - t2;
+                        end else begin
+                            phase2 <= s2;
+                        end
+                    end else begin
+                        phase2 <= {PHASE_WIDTH{1'b0}};
+                    end
                 end
             end
         end