chisel icon indicating copy to clipboard operation
chisel copied to clipboard

Provide ChiselEnum Value for OneHot encoding

Open hellow554 opened this issue 8 months ago • 0 comments

Type of issue: Feature Request

Is your feature request related to a problem? Please describe. When describing a normal enum it is relatitly easy to do so:

object MyEnum extends ChiselEnum {
  val A, B, C, D, E, F, G = Value
}

but when trying to have it a one-hot encoding it gets complicated fast

object MyEnum1H extends ChiselEnum {
  val A = Value(1.U)
  val B = Value(2.U)
  val C = Value(4.U)
  // ...
}

It is very error prone and verbose. Moving or reordering the items is also a hell. Maybe there's a clever scala trick to do this easly, but my scala knowlodge is limited.

Describe the solution you'd like I want to see something like one of the two Solutions

object MyEnum1H_A extends ChiselEnum {
  val A, B, C, D = Value1H
}

object MyEnum1H_B extends ChiselEnum {
  val A, B, C, D = Value(flavor = OneHot)
}

Describe alternatives you've considered Describing each and every value seperatly is possible, but error prone and very tedious.

What is the use case for implementing this feature? Using it with a Mux1H is the obvious use-case for this feature.

hellow554 avatar Feb 25 '25 18:02 hellow554