diff --git a/sync_rtl/sample_ntt/sample_ntt_sync.v b/sync_rtl/sample_ntt/sample_ntt_sync.v index 62539fe..afc1658 100644 --- a/sync_rtl/sample_ntt/sample_ntt_sync.v +++ b/sync_rtl/sample_ntt/sample_ntt_sync.v @@ -210,6 +210,10 @@ module sample_ntt_sync #(parameter K = 4) ( // d2 rejected, no longer need coefficients, or d2 was just accepted out. wire grp_done = (state_r == ST_SQUEEZE) && (sq_phase_r == 2'd2) && (!d2_acc_r || !need_more || (valid_o_r && ready_i)); + // `need_more` observes the registered counter before the final d2 + // handshake increments it. Detect that boundary explicitly so a full + // rate block does not launch an unnecessary final re-permutation. + wire completes_output = valid_o_r && ready_i && (coeff_cnt_r == 9'd255); // ================================================================ // FSM: state_next (combinational) @@ -235,7 +239,7 @@ module sample_ntt_sync #(parameter K = 4) ( // next group in this block, re-permute (block exhausted), or // finish. if (grp_done) begin - if (!need_more) + if (!need_more || completes_output) state_next = ST_DONE; else if (grp_ptr_r < GRP_MAX) state_next = ST_SQUEEZE; // next group, no re-permute diff --git a/sync_rtl/sample_ntt/sample_ntt_sync_shared.v b/sync_rtl/sample_ntt/sample_ntt_sync_shared.v index 9896ba2..43944a4 100644 --- a/sync_rtl/sample_ntt/sample_ntt_sync_shared.v +++ b/sync_rtl/sample_ntt/sample_ntt_sync_shared.v @@ -224,6 +224,10 @@ module sample_ntt_sync_shared #(parameter K = 4) ( // d2 rejected, no longer need coefficients, or d2 was just accepted out. wire grp_done = (state_r == ST_SQUEEZE) && (sq_phase_r == 2'd2) && (!d2_acc_r || !need_more || (valid_o_r && ready_i)); + // `need_more` observes the registered counter before the final d2 + // handshake increments it. Detect that boundary explicitly so a full + // rate block does not launch an unnecessary final re-permutation. + wire completes_output = valid_o_r && ready_i && (coeff_cnt_r == 9'd255); // ================================================================ // FSM: state_next (combinational) @@ -249,7 +253,7 @@ module sample_ntt_sync_shared #(parameter K = 4) ( // next group in this block, re-permute (block exhausted), or // finish. if (grp_done) begin - if (!need_more) + if (!need_more || completes_output) state_next = ST_DONE; else if (grp_ptr_r < GRP_MAX) state_next = ST_SQUEEZE; // next group, no re-permute