Skip to content

Conversation

@uenoku
Copy link
Member

@uenoku uenoku commented Sep 2, 2025

Towards #8786, this commit introduces a new MajorityInverterOp operation to represent majority-inverter gates in Majority-Inverter Graphs (MIG) for synthesis (https://ieeexplore.ieee.org/document/7293649). Majority-Inverter Graphs have become a prominent representation for logic synthesis in recent years, offering advantages in certain optimization scenarios alongside And-Inverter Graphs (AIG).

The implementation provides a synth.mig.maj_inv operation that computes the majority function of its inputs with optional inversion per operand. The operation requires an odd number of operands to avoid ties in majority computation and uses a custom assembly format with 'not' keyword prefix for inverted inputs.

The majority function returns 1 when more than half of the inputs are 1. For three inputs, it's equivalent to: (a & b) | (a & c) | (b & c).

This addition aligns with the goal of making the circt-synth pipeline handle both AIG and MIG representations seamlessly, providing flexibility in choosing the most appropriate intermediate representation (or mix them). Also MIG can represent and/or/carry in a single depth (and-inverter takes 2 depth for or/carry) so would be slightly accurate metric as logic depth.

Example usage:

  %r1 = synth.mig.maj_inv %a, %b, %c : i1
  %r2 = synth.mig.maj_inv not %a, %b, not %c : i1

This commit introduces a new MajorityInverterOp operation to represent
majority-inverter gates in Majority-Inverter Graphs (MIG) for synthesis.
Majority-Inverter Graphs have become a prominent representation for logic
synthesis in recent years, offering advantages in certain optimization
scenarios alongside traditional And-Inverter Graphs (AIG).

The implementation provides a synth.mig.maj_inv operation that computes the
majority function of its inputs with optional inversion per operand. The
operation requires an odd number of operands to avoid ties in majority
computation and uses a custom assembly format with 'not' keyword prefix
for inverted inputs. Comprehensive verification and error handling ensure
correctness, while shared custom directives enable consistent parsing and
printing of invertible operands across both MIG and AIG operations.

The majority function returns 1 when more than half of the inputs are 1.
For three inputs, it's equivalent to: (a & b) | (a & c) | (b & c).

This addition aligns with the goal of making the circt-synth pipeline
handle both AIG and MIG representations seamlessly, providing flexibility
in choosing the most appropriate intermediate representation for different
synthesis tasks.

Example usage:
  %r1 = synth.mig.maj_inv %a, %b, %c : i1
  %r2 = synth.mig.maj_inv not %a, %b, not %c : i1
@uenoku uenoku force-pushed the dev/hidetou/maj-inv branch from cd12a6a to 25f74f5 Compare September 2, 2025 09:55
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

Very cool!

Comment on lines +59 to +61
let assemblyFormat = [{
custom<VariadicInvertibleOperands>($inputs, type($result), $inverted, attr-dict)
}];
Copy link
Contributor

Choose a reason for hiding this comment

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

Very cool! Love the use of custom here 🙌

@uenoku uenoku merged commit 2f05f7a into main Sep 2, 2025
7 checks passed
@uenoku uenoku deleted the dev/hidetou/maj-inv branch September 2, 2025 18:22
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.

3 participants