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 |
|
(0x00ff000000000000ull & x) >> 050 |
|
||||||
(0xff00000000000000ull & x) >> 070;
|
(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 uint16_t bswap_16(uint16_t) pureconst;
|
||||||
libcesque uint32_t bswap_32(uint32_t) pureconst;
|
libcesque uint32_t bswap_32(uint32_t) pureconst;
|
||||||
libcesque uint64_t bswap_64(uint64_t) pureconst;
|
libcesque uint64_t bswap_64(uint64_t) pureconst;
|
||||||
|
libcesque uint128_t bswap_128(uint128_t) pureconst;
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||||
#define bswap_16(x) __builtin_bswap16(x)
|
#define bswap_16(x) __builtin_bswap16(x)
|
||||||
#define bswap_32(x) __builtin_bswap32(x)
|
#define bswap_32(x) __builtin_bswap32(x)
|
||||||
#define bswap_64(x) __builtin_bswap64(x)
|
#define bswap_64(x) __builtin_bswap64(x)
|
||||||
|
#define bswap_128(x) __builtin_bswap128(x)
|
||||||
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
|
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -8,43 +8,55 @@
|
||||||
#define PDP_ENDIAN __ORDER_PDP_ENDIAN__
|
#define PDP_ENDIAN __ORDER_PDP_ENDIAN__
|
||||||
|
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
#define htobe16(x) bswap_16(x)
|
#define htobe16(x) bswap_16(x)
|
||||||
#define be16toh(x) bswap_16(x)
|
#define be16toh(x) bswap_16(x)
|
||||||
#define betoh16(x) bswap_16(x)
|
#define betoh16(x) bswap_16(x)
|
||||||
#define htobe32(x) bswap_32(x)
|
#define htobe32(x) bswap_32(x)
|
||||||
#define be32toh(x) bswap_32(x)
|
#define be32toh(x) bswap_32(x)
|
||||||
#define betoh32(x) bswap_32(x)
|
#define betoh32(x) bswap_32(x)
|
||||||
#define htobe64(x) bswap_64(x)
|
#define htobe64(x) bswap_64(x)
|
||||||
#define be64toh(x) bswap_64(x)
|
#define be64toh(x) bswap_64(x)
|
||||||
#define betoh64(x) bswap_64(x)
|
#define betoh64(x) bswap_64(x)
|
||||||
#define htole16(x) (uint16_t)(x)
|
#define htobe128(x) bswap_128(x)
|
||||||
#define le16toh(x) (uint16_t)(x)
|
#define be128toh(x) bswap_128(x)
|
||||||
#define letoh16(x) (uint16_t)(x)
|
#define betoh128(x) bswap_128(x)
|
||||||
#define htole32(x) (uint32_t)(x)
|
#define htole16(x) (uint16_t)(x)
|
||||||
#define le32toh(x) (uint32_t)(x)
|
#define le16toh(x) (uint16_t)(x)
|
||||||
#define letoh32(x) (uint32_t)(x)
|
#define letoh16(x) (uint16_t)(x)
|
||||||
#define htole64(x) (uint64_t)(x)
|
#define htole32(x) (uint32_t)(x)
|
||||||
#define le64toh(x) (uint64_t)(x)
|
#define le32toh(x) (uint32_t)(x)
|
||||||
#define letoh64(x) (uint64_t)(x)
|
#define letoh32(x) (uint32_t)(x)
|
||||||
|
#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
|
#else
|
||||||
#define htobe16(x) (uint16_t)(x)
|
#define htobe16(x) (uint16_t)(x)
|
||||||
#define be16toh(x) (uint16_t)(x)
|
#define be16toh(x) (uint16_t)(x)
|
||||||
#define betoh16(x) (uint16_t)(x)
|
#define betoh16(x) (uint16_t)(x)
|
||||||
#define htobe32(x) (uint32_t)(x)
|
#define htobe32(x) (uint32_t)(x)
|
||||||
#define be32toh(x) (uint32_t)(x)
|
#define be32toh(x) (uint32_t)(x)
|
||||||
#define betoh32(x) (uint32_t)(x)
|
#define betoh32(x) (uint32_t)(x)
|
||||||
#define htobe64(x) (uint64_t)(x)
|
#define htobe64(x) (uint64_t)(x)
|
||||||
#define be64toh(x) (uint64_t)(x)
|
#define be64toh(x) (uint64_t)(x)
|
||||||
#define betoh64(x) (uint64_t)(x)
|
#define betoh64(x) (uint64_t)(x)
|
||||||
#define htole16(x) bswap_16(x)
|
#define htobe128(x) (uint128_t)(x)
|
||||||
#define le16toh(x) bswap_16(x)
|
#define be128toh(x) (uint128_t)(x)
|
||||||
#define letoh16(x) bswap_16(x)
|
#define betoh128(x) (uint128_t)(x)
|
||||||
#define htole32(x) bswap_32(x)
|
#define htole16(x) bswap_16(x)
|
||||||
#define le32toh(x) bswap_32(x)
|
#define le16toh(x) bswap_16(x)
|
||||||
#define letoh32(x) bswap_32(x)
|
#define letoh16(x) bswap_16(x)
|
||||||
#define htole64(x) bswap_64(x)
|
#define htole32(x) bswap_32(x)
|
||||||
#define le64toh(x) bswap_64(x)
|
#define le32toh(x) bswap_32(x)
|
||||||
#define letoh64(x) bswap_64(x)
|
#define letoh32(x) bswap_32(x)
|
||||||
|
#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
|
||||||
|
|
||||||
#endif /* COSMOPOLITAN_LIBC_BITS_NEWBIE_H_ */
|
#endif /* COSMOPOLITAN_LIBC_BITS_NEWBIE_H_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue