diff options
Diffstat (limited to 'src/corelib/tools/qalgorithms.h')
-rw-r--r-- | src/corelib/tools/qalgorithms.h | 69 |
1 files changed, 13 insertions, 56 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 11e4d9da39..8889effece 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -1,45 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QALGORITHMS_H #define QALGORITHMS_H +#if 0 +#pragma qt_class(QtAlgorithms) +#endif + #include <QtCore/qglobal.h> #if __has_include(<bit>) && __cplusplus > 201703L @@ -73,19 +41,11 @@ inline void qDeleteAll(const Container &c) */ namespace QAlgorithmsPrivate { -#ifdef Q_CC_CLANG -// Clang had a bug where __builtin_ctz/clz/popcount were not marked as constexpr. -# if (defined __apple_build_version__ && __clang_major__ >= 7) || (Q_CC_CLANG >= 307) -# define QT_HAS_CONSTEXPR_BUILTINS -# endif -#elif defined(Q_CC_MSVC) && !defined(Q_CC_INTEL) && !defined(Q_PROCESSOR_ARM) -# define QT_HAS_CONSTEXPR_BUILTINS +#if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L +// We use C++20 <bit> operations instead which ensures constexpr bit ops +# define QT_HAS_CONSTEXPR_BITOPS #elif defined(Q_CC_GNU) -# define QT_HAS_CONSTEXPR_BUILTINS -#endif - -#if defined QT_HAS_CONSTEXPR_BUILTINS -#if defined(Q_CC_GNU) || defined(Q_CC_CLANG) +# define QT_HAS_CONSTEXPR_BITOPS # define QT_HAS_BUILTIN_CTZS constexpr Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) noexcept { @@ -201,9 +161,7 @@ Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) noexcept // architecture), but unlike the other compilers, MSVC has no option // to generate code for those processors. // So it's an acceptable compromise. -#if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L -// We use C++20 <bit> operations instead which ensures constexpr popcount -#elif defined(__AVX__) || defined(__SSE4_2__) || defined(__POPCNT__) +#if defined(__AVX__) || defined(__SSE4_2__) || defined(__POPCNT__) #define QT_POPCOUNT_CONSTEXPR #define QT_POPCOUNT_RELAXED_CONSTEXPR #define QALGORITHMS_USE_BUILTIN_POPCOUNT @@ -232,7 +190,6 @@ Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) noexcept #endif // __AVX__ || __SSE4_2__ || __POPCNT__ #endif // MSVC -#endif // QT_HAS_CONSTEXPR_BUILTINS #ifndef QT_POPCOUNT_CONSTEXPR #define QT_POPCOUNT_CONSTEXPR constexpr @@ -333,7 +290,7 @@ constexpr inline uint qConstexprCountTrailingZeroBits(quint64 v) noexcept constexpr inline uint qConstexprCountTrailingZeroBits(quint8 v) noexcept { unsigned int c = 8; // c will be the number of zero bits on the right - v &= -signed(v); + v &= quint8(-signed(v)); if (v) c--; if (v & 0x0000000F) c -= 4; if (v & 0x00000033) c -= 2; @@ -344,7 +301,7 @@ constexpr inline uint qConstexprCountTrailingZeroBits(quint8 v) noexcept constexpr inline uint qConstexprCountTrailingZeroBits(quint16 v) noexcept { unsigned int c = 16; // c will be the number of zero bits on the right - v &= -signed(v); + v &= quint16(-signed(v)); if (v) c--; if (v & 0x000000FF) c -= 8; if (v & 0x00000F0F) c -= 4; |