x86: Add detection of the AES and SHA New Instructions

The AES instructions were first introduced with the Westmere shrink
(22nm) of the Nehalem architecture. The SHA instructions are still
pending on Intel architecture, but is available on AMD family 17h (gcc
argument -march=znver1).

Both features operate on SSE registers, so that's why the MSVC command-
line argument is the SSE2 one and the configure-time tests depend on
features.sse2.

The qmake feature names end in "ni" because "aes" and "sha" are too
simple and could clash with other uses. The QT_COMPILER_SUPPORTS_ macro
doesn't have the "NI" suffix because it has to match the GCC/Clang
predefined macro.

Change-Id: I445bb15619f6401494e8fffd149dbd1f862ff51c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Thiago Macieira 2017-01-27 13:09:55 -08:00
parent db1c8553a1
commit 0f1b6acab7
15 changed files with 150 additions and 1 deletions

View File

@ -0,0 +1,49 @@
/****************************************************************************
**
** Copyright (C) 2017 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the config.tests of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <wmmintrin.h>
int main(int, char**)
{
__m128i a = _mm_setzero_si128();
__m128i b = _mm_aesenc_si128(a, a);
__m128i c = _mm_aesdec_si128(a, b);
(void)c;
return 0;
}

View File

@ -0,0 +1,3 @@
SOURCES = aesni.cpp
!defined(QMAKE_CFLAGS_AESNI, "var"): error("This compiler does not support AES New Instructions")
else: QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_AESNI

View File

@ -0,0 +1,50 @@
/****************************************************************************
**
** Copyright (C) 2017 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the config.tests of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <immintrin.h>
int main(int, char**)
{
__m128i a = _mm_setzero_si128();
__m128i b = _mm_sha1rnds4_epu32(a, a, 0);
__m128i c = _mm_sha1msg1_epu32(a, b);
__m128i d = _mm_sha256msg2_epu32(b, c);
(void)d;
return 0;
}

View File

@ -0,0 +1,3 @@
SOURCES = shani.cpp
!defined(QMAKE_CFLAGS_SHANI, "var"): error("This compiler does not support Secure Hash Algorithm extensions")
else: QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SHANI

View File

@ -317,11 +317,21 @@
"type": "compile", "type": "compile",
"test": "common/sse4_2" "test": "common/sse4_2"
}, },
"aesni": {
"label": "AES new instructions",
"type": "compile",
"test": "common/aesni"
},
"f16c": { "f16c": {
"label": "F16C instructions", "label": "F16C instructions",
"type": "compile", "type": "compile",
"test": "common/f16c" "test": "common/f16c"
}, },
"shani": {
"label": "SHA new instructions",
"type": "compile",
"test": "common/shani"
},
"avx": { "avx": {
"label": "AVX instructions", "label": "AVX instructions",
"type": "compile", "type": "compile",
@ -871,6 +881,22 @@
{ "type": "define", "name": "QT_COMPILER_SUPPORTS_AVX512VBMI", "value": 1 } { "type": "define", "name": "QT_COMPILER_SUPPORTS_AVX512VBMI", "value": 1 }
] ]
}, },
"aesni": {
"label": "aesni",
"condition": "features.sse2 && tests.aesni",
"output": [
"privateConfig",
{ "type": "define", "name": "QT_COMPILER_SUPPORTS_AES", "value": 1 }
]
},
"shani": {
"label": "shani",
"condition": "features.sse2 && tests.shani",
"output": [
"privateConfig",
{ "type": "define", "name": "QT_COMPILER_SUPPORTS_SHA", "value": 1 }
]
},
"mips_dsp": { "mips_dsp": {
"label": "DSP", "label": "DSP",
"condition": "arch.mips && tests.mips_dsp", "condition": "arch.mips && tests.mips_dsp",

View File

@ -97,6 +97,8 @@ QMAKE_CFLAGS_AVX512BW += -mavx512bw
QMAKE_CFLAGS_AVX512VL += -mavx512vl QMAKE_CFLAGS_AVX512VL += -mavx512vl
QMAKE_CFLAGS_AVX512IFMA += -mavx512ifma QMAKE_CFLAGS_AVX512IFMA += -mavx512ifma
QMAKE_CFLAGS_AVX512VBMI += -mavx512vbmi QMAKE_CFLAGS_AVX512VBMI += -mavx512vbmi
QMAKE_CFLAGS_AESNI += -maes
QMAKE_CFLAGS_SHANI += -msha
QMAKE_CFLAGS_NEON += -mfpu=neon QMAKE_CFLAGS_NEON += -mfpu=neon
QMAKE_CFLAGS_MIPS_DSP += -mdsp QMAKE_CFLAGS_MIPS_DSP += -mdsp
QMAKE_CFLAGS_MIPS_DSPR2 += -mdspr2 QMAKE_CFLAGS_MIPS_DSPR2 += -mdspr2

View File

@ -44,6 +44,8 @@ QMAKE_CFLAGS_SSE3 = $$QMAKE_CFLAGS_SSE2
QMAKE_CFLAGS_SSSE3 = $$QMAKE_CFLAGS_SSE2 QMAKE_CFLAGS_SSSE3 = $$QMAKE_CFLAGS_SSE2
QMAKE_CFLAGS_SSE4_1 = $$QMAKE_CFLAGS_SSE2 QMAKE_CFLAGS_SSE4_1 = $$QMAKE_CFLAGS_SSE2
QMAKE_CFLAGS_SSE4_2 = $$QMAKE_CFLAGS_SSE2 QMAKE_CFLAGS_SSE4_2 = $$QMAKE_CFLAGS_SSE2
QMAKE_CFLAGS_AESNI = $$QMAKE_CFLAGS_SSE2
QMAKE_CFLAGS_SHANI = $$QMAKE_CFLAGS_SSE2
QMAKE_CXX = $$QMAKE_CC QMAKE_CXX = $$QMAKE_CC
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS QMAKE_CXXFLAGS = $$QMAKE_CFLAGS

View File

@ -33,6 +33,8 @@ QMAKE_CFLAGS_SSE4_1 += -msse4.1
QMAKE_CFLAGS_SSE4_2 += -msse4.2 QMAKE_CFLAGS_SSE4_2 += -msse4.2
QMAKE_CFLAGS_AVX += -mavx QMAKE_CFLAGS_AVX += -mavx
QMAKE_CFLAGS_AVX2 += -mavx2 QMAKE_CFLAGS_AVX2 += -mavx2
QMAKE_CFLAGS_AESNI += -maes
QMAKE_CFLAGS_SHANI += -msha
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS -lang-c++ QMAKE_CXXFLAGS += $$QMAKE_CFLAGS -lang-c++
QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS

View File

@ -34,6 +34,8 @@ QMAKE_CFLAGS_SSE4_1 = -arch:SSE2
QMAKE_CFLAGS_SSE4_2 = -arch:SSE2 QMAKE_CFLAGS_SSE4_2 = -arch:SSE2
QMAKE_CFLAGS_AVX = -arch:AVX QMAKE_CFLAGS_AVX = -arch:AVX
QMAKE_CFLAGS_AVX2 = -arch:AVX QMAKE_CFLAGS_AVX2 = -arch:AVX
QMAKE_CFLAGS_AESNI = -arch:SSE2
QMAKE_CFLAGS_SHANI = -arch:SSE2
QMAKE_CXX = $$QMAKE_CC QMAKE_CXX = $$QMAKE_CC
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS QMAKE_CXXFLAGS = $$QMAKE_CFLAGS

View File

@ -93,6 +93,8 @@ addSimdCompiler(sse3)
addSimdCompiler(ssse3) addSimdCompiler(ssse3)
addSimdCompiler(sse4_1) addSimdCompiler(sse4_1)
addSimdCompiler(sse4_2) addSimdCompiler(sse4_2)
addSimdCompiler(aesni)
addSimdCompiler(shani)
addSimdCompiler(avx) addSimdCompiler(avx)
addSimdCompiler(avx2) addSimdCompiler(avx2)
addSimdCompiler(avx512f) addSimdCompiler(avx512f)

View File

@ -42,6 +42,8 @@ QMAKE_CFLAGS_AVX512PF += -xMIC-AVX512
QMAKE_CFLAGS_AVX512DQ += -xCORE-AVX512 QMAKE_CFLAGS_AVX512DQ += -xCORE-AVX512
QMAKE_CFLAGS_AVX512BW += -xCORE-AVX512 QMAKE_CFLAGS_AVX512BW += -xCORE-AVX512
QMAKE_CFLAGS_AVX512VL += -xCORE-AVX512 QMAKE_CFLAGS_AVX512VL += -xCORE-AVX512
QMAKE_CFLAGS_AESNI += -maes
QMAKE_CFLAGS_SHANI += -msha
QMAKE_CXX = icpc QMAKE_CXX = icpc
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS QMAKE_CXXFLAGS = $$QMAKE_CFLAGS

View File

@ -40,6 +40,8 @@ QMAKE_CFLAGS_AVX512PF += -xMIC-AVX512
QMAKE_CFLAGS_AVX512DQ += -xCORE-AVX512 QMAKE_CFLAGS_AVX512DQ += -xCORE-AVX512
QMAKE_CFLAGS_AVX512BW += -xCORE-AVX512 QMAKE_CFLAGS_AVX512BW += -xCORE-AVX512
QMAKE_CFLAGS_AVX512VL += -xCORE-AVX512 QMAKE_CFLAGS_AVX512VL += -xCORE-AVX512
QMAKE_CFLAGS_AESNI += -maes
QMAKE_CFLAGS_SHANI += -msha
QMAKE_CXX = icpc QMAKE_CXX = icpc
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS QMAKE_CXXFLAGS = $$QMAKE_CFLAGS

View File

@ -28,6 +28,8 @@ QMAKE_YACCFLAGS = -d
QMAKE_CFLAGS += -fno-keep-inline-dllexport QMAKE_CFLAGS += -fno-keep-inline-dllexport
QMAKE_CFLAGS_WARN_ON += -Wextra QMAKE_CFLAGS_WARN_ON += -Wextra
QMAKE_CFLAGS_SSE2 += -mstackrealign QMAKE_CFLAGS_SSE2 += -mstackrealign
QMAKE_CFLAGS_AESNI = -maes
QMAKE_CFLAGS_SHANI = -msha
QMAKE_CXX = $${CROSS_COMPILE}g++ QMAKE_CXX = $${CROSS_COMPILE}g++
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD

View File

@ -33,6 +33,8 @@ QMAKE_CFLAGS_AVX512PF += -QxMIC-AVX512
QMAKE_CFLAGS_AVX512DQ += -QxCORE-AVX512 QMAKE_CFLAGS_AVX512DQ += -QxCORE-AVX512
QMAKE_CFLAGS_AVX512BW += -QxCORE-AVX512 QMAKE_CFLAGS_AVX512BW += -QxCORE-AVX512
QMAKE_CFLAGS_AVX512VL += -QxCORE-AVX512 QMAKE_CFLAGS_AVX512VL += -QxCORE-AVX512
QMAKE_CFLAGS_AESNI = -QxSSE2
QMAKE_CFLAGS_SHANI = -QxSSE4.2
QMAKE_CXX = $$QMAKE_CC QMAKE_CXX = $$QMAKE_CC
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS /Zc:forScope QMAKE_CXXFLAGS = $$QMAKE_CFLAGS /Zc:forScope

View File

@ -261,7 +261,7 @@
# endif # endif
#endif #endif
#if defined(__AES__) || defined(__PCLMUL__) #if defined(__AES__) || defined(__PCLMUL__) || (defined(QT_COMPILER_SUPPORTS_AES) && defined(QT_COMPILER_SUPPORTS_SIMD_ALWAYS))
# include <wmmintrin.h> # include <wmmintrin.h>
#endif #endif