소스 검색

Share queue-space and insertion-address calculations across scratch rows

codex 3 달 전
부모
커밋
dc050bda81
1개의 변경된 파일과 18개의 추가작업 그리고 21개의 파일을 삭제
  1. 18 21
      src/motor/motor_engine.v

+ 18 - 21
src/motor/motor_engine.v

@@ -189,13 +189,9 @@ module motor_engine #(
     reg [5:0] qc_new_count [0:AXIS_COUNT-1];
     reg [4:0] qc_new_head [0:AXIS_COUNT-1];
     reg [AXIS_COUNT-1:0] qc_resume, start_credit;
-    reg qc_space_bad;
-    integer space_axis;
-    always @* begin
-        qc_space_bad=0;
-        for(space_axis=0;space_axis<AXIS_COUNT;space_axis=space_axis+1)
-            if(qc_old_depth[space_axis]+qc_new_count[space_axis]>32) qc_space_bad=1;
-    end
+    reg [AXIS_INDEX_BITS-1:0] qc_space_axis;
+    wire [6:0] qc_space_total={1'b0,qc_old_depth[qc_space_axis]}+{1'b0,qc_new_count[qc_space_axis]};
+    wire qc_space_bad=qc_space_total>7'd32;
     reg [5:0] qc_proj_depth [0:AXIS_COUNT-1];   // projected waiting depth
     reg [5:0] qc_append_pos [0:AXIS_COUNT-1];   // next free slot per axis
     reg [AXIS_COUNT-1:0] qc_first_of_axis;
@@ -577,7 +573,7 @@ module motor_engine #(
     // ---- main sequencer: batch validate/commit + fetch + control ----
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
-            qc_state <= QC_IDLE; qc_index <= 4'd0;start_credit<=0;
+            qc_state <= QC_IDLE;qc_space_axis<=0; qc_index <= 4'd0;start_credit<=0;
             stage_byte_index<=0;stage_for_write<=0;stage_data<=0;
             qw_accept <= 1'b0; qw_status <= 8'd0; qw_detail <= 16'd0;
             ctl_accept <= 1'b0; ctl_status <= 8'd0; ctl_detail <= 16'd0;
@@ -621,7 +617,7 @@ module motor_engine #(
                     qw_accept<=1;qw_status<=ST_BAD_VALUE;qw_detail<=0;
                 end else begin qc_count<=qw_count;qc_state<=QC_QUIESCE;end
             end else if(qc_state==QC_QUIESCE && fx_state==FX_IDLE && ax_seg_load==0) begin
-                qc_index<=0;qc_is_urgent<=0;
+                qc_index<=0;qc_is_urgent<=0;qc_space_axis<=0;
                 for(i=0;i<AXIS_COUNT;i=i+1) begin
                     qc_old_depth[i]<=depth_r[i];qc_new_count[i]<=0;
                     qc_first_of_axis[i]<=1;qc_want_preempt[i]<=0;qc_want_clear[i]<=0;qc_resume[i]<=0;
@@ -659,18 +655,19 @@ module motor_engine #(
                 if(qc_space_bad) begin
                     qw_accept<=1;qw_status<=8'd5;qw_detail<=0;qc_state<=QC_IDLE;
                 end else begin
-                    for(i=0;i<AXIS_COUNT;i=i+1) begin
-                        // Preempt's new waiting segments precede the old queue.
-                        // Clear permits reusing old slots only AFTER validation.
-                        qc_proj_depth[i]<=qc_old_depth[i]+qc_new_count[i];
-                        qc_new_head[i]<=qc_want_preempt[i] && !qc_want_clear[i] ?
-                            (head_r[i][4:0]-qc_new_count[i][4:0]) : head_r[i][4:0];
-                        qc_append_pos[i]<=qc_want_preempt[i] ?
-                            (qc_want_clear[i] ? head_r[i][4:0] :
-                                ((head_r[i][4:0]-qc_new_count[i][4:0]) & 5'h1F)) :
-                            ((head_r[i][4:0]+qc_old_depth[i][4:0]) & 5'h1F);
-                    end
-                    qc_index<=0;stage_byte_index<=0;stage_for_write<=1;qc_state<=QC_STAGE_WAIT;
+                    // One queue-space/address datapath serves one scratch
+                    // row per clock. No live queue state or RAM is published
+                    // until every row and every descriptor has passed.
+                    qc_proj_depth[qc_space_axis]<=qc_space_total[5:0];
+                    qc_new_head[qc_space_axis]<=qc_want_preempt[qc_space_axis] && !qc_want_clear[qc_space_axis] ?
+                        (head_r[qc_space_axis][4:0]-qc_new_count[qc_space_axis][4:0]) : head_r[qc_space_axis][4:0];
+                    qc_append_pos[qc_space_axis]<=qc_want_preempt[qc_space_axis] ?
+                        (qc_want_clear[qc_space_axis] ? head_r[qc_space_axis][4:0] :
+                            ((head_r[qc_space_axis][4:0]-qc_new_count[qc_space_axis][4:0]) & 5'h1F)) :
+                        ((head_r[qc_space_axis][4:0]+qc_old_depth[qc_space_axis][4:0]) & 5'h1F);
+                    if(qc_space_axis==AXIS_COUNT-1)begin
+                        qc_index<=0;stage_byte_index<=0;stage_for_write<=1;qc_state<=QC_STAGE_WAIT;
+                    end else qc_space_axis<=qc_space_axis+1'b1;
                 end
             end else if(qc_state==QC_WRITE) begin
                 if(qc_index==qc_count) qc_state<=QC_DRAIN;