Skip to content

Chisel tips&tricks

erling edited this page Sep 23, 2019 · 7 revisions

DontTouch

To prevent the FIRRTL compiler to optimize your structures away wrap them in dontTouch()'s

Wrap-around inc/dec/add/sub

object WrapInc { // "n" is the number of increments, so we wrap at n-1. def apply(value: UInt, n: Int): UInt = { if (isPow2(n)) { (value + 1.U)(log2Ceil(n)-1,0) } else { val wrap = (value === (n-1).U) Mux(wrap, 0.U, value + 1.U) } } }

Clone this wiki locally