Chisel bootcamp 3.2 Muxes 结果错误?
Chisel bootcamp 3.2 Muxes result wrong?
这是 Chisel Bootcamp 中的代码:
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)}")
} }
我得到的结果是这样的:
[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的结果
Mux1H
的行为在其多个选择为高时未定义。如果您查看实现,它正在使用 or
来创建行为。 30 是 10 | 的结果20. 但是,同样,因为它是未定义的,所以当多重选择很高时,你不能依赖这个结果。
这是 Chisel Bootcamp 中的代码:
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)}")
} }
我得到的结果是这样的:
[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的结果
Mux1H
的行为在其多个选择为高时未定义。如果您查看实现,它正在使用 or
来创建行为。 30 是 10 | 的结果20. 但是,同样,因为它是未定义的,所以当多重选择很高时,你不能依赖这个结果。