Skip to content

Add decoder for C extension#241

Open
tandr3w wants to merge 4 commits into
mainfrom
compressed-decoder
Open

Add decoder for C extension#241
tandr3w wants to merge 4 commits into
mainfrom
compressed-decoder

Conversation

@tandr3w

@tandr3w tandr3w commented May 28, 2026

Copy link
Copy Markdown
Contributor

Issue #239

Implemented decompression for all rv32 instructions other than F and D extension ones

Also added checking for illegal/reserved and unimplemented instructions though I don't think we have a way to handle that properly yet?

Note C.JAL and C.JALR need extra handling to work properly (I think)

@tandr3w tandr3w force-pushed the compressed-decoder branch from 5f40d07 to 5160b8a Compare May 28, 2026 06:57
@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

🔧 DE1-SoC Synthesis Report Summary Diff

  • RV32I

    1. Fitter Summary

      @@ -1,4 +1,4 @@
      -Fitter Status : Successful - Tue Jun  9 23:39:28 2026
      +Fitter Status : Successful - Sun Jun 14 03:13:41 2026
       Quartus Prime Version : 25.1std.0 Build 1129 10/21/2025 SC Lite Edition
       Revision Name : utoss-risc-v
       Top-level Entity Name : top
    2. Fitter by entity
      No changes detected

    3. Timing
      No changes detected

  • RV32IB

    1. Fitter Summary

      @@ -1,4 +1,4 @@
      -Fitter Status : Successful - Tue Jun  9 23:39:07 2026
      +Fitter Status : Successful - Sun Jun 14 03:13:41 2026
       Quartus Prime Version : 25.1std.0 Build 1129 10/21/2025 SC Lite Edition
       Revision Name : utoss-risc-v
       Top-level Entity Name : top
    2. Fitter by entity
      No changes detected

    3. Timing
      No changes detected


Comparing synthesis results from main branch vs. this PR

@tandr3w tandr3w requested a review from TheDeepestSpace May 28, 2026 07:05
@TheDeepestSpace TheDeepestSpace linked an issue Jun 7, 2026 that may be closed by this pull request
Comment thread src/ext/c/Compressed_Decode.sv Outdated
2'b00: begin // Quadrant 0
case (funct3)
3'b000: begin
instr_out = {ciw_imm, 5'd2, 3'b000, rd_prime, IType_logic}; // C.ADDI4SPN

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think since there are a lot compositions here, im wondering if we can cook up a function here like build_<opcode>_instr that can be passed all the needed parameters for a particular opcode, and this would make things a bit more readable here + force a bit more wire width checking as part of compilation, i.e. in my head it looks like something along the lines of

Suggested change
instr_out = {ciw_imm, 5'd2, 3'b000, rd_prime, IType_logic}; // C.ADDI4SPN
instr_out = build_immlogic_instr( .imm (ciw_imm), .rs1 (5'd2), .funct3 (3'b000), .rd (rd_prime) ); // C.ADDI4SPN

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but we would probably need to add like 8 functions to get all the composition types

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine, we might be able to reuse them in tests maybe, but even if not -- there are essentially just for readability, and don't add any overhead at runtime.

@tandr3w tandr3w force-pushed the compressed-decoder branch 7 times, most recently from 476c407 to 0b66ced Compare June 14, 2026 02:57
Comment thread src/ext/c/Compressed_Decode.sv Outdated
is_illegal = 1'b0;

case (quadrant) // Opcode
2'b11: instr_out = {16'b0, instr_c}; // Not a compressed instruction, just pass through (should not actually happen i think?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can just say its illegal in this case, since the spec does not even define 2'b11 as its own quadrant

@tandr3w tandr3w force-pushed the compressed-decoder branch from 0b66ced to f68d968 Compare June 14, 2026 03:00
case (instr_c[11:10])
2'b00: begin
instr_out = build_i_shift_instr(.funct7(7'h00), .shamt(shamt), .rs1(rs1_prime), .funct3(3'b101), .rd(rs1_prime), .opcode(IType_logic)); // C.SRLI
if (instr_c[12]) is_illegal = 1'b1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you point to the spec for this condition? i did not find it in C extension spec, might be elsewhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because instr_c[12] represents shamt[5]
"For RV32C, shamt[5] must be zero; the code points with shamt[5]=1 are designated for custom extensions."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compresed instruction decoder

2 participants