https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93328
--- Comment #3 from Paco Arjonilla <pacoarjonilla at yahoo dot es> --- But this gets optimized indeed! #include <cstdint> using type = std::uint32_t; type foo(type v){ type r = ((v << 24) & 0xFF000000) | ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00) | ((v >> 24) & 0x000000FF); return r; } GCC -O2: foo(unsigned int): mov eax, edi bswap eax ret