Skip to content

feat: Accounting for Zero-Extensions - #27

Merged
osmanyasar05 merged 1 commit into
mainfrom
zero_extend
Jul 30, 2026
Merged

feat: Accounting for Zero-Extensions#27
osmanyasar05 merged 1 commit into
mainfrom
zero_extend

Conversation

@osmanyasar05

@osmanyasar05 osmanyasar05 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

This PR introduces a new mechanism for accounting for zero extended operands. In addition to the width w of ArithCircuit, we introduce a new variable bits : Nat for ArithCircuit operands, denoting the live bits. Any bit that has a position higher than bits is 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 bits variable.

@osmanyasar05
osmanyasar05 requested a review from cowardsa July 29, 2026 18:10

@cowardsa cowardsa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +112 to +113
-- i3 -> i6 zero extension
def mulZext : ArithCircuit 6 := .mul (.var 0 3) (.var 1 3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm - this is a slightly unconventional choice - here you're implicitly assuming everything is zero-extended - how would we represent sign-extension?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sext is a sequence of three operations (extract msb, replicate bits, concatenate) - so indeed its not convenient

@osmanyasar05

Copy link
Copy Markdown
Collaborator Author

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?

That part happens in bitheapOfVar function. Basically, we create a BitHeap with the new size, but do not add any bit variables to the zero extended positions (or we could add False bits as well, it's the same thing). And then business as usual. This results in not creating any partial products for the zero-extended positions.

@cowardsa

Copy link
Copy Markdown

I'm happy with this approach for now - I think its quite similar to how the BitHeap folks do it as well

@osmanyasar05

Copy link
Copy Markdown
Collaborator Author

cool, I'm merging this now.

I'm happy with this approach for now - I think its quite similar to how the BitHeap folks do it as well

@osmanyasar05
osmanyasar05 merged commit f44ea0f into main Jul 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants