如何为异步电路编写凿子scala语言的muller c元素?

发布于 2025-02-03 02:31:51 字数 1418 浏览 3 评论 0原文

当我写这篇文章时:


class MullerC(val WIDTH: Int = 2) extends Module {
  val io = IO(new Bundle {
    val in = Input(Vec(WIDTH, Bool()))
    val out = Output(Bool())
  })

  io.out := false.B
  when (io.in.reduce(_ & _)) {
    io.out := true.B
  }.elsewhen (io.in.map(!_).reduce(_ & _)) {
    io.out := false.B
  }
}

我得到了这样的verilog:

module MullerC(
  input   clock,
  input   reset,
  input   io_in_0,
  input   io_in_1,
  output  io_out
);
  assign io_out = io_in_0 & io_in_1;
endmodule

那是一个简单而不是C门。

但是,当我尝试添加否则这样的时:


class MullerC(val WIDTH: Int = 2) extends Module {
  val io = IO(new Bundle {
    val in = Input(Vec(WIDTH, Bool()))
    val out = Output(Bool())
  })

  io.out := false.B
  when (io.in.reduce(_ & _)) {
    io.out := true.B
  }.elsewhen (io.in.map(!_).reduce(_ & _)) {
    io.out := false.B
  }.otherwise {
    io.out := io.out
  }
}

它不能再编译了:

Exception in thread "main" firrtl.transforms.CheckCombLoops$CombLoopException: : [module MullerC] Combinational loop detected:
MullerC.io_out
MullerC._GEN_0   @[----.scala 14:38 ----.scala 15:12 ----.scala 17:12]
MullerC._GEN_1   @[----.scala 12:30 ----.scala 13:12]
MullerC.io_out  

我应该如何在凿子中实现muller c?非常感谢。

When I wrote this :


class MullerC(val WIDTH: Int = 2) extends Module {
  val io = IO(new Bundle {
    val in = Input(Vec(WIDTH, Bool()))
    val out = Output(Bool())
  })

  io.out := false.B
  when (io.in.reduce(_ & _)) {
    io.out := true.B
  }.elsewhen (io.in.map(!_).reduce(_ & _)) {
    io.out := false.B
  }
}

I got Verilog like this :

module MullerC(
  input   clock,
  input   reset,
  input   io_in_0,
  input   io_in_1,
  output  io_out
);
  assign io_out = io_in_0 & io_in_1;
endmodule

That is a simple and gate instead of a C gate.

But when I tried to add otherwise like this :


class MullerC(val WIDTH: Int = 2) extends Module {
  val io = IO(new Bundle {
    val in = Input(Vec(WIDTH, Bool()))
    val out = Output(Bool())
  })

  io.out := false.B
  when (io.in.reduce(_ & _)) {
    io.out := true.B
  }.elsewhen (io.in.map(!_).reduce(_ & _)) {
    io.out := false.B
  }.otherwise {
    io.out := io.out
  }
}

It could not be compiled any more:

Exception in thread "main" firrtl.transforms.CheckCombLoops$CombLoopException: : [module MullerC] Combinational loop detected:
MullerC.io_out
MullerC._GEN_0   @[----.scala 14:38 ----.scala 15:12 ----.scala 17:12]
MullerC._GEN_1   @[----.scala 12:30 ----.scala 13:12]
MullerC.io_out  

How should I implement the Muller C in Chisel? Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淑女气质 2025-02-10 02:31:51

我通过此链接找到了答案: disable firrtl firrtl firrtl通过

我应该使用否则,然后添加- no-Check-comb-loops作为发射Verilog代码的参数。谢谢。

顺便说一句,我也尝试了这一点,并且也有效。

class MullerC(val WIDTH: Int = 2) extends Module {
  val io = IO(new Bundle {
    val in = Input(Vec(WIDTH, Bool()))
    val out = Output(Bool())
  })

  io.out := false.B
  val allTrue = Wire(Bool())
  val allFalse = Wire(Bool())

  allTrue := io.in.reduce(_ & _);
  allFalse := io.in.map(!_).reduce(_ & _)
  io.out := Mux(allTrue | allFalse, Mux(allTrue, true.B, false.B), io.out)
}

这将产生更美丽的Verilog代码,尽管它并不重要。

I found the answer via this link: Disable FIRRTL pass that checks for combinational loops

I should use otherwise and then add --no-check-comb-loops as a parameter to emit verilog code. Thanks.

By the way, I also tried this and it works as well.

class MullerC(val WIDTH: Int = 2) extends Module {
  val io = IO(new Bundle {
    val in = Input(Vec(WIDTH, Bool()))
    val out = Output(Bool())
  })

  io.out := false.B
  val allTrue = Wire(Bool())
  val allFalse = Wire(Bool())

  allTrue := io.in.reduce(_ & _);
  allFalse := io.in.map(!_).reduce(_ & _)
  io.out := Mux(allTrue | allFalse, Mux(allTrue, true.B, false.B), io.out)
}

This will generate more beautiful verilog code althought it does not matter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文