LFSR: use random intial value of the start register
We just need to make sure it doesn't initialize randomly stuck at 0.
This commit is contained in:
		| @@ -37,10 +37,11 @@ object LFSR64 | |||||||
|   def apply(increment: Bool = Bool(true)): UInt = |   def apply(increment: Bool = Bool(true)): UInt = | ||||||
|   {  |   {  | ||||||
|     val wide = 64 |     val wide = 64 | ||||||
|     val undef = Reg(UInt(width = wide)) // random value based on simulation seed |     val lfsr = Reg(UInt(width = wide)) // random initial value based on simulation seed | ||||||
|     val lfsr = RegInit(Mux(undef === UInt(0), UInt(1), undef)) |  | ||||||
|     val xor = lfsr(0) ^ lfsr(1) ^ lfsr(3) ^ lfsr(4) |     val xor = lfsr(0) ^ lfsr(1) ^ lfsr(3) ^ lfsr(4) | ||||||
|     when (increment) { lfsr := Cat(xor, lfsr(wide-1,1)) } |     when (increment) { | ||||||
|  |       lfsr := Mux(lfsr === UInt(0), UInt(1), Cat(xor, lfsr(wide-1,1))) | ||||||
|  |     } | ||||||
|     lfsr |     lfsr | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user