blob: 9d945ef7fc1d6a7aa12ffbc0837c1aec5f1bb08a [file] [log] [blame]
Fredrik Solenberg500e75b2018-05-23 11:49:01 +02001/*
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 Gu6215ba82020-12-17 22:41:43 -080018// 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 Solenberg500e75b2018-05-23 11:49:01 +020021// 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 Tan4c93aab2019-09-23 17:29:25 -070027#elif defined(_M_ARM64) || defined(__aarch64__)
Fredrik Solenberg500e75b2018-05-23 11:49:01 +020028#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 Gu6215ba82020-12-17 22:41:43 -080036#elif defined(_M_ARM) || defined(__ARMEL__)
Fredrik Solenberg500e75b2018-05-23 11:49:01 +020037#define WEBRTC_ARCH_ARM_FAMILY
38#define WEBRTC_ARCH_32_BITS
39#define WEBRTC_ARCH_LITTLE_ENDIAN
Timothy Gu6215ba82020-12-17 22:41:43 -080040#elif defined(__MIPSEL__) || defined(__MIPSEB__)
Fredrik Solenberg500e75b2018-05-23 11:49:01 +020041#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 Gu6215ba82020-12-17 22:41:43 -080047#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 Solenberg500e75b2018-05-23 11:49:01 +020075#define WEBRTC_ARCH_LITTLE_ENDIAN
Wang Qing842858c2022-09-13 11:27:34 +080076#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 Solenberg500e75b2018-05-23 11:49:01 +020086#elif defined(__pnacl__)
87#define WEBRTC_ARCH_32_BITS
88#define WEBRTC_ARCH_LITTLE_ENDIAN
Mirko Bonadeib028c6a2019-06-18 13:46:42 +020089#elif defined(__EMSCRIPTEN__)
90#define WEBRTC_ARCH_32_BITS
91#define WEBRTC_ARCH_LITTLE_ENDIAN
Fredrik Solenberg500e75b2018-05-23 11:49:01 +020092#else
Mirko Bonadei79976e02019-06-07 09:38:26 +020093#error Please add support for your architecture in rtc_base/system/arch.h
Fredrik Solenberg500e75b2018-05-23 11:49:01 +020094#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_