Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit reversing instructions #1382

Open
MaxGraey opened this issue Sep 27, 2020 · 7 comments
Open

Bit reversing instructions #1382

MaxGraey opened this issue Sep 27, 2020 · 7 comments
Labels

Comments

@MaxGraey
Copy link

MaxGraey commented Sep 27, 2020

Future features mentioned a nice set for instruction set future improvements. For example bswap and bswap16 but missing bireverse/bitrev/rbit operations which I think quite important due to it could be useful for wide range of compression algorithms, Cooley–Tukey's FFT, FHT, dyadic rational numbers and etc.

Clang has builtins for that:
__builtin_bitreverse8
__builtin_bitreverse16
__builtin_bitreverse32
__builtin_bitreverse64

which quite useful due to implement bit reversing is quite challenging and some architectures like ARM64 could be lowered to single instruction RBIT.

So it would be interesting to hear your opinion on whether to add bitrev to post-MVP?

Proposed unary instructions:

i32.bitrev8
i32.bitrev16
i32.bitrev
i64.bitrev

Implementation details for runtimes

For x64 / ARMv7 / RISCV / MIPS / POWER and etc:

  • i32.bitrev8:
    one read from 8-bit lookup table
  • i32.bitrev16:
    two reads from 8-bit lookup table
  • i32.bitrev:
    four reads from 8-bit lookup table
  • i64.bitrev:
    use Knuth's method from Hacker's delight or 8 lookups if it faster on target architecture.

For more modern x64 architecture like Zen3 and Skylake bit reversing could be implemented via PDEP / PEXT instructions.

For ARM64:

  • i32.bitrev8:
    rbit w1, w0
    lsr  w0, w1, #24
  • i32.bitrev16:
    rbit w1, w0
    lsr  w0, w1, #16
  • i32.bitrev:
    rbit w0, w1
  • i64.bitrev:
    rbit x0, x1
@KloudKoder
Copy link

I second this. SHR, SHR, AND, and BSWAP will be of help on the X86 implementation. Bit reversal is really useful, but really expensive in the absence of a competent primitive.

@MaxGraey MaxGraey changed the title [post-MVP proposal] Bit reversing instructions for i32 and i64 [post-MVP proposal] Bit reversing instructions Oct 11, 2020
@KloudKoder
Copy link

KloudKoder commented Apr 23, 2021

@MaxGraey Are you still there? Perhaps we should propose a discussion of this at a future community group meeting.

Related: register exchange instructions. Let's double check that these are already well supported.

@MaxGraey
Copy link
Author

Perhaps we should propose a discussion of this at a future community group meeting.

That's will be great.

@KloudKoder
Copy link

@MaxGraey Cool, care to pick a date? Ideally one with little or nothing already slated for discussion.

https://github.com/WebAssembly/meetings/tree/master/main/2021

@MaxGraey
Copy link
Author

If you have the opportunity, could you take it upon yourself? In the near future, I will be too busy to participate in meeting calls and try to propose this to WG as post-MVP op codes.

@KloudKoder
Copy link

@MaxGraey I'll see what I can do. It would be after May 11.

@sirus20x6
Copy link

which may 11th? ;)

@sunfishcode sunfishcode changed the title [post-MVP proposal] Bit reversing instructions Bit reversing instructions Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants