Please nominate your Qt Champions for 2021!

Regarding Qt configuration and SSE/SSE2

  • Hi.

    I generally try to make my applications as compatible as possible.

    However the following configuration options of Qt came to my attention recently:

    @ + -mmx ............... Compile with use of MMX instructions

    • -3dnow ............. Compile with use of 3DNOW instructions
    • -sse ............... Compile with use of SSE instructions
    • -sse2 .............. Compile with use of SSE2 instructions@

    These are enabled by default, it seems.

    Does "Compile with use of SSE2 instructions" mean that the Qt binary will actually (potentially) use SSE2-instructions on all code paths or does it mean that there will be a SSE2-optimized code path that is used only if supported by the CPU? Or in other words: Does Qt internally apply Runtime CPU-Detection?

    BTW: In the Visual Studio project settings I have disabled the generation of SSE/SSE2 code. Would Qt still use SSE or SSE2 instructions (e.g. via Assembly or via Intrinsics) when "-sse" or "-sse2" have been set?

  • Okay, after searching the code a bit, I found this:

    @ const uint features = qDetectCPUFeatures();

    #ifdef QT_HAVE_SSE2
    if (features & SSE2) {
    extern bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags);
    inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_sse2;

    So am I right that the "-sse2" configure option will define QT_HAVE_SSE2 and will enable CPU Runtime Detection for SSE2, but it won't enable SSE2 optimizations in a "hardcoded" way?

  • As far as I've tested, if Qt library is compiled with SSE2 and machine does not have the SSE2 support, your Qt application will crash with "The application failed to initialize properly "0xc000001d"" error message.

    Not sure why, but when I try to compile Qt with "-no-sse2" flag - I'm getting some compiler errors while compiling the qtgui library...

  • I have had same question for a long time ago. I'm not sure, but I remember I have checked the source code of Qt regarding instruction checks etc... and found what Qt checks for supported instruction before it is executed/method selected...

    But I can be wrong, I don't really remember if it was in Qt already or it was a patch or I have merged this checks from other code when I was playing with asm and SSE instructions....

    Maybe some Qt Dev-Trolls can answer this for us. Have you asked your question on IRC channel?

  • Yes, I checked it too and found that Qt will only execute MMX/3DNOW/SSE/SSE2 code paths after a CPU runtime check. But that of course only applies to the special "hand optimized" assembler code in Qt.

    MMX/SSE/SSE2 instructions might be used in any plain C/C++ code, unconditionally, if enabled in the compiler settings. Up to and including VS2010, the default was that SSE or SSE2 are disabled by default (aka "not set"). But starting VS2012, the default (aka "not set") now is SSE2. You need to select "IA32" for max compatibility.

Log in to reply