Skip to content

Commit eb35987

Browse files
committed
feat(decode): implement RV32I arithmetic operation instruction
1 parent 6ee1265 commit eb35987

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sim/src/decode.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void decode_operand(Decode *s, int *rd, uint64_t *src1, uint64_t *src2, u
3737
int rs2 = BITS(i, 24, 20);
3838
*rd = BITS(i, 11, 7);
3939
switch(type) {
40-
// TODO: TYPE_R
40+
case TYPE_R: src1R(); src2R(); break;
4141
case TYPE_I: src1R(); immI(); break;
4242
case TYPE_U: immU(); break;
4343
case TYPE_J: immJ(); break;
@@ -98,6 +98,16 @@ void decode_exec(Decode *s){
9898
INSTPAT("??????? ????? ????? 111 ????? 00100 11", andi , I, R(rd) = src1 & imm);
9999
INSTPAT("??????? ????? ????? 000 ????? 00110 11", addiw , I, R(rd) = SEXT((int32_t)src1 + (int32_t)imm, 32));
100100
// ADD, SUB, SLL, SLT, SLTU, XOR, SRL, SRA, OR, AND
101+
INSTPAT("0000000 ????? ????? 000 ????? 01100 11", add , R, R(rd) = src1 + src2);
102+
INSTPAT("0100000 ????? ????? 000 ????? 01100 11", sub , R, R(rd) = src1 - src2);
103+
INSTPAT("0000000 ????? ????? 001 ????? 01100 11", sll , R, R(rd) = src1 << (src2 & 0x3f));
104+
INSTPAT("0000000 ????? ????? 010 ????? 01100 11", slt , R, R(rd) = (int64_t)src1 < (int64_t)src2);
105+
INSTPAT("0000000 ????? ????? 011 ????? 01100 11", sltu , R, R(rd) = src1 < src2);
106+
INSTPAT("0000000 ????? ????? 100 ????? 01100 11", xor , R, R(rd) = src1 ^ src2);
107+
INSTPAT("0000000 ????? ????? 101 ????? 01100 11", srl , R, R(rd) = src1 >> (src2 & 0x3f));
108+
INSTPAT("0100000 ????? ????? 101 ????? 01100 11", sra , R, R(rd) = (int64_t)src1 >> (src2 & 0x3f));
109+
INSTPAT("0000000 ????? ????? 110 ????? 01100 11", or , R, R(rd) = src1 | src2);
110+
INSTPAT("0000000 ????? ????? 111 ????? 01100 11", and , R, R(rd) = src1 & src2);
101111
// ADDW, SUBW, SLLW, SRLW, SRAW
102112
// FENCE, FENCE.I
103113
// ECALL

0 commit comments

Comments
 (0)