You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在新版Chisel(>3.6.1)中为SyncReadMem添加AttributeAnnotation的方法

解决新版Chisel(>3.6.1)中SyncReadMem配合firtool添加Verilog内存属性的问题

问题根源

切换到firtool编译器后,原有的AttributeAnnotation无法作用于SyncReadMem生成的smem节点——firtool要求该注解的目标必须是模块、wire、node或寄存器,而smem不在此范围内。

解决方法

使用Chisel 3.6+提供的内存专用注解,直接为SyncReadMem添加目标属性,firtool会自动将属性传递到最终生成的SystemVerilog寄存器数组上。

方法1:使用addMemoryAttribute工具函数(推荐)

导入工具类后,直接调用函数添加属性:

import chisel3._
import chisel3.util.experimental.addMemoryAttribute

// 创建SyncReadMem实例
val entries = 1024
val gen = UInt(8.W)
val ram = SyncReadMem(entries, Vec(1, gen), SyncReadMem.WriteFirst)

// 添加ram_style属性,指定为block RAM
addMemoryAttribute(ram, "ram_style", "block")

方法2:手动创建MemoryAttributesAnnotation

如果需要更灵活的属性配置,可直接构建专用注解:

import chisel3._
import chisel3.experimental.annotate
import firrtl.transforms.MemoryAttributesAnnotation

val entries = 1024
val gen = UInt(8.W)
val ram = SyncReadMem(entries, Vec(1, gen), SyncReadMem.WriteFirst)

annotate(new ChiselAnnotation {
  def toFirrtl = MemoryAttributesAnnotation(
    target = ram.toTarget,
    attributes = Map("ram_style" -> "\"block\"")
  )
})

验证结果

生成的SystemVerilog代码中,寄存器数组会带上指定的属性标注:

(* ram_style = "block" *)
reg [7:0] Memory[0:1023];

内容的提问来源于stack exchange,提问作者AlexMontgomerie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:52:38