Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qyieldcpu.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2023 The Qt Company Ltd.
0002 // Copyright (C) 2023 Intel Corporation.
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 
0005 #ifndef QYIELDCPU_H
0006 #define QYIELDCPU_H
0007 
0008 #include <QtCore/qcompilerdetection.h>
0009 #include <QtCore/qprocessordetection.h>
0010 #include <QtCore/qtconfigmacros.h>
0011 
0012 #ifdef Q_CC_MSVC_ONLY
0013 // MSVC defines _YIELD_PROCESSOR() in <xatomic.h>, but as that is a private
0014 // header, we include the public ones
0015 #  ifdef __cplusplus
0016 #    include <atomic>
0017 extern "C"
0018 #  endif
0019 void _mm_pause(void);       // the compiler recognizes as intrinsic
0020 #endif
0021 
0022 QT_BEGIN_NAMESPACE
0023 
0024 #ifdef Q_CC_GNU
0025 __attribute__((artificial))
0026 #endif
0027 Q_ALWAYS_INLINE void qYieldCpu(void) Q_DECL_NOEXCEPT;
0028 
0029 void qYieldCpu(void)
0030 #ifdef __cplusplus
0031     noexcept
0032 #endif
0033 {
0034 #if __has_builtin(__yield)
0035     __yield();              // Generic
0036 #elif defined(_YIELD_PROCESSOR) && defined(Q_CC_MSVC)
0037     _YIELD_PROCESSOR();     // Generic; MSVC's <atomic>
0038 
0039 #elif __has_builtin(__builtin_ia32_pause)
0040     __builtin_ia32_pause();
0041 #elif defined(Q_PROCESSOR_X86) && defined(Q_CC_GNU)
0042     // GCC < 10 didn't have __has_builtin()
0043     __builtin_ia32_pause();
0044 #elif defined(Q_PROCESSOR_X86) && defined(Q_CC_MSVC)
0045     _mm_pause();
0046 #elif defined(Q_PROCESSOR_X86)
0047     asm("pause");           // hopefully asm() works in this compiler
0048 
0049 #elif __has_builtin(__builtin_arm_yield)
0050     __builtin_arm_yield();
0051 #elif defined(Q_PROCESSOR_ARM) && Q_PROCESSOR_ARM >= 7 && defined(Q_CC_GNU)
0052     asm("yield");           // this works everywhere
0053 
0054 #elif defined(Q_PROCESSOR_RISCV)
0055     asm(".word 0x0100000f");        // a.k.a. "pause"
0056 
0057 #elif defined(_YIELD_PROCESSOR) && defined(Q_CC_GHS)
0058     _YIELD_PROCESSOR;       // Green Hills (INTEGRITY), but only on ARM
0059 #endif
0060 }
0061 
0062 QT_END_NAMESPACE
0063 
0064 #endif // QYIELDCPU_H