diff --git a/src/main/scala/uk/ac/soton/ecs/can/core/Adder.scala b/src/main/scala/uk/ac/soton/ecs/can/core/Adder.scala index 9d5c08312234aecd70e807eaaa47fde436771bf8..581e5587494a7a2dfc39a693c51988314a86b96f 100644 --- a/src/main/scala/uk/ac/soton/ecs/can/core/Adder.scala +++ b/src/main/scala/uk/ac/soton/ecs/can/core/Adder.scala @@ -10,6 +10,8 @@ class Adder extends MultiIOModule { val rhs = IO(Input(UInt(512.W))) val out = IO(Output(UInt(512.W))) + // NOTE: Unlike what's done in `BaseRound`, here no reversal is applied, since + // the additions are done on the basis of words and do not spread bits. private val _lhs = lhs.asTypeOf(Vec(16, UInt(32.W))) private val _rhs = rhs.asTypeOf(Vec(16, UInt(32.W))) private val _out = Wire(Vec(16, UInt(32.W))) diff --git a/src/main/scala/uk/ac/soton/ecs/can/core/BaseRound.scala b/src/main/scala/uk/ac/soton/ecs/can/core/BaseRound.scala index f92a53ad364647ae4f8db999111f7e3c6cc3b37f..66523eec2c64c5be14e214f884f33c5abc29342b 100644 --- a/src/main/scala/uk/ac/soton/ecs/can/core/BaseRound.scala +++ b/src/main/scala/uk/ac/soton/ecs/can/core/BaseRound.scala @@ -4,6 +4,7 @@ package uk.ac.soton.ecs.can.core import chisel3._ +import chisel3.util.Cat import uk.ac.soton.ecs.can.config.CanCoreConfiguration abstract class BaseRound(implicit cfg: CanCoreConfiguration) @@ -11,9 +12,19 @@ abstract class BaseRound(implicit cfg: CanCoreConfiguration) val in = IO(Input(UInt(512.W))) val out = IO(Output(UInt(512.W))) - protected val _in = in.asTypeOf(Vec(16, UInt(32.W))) + // NOTE: A conversion between an UInt and an aggregate type reverses the + // sequence of elements. The `_in` cast below reverses such reversal by + // manually creating a `Vec` with the elements in the casted `Vec` reversed. + // Same for the `out` connection, where `Cat`, which concatenates elements + // from the most significant element to the least significant element, is used + // instead of `_out.asUInt()`, which puts the first element in the `Vec` to + // the least significant position of `UInt`. + // + // See also: + // - https://github.com/chipsalliance/chisel3/blob/master/core/src/main/scala/chisel3/Data.scala#L695-L696 + protected val _in = VecInit(in.asTypeOf(Vec(16, UInt(32.W))).reverse) protected val _out = Wire(Vec(16, UInt(32.W))) - out := _out.asUInt() + out := Cat(_out) protected def wire(wireBox: Seq[Seq[Int]]): Unit = wireBox.foreach { wireSeq =>