Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
[MUSIC PLAYING] PROFESSOR: Hi.
Welcome back to our pipelining module. Previously, we have seen how pipelining is applied to laundry processing. And we have also outlined how should we pipeline a RISC-V data path.
My conclusion there is that if we would like to build a five-stage pipeline, we should divide the execution into five stages — instruction fetch, instruction decode, execute, memory access, and write back.
So let's take a look at our single-cycle data path that we are well familiar with by now and see how should we pipeline it. So here is our single-cycle data path.
It has familiar blocks that we have seen before, like the program counter, instruction memory, this fix plus 4 adder, immediate generation, register file, branch, comparator, ALU, the data memory, and multiplexers that help configure this data path to execute
a particular instruction. And of course, there is the control logic that configures the data path.
We have also outlined that there are different stages of execution inside this data path. And those are the stages that we are going to break down into different pipeline stages.
To recap, these stages are the instruction fetch, instruction decode with register read, ALU execute stage, memory access, and write back.
The instruction fetch starts on rising edge of a clock by incrementing the program counter.
And it finishes by having the data read out of the instruction memory.
Remember, our memory read and register access are treated as combinational logic operations, meaning that they do not rely on clocks.
And as soon as the data is stable at the output, we assume that that operation has been concluded, has been finished.
So as soon as the instruction here — instruction bits are stable at the output of the instruction memory, we move on to a next stage.
The next stage is the instruction decode, when — where we'll this — decode this memory and read the registers. Again, the registers are read like a combinational logic.
So as soon as those values are stable at the output of the register file, the instruction decode phase is done.
We move on to the execution phase, or the execute phase, where we perform the ALU operation. And that one is done when the output at the ALU is valid.
We move on to the memory access phase if we are accessing memory in loads or stores.
And when we are done with that, we move on to the write back, where we write back into destination register in the register file on the rising edge of a clock.
So how do we pipeline? Well, we simply insert registers at appropriate places. On the boundary between each of these execution phases, we need to put registers.
So we are going to have registers here that are conveniently labeled as IF/ID, ID/EX, EX/MA, and MA/WB to separate various execution phases.
Let's take a look at a few of the highlights here, although this looks fairly familiar. First, at the end of the instruction fetch phase, we have two registers.
We have a register for the program counter and for the instruction. The latter one is particularly interesting. Keep in mind that we have five instructions in flight.
While one of them is being fetched, we have copies of the previously fetched-for instructions down the stream. So we need to save those instructions.
That's why we have them in this register, then in the registers below that, and so on.
Each one of these pipeline registers will have to hold the bits that correspond to the instruction that is being executed in that particular stage. Otherwise, we will know what that stage is doing.
So that stage has to keep the instruction, but also control bits that correspond to that. The other thing that should be noticed here is that we are sending down the program counter.
And we are pipelining the program counter value. But we are not sending down the PC plus 4 value.
Instead, we are recreating PC plus 4 value in the memory access stage. That's a design decision.
It is cheaper to have fixed function adder plus 4 adder instead of using 1, 2, 3 registers to store three 32-bit PC plus 4 values.
The other thing that we notice here — we are using the PC value more upstream here in the first three stages of.
Execution and then we need only PC plus 4 down in the memory access stage to send it down to be written back, if needed.
And that is, essentially, it. It looks fairly straightforward, although there are a few catches that we are going to see a bit later.
The other thing that I just wanted to highlight here is this fact that we actually have five instructions that are in flight here. And a fifth one is not shown.
That is in the write back stage.
So the oldest instruction, the one that made it the furthest down the pipe, the first one that went through the pipe, made it the furthest down the pipe, is the one in the memory access stage, which is "or."
Then the one that is a little younger than that one is "slt." And then we have "store word."
And the one that is being presently fetched is "load word."
Keep in mind that we do have to pack everything that is associated with that instruction into that pipeline stage.
So the instruction that is in the memory access will have its copy in the register here, and also the values that correspond to it in the associated registers that precede that stage.
And the same thing here happens.
Before the execute stage, we have copies of everything that is needed for that particular instruction because we are going to get new values for the next instruction, which is store word.
The other thing to keep in mind besides the instruction bits — we also need to save the decoded control bits.
Remember, we have control logic that tells us what each stage should be doing, how each stage should be configured.
So once when we decode the instruction, we — in addition to our instruction, we need to send down the stream all the control bits that correspond to that instruction.
So each of these registers that are storing the program counter are going to be a bit wider to save the necessary control signals.
So for example, our memory access stage register — or the register is sitting between the memory access and the write back — has to save the control signals that correspond to that final write back over there.
And then between write back and memory access — between the execute and memory access, we need to save the bits that correspond to the memory access and the write back stages, and so on.
That is, basically, it.
There are some things, however, that are particular to the situation or have multiple instructions in flight and — which are called hazards.
We're going to take a look at the hazards next. See you then.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.