-
Notifications
You must be signed in to change notification settings - Fork 32
[TODO] Add RV32C support #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
howard0su
wants to merge
1
commit into
PulseRain:master
Choose a base branch
from
howard0su:checkin3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 234 additions & 0 deletions
234
submodules/PulseRain_MCU/PulseRain_processor_core/source/RV2T_compressed_decode.v
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| `include "RV2T_common.vh" | ||
|
|
||
| `default_nettype none | ||
|
|
||
| module RV2T_compressed_decode | ||
| ( | ||
| input wire [31:0] instr_i, | ||
| output reg [31:2] instr_o, | ||
| output wire is_compressed_o, | ||
| output reg illegal_instr_o | ||
| ); | ||
|
|
||
| always @(*) begin | ||
| illegal_instr_o = 1'b0; | ||
| instr_o = 30'b0; | ||
|
|
||
| case (instr_i[1:0]) | ||
| // C0 | ||
| 2'b00: begin | ||
| case (instr_i[15:13]) | ||
| 3'b000: begin | ||
| // c.addi4spn -> addi rd', x2, imm | ||
| instr_o = {2'b0, instr_i[10:7], instr_i[12:11], instr_i[5], instr_i[6], 2'b00, 5'h02, 3'b000, 2'b01, instr_i[4:2], `CMD_OP_IMM}; | ||
| if (instr_i[12:5] == 8'b0) illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b001: begin | ||
| // c.fld -> fld rd', imm(rs1') | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b010: begin | ||
| // c.lw -> lw rd', imm(rs1') | ||
| instr_o = {5'b0, instr_i[5], instr_i[12:10], instr_i[6], 2'b00, 2'b01, instr_i[9:7], 3'b010, 2'b01, instr_i[4:2], `CMD_LOAD}; | ||
| end | ||
|
|
||
| 3'b011: begin | ||
| // c.flw -> flw rd', imm(rs1') | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b101: begin | ||
| // c.fsd -> fsd rs2', imm(rs1') | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b110: begin | ||
| // c.sw -> sw rs2', imm(rs1') | ||
| instr_o = {5'b0, instr_i[5], instr_i[12], 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b010, instr_i[11:10], instr_i[6], 2'b00, `CMD_STORE}; | ||
| end | ||
|
|
||
| 3'b111: begin | ||
| // c.fsw -> fsw rs2', imm(rs1') | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
| default: begin | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
| endcase | ||
| end | ||
|
|
||
|
|
||
| // C1 | ||
| 2'b01: begin | ||
| case (instr_i[15:13]) | ||
| 3'b000: begin | ||
| // c.addi -> addi rd, rd, nzimm | ||
| // c.nop | ||
| instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], instr_i[11:7], 3'b0, instr_i[11:7], `CMD_OP_IMM}; | ||
| end | ||
|
|
||
| 3'b001, 3'b101: begin | ||
| // 001: c.jal -> jal x1, imm | ||
| // 101: c.j -> jal x0, imm | ||
| instr_o = {instr_i[12], instr_i[8], instr_i[10:9], instr_i[6], instr_i[7], instr_i[2], instr_i[11], instr_i[5:3], {9 {instr_i[12]}}, 4'b0, ~instr_i[15], `CMD_JAL}; | ||
| end | ||
|
|
||
| 3'b010: begin | ||
| // c.li -> addi rd, x0, nzimm | ||
| instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], 5'b0, 3'b0, instr_i[11:7], `CMD_OP_IMM}; | ||
| if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b011: begin | ||
| // c.lui -> lui rd, imm | ||
| instr_o = {{15 {instr_i[12]}}, instr_i[6:2], instr_i[11:7], `CMD_LUI}; | ||
|
|
||
| if (instr_i[11:7] == 5'h02) begin | ||
| // c.addi16sp -> addi x2, x2, nzimm | ||
| instr_o = {{3 {instr_i[12]}}, instr_i[4:3], instr_i[5], instr_i[2], instr_i[6], 4'b0, 5'h02, 3'b000, 5'h02, `CMD_OP_IMM}; | ||
| end else if (instr_i[11:7] == 5'b0) begin | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| if ({instr_i[12], instr_i[6:2]} == 6'b0) illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b100: begin | ||
| case (instr_i[11:10]) | ||
| 2'b00, | ||
| 2'b01: begin | ||
| // 00: c.srli -> srli rd, rd, shamt | ||
| // 01: c.srai -> srai rd, rd, shamt | ||
| instr_o = {1'b0, instr_i[10], 5'b0, instr_i[6:2], 2'b01, instr_i[9:7], 3'b101, 2'b01, instr_i[9:7], `CMD_OP_IMM}; | ||
| if (instr_i[12] == 1'b1) illegal_instr_o = 1'b1; | ||
| if (instr_i[6:2] == 5'b0) illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 2'b10: begin | ||
| // c.andi -> andi rd, rd, imm | ||
| instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], 2'b01, instr_i[9:7], 3'b111, 2'b01, instr_i[9:7], `CMD_OP_IMM}; | ||
| end | ||
|
|
||
| 2'b11: begin | ||
| case ({instr_i[12], instr_i[6:5]}) | ||
| 3'b000: begin | ||
| // c.sub -> sub rd', rd', rs2' | ||
| instr_o = {2'b01, 5'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b000, 2'b01, instr_i[9:7], `CMD_OP}; | ||
| end | ||
|
|
||
| 3'b001: begin | ||
| // c.xor -> xor rd', rd', rs2' | ||
| instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b100, 2'b01, instr_i[9:7], `CMD_OP}; | ||
| end | ||
|
|
||
| 3'b010: begin | ||
| // c.or -> or rd', rd', rs2' | ||
| instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b110, 2'b01, instr_i[9:7], `CMD_OP}; | ||
| end | ||
|
|
||
| 3'b011: begin | ||
| // c.and -> and rd', rd', rs2' | ||
| instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b111, 2'b01, instr_i[9:7], `CMD_OP}; | ||
| end | ||
|
|
||
| 3'b100, | ||
| 3'b101, | ||
| 3'b110, | ||
| 3'b111: begin | ||
| // 100: c.subw | ||
| // 101: c.addw | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
| endcase | ||
| end | ||
| endcase | ||
| end | ||
|
|
||
| 3'b110, 3'b111: begin | ||
| // 0: c.beqz -> beq rs1', x0, imm | ||
| // 1: c.bnez -> bne rs1', x0, imm | ||
| instr_o = {{4 {instr_i[12]}}, instr_i[6:5], instr_i[2], 5'b0, 2'b01, instr_i[9:7], 2'b00, instr_i[13], instr_i[11:10], instr_i[4:3], instr_i[12], `CMD_BRANCH}; | ||
| end | ||
| endcase | ||
| end | ||
|
|
||
| // C2 | ||
| 2'b10: begin | ||
| case (instr_i[15:13]) | ||
| 3'b000: begin | ||
| // c.slli -> slli rd, rd, shamt | ||
| instr_o = {7'b0, instr_i[6:2], instr_i[11:7], 3'b001, instr_i[11:7], `CMD_OP_IMM}; | ||
| if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1; | ||
| if (instr_i[12] == 1'b1 || instr_i[6:2] == 5'b0) illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b001: begin | ||
| // c.fldsp -> fld rd, imm(x2) | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b010: begin | ||
| // c.lwsp -> lw rd, imm(x2) | ||
| instr_o = {4'b0, instr_i[3:2], instr_i[12], instr_i[6:4], 2'b00, 5'h02, 3'b010, instr_i[11:7], `CMD_LOAD}; | ||
| if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b011: begin | ||
| // c.flwsp -> flw rd, imm(x2) | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b100: begin | ||
| if (instr_i[12] == 1'b0) begin | ||
| // c.mv -> add rd/rs1, x0, rs2 | ||
| instr_o = {7'b0, instr_i[6:2], 5'b0, 3'b0, instr_i[11:7], `CMD_OP}; | ||
|
|
||
| if (instr_i[6:2] == 5'b0) begin | ||
| // c.jr -> jalr x0, rd/rs1, 0 | ||
| instr_o = {12'b0, instr_i[11:7], 3'b0, 5'b0, `CMD_JALR}; | ||
| end | ||
| end else begin | ||
| // c.add -> add rd, rd, rs2 | ||
| instr_o = {7'b0, instr_i[6:2], instr_i[11:7], 3'b0, instr_i[11:7], `CMD_OP}; | ||
|
|
||
| if (instr_i[11:7] == 5'b0) begin | ||
| // c.ebreak -> ebreak | ||
| instr_o = {30'h04_00_1C}; | ||
| if (instr_i[6:2] != 5'b0) | ||
| illegal_instr_o = 1'b1; | ||
| end else if (instr_i[6:2] == 5'b0) begin | ||
| // c.jalr -> jalr x1, rs1, 0 | ||
| instr_o = {12'b0, instr_i[11:7], 3'b000, 5'b00001, `CMD_JALR}; | ||
| end | ||
| end | ||
| end | ||
|
|
||
| 3'b101: begin | ||
| // c.fsdsp -> fsd rs2, imm(x2) | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
|
|
||
| 3'b110: begin | ||
| // c.swsp -> sw rs2, imm(x2) | ||
| instr_o = {4'b0, instr_i[8:7], instr_i[12], instr_i[6:2], 5'h02, 3'b010, instr_i[11:9], 2'b00, `CMD_STORE}; | ||
| end | ||
|
|
||
| 3'b111: begin | ||
| // c.fswsp -> fsw rs2, imm(x2) | ||
| illegal_instr_o = 1'b1; | ||
| end | ||
| endcase | ||
| end | ||
|
|
||
| default: begin | ||
| // 32 bit (or more) instruction | ||
| instr_o = instr_i[31:2]; | ||
| end | ||
| endcase | ||
| end | ||
|
|
||
| assign is_compressed_o = (instr_i[1:0] != 2'b11); | ||
|
|
||
| endmodule | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion is to make those constants as macro definitions, which can include both bit [15:13] and bit [1 :0], and put them in common.vh, like the following:
define C_ADDI4SPN (5'b000_00)define C_LW (5'b010_00)define C_SW (5'b110_00)define C_NOP_ADDI (5'b000_01)define C_JAL (5'b001_01)define C_J (5'b101_01)define C_LI (5'b010_01)define C_BEQZ (5'b110_01)define C_BNEZ (5'b111_01)define C_ADDI16SP_LUI (5'b011_01)define C_SLLI (5'b000_10)define C_SWSP (5'b110_10)define C_LWSP (5'b010_10)define C_JR_JALR_MV_ADD (5'b100_10)`define C_MISC_ALU (5'b100_01)