Skip to content

Conversation

@cdleary
Copy link
Collaborator

@cdleary cdleary commented Jan 24, 2026

Note the "ZeroExtendedBitsView" in this change seems useful until we come to stronger conclusions on canonical forms (i.e. zero_ext I think should be more canonical than concat as it's a more precise operator, but wouldn't want to make that a prereq).

  • Match: bit_slice(add(zext(v), k), start=N, width=1) (carry-out of v + k).
  • Rewrite: bit_slice(...) becomes (k[N] ? ult(v, (2^N - (k mod 2^N))) : uge(v, (2^N - (k mod 2^N)))) (and if (k mod 2^N) == 0, becomes literal(k[N])).

before:

$ bazel-bin/xls/tools/opt_main ~/missed_cone.ir 
package cone

top fn cone(leaf_193: bits[8] id=1, leaf_237: bits[1] id=2, leaf_466: bits[1] id=3) -> bits[1] {
  literal.4: bits[1] = literal(value=0, id=4)
  not.6: bits[8] = not(leaf_193, id=6)
  concat.7: bits[9] = concat(literal.4, not.6, id=7)
  literal.8: bits[9] = literal(value=127, id=8)
  add.9: bits[9] = add(concat.7, literal.8, id=9)
  literal.5: bits[8] = literal(value=255, id=5)
  bit_slice.10: bits[1] = bit_slice(add.9, start=8, width=1, id=10)
  eq.20: bits[1] = eq(leaf_193, literal.5, id=20)
  not.13: bits[1] = not(leaf_237, id=13)
  ret and.30: bits[1] = and(bit_slice.10, eq.20, leaf_466, not.13, id=30)
}

which is:

$ ~/proj/xlsynth-crate/target/release/xlsynth-driver ir2gates ~/missed_cone.ir --quiet true
{"live_nodes":28,"deepest_path":7,...}

after:

$ bazel-bin/xls/tools/opt_main ~/missed_cone.ir 
package cone

top fn cone(leaf_193: bits[8] id=1, leaf_237: bits[1] id=2, leaf_466: bits[1] id=3) -> bits[1] {
  ret literal.35: bits[1] = literal(value=0, id=35)
}

@cdleary cdleary requested a review from meheff January 24, 2026 22:38
@cdleary cdleary force-pushed the cdleary/2026-01-24-simplify-carry-extract branch from cd10c2e to 8c2d439 Compare January 24, 2026 23:00
@cdleary cdleary force-pushed the cdleary/2026-01-24-simplify-carry-extract branch from 26418bf to 0f31205 Compare January 25, 2026 18:09
@cdleary cdleary marked this pull request as ready for review January 25, 2026 18:10
@cdleary cdleary requested a review from allight January 25, 2026 19:24
@cdleary cdleary force-pushed the cdleary/2026-01-24-simplify-carry-extract branch from 0f31205 to 1f881c4 Compare January 27, 2026 05:15
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