| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <generated/autoconf.h> |
| 6 | |
| 7 | #define MOS_DO_PRAGMA(x) _Pragma(#x) |
| 8 | |
| 9 | #if defined(__clang__) |
| 10 | #define MOS_COMPILER_CLANG 1 |
| 11 | #define MOS_PRAGMA(text) MOS_DO_PRAGMA(clang text) |
| 12 | #elif defined(__GNUC__) |
| 13 | #define MOS_COMPILER_GCC 1 |
| 14 | #define MOS_PRAGMA(text) MOS_DO_PRAGMA(GCC text) |
| 15 | #endif |
| 16 | |
| 17 | #if MOS_COMPILER_GCC && __GNUC__ < 12 |
| 18 | #define MOS_FILE_LOCATION __FILE__ ":" MOS_STRINGIFY(__LINE__) |
| 19 | #else |
| 20 | #define MOS_FILE_LOCATION __FILE_NAME__ ":" MOS_STRINGIFY(__LINE__) |
| 21 | #endif |
| 22 | |
| 23 | // * BEGIN find out if the compiler is big or little endian |
| 24 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 25 | #define MOS_BIG_ENDIAN 1 |
| 26 | |
| 27 | #define cpu_to_be16(x) (x) |
| 28 | #define cpu_to_be32(x) (x) |
| 29 | #define cpu_to_be64(x) (x) |
| 30 | |
| 31 | #define be16_to_cpu(x) (x) |
| 32 | #define be32_to_cpu(x) (x) |
| 33 | #define be64_to_cpu(x) (x) |
| 34 | |
| 35 | #define cpu_to_le16(x) __builtin_bswap16(x) |
| 36 | #define cpu_to_le32(x) __builtin_bswap32(x) |
| 37 | #define cpu_to_le64(x) __builtin_bswap64(x) |
| 38 | |
| 39 | #define le16_to_cpu(x) __builtin_bswap32(x) |
| 40 | #define le32_to_cpu(x) __builtin_bswap16(x) |
| 41 | #define le64_to_cpu(x) __builtin_bswap64(x) |
| 42 | #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 43 | #define MOS_LITTLE_ENDIAN 1 |
| 44 | |
| 45 | #define cpu_to_be16(x) __builtin_bswap16(x) |
| 46 | #define cpu_to_be32(x) __builtin_bswap32(x) |
| 47 | #define cpu_to_be64(x) __builtin_bswap64(x) |
| 48 | |
| 49 | #define be16_to_cpu(x) __builtin_bswap16(x) |
| 50 | #define be32_to_cpu(x) __builtin_bswap32(x) |
| 51 | #define be64_to_cpu(x) __builtin_bswap64(x) |
| 52 | |
| 53 | #define cpu_to_le16(x) (x) |
| 54 | #define cpu_to_le32(x) (x) |
| 55 | #define cpu_to_le64(x) (x) |
| 56 | |
| 57 | #define le16_to_cpu(x) (x) |
| 58 | #define le32_to_cpu(x) (x) |
| 59 | #define le64_to_cpu(x) (x) |
| 60 | #endif |
| 61 | |
| 62 | #if !defined(MOS_BIG_ENDIAN) && !defined(MOS_LITTLE_ENDIAN) |
| 63 | #error "Unknown endianness" |
| 64 | #endif |
| 65 | // * END find out if the compiler is big or little endian |
| 66 | |
| 67 | // * BEGIN determine the code model |
| 68 | #if defined(__LP64__) |
| 69 | #define MOS_LP64 1 // sizeof(long) == sizeof(void *) == 8 |
| 70 | #else |
| 71 | #error "Unknown code model" |
| 72 | #endif |
| 73 | // * END determine the code model |
| 74 | |