riscv / riscv-bitmanip

Working draft of the proposed RISC-V Bitmanipulation extension
https://jira.riscv.org/browse/RVG-122
Creative Commons Attribution 4.0 International
204 stars 65 forks source link

Is there a instruction to implement bit reverse?? #176

Closed yuyang-ok closed 2 years ago

yuyang-ok commented 2 years ago

or there is a cheap way to implement bit reverse? current now I only can do this using iteration.

topperc commented 2 years ago

You can use the Zbb rev8 from instruction to swap the bytes and then use shifts, ands, and ors to reverse the bits within each byte. https://godbolt.org/z/5onMsrq7r

Or you can use rev8 and brev8 from Zbkb to reverse bytes and bits within bytes. https://godbolt.org/z/5zh6dbjM7

yuyang-ok commented 2 years ago

ok,thanks you.