-
Notifications
You must be signed in to change notification settings - Fork 301
Description
InstructionCounter could be updated to also have counts for B and J. This would require copying some extra UI elements, adding some state to track counts and changing this if. This would only require understanding the code in InstructionCounter.
rars/rars/tools/InstructionCounter.java
Lines 225 to 237 in 9ff2b88
| // TODO: update this to have labels for the extra formats | |
| try { | |
| ProgramStatement stmt = Memory.getInstance().getStatement(a); | |
| BasicInstruction instr = (BasicInstruction) stmt.getInstruction(); | |
| BasicInstructionFormat format = instr.getInstructionFormat(); | |
| if (format == BasicInstructionFormat.R_FORMAT) | |
| counterR++; | |
| else if (format == BasicInstructionFormat.I_FORMAT) | |
| counterI++; | |
| else if (format == BasicInstructionFormat.S_FORMAT || format == BasicInstructionFormat.B_FORMAT) | |
| counterS++; | |
| else if (format == BasicInstructionFormat.U_FORMAT || format == BasicInstructionFormat.J_FORMAT) | |
| counterU++; |
InstructionStatistics is was never updated from MIPS. Updating this requires more work that InstructionCounter. You will need to update getInstructionCategory(...); that will probably involve a fair amount of instanceof checks. This requires understanding code in rars.riscv.instructions.
rars/rars/tools/InstructionStatistics.java
Lines 238 to 274 in 4b2d4b6
| protected int getInstructionCategory(ProgramStatement stmt) { | |
| int opCode = stmt.getBinaryStatement() >>> (32 - 6); | |
| int funct = stmt.getBinaryStatement() & 0x1F; | |
| if (opCode == 0x00) { | |
| if (funct == 0x00) | |
| return InstructionStatistics.CATEGORY_ALU; // sll | |
| if (0x02 <= funct && funct <= 0x07) | |
| return InstructionStatistics.CATEGORY_ALU; // srl, sra, sllv, srlv, srav | |
| if (funct == 0x08 || funct == 0x09) | |
| return InstructionStatistics.CATEGORY_JUMP; // jr, jalr | |
| if (0x10 <= funct && funct <= 0x2F) | |
| return InstructionStatistics.CATEGORY_ALU; // mfhi, mthi, mflo, mtlo, mult, multu, div, divu, add, addu, sub, subu, and, or, xor, nor, slt, sltu | |
| return InstructionStatistics.CATEGORY_OTHER; | |
| } | |
| if (opCode == 0x01) { | |
| if (0x00 <= funct && funct <= 0x07) | |
| return InstructionStatistics.CATEGORY_BRANCH; // bltz, bgez, bltzl, bgezl | |
| if (0x10 <= funct && funct <= 0x13) | |
| return InstructionStatistics.CATEGORY_BRANCH; // bltzal, bgezal, bltzall, bgczall | |
| return InstructionStatistics.CATEGORY_OTHER; | |
| } | |
| if (opCode == 0x02 || opCode == 0x03) | |
| return InstructionStatistics.CATEGORY_JUMP; // j, jal | |
| if (0x04 <= opCode && opCode <= 0x07) | |
| return InstructionStatistics.CATEGORY_BRANCH; // beq, bne, blez, bgtz | |
| if (0x08 <= opCode && opCode <= 0x0F) | |
| return InstructionStatistics.CATEGORY_ALU; // addi, addiu, slti, sltiu, andi, ori, xori, lui | |
| if (0x14 <= opCode && opCode <= 0x17) | |
| return InstructionStatistics.CATEGORY_BRANCH; // beql, bnel, blezl, bgtzl | |
| if (0x20 <= opCode && opCode <= 0x26) | |
| return InstructionStatistics.CATEGORY_MEM; // lb, lh, lwl, lw, lbu, lhu, lwr | |
| if (0x28 <= opCode && opCode <= 0x2E) | |
| return InstructionStatistics.CATEGORY_MEM; // sb, sh, swl, sw, swr | |
| return InstructionStatistics.CATEGORY_OTHER; | |
| } |
If you want to try to solve either of these and have trouble, feel free to ask for advice.