Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qprocessordetection.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#if 0
8#pragma qt_class(QtProcessorDetection)
9#pragma qt_sync_skip_header_check
10#pragma qt_sync_stop_processing
11#endif
12
13#ifndef QPROCESSORDETECTION_H
14#define QPROCESSORDETECTION_H
15
16/*
17 This file uses preprocessor #defines to set various Q_PROCESSOR_* #defines
18 based on the following patterns:
19
20 Q_PROCESSOR_{FAMILY}
21 Q_PROCESSOR_{FAMILY}_{VARIANT}
22 Q_PROCESSOR_{FAMILY}_{REVISION}
23
24 The first is always defined. Defines for the various revisions/variants are
25 optional and usually dependent on how the compiler was invoked. Variants
26 that are a superset of another should have a define for the superset.
27
28 In addition to the processor family, variants, and revisions, we also set
29 Q_BYTE_ORDER appropriately for the target processor. For bi-endian
30 processors, we try to auto-detect the byte order using the __BIG_ENDIAN__,
31 __LITTLE_ENDIAN__, or __BYTE_ORDER__ preprocessor macros.
32
33 Note: when adding support for new processors, be sure to update
34 config.tests/arch/arch.cpp to ensure that configure can detect the target
35 and host architectures.
36*/
37
38/* Machine byte-order, reuse preprocessor provided macros when available */
39#if defined(__ORDER_BIG_ENDIAN__)
40# define Q_BIG_ENDIAN __ORDER_BIG_ENDIAN__
41#else
42# define Q_BIG_ENDIAN 4321
43#endif
44#if defined(__ORDER_LITTLE_ENDIAN__)
45# define Q_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
46#else
47# define Q_LITTLE_ENDIAN 1234
48#endif
49
50/*
51 Alpha family, no revisions or variants
52
53 Alpha is bi-endian, use endianness auto-detection implemented below.
54*/
55#if defined(__alpha__) || defined(_M_ALPHA)
56# define Q_PROCESSOR_ALPHA
57// Q_BYTE_ORDER not defined, use endianness auto-detection
58
59/*
60 ARM family, known revisions: V5, V6, V7, V8
61
62 ARM is bi-endian, detect using __ARMEL__ or __ARMEB__, falling back to
63 auto-detection implemented below.
64*/
65#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__) || defined(_ARM64EC_)
66# if defined(__aarch64__) || defined(__ARM64__) || defined(_M_ARM64) || defined(_ARM64EC_)
67# define Q_PROCESSOR_ARM_64
68# define Q_PROCESSOR_WORDSIZE 8
69# else
70# define Q_PROCESSOR_ARM_32
71# endif
72# if defined(__ARM_ARCH) && __ARM_ARCH > 1
73# define Q_PROCESSOR_ARM __ARM_ARCH
74# elif defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM > 1
75# define Q_PROCESSOR_ARM __TARGET_ARCH_ARM
76# elif defined(_M_ARM) && _M_ARM > 1
77# define Q_PROCESSOR_ARM _M_ARM
78# elif defined(__ARM64_ARCH_8__)
79 || defined(__aarch64__)
80 || defined(__ARMv8__)
81 || defined(__ARMv8_A__)
82 || defined(_M_ARM64)
83 || defined (_ARM64EC_)
84# define Q_PROCESSOR_ARM 8
85# elif defined(__ARM_ARCH_7__)
86 || defined(__ARM_ARCH_7A__)
87 || defined(__ARM_ARCH_7R__)
88 || defined(__ARM_ARCH_7M__)
89 || defined(__ARM_ARCH_7S__)
90 || defined(_ARM_ARCH_7)
91 || defined(__CORE_CORTEXA__)
92# define Q_PROCESSOR_ARM 7
93# elif defined(__ARM_ARCH_6__)
94 || defined(__ARM_ARCH_6J__)
95 || defined(__ARM_ARCH_6T2__)
96 || defined(__ARM_ARCH_6Z__)
97 || defined(__ARM_ARCH_6K__)
98 || defined(__ARM_ARCH_6ZK__)
99 || defined(__ARM_ARCH_6M__)
100# define Q_PROCESSOR_ARM 6
101# elif defined(__ARM_ARCH_5TEJ__)
102 || defined(__ARM_ARCH_5TE__)
103# define Q_PROCESSOR_ARM 5
104# else
105# define Q_PROCESSOR_ARM 0
106# endif
107# if Q_PROCESSOR_ARM >= 8
108# define Q_PROCESSOR_ARM_V8
109# endif
110# if Q_PROCESSOR_ARM >= 7
111# define Q_PROCESSOR_ARM_V7
112# endif
113# if Q_PROCESSOR_ARM >= 6
114# define Q_PROCESSOR_ARM_V6
115# endif
116# if Q_PROCESSOR_ARM >= 5
117# define Q_PROCESSOR_ARM_V5
118# else
119# error "ARM architecture too old"
120# endif
121# if defined(_ARM64EC_)
122# define Q_PROCESSOR_ARM_64_EC
123# endif
124# if defined(__ARMEL__) || defined(_M_ARM64) || defined(_ARM64EC_)
125# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
126# elif defined(__ARMEB__)
127# define Q_BYTE_ORDER Q_BIG_ENDIAN
128# else
129// Q_BYTE_ORDER not defined, use endianness auto-detection
130#endif
131
132/*
133 AVR32 family, no revisions or variants
134
135 AVR32 is big-endian.
136*/
137// #elif defined(__avr32__)
138// # define Q_PROCESSOR_AVR32
139// # define Q_BYTE_ORDER Q_BIG_ENDIAN
140
141/*
142 Blackfin family, no revisions or variants
143
144 Blackfin is little-endian.
145*/
146// #elif defined(__bfin__)
147// # define Q_PROCESSOR_BLACKFIN
148// # define Q_BYTE_ORDER Q_LITTLE_ENDIAN
149
150/*
151 PA-RISC family, no revisions or variants
152
153 PA-RISC is big-endian.
154*/
155#elif defined(__hppa__)
156# define Q_PROCESSOR_HPPA
157# define Q_BYTE_ORDER Q_BIG_ENDIAN
158
159/*
160 X86 family, known variants: 32- and 64-bit
161
162 X86 is little-endian.
163*/
164#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
165# define Q_PROCESSOR_X86_32
166# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
167# define Q_PROCESSOR_WORDSIZE 4
168
169/*
170 * We define Q_PROCESSOR_X86 == 6 for anything above a equivalent or better
171 * than a Pentium Pro (the processor whose architecture was called P6) or an
172 * Athlon.
173 *
174 * All processors since the Pentium III and the Athlon 4 have SSE support, so
175 * we use that to detect. That leaves the original Athlon, Pentium Pro and
176 * Pentium II.
177 */
178
179# if defined(_M_IX86)
180# define Q_PROCESSOR_X86 (_M_IX86/100)
181# elif defined(__i686__) || defined(__athlon__) || defined(__SSE__) || defined(__pentiumpro__)
182# define Q_PROCESSOR_X86 6
183# elif defined(__i586__) || defined(__k6__) || defined(__pentium__)
184# define Q_PROCESSOR_X86 5
185# elif defined(__i486__) || defined(__80486__)
186# define Q_PROCESSOR_X86 4
187# else
188# define Q_PROCESSOR_X86 3
189# endif
190
191#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
192# define Q_PROCESSOR_X86 6
193# define Q_PROCESSOR_X86_64
194# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
195# define Q_PROCESSOR_WORDSIZE 8
196
197/*
198 Itanium (IA-64) family, no revisions or variants
199
200 Itanium is bi-endian, use endianness auto-detection implemented below.
201*/
202#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
203# define Q_PROCESSOR_IA64
204# define Q_PROCESSOR_WORDSIZE 8
205// Q_BYTE_ORDER not defined, use endianness auto-detection
206
207/*
208 LoongArch family, known variants: 32- and 64-bit
209
210 LoongArch is little-endian.
211*/
212#elif defined(__loongarch__)
213# define Q_PROCESSOR_LOONGARCH
214# if __loongarch_grlen == 64
215# define Q_PROCESSOR_LOONGARCH_64
216# else
217# define Q_PROCESSOR_LOONGARCH_32
218# endif
219# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
220
221/*
222 Motorola 68000 family, no revisions or variants
223
224 M68K is big-endian.
225*/
226#elif defined(__m68k__)
227# define Q_PROCESSOR_M68K
228# define Q_BYTE_ORDER Q_BIG_ENDIAN
229
230/*
231 MIPS family, known revisions: I, II, III, IV, 32, 64
232
233 MIPS is bi-endian, use endianness auto-detection implemented below.
234*/
235#elif defined(__mips) || defined(__mips__) || defined(_M_MRX000)
236# define Q_PROCESSOR_MIPS
237# if defined(_MIPS_ARCH_MIPS1) || (defined(__mips) && __mips - 0 >= 1)
238# define Q_PROCESSOR_MIPS_I
239# endif
240# if defined(_MIPS_ARCH_MIPS2) || (defined(__mips) && __mips - 0 >= 2)
241# define Q_PROCESSOR_MIPS_II
242# endif
243# if defined(_MIPS_ARCH_MIPS3) || (defined(__mips) && __mips - 0 >= 3)
244# define Q_PROCESSOR_MIPS_III
245# endif
246# if defined(_MIPS_ARCH_MIPS4) || (defined(__mips) && __mips - 0 >= 4)
247# define Q_PROCESSOR_MIPS_IV
248# endif
249# if defined(_MIPS_ARCH_MIPS5) || (defined(__mips) && __mips - 0 >= 5)
250# define Q_PROCESSOR_MIPS_V
251# endif
252# if defined(_MIPS_ARCH_MIPS32) || defined(__mips32) || (defined(__mips) && __mips - 0 >= 32)
253# define Q_PROCESSOR_MIPS_32
254# endif
255# if defined(_MIPS_ARCH_MIPS64) || defined(__mips64)
256# define Q_PROCESSOR_MIPS_64
257# define Q_PROCESSOR_WORDSIZE 8
258# endif
259# if defined(__MIPSEL__)
260# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
261# elif defined(__MIPSEB__)
262# define Q_BYTE_ORDER Q_BIG_ENDIAN
263# else
264// Q_BYTE_ORDER not defined, use endianness auto-detection
265# endif
266
267/*
268 Power family, known variants: 32- and 64-bit
269
270 There are many more known variants/revisions that we do not handle/detect.
271 See http://en.wikipedia.org/wiki/Power_Architecture
272 and http://en.wikipedia.org/wiki/File:PowerISA-evolution.svg
273
274 Power is bi-endian, use endianness auto-detection implemented below.
275*/
276#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__)
277 || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC)
278 || defined(_M_MPPC) || defined(_M_PPC)
279# define Q_PROCESSOR_POWER
280# if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
281# define Q_PROCESSOR_POWER_64
282# define Q_PROCESSOR_WORDSIZE 8
283# else
284# define Q_PROCESSOR_POWER_32
285# endif
286// Q_BYTE_ORDER not defined, use endianness auto-detection
287
288/*
289 RISC-V family, known variants: 32- and 64-bit
290
291 RISC-V is little-endian.
292*/
293#elif defined(__riscv)
294# define Q_PROCESSOR_RISCV
295# if __riscv_xlen == 64
296# define Q_PROCESSOR_RISCV_64
297# else
298# define Q_PROCESSOR_RISCV_32
299# endif
300# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
301
302/*
303 S390 family, known variant: S390X (64-bit)
304
305 S390 is big-endian.
306*/
307#elif defined(__s390__)
308# define Q_PROCESSOR_S390
309# if defined(__s390x__)
310# define Q_PROCESSOR_S390_X
311# endif
312# define Q_BYTE_ORDER Q_BIG_ENDIAN
313
314/*
315 SuperH family, optional revision: SH-4A
316
317 SuperH is bi-endian, use endianness auto-detection implemented below.
318*/
319// #elif defined(__sh__)
320// # define Q_PROCESSOR_SH
321// # if defined(__sh4a__)
322// # define Q_PROCESSOR_SH_4A
323// # endif
324// Q_BYTE_ORDER not defined, use endianness auto-detection
325
326/*
327 SPARC family, optional revision: V9
328
329 SPARC is big-endian only prior to V9, while V9 is bi-endian with big-endian
330 as the default byte order. Assume all SPARC systems are big-endian.
331*/
332#elif defined(__sparc__)
333# define Q_PROCESSOR_SPARC
334# if defined(__sparc_v9__) || defined(__sparcv9)
335# define Q_PROCESSOR_SPARC_V9
336# endif
337# if defined(__sparc64__)
338# define Q_PROCESSOR_SPARC_64
339# endif
340# define Q_BYTE_ORDER Q_BIG_ENDIAN
341
342// -- Web Assembly --
343#elif defined(__EMSCRIPTEN__)
344# define Q_PROCESSOR_WASM
345# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
346# define Q_PROCESSOR_WORDSIZE 8
347#ifdef QT_COMPILER_SUPPORTS_SSE2
348# define Q_PROCESSOR_X86 6 // enables SIMD support
349# define Q_PROCESSOR_X86_64 // wasm64
350# define Q_PROCESSOR_WASM_64
351#endif
352
353#endif
354
355/*
356 NOTE:
357 GCC 4.6 added __BYTE_ORDER__, __ORDER_BIG_ENDIAN__, __ORDER_LITTLE_ENDIAN__
358 and __ORDER_PDP_ENDIAN__ in SVN r165881. If you are using GCC 4.6 or newer,
359 this code will properly detect your target byte order; if you are not, and
360 the __LITTLE_ENDIAN__ or __BIG_ENDIAN__ macros are not defined, then this
361 code will fail to detect the target byte order.
362*/
363// Some processors support either endian format, try to detect which we are using.
364#if !defined(Q_BYTE_ORDER)
365# if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == Q_BIG_ENDIAN || __BYTE_ORDER__ == Q_LITTLE_ENDIAN)
366// Reuse __BYTE_ORDER__ as-is, since our Q_*_ENDIAN #defines match the preprocessor defaults
367# define Q_BYTE_ORDER __BYTE_ORDER__
368# elif defined(__BIG_ENDIAN__) || defined(_big_endian__) || defined(_BIG_ENDIAN)
369# define Q_BYTE_ORDER Q_BIG_ENDIAN
370# elif defined(__LITTLE_ENDIAN__) || defined(_little_endian__) || defined(_LITTLE_ENDIAN)
371# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
372# else
373# error "Unable to determine byte order!"
374# endif
375#endif
376
377/*
378 Size of a pointer and the machine register size. We detect a 64-bit system by:
379 * GCC and compatible compilers (Clang, ICC on OS X and Windows) always define
380 __SIZEOF_POINTER__. This catches all known cases of ILP32 builds on 64-bit
381 processors.
382 * Most other Unix compilers define __LP64__ or _LP64 on 64-bit mode
383 (Long and Pointer 64-bit)
384 * If Q_PROCESSOR_WORDSIZE was defined above, it's assumed to match the pointer
385 size.
386 Otherwise, we assume to be 32-bit and then check in qglobal.cpp that it is right.
387*/
388
389#if defined __SIZEOF_POINTER__
390# define QT_POINTER_SIZE __SIZEOF_POINTER__
391#elif defined(__LP64__) || defined(_LP64)
392# define QT_POINTER_SIZE 8
393#elif defined(Q_PROCESSOR_WORDSIZE)
394# define QT_POINTER_SIZE Q_PROCESSOR_WORDSIZE
395#else
396# define QT_POINTER_SIZE 4
397#endif
398
399/*
400 Define Q_PROCESSOR_WORDSIZE to be the size of the machine's word (usually,
401 the size of the register). On some architectures where a pointer could be
402 smaller than the register, the macro is defined above.
403
404 Falls back to QT_POINTER_SIZE if not set explicitly for the platform.
405*/
407# define Q_PROCESSOR_WORDSIZE QT_POINTER_SIZE
408#endif
409
410
411#endif // QPROCESSORDETECTION_H
#define ARCH_POINTER
#define ARCH_PROCESSOR
#define ARCH_ABI
#define ARCH_COORD_TYPE
#define ARCH_ABI1
#define ARCH_ABI2
#define QT_POINTER_SIZE
#define Q_PROCESSOR_WORDSIZE
#define Q_LITTLE_ENDIAN