[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#792594: libqt5qml5 requires SSE2 on i386



Hi!

On Sun, 2017-01-01 at 11:41:45 -0300, Lisandro Damián Nicanor Pérez Meyer wrote:
> On domingo, 1 de enero de 2017 04:13:41 ART Guillem Jover wrote:
> [snip]
> > > In any case, because I need a patched Qt on my systems to be
> > > able to run many Qt applications at all, I'll have to rebase the patches
> > > and build local packages anyway. I'll try to send the rebased patches
> > > here for whoever else needs them, if I remember.
> > 
> > As I had to upgrade all the systems involved, I needed to update
> > the patches, which I did against 5.7.x and 5.8.x (git HEAD).
> > 
> > > If someone else wants access to the Qt Declaratives packages I'm
> > > building please say so, and I'll publish them on some repository.
> > 
> > This still stands.
> 
> And you are really willing to take care of this delta, so let's make it 
> official.

Ah, perfect thanks! And well, as long as I've got such hardware I'll
have to do that anyway, yes.

> The only thing I would like you to change in order to accept the patch is to 
> change the generic hasRequiredCpuSupport() for something more precise, maybe 
> something along cpuHasSse2Support() or alike. Yes, I know it's just details, 
> but helps while looking at the code.

I think we might have covered this in the past reviews, but in any
case I think that would be very confusing, because on non-i386 such
cpuHasSse2Support() function would need to return true, which is very
much not correct. :) I've left it as is, but reworked the text message
handling so that it's also generic now. Hope that qualms your concerns.

Actually, I didn't like that either, and reworked it even further (v2),
but I've not build tested that one yet.

Attached both updated patches, for which I've only built tested the first
one for now, but I'd not expect any run-time problems. But I'll try to do
that for the second one tomorrow.

Thanks,
Guillem
From 8020224f94ff24b6bafd59613427ed91bf8c341e Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Mon, 12 Oct 2015 01:45:37 +0200
Subject: [PATCH] Do not make lack of SSE2 support on x86-32 fatal

When an x86-32 CPU does not have SSE2 support (which is the case for
all AMD CPUs, and older Intel CPUs), fallback to use the interpreter,
otherwise use the JIT engine.

Even then, make the lack of SSE2 support on x86-32 fatal when trying
to instantiate a JIT engine, which does require it.

Refactor the required CPU support check and text into a new pair of
privately exported functions to avoid duplicating the logic, and do
so in functions instead of class members to avoid changing the class
signatures.

Version: 5.7.x
Bug-Debian: https://bugs.debian.org/792594
---
 src/qml/jit/qv4isel_masm.cpp    |  3 +++
 src/qml/jit/qv4isel_masm_p.h    | 19 +++++++++++++++++++
 src/qml/jsruntime/qv4engine.cpp |  1 +
 src/qml/qml/v8/qv8engine.cpp    |  7 -------
 tools/qmljs/qmljs.cpp           |  7 +++----
 5 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp
index d047623ac..5be02998e 100644
--- a/src/qml/jit/qv4isel_masm.cpp
+++ b/src/qml/jit/qv4isel_masm.cpp
@@ -265,6 +265,9 @@ InstructionSelection::InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::Ex
     , compilationUnit(new CompilationUnit)
     , qmlEngine(qmlEngine)
 {
+    if (!hasRequiredCpuSupport())
+        qFatal("This program requires %s", getRequiredCpuSupportText());
+
     compilationUnit->codeRefs.resize(module->functions.size());
 }
 
diff --git a/src/qml/jit/qv4isel_masm_p.h b/src/qml/jit/qv4isel_masm_p.h
index 1e6ac1f51..0f48f9c01 100644
--- a/src/qml/jit/qv4isel_masm_p.h
+++ b/src/qml/jit/qv4isel_masm_p.h
@@ -59,6 +59,7 @@
 
 #include <QtCore/QHash>
 #include <QtCore/QStack>
+#include <private/qsimd_p.h>
 #include <config.h>
 #include <wtf/Vector.h>
 
@@ -71,6 +72,24 @@ QT_BEGIN_NAMESPACE
 namespace QV4 {
 namespace JIT {
 
+Q_QML_PRIVATE_EXPORT inline bool hasRequiredCpuSupport()
+{
+#ifdef Q_PROCESSOR_X86_32
+    return qCpuHasFeature(SSE2);
+#else
+    return true;
+#endif
+}
+
+Q_QML_PRIVATE_EXPORT inline const char *getRequiredCpuSupportText()
+{
+#ifdef Q_PROCESSOR_X86_32
+    return "an X86 processor that supports SSE2 extension, at least a Pentium 4 or newer";
+#else
+    return "no specific processor features, something strange happened";
+#endif
+}
+
 class Q_QML_EXPORT InstructionSelection:
         protected IR::IRDecoder,
         public EvalInstructionSelection
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 26f473a7a..5e4100ac0 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -162,6 +162,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
 
 #ifdef V4_ENABLE_JIT
         static const bool forceMoth = !qEnvironmentVariableIsEmpty("QV4_FORCE_INTERPRETER") ||
+                                      !JIT::hasRequiredCpuSupport() ||
                                       !OSAllocator::canAllocateExecutableMemory();
         if (forceMoth) {
             factory = new Moth::ISelFactory;
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 46fd4fbbe..20ed1ddb4 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -65,7 +65,6 @@
 #include <QtCore/qjsonvalue.h>
 #include <QtCore/qdatetime.h>
 #include <QtCore/qdatastream.h>
-#include <private/qsimd_p.h>
 
 #include <private/qv4value_p.h>
 #include <private/qv4dateobject_p.h>
@@ -130,12 +129,6 @@ QV8Engine::QV8Engine(QJSEngine* qq)
     , m_xmlHttpRequestData(0)
     , m_listModelData(0)
 {
-#ifdef Q_PROCESSOR_X86_32
-    if (!qCpuHasFeature(SSE2)) {
-        qFatal("This program requires an X86 processor that supports SSE2 extension, at least a Pentium 4 or newer");
-    }
-#endif
-
     QML_MEMORY_SCOPE_STRING("QV8Engine::QV8Engine");
     qMetaTypeId<QJSValue>();
     qMetaTypeId<QList<int> >();
diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp
index 68aa52ce9..94b10f2b3 100644
--- a/tools/qmljs/qmljs.cpp
+++ b/tools/qmljs/qmljs.cpp
@@ -135,11 +135,10 @@ int main(int argc, char *argv[])
     enum {
         use_masm,
         use_moth
-    } mode;
+    } mode = use_moth;
 #ifdef V4_ENABLE_JIT
-    mode = use_masm;
-#else
-    mode = use_moth;
+    if (QV4::JIT::hasRequiredCpuSupport())
+        mode = use_masm;
 #endif
 
     bool runAsQml = false;
-- 
2.11.0

From 4950c366b12265f1ea390a6feb8dbbd0d850d206 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Mon, 12 Oct 2015 01:45:37 +0200
Subject: [PATCH v2] Do not make lack of SSE2 support on x86-32 fatal

When an x86-32 CPU does not have SSE2 support (which is the case for
all AMD CPUs, and older Intel CPUs), fallback to use the interpreter,
otherwise use the JIT engine.

Even then, make the lack of SSE2 support on x86-32 fatal when trying
to instantiate a JIT engine, which does require it.

Refactor the required CPU support check into a new pair of privately
exported functions to avoid duplicating the logic, and do so in
functions instead of class members to avoid changing the class
signatures.

Version: 5.7.x
Bug-Debian: https://bugs.debian.org/792594
---
 src/qml/jit/qv4isel_masm.cpp    |  2 ++
 src/qml/jit/qv4isel_masm_p.h    | 18 ++++++++++++++++++
 src/qml/jsruntime/qv4engine.cpp |  1 +
 src/qml/qml/v8/qv8engine.cpp    |  7 -------
 tools/qmljs/qmljs.cpp           |  7 +++----
 5 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp
index d047623ac..5c149f9d2 100644
--- a/src/qml/jit/qv4isel_masm.cpp
+++ b/src/qml/jit/qv4isel_masm.cpp
@@ -265,6 +265,8 @@ InstructionSelection::InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::Ex
     , compilationUnit(new CompilationUnit)
     , qmlEngine(qmlEngine)
 {
+    checkRequiredCpuSupport();
+
     compilationUnit->codeRefs.resize(module->functions.size());
 }
 
diff --git a/src/qml/jit/qv4isel_masm_p.h b/src/qml/jit/qv4isel_masm_p.h
index 1e6ac1f51..d6c1b414f 100644
--- a/src/qml/jit/qv4isel_masm_p.h
+++ b/src/qml/jit/qv4isel_masm_p.h
@@ -59,6 +59,7 @@
 
 #include <QtCore/QHash>
 #include <QtCore/QStack>
+#include <private/qsimd_p.h>
 #include <config.h>
 #include <wtf/Vector.h>
 
@@ -71,6 +72,23 @@ QT_BEGIN_NAMESPACE
 namespace QV4 {
 namespace JIT {
 
+Q_QML_PRIVATE_EXPORT inline bool hasRequiredCpuSupport()
+{
+#ifdef Q_PROCESSOR_X86_32
+    return qCpuHasFeature(SSE2);
+#else
+    return true;
+#endif
+}
+
+Q_QML_PRIVATE_EXPORT inline void checkRequiredCpuSupport()
+{
+#ifdef Q_PROCESSOR_X86_32
+    if (!qCpuHasFeature(SSE2))
+        qFatal("This program requires an X86 processor that supports SSE2 extension, at least a Pentium 4 or newer");
+#endif
+}
+
 class Q_QML_EXPORT InstructionSelection:
         protected IR::IRDecoder,
         public EvalInstructionSelection
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 26f473a7a..5e4100ac0 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -162,6 +162,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
 
 #ifdef V4_ENABLE_JIT
         static const bool forceMoth = !qEnvironmentVariableIsEmpty("QV4_FORCE_INTERPRETER") ||
+                                      !JIT::hasRequiredCpuSupport() ||
                                       !OSAllocator::canAllocateExecutableMemory();
         if (forceMoth) {
             factory = new Moth::ISelFactory;
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 46fd4fbbe..20ed1ddb4 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -65,7 +65,6 @@
 #include <QtCore/qjsonvalue.h>
 #include <QtCore/qdatetime.h>
 #include <QtCore/qdatastream.h>
-#include <private/qsimd_p.h>
 
 #include <private/qv4value_p.h>
 #include <private/qv4dateobject_p.h>
@@ -130,12 +129,6 @@ QV8Engine::QV8Engine(QJSEngine* qq)
     , m_xmlHttpRequestData(0)
     , m_listModelData(0)
 {
-#ifdef Q_PROCESSOR_X86_32
-    if (!qCpuHasFeature(SSE2)) {
-        qFatal("This program requires an X86 processor that supports SSE2 extension, at least a Pentium 4 or newer");
-    }
-#endif
-
     QML_MEMORY_SCOPE_STRING("QV8Engine::QV8Engine");
     qMetaTypeId<QJSValue>();
     qMetaTypeId<QList<int> >();
diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp
index 68aa52ce9..94b10f2b3 100644
--- a/tools/qmljs/qmljs.cpp
+++ b/tools/qmljs/qmljs.cpp
@@ -135,11 +135,10 @@ int main(int argc, char *argv[])
     enum {
         use_masm,
         use_moth
-    } mode;
+    } mode = use_moth;
 #ifdef V4_ENABLE_JIT
-    mode = use_masm;
-#else
-    mode = use_moth;
+    if (QV4::JIT::hasRequiredCpuSupport())
+        mode = use_masm;
 #endif
 
     bool runAsQml = false;
-- 
2.11.0


Reply to: