1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

AK: Use __builtin_bswap() in NetworkOrdered.

This commit is contained in:
Andreas Kling 2019-06-26 20:01:48 +02:00
parent a2e5b821b4
commit eb129bd730

View file

@ -3,18 +3,16 @@
#include <AK/Types.h> #include <AK/Types.h>
template<typename T> template<typename T>
[[gnu::always_inline]] inline T convert_between_host_and_network(T host_value) [[gnu::always_inline]] inline T convert_between_host_and_network(T value)
{ {
if constexpr (sizeof(T) == 4) { if constexpr (sizeof(T) == 8)
auto* s = (byte*)&host_value; return __builtin_bswap64(value);
return (dword)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); if constexpr (sizeof(T) == 4)
} return __builtin_bswap32(value);
if constexpr (sizeof(T) == 2) { if constexpr (sizeof(T) == 2)
auto* s = (byte*)&host_value; return __builtin_bswap16(value);
return (word)(s[0] << 8 | s[1]);
}
if constexpr (sizeof(T) == 1) if constexpr (sizeof(T) == 1)
return host_value; return value;
} }
template<typename T> template<typename T>