brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 52d95dc Raw
51 lines · c
1//===-- Definition of macros from endian.h --------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_MACROS_ENDIAN_MACROS_H10#define LLVM_LIBC_MACROS_ENDIAN_MACROS_H11 12#include "stdint-macros.h"13 14#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__15#define BIG_ENDIAN __ORDER_BIG_ENDIAN__16#define BYTE_ORDER __BYTE_ORDER__17 18#if BYTE_ORDER == LITTLE_ENDIAN19 20#define htobe16(x) __builtin_bswap16((x))21#define htobe32(x) __builtin_bswap32((x))22#define htobe64(x) __builtin_bswap64((x))23#define htole16(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x)24#define htole32(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x)25#define htole64(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x)26#define be16toh(x) __builtin_bswap16((x))27#define be32toh(x) __builtin_bswap32((x))28#define be64toh(x) __builtin_bswap64((x))29#define le16toh(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x)30#define le32toh(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x)31#define le64toh(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x)32 33#else34 35#define htobe16(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x)36#define htobe32(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x)37#define htobe64(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x)38#define htole16(x) __builtin_bswap16((x))39#define htole32(x) __builtin_bswap32((x))40#define htole64(x) __builtin_bswap64((x))41#define be16toh(x) __LLVM_LIBC_CAST(static_cast, uint16_t, x)42#define be32toh(x) __LLVM_LIBC_CAST(static_cast, uint32_t, x)43#define be64toh(x) __LLVM_LIBC_CAST(static_cast, uint64_t, x)44#define le16toh(x) __builtin_bswap16((x))45#define le32toh(x) __builtin_bswap32((x))46#define le64toh(x) __builtin_bswap64((x))47 48#endif49 50#endif // LLVM_LIBC_MACROS_ENDIAN_MACROS_H51