google / google/xls

Add DSLX optimization tests for is_pow2

Open
#261 0 comments 0 reactions 0 assignees View on GitHub
optimizer
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

The following DSLX cods should be added to xls/tests/dslx_optimization_test. In general, tests in this file verify that a snippet of DSLX code is properly optimized. The test should verify this library function is properly optimized:

pub fn is_pow2(x: uN[N]) -> bool {
x > uN[N]:0 && (x & (x - uN[N]:1) == uN[N]:0)
}

Also add an equivalent implementation:

pub fn is_pow2(x: uN[N]) -> bool {
let shift = clog2(x);
x > uN[N]:0 && ((x >> shift) << shift == x)
}

Ideally I think this should optimize to something like:

one_hot(x, ls_prio=true) == one_hot(x, lsb_prio=false) && x != 0

Not sure what the sequence of transformations that would get us there though.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.