new r_type switch

This commit is contained in:
inixyz
2023-10-22 16:37:03 +03:00
parent 4fd0c68f10
commit f2fbde2e97

View File

@@ -210,4 +210,32 @@ void tinyriscv_step(tinyriscv_hart* hart){
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#endif //TINYRISCV_H #endif //TINYRISCV_H
#ifdef TESTING
void step(){
//func7 and func3 are just bitmasked from the whole inst
switch(opcode){
case /*R-type*/ 0x33:
switch(funct7 | funct3){
case /*ADD*/ 0x0: x[rd] = x[rs1] + x[rs2]; break;
case /*SUB*/ 0x40000000: x[rd] = x[rs1] - x[rs2]; break;
case /*SLL*/ 0x1000: x[rd] = x[rs1] << (x[rs2] & 0x1f); break;
case /*SLT*/ 0x2000: x[rd] = (i32)x[rs1] < (i32)x[rs2]; break;
case /*SLTU*/ 0x3000: x[rd] = x[rs1] < x[rs2]; break;
case /*XOR*/ 0x4000: x[rd] = x[rs1] ^ x[rs2]; break;
case /*SRL*/ 0x5000: x[rd] = x[rs1] >> (x[rs2] & 0x1f); break;
case /*SRA*/ 0x40005000: x[rd] = (i32)x[rs1] >> (x[rs2] & 0x1f); break;
case /*OR*/ 0x6000: x[rd] = x[rs1] | x[rs2]; break;
case /*AND*/ 0x7000: x[rd] = x[rs1] & x[rs2]; break;
}
}
}
#endif