https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122375
Bug ID: 122375
Summary: gcc does not know bextr ignored high bits
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: rockeet at gmail dot com
Target Milestone: ---
#include <immintrin.h>
long getuint(const char* ptr, unsigned long width, unsigned long i) {
//[[assume(width <= 64)]];
auto offset = (width * i) % 8u;
auto u = *(long*)(ptr + (width * i) / 8u);
return _bextr_u64(u, offset, width);
}
---------------------
_bextr_u64 use bit 8~15 as width and ignore higer bits,
but gcc generate: (https://godbolt.org/z/Pz578K3E8)
---------------------
getuint(char const*, unsigned long, unsigned long):
imul rdx, rsi
sal esi, 8
and esi, 65280 ; This is redundant(without assume)
mov rax, rdx
and edx, 7
shr rax, 3
or rsi, rdx
bextr rax, QWORD PTR [rdi+rax], rsi
ret