Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This file contains platform-specific typedefs and defines. |
| 12 | // Much of it is derived from Chromium's build/build_config.h. |
| 13 | |
| 14 | #ifndef RTC_BASE_SYSTEM_ARCH_H_ |
| 15 | #define RTC_BASE_SYSTEM_ARCH_H_ |
| 16 | |
| 17 | // Processor architecture detection. For more info on what's defined, see: |
Timothy Gu | 6215ba8 | 2020-12-17 22:41:43 -0800 | [diff] [blame] | 18 | // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros |
| 19 | // https://www.agner.org/optimize/calling_conventions.pdf |
| 20 | // https://sourceforge.net/p/predef/wiki/Architectures/ |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 21 | // or with gcc, run: "echo | gcc -E -dM -" |
| 22 | #if defined(_M_X64) || defined(__x86_64__) |
| 23 | #define WEBRTC_ARCH_X86_FAMILY |
| 24 | #define WEBRTC_ARCH_X86_64 |
| 25 | #define WEBRTC_ARCH_64_BITS |
| 26 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Tom Tan | 4c93aab | 2019-09-23 17:29:25 -0700 | [diff] [blame] | 27 | #elif defined(_M_ARM64) || defined(__aarch64__) |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 28 | #define WEBRTC_ARCH_ARM_FAMILY |
| 29 | #define WEBRTC_ARCH_64_BITS |
| 30 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
| 31 | #elif defined(_M_IX86) || defined(__i386__) |
| 32 | #define WEBRTC_ARCH_X86_FAMILY |
| 33 | #define WEBRTC_ARCH_X86 |
| 34 | #define WEBRTC_ARCH_32_BITS |
| 35 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Timothy Gu | 6215ba8 | 2020-12-17 22:41:43 -0800 | [diff] [blame] | 36 | #elif defined(_M_ARM) || defined(__ARMEL__) |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 37 | #define WEBRTC_ARCH_ARM_FAMILY |
| 38 | #define WEBRTC_ARCH_32_BITS |
| 39 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Timothy Gu | 6215ba8 | 2020-12-17 22:41:43 -0800 | [diff] [blame] | 40 | #elif defined(__MIPSEL__) || defined(__MIPSEB__) |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 41 | #define WEBRTC_ARCH_MIPS_FAMILY |
| 42 | #if defined(__LP64__) |
| 43 | #define WEBRTC_ARCH_64_BITS |
| 44 | #else |
| 45 | #define WEBRTC_ARCH_32_BITS |
| 46 | #endif |
Timothy Gu | 6215ba8 | 2020-12-17 22:41:43 -0800 | [diff] [blame] | 47 | #if defined(__MIPSEL__) |
| 48 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
| 49 | #else |
| 50 | #define WEBRTC_ARCH_BIG_ENDIAN |
| 51 | #endif |
| 52 | #elif defined(__PPC__) |
| 53 | #if defined(__PPC64__) |
| 54 | #define WEBRTC_ARCH_64_BITS |
| 55 | #else |
| 56 | #define WEBRTC_ARCH_32_BITS |
| 57 | #endif |
| 58 | #if defined(__LITTLE_ENDIAN__) |
| 59 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
| 60 | #else |
| 61 | #define WEBRTC_ARCH_BIG_ENDIAN |
| 62 | #endif |
| 63 | #elif defined(__sparc) || defined(__sparc__) |
| 64 | #if __SIZEOF_LONG__ == 8 |
| 65 | #define WEBRTC_ARCH_64_BITS |
| 66 | #else |
| 67 | #define WEBRTC_ARCH_32_BITS |
| 68 | #endif |
| 69 | #define WEBRTC_ARCH_BIG_ENDIAN |
| 70 | #elif defined(__riscv) && __riscv_xlen == 64 |
| 71 | #define WEBRTC_ARCH_64_BITS |
| 72 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
| 73 | #elif defined(__riscv) && __riscv_xlen == 32 |
| 74 | #define WEBRTC_ARCH_32_BITS |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 75 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Wang Qing | 842858c | 2022-09-13 11:27:34 +0800 | [diff] [blame] | 76 | #elif defined(__loongarch32) |
| 77 | #define WEBRTC_ARCH_LOONG_FAMILY |
| 78 | #define WEBRTC_ARCH_LOONG32 |
| 79 | #define WEBRTC_ARCH_32_BITS |
| 80 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
| 81 | #elif defined(__loongarch64) |
| 82 | #define WEBRTC_ARCH_LOONG_FAMILY |
| 83 | #define WEBRTC_ARCH_LOONG64 |
| 84 | #define WEBRTC_ARCH_64_BITS |
| 85 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 86 | #elif defined(__pnacl__) |
| 87 | #define WEBRTC_ARCH_32_BITS |
| 88 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Mirko Bonadei | b028c6a | 2019-06-18 13:46:42 +0200 | [diff] [blame] | 89 | #elif defined(__EMSCRIPTEN__) |
| 90 | #define WEBRTC_ARCH_32_BITS |
| 91 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 92 | #else |
Mirko Bonadei | 79976e0 | 2019-06-07 09:38:26 +0200 | [diff] [blame] | 93 | #error Please add support for your architecture in rtc_base/system/arch.h |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | #if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN)) |
| 97 | #error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN |
| 98 | #endif |
| 99 | |
| 100 | #endif // RTC_BASE_SYSTEM_ARCH_H_ |