From f8d9957ef899acf54c01f0289b586871c846402a Mon Sep 17 00:00:00 2001 From: Sebastian Peryt Date: Mon, 14 May 2018 13:22:53 +0200 Subject: [PATCH] i386-common.c (OPTION_MASK_ISA_CLDEMOTE_SET, [...]): New defines. 2018-05-14 Sebastian Peryt gcc/ * common/config/i386/i386-common.c (OPTION_MASK_ISA_CLDEMOTE_SET, OPTION_MASK_ISA_CLDEMOTE_UNSET): New defines. (ix86_handle_option): Handle -mcldemote. * config.gcc: New header. * config/i386/cldemoteintrin.h: New file. * config/i386/cpuid.h (bit_CLDEMOTE): New bit. * config/i386/driver-i386.c (host_detect_local_cpu): Detect -mcldemote. * config/i386/i386-c.c (ix86_target_macros_internal): Handle OPTION_MASK_ISA_CLDEMOTE. * config/i386/i386.c (ix86_target_string): Add -mcldemote. (ix86_valid_target_attribute_inner_p): Ditto. (enum ix86_builtins): Add IX86_BUILTIN_CLDEMOTE. (ix86_init_mmx_sse_builtins): Define __builtin_ia32_cldemote. (ix86_expand_builtin): Expand IX86_BUILTIN_CLDEMOTE. * config/i386/i386.h (TARGET_CLDEMOTE, TARGET_CLDEMOTE_P): New. * config/i386/i386.md (UNSPECV_CLDEMOTE): New. (cldemote): New. * config/i386/i386.opt: Add -mcldemote. * config/i386/x86intrin.h: New header. * doc/invoke.texi: Add -mcldemote. gcc/testsuite/ * gcc.target/i386/cldemote-1.c: New test. From-SVN: r260224 --- gcc/ChangeLog | 24 +++++++++++ gcc/common/config/i386/i386-common.c | 15 +++++++ gcc/config.gcc | 4 +- gcc/config/i386/cldemoteintrin.h | 47 ++++++++++++++++++++++ gcc/config/i386/cpuid.h | 1 + gcc/config/i386/driver-i386.c | 6 ++- gcc/config/i386/i386-c.c | 2 + gcc/config/i386/i386.c | 19 ++++++++- gcc/config/i386/i386.h | 2 + gcc/config/i386/i386.md | 11 +++++ gcc/config/i386/i386.opt | 4 ++ gcc/config/i386/x86intrin.h | 2 + gcc/doc/invoke.texi | 10 +++-- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.target/i386/cldemote-1.c | 11 +++++ 15 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 gcc/config/i386/cldemoteintrin.h create mode 100644 gcc/testsuite/gcc.target/i386/cldemote-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c8bb4c7b3dd..a2121a99558 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,27 @@ +2018-05-14 Sebastian Peryt + + * common/config/i386/i386-common.c (OPTION_MASK_ISA_CLDEMOTE_SET, + OPTION_MASK_ISA_CLDEMOTE_UNSET): New defines. + (ix86_handle_option): Handle -mcldemote. + * config.gcc: New header. + * config/i386/cldemoteintrin.h: New file. + * config/i386/cpuid.h (bit_CLDEMOTE): New bit. + * config/i386/driver-i386.c (host_detect_local_cpu): Detect + -mcldemote. + * config/i386/i386-c.c (ix86_target_macros_internal): Handle + OPTION_MASK_ISA_CLDEMOTE. + * config/i386/i386.c (ix86_target_string): Add -mcldemote. + (ix86_valid_target_attribute_inner_p): Ditto. + (enum ix86_builtins): Add IX86_BUILTIN_CLDEMOTE. + (ix86_init_mmx_sse_builtins): Define __builtin_ia32_cldemote. + (ix86_expand_builtin): Expand IX86_BUILTIN_CLDEMOTE. + * config/i386/i386.h (TARGET_CLDEMOTE, TARGET_CLDEMOTE_P): New. + * config/i386/i386.md (UNSPECV_CLDEMOTE): New. + (cldemote): New. + * config/i386/i386.opt: Add -mcldemote. + * config/i386/x86intrin.h: New header. + * doc/invoke.texi: Add -mcldemote. + 2018-05-14 Richard Biener * doc/match-and-simplify.texi: Adjust :s documentation. diff --git a/gcc/common/config/i386/i386-common.c b/gcc/common/config/i386/i386-common.c index b17646c165a..3aa32f5934b 100644 --- a/gcc/common/config/i386/i386-common.c +++ b/gcc/common/config/i386/i386-common.c @@ -153,6 +153,7 @@ along with GCC; see the file COPYING3. If not see #define OPTION_MASK_ISA_MOVDIRI_SET OPTION_MASK_ISA_MOVDIRI #define OPTION_MASK_ISA_MOVDIR64B_SET OPTION_MASK_ISA_MOVDIR64B #define OPTION_MASK_ISA_WAITPKG_SET OPTION_MASK_ISA_WAITPKG +#define OPTION_MASK_ISA_CLDEMOTE_SET OPTION_MASK_ISA_CLDEMOTE /* Define a set of ISAs which aren't available when a given ISA is disabled. MMX and SSE ISAs are handled separately. */ @@ -230,6 +231,7 @@ along with GCC; see the file COPYING3. If not see #define OPTION_MASK_ISA_MOVDIRI_UNSET OPTION_MASK_ISA_MOVDIRI #define OPTION_MASK_ISA_MOVDIR64B_UNSET OPTION_MASK_ISA_MOVDIR64B #define OPTION_MASK_ISA_WAITPKG_UNSET OPTION_MASK_ISA_WAITPKG +#define OPTION_MASK_ISA_CLDEMOTE_UNSET OPTION_MASK_ISA_CLDEMOTE /* SSE4 includes both SSE4.1 and SSE4.2. -mno-sse4 should the same as -mno-sse4.1. */ @@ -608,6 +610,19 @@ ix86_handle_option (struct gcc_options *opts, opts->x_ix86_isa_flags2 &= ~OPTION_MASK_ISA_MOVDIR64B_UNSET; opts->x_ix86_isa_flags2_explicit |= OPTION_MASK_ISA_MOVDIR64B_UNSET; } + return true; + + case OPT_mcldemote: + if (value) + { + opts->x_ix86_isa_flags2 |= OPTION_MASK_ISA_CLDEMOTE_SET; + opts->x_ix86_isa_flags2_explicit |= OPTION_MASK_ISA_CLDEMOTE_SET; + } + else + { + opts->x_ix86_isa_flags2 &= ~OPTION_MASK_ISA_CLDEMOTE_UNSET; + opts->x_ix86_isa_flags2_explicit |= OPTION_MASK_ISA_CLDEMOTE_UNSET; + } return true; case OPT_mwaitpkg: diff --git a/gcc/config.gcc b/gcc/config.gcc index be43a09e8af..d509800071b 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -385,7 +385,7 @@ i[34567]86-*-*) avx512vnnivlintrin.h vaesintrin.h vpclmulqdqintrin.h avx512vpopcntdqvlintrin.h avx512bitalgintrin.h pconfigintrin.h wbnoinvdintrin.h movdirintrin.h - waitpkgintrin.h" + waitpkgintrin.h cldemoteintrin.h" ;; x86_64-*-*) cpu_type=i386 @@ -415,7 +415,7 @@ x86_64-*-*) avx512vnnivlintrin.h vaesintrin.h vpclmulqdqintrin.h avx512vpopcntdqvlintrin.h avx512bitalgintrin.h pconfigintrin.h wbnoinvdintrin.h movdirintrin.h - waitpkgintrin.h" + waitpkgintrin.h cldemoteintrin.h" ;; ia64-*-*) extra_headers=ia64intrin.h diff --git a/gcc/config/i386/cldemoteintrin.h b/gcc/config/i386/cldemoteintrin.h new file mode 100644 index 00000000000..1fa4c2d34d0 --- /dev/null +++ b/gcc/config/i386/cldemoteintrin.h @@ -0,0 +1,47 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GCC is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#if !defined _X86INTRIN_H_INCLUDED +# error "Never use directly; include instead." +#endif + +#ifndef _CLDEMOTE_H_INCLUDED +#define _CLDEMOTE_H_INCLUDED + +#ifndef __CLDEMOTE__ +#pragma GCC push_options +#pragma GCC target("cldemote") +#define __DISABLE_CLDEMOTE__ +#endif /* __CLDEMOTE__ */ +extern __inline void +__attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_cldemote (void *__A) +{ + __builtin_ia32_cldemote (__A); +} +#ifdef __DISABLE_CLDEMOTE__ +#undef __DISABLE_CLDEMOTE__ +#pragma GCC pop_options +#endif /* __DISABLE_CLDEMOTE__ */ + +#endif /* _CLDEMOTE_H_INCLUDED */ diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h index 0672cf54a9b..7e9e2d153dc 100644 --- a/gcc/config/i386/cpuid.h +++ b/gcc/config/i386/cpuid.h @@ -110,6 +110,7 @@ #define bit_RDPID (1 << 22) #define bit_MOVDIRI (1 << 27) #define bit_MOVDIR64B (1 << 28) +#define bit_CLDEMOTE (1 << 25) /* %edx */ #define bit_AVX5124VNNIW (1 << 2) diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c index 52891f9ecf0..57e01a06dff 100644 --- a/gcc/config/i386/driver-i386.c +++ b/gcc/config/i386/driver-i386.c @@ -425,6 +425,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) unsigned int has_vpclmulqdq = 0; unsigned int has_movdiri = 0, has_movdir64b = 0; unsigned int has_waitpkg = 0; + unsigned int has_cldemote = 0; bool arch; @@ -522,6 +523,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) has_avx512bitalg = ecx & bit_AVX512BITALG; has_movdiri = ecx & bit_MOVDIRI; has_movdir64b = ecx & bit_MOVDIR64B; + has_cldemote = ecx & bit_CLDEMOTE; has_avx5124vnniw = edx & bit_AVX5124VNNIW; has_avx5124fmaps = edx & bit_AVX5124FMAPS; @@ -1111,6 +1113,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) const char *movdiri = has_movdiri ? " -mmovdiri" : " -mno-movdiri"; const char *movdir64b = has_movdir64b ? " -mmovdir64b" : " -mno-movdir64b"; const char *waitpkg = has_waitpkg ? " -mwaitpkg" : " -mno-waitpkg"; + const char *cldemote = has_cldemote ? " -mcldemote" : " -mno-cldemote"; options = concat (options, mmx, mmx3dnow, sse, sse2, sse3, ssse3, sse4a, cx16, sahf, movbe, aes, sha, pclmul, popcnt, abm, lwp, fma, fma4, xop, bmi, sgx, bmi2, @@ -1123,7 +1126,8 @@ const char *host_detect_local_cpu (int argc, const char **argv) avx512ifma, avx512vbmi, avx5124fmaps, avx5124vnniw, clwb, mwaitx, clzero, pku, rdpid, gfni, shstk, avx512vbmi2, avx512vnni, vaes, vpclmulqdq, - avx512bitalg, movdiri, movdir64b, waitpkg, NULL); + avx512bitalg, movdiri, movdir64b, waitpkg, cldemote, + NULL); } done: diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c index 93766be7230..28ea046fe35 100644 --- a/gcc/config/i386/i386-c.c +++ b/gcc/config/i386/i386-c.c @@ -518,6 +518,8 @@ ix86_target_macros_internal (HOST_WIDE_INT isa_flag, def_or_undef (parse_in, "__MOVDIR64B__"); if (isa_flag2 & OPTION_MASK_ISA_WAITPKG) def_or_undef (parse_in, "__WAITPKG__"); + if (isa_flag2 & OPTION_MASK_ISA_CLDEMOTE) + def_or_undef (parse_in, "__CLDEMOTE__"); if (TARGET_IAMCU) { def_or_undef (parse_in, "__iamcu"); diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ffb1386e80f..91e7e002790 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -2773,7 +2773,8 @@ ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2, { "-mclzero", OPTION_MASK_ISA_CLZERO }, { "-mmwaitx", OPTION_MASK_ISA_MWAITX }, { "-mmovdir64b", OPTION_MASK_ISA_MOVDIR64B }, - { "-mwaitpkg", OPTION_MASK_ISA_WAITPKG } + { "-mwaitpkg", OPTION_MASK_ISA_WAITPKG }, + { "-mcldemote", OPTION_MASK_ISA_CLDEMOTE } }; static struct ix86_target_opts isa_opts[] = { @@ -5390,6 +5391,7 @@ ix86_valid_target_attribute_inner_p (tree args, char *p_strings[], IX86_ATTR_ISA ("movdiri", OPT_mmovdiri), IX86_ATTR_ISA ("movdir64b", OPT_mmovdir64b), IX86_ATTR_ISA ("waitpkg", OPT_mwaitpkg), + IX86_ATTR_ISA ("cldemote", OPT_mcldemote), /* enum options */ IX86_ATTR_ENUM ("fpmath=", OPT_mfpmath_), @@ -30649,6 +30651,7 @@ enum ix86_builtins IX86_BUILTIN_UMWAIT, IX86_BUILTIN_TPAUSE, IX86_BUILTIN_CLZERO, + IX86_BUILTIN_CLDEMOTE, IX86_BUILTIN_VEC_INIT_V2SI, IX86_BUILTIN_VEC_INIT_V4HI, IX86_BUILTIN_VEC_INIT_V8QI, @@ -31987,6 +31990,10 @@ ix86_init_mmx_sse_builtins (void) def_builtin2 (OPTION_MASK_ISA_WAITPKG, "__builtin_ia32_tpause", UINT8_FTYPE_UNSIGNED_UINT64, IX86_BUILTIN_TPAUSE); + /* CLDEMOTE. */ + def_builtin2 (OPTION_MASK_ISA_CLDEMOTE, "__builtin_ia32_cldemote", + VOID_FTYPE_PCVOID, IX86_BUILTIN_CLDEMOTE); + /* Add FMA4 multi-arg argument instructions */ for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++) { @@ -37146,6 +37153,16 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget, emit_insn (ix86_gen_clzero (op0)); return 0; + case IX86_BUILTIN_CLDEMOTE: + arg0 = CALL_EXPR_ARG (exp, 0); + op0 = expand_normal (arg0); + icode = CODE_FOR_cldemote; + if (!insn_data[icode].operand[0].predicate (op0, Pmode)) + op0 = ix86_zero_extend_to_Pmode (op0); + + emit_insn (gen_cldemote (op0)); + return 0; + case IX86_BUILTIN_VEC_INIT_V2SI: case IX86_BUILTIN_VEC_INIT_V4HI: case IX86_BUILTIN_VEC_INIT_V8QI: diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 8fc980f3ca3..80745bc25a7 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -191,6 +191,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define TARGET_MOVDIR64B_P(x) TARGET_ISA_MOVDIR64B_P(x) #define TARGET_WAITPKG TARGET_ISA_WAITPKG #define TARGET_WAITPKG_P(x) TARGET_ISA_WAITPKG_P(x) +#define TARGET_CLDEMOTE TARGET_ISA_CLDEMOTE +#define TARGET_CLDEMOTE_P(x) TARGET_ISA_CLDEMOTE_P(x) #define TARGET_LP64 TARGET_ABI_64 #define TARGET_LP64_P(x) TARGET_ABI_64_P(x) diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 1ba352ac293..302ccc524bb 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -298,6 +298,9 @@ UNSPECV_UMWAIT UNSPECV_UMONITOR UNSPECV_TPAUSE + + ;; For CLDEMOTE support + UNSPECV_CLDEMOTE ]) ;; Constants to represent rounding modes in the ROUND instruction @@ -21033,6 +21036,14 @@ "tpause\t%0" [(set_attr "length" "3")]) +(define_insn "cldemote" + [(unspec_volatile[(match_operand 0 "address_operand" "p")] + UNSPECV_CLDEMOTE)] + "TARGET_CLDEMOTE" + "cldemote\t%a0" + [(set_attr "type" "other") + (set_attr "memory" "unknown")]) + (include "mmx.md") (include "sse.md") (include "sync.md") diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index eec702623d2..58d097371d8 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -1059,3 +1059,7 @@ Support MOVDIR64B built-in functions and code generation. mwaitpkg Target Report Mask(ISA_WAITPKG) Var(ix86_isa_flags2) Save Support WAITPKG built-in functions and code generation. + +mcldemote +Target Report Mask(ISA_CLDEMOTE) Var(ix86_isa_flags2) Save +Support CLDEMOTE built-in functions and code generation. diff --git a/gcc/config/i386/x86intrin.h b/gcc/config/i386/x86intrin.h index 71a33feb778..6d67e9cebf4 100644 --- a/gcc/config/i386/x86intrin.h +++ b/gcc/config/i386/x86intrin.h @@ -103,6 +103,8 @@ #include +#include + #endif /* __iamcu__ */ #endif /* _X86INTRIN_H_INCLUDED */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8066fd3f5cc..462aedc255b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1260,7 +1260,8 @@ See RS/6000 and PowerPC Options. -mlzcnt -mbmi2 -mfxsr -mxsave -mxsaveopt -mrtm -mlwp -mmpx @gol -mmwaitx -mclzero -mpku -mthreads -mgfni -mvaes -mwaitpkg @gol -mshstk -mforce-indirect-call -mavx512vbmi2 @gol --mvpclmulqdq -mavx512bitalg -mmovdiri -mmovdir64b -mavx512vpopcntdq @gol +-mvpclmulqdq -mavx512bitalg -mmovdiri -mmovdir64b -mavx512vpopcntdq +-mcldemote @gol -mms-bitfields -mno-align-stringops -minline-all-stringops @gol -minline-stringops-dynamically -mstringop-strategy=@var{alg} @gol -mmemcpy-strategy=@var{strategy} -mmemset-strategy=@var{strategy} @gol @@ -27263,14 +27264,17 @@ preferred alignment to @option{-mpreferred-stack-boundary=2}. @need 200 @itemx -mavx512vpopcntdq @opindex mavx512vpopcntdq +@need 200 +@itemx -mcldemote +@opindex mcldemote These switches enable the use of instructions in the MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, AVX, AVX2, AVX512F, AVX512PF, AVX512ER, AVX512CD, SHA, AES, PCLMUL, FSGSBASE, RDRND, F16C, FMA, SSE4A, FMA4, XOP, LWP, ABM, AVX512VL, AVX512BW, AVX512DQ, AVX512IFMA, AVX512VBMI, BMI, BMI2, VAES, WAITPKG, FXSR, XSAVE, XSAVEOPT, LZCNT, RTM, MPX, MWAITX, PKU, IBT, SHSTK, AVX512VBMI2, GFNI, VPCLMULQDQ, AVX512BITALG, MOVDIRI, MOVDIR64B, -AVX512VPOPCNTDQ3DNow!@: or enhanced 3DNow!@: extended instruction sets. -Each has a corresponding @option{-mno-} option to disable use of these +AVX512VPOPCNTDQ, CLDEMOTE, 3DNow!@: or enhanced 3DNow!@: extended instruction +sets. Each has a corresponding @option{-mno-} option to disable use of these instructions. These extensions are also available as built-in functions: see diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 657390ce5d4..a256329e865 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-05-14 Sebastian Peryt + + * gcc.target/i386/cldemote-1.c: New test. + 2018-05-13 Paul Thomas PR fortran/85742 diff --git a/gcc/testsuite/gcc.target/i386/cldemote-1.c b/gcc/testsuite/gcc.target/i386/cldemote-1.c new file mode 100644 index 00000000000..47482612d2c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/cldemote-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcldemote" } */ +/* { dg-final { scan-assembler "cldemote\[ \\t\]" } } */ + +#include "x86intrin.h" + +void +test_cldemote (void *__A) +{ + _cldemote (__A); +} -- 2.30.2