chisel icon indicating copy to clipboard operation
chisel copied to clipboard

Make BitPat accept ChiselEnum

Open carlosedp opened this issue 3 years ago • 5 comments

Contributor Checklist

  • [x] Did you add Scaladoc to every public function/method?
  • [x] Did you add at least one test demonstrating the PR?
  • [x] Did you delete any extraneous printlns/debugging code?
  • [x] Did you specify the type of improvement?
  • [ ] Did you add appropriate documentation in docs/src?
  • [x] Did you state the API impact?
  • [x] Did you specify the code generation impact?
  • [x] Did you request a desired merge strategy?
  • [x] Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • new feature/API

API Impact

No impact to current API, the PR makes BitPat accept ChiselEnum as input, converting to it's value.

Backend Code Generation Impact

No change.

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference.

Release Notes

BitPat now accept ChiselEnum as an input.

Reviewer Checklist (only modified by reviewer)

  • [ ] Did you add the appropriate labels?
  • [ ] Did you mark the proper milestone (Bug fix: 3.3.x, [small] API extension: 3.4.x, API modification or big change: 3.5.0)?
  • [ ] Did you review?
  • [ ] Did you check whether all relevant Contributor checkboxes have been checked?
  • [ ] Did you mark as Please Merge?

carlosedp avatar Jan 05 '22 17:01 carlosedp

Since apply is already overloaded for UInt, maybe it would make sense to also just overload it for EnumType. This way your example would be even easier to write.

ekiwi avatar Jan 05 '22 17:01 ekiwi

That's neat @ekiwi! Even better... thanks!

carlosedp avatar Jan 05 '22 18:01 carlosedp

If directly cast to UInt, if might have negative influence to circuit PPA, since no mask is used, while actually there is mask for MuxOH, and we cannot ignore it.

Think about another option: what if an API like this?

def apply(x: EnumType*): BitPat = ???

There is a common use case that we need match multiple Enum which a single circuit. For example, we need to use BitPat match s1 and s0 at the same time. if s1 and s0 is OneHot type, we just set correspond bits to 1, while set other bits to 0.

sequencer avatar Jan 10 '22 19:01 sequencer

This is an algorithm problem, if you have multiple encodings, for example, s0 -> 010, s1 -> 110, s2 -> 001. How do you cover one(some) of them with minimal set. It's simple in OneHot(just extract correspond bit). However, for arbitrary user defined encoding, this problem is extended to the set cover problem, which is NP-hard. Luckily, that's the problem, which is already solved by our decoder, you can construct a TruthTable in below:

s0 -> 1
s1 -> 1
s2 -> 0
default -> ?

to match a selection to s0 and s1 The generated circuit should be optimized to minimal circuit to use. In this case, state is always small and we don't wanna this simple function depends on espresso, so you can directly select qmc to handle this job.

sequencer avatar Jan 10 '22 20:01 sequencer

As an aside, I think we might need more documentation on espresso requirements, install instructions and Chisel dependency on it (like what can and can't be made without it).

carlosedp avatar Jan 10 '22 20:01 carlosedp