Simultaneous reading and writing to registers

时间:2015-12-08 19:25:48

标签: vhdl mips fpga computer-architecture

I'm planning to design a MIPS-like CPU in VHDL on a FPGA. The CPU will have a classic five stage pipeline without forwarding and hazard prevention. In the computer architecture course I learned that the first MIPS-CPUs used to read from the register file on rising clock edge and write on falling clock edge. The FPGA I'm using doesn't support using rising and falling clock edge at the same time (regarding reading and writing to registers), so I can't exactly do like the original MIPS and have to do it all on rising clock edge.

So, here comes the part where I'm having a problem. The instruction writes back to the register in the write back stage. The write back stage sends the data directly to the decode stage. Another instruction in the decode stage wants to read the same register that also the write back stage wants to write.

What happens in this case? Does the decode stage take the new value for the instruction or the old value that is still in the register file?

2 个答案:

答案 0 :(得分:0)

问题是您对术语"注册"有什么理解?或者更具体地说,您希望如何将寄存器组映射到FPGA。

最简单但不那么有效的方法是根据寄存器大小将每个MIPS寄存器映射到几个触发器。您可以仅在时钟边沿(例如下降沿)更新这些触发器。之后,您可以随时读取新内容,也称为异步读取。这种解决方案效率不高,因为从寄存器组中选择一个MIPS寄存器的多路复用器需要大量的逻辑资源。

如果你有一个FPGA,其中LUT可以用作分布式存储器,那么几乎所有的多路复用器逻辑资源都可以保存。分布式存储器通常也提供异步读取(当然也是同步写入)。请阅读综合工具的供应商文档,了解如何描述这种类型的内存以进行综合。

最后但并非最不重要的是,您可以将完整的寄存器库映射到片上块存储器。这些通常仅提供同步读取,即,读取在时钟边缘开始。 (当然,它们也只提供同步写入)。但是,这些通常是双端口RAM。因此,您可以在一个端口的下降沿写入,并在另一个端口上的上升沿读取。请阅读关于写入时间的FPGA文档。例如,在某些Altera FPGA上,写操作会延迟到时钟的下一个相对边沿(此处为上升沿)。

答案 1 :(得分:0)

适合经典五级设计解码阶段的寄存器文件包括一个三端口RAM(或两个双端口RAM)和两个复用器和比较器。比较器和复用器需要绕过来自回写阶段的数据。这是需要的,因为写数据在下一个周期被写入三端口RAM。因为来自回写阶段的信号是同步的,所以这不是问题。

相关问题