Skip to content

Commit

Permalink
Fix detection of F16C for the Intel compiler (again) and Visual Studio
Browse files Browse the repository at this point in the history
Neither the Intel compiler nor Visual C++ have a dedicated switch to
enable F16C support, like GCC and Clang do. So we used the AVX switch
for that in commit 8241d51, as it was
the closest, lowest denominator. That was incorrect and insufficient.

The Intel compiler silently miscompiles the intrinsics with -xAVX,
making calls to out-of-line functions like _mm_cvtps_ph, which don't
exist. So we actually have to use AVX2 support to generate correct code.
That might be a problem later, since Ivy Bridge supports F16C but not
AVX2.

Visual C++ is able to generate F16C code with just -arch:AVX.

Either way, since there's no dedicated command-line switch, there's also
no dedicated preprocessor macro. We're using __AVX2__ for both
compilers, as that's a sufficient condition to indicate a processor that
supports F16C.

Change-Id: I27b55fdf514247549455fffd14b205b8d8b86da7
Reviewed-by: Allan Sandfeld Jensen <[email protected]>
  • Loading branch information
thiagomacieira committed Apr 6, 2017
1 parent c817b33 commit 280e321
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mkspecs/common/msvc-version.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ greaterThan(QMAKE_MSC_VER, 1799) {
QMAKE_CFLAGS += -FS
QMAKE_CXXFLAGS += -FS

QMAKE_CFLAGS_F16C = -arch:AVX

equals(QMAKE_MSC_VER, 1800) {
QMAKE_CFLAGS_RELEASE += -Zc:strictStrings
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -Zc:strictStrings
Expand Down
2 changes: 1 addition & 1 deletion mkspecs/linux-icc/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ QMAKE_CFLAGS_AVX512PF += -xMIC-AVX512
QMAKE_CFLAGS_AVX512DQ += -xCORE-AVX512
QMAKE_CFLAGS_AVX512BW += -xCORE-AVX512
QMAKE_CFLAGS_AVX512VL += -xCORE-AVX512
QMAKE_CFLAGS_F16C += -xAVX
QMAKE_CFLAGS_F16C += $$QMAKE_CFLAGS_AVX2

QMAKE_CXX = icpc
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
Expand Down
2 changes: 1 addition & 1 deletion mkspecs/macx-icc/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ QMAKE_CFLAGS_AVX512PF += -xMIC-AVX512
QMAKE_CFLAGS_AVX512DQ += -xCORE-AVX512
QMAKE_CFLAGS_AVX512BW += -xCORE-AVX512
QMAKE_CFLAGS_AVX512VL += -xCORE-AVX512
QMAKE_CFLAGS_F16C += -xAVX
QMAKE_CFLAGS_F16C += $$QMAKE_CFLAGS_AVX2

QMAKE_CXX = icpc
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
Expand Down
2 changes: 1 addition & 1 deletion mkspecs/win32-icc/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QMAKE_CFLAGS_AVX512PF += -QxMIC-AVX512
QMAKE_CFLAGS_AVX512DQ += -QxCORE-AVX512
QMAKE_CFLAGS_AVX512BW += -QxCORE-AVX512
QMAKE_CFLAGS_AVX512VL += -QxCORE-AVX512
QMAKE_CFLAGS_F16C = -QxAVX
QMAKE_CFLAGS_F16C = $$QMAKE_CFLAGS_AVX2

QMAKE_CXX = $$QMAKE_CC
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS /Zc:forScope
Expand Down
4 changes: 2 additions & 2 deletions src/corelib/global/qfloat16.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wc99-extensions")
inline qfloat16::qfloat16(float f) Q_DECL_NOTHROW
{
#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
#if defined(QT_COMPILER_SUPPORTS_F16C) && (defined(__F16C__) || defined(__AVX2__))
__m128 packsingle = _mm_set_ss(f);
__m128i packhalf = _mm_cvtps_ph(packsingle, 0);
b16 = _mm_extract_epi16(packhalf, 0);
Expand All @@ -135,7 +135,7 @@ QT_WARNING_POP

inline qfloat16::operator float() const Q_DECL_NOTHROW
{
#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
#if defined(QT_COMPILER_SUPPORTS_F16C) && (defined(__F16C__) || defined(__AVX2__))
__m128i packhalf = _mm_cvtsi32_si128(b16);
__m128 packsingle = _mm_cvtph_ps(packhalf);
return _mm_cvtss_f32(packsingle);
Expand Down

0 comments on commit 280e321

Please sign in to comment.