feat: Accounting for Zero-Extensions - #27
Conversation
cowardsa
left a comment
There was a problem hiding this comment.
Not fundamentally opposed but this does make your implementation diverge from comb (and pretty much all other compilers) allowing for different width operands and results.
How would you represent sign-extension here?
I also didn't see how the multiplier implementation has changed to factor in the bitwidth? Namely when the partial products are being constructed?
| -- i3 -> i6 zero extension | ||
| def mulZext : ArithCircuit 6 := .mul (.var 0 3) (.var 1 3) |
There was a problem hiding this comment.
Hmmm - this is a slightly unconventional choice - here you're implicitly assuming everything is zero-extended - how would we represent sign-extension?
There was a problem hiding this comment.
yes, this was implemented only with zero extension in mind. how is signedness expressed in Comb? Afaiu, there is no concept of signedness in Comb.
I imagine we can carry signedness on the var constructor of ArithCircuit. As in:
inductive ArithCircuit : Nat → Type
| var (varIndex : Nat) (sign : Bool) : ArithCircuit w
something along these lines. We should probably think more about this part.
There was a problem hiding this comment.
Sext is a sequence of three operations (extract msb, replicate bits, concatenate) - so indeed its not convenient
That part happens in |
|
I'm happy with this approach for now - I think its quite similar to how the BitHeap folks do it as well |
|
cool, I'm merging this now.
|
This PR introduces a new mechanism for accounting for zero extended operands. In addition to the width
wofArithCircuit, we introduce a new variablebits : NatforArithCircuitoperands, denoting the live bits. Any bit that has a position higher thanbitsis known to be zeros.This makes our synthesis flow suitable for the zero-extended operands that arise in multiplication. Since multiplying two n-bit values produces a 2n-bit result, the convention in CIRCT is to zero-extend the operands by concatenating 0s onto their high bits. Therefore we model zero-extension by keeping track of live bits as a separate property, as Comb dialect does not have a zeroExtend operation but uses the concatenation operation.
This implementation will be handy when connecting our framework to CIRCT. In our verified synthesis pass that we'll implement in CIRCT, we will use MLIR's known-bit analysis to determine the zeros and pass that knowledge to our framework through this newly introduced
bitsvariable.