我正在使用开源工具链Yosys > NextPnr > IcePack来合成 Lattice HX8K FPGA 的代码。这是 1Kb RAM 的通用版本(我将其用作 VGA 模块的视频 RAM):
module text_ram #(
    parameter A = 10,
    parameter D = 8
  ) (
    input  clk,
    input  we,
    input  [A-1:0] addr,
    input  [D-1:0] din,
    output reg [D-1:0] dout
  );
  reg [D-1:0] vram [0:(1<<A)-1];   // 2^A memory spaces of D bits
  initial
    $readmemh("lib/video.hex", vram, 0, 1024);
  always @(posedge clk) begin
      if (we) vram[addr] <= din;
      dout <= vram[addr];
  end
endmodule
分析资源icebox_stat(连同我拥有的所有其他逻辑;对不起,但我不知道如何隔离单个组件的统计信息),它报告:
DFFs:     21
LUTs:    204
CARRYs:   26
BRAMs:     3
IOBs:      4
PLLs:      0
GLBs:      3
现在,通过这个简单的修改(当然,这dout有所不同,但符合我的预期目的):
  always @(posedge clk)
      if (we) vram[addr] <= din;
  always @(*)
      dout <= vram[addr];
它报告:
DFFs:     21
LUTs:    151
CARRYs:   26
BRAMs:     0
IOBs:      4
PLLs:      0
GLBs:      1
不仅减少了 53 个 LUT,而且真正让我吃惊的是 BRAM 的使用似乎消失了!有人可以解释一下为什么吗?此外,我如何检查此类案例以确保我了解Yosys 和 NextPnr 的基本决策?