summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qlibrary_unix.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-06-20 15:20:32 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-07-09 00:18:27 +0000
commit5219c37f7c98f37f078fee00fe8ca35d83ff4f5d (patch)
treeb1d8264e2fe35b22fd5bd3363d6c07342bcc8f1a /src/corelib/plugin/qlibrary_unix.cpp
parentc3a4ec5d0bbd5f2710f4fd1d3bd4a2d7f0f507ad (diff)
QLibrary: find AVX2 (Haswell) optimized plugins and libraries
Libraries are placed in a subdir "haswell/" of the main library dir, whereas plugins are simply named with ".avx2" appended to the plugin name (plugin.so.avx2). The "haswell/" library directory suffix is a convention found in glibc since version 2.26, whereas the ".avx2" and ".avx512" suffixes are a convention found in the Clear Linux OS for Intel Architecture. This patch implements this for all Unix OSes, except for Darwin, where the fat file format already has a sub-architecture for Haswell (x86_64h). We could also implement the "sse2/" subdir search for libraries, but I don't think it's worth the cost in 2018. Change-Id: Iff4151c519c144d580c4fffd1539fe5ee9a4d7b1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/plugin/qlibrary_unix.cpp')
-rw-r--r--src/corelib/plugin/qlibrary_unix.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp
index 23b9ad6434..7ffd1369b9 100644
--- a/src/corelib/plugin/qlibrary_unix.cpp
+++ b/src/corelib/plugin/qlibrary_unix.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2018 Intel Corporation
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -43,6 +44,7 @@
#include "qlibrary_p.h"
#include <qcoreapplication.h>
#include <private/qfilesystementry_p.h>
+#include <private/qsimd_p.h>
#include <dlfcn.h>
@@ -178,6 +180,27 @@ bool QLibraryPrivate::load_sys()
prefixes.append(QString());
}
+#if defined(Q_PROCESSOR_X86) && !defined(Q_OS_DARWIN)
+ if (qCpuHasFeature(ArchHaswell)) {
+ auto transform = [](QStringList &list, QString (*f)(QString)) {
+ QStringList tmp;
+ qSwap(tmp, list);
+ list.reserve(tmp.size() * 2);
+ for (const QString &s : qAsConst(tmp)) {
+ list.append(f(s));
+ list.append(s);
+ }
+ };
+ if (pluginState == IsAPlugin) {
+ // add ".avx2" to each suffix in the list
+ transform(suffixes, [](QString s) { return s.append(QLatin1String(".avx2")); });
+ } else {
+ // prepend "haswell/" to each prefix in the list
+ transform(prefixes, [](QString s) { return s.prepend(QLatin1String("haswell/")); });
+ }
+ }
+#endif
+
bool retry = true;
for(int prefix = 0; retry && !pHnd && prefix < prefixes.size(); prefix++) {
for(int suffix = 0; retry && !pHnd && suffix < suffixes.size(); suffix++) {