Skip to content

[Synth] Improve the truth table expansion of > 6 inputs#10420

Merged
uenoku merged 1 commit intollvm:mainfrom
okekayode:dev/expand-truth-table
May 9, 2026
Merged

[Synth] Improve the truth table expansion of > 6 inputs#10420
uenoku merged 1 commit intollvm:mainfrom
okekayode:dev/expand-truth-table

Conversation

@okekayode
Copy link
Copy Markdown
Contributor

@okekayode okekayode commented May 9, 2026

Concerns #10419

We improve the truth table expansion of > 6 inputs by replacing the bit-by-bit implementation ofexpandTruthTableToInputSpaceGeneric with a word-level one. To do so we generate a mask corresponding to the rows that are expanded and set them all at once. This reduces the time complexity from O(2^numExpandedInputs) to O(2^numOrigInputs).

@okekayode okekayode force-pushed the dev/expand-truth-table branch from d15606d to c675b6e Compare May 9, 2026 05:53
Comment thread lib/Support/TruthTable.cpp Outdated
@okekayode okekayode force-pushed the dev/expand-truth-table branch from c675b6e to a650eaa Compare May 9, 2026 06:27
Comment thread lib/Support/TruthTable.cpp Outdated
Comment thread lib/Support/TruthTable.cpp
@uenoku
Copy link
Copy Markdown
Member

uenoku commented May 9, 2026

Fantastic, thanks! I think it would be worth checking the sparsity of the truthtable and flip if necessary. Also can you add a bit more tests for here?

TEST(TruthTableUtilTest, ExpandTruthTableToInputSpaceGenericPath) {
// 3-input parity embedded into inputs [x0, x3, x6].
APInt tt(8, 0b10010110);
SmallVector<unsigned> mapping = {0, 3, 6};
APInt expanded = circt::detail::expandTruthTableToInputSpace(tt, mapping, 7);
APInt expected(128, 0);
for (unsigned expandedIdx = 0; expandedIdx < 128; ++expandedIdx) {
unsigned origIdx = ((expandedIdx >> 0) & 1U) |
(((expandedIdx >> 3) & 1U) << 1) |
(((expandedIdx >> 6) & 1U) << 2);
if (tt[origIdx])
expected.setBit(expandedIdx);
}
EXPECT_EQ(expanded, expected);
}

Also could you make the PR description a bit more verbose? A few sentences would be great!

@okekayode okekayode force-pushed the dev/expand-truth-table branch from a650eaa to 95681a0 Compare May 9, 2026 07:38
@okekayode
Copy link
Copy Markdown
Contributor Author

Fantastic, thanks! I think it would be worth checking the sparsity of the truthtable and flip if necessary. Also can you add a bit more tests for here?

TEST(TruthTableUtilTest, ExpandTruthTableToInputSpaceGenericPath) {
// 3-input parity embedded into inputs [x0, x3, x6].
APInt tt(8, 0b10010110);
SmallVector<unsigned> mapping = {0, 3, 6};
APInt expanded = circt::detail::expandTruthTableToInputSpace(tt, mapping, 7);
APInt expected(128, 0);
for (unsigned expandedIdx = 0; expandedIdx < 128; ++expandedIdx) {
unsigned origIdx = ((expandedIdx >> 0) & 1U) |
(((expandedIdx >> 3) & 1U) << 1) |
(((expandedIdx >> 6) & 1U) << 2);
if (tt[origIdx])
expected.setBit(expandedIdx);
}
EXPECT_EQ(expanded, expected);
}

Also could you make the PR description a bit more verbose? A few sentences would be great!

🫡

Comment thread unittests/Support/TruthTableTest.cpp
@okekayode okekayode force-pushed the dev/expand-truth-table branch from 95681a0 to a0380f3 Compare May 9, 2026 08:19
@okekayode okekayode force-pushed the dev/expand-truth-table branch from a0380f3 to c3e294c Compare May 9, 2026 08:21
@uenoku uenoku merged commit e29ec5f into llvm:main May 9, 2026
6 checks passed
@uenoku
Copy link
Copy Markdown
Member

uenoku commented May 9, 2026

Thanks!

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