Search code examples
memoryfpgachiselflip-flopdigital-design

Store a bitvector in flipflops instead of memory - Chisel


I would like to know the difference in usage of Reg and Mem in Chisel, and how I can decide which of these to choose in common scenarios. I would assume that Mem is the best idea when storing large amount of data, because it would store the data to the SRAM instead of using the flip-flops inside FPGa slices, correct?

If I would like to implement a large register file (10x usual size), would it be best to use Mem then istead of Reg?


Solution

  • There are several differences. The one point you about using SRAM versus flops is kind of the surface difference. In fact, most FPGA vendors support the idea of implementing Memory as block memory or as flops. Functionally, they would be the same.

    Because of the way most FPGA vendors implement their technologies, if you use a little tiny sliver of a single Block RAM, you basically use All of that single block RAM. Lets say your device has 10 ten block RAM's in it. An you implement 10 tiny memories, each one only byte wide lets say... You will use all 10 block RAM's! That's not good. If the memory tables you have are small, implement them as flops and save the block RAM for the big stuff. To your own question, where you suggest mem is better for large data, this is why that is true.

    The next issue, is timing. It turns out that timing to FPGA memory can sometimes be slow relative to Flops. In otherwords, if you had a buffer that you had implemented in memory and were finding out that you could not get the design to run at 300Mhz, you could change the buffer to use flops and you might squeeze out the extra speed you need to get you to 300Mhz.

    There are routing differences too. Depending on your design you might find that all of your memory in one quadrant of a chip is utilized and so now the design is trying to reach into another quadrant to get more block RAM, thus causing your logic to spread out. This might manifest itself also as poor timing. If you allow some of the memory to instance as flops, then you might see your design snap back into shape in a quadrant because it doesn't need to stretch for the extra resources.

    These are some of the things I think about when choosing RAM over Flops for memory.