Skip to content

Conversation

@cdleary
Copy link
Collaborator

@cdleary cdleary commented Jan 3, 2026

From the block comment:

  // Reduction of a value masked by sign_ext(bits[1]) (eliminate mask plumbing).
  //
  // Note on abbreviation in the pattern below:
  //
  // - `w` is the bit-width of the masked datapath value `x` (and thus the
  //   width of the `and(x, mask)`).
  // - `b` is the 1-bit predicate (bits[1]) being sign-extended to a `w`-bit
  //   mask via `sign_ext(b, w)` (all-zeros when b=0, all-ones when b=1).
  //
  // For w > 1, sign_ext(b:bits[1], w) is either 0_w or all_ones_w, so:
  //
  //   or_reduce(and(x, sign_ext(b,w)))  == and(b, or_reduce(x))
  //   and_reduce(and(x, sign_ext(b,w))) == and(b, and_reduce(x))
  //
  // And similarly for the inverted mask not(sign_ext(b,w)).
  //
  // This is always semantics-preserving and strictly reduces mask plumbing for
  // w > 1.

@cdleary cdleary changed the title [opt] Reduction under mask -- signex elimination [opt] Reduction under mask -- sign_ext elimination Jan 3, 2026
@cdleary cdleary force-pushed the cdleary/2026-01-02-signext-mask-elim branch from 255a3bd to ebb32ac Compare January 3, 2026 06:03
@cdleary cdleary marked this pull request as ready for review January 3, 2026 06:58
@cdleary cdleary force-pushed the cdleary/2026-01-02-signext-mask-elim branch from ebb32ac to 83b7122 Compare January 5, 2026 23:44
@scampanoni scampanoni self-assigned this Jan 6, 2026
@scampanoni scampanoni self-requested a review January 8, 2026 13:54
Copy link
Contributor

@scampanoni scampanoni left a comment

Choose a reason for hiding this comment

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

Great addition, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants