From e157d4567738df5cb009a3304ca910501d77585f Mon Sep 17 00:00:00 2001 From: Julia Koval Date: Tue, 12 Dec 2017 06:55:23 +0100 Subject: [PATCH] Enable VAES support [2/5] gcc/ * config.gcc: Add vaesintrin.h. * config/i386/i386-builtin-types.def (V64QI_FTYPE_V64QI_V64QI): New type. * config/i386/i386-builtin.def (__builtin_ia32_vaesdec_v16qi, __builtin_ia32_vaesdec_v32qi, __builtin_ia32_vaesdec_v64qi): New builtins. * config/i386/i386.c (ix86_expand_args_builtin): Handle new type. * config/i386/immintrin.h: Include vaesintrin.h. * config/i386/sse.md (vaesdec_): New pattern. * config/i386/vaesintrin.h (_mm256_aesdec_epi128, _mm512_aesdec_epi128, _mm_aesdec_epi128): New intrinsics. gcc/testsuite/ * gcc.target/i386/avx512-check.h: Handle bit_VAES. * gcc.target/i386/avx512f-aesdec-2.c: New test. * gcc.target/i386/avx512fvl-vaes-1.c: Ditto. * gcc.target/i386/avx512vl-aesdec-2.c: Ditto. * gcc.target/i386/i386.exp (check_effective_target_avx512vaes): New. From-SVN: r255572 --- gcc/ChangeLog | 12 ++++ gcc/config.gcc | 4 +- gcc/config/i386/i386-builtin.def | 5 ++ gcc/config/i386/immintrin.h | 2 + gcc/config/i386/sse.md | 16 +++++ gcc/config/i386/vaesintrin.h | 59 +++++++++++++++++++ gcc/testsuite/ChangeLog | 8 +++ gcc/testsuite/gcc.target/i386/avx512-check.h | 3 + .../gcc.target/i386/avx512f-aesdec-2.c | 52 ++++++++++++++++ .../gcc.target/i386/avx512fvl-vaes-1.c | 24 ++++++++ .../gcc.target/i386/avx512vl-aesdec-2.c | 17 ++++++ gcc/testsuite/gcc.target/i386/i386.exp | 14 +++++ 12 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 gcc/config/i386/vaesintrin.h create mode 100644 gcc/testsuite/gcc.target/i386/avx512f-aesdec-2.c create mode 100644 gcc/testsuite/gcc.target/i386/avx512fvl-vaes-1.c create mode 100644 gcc/testsuite/gcc.target/i386/avx512vl-aesdec-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 62f1c240b2a..9ec6f5f6d14 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2017-12-12 Julia Koval + + * config.gcc: Add vaesintrin.h. + * config/i386/i386-builtin-types.def (V64QI_FTYPE_V64QI_V64QI): New type. + * config/i386/i386-builtin.def (__builtin_ia32_vaesdec_v16qi, + __builtin_ia32_vaesdec_v32qi, __builtin_ia32_vaesdec_v64qi): New builtins. + * config/i386/i386.c (ix86_expand_args_builtin): Handle new type. + * config/i386/immintrin.h: Include vaesintrin.h. + * config/i386/sse.md (vaesdec_): New pattern. + * config/i386/vaesintrin.h (_mm256_aesdec_epi128, _mm512_aesdec_epi128, + _mm_aesdec_epi128): New intrinsics. + 2017-12-12 Julia Koval * common/config/i386/i386-common.c (OPTION_MASK_ISA_VAES_SET, diff --git a/gcc/config.gcc b/gcc/config.gcc index 870e35afaec..e208d00bd5b 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -381,7 +381,7 @@ i[34567]86-*-*) clzerointrin.h pkuintrin.h sgxintrin.h cetintrin.h gfniintrin.h cet.h avx512vbmi2intrin.h avx512vbmi2vlintrin.h avx512vnniintrin.h - avx512vnnivlintrin.h" + avx512vnnivlintrin.h gfniintrin.h vaesintrin.h" ;; x86_64-*-*) cpu_type=i386 @@ -408,7 +408,7 @@ x86_64-*-*) clzerointrin.h pkuintrin.h sgxintrin.h cetintrin.h gfniintrin.h cet.h avx512vbmi2intrin.h avx512vbmi2vlintrin.h avx512vnniintrin.h - avx512vnnivlintrin.h" + avx512vnnivlintrin.h gfniintrin.h vaesintrin.h" ;; ia64-*-*) extra_headers=ia64intrin.h diff --git a/gcc/config/i386/i386-builtin.def b/gcc/config/i386/i386-builtin.def index 02a2b7a287c..8cfa1497213 100644 --- a/gcc/config/i386/i386-builtin.def +++ b/gcc/config/i386/i386-builtin.def @@ -2763,6 +2763,11 @@ BDESC (OPTION_MASK_ISA_AVX512VNNI, CODE_FOR_vpdpwssds_v4si, "__builtin_ia32_vpdp BDESC (OPTION_MASK_ISA_AVX512VNNI, CODE_FOR_vpdpwssds_v4si_mask, "__builtin_ia32_vpdpwssds_v4si_mask", IX86_BUILTIN_VPDPWSSDSV4SI_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_INT) BDESC (OPTION_MASK_ISA_AVX512VNNI, CODE_FOR_vpdpwssds_v4si_maskz, "__builtin_ia32_vpdpwssds_v4si_maskz", IX86_BUILTIN_VPDPWSSDSV4SI_MASKZ, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_INT) +/* VAES */ +BDESC (OPTION_MASK_ISA_VAES, CODE_FOR_vaesdec_v16qi, "__builtin_ia32_vaesdec_v16qi", IX86_BUILTIN_VAESDEC16, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI) +BDESC (OPTION_MASK_ISA_VAES, CODE_FOR_vaesdec_v32qi, "__builtin_ia32_vaesdec_v32qi", IX86_BUILTIN_VAESDEC32, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI) +BDESC (OPTION_MASK_ISA_VAES, CODE_FOR_vaesdec_v64qi, "__builtin_ia32_vaesdec_v64qi", IX86_BUILTIN_VAESDEC64, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI) + BDESC_END (ARGS2, SPECIAL_ARGS2) BDESC_FIRST (special_args2, SPECIAL_ARGS2, OPTION_MASK_ISA_AVX512VBMI2, CODE_FOR_compressstorev64qi_mask, "__builtin_ia32_compressstoreuqi512_mask", IX86_BUILTIN_PCOMPRESSBSTORE512, UNKNOWN, (int) VOID_FTYPE_PV64QI_V64QI_UDI) diff --git a/gcc/config/i386/immintrin.h b/gcc/config/i386/immintrin.h index abc1d310804..a6e27dd43a3 100644 --- a/gcc/config/i386/immintrin.h +++ b/gcc/config/i386/immintrin.h @@ -102,6 +102,8 @@ #include +#include + #ifndef __RDRND__ #pragma GCC push_options #pragma GCC target("rdrnd") diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 6ec97e17e5c..238a6062f98 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -172,6 +172,9 @@ UNSPEC_VPMADDUBSWACCSSD UNSPEC_VPMADDWDACCD UNSPEC_VPMADDWDACCSSD + + ;; For VAES support + UNSPEC_VAESDEC ]) (define_c_enum "unspecv" [ @@ -374,6 +377,9 @@ (define_mode_iterator VI2_AVX512VL [(V8HI "TARGET_AVX512VL") (V16HI "TARGET_AVX512VL") V32HI]) +(define_mode_iterator VI1_AVX512VL_F + [V32QI (V16QI "TARGET_AVX512VL") (V64QI "TARGET_AVX512F")]) + (define_mode_iterator VI8_AVX2_AVX512BW [(V8DI "TARGET_AVX512BW") (V4DI "TARGET_AVX2") V2DI]) @@ -20449,3 +20455,13 @@ "TARGET_AVX512VNNI" "vpdpwssds\t{%3, %2, %0%{%5%}%{z%}|%0%{%5%}%{z%}, %2, %3 }" [(set_attr ("prefix") ("evex"))]) + +(define_insn "vaesdec_" + [(set (match_operand:VI1_AVX512VL_F 0 "register_operand" "=v") + (unspec:VI1_AVX512VL_F + [(match_operand:VI1_AVX512VL_F 1 "register_operand" "v") + (match_operand:VI1_AVX512VL_F 2 "vector_operand" "v")] + UNSPEC_VAESDEC))] + "TARGET_VAES" + "vaesdec\t{%2, %1, %0|%0, %1, %2}" +) diff --git a/gcc/config/i386/vaesintrin.h b/gcc/config/i386/vaesintrin.h new file mode 100644 index 00000000000..0208cc7cce2 --- /dev/null +++ b/gcc/config/i386/vaesintrin.h @@ -0,0 +1,59 @@ +#ifndef __VAESINTRIN_H_INCLUDED +#define __VAESINTRIN_H_INCLUDED + +#ifndef __VAES__ +#pragma GCC push_options +#pragma GCC target("vaes") +#define __DISABLE_VAES__ +#endif /* __VAES__ */ + +extern __inline __m256i +__attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm256_aesdec_epi128 (__m256i __A, __m256i __B) +{ + return (__m256i)__builtin_ia32_vaesdec_v32qi ((__v32qi) __A, (__v32qi) __B); +} + +#ifdef __DISABLE_VAES__ +#undef __DISABLE_VAES__ +#pragma GCC pop_options +#endif /* __DISABLE_VAES__ */ + + +#if !defined(__VAES__) || !defined(__AVX512F) +#pragma GCC push_options +#pragma GCC target("vaes,avx512f") +#define __DISABLE_VAESF__ +#endif /* __VAES__ */ + + +extern __inline __m512i +__attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm512_aesdec_epi128 (__m512i __A, __m512i __B) +{ + return (__m512i)__builtin_ia32_vaesdec_v64qi ((__v64qi) __A, (__v64qi) __B); +} + +#ifdef __DISABLE_VAESF__ +#undef __DISABLE_VAESF__ +#pragma GCC pop_options +#endif /* __DISABLE_VAES__ */ + +#if !defined(__VAES__) || !defined(__AVX512VL) +#pragma GCC push_options +#pragma GCC target("vaes,avx512vl") +#define __DISABLE_VAESVL__ +#endif /* __VAES__ */ + +extern __inline __m128i +__attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aesdec_epi128 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_vaesdec_v16qi ((__v16qi) __A, (__v16qi) __B); +} + +#ifdef __DISABLE_VAESVL__ +#undef __DISABLE_VAESVL__ +#pragma GCC pop_options +#endif /* __DISABLE_VAES__ */ +#endif /* __VAESINTRIN_H_INCLUDED */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a4bd47b613e..cacb3f4f976 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-12-12 Julia Koval + + * gcc.target/i386/avx512-check.h: Handle bit_VAES. + * gcc.target/i386/avx512f-aesdec-2.c: New test. + * gcc.target/i386/avx512fvl-vaes-1.c: Ditto. + * gcc.target/i386/avx512vl-aesdec-2.c: Ditto. + * gcc.target/i386/i386.exp (check_effective_target_avx512vaes): New. + 2017-12-11 David Malcolm PR c/82050 diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h index 222992baf45..8ea8751990e 100644 --- a/gcc/testsuite/gcc.target/i386/avx512-check.h +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h @@ -83,6 +83,9 @@ main () #endif #ifdef AVX512VNNI && (ecx & bit_AVX512VNNI) +#endif +#ifdef VAES + && (ecx & bit_VAES) #endif && avx512f_os_support ()) { diff --git a/gcc/testsuite/gcc.target/i386/avx512f-aesdec-2.c b/gcc/testsuite/gcc.target/i386/avx512f-aesdec-2.c new file mode 100644 index 00000000000..a343fbba4eb --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512f-aesdec-2.c @@ -0,0 +1,52 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -mavx512f -mvaes" } */ +/* { dg-require-effective-target avx512f } */ +/* { dg-require-effective-target avx512vaes } */ + +#define AVX512F + +#define VAES +#include "avx512f-helper.h" + +#define SIZE (AVX512F_LEN / 32) + +#include "avx512f-mask-type.h" + +static void +CALC (unsigned int *r) +{ + for (int i = 0; i < SIZE; i+=4) + { + r[i] = 0xba0cda94; + r[i + 1] = 0x73676a7; + r[i + 2] = 0xd3204422; + r[i + 3] = 0x5506edd; + } +} + +void +TEST (void) +{ + int i; + UNION_TYPE (AVX512F_LEN, i_ud) res1, src1, src2; + MASK_TYPE mask = MASK_VALUE; + unsigned int res_ref[SIZE]; + + for (int i = 0; i < SIZE; i+=4) + { + src1.a[i] = 0x5d53475d; + src1.a[i + 1] = 0x63746f72; + src1.a[i + 2] = 0x73745665; + src1.a[i + 3] = 0x7b5b5465; + src2.a[i] = 0x726f6e5d; + src2.a[i + 1] = 0x5b477565; + src2.a[i + 2] = 0x68617929; + src2.a[i + 3] = 0x48692853; + } + + CALC (res_ref); + res1.x = INTRINSIC (_aesdec_epi128) (src2.x, src1.x); + + if (UNION_CHECK (AVX512F_LEN, i_ud) (res1, res_ref)) + abort (); +} diff --git a/gcc/testsuite/gcc.target/i386/avx512fvl-vaes-1.c b/gcc/testsuite/gcc.target/i386/avx512fvl-vaes-1.c new file mode 100644 index 00000000000..fc4e6bfb5ea --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512fvl-vaes-1.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-mvaes -mavx512f -mavx512vl -O2" } */ +/* { dg-final { scan-assembler-times "vaesdec\[ \\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\r]*%zmm\[0-9\]+\[^\n\r]*%zmm\[0-9\]+(?:\n|\[ \\t\]+#)" 1 } } */ + +/* { dg-final { scan-assembler-times "vaesdec\[ \\t\]+\[^\{\n\]*%ymm\[0-9\]+\[^\{\n\]*%ymm\[0-9\]+\[^\{\n\]*%ymm\[0-9\]+(?:\n|\[ \\t\]+#)" 1 } } */ + +/* { dg-final { scan-assembler-times "vaesdec\[ \\t\]+\[^\{\n\]*%xmm\[0-9\]+\[^\{\n\]*%xmm\[0-9\]+\[^\{\n\]*%xmm\[0-9\]+(?:\n|\[ \\t\]+#)" 1 } } */ + +#include + +volatile __m512i x,y; +volatile __m256i x256, y256; +volatile __m128i x128, y128; + +void extern +avx512f_test (void) +{ + x = _mm512_aesdec_epi128 (x, y); + + x256 = _mm256_aesdec_epi128 (x256, y256); + + x128 = _mm_aesdec_epi128 (x128, y128); + +} diff --git a/gcc/testsuite/gcc.target/i386/avx512vl-aesdec-2.c b/gcc/testsuite/gcc.target/i386/avx512vl-aesdec-2.c new file mode 100644 index 00000000000..92a6eb3cbdc --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512vl-aesdec-2.c @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -mavx512bw -mavx512vl -mvaes" } */ +/* { dg-require-effective-target avx512vl } */ +/* { dg-require-effective-target avx512bw } */ +/* { dg-require-effective-target avx512vaes } */ + +#define AVX512VL +#define AVX512F_LEN 256 +#define AVX512F_LEN_HALF 128 +#include "avx512f-aesdec-2.c" + +#undef AVX512F_LEN +#undef AVX512F_LEN_HALF + +#define AVX512F_LEN 128 +#define AVX512F_LEN_HALF 128 +#include "avx512f-aesdec-2.c" diff --git a/gcc/testsuite/gcc.target/i386/i386.exp b/gcc/testsuite/gcc.target/i386/i386.exp index c663a12bcb3..bebc6dd7935 100644 --- a/gcc/testsuite/gcc.target/i386/i386.exp +++ b/gcc/testsuite/gcc.target/i386/i386.exp @@ -456,6 +456,20 @@ proc check_effective_target_avx512vnni { } { } "-mavx512vnni -mavx512f" ] } +# Return 1 if vaes instructions can be compiled. +proc check_effective_target_avx512vaes { } { + return [check_no_compiler_messages avx512vaes object { + + typedef int __v16si __attribute__ ((__vector_size__ (64))); + + __v32qi + _mm256_aesdec_epi128 (__v32qi __A, __v32qi __B) + { + return (__v32qi)__builtin_ia32_vaesdec_v32qi ((__v32qi) __A, (__v32qi) __B); + } + } "-mvaes" ] +} + # If a testcase doesn't have special options, use these. global DEFAULT_CFLAGS if ![info exists DEFAULT_CFLAGS] then { -- 2.30.2