Memory Blackboxing

Overview

我们在调用memory的时候,通常使用如下code

1
val mem = Mem(Bits(32 bit), 1024)

其生成的Verilog,通常是reg array的形式,以模仿regfile或者SRAM的行为。在FPGA开发里面,可以用工具自动推断BRAM。而另外一种方式,则是将生成的Memory作为一个blackbox。

Standard Mem Black Boxer

Spinal提供标准的黑盒方法,使用方法:

1
2
3
SpinalConfig()
.addStandardMemBlackboxing(blackboxAll) //黑盒策略
.generateVhdl(new TopLevel)

黑盒策略有以下几种

Policy Kind Description
blackboxAll Blackbox all memory.Throw an error on unblackboxable memory
blackboxAllWhatsYouCan Blackbox all memory that is blackboxable
blackboxRequestedAndUninferable Blackbox memory specified by the user and memory that is known to be uninferable (mixed-width, …).Throw an error on unblackboxable memory
blackboxOnlyIfRequested Blackbox memory specified by the userThrow an error on unblackboxable memory

除开上面的标准黑盒方法,我们可以自定义自己的黑盒方法,以例化fab-specific SRAM。

Customized Black Boxer

基本类

Phase中涉及到mem blackbox flow的phase uml类图如下:

上图中,红色字体标识的类是我们自定义的Black boxer,用以实现SRAM的例化。

流程

下图展示了Memory黑盒化的流程图。

蓝色框框是我们自定义黑盒化方法的地方。有几个例子,一个是在 spinal.core.internals.Phase 内的 PhaseMemBlackBoxingDefault 内,另一个例子是NaxRiscv里的 XOR-based SRAM。

TODO
TODO