Video
Đăng bởi Quản trị viên OpenER ·
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. Let's continue with our RISC-V CPU design. We have designed the data path and the control that supports all R types.
We have seen how we support the execution of the register-based addition and then extended it to support subtraction and then all the other R types.
Let's see what do we need in order to support operations with immediates. First, let's recap what is — what are — how do our immediate instructions look like.
In this example, add immediate takes an immediate value of minus 50, adds it to the contents of a register x1, and stores the result in x15.
It has similar, but slightly different, format from R types. It has a different opcode. But the fields for rd and rs1 are the same as what we have had in R types.
Funct3, function 3, encoding is the same as what we've seen before.
But instead of r is 2 field that was 5 bits wide and the function 7 field that was 7 bits wide, it has one 12-bit field that stores the immediate value.
So let's take a look at how do we plug that into a data path.
Let's start with our add sub data part or, actually, a general data path that supports R types, and see how we can modify it to add support for the immediates.
Remember, we had our program counter, our fixed adder that would increment that program counter by 4 on every clock tick, instruction memory, register file, and the ALU and the appropriate control.
Now, instead of adding two register values, rs1 and rs2, we would like to change that and add the contents of rs1 to an immediate or an immediate — or contents of register rs1 and stored it in rd.
We got 2/3 of what we need here.
We got the value from rs1 in the right place in the ALU and we are writing it into a correct place in the register file except that the second input of the ALU, or what we would call a B input of the ALU, we have rs2 connected instead of the immediate.
So we could build another data path that would be supporting immediates. We would rip out everything.
And instead of this input being connected to rs2, we can connect it to — connect an immediate to it. But let's not do that.
Let's just build one data path that supports both R types and I types. And how would we do that? Well, we would just put a multiplexer.
So this multiplexer selects between rs2 value and the immediate based on some select signal, which is Bsel.
And Bsel stands for "B select" — B operant for the ALU. So if it is equal to 0, we will pick rs2. If it is equal to 1, we'll pick the immediate.
Keep in mind that both of these inputs are 32-bit values, meaning there are 32-bit wires, 32 different wires, coming in the input 0 and the input 1.
And 32 wires are coming out based on one select signal. Now, we got pretty much everything we needed here. We do need to get this immediate from somewhere.
Immediate is in the upper part of the instruction. And it is only 12 bits wide. So we need to take that 12-bit-wide value and make 32 bits out of that.
So we need a little block here that will do that immediate generation. So it will be controlled by this immediate select.
What we'll find out a little bit later on is that we will see different types of immediates. Remember, different instruction types have different encodings for the immediates.
So we would like to use that block. So we'll say, make us an immediate of an I type this time. But we'll see that a bit later.
So let's see what happens when we light up this data path. And this is a fun example here. So when we light up the data path, we first read the program counter.
Program counter points to the instruction memory, reads out the contents of the instruction memory, and reads out the instruction that it addresses and updates the program counter.
Now, we got all of this instruction.
So we will point to the register file, to the three parts of a register file, all three parts of the register file, and simultaneously start generating the immediate.
Now, you may wonder over here, uh-oh, don't we need to disconnect this input, B? We really don't want that rs2 value.
Well, we are going to generate both rs1 and rs2 at the output of the register file, and we are going to, well, use the rs1 value. But rs2 simply will be ignored.
Remember, our register file always reads. We just give it an address. It produces an output. We don't need a clock or anything to make that happen.
So it produce that value. But our multiplexer will be set to take the value of the immediate and forward it to the ALU.
So ALU will calculate the new value, the contents of rs1 plus the immediate, and put it back at the input of the register file.
On the next clock tick, we are going to write that new value, new state, into the destination register, rb, together with updating the program counter.
And that's it. This is a support for the immediates. Let's take a little bit — or just one more thing here.
The key thing here is we have to have B select set to 1. So one more thing here is, how do we generate the immediate here?
So if we were just to take a look, if we just needed to support I-type immediates, that would have been very simple. Our I-type immediates are in the upper 12 bits of the instruction.
So what we would do — we would just take 12 wires and move them down to the lowest 12 bits of the immediate.
So we'll take 12 wires and wire them down to the immediate. What do we do with the upper 20 bits?
Well, all what we need to do is to copy the most significant bit of the instruction field to perform sign extension.
So we would just make 20 copies of that most significant bit of the immediate value.
In general, we are going to be using a few multiplexers to support different types of immediates when we introduced — introduce the other formats, support for the other formats, a bit later.
We'll break now, and we are going to take a look at more instructions. 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.