summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-09-02 12:42:01 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-09-02 12:42:01 (GMT)
commit7aed1cf06ed7b50f060ebce7a5a041c752989307 (patch)
tree80bb70bc893f420494507566036b61b496090bd2 /src/corelib
parentcf0917cfc3b040e9650953560038f92cac42b6e3 (diff)
parentadcd745d6ef2dbd68a28e932e2a8961b70bece09 (diff)
downloadQt-7aed1cf06ed7b50f060ebce7a5a041c752989307.zip
Qt-7aed1cf06ed7b50f060ebce7a5a041c752989307.tar.gz
Qt-7aed1cf06ed7b50f060ebce7a5a041c752989307.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: Doc: Updated Supported Platforms page. Finished New binary of configure.exe with -mp/-no-mp option Turn Makefile.win32 into batch-mode, enable /MP and PCH Add option to enable -MP compile option for MSVC Rewrite ucstrcmp in terms of ucstrncmp Reorganise qelapsedtimer_unix.cpp for better inlining performance. Update the cpuid code to be better Revert "Restore default if to system default on session close."
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qelapsedtimer_unix.cpp129
-rw-r--r--src/corelib/tools/qsimd.cpp106
-rw-r--r--src/corelib/tools/qstring.cpp23
3 files changed, 121 insertions, 137 deletions
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp
index 2c4ea58..633fa00 100644
--- a/src/corelib/tools/qelapsedtimer_unix.cpp
+++ b/src/corelib/tools/qelapsedtimer_unix.cpp
@@ -40,22 +40,58 @@
****************************************************************************/
#include "qelapsedtimer.h"
-#include "qpair.h"
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
-#if !defined(QT_NO_CLOCK_MONOTONIC)
-# if defined(QT_BOOTSTRAPPED)
-# define QT_NO_CLOCK_MONOTONIC
+#if defined(QT_NO_CLOCK_MONOTONIC) || defined(QT_BOOTSTRAPPED)
+// turn off the monotonic clock
+# ifdef _POSIX_MONOTONIC_CLOCK
+# undef _POSIX_MONOTONIC_CLOCK
# endif
+# define _POSIX_MONOTONIC_CLOCK -1
#endif
QT_BEGIN_NAMESPACE
-static qint64 fractionAdjustment()
+#if (_POSIX_MONOTONIC_CLOCK-0 != 0)
+static const bool monotonicClockChecked = true;
+static const bool monotonicClockAvailable = _POSIX_MONOTONIC_CLOCK > 0;
+#else
+static int monotonicClockChecked = false;
+static int monotonicClockAvailable = false;
+#endif
+
+#ifdef Q_CC_GNU
+# define is_likely(x) __builtin_expect((x), 1)
+#else
+# define is_likely(x) (x)
+#endif
+#define load_acquire(x) ((volatile const int&)(x))
+#define store_release(x,v) ((volatile int&)(x) = (v))
+
+static void unixCheckClockType()
+{
+#if (_POSIX_MONOTONIC_CLOCK-0 == 0)
+ if (is_likely(load_acquire(monotonicClockChecked)))
+ return;
+
+# if defined(_SC_MONOTONIC_CLOCK)
+ // detect if the system support monotonic timers
+ long x = sysconf(_SC_MONOTONIC_CLOCK);
+ store_release(monotonicClockAvailable, x >= 200112L);
+# endif
+
+ store_release(monotonicClockChecked, true);
+#endif
+}
+
+static inline qint64 fractionAdjustment()
{
- if (QElapsedTimer::isMonotonic()) {
+ // disabled, but otherwise indicates bad usage of QElapsedTimer
+ //Q_ASSERT(monotonicClockChecked);
+
+ if (monotonicClockAvailable) {
// the monotonic timer is measured in nanoseconds
// 1 ms = 1000000 ns
return 1000*1000ull;
@@ -68,90 +104,73 @@ static qint64 fractionAdjustment()
bool QElapsedTimer::isMonotonic()
{
-#if (_POSIX_MONOTONIC_CLOCK-0 > 0)
- return true;
-#else
- static int returnValue = 0;
-
- if (returnValue == 0) {
-# if (_POSIX_MONOTONIC_CLOCK-0 < 0) || !defined(_SC_MONOTONIC_CLOCK)
- returnValue = -1;
-# elif (_POSIX_MONOTONIC_CLOCK == 0)
- // detect if the system support monotonic timers
- long x = sysconf(_SC_MONOTONIC_CLOCK);
- returnValue = (x >= 200112L) ? 1 : -1;
-# endif
- }
-
- return returnValue != -1;
-#endif
+ unixCheckClockType();
+ return monotonicClockAvailable;
}
QElapsedTimer::ClockType QElapsedTimer::clockType()
{
- return isMonotonic() ? MonotonicClock : SystemTime;
+ unixCheckClockType();
+ return monotonicClockAvailable ? MonotonicClock : SystemTime;
}
-static inline QPair<long, long> do_gettime()
+static inline void do_gettime(qint64 *sec, qint64 *frac)
{
-#if (_POSIX_MONOTONIC_CLOCK-0 > 0)
- timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- return qMakePair<long,long>(ts.tv_sec, ts.tv_nsec);
-#else
-# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED)
- if (QElapsedTimer::isMonotonic()) {
+#if (_POSIX_MONOTONIC_CLOCK-0 >= 0)
+ unixCheckClockType();
+ if (is_likely(monotonicClockAvailable)) {
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- return qMakePair<long,long>(ts.tv_sec, ts.tv_nsec);
+ *sec = ts.tv_sec;
+ *frac = ts.tv_nsec;
+ return;
}
-# endif
+#endif
// use gettimeofday
timeval tv;
::gettimeofday(&tv, 0);
- return qMakePair<long,long>(tv.tv_sec, tv.tv_usec);
-#endif
+ *sec = tv.tv_sec;
+ *frac = tv.tv_usec;
}
// used in qcore_unix.cpp and qeventdispatcher_unix.cpp
timeval qt_gettime()
{
- QPair<long, long> r = do_gettime();
+ qint64 sec, frac;
+ do_gettime(&sec, &frac);
timeval tv;
- tv.tv_sec = r.first;
- tv.tv_usec = r.second;
- if (QElapsedTimer::isMonotonic())
+ tv.tv_sec = sec;
+ tv.tv_usec = frac;
+ if (monotonicClockAvailable)
tv.tv_usec /= 1000;
return tv;
}
+static qint64 elapsedAndRestart(qint64 sec, qint64 frac,
+ qint64 *nowsec, qint64 *nowfrac)
+{
+ do_gettime(nowsec, nowfrac);
+ sec = *nowsec - sec;
+ frac = *nowfrac - frac;
+ return sec * Q_INT64_C(1000) + frac / fractionAdjustment();
+}
+
void QElapsedTimer::start()
{
- QPair<long, long> r = do_gettime();
- t1 = r.first;
- t2 = r.second;
+ do_gettime(&t1, &t2);
}
qint64 QElapsedTimer::restart()
{
- QPair<long, long> r = do_gettime();
- qint64 oldt1 = t1;
- qint64 oldt2 = t2;
- t1 = r.first;
- t2 = r.second;
-
- r.first -= oldt1;
- r.second -= oldt2;
- return r.first * Q_INT64_C(1000) + r.second / fractionAdjustment();
+ return elapsedAndRestart(t1, t2, &t1, &t2);
}
qint64 QElapsedTimer::elapsed() const
{
- QElapsedTimer now;
- now.start();
- return msecsTo(now);
+ qint64 sec, frac;
+ return elapsedAndRestart(t1, t2, &sec, &frac);
}
qint64 QElapsedTimer::msecsSinceReference() const
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index 68ab033..7349432 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -140,56 +140,41 @@ static inline uint detectProcessorFeatures()
uint result = 0;
/* see p. 118 of amd64 instruction set manual Vol3 */
#if defined(Q_CC_GNU)
- asm ("push %%ebx\n"
- "pushf\n"
- "pop %%eax\n"
- "mov %%eax, %%ebx\n"
- "xor $0x00200000, %%eax\n"
- "push %%eax\n"
- "popf\n"
- "pushf\n"
- "pop %%eax\n"
- "xor %%edx, %%edx\n"
- "xor %%ebx, %%eax\n"
- "jz 1f\n"
-
- "mov $0x00000001, %%eax\n"
- "cpuid\n"
- "1:\n"
- "pop %%ebx\n"
- "mov %%edx, %0\n"
- "mov %%ecx, %1\n"
- : "=r" (result), "=r" (feature_result)
- :
- : "%eax", "%ecx", "%edx"
- );
-
- asm ("push %%ebx\n"
- "pushf\n"
- "pop %%eax\n"
- "mov %%eax, %%ebx\n"
- "xor $0x00200000, %%eax\n"
- "push %%eax\n"
+ long cpuid_supported, tmp1;
+ asm ("pushf\n"
+ "pop %0\n"
+ "mov %0, %1\n"
+ "xor $0x00200000, %0\n"
+ "push %0\n"
"popf\n"
"pushf\n"
- "pop %%eax\n"
- "xor %%edx, %%edx\n"
- "xor %%ebx, %%eax\n"
- "jz 2f\n"
-
- "mov $0x80000000, %%eax\n"
- "cpuid\n"
- "cmp $0x80000000, %%eax\n"
- "jbe 2f\n"
- "mov $0x80000001, %%eax\n"
- "cpuid\n"
- "2:\n"
- "pop %%ebx\n"
- "mov %%edx, %0\n"
- : "=r" (extended_result)
- :
- : "%eax", "%ecx", "%edx"
- );
+ "pop %0\n"
+ "xor %1, %0\n" // %eax is now 0 if CPUID is not supported
+ : "=a" (cpuid_supported), "=r" (tmp1)
+ );
+ if (cpuid_supported) {
+ asm ("xchg %%ebx, %2\n"
+ "cpuid\n"
+ "xchg %%ebx, %2\n"
+ : "=c" (feature_result), "=d" (result), "=&r" (tmp1)
+ : "a" (1));
+
+ asm ("xchg %%ebx, %1\n"
+ "cpuid\n"
+ "cmp $0x80000000, %%eax\n"
+ "jnbe 1f\n"
+ "xor %0, %0\n"
+ "jmp 2f\n"
+ "1:\n"
+ "mov $0x80000001, %%eax\n"
+ "cpuid\n"
+ "2:\n"
+ "xchg %%ebx, %1\n"
+ : "=d" (extended_result), "=&r" (tmp1)
+ : "a" (0x80000000)
+ : "%ecx"
+ );
+ }
#elif defined (Q_OS_WIN)
_asm {
@@ -289,27 +274,10 @@ static inline uint detectProcessorFeatures()
uint feature_result = 0;
#if defined(Q_CC_GNU)
- asm ("push %%rbx\n"
- "pushf\n"
- "pop %%rax\n"
- "mov %%eax, %%ebx\n"
- "xor $0x00200000, %%eax\n"
- "push %%rax\n"
- "popf\n"
- "pushf\n"
- "pop %%rax\n"
- "xor %%edx, %%edx\n"
- "xor %%ebx, %%eax\n"
- "jz 1f\n"
-
- "mov $0x00000001, %%eax\n"
- "cpuid\n"
- "1:\n"
- "pop %%rbx\n"
- "mov %%ecx, %0\n"
- : "=r" (feature_result)
- :
- : "%eax", "%ecx", "%edx"
+ asm ("cpuid"
+ : "=c" (feature_result)
+ : "a" (1)
+ : "%ebx", "%edx"
);
#elif defined (Q_OS_WIN64)
{
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d940bf8..2813b29 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -173,19 +173,6 @@ static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b)
return 1;
}
-// Unicode case-sensitive comparison
-static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen)
-{
- if (a == b && alen == blen)
- return 0;
- int l = qMin(alen, blen);
- while (l-- && *a == *b)
- a++,b++;
- if (l == -1)
- return (alen-blen);
- return a->unicode() - b->unicode();
-}
-
// Unicode case-sensitive compare two same-sized strings
static int ucstrncmp(const QChar *a, const QChar *b, int l)
{
@@ -196,6 +183,16 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l)
return a->unicode() - b->unicode();
}
+// Unicode case-sensitive comparison
+static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen)
+{
+ if (a == b && alen == blen)
+ return 0;
+ int l = qMin(alen, blen);
+ int cmp = ucstrncmp(a, b, l);
+ return cmp ? cmp : (alen-blen);
+}
+
// Unicode case-insensitive compare two same-sized strings
static int ucstrnicmp(const ushort *a, const ushort *b, int l)
{