https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50481
--- Comment #28 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:c0fd049ae75349dc273de868fd3b3e8935115418 commit r17-563-gc0fd049ae75349dc273de868fd3b3e8935115418 Author: Jakub Jelinek <[email protected]> Date: Mon May 18 09:41:59 2026 +0200 i386: Implement bitreverse<mode>2 optab for GFNI [PR50481] The following patch implements the bitreverse<mode>2 optab for -mgfni -msse2 (SSE2 because apparently -mgfni doesn't imply -msse nor -msse2). This is done by using gf2p8affineqb insn with a special constant which reverses bits in each byte, and for modes wider than QImode also by doing a byteswap afterwards. With -m64 it emits .LC0: .byte 1, 2, 4, 8, 16, 32, 64, -128 .byte 1, 2, 4, 8, 16, 32, 64, -128 and movd %edi, %xmm0 gf2p8affineqb $0, .LC0(%rip), %xmm0 movd %xmm0, %eax for __builtin_bitreverse8, movd %edi, %xmm0 gf2p8affineqb $0, .LC0(%rip), %xmm0 movd %xmm0, %eax rolw $8, %ax for __builtin_bitreverse16, movd %edi, %xmm0 gf2p8affineqb $0, .LC0(%rip), %xmm0 movd %xmm0, %eax bswap %eax for __builtin_bitreverse32, movq %rdi, %xmm0 gf2p8affineqb $0, .LC0(%rip), %xmm0 movq %xmm0, %rax bswap %rax for __builtin_bitreverse64, and movq %rdi, %xmm0 pinsrq $1, %rsi, %xmm0 gf2p8affineqb $0, .LC0(%rip), %xmm0 movq %xmm0, %rax pextrq $1, %xmm0, %rdx bswap %rax bswap %rdx xchgq %rdx, %rax for __builtin_bitreverse128 (only the xchgq is unnecessary and surprising, some RA issue). 2026-05-18 Jakub Jelinek <[email protected]> PR target/50481 * config/i386/i386-protos.h (ix86_expand_gfni_bitreverse): Declare. * config/i386/i386-expand.cc (ix86_expand_gfni_bitreverse): New function. * config/i386/i386.md (bitreverse<mode>2): New expander. * gcc.target/i386/gfni-builtin-bitreverse-1.c: New test. Reviewed-by: Hongtao Liu <[email protected]>
