Pipelines Flashcards

1
Q

What is the purpose of status flags?

A

Programs may need to execute some parts conditionally.

Done by conditionally branching to another part of code.

It decides when to branch via the use of status flags, stored in the status register.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Four most common status flags (CPSR)

A

N: Last operation yielded negative result (bit 7 of the ALU result)
Z: Last operation yielded 0 result (NOR all bits of the ALU together)
V: Overflow bit (carryout value)
C: Carry flag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to generate status flags

A

Easy to generate the signal.

Then we just need a bit of logic to update the status register in the right state depending on which instruction has been executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the bit format of branch instructions

A

All branch instructions are in the form xxy10000

The xx bits encode which status flag the branch is based on (use multiplexors to select the correct flag)

The status flag is then compared with the value in y

If they are equal the branch is taken

Otherwise it isn’t.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the fetch stage of the CPU cycle

A

The opcode of the instruction is fetched from memory.

CPU puts the address in the program counter onto the address bus

Memory system places the required data value onto the data bus.

CPU reads the value from the data bus into a temporary “register” called the instruction register.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the decode stage of the CPU cycle

A

Opcode is decoded to decide what parts of the CPU are needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain the execute stage of the CPU cycle

A

CPU processes / executes the instruction.

Might need to access memory again.

Then repeat for the next instruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many clock cycles will it take to complete one fetch-decode-execute cycle

A

At minimum 3 clock cycles (1 cycle for each stage).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain instruction pipelining

A

Instruction pipelining is a technique used in CPUs to improve performance by overlapping the execution of multiple instructions, dividing the process into stages (e.g., fetch, decode, execute). Each stage works concurrently on different instructions, allowing the CPU to complete one instruction per cycle after the pipeline is filled, increasing throughput.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Pipeline Hazards

Explain structural hazards

A

Structural hazards occur when the design of a CPU doesn’t allow two operations to happen in parallel.

For example, in instruction pipelining, multiple stages may require you to fetch data, but it might not be possible to fetch multiple values in the same time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the solution to structual hazards?

A

Delay one of the stages until the next clock cycle (or however many clock cycles until there would be no clash).

This is called a bubble.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define pipeline bubbles

A

A pipeline bubble is a delay in an instruction pipeline caused by a stall, where one or more stages remain idle.

Pipeline hazards introduce bubbles into the pipeline.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pipeline Hazards

Explain control hazards

A

Branches can cause control hazards.

Happens when the proper instruction can’t be executed because a different instruction was fetched and decoded.

With a conditional branch, cannot know which instruction to execute next until branch condition is evaluated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s the solution to control hazards?

A

Discard the currently fetch and decoded instruction and start again for the correct one.

Causes a stall one cycle less than the length of the pipeline.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Branch Prediction

A

Instead of always fetching the next instruction in memory, CPU uses the past to predict how a branch will be taken.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Define speculative execution

A

Speculative execution is a performance optimization technique where a processor predicts the outcome of instructions or branches and executes them ahead of time. If the prediction is correct, the results are used, reducing idle time. If incorrect, the speculative results are discarded.

17
Q

Advantage of longer pipeline length

A

Smaller steps do less and take less time to run, thus CPU’s can run at a higher clock speed.

18
Q

Disadvantage of longer pipeline length

A

More stages means the cost of a stall becomes much greater, as you have to re-process a lot more stages.