WebAssembly / WebAssembly/binaryen
optimise LSBit mask (followed by branch) to use `ctz`
Open
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 69
Description
I have code snippets like
i32.const 1
i32.and
i32.eqz
br_if 1 (;@1;)
which could be optimised to
i32.ctz
br_if 1 (;@1;)
Similar analogous transformations:
i32.const 1; i32.and; i32.eqz; iftoi32.ctz; ifi32.const 1; i32.and; iftoi32.ctz; if(with legs swapped)i32.const 2_147_483_648; i32.and; iftoi32.clz; if(with legs swapped)i32.const 31; i32.shr_u; iftoi32.clz; if(with legs swapped)- possibly 64-bit variants (but here probably instructions for truncation need to be added)
- what about signedness testing? (cmp against 0 -->
clz)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or entry point is named. Start by tracing the optimizer support for i32.and, i32.eqz, branches, ctz, and clz, then assess the listed 32-bit and possible 64-bit patterns; done means implementing agreed transformations with coverage for the applicable cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100