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] Hello. Welcome back to RISC-V CPU design.
We have designed a data pod that we can share between all R-type and I-type instructions, including the loads. To support the loads, we have added the memory to our data path.
We access the memory by pointing the address to it, and then we read the value and store it into the destination register.
Let's see what do we need to modify in order to support the stores.
So here is a representative store instruction, which is store word in RISC-V. It reads two registers, rs1 and rs2 and the immediate from the instruction.
We take that immediate value, we extend it, and add it to the value that is stored in the register rs1. That is what forms the address that is used to access the memory.
Now, when we have that address, we take the contents of our register rs2 and write it to the memory.
So what we can see from this is that we can reuse much of the data path.
We are still going to use the ALU to form the address to add the immediate value to the contents of register rs1.
We do need to provide an additional path that would put the contents of register rs2 in the port of the memory that is going to be used for writing.
And we need to modify the memory to enable it for writing, such that it will be updated on the next clock cycle. Another important thing here is we need a different immediate this time.
So our immediate generation unit will need to be updated to be able to support two types of immediate.
In the I-type of an immediate, our immediate was located in the top 12 most significant bits of the instruction.
But in the S format, the immediate split split into two parts.
We have still the top 7 bits in the top 7 most significant bits of the instruction, but the lower 5 bits are now in locations 11 to 7.
Remember, this was done such that we keep the fields that store the addresses of the registers the same across all instruction formats, because those are in the critical path.
You can just imagine now we know the reason for that.
It would be a mess to try to move these addresses all over the place before we start accessing the register file, and the register the file is often in a critical path.
So we'll need a modification to the immediate generation unit. But let's see what we got so far. So what we have so far is the data path that supports the loads.
And in the loads, I'm just showing the data path with lw.
Load bytes and load half words need an additional multiplexer over here and a few logic gates, but I'm leaving them out to avoid too much complexity here.
So what we had is the data memory. We have added a data memory that we're going to use to read the value from and store it back into the register file.
Our ALU points to the address where we would like to read from, and it is formed by adding the immediate to the source register rs1.
The things that we added were these control signals at the end — mem, rw, and write back select.
Let's see what we need to do to support stores. So in order to support stores, we need to modify our model of the memory, such that we can write to it.
So two things will happen — our control signal, mem read write, is going to be given a value write so we can write to the memory on the next clock tick.
And we are adding another port to the memory, which is DataW This is where we are going to place the data that you would like to write into the memory at.
And we are going to ignore whatever is being read out of the memory accidentally. We don't care about anything that appears at the data read port.
So we are setting the write back slot select signal to a star or a don't care.
We'll use it in logic optimization later to minimize the number of gates that we need in the control.
So our data path now is very similar to what we have seen in the loads with a few exceptions.
Immediate select is going to select a new type of an immediate, which is the S-type.
We are not writing back to the register file, so we are going to set the RegWriteEnable signal to 0.
And then we are still going to select the B operant here, which will pick the B operant to be the immediate.
ALU is still going to add that immediate to the rs1, and that's how we got our address. Let's light up this data path to see how things actually propagate through it.
We're going to cut through the chase and we are going to go through the instruction fetch and end up with the instruction that is going to be decoded.
Our control object is now going to process that instruction and set appropriate signals in the control, such that we light up the right parts of the data path.
So immediate select is going to be set to S, register file writing is going to be disabled, B select is going to be set to pick the immediate, ALU is going to be set to execute an addition, and memory is going to be enabled for writing.
The final select signal is write back as I don't care. So while the control is being lit up, simultaneously we are accessing the registers and generating the immediate.
And what we see here, we got our rs1 contents and rs2 contents, and the important thing that we see here is that rs2, although it shows up at this multiplexer, multiplexer is not selected to take it.
Rs2 goes around it and goes to the data port of the memory. At the same time, our immediate is formed and goes to the ALU.
Output of that ALU points to the address where we are going to write this data. And that is it. That completes the store cycle.
On the next clock tick, a new datum is going to be written into the data memory, and the program counter is going to be updated.
Let's see a little bit about what do we need to do to our immediate generation unit. Our immediate generation unit so far was very simple.
It was designed to take 12 bits from the I-type instruction and sign extend it to 32 bits.
Now, we have to support both I and S-type immediates. These immediates are similar. They have the top 7 bits being the same.
So whatever we have in the top 7 bits in both of I-type and S-type instructions is going to go into the same spot bits 7 to 12 or 6 to 11 of the new immediate, with 11th bit extended all the way to 31st bit for sign extension.
But the lower 5 bits in case of I-type are going to come from the instruction bits 24 to 20. In case of S-type are going to come from instruction bits 11 to 7.
So all what we need to do is to implement one multiplexer that is going to be working two way.
In case of an I-type of an instruction, it's going to take bits 24 to 20. In case of S-type instruction, it's going to take bits 11 to 7.
And that's it. That logic design is fairly simple.
All what we have is the same logic that we have had for I immediate creation, and we are just adding one multiplexer in front of it.
That's most of it that we need to implement source. There are two other storage instructions. In RISC-V ISA, store bytes and store half words, those are relatively straightforward to implement.
We use exactly the same data path.
The only modification that we need to do, we adjust a gate or two, is to make sure that we don't accidentally overwrite something in the memory that we should not write into.
That completes the story about the stores. When we come back, we're going to add a few major modifications to the data path, but that will be it.
That's pretty much everything we need to know about that data path. 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.