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 Design Number RISC-V CPU. We said that the CPU can be viewed as a complex state machine that consists of a datapath and the control that are shared among all instructions.
But we're not going to go and go ahead and design the entire data path that is shared across all the instructions. Let's try to start with something smaller.
So let's design a datapath that will support one instruction type. And in order to start fairly simple, let's just pick one instruction. Let that be the R-type add instruction.
Remember our R-type instructions? Those are all, they all look similar, and those were register to register arithmetic and logic instructions.
They would operate on the contents of two source registers, and store the result of that operation in the destination register RT. They look similar.
They had the same upcode, 011-0011. And same fields for the destination register, first source register, and the second source register.
And they differ by the encoding of the funct3 field, and the slight difference in the 30th bit of instruction. Some of those were 0. Some of those were 1s.
So add are the RS1 RS2 instruction. Will take the values in the registers RS1 and RS2, and store the result in the register RD.
Sub RD RS1 RS2 instruction would subtract the value of registrar RS2 from the value of the register RS1, and store the result in the destination register RD.
To take a look a bit in more detail, here is there is no new information at the top of the slide. It just repeats the encoding for convenience.
But it helps us here illustrate what is the change in state of this state machine that executes instructions. So instruction makes two changes to the machine state.
It updates the contents of a register RD with the sum of the values of RS1 and RS2 without changing RS1 and RS2, and it updates the program counter to a new value that is 4 bytes larger.
So we need to build a data path that is going to do these two state updates. So what we will see, first we have a program counter that has its own state.
At the output of that program counter, there is a current value of PC that points to the address in the instruction memory.
By pointing to a particular instruction, the instruction memory will read its contents, and that will be an instruction that we would like to execute. Remember, our model for the instruction memory is fairly simple.
We just need to point, and the instruction is going to show up. At the output, we don't need the clock. Simultaneously, we need this piece of hardware.
We need this fixed function addr that will be always adding a value of 4 to the current value of the PC, and putting — will be put PC plus 4 value at the input of the program counter.
Now, remember, the contents of the program counter will not change until the next clock tick.
On the next rising edge of a clock, program counter will take a new value of PC plus 4. But let's see what else do we need to do with this instruction.
So decoding instructions is fairly straightforward, because we are going to always find things in the same place.
So our instruction here needs to point to the register file. And conveniently, we always are pointing to the same place in the register file.
We know that if we take a part of that instruction that contains bits, 19 to 15 will point to the address of RS1.
So what we need to do, take those five bits from the instruction, and connect them to the address port, the first address part of the register file.
Remember, we are using a register file that simultaneously can read two registers.
So we are going to take the second collection of bits, 24 to 20, and hook them up to the address of the second port.
As a result, this register file will produce the outputs that correspond to the contents of our register RS1 and RS2.
Then all what we need to do is to add them together by using our ALU. ALU is configured to be very simple here, to just do additions, so this is just an addr.
We'll get the new value at the output of an ALU that needs to be written into the register file. To where should be written? To the registrar RD?
Where is registrar RD? We know from the instruction, it is at the address that instruction bits 11 to 7 point to.
So on the next clock tick, we are going to write that in to our destination register RD. What else do we need to complete this?
Well, let's recap first what we need to do to execute the whole instruction.
First, we have the current value of the program counter points to the address in the instruction memory that is going to, after the access delay, produce the instruction and its output.
Simultaneously, we are going to get a new value of the program counter, PC plus 4, but we are not going to write it in until the next clock tick.
And let's take a look at what is happening with the instruction itself. Decoding is straightforward. We just pluck the parts of that instruction point to the register file.
Notice that we already have the address of the destination register. So it will just show up at the input of the register file, although we are not going to do anything with it.
Our results are going to show up at the output of the register file, after the ALU delay. We are going to get the new value that should be written in the RD.
And it is just going to be sitting at the input of the registered file until the next clock tick.
Then two new values, PC equals to PC plus 4, and RD equals to RD values of RS1 and RS2 is going to be updated on the next clock tick.
What do we need to complete this? We need control. And in this case, control is fairly simple, because we have a fixed function ALU that just does the addition.
So all what we need to do is to enable register file for writing to, so we need to have this control register that enables writing into the register file, asserted the signal RegWriteEnable has to be equal to 1.
Let's take a look a bit at the timing of addition. So here is the repeated data. But it's exactly the same as what we have had in the previous slide.
We just added explicitly clock to see how does it orchestrate the operation of the CPU. Let's see what is happening as time goes by.
And time is going to move here from left to right.
We are going to look at what happens at roughly three clock cycles during three rising edges of a clock, and we'll actually going to focus only on two of them.
First, on the first clock tick, we update the value of the program counter, and we write a new address into the program counter. In this case, it is 1000.
We are using some short, kind of a short handle notation here. Yes. Because the program run counter has 32 wires coming out of it. So the single PC will have 32 binary values.
We are using bundle representation, because it is really inconvenient to stare at 32 wires containing zeros and ones for a while. We would not handle it well after about five minutes.
So we'll say this is a bundle that represents the hexadecimal value 1000, corresponding to 32 bits. Okay, our current address is 1000.
And the value that we are going to get at the output of this addr is 1004. Okay. That is going to happen after the addr delay.
So this addr has a little bit of a delay.
The next thing that is going to happen at about the same time after the axis time of the memory, we are going to get a value at the output of the memory.
That value here is the new instruction.
And that instruction is another 32-bit binary number, but the binary number, instead of writing into hexadecimal value, we did another shorthand notation.
That shorthand notation basically says that we disassembled it and we got add x1, x2, x3 as the value on our wires. So that's a fairly straightforward thing to decode.
What we need to do is to point to parts of that instruction to the addresses of the registered files that contain RS1 and RS2.
And we get the values x2 and x3 as the contents of the registers x2 and x3. Very good. Now, in the next step, we perform the ALU.
We again have a bit of a delay there that corresponds to the addition delay. And the output of that register, that ALU, we get a new value after a propagation delay.
So sum of the values of register 2 and register 3 is sitting on these wires. But it is not getting written into the register file for a while.
It'll get written on the next clock tick, on the next rising edge of a clock. So the next rising edge of a clock restore the values of reg2 and reg3 into the register file.
So simultaneously, as we are updating that value in the register file, that's when we are writing the new address into the program counter. 1004.
And we are continuing to execute the next instruction in the same order.
Well, that next instruction better be an add, because we don't know how to execute anything else. We are going to see how we execute other things after a bit of a break.
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.