mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-21 09:02:17 +00:00
Add bswap_128()
This greatly helps for IPv6 endianess convertion
This commit is contained in:
parent
f1e83d5240
commit
f466d757ec
3 changed files with 58 additions and 39 deletions
|
@ -45,3 +45,8 @@ uint64_t(bswap_64)(uint64_t x) {
|
|||
(0x00ff000000000000ull & x) >> 050 |
|
||||
(0xff00000000000000ull & x) >> 070;
|
||||
}
|
||||
|
||||
uint128_t(bswap_128)(uint128_t x) {
|
||||
return ((uint128_t)bswap_64((uint64_t)x) << 64) |
|
||||
(uint128_t)bswap_64((uint64_t)(x >> 64));
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@ COSMOPOLITAN_C_START_
|
|||
libcesque uint16_t bswap_16(uint16_t) pureconst;
|
||||
libcesque uint32_t bswap_32(uint32_t) pureconst;
|
||||
libcesque uint64_t bswap_64(uint64_t) pureconst;
|
||||
libcesque uint128_t bswap_128(uint128_t) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#define bswap_16(x) __builtin_bswap16(x)
|
||||
#define bswap_32(x) __builtin_bswap32(x)
|
||||
#define bswap_64(x) __builtin_bswap64(x)
|
||||
#define bswap_128(x) __builtin_bswap128(x)
|
||||
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#define htobe64(x) bswap_64(x)
|
||||
#define be64toh(x) bswap_64(x)
|
||||
#define betoh64(x) bswap_64(x)
|
||||
#define htobe128(x) bswap_128(x)
|
||||
#define be128toh(x) bswap_128(x)
|
||||
#define betoh128(x) bswap_128(x)
|
||||
#define htole16(x) (uint16_t)(x)
|
||||
#define le16toh(x) (uint16_t)(x)
|
||||
#define letoh16(x) (uint16_t)(x)
|
||||
|
@ -26,6 +29,9 @@
|
|||
#define htole64(x) (uint64_t)(x)
|
||||
#define le64toh(x) (uint64_t)(x)
|
||||
#define letoh64(x) (uint64_t)(x)
|
||||
#define htole128(x) (uint128_t)(x)
|
||||
#define le128toh(x) (uint128_t)(x)
|
||||
#define letoh128(x) (uint128_t)(x)
|
||||
#else
|
||||
#define htobe16(x) (uint16_t)(x)
|
||||
#define be16toh(x) (uint16_t)(x)
|
||||
|
@ -36,6 +42,9 @@
|
|||
#define htobe64(x) (uint64_t)(x)
|
||||
#define be64toh(x) (uint64_t)(x)
|
||||
#define betoh64(x) (uint64_t)(x)
|
||||
#define htobe128(x) (uint128_t)(x)
|
||||
#define be128toh(x) (uint128_t)(x)
|
||||
#define betoh128(x) (uint128_t)(x)
|
||||
#define htole16(x) bswap_16(x)
|
||||
#define le16toh(x) bswap_16(x)
|
||||
#define letoh16(x) bswap_16(x)
|
||||
|
@ -45,6 +54,9 @@
|
|||
#define htole64(x) bswap_64(x)
|
||||
#define le64toh(x) bswap_64(x)
|
||||
#define letoh64(x) bswap_64(x)
|
||||
#define htole128(x) bswap_128(x)
|
||||
#define le128toh(x) bswap_128(x)
|
||||
#define letoh128(x) bswap_128(x)
|
||||
#endif
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_NEWBIE_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue