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)
committerDmitry Shachnev <mitya57@debian.org>
Thu, 26 Oct 2017 13:27:02 +0000 (14:27 +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 50d40f6f98fd2e96926582cf772770c75f1c68b8..1396956eafd43f72b807218024af4f4f563b8659 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 0992e96e8b7d73b24b55f13b9ea74f0d22404c4b..1da0033d102a5eb772ed103c4517cbcd9e3b4baf 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 54011e6bd23bb26e076e08ee391eb202676589d7..6c84826d19ef48488cd630175b89527ba894c270 100644 (file)
@@ -159,6 +159,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 14a20731c0d7635ac9e55a31bf4265e60678bc45..3183bfe868eb97158bcc2803348b02a2208508d9 100644 (file)
@@ -92,11 +92,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;