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
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.

1 participant