6#define __INTEL_COMPILER_USE_INTRINSIC_PROTOTYPES
15#if defined(QT_NO_DEBUG) && !defined(NDEBUG)
21# include "../testlib/3rdparty/valgrind_p.h"
24#define QT_FUNCTION_TARGET_BASELINE
27# if !defined(Q_CC_GNU)
30# if defined(Q_PROCESSOR_ARM_64)
32# include <processthreadsapi.h>
34#elif defined(Q_OS_LINUX) && defined(Q_PROCESSOR_MIPS_32)
35# include "private/qcore_unix_p.h"
36#elif QT_CONFIG(getauxval) && defined(Q_PROCESSOR_ARM)
43#define HWCAP_NEON 4096
46#define HWCAP2_AES (1 << 0)
47#define HWCAP2_CRC32 (1 << 4)
50#define HWCAP_AES (1 << 3)
51#define HWCAP_CRC32 (1 << 7)
57#elif defined(Q_CC_GHS)
58# include <INTEGRITY_types.h>
59#elif defined(Q_OS_DARWIN) && defined(Q_PROCESSOR_ARM)
60# include <sys/sysctl.h>
73#if defined(Q_PROCESSOR_ARM)
85#elif defined(Q_PROCESSOR_MIPS)
98#elif defined(Q_PROCESSOR_X86)
106#if defined (Q_OS_NACL)
111#elif defined(Q_PROCESSOR_ARM)
116#if QT_CONFIG(getauxval)
117 unsigned long auxvHwCap = getauxval(AT_HWCAP);
118 if (auxvHwCap != 0) {
119# if defined(Q_PROCESSOR_ARM_64)
121 features |= CpuFeatureNEON;
122 if (auxvHwCap & HWCAP_CRC32)
123 features |= CpuFeatureCRC32;
124 if (auxvHwCap & HWCAP_AES)
125 features |= CpuFeatureAES;
128 if (auxvHwCap & HWCAP_NEON)
129 features |= CpuFeatureNEON;
130 auxvHwCap = getauxval(AT_HWCAP2);
131 if (auxvHwCap & HWCAP2_CRC32)
132 features |= CpuFeatureCRC32;
133 if (auxvHwCap & HWCAP2_AES)
134 features |= CpuFeatureAES;
139#elif defined(Q_OS_DARWIN) && defined(Q_PROCESSOR_ARM)
141 size_t len =
sizeof(feature);
142 if (sysctlbyname(
"hw.optional.neon", &feature, &
len,
nullptr, 0) == 0)
143 features |= feature ? CpuFeatureNEON : 0;
144 if (sysctlbyname(
"hw.optional.armv8_crc32", &feature, &
len,
nullptr, 0) == 0)
145 features |= feature ? CpuFeatureCRC32 : 0;
147#if defined(__ARM_FEATURE_CRYPTO)
148 features |= CpuFeatureAES;
151#elif defined(Q_OS_WIN) && defined(Q_PROCESSOR_ARM_64)
152 features |= CpuFeatureNEON;
153 if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) != 0)
154 features |= CpuFeatureCRC32;
155 if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0)
156 features |= CpuFeatureAES;
159#if defined(__ARM_NEON__) || defined(__ARM_NEON)
160 features |= CpuFeatureNEON;
162#if defined(__ARM_FEATURE_CRC32)
163 features |= CpuFeatureCRC32;
165#if defined(__ARM_FEATURE_CRYPTO)
166 features |= CpuFeatureAES;
172#elif defined(Q_PROCESSOR_X86)
174#ifdef Q_PROCESSOR_X86_32
175# define PICreg "%%ebx"
177# define PICreg "%%rbx"
180# define X86_BASELINE "no-sse3"
182# define X86_BASELINE "no-sse"
187# undef QT_FUNCTION_TARGET_BASELINE
188# define QT_FUNCTION_TARGET_BASELINE __attribute__((target(X86_BASELINE)))
189# define QT_FUNCTION_TARGET_STRING_BASELINE_RDRND \
190 X86_BASELINE "," QT_FUNCTION_TARGET_STRING_RDRND
193static bool checkRdrndWorks() noexcept;
196static
int maxBasicCpuidSupported()
198#if defined(Q_CC_EMSCRIPTEN)
200#elif defined(Q_CC_GNU)
203# if Q_PROCESSOR_X86 < 5
205 long cpuid_supported;
209 "xor $0x00200000, %0\n"
215 :
"=a" (cpuid_supported),
"=r" (tmp1)
217 if (!cpuid_supported)
222 asm (
"xchg " PICreg
", %1\n"
224 "xchg " PICreg
", %1\n"
225 :
"=&a" (
result),
"=&r" (tmp1)
229#elif defined(Q_OS_WIN)
234#elif defined(Q_CC_GHS)
235 unsigned int info[4];
244static void cpuidFeatures01(
uint &ecx,
uint &edx)
246#if defined(Q_CC_GNU) && !defined(Q_CC_EMSCRIPTEN)
248 asm (
"xchg " PICreg
", %2\n"
250 "xchg " PICreg
", %2\n"
251 :
"=&c" (ecx),
"=&d" (edx),
"=&r" (tmp1)
253#elif defined(Q_OS_WIN)
258#elif defined(Q_CC_GHS)
259 unsigned int info[4];
270inline void __cpuidex(
int info[4],
int, __int64) { memset(
info, 0, 4*
sizeof(
int));}
274static void cpuidFeatures07_00(
uint &ebx,
uint &ecx,
uint &edx)
276#if defined(Q_CC_GNU) && !defined(Q_CC_EMSCRIPTEN)
278 qregisteruint rcx = 0;
279 qregisteruint rdx = 0;
280 asm (
"xchg " PICreg
", %0\n"
282 "xchg " PICreg
", %0\n"
283 :
"=&r" (rbx),
"+&c" (rcx),
"+&d" (rdx)
288#elif defined(Q_OS_WIN)
290 __cpuidex(
info, 7, 0);
294#elif defined(Q_CC_GHS)
295 unsigned int info[4];
296 __CPUIDEX(7, 0,
info);
308#if defined(Q_OS_WIN) && !(defined(Q_CC_GNU) || defined(Q_CC_GHS))
310inline quint64 _xgetbv(__int64) {
return 0; }
314#if (defined(Q_CC_GNU) && !defined(Q_CC_EMSCRIPTEN)) || defined(Q_CC_GHS)
315 asm (
".byte 0x0F, 0x01, 0xD0"
316 :
"=a" (eax),
"=d" (edx)
318#elif defined(Q_OS_WIN)
345 constexpr quintptr commpage =
sizeof(
void *) > 4 ?
Q_UINT64_C(0x00007fffffe00000) : 0xffff0000;
346 constexpr quintptr cpu_capabilities64 = commpage + 0x10;
348 if (capab & kHasAVX512F)
359 int cpuidLevel = maxBasicCpuidSupported();
360#if Q_PROCESSOR_X86 < 5
385 uint xgetbvA = 0, xgetbvD = 0;
386 xgetbv(0, xgetbvA, xgetbvD);
390 xcr0 |=
quint64(xgetbvD) << 32;
391 xcr0 = adjustedXcr0(xcr0);
395 if ((xcr0 & req.xsave_state) != req.xsave_state)
396 features &= ~req.cpu_features;
399 if (features & CpuFeatureRDRND && !checkRdrndWorks())
400 features &= ~(CpuFeatureRDRND | CpuFeatureRDSEED);
405#elif defined(Q_PROCESSOR_MIPS_32)
407#if defined(Q_OS_LINUX)
416 static const int chunk_size = 256;
422 ~QSimpleBuffer() { ::free(
data); }
424 void resize(
unsigned newsize)
426 if (newsize > alloc) {
427 unsigned newalloc = chunk_size * ((newsize / chunk_size) + 1);
428 if (newalloc < newsize)
430 if (newalloc != alloc) {
431 data =
static_cast<char *
>(::realloc(
data, newalloc));
437 void append(
const QSimpleBuffer &
other,
unsigned appendsize)
443 void popleft(
unsigned amount)
464static void bufReadLine(
int fd, QSimpleBuffer &
line, QSimpleBuffer &
buffer)
467 char *newline =
static_cast<char *
>(::memchr(
buffer.data,
'\n',
buffer.size));
469 unsigned piece_size = newline -
buffer.data + 1;
471 buffer.popleft(piece_size);
475 if (
buffer.size + QSimpleBuffer::chunk_size >
buffer.alloc) {
483 buffer.size += read_bytes;
493static bool procCpuinfoContains(
const char *prefix,
const char *
string)
496 if (cpuinfo_fd == -1)
499 unsigned string_len = ::strlen(
string);
500 unsigned prefix_len = ::strlen(prefix);
502 bool present =
false;
507 if (colon &&
line.
size > prefix_len + string_len) {
508 if (!::strncmp(prefix,
line.
data, prefix_len)) {
512 char *found = ::strstr(
line.cString(),
string);
513 if (found && ::isspace(found[-1]) &&
514 (::isspace(found[string_len]) || found[string_len] ==
'\0')) {
533#if defined __mips_dsp
534 flags |= CpuFeatureDSP;
535# if defined __mips_dsp_rev && __mips_dsp_rev >= 2
536 flags |= CpuFeatureDSPR2;
537# elif defined(Q_OS_LINUX)
538 if (procCpuinfoContains(
"cpu model",
"MIPS 74Kc") || procCpuinfoContains(
"cpu model",
"MIPS 74Kf"))
539 flags |= CpuFeatureDSPR2;
541#elif defined(Q_OS_LINUX)
542 if (procCpuinfoContains(
"ASEs implemented",
"dsp")) {
543 flags |= CpuFeatureDSP;
544 if (procCpuinfoContains(
"cpu model",
"MIPS 74Kc") || procCpuinfoContains(
"cpu model",
"MIPS 74Kf"))
545 flags |= CpuFeatureDSPR2;
569#if defined(Q_OS_LINUX) && defined(Q_PROCESSOR_ARM_64)
572 minFeatureTest &= ~(CpuFeatureAES|CpuFeatureCRC32);
574#if defined(Q_PROCESSOR_X86_64) && defined(cpu_feature_shstk)
578 minFeatureTest &= ~CpuFeatureSHSTK;
583 if (
char *disable = getenv(
"QT_NO_CPU_FEATURE"); disable && *disable) {
584#if _POSIX_C_SOURCE >= 200112L
585 char *saveptr =
nullptr;
586 auto strtok = [&saveptr](
char *
str,
const char *delim) {
587 return ::strtok_r(
str, delim, &saveptr);
590 while (
char *
token = strtok(disable,
" ")) {
599#ifdef RUNNING_ON_VALGRIND
600 bool runningOnValgrind = RUNNING_ON_VALGRIND;
602 bool runningOnValgrind =
false;
604 if (
Q_UNLIKELY(!runningOnValgrind && minFeatureTest != 0 && (
f & minFeatureTest) != minFeatureTest)) {
606 fprintf(stderr,
"Incompatible processor. This Qt build requires the following features:\n ");
611 fprintf(stderr,
"\n");
626 printf(
"Processor features: ");
633 printf(
"\n!!!!!!!!!!!!!!!!!!!!\n!!! Missing required features:");
638 printf(
"\n!!! Applications will likely crash with \"Invalid Instruction\"\n!!!!!!!!!!!!!!!!!!!!");
643#if defined(Q_PROCESSOR_X86) && QT_COMPILER_SUPPORTS_HERE(RDRND)
645# ifdef Q_PROCESSOR_X86_64
646# define _rdrandXX_step _rdrand64_step
647# define _rdseedXX_step _rdseed64_step
649# define _rdrandXX_step _rdrand32_step
650# define _rdseedXX_step _rdseed32_step
657template <
typename F>
struct ExtractParameter;
658template <
typename T>
struct ExtractParameter<int (T *)> {
using Type = T; };
659using randuint = ExtractParameter<
decltype(_rdrandXX_step)>
::Type;
662# if QT_COMPILER_SUPPORTS_HERE(RDSEED)
670 while (
ptr +
sizeof(randuint) /
sizeof(*
ptr) <=
end) {
671 if (_rdseedXX_step(
reinterpret_cast<randuint *
>(
ptr)) == 0)
673 ptr +=
sizeof(randuint) /
sizeof(*
ptr);
676 if (
sizeof(*
ptr) !=
sizeof(randuint) &&
ptr !=
end) {
677 if (_rdseed32_step(
ptr) == 0)
686static unsigned *qt_random_rdseed(
unsigned *
ptr,
unsigned *)
695 while (
ptr +
sizeof(randuint)/
sizeof(*
ptr) <=
end) {
696 if (_rdrandXX_step(
reinterpret_cast<randuint *
>(
ptr)))
697 ptr +=
sizeof(randuint)/
sizeof(*
ptr);
698 else if (--retries == 0)
702 while (
sizeof(*
ptr) !=
sizeof(randuint) &&
ptr !=
end) {
703 bool ok = _rdrand32_step(
ptr);
704 if (!
ok && --retries)
716static bool checkRdrndWorks() noexcept
730 unsigned testBuffer[TestBufferSize] = {};
732 unsigned *
end = qt_random_rdrnd(testBuffer, testBuffer + TestBufferSize);
733 if (
end < testBuffer + 3) {
741 if (testBuffer[0] == testBuffer[1]
742 && testBuffer[0] == testBuffer[2]
743 && (
end < testBuffer + TestBufferSize || testBuffer[0] == testBuffer[3])) {
744 fprintf(stderr,
"WARNING: CPU random generator seem to be failing, "
745 "disabling hardware random number generation\n"
746 "WARNING: RDRND generated:");
748 fprintf(stderr,
" 0x%x", *
ptr);
749 fprintf(stderr,
"\n");
759 unsigned *
ptr =
reinterpret_cast<unsigned *
>(
buffer);
767 return ptr -
reinterpret_cast<unsigned *
>(
buffer);
769#elif defined(Q_PROCESSOR_X86) && !defined(Q_OS_NACL) && !defined(Q_PROCESSOR_ARM)
770static bool checkRdrndWorks() noexcept {
return false; }
773#if QT_SUPPORTS_INIT_PRIORITY
775struct QSimdInitializer
782Q_DECL_INIT_PRIORITY(01) static QSimdInitializer initializer;
qsizetype size() const
Returns the number of characters in this string.
QChar * data()
Returns a pointer to the data stored in the QString.
QString & append(QChar c)
void resize(qsizetype size)
Sets the size of the string to size characters.
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
#define Q_DECL_COLD_FUNCTION
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static int qt_safe_close(int fd)
static ControlElement< T > * ptr(QWidget *widget)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QT_BEGIN_NAMESPACE QT_FUNCTION_TARGET_BASELINE uint arraysize(T(&)[N])
#define QT_FUNCTION_TARGET_BASELINE
QT_FUNCTION_TARGET_BASELINE void qDumpCPUFeatures()
static constexpr auto SimdInitialized
QT_FUNCTION_TARGET_BASELINE uint64_t QT_MANGLE_NAMESPACE() qDetectCpuFeatures()
static const quint64 minFeature
static uint detectProcessorFeatures()
static const char features_string[]
static const int features_indices[]
#define qCpuHasFeature(feature)
#define QT_FUNCTION_TARGET(x)
static const uint64_t qCompilerCpuFeatures
static const struct XSaveRequirementMapping xsave_requirements[]
static const uint16_t x86_locators[]
#define QT_MANGLE_NAMESPACE(name)
unsigned long long quint64
QFileInfo info(fileName)
[8]
QTextStream out(stdout)
[7]