TheThirdOne/rars

Tool Instruction Counter: Wrong total number of instructions and Wrong SSLI instruction type

Closed this issue · 2 comments

Description

  1. The total number of instructions is always 1 more than the actual instructions.
  2. The type of SLLI is R-type, but it should be I-type.
    image

Probability

  • Always

Environment
Using tools Instruction Counter, version 1.0 (Felipe Lessa) on RARS version 1.6

Wrong SSLI instruction type

  • Source code: https://github.com/TheThirdOne/rars/blob/master/src/rars/riscv/instructions/SLLI.java
  • Extracted Code:
      public SLLI() {
        super("slli t1,t2,10", "Shift left logical : Set t1 to result of shifting t2 left by number of bits specified by immediate",
                BasicInstructionFormat.R_FORMAT, "0000000 ttttt sssss 001 fffff 0010011",false);
        }
  • Detail: SLLI should be I_FORMAT.
  • Propose: replace BasicInstructionFormat.R_FORMAT by BasicInstructionFormat.I_FORMAT

Wrong total number of instructions

protected void processRISCVUpdate(Observable resource, AccessNotice notice) {
        //...............................................................
        lastAddress = a;
        counter++;
        try {
            ProgramStatement stmt = Memory.getInstance().getStatement(a);
            
            // If the program is finished, getStatement() will return null,
            // a null statement will cause the simulator to stall.
            if(stmt != null) {
	            BasicInstruction instr = (BasicInstruction) stmt.getInstruction();
	            BasicInstructionFormat format = instr.getInstructionFormat();
	            if (format == BasicInstructionFormat.R_FORMAT)
	                counterR++;
        //...............................................................
  • Detail: **counter++; ** is always executed before checking stmt !=null
  • Propose: move instruction counter++; to be inside the block if(stmt != null) { }

just propose, not fix