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: Hello, and welcome back to RISC-V CPU Design Module.
In the past few segments, we walked through the execution of several instructions. And at moments, that might have felt repetitive and perhaps boring.
But we wanted to accomplish two purposes by doing that. The first one was to get a good sense of how long does it take us to execute an instruction.
And we actually ended up measuring that. That'll help us in the next module. But the second purpose was to get a really good handle on what is the control logic supposed to do.
That's going to make this segment much easier to understand and make it look fairly straightforward. So let's get into that.
First, let's recap what do we expect control logic to do. Control logic can be viewed essentially as a lookup table. This is a lookup table with a bunch of rows and columns.
Rows are the inputs, which will be the instructions that we would like to execute. The columns will be the control bits.
So each row input is an instruction that we are running, along with two more inputs. These are the branch comparison outcomes, whether the operations are equal or less than.
Remember, those are the two arrows that were also pointing down into the control logic as the inputs. We need those to figure out how to select some of the control signals.
And then each row has a particular set of control signals that are set that it needs to correctly execute.
So, well, the instructions we are well familiar with is our add. The add has its control word encoded in the first row.
So we can view this as a word. It has a number of bits, about 15 of them.
So it simply says, what is the control. What are the control bits supposed to be?
So we know that PCSel is supposed to be pointing to the input that will take the next instruction, plus 4. Immediate select is don't care whether it's a zero or one.
Or, actually this is a three-bit value for the immediate select. So they can be anything, 000001010, and so on, and it doesn't matter to us.
Also, Branch Signness does not matter either, because we are not executing a branch. But ASel and BSel signals do matter. And they should be taking the inputs from the registers.
ALU is up for bit control signal, because ALU can do quite a bit of stuff. In this case, we are going to encode it to do the addition.
We're going to set its control bits to do the addition. And then Memory Rewrite is going to be set to read. Register Write Enable is going to be one.
And finally, Write Back Select is a two-bit control signal that will be set to write back from the ALU. So how do we implement this control logic, this essentially truth table.
There are two options to do that. One of them is to use a read-only memory. The other option is to use the control combinational logic, a bunch of ands and ors.
Read-only memory is like a standard memory that we have seen before, except that we don't write into it. We just read from it. So that's why it's called read-only.
We actually write to it at the design time when we are designing this control logic. We populate it with ones and zeros, whatever we would like to see in particular control words.
So it's relatively easy to do that. And then we will just read it by pointing to a particular control word that you would like to get out of this read-only memory.
So a designer can keep reprogramming it while designing it. And then we can test it out by executing a whole bunch of instructions. It's really easy. It's popular during prototyping.
It is also popular when we are trying to perhaps add an extension. So, for example, we would like to add a compressed part of the instruction set, RISC-V instruction set.
We have heard about compressed instructions before. So we would just add that part of the table to our ROM, and then try it out.
In practice, when we design real chips, control will be designed as a bunch of and and ors, because that's more compact. And it is faster.
But let's actually see what do we need in order to implement control logic. What kind of inputs do we need?
Well, we need to have a unique representation for every single one of these instructions. And we need those two bits for the branch outcomes.
Instructions are 32-bits wide, but the relevant information is stored in only nine bits. So somebody can say that this 5i arbitrary 2i, is just a 9-bit ISA.
Where are the relevant bits?
The relevant bits are the upper five bits of the upcode, the entire function three field, and that one bit from the function seven field, the 30 bit of the instruction.
That is used for encoding some of the adds, subs, and shifts.
So there is just a total of nine of them, five plus three plus one.
If we are going to add some instructions, like a compressed instruction, we would need to take a look also at the last two bits, or the least significant two bits, which are set to be one and one for RV32I.
But for now, since we're only dealing with the arbitrary 2i, instructions, in order to decode them, we just need those nine bits from the instruction, and two additional bits which are the branch outcomes.
So we would point to the ROM with an address that is 18-bits wide. And we are going to read out of that ROM a 15-bit control word.
This control word will contain one bit for a PC Select, three bits for the Immediate Select, a bit for Signness of a Branch, a bit for A Select and B Select each.
ALU Select will be a four-bit control signal. Memory read-write is a single control bit.
Register Write Enable is also a single control Bit and finally, write back select is a two-bit output. How does the ROM actually work inside?
It looks like a lookup table literally. We are going to address this lookup table with the same stuff that we have had in the original initial lookup table.
We are going to have instructions represented by their nine-bit values, plus two bits that represent the branch outcomes.
And then in each row here will be a corresponding control word for those instructions.
First, what we do, we decode the address.
These inputs, the instruction types, are binary encoded. The output of the address decoded is so-called one hot.
Only one of these lines is going to light up. We are going to address only one controlled word, because that's what makes sense. We don't want to have two different control words.
That would confuse the data path. We only produce one control word for each instruction, or instruction branch combination.
So, for example, our add would point to the first line in this read-only memory.
And if we are executing an add, this is the only word that is going to light up. This is the only word that is going to be true.
All the other ones are going to be zeros. So the output of this controller, we are going to get a control word that only corresponds to an add.
All the other ones are zeros.
In a way, you can view this as an and/or structure.
In order to only have one of these lines enabled, this address decoder has to be a fairly wide and.
And then, in order to form the output controller word, it can be just an or. That's the simplest way to implement it. So this is and/or structure.
In general, there is a lot of redundancy here. Many of these entries are going to be zeros.
So that's the idea of trying to simplify the entire control logic into smaller numbers, number of ands and ors.
So in this case, let's take an example, what is perhaps the simplest encoding example that we have in our instruction set, and that would be whether the branch is assigned or not.
So let's take a look at what encodes that we are dealing with a branch.
These are the instruction bits, six to two, these five instruction bits are telling us that it's a branch if the values are 111 and 11000.
And then we need to find out in the three-field function, three field, what kind of a branch it is.
So, when looking at these, the bottom two, the last two, are the unsigned branches, BLTU and BGEU.
What is common for them and different for the other instructions? Well, you can take a look at this middle bit, instruction three bit. It is true only for those two.
So that sets the signness of a branch. In order to decode this branch, we just need to look at that middle bit instruction three bit.
And it tells us whether the branch is signed or not. So that control signal is essentially equal to instruction 13 and the branch, because this bit will be true for other types of instructions.
In order to decode the branch, right, I mean, the branch is encoded with lower bits.
So it is I6 and I5, and not I4 and not I3, and not I2.
That is our branch.
That tells us that decodes all the branch instructions. And then to just select that, we are looking for an unsigned branch. We add that with the instruction bit 13.
Fairly simple, isn't it. This is a six-bit wide and gate.
Keep in mind that sometimes six-bit wide and gates may not be the most practical thing to implement. So we'll try to break this down, typically, into a couple of gates.
That's what our Boolean manipulation is for, isn't it. That's designed to decode logic for add.
So add is just one line in this truth table that has our nine bits. Here is our add.
So what we would do to decode that we are executing an add?
Well, we would just write down the expression that it is equal to I30 instruction bit being false. I14 is false.
I13 is false. I12 is false. All of them are zeros. And then we need to and this with an R-type instruction.
R-type is encoded as I6 being false, I5 being true, I4 being true, I3 being false, I2 being false.
And that's it. If we are adding other extensions, we would have to and this with 11 in the last bit positions.
But we don't have to for the purpose of our project, because we don't have any other instructions. And that's it. We just finished all what we need to know about instruction decoding.
And you've done more than that. We actually built a complete RISC-V processor. We should celebrate that, which we'll do after a bit of a break.
Đă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.