Here is one way to make this seem ugly.
class DiffSquared extends Module {
val inputWidth = 8
val width = 16
val io = IO(new Bundle {
val X = Input(UInt(inputWidth.W))
val M = Input(UInt(inputWidth.W))
val Out = Output(UInt(width.W))
})
val x = Wire(UInt((inputWidth+1).W))
val m = Wire(UInt((inputWidth+1).W))
x := io.X
m := io.M
val diff = Wire(SInt((inputWidth+1).W))
diff := x.asSInt - m.asSInt
io.Out := (diff*diff).asUInt
}
What is the best way to null the UInt extension for a 9-bit SInt, make a difference, squared it and present the result as a 16-bit UInt?
source
share