File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed 
core/src/main/scala/chisel3 
src/test/scala/chiselTests Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -279,7 +279,7 @@ abstract class EnumFactory {
279279  protected  def  do_Value (name : String ):  Type  =  {
280280    val  result  =  new  Type 
281281
282-     val  resId  =  if  (! oneHot) id else  BigInt (1  <<  id.toInt) 
282+     val  resId  =  if  (! oneHot) id else  BigInt (1 )  <<  id.toInt
283283
284284    //  We have to use UnknownWidth here, because we don't actually know what the final width will be
285285    result.bindToLiteral(resId, UnknownWidth ())
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package chiselTests
44
55import  chisel3 ._ 
66import  chisel3 .experimental .FixedPoint 
7+ import  chisel3 .experimental .ChiselEnum1H 
78import  chisel3 .internal .ChiselException 
89import  chisel3 .testers .BasicTester 
910import  chisel3 .util .{Mux1H , UIntToOH }
@@ -51,6 +52,9 @@ class OneHotMuxSpec extends AnyFreeSpec with Matchers with ChiselRunners {
5152      })
5253    }
5354  }
55+   " one hot mux with OneHotEnum should work"   in {
56+     assertTesterPasses(new  OneHotEnumMux1HTester )
57+   }
5458
5559}
5660
@@ -304,3 +308,22 @@ class UIntToOHTester extends BasicTester {
304308
305309  stop()
306310}
311+ 
312+ 
313+ class  OneHotEnumMux1HTester  extends  BasicTester  {
314+    object  selector  extends  ChiselEnum1H  {
315+      val  s0, s1, s2, s3  =  Value 
316+    }
317+    val  selectorVal  =  Wire (UInt (selector.getWidth.W ))
318+    selectorVal :=  selector.s1.asUInt
319+    val  hotValue  =  chisel3.util.Mux1H (selectorVal.asUInt,
320+       Seq (
321+        2 .U ,
322+        4 .U ,
323+        8 .U ,
324+        11 .U ,
325+      ))
326+     assert(hotValue ===  4 .U )
327+ 
328+     stop()
329+   }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package chiselTests
44
55import  chisel3 ._ 
66import  chisel3 .experimental .ChiselEnum 
7+ import  chisel3 .experimental .ChiselEnum1H 
78import  chisel3 .internal .firrtl .UnknownWidth 
89import  chisel3 .internal .naming .chiselName 
910import  chisel3 .stage .{ChiselGeneratorAnnotation , ChiselStage }
@@ -513,6 +514,18 @@ class StrongEnumSpec extends ChiselFlatSpec with Utils {
513514  it should " correctly check if the enumeration is one of the values in a given sequence"   in {
514515    assertTesterPasses(new  IsOneOfTester )
515516  }
517+ 
518+   it should " check OneHot enums values"   in {
519+     object  OneHotEnum  extends  ChiselEnum1H  {
520+ 	    val  VAL1, VAL2, VAL3  =  Value 
521+     }
522+ 
523+     var  r  =  1 
524+     for  (enumVal <-  OneHotEnum .all) {
525+       assert(enumVal.litValue ===  r)
526+       r =  r <<  1 
527+     }
528+   }
516529}
517530
518531class  StrongEnumAnnotator  extends  Module  {
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments