Course: Computer Architectures
Lecture summary
Once instructions can compute values, the program must decide which computation comes next. That decision connects source-level conditions and loops to the instruction-fetch problem.
Functions explain one form of control transfer, but conditions and loops also need to choose what executes next. A branch changes the program counter when its condition is true; otherwise execution continues sequentially. A jump transfers control without that conditional test. Branches
As programs grow, reusable functions need a way to transfer control and then return. A call saves a return address before jumping; a return uses that address. Nested calls make saving the caller’s return address essential because a later call can overwrite the return-address register. Function Calls
Knowing what instructions do lets us ask how to execute more of them in a given time. Pipelining overlaps stages from different instructions to improve throughput. Shared resources, unavailable operands and unresolved branches can interrupt that overlap, so the ideal completion rate is not always achieved. Pipelining
The detailed notes below retain the lecture’s examples, timing diagrams or comparisons, and source references. Continue afterward with Lecture 04 - Pipelining.
Topics
Branches
A branch changes control flow only if its condition is satisfied.
Example:
beq x1, x2, targetIf:
x1 == x2the branch is taken and execution goes to target.
If:
x1 != x2the branch is not taken and execution continues with the next sequential instruction.
Jumps
A jump changes the PC unconditionally.
jal
jal ra, labeljumps and saves a return address.
j
j labeljumps without keeping a useful return address.
jalr
jalr rd, offset(rs1)uses a register-derived destination.
ret
retreturns through ra.
Loop pattern
A loop may use a conditional branch such as:
loop:
...
addi x1, x1, -1
bne x1, x0, loopThe branch is taken while x1 != 0, and not taken when x1 == 0.
Why branches matter to pipelines
A branch can change the PC, so the processor may not know which instruction should be fetched next until the branch condition is resolved.
This leads directly to Pipelining > 11. Control hazards.
Questions to review
- What does “taken” actually mean?
- What is the difference between branch and jump?
- Why does
jalsave a return address? - Why do branches create a pipeline problem?