Do not make lack of SSE2 support on x86-32 fatal
authorGuillem Jover <guillem@hadrons.org>
Sun, 11 Oct 2015 23:45:37 +0000 (01:45 +0200)
committerSimon Quigley <tsimonq2@ubuntu.com>
Mon, 9 Apr 2018 23:44:03 +0000 (00:44 +0100)
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

Gbp-Pq: Name Do-not-make-lack-of-SSE2-support-on-x86-32-fatal.patch

src/qml/jit/qv4isel_masm.cpp
src/qml/jit/qv4isel_masm_p.h
src/qml/jsruntime/qv4engine.cpp
src/qml/qml/v8/qv8engine.cpp
tools/qmljs/qmljs.cpp

index a35b12d51ee2d2f170216a81c3fcba9eb583fb74..1b8120f250b6f1ca06f1637b9e10f045423c5bfb 100644 (file)
@@ -72,6 +72,8 @@ InstructionSelection<JITAssembler>::InstructionSelection(QQmlEnginePrivate *qmlE
     , compilationUnit(new CompilationUnit)
     , qmlEngine(qmlEngine)
 {
+    checkRequiredCpuSupport();
+
     compilationUnit->codeRefs.resize(module->functions.size());
     module->unitFlags |= QV4::CompiledData::Unit::ContainsMachineCode;
 }
index 7019a117a2d270054b539d9709a1d2eab798224c..7eb9ccef5339831e67f3c4370781d40e4d89c01b 100644 (file)
@@ -60,6 +60,7 @@
 
 #include <QtCore/QHash>
 #include <QtCore/QStack>
+#include <private/qsimd_p.h>
 #include <config.h>
 #include <wtf/Vector.h>
 
@@ -72,6 +73,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
+}
+
 template <typename JITAssembler = Assembler<DefaultAssemblerTargetConfiguration>>
 class Q_QML_EXPORT InstructionSelection:
         protected IR::IRDecoder,
index f19f134c535edcdc2e092bd6df119b73a7f58fb9..47b832d79146c1eb9b42175d7ba2911065e3e96d 100644 (file)
@@ -160,6 +160,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;
index dadff819cffb156ca457107fe7049ed895497e30..0a53d26d896a49f1732bd81e9e0251da205f1afe 100644 (file)
@@ -64,7 +64,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>
@@ -129,12 +128,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> >();
index 83245c4295c86f62be6e65565e9dbcb63212868d..ddc75d0ccea9511e4d76d3f8f231399adb1425cd 100644 (file)
@@ -90,11 +90,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;