Skip to content

Commit 11d7d7a

Browse files
committed
[rtl] Compute gets_expanded_o only if the instruction is valid
1 parent e7874a1 commit 11d7d7a

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

rtl/ibex_compressed_decoder.sv

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ module ibex_compressed_decoder #(
185185
logic [4:0] cm_sp_offset_d, cm_sp_offset_q;
186186
cm_state_e cm_state_d, cm_state_q;
187187

188+
// Gate the `gets_expanded_o` to ensure that a invalid instruction looking like expandable cm.*
189+
// instructions will not be stalled/blocked in later control logic because it is waiting for
190+
// `INSTR_EXPANDED_LAST`.
191+
ibex_pkg::instr_exp_e gets_expanded;
192+
if (RV32ZC == RV32ZcaZcbZcmp || RV32ZC == RV32ZcaZcmp) begin : gen_gets_expanded
193+
assign gets_expanded_o = valid_i ? gets_expanded : INSTR_NOT_EXPANDED;
194+
end else begin : gen_gets_expanded
195+
// `gets_expanded` will be tied to INSTR_NOT_EXPANDED in this case
196+
assign gets_expanded_o = gets_expanded;
197+
end
198+
188199
////////////////////////
189200
// Compressed decoder //
190201
////////////////////////
@@ -193,7 +204,7 @@ module ibex_compressed_decoder #(
193204
// By default, forward incoming instruction, mark it as legal, and don't expand.
194205
instr_o = instr_i;
195206
illegal_instr_o = 1'b0;
196-
gets_expanded_o = INSTR_NOT_EXPANDED;
207+
gets_expanded = INSTR_NOT_EXPANDED;
197208

198209
// Maintain state of CM FSM.
199210
cm_rlist_d = cm_rlist_q;
@@ -534,7 +545,7 @@ module ibex_compressed_decoder #(
534545
// cm.push
535546
5'b11000: begin
536547
// This compressed instruction gets expanded into multiple instructions.
537-
gets_expanded_o = INSTR_EXPANDED;
548+
gets_expanded = INSTR_EXPANDED;
538549
unique case (cm_state_q)
539550
CmIdle: begin
540551
// No cm.push instruction is active yet; start a new one.
@@ -586,7 +597,7 @@ module ibex_compressed_decoder #(
586597
instr_o = cm_sp_addi(.rlist(instr_i[7:4]), .spimm(instr_i[3:2]), .decr(1'b1));
587598
if (id_in_ready_i) begin
588599
// This is the final operation, so stop expanding and return to idle.
589-
gets_expanded_o = INSTR_EXPANDED_LAST;
600+
gets_expanded = INSTR_EXPANDED_LAST;
590601
cm_state_d = CmIdle;
591602
end
592603
end
@@ -599,7 +610,7 @@ module ibex_compressed_decoder #(
599610
5'b11100,
600611
5'b11110: begin
601612
// This compressed instruction gets expanded into multiple instructions.
602-
gets_expanded_o = INSTR_EXPANDED;
613+
gets_expanded = INSTR_EXPANDED;
603614
unique case (cm_state_q)
604615
CmIdle: begin
605616
// No cm.pop instruction is active yet; start a new one.
@@ -657,7 +668,7 @@ module ibex_compressed_decoder #(
657668
5'b11110: cm_state_d = CmPopRetRa; // cm.popret
658669
default: begin // cm.pop
659670
// This is the final operation, so stop expanding and return to idle.
660-
gets_expanded_o = INSTR_EXPANDED_LAST;
671+
gets_expanded = INSTR_EXPANDED_LAST;
661672
cm_state_d = CmIdle;
662673
end
663674
endcase
@@ -673,7 +684,7 @@ module ibex_compressed_decoder #(
673684
instr_o = cm_ret_ra();
674685
if (id_in_ready_i) begin
675686
// This is the final operation, so stop expanding and return to idle.
676-
gets_expanded_o = INSTR_EXPANDED_LAST;
687+
gets_expanded = INSTR_EXPANDED_LAST;
677688
cm_state_d = CmIdle;
678689
end
679690
end
@@ -687,7 +698,7 @@ module ibex_compressed_decoder #(
687698
// cm.mvsa01
688699
2'b01: begin
689700
// This compressed instruction gets expanded into multiple instructions.
690-
gets_expanded_o = INSTR_EXPANDED;
701+
gets_expanded = INSTR_EXPANDED;
691702
unique case (cm_state_q)
692703
CmIdle: begin
693704
// No cm.mvsa01 instruction is active yet; start a new one.
@@ -702,7 +713,7 @@ module ibex_compressed_decoder #(
702713
instr_o = cm_mvsa01(.a01(1'b1), .rs(instr_i[4:2]));
703714
if (id_in_ready_i) begin
704715
// This is the final operation, so stop expanding and return to idle.
705-
gets_expanded_o = INSTR_EXPANDED_LAST;
716+
gets_expanded = INSTR_EXPANDED_LAST;
706717
cm_state_d = CmIdle;
707718
end
708719
end
@@ -713,7 +724,7 @@ module ibex_compressed_decoder #(
713724
// cm.mva01s
714725
2'b11: begin
715726
// This compressed instruction gets expanded into multiple instructions.
716-
gets_expanded_o = INSTR_EXPANDED;
727+
gets_expanded = INSTR_EXPANDED;
717728
unique case (cm_state_q)
718729
CmIdle: begin
719730
// No cm.mva01s instruction is active yet; start a new one.
@@ -728,7 +739,7 @@ module ibex_compressed_decoder #(
728739
instr_o = cm_mva01s(.rs(instr_i[4:2]), .a01(1'b1));
729740
if (id_in_ready_i) begin
730741
// This is the final operation, so stop expanding and return to idle.
731-
gets_expanded_o = INSTR_EXPANDED_LAST;
742+
gets_expanded = INSTR_EXPANDED_LAST;
732743
cm_state_d = CmIdle;
733744
end
734745
end

0 commit comments

Comments
 (0)