0

During a particular clock cycle, consider the CPU shown in the drawing.
Assume that the following initial data is present
(all values are shown in decimal, DM is Data Memory):x3=8, x14=40
During the cycle in question, assume that the following instruction is executed
(the first column is the instruction's address; all values are shown in decimal):
50788 beq x3,x14,80
How to determine the value of L1, L2 and L3


As per what I understand the L1 will have the program counter
But how do I determine the value of program counter
L2 will have 0 or 1 depending upon whether it uses MemtoReg
Now sure about L3. Although above is a guesswork.
Any hints or pointers how to procees on this ?

enter image description here

rohit sharma
  • 171
  • 1
  • 9

2 Answers2

1

L1 has 50788, which is the address of the current branch instruction being executed — it is the address that was fed into the Instruction Memory that results in fetching the beq x3, x14, 80.

You can follow that after L1, there's an ADDer, which will add 4 to the PC value (offering that value to subsequent circuitry), adding 4 to skip past this 4 byte instruction, and thus referring to the next sequential memory address, which holds the next sequential instruction.

L2 is "don't care", which means it doesn't matter whether it is 0 or 1, so different implementations of the same basic design could use either value.  Why doesn't it matter whether this signal is 0 or 1?  Because this instruction is a conditional branch, and as such does not update a register, so RegWrite will be 0, thus the value of WriteData is unimportant and is ignored.

The hardware is a union of all the necessary components to execute any instruction in the instruction set, and as such, some circuitry here or there goes unused during execution of different instructions.  Rather than turning off the unused circuitry (which is an advance technique that takes work to design & implement, not employed here) the unused circuitry for any given instruction is allowed to execute — but (whether turned off or allowed to execute) the control signals further down the line of datapaths are set up to ignore the results of these unused circuits based on the current instruction.

L3 is the branch condition signal, that dynamically informs the PC update circuitry whether to take the branch or not.  Here that condition is effectively generated in the ALU from the expression x3 == x14 and determines the value of this control signal: if they are equal then that control signal needs to be 1 to make it take the branch (as per the definition of the conditional branch instruction) and that control signal needs to be 0 to make it not take the branch and instead continue with sequential execution.

Hopefully, you can see that for conditional branch instructions, the Branch control signal is asserted (1/true) — this signal combined with Zero goes into an AND gate, which results in 1 for take the branch vs. 0 for don't take the branch, by controlling that MUX after the AND gate.  So, the only condition in which the branch can be taken [pc := pc + sxt(imm)*2] is when both Branch and Zero are true.  If Branch is false, it is not a branch instruction, so Zero doesn't matter, and if Zero is false, the branch condition is false, so Branch is overridden [pc := pc + 4].

More explicitly, the PC update circuitry says:

PC := (Branch & Zero) ? PC + sxt(imm)*2 : PC + 4;

Using C ternary operator (could also be written using if-then-else).


Zero is a rather poor choice for the name of this dynamic control signal.  I would have chosen Take or Taken instead.  I believe the name Zero is historical from older RISC architectures.


This circuitry follows the RISC V standard of multiplying the branch target immediate field by 2 (instead of 4 as with MIPS), and this standard makes it so that regular 4 byte instructions are identical (unchanged) in the presence of compressed instructions — thus, on hardware that supports compressed instructions, no mode switching is needed, and, compressed instructions can be interleaved with uncompressed instructions (unlike with MIPS16 or ARM Thumb).  However, this block diagram does not provide the other features necessary to execute compressed instructions (for one, there is no increment by 2 option diagrammed in this PC update circuitry, for another there is no compressed instruction expander, which would go in between the Instruction Memory output and the Decode logic).

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
0

What you asking is very implementation depended. From the diagram I guess it is some MIPS or MIPS like uarch. Some of real RISC implementations have (curr_instr_addr+2instrsize) in the PC according to ISA. This has some historical reasons, because on old machines depth of the pipeline was 3 levels. So L1 has addr of the next or some of the next instructions. I can't say which exactly. If beq instruciton is in ALU, then L2 has MemToReg of the previous instruction to determine if writeback phase is needed. L3 keeping the zero flag to bypass the pipeline directly to the PC if the next instruction is branch.

saidm
  • 101
  • 3
  • It's tagged RISC-V, so yes, similar to MIPS. But RISC-V encodes branch offsets relative to the start of the branch instruction, not the end. (And doesn't have a branch-delay slot.) – Peter Cordes May 06 '21 at 13:44
  • @PeterCordes yup, I wasn't suggesting that there is a delay slot. zero flag is transferred directly to the PC right after ALU produced the result. – saidm May 06 '21 at 13:53
  • I didn't say you were suggesting that, just that actual MIPS does and it's relevant to branch-target encoding and control signals. (And I wasn't 100% sure I was remembering what [MIPS branch displacements](https://stackoverflow.com/questions/6950230/how-to-calculate-jump-target-address-and-branch-target-address) were relative to, so I was also hedging my bets a bit.) – Peter Cordes May 06 '21 at 13:58