https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121769
Bug ID: 121769
Summary: gcc does not optimize manual bswap
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rockeet at gmail dot com
Target Milestone: ---
long long get_big_endian(const unsigned char* p) {
long long r = 0;
for (int i = 0; i < sizeof(long long); i++)
r |= (long long)(p[i]) << ((sizeof(long long)-1-i)*8);
return r;
}
clang optimize it to bswap, but gcc does not, see
https://godbolt.org/z/Ge7vox1Tc