assemblyriscvno-op

Risc-V Assembly - amount of bubbles needed to make the code operational - [Hypothetical]


I want to know why when executing this assembly code on a pipelined RiscV - that does not stall automatically - with forwarding (except for internal register file WB->DEC forwarding) we need to place two NOP commands immediatly after the third command, wouldn't one NOP suffice?

addi t0, x0, 0
addi t1, x0, 5
addi s1, x0, 0x200 //why are two NOPS required after this command?
beq t1, t0, finish

Here's my line of thinking - after one nop the first command finished compiling, and we can forward t1 from the second command's WB into the EXE of the beq. Where am I wrong?


Solution

  • So after working on this for a few hours, here's the solution: two key facts are needed:

    IF DEC EXE MEM WB 
    1
    2   1
    3   2   1
    4   3   2   1 
        4   3   2  1
    
    IF DEC EXE MEM WB
        4  NOP  3  2 
    
    IF DEC EXE MEM WB
        4  NOP NOP 3 - notice 2 has finished, we can now continue with the correct t1.
            4  NOP NOP
                4  NOP
                    4
    DONE.
    

    yup