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>
This commit is contained in:
Thiago Macieira 2018-06-20 15:20:32 -07:00
parent c3a4ec5d0b
commit 5219c37f7c
2 changed files with 28 additions and 0 deletions

View File

@ -133,6 +133,11 @@ void QFactoryLoader::update()
// versions of the same Qt libraries (due to the plugin's dependencies).
if (isDebugPlugin != isDebugLibrary)
continue;
#elif defined(Q_PROCESSOR_X86)
if (fileName.endsWith(QLatin1String(".avx2")) || fileName.endsWith(QLatin1String(".avx512"))) {
// ignore AVX2-optimized file, we'll do a bait-and-switch to it later
continue;
}
#endif
if (qt_debug_component()) {
qDebug() << "QFactoryLoader::QFactoryLoader() looking at" << fileName;

View File

@ -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++) {