首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >凿训练营3.2 Muxes的结果是错误的?

凿训练营3.2 Muxes的结果是错误的?
EN

Stack Overflow用户
提问于 2019-12-10 22:37:55
回答 1查看 108关注 0票数 0

以下是Chisel Bootcamp中的代码:

代码语言:javascript
复制
Driver(() => new Module {
    // Example circuit using Mux1H
    val io = IO(new Bundle {
      val in_sels = Input(Vec(2, Bool()))
      val in_bits = Input(Vec(2, UInt(8.W)))
      val out = Output(UInt(8.W))
    })
    io.out := Mux1H(io.in_sels, io.in_bits)
  }) { c => new PeekPokeTester(c) {
    poke(c.io.in_bits(0), 10)
    poke(c.io.in_bits(1), 20)

    // Select index 1
    poke(c.io.in_sels(0), 0)
    poke(c.io.in_sels(1), 1)
    println(s"in_sels=${peek(c.io.in_sels)}, out=${peek(c.io.out)}")

    // Select index 0
    poke(c.io.in_sels(0), 1)
    poke(c.io.in_sels(1), 0)
    println(s"in_sels=${peek(c.io.in_sels)}, out=${peek(c.io.out)}")

    // Select none (invalid)
    poke(c.io.in_sels(0), 0)
    poke(c.io.in_sels(1), 0)
    println(s"in_sels=${peek(c.io.in_sels)}, out=${peek(c.io.out)}")

    // Select both (invalid)
    poke(c.io.in_sels(0), 1)
    poke(c.io.in_sels(1), 1)
    println(s"in_sels=${peek(c.io.in_sels)}, out=${peek(c.io.out)}")
} }

我得到了这样的结果:

代码语言:javascript
复制
[info] [0.001] in_sels=Vector(0, 1), out=20
[info] [0.001] in_sels=Vector(1, 0), out=10
[info] [0.002] in_sels=Vector(0, 0), out=0
[info] [0.002] in_sels=Vector(1, 1), out=30

为什么select = (1,1)时结果是30?PS: 30是一个随机数,而不是结果10 + 20

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-11 00:59:59

当多个selects为高时,Mux1H的行为是未定义的。如果你查看实现,它使用or创建行为。30是10 | 20的结果。但是,同样,因为它是未定义的,所以当多个selects为高时,您不能依赖此结果。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59269647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档