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ả.
BORA NIKOLIC
Hi. Welcome back to our design of RISC-V processor. We have designed a data path that can execute both R-type and I-type instructions.
So let's recap it before we figure out what we need to do to it to add loads.
In the datapath that we had so far, we had only four phases of execution. Remember, we said, typically instruction execution has five phases.
But here R-types or I-types that we have seen so far did not need to access memory. So that phase was dropped. First, we have our instruction address stored in the program counter.
The program counter points to the instruction memory, and fetches the instruction that we would like to execute. In the second phase, we could decode that instruction.
And by using the information that we decoded from the instructions fields, we set the control bits.
At the same time, we fetch the data from the registers and prepare the immediate. In the third phase, we execute the instruction in the ALU.
We perform addition, subtraction, or any of the logic operations that we would like to do based on the instruction fields.
There is no memory access phase in instructions that we have seen so far. So we proceed straight to the fifth stage of execution.
That is writing back the output of the ALU into the destination register. Now, in order to support loads and stores, we'll have to have the data memory.
And keep in mind that RISC-V is so-called a load store type of an architecture where all operations with the memory are done just with loads and stores.
No other instruction type accesses memory. So let's review first what do we need to do with our loads. Here is a load word memory that we have seen before.
It is of an I-type as well, because it has the same format of an immediate as the previous I-type instructions that we have seen before.
So immediate is 12 bits wide, and it should be signed extended before its contents is added to the value in the register rs1.
Now, that sum of the immediate and the value from rs1 should not be written straight back into the destination register, which is what we did in i-types.
Instead, it is being used to point to the memory address where we would like to retrieve data from.
And then that data that we get from the memory will be written back into the destination register. So what does our datapath need to support?
Well, the first part looks exactly the same as what we have seen already in I-types shared with R-types, except that we need to have memory back in the picture.
So memory is right here. And it shouldn't be a surprise. We point to an address in the memory where we would like to read the data from.
And that data appears at dataR port. We'll take that value from the dataR port and write it back into the destination register.
But keep in mind we are not building a separate data path for loads. This is the shared datapath that we had before.
So in order to support both arithmetic instructions and loads, we use a multiplexer.
And we select where does our destination for write back — where does our operand for write back come from, whether it comes straight from the ALU, or comes from the memory.
So we have a new select signal, write back select. In this case, memory is configured for reading. So we treat it essentially as a combinational block. We don't really care about the clock.
And our memory rewrite is going to be set to read. Let's light up this datapath to see what it actually does.
So remember, first, we have our next instruction or current instruction to be executed in the program counter.
The program counter points to the address in the instruction memory where the instruction is. We retrieve that instruction, and decode it in the second phase of execution.
When decoding that address, we find out — when decoding the instruction — I'm sorry — we find out what do we want to do, and set the appropriate control to execute it.
So in this case, we'll set the immediate to be of an I-type. We'll see we have other immediates later on.
Then we will say that we would like to write back into the register file.
We pick the B operand in the ALU to be the immediate, not the output of the register rs2.
We set the type of ALU operation that we would like to do. Remember, we are using ALU here to add the immediate to the value in rs1.
We set memory read/write to read, and we set the write back select to 0 to write back from the memory.
In the same phase of execution, we prepare the ALU operands, which will be rs1 by reading the — accessing the registers in the register file, and extending the immediate value.
In the third phase of execution, we perform the addition and point to the address in the data memory. In the fourth phase of execution, we perform the memory access.
And finally, in the fifth phase of execution, we write back to the destination register.
And that's it. This is our support for the loads.
One thing that just has to be kept in mind, there are several different load instructions in the RISC-V base RV32 instruction set.
So we have narrower loads. These narrower loads can load bytes or half words, meaning they can load 8-bit wide data, or 16-bit wide data.
And it can be of signed or unsigned type.
It is supported by the same datapath, except that we may have to add, or we definitely have to add a few logic gates and a few multiplexers to support that.
This is a good exercise in logic design. And I strongly encourage you to take a look at that. You may actually need it for a project.
And you will find it in some of the previous exams. We can break now before we get to the stores. So see you when we get to the stores module.
Đă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.