It would be useful if gcc provided a builtin to reverse the order of the bits (turn abcdefgh into hgfedcba) in objects of all sizes from a byte to an unsigned long long. According to Joseph: "Various processors have an instruction to reverse the bit order in a word (ARMv6T2 and later have RBIT, for example, and C6X has BITR on C64X and above)." This kind of bit manipulation also has various optimizations depending on the architecture (mirroring a byte can be implemented using a 64bit multiplication). It is thus well suited to a builtin with different platform-specific implementations. Such a builtin could be used for instance for Bug 50160.
Informative web-page listing some methods: http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv
I totally don't understand what you talking about =_= http://www.buyanessay.com/
Bump! Proper intrinsics for bitreverse would be much appreciated! A plain C implementation is ugly and results in equally awful code output, while using inline asm breaks portability and can't be constant-folded or used in constexpr. What makes the continued lack of a __builtin_arm_rbit() in gcc a bit bizarre is that the (identically named) Neon versions of this instruction on AArch64 actually *did* receive proper intrinsics! [1] It's worth mentioning that clang does support __builtin_arm_rbit(), and they've actually generalized this to a full set of target-independent bitreverse builtins [2]. [1] https://gcc.gnu.org/ml/gcc-patches/2014-08/msg01913.html [2] http://clang.llvm.org/docs/LanguageExtensions.html#builtin-bitreverse
+1 The builtins already produce better code than a generic bitreverse implementation: https://godbolt.org/z/Um2Tit But using special hardware instructions automatically is even more important imho.
Yes it would be good to have a generic builtin, this issue keeps coming up: https://gcc.gnu.org/ml/gcc-patches/2019-06/msg01187.html
As noted in the RISC-V BoF today, this would also be useful for the RISC-V bit-manipulation extension.
Would be really useful to have this.
Bump - I need this too ;)
Useful for LoongArch too. And now we already have bitreverse RTX code since r14-1586.
I am going to implement this. and add an optab too.
The builtins I am going to implement to be similar to clang: __builtin_bitreverse{8,16,32,64,g} The g one is not part of clang but will be used for _BitInt types.
Also will add an internal function which will be used for vectorization.