diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2024-06-27 09:55:21 -0700 |
|---|---|---|
| committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-07-03 19:33:58 +0000 |
| commit | 15f753ca5a60b5273d243f528978e25c28a9b56d (patch) | |
| tree | da581a9e77ea3c8ba266e9278306e831975a36fa /src/corelib/plugin/quuid.cpp | |
| parent | da3997af0d87aa8ebe25a195c08130f69c6b19e5 (diff) | |
QUuid: simplify the three-way comparison functions to make them constexpr
While retaining the old sorting order, this allows us to simplify the
ifdef'ery and produces much better code.
With Clang, an equality check is
vmovdqu (%rdi), %xmm0
vpxor (%rsi), %xmm0, %xmm0
vptest %xmm0, %xmm0
sete %al
in C++20 mode.
GCC generates four 64-bit loads instead of using vectors:
movbeq (%rdi), %rax
movbeq 8(%rdi), %rdx
movbeq (%rsi), %r8
movbeq 8(%rsi), %rcx
movq %rdx, %r10
movq %rax, %r11
movq %r8, %rdx
movq %rcx, %rax
xorq %r10, %rax
xorq %r11, %rdx
orq %rdx, %rax
sete %al
(the four MOV in the middle don't seem necessary)
For the sorting case, the compilers need to generate extra code
because of the check on the variant, something I'm scheduling for
removal in Qt 7.0. For long-term sorting code, both GCC and Clang
generate four 64-bit load-and-swap-endianness instructions, but Clang
for some reason also kept the 128-bit vector code (I'm guessing it's a
minor optimization bug that will be corrected in due time).
Pick-to: 6.8
Change-Id: I46feca3a447244a8ba19fffd17dceacc8e528c3e
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib/plugin/quuid.cpp')
| -rw-r--r-- | src/corelib/plugin/quuid.cpp | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index b3fad47ee69..af7c07d23e6 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -910,50 +910,17 @@ QUuid::Version QUuid::version() const noexcept /*! \fn bool QUuid::operator<(const QUuid &lhs, const QUuid &rhs) - - Returns \c true if \a lhs QUuid has the same \l{Variant field} - {variant field} as the \a rhs QUuid and is lexicographically - \e{before} the \a rhs QUuid. If the \a rhs QUuid has a - different variant field, the return value is determined by - comparing the two \l{QUuid::Variant} {variants}. - - \sa variant() -*/ - -/*! \fn bool QUuid::operator>(const QUuid &lhs, const QUuid &rhs) - - Returns \c true if \a lhs QUuid has the same \l{Variant field} - {variant field} as the \a rhs QUuid and is lexicographically - \e{after} the \a rhs QUuid. If the \a rhs QUuid has a - different variant field, the return value is determined by - comparing the two \l{QUuid::Variant} {variants}. - - \sa variant() -*/ - -/*! \fn bool QUuid::operator<=(const QUuid &lhs, const QUuid &rhs) - \since 5.5 - - Returns \c true if \a lhs has the same \l{Variant field} - {variant field} as \a rhs and is lexicographically - \e{not after} \a rhs. If \a rhs has a - different variant field, the return value is determined by - comparing the two \l{QUuid::Variant} {variants}. - - \sa {QUuid::}{variant()} -*/ - -/*! \fn bool QUuid::operator>=(const QUuid &lhs, const QUuid &rhs) \since 5.5 - Returns \c true if \a lhs has the same \l{Variant field} - {variant field} as \a rhs and is lexicographically - \e{not before} \a rhs. If \a rhs has a - different variant field, the return value is determined by - comparing the two \l{QUuid::Variant} {variants}. + Performs a comparison of \a lhs against \a rhs and returns \c true if the + relative sorting of \a lhs and \a rhs is correct for the operation in + question, \c false otherwise. Note that the sorting performed by this + functions may not be equal to the sorting of the strings created by + toString(), nor the integers toId128(), or the byte array returned by + toBytes() and toRfc4122(). \sa {QUuid::}{variant()} */ |
