]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Support Intel USER_MSR
authorHu, Lin1 <lin1.hu@intel.com>
Thu, 22 Dec 2022 02:26:47 +0000 (10:26 +0800)
committerHu, Lin1 <lin1.hu@intel.com>
Thu, 12 Oct 2023 07:33:07 +0000 (15:33 +0800)
gcc/ChangeLog:

* common/config/i386/cpuinfo.h (get_available_features):
Detect USER_MSR.
* common/config/i386/i386-common.cc (OPTION_MASK_ISA2_USER_MSR_SET): New.
(OPTION_MASK_ISA2_USER_MSR_UNSET): Ditto.
(ix86_handle_option): Handle -musermsr.
* common/config/i386/i386-cpuinfo.h (enum processor_features):
Add FEATURE_USER_MSR.
* common/config/i386/i386-isas.h: Add ISA_NAME_TABLE_ENTRY for usermsr.
* config.gcc: Add usermsrintrin.h
* config/i386/cpuid.h (bit_USER_MSR): New.
* config/i386/i386-builtin-types.def:
Add DEF_FUNCTION_TYPE (VOID, UINT64, UINT64).
* config/i386/i386-builtins.cc (ix86_init_mmx_sse_builtins):
Add __builtin_urdmsr and __builtin_uwrmsr.
* config/i386/i386-builtins.h (ix86_builtins):
Add IX86_BUILTIN_URDMSR and IX86_BUILTIN_UWRMSR.
* config/i386/i386-c.cc (ix86_target_macros_internal):
Define __USER_MSR__.
* config/i386/i386-expand.cc (ix86_expand_builtin):
Handle new builtins.
* config/i386/i386-isa.def (USER_MSR): Add DEF_PTA(USER_MSR).
* config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p):
Handle usermsr.
* config/i386/i386.md (urdmsr): New define_insn.
(uwrmsr): Ditto.
* config/i386/i386.opt: Add option -musermsr.
* config/i386/x86gprintrin.h: Include usermsrintrin.h
* doc/extend.texi: Document usermsr.
* doc/invoke.texi: Document -musermsr.
* doc/sourcebuild.texi: Document target usermsr.
* config/i386/usermsrintrin.h: New file.

gcc/testsuite/ChangeLog:

* gcc.target/i386/funcspec-56.inc: Add new target attribute.
* gcc.target/i386/x86gprintrin-1.c: Add -musermsr for 64bit target.
* gcc.target/i386/x86gprintrin-2.c: Ditto.
* gcc.target/i386/x86gprintrin-3.c: Ditto.
* gcc.target/i386/x86gprintrin-4.c: Add musermsr for 64bit target.
* gcc.target/i386/x86gprintrin-5.c: Ditto
* gcc.target/i386/user_msr-1.c: New test.
* gcc.target/i386/user_msr-2.c: Ditto.

28 files changed:
gcc/common/config/i386/cpuinfo.h
gcc/common/config/i386/i386-common.cc
gcc/common/config/i386/i386-cpuinfo.h
gcc/common/config/i386/i386-isas.h
gcc/config.gcc
gcc/config/i386/cpuid.h
gcc/config/i386/i386-builtin-types.def
gcc/config/i386/i386-builtins.cc
gcc/config/i386/i386-builtins.h
gcc/config/i386/i386-c.cc
gcc/config/i386/i386-expand.cc
gcc/config/i386/i386-isa.def
gcc/config/i386/i386-options.cc
gcc/config/i386/i386.md
gcc/config/i386/i386.opt
gcc/config/i386/usermsrintrin.h [new file with mode: 0644]
gcc/config/i386/x86gprintrin.h
gcc/doc/extend.texi
gcc/doc/invoke.texi
gcc/doc/sourcebuild.texi
gcc/testsuite/gcc.target/i386/funcspec-56.inc
gcc/testsuite/gcc.target/i386/user_msr-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/user_msr-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/x86gprintrin-1.c
gcc/testsuite/gcc.target/i386/x86gprintrin-2.c
gcc/testsuite/gcc.target/i386/x86gprintrin-3.c
gcc/testsuite/gcc.target/i386/x86gprintrin-4.c
gcc/testsuite/gcc.target/i386/x86gprintrin-5.c

index 141d37433162b100d86f835273ee7d706b49c5e5..0f86b44730b8bcb2ab0d52a1c45be439341b93af 100644 (file)
@@ -838,6 +838,8 @@ get_available_features (struct __processor_model *cpu_model,
        set_feature (FEATURE_IBT);
       if (edx & bit_UINTR)
        set_feature (FEATURE_UINTR);
+      if (edx & bit_USER_MSR)
+       set_feature (FEATURE_USER_MSR);
       if (amx_usable)
        {
          if (edx & bit_AMX_TILE)
index 684b0451bb340cf3c844b2bf0c62c06dbfd97237..13e423deceb961fee2c0e6ed074a4e55c4801117 100644 (file)
@@ -125,6 +125,7 @@ along with GCC; see the file COPYING3.  If not see
 #define OPTION_MASK_ISA2_SM4_SET OPTION_MASK_ISA2_SM4
 #define OPTION_MASK_ISA2_APX_F_SET OPTION_MASK_ISA2_APX_F
 #define OPTION_MASK_ISA2_EVEX512_SET OPTION_MASK_ISA2_EVEX512
+#define OPTION_MASK_ISA2_USER_MSR_SET OPTION_MASK_ISA2_USER_MSR
 
 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
    as -msse4.2.  */
@@ -313,6 +314,7 @@ along with GCC; see the file COPYING3.  If not see
 #define OPTION_MASK_ISA2_SM4_UNSET OPTION_MASK_ISA2_SM4
 #define OPTION_MASK_ISA2_APX_F_UNSET OPTION_MASK_ISA2_APX_F
 #define OPTION_MASK_ISA2_EVEX512_UNSET OPTION_MASK_ISA2_EVEX512
+#define OPTION_MASK_ISA2_USER_MSR_UNSET OPTION_MASK_ISA2_USER_MSR
 
 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
    as -mno-sse4.1. */
@@ -1373,6 +1375,19 @@ ix86_handle_option (struct gcc_options *opts,
        }
       return true;
 
+    case OPT_musermsr:
+      if (value)
+       {
+         opts->x_ix86_isa_flags2 |= OPTION_MASK_ISA2_USER_MSR_SET;
+         opts->x_ix86_isa_flags2_explicit |= OPTION_MASK_ISA2_USER_MSR_SET;
+       }
+      else
+       {
+         opts->x_ix86_isa_flags2 &= ~OPTION_MASK_ISA2_USER_MSR_UNSET;
+         opts->x_ix86_isa_flags2_explicit |= OPTION_MASK_ISA2_USER_MSR_UNSET;
+       }
+      return true;
+
     case OPT_mfma:
       if (value)
        {
index 8bf592191ab4a9186fba22571ca585d1daca6f60..47e9dcfb8f75938e6b907de2f7ac8b70e682e472 100644 (file)
@@ -262,6 +262,7 @@ enum processor_features
   FEATURE_SHA512,
   FEATURE_SM4,
   FEATURE_APX_F,
+  FEATURE_USER_MSR,
   CPU_FEATURE_MAX
 };
 
index 47e0cbd6f5bf8e8316c79d0f6f1f2875f74ec1c1..6875924994d190704814ffcf0951972606dcf6d5 100644 (file)
@@ -192,4 +192,5 @@ ISA_NAMES_TABLE_START
   ISA_NAMES_TABLE_ENTRY("sha512", FEATURE_SHA512, P_NONE, "-msha512")
   ISA_NAMES_TABLE_ENTRY("sm4", FEATURE_SM4, P_NONE, "-msm4")
   ISA_NAMES_TABLE_ENTRY("apxf", FEATURE_APX_F, P_NONE, "-mapxf")
+  ISA_NAMES_TABLE_ENTRY("usermsr", FEATURE_USER_MSR, P_NONE, "-musermsr")
 ISA_NAMES_TABLE_END
index 7d2fe2e29c3bdff255741d8a71d8ebfd4c7e567f..fa192637a52fa88bbe92f5797c274c9433f6d56b 100644 (file)
@@ -448,7 +448,8 @@ i[34567]86-*-* | x86_64-*-*)
                       avxvnniint8intrin.h avxneconvertintrin.h
                       cmpccxaddintrin.h amxfp16intrin.h prfchiintrin.h
                       raointintrin.h amxcomplexintrin.h avxvnniint16intrin.h
-                      sm3intrin.h sha512intrin.h sm4intrin.h"
+                      sm3intrin.h sha512intrin.h sm4intrin.h
+                      usermsrintrin.h"
        ;;
 ia64-*-*)
        extra_headers=ia64intrin.h
index f3d3a2a1c2237354596d09de518b8a7da783da15..75ef271820471c8d72e1832ba68386c3bbe5a6e9 100644 (file)
 #define bit_AVXNECONVERT       (1 << 5)
 #define bit_AVXVNNIINT16       (1 << 10)
 #define bit_PREFETCHI  (1 << 14)
+#define bit_USER_MSR   (1 << 15)
 #define bit_APX_F      (1 << 21)
 
 /* Extended State Enumeration Sub-leaf (%eax == 0xd, %ecx == 1) */
index e9463120eeaccb8c17cf13592e78e4fbd7e662cd..183029f2c75aeaaa32e84311b018e57568877671 100644 (file)
@@ -1422,3 +1422,6 @@ DEF_FUNCTION_TYPE (V4SI, V4SI, V4SI, V4SI, INT)
 
 # SHA512 builtins
 DEF_FUNCTION_TYPE (V4DI, V4DI, V4DI, V2DI)
+
+# USER_MSR builtins
+DEF_FUNCTION_TYPE (VOID, UINT64, UINT64)
index 70538fbe17bb21be19a7d24297cf3f6e646a3cba..42fc3751676dbe1f055d8bd0c9f1f231db10b3bb 100644 (file)
@@ -1262,6 +1262,14 @@ ix86_init_mmx_sse_builtins (void)
               "__builtin_ia32_testui",
               UINT8_FTYPE_VOID, IX86_BUILTIN_TESTUI);
 
+  /* USER_MSR.  */
+  def_builtin (OPTION_MASK_ISA_64BIT, OPTION_MASK_ISA2_USER_MSR,
+              "__builtin_ia32_urdmsr", UINT64_FTYPE_UINT64,
+              IX86_BUILTIN_URDMSR);
+  def_builtin (OPTION_MASK_ISA_64BIT, OPTION_MASK_ISA2_USER_MSR,
+              "__builtin_ia32_uwrmsr", VOID_FTYPE_UINT64_UINT64,
+              IX86_BUILTIN_UWRMSR);
+
   /* CLDEMOTE.  */
   def_builtin (0, OPTION_MASK_ISA2_CLDEMOTE, "__builtin_ia32_cldemote",
               VOID_FTYPE_PCVOID, IX86_BUILTIN_CLDEMOTE);
index c632482087c114eb547434947436d803f5d2ee8f..40785b0aa34bce77374210b6d51b129282970865 100644 (file)
@@ -39,6 +39,8 @@ enum ix86_builtins
   IX86_BUILTIN_MWAIT,
   IX86_BUILTIN_UMONITOR,
   IX86_BUILTIN_UMWAIT,
+  IX86_BUILTIN_URDMSR,
+  IX86_BUILTIN_UWRMSR,
   IX86_BUILTIN_TPAUSE,
   IX86_BUILTIN_TESTUI,
   IX86_BUILTIN_CLZERO,
index 9c44bd7fb638af0713cc9f2afe7c6157d6c92ca9..042ad8b9d9c42af6189d18e8c4f9f87d94670f67 100644 (file)
@@ -712,6 +712,8 @@ ix86_target_macros_internal (HOST_WIDE_INT isa_flag,
     def_or_undef (parse_in, "__SM4__");
   if (isa_flag2 & OPTION_MASK_ISA2_EVEX512)
     def_or_undef (parse_in, "__EVEX512__");
+  if (isa_flag2 & OPTION_MASK_ISA2_USER_MSR)
+    def_or_undef (parse_in, "__USER_MSR__");
   if (TARGET_IAMCU)
     {
       def_or_undef (parse_in, "__iamcu");
index d5083494798979451c4eb72c19f59fb2227c1e4c..4ef85570d44a7b29a6adf44a4ca43fa3351fdd12 100644 (file)
@@ -13471,6 +13471,41 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
        return 0;
       }
 
+    case IX86_BUILTIN_URDMSR:
+    case IX86_BUILTIN_UWRMSR:
+      {
+       arg0 = CALL_EXPR_ARG (exp, 0);
+       op0 = expand_normal (arg0);
+
+       if (CONST_INT_P (op0))
+         {
+           unsigned HOST_WIDE_INT val = UINTVAL (op0);
+           if (val > 0xffffffff)
+             op0 = force_reg (DImode, op0);
+         }
+       else
+         op0 = force_reg (DImode, op0);
+
+       if (fcode == IX86_BUILTIN_UWRMSR)
+         {
+           arg1 = CALL_EXPR_ARG (exp, 1);
+           op1 = expand_normal (arg1);
+           op1 = force_reg (DImode, op1);
+           icode = CODE_FOR_uwrmsr;
+           target = 0;
+         }
+       else
+         {
+           if (target == 0)
+             target = gen_reg_rtx (DImode);
+           icode = CODE_FOR_urdmsr;
+           op1 = op0;
+           op0 = target;
+         }
+       emit_insn (GEN_FCN (icode) (op0, op1));
+       return target;
+      }
+
     case IX86_BUILTIN_VEC_INIT_V2SI:
     case IX86_BUILTIN_VEC_INIT_V4HI:
     case IX86_BUILTIN_VEC_INIT_V8QI:
index c581f343339f3b4422a385ef5e114ad26c8a1d9c..991df5e2ef09451f943bc440c899cdaf226a3ed7 100644 (file)
@@ -122,3 +122,4 @@ DEF_PTA(SM3)
 DEF_PTA(SHA512)
 DEF_PTA(SM4)
 DEF_PTA(APX_F)
+DEF_PTA(USER_MSR)
index 06af373ca57ae1a610f404bdad1adc4a3e0ad489..818954d6dbc44f58159092ba59888063f79a1563 100644 (file)
@@ -251,7 +251,8 @@ static struct ix86_target_opts isa2_opts[] =
   { "-msm3",           OPTION_MASK_ISA2_SM3 },
   { "-msha512",                OPTION_MASK_ISA2_SHA512 },
   { "-msm4",            OPTION_MASK_ISA2_SM4 },
-  { "-mevex512",        OPTION_MASK_ISA2_EVEX512 }
+  { "-mevex512",       OPTION_MASK_ISA2_EVEX512 },
+  { "-musermsr",       OPTION_MASK_ISA2_USER_MSR }
 };
 static struct ix86_target_opts isa_opts[] =
 {
@@ -1114,6 +1115,7 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
     IX86_ATTR_ISA ("sm4", OPT_msm4),
     IX86_ATTR_ISA ("apxf", OPT_mapxf),
     IX86_ATTR_ISA ("evex512", OPT_mevex512),
+    IX86_ATTR_ISA ("usermsr", OPT_musermsr),
 
     /* enum options */
     IX86_ATTR_ENUM ("fpmath=", OPT_mfpmath_),
index 22bd5dde2faddd9152705685c8a1f57bb5c891a4..2a60df59a0b5fd3278bcbb60d2b5ce2a7dc77ea9 100644 (file)
 
   ;; For PREFETCHI support
   UNSPECV_PREFETCHI
+
+  ;; For USER_MSR support
+  UNSPECV_URDMSR
+  UNSPECV_UWRMSR
 ])
 
 ;; Constants to represent rounding modes in the ROUND instruction
   DONE;
 })
 
+(define_insn "urdmsr"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+    (unspec_volatile:DI
+      [(match_operand:DI 1 "x86_64_szext_nonmemory_operand" "reZ")]
+      UNSPECV_URDMSR))]
+  "TARGET_USER_MSR && TARGET_64BIT"
+  "urdmsr\t{%1, %0|%0, %1}"
+  [(set_attr "prefix" "vex")
+   (set_attr "type" "other")])
+
+(define_insn "uwrmsr"
+  [(unspec_volatile
+    [(match_operand:DI 0 "x86_64_szext_nonmemory_operand" "reZ")
+      (match_operand:DI 1 "register_operand" "r")]
+      UNSPECV_UWRMSR)]
+  "TARGET_USER_MSR && TARGET_64BIT"
+  "uwrmsr\t{%1, %0|%0, %1}"
+  [(set_attr "prefix" "vex")
+   (set_attr "type" "other")])
+
 (include "mmx.md")
 (include "sse.md")
 (include "sync.md")
index 05ba7f372443cd8fd0f0a4de98f1785790d232c1..b8382c4809988df8f167b0e93b3919594d42cd6e 100644 (file)
@@ -1344,3 +1344,7 @@ hook reg or mem constraint in inline asm to GPR16.
 mevex512
 Target Mask(ISA2_EVEX512) Var(ix86_isa_flags2) Save
 Support 512 bit vector built-in functions and code generation.
+
+musermsr
+Target Mask(ISA2_USER_MSR) Var(ix86_isa_flags2) Save
+Support USER_MSR built-in functions and code generation.
diff --git a/gcc/config/i386/usermsrintrin.h b/gcc/config/i386/usermsrintrin.h
new file mode 100644 (file)
index 0000000..9e1dbdc
--- /dev/null
@@ -0,0 +1,60 @@
+/* Copyright (C) 2022 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
+   <http://www.gnu.org/licenses/>.  */
+
+#if !defined _X86GPRINTRIN_H_INCLUDED
+#error "Never use <usermsrintrin.h> directly; include <x86gprintrin.h> instead."
+#endif
+
+#ifndef _USER_MSRINTRIN_H_INCLUDED
+#define _USER_MSRINTRIN_H_INCLUDED
+
+#ifdef __x86_64__
+
+#ifndef __USER_MSR__
+#pragma GCC push_options
+#pragma GCC target("usermsr")
+#define __DISABLE_USER_MSR__
+#endif /* __USER_MSR__ */
+
+extern __inline unsigned long long
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_urdmsr (unsigned long long __A)
+{
+  return (unsigned long long) __builtin_ia32_urdmsr (__A);
+}
+
+extern __inline void
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_uwrmsr (unsigned long long __A, unsigned long long __B)
+{
+  __builtin_ia32_uwrmsr (__A, __B);
+}
+
+#ifdef __DISABLE_USER_MSR__
+#undef __DISABLE_USER_MSR__
+#pragma GCC pop_options
+#endif /* __DISABLE_USER_MSR__ */
+
+#endif /* __x86_64__ */
+
+#endif /* _USER_MSRINTRIN_H_INCLUDED */
index f41be3ffcdebcbe5a38277bdbf9b3eef280a5f5e..11a8a9630209635d133b67a714ad30de44955c04 100644 (file)
 
 #include <hresetintrin.h>
 
+#include <usermsrintrin.h>
+
 extern __inline void
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _wbinvd (void)
index eb665188cafbcfc89e61766af565c681dca4d003..ffe8532ad91c334f365e926e9064098748dbf983 100644 (file)
@@ -7210,6 +7210,11 @@ Enable/disable the generation of the SHA512 instructions.
 @itemx no-sm4
 Enable/disable the generation of the SM4 instructions.
 
+@cindex @code{target("usermsr")} function attribute, x86
+@item usermsr
+@itemx no-usermsr
+Enable/disable the generation of the USER_MSR instructions.
+
 @cindex @code{target("cld")} function attribute, x86
 @item cld
 @itemx no-cld
index 7c5f81d9783feaff81bdfc6a9e5824e9e5c18e06..fee659462ff9de6e210cc0921b3513143d477064 100644 (file)
@@ -1444,6 +1444,7 @@ See RS/6000 and PowerPC Options.
 -mamx-tile  -mamx-int8  -mamx-bf16 -muintr -mhreset -mavxvnni
 -mavx512fp16 -mavxifma -mavxvnniint8 -mavxneconvert -mcmpccxadd -mamx-fp16
 -mprefetchi -mraoint -mamx-complex -mavxvnniint16 -msm3 -msha512 -msm4 -mapxf
+-musermsr
 -mcldemote  -mms-bitfields  -mno-align-stringops  -minline-all-stringops
 -minline-stringops-dynamically  -mstringop-strategy=@var{alg}
 -mkl -mwidekl
@@ -33830,6 +33831,9 @@ preferred alignment to @option{-mpreferred-stack-boundary=2}.
 @need 200
 @opindex mapxf
 @itemx -mapxf
+@need 200
+@opindex musermsr
+@itemx -musermsr
 These switches enable the use of instructions in the MMX, SSE,
 AVX512ER, AVX512CD, AVX512VL, AVX512BW, AVX512DQ, AVX512IFMA, AVX512VBMI, SHA,
 AES, PCLMUL, CLFLUSHOPT, CLWB, FSGSBASE, PTWRITE, RDRND, F16C, FMA, PCONFIG,
@@ -33840,9 +33844,9 @@ GFNI, VAES, WAITPKG, VPCLMULQDQ, AVX512BITALG, MOVDIRI, MOVDIR64B, AVX512BF16,
 ENQCMD, AVX512VPOPCNTDQ, AVX5124FMAPS, AVX512VNNI, AVX5124VNNIW, SERIALIZE,
 UINTR, HRESET, AMXTILE, AMXINT8, AMXBF16, KL, WIDEKL, AVXVNNI, AVX512-FP16,
 AVXIFMA, AVXVNNIINT8, AVXNECONVERT, CMPCCXADD, AMX-FP16, PREFETCHI, RAOINT,
-AMX-COMPLEX, AVXVNNIINT16, SM3, SHA512, SM4, APX_F or CLDEMOTE extended
-instruction sets. Each has a corresponding @option{-mno-} option to disable
-use of these instructions.
+AMX-COMPLEX, AVXVNNIINT16, SM3, SHA512, SM4, APX_F, USER_MSR or CLDEMOTE
+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
 @ref{x86 Built-in Functions}, for details of the functions enabled and
index 0cff2e8953ae9685c810df193720b32f57dd1b41..c20af31c64237baff70f8781b1dc47f4d1a48aa9 100644 (file)
@@ -2636,6 +2636,9 @@ Test environment appears to run executables on a simulator that
 accepts only @code{EM_SPARC} executables and chokes on @code{EM_SPARC32PLUS}
 or @code{EM_SPARCV9} executables.
 
+@item user_msr
+Target supports the execution of @code{user_msr} instructions.
+
 @item vect_cmdline_needed
 Target requires a command line argument to enable a SIMD instruction set.
 
index ca558b3e82882b53cd34b0656125023ef8fe1eb4..e0470a604837b1c83c82dc10024320e9e2078703 100644 (file)
@@ -92,6 +92,7 @@ extern void test_avxvnniint16 (void)          __attribute__((__target__("avxvnniint16"))
 extern void test_sm3 (void)                    __attribute__((__target__("sm3")));
 extern void test_sha512 (void)                 __attribute__((__target__("sha512")));
 extern void test_sm4 (void)                     __attribute__((__target__("sm4")));
+extern void test_user_msr (void)               __attribute__((__target__("usermsr")));
 
 extern void test_no_sgx (void)                 __attribute__((__target__("no-sgx")));
 extern void test_no_avx5124fmaps(void)         __attribute__((__target__("no-avx5124fmaps")));
@@ -185,6 +186,7 @@ extern void test_no_avxvnniint16 (void)             __attribute__((__target__("no-avxvnniin
 extern void test_no_sm3 (void)                 __attribute__((__target__("no-sm3")));
 extern void test_no_sha512 (void)              __attribute__((__target__("no-sha512")));
 extern void test_no_sm4 (void)                  __attribute__((__target__("no-sm4")));
+extern void test_no_user_msr (void)            __attribute__((__target__("no-usermsr")));
 
 extern void test_arch_nocona (void)            __attribute__((__target__("arch=nocona")));
 extern void test_arch_core2 (void)             __attribute__((__target__("arch=core2")));
diff --git a/gcc/testsuite/gcc.target/i386/user_msr-1.c b/gcc/testsuite/gcc.target/i386/user_msr-1.c
new file mode 100644 (file)
index 0000000..4478523
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile { target { ! ia32  }  }  } */
+/* { dg-options "-musermsr -O2"  } */
+/* { dg-final { scan-assembler-times "urdmsr\[ \\t\]\\%r\[a-z\]x, \\%r\[a-z\]x" 1  }  } */
+/* { dg-final { scan-assembler-times "urdmsr\[ \\t\]\\\$121" 1  }  } */
+/* { dg-final { scan-assembler-times "uwrmsr\[ \\t\]\\%r\[a-z\]x, \\%r\[a-z\]x" 1  }  } */
+/* { dg-final { scan-assembler-times "uwrmsr\[ \\t\]\\%r\[a-z\]x, \\\$121" 1  }  } */
+
+#include <x86gprintrin.h>
+
+volatile unsigned long long x;
+volatile unsigned long long y;
+
+void extern
+user_msr_test (void)
+{
+  x = _urdmsr(y);
+  x = _urdmsr(121);
+  _uwrmsr(y, x);
+  _uwrmsr(121, x);
+}
diff --git a/gcc/testsuite/gcc.target/i386/user_msr-2.c b/gcc/testsuite/gcc.target/i386/user_msr-2.c
new file mode 100644 (file)
index 0000000..ab0e76f
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -musermsr" } */
+/* { dg-final { scan-assembler-times "urdmsr\[ \\t\]\\%r\[a-z\]x, \\%r\[a-z\]x" 1  }  } */
+/* { dg-final { scan-assembler-times "uwrmsr\[ \\t\]\\%r\[a-z\]x, \\%r\[a-z\]x" 1  }  } */
+/* { dg-final { scan-assembler-times "movabsq\[ \\t\]\\\$20018842566655, \\%r\[a-z\]x" 1  }  } */
+
+#include <x86gprintrin.h>
+
+volatile unsigned long long x;
+
+void extern
+user_msr_test (void)
+{
+  x = _urdmsr(0x1234ffffffffULL);
+  _uwrmsr(0x1234ffffffffULL, x);
+}
index 68da4db4f3ca1467c4d0ece57fde51e2437532d5..b9479beef7c33fab5cd9e893c92d4025a00f97b1 100644 (file)
@@ -1,7 +1,7 @@
 /* Test that <x86gprintrin.h> is usable with -O -std=c89 -pedantic-errors.  */
 /* { dg-do compile } */
 /* { dg-options "-O -std=c89 -pedantic-errors -march=x86-64 -madx -mbmi -mbmi2 -mcldemote -mclflushopt -mclwb -mclzero -menqcmd -mfsgsbase -mfxsr -mhreset -mlzcnt -mlwp -mmovdiri -mmwaitx -mpconfig -mpopcnt -mpku -mptwrite -mrdpid -mrdrnd -mrdseed -mrtm -mserialize -msgx -mshstk -mtbm -mtsxldtrk -mwaitpkg -mwbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mraoint -mno-sse -mno-mmx" } */
-/* { dg-additional-options "-mcmpccxadd -mprefetchi -muintr" { target { ! ia32 } } }  */
+/* { dg-additional-options "-musermsr -mcmpccxadd -mprefetchi -muintr" { target { ! ia32 } } }  */
 
 #include <x86gprintrin.h>
 
index 737c2a26f98d544c761e60a8b98ff03a3e6b1a51..ee167ebab90d4a84cb34b402d0f6be9e0d9336e4 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
 /* { dg-options "-O2 -Werror-implicit-function-declaration -march=x86-64 -madx -mbmi -mbmi2 -mcldemote -mclflushopt -mclwb -mclzero -menqcmd -mfsgsbase -mfxsr -mhreset -mlzcnt -mlwp -mmovdiri -mmwaitx -mpconfig -mpopcnt -mpku -mptwrite -mrdpid -mrdrnd -mrdseed -mrtm -mserialize -msgx -mshstk -mtbm -mtsxldtrk -mwaitpkg -mwbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mraoint -mno-sse -mno-mmx" } */
 /* { dg-add-options bind_pic_locally } */
-/* { dg-additional-options "-mcmpccxadd -mprefetchi -muintr" { target { ! ia32 } } }  */
+/* { dg-additional-options "-musermsr -mcmpccxadd -mprefetchi -muintr" { target { ! ia32 } } }  */
 
 /* Test that the intrinsics in <x86gprintrin.h> compile with optimization.
    All of them are defined as inline functions that reference the proper
@@ -32,4 +32,8 @@
 #define __builtin_ia32_cmpccxadd(A, B, C, D) __builtin_ia32_cmpccxadd(A, B, C, 1)
 #define __builtin_ia32_cmpccxadd64(A, B, C, D) __builtin_ia32_cmpccxadd64(A, B, C, 1)
 
+/* usermsrintrin.h */
+#define __builtin_ia32_urdmsr(A) __builtin_ia32_urdmsr(1)
+#define __builtin_ia32_uwrmsr(A, B) __builtin_ia32_uwrmsr(1, B)
+
 #include <x86gprintrin.h>
index 52690b1dfb56e6e937073b65eecd2c631d9d3551..a87039149f9147d9fd6e8fbedad26b45fe5a534f 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
 /* { dg-options "-O0 -Werror-implicit-function-declaration -march=x86-64 -madx -mbmi -mbmi2 -mcldemote -mclflushopt -mclwb -mclzero -menqcmd -mfsgsbase -mfxsr -mhreset -mlzcnt -mlwp -mmovdiri -mmwaitx -mpconfig -mpopcnt -mpku -mptwrite -mrdpid -mrdrnd -mrdseed -mrtm -mserialize -msgx -mshstk -mtbm -mtsxldtrk -mwaitpkg -mwbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mraoint -mno-sse -mno-mmx" } */
 /* { dg-add-options bind_pic_locally } */
-/* { dg-additional-options "-mcmpccxadd -mprefetchi -muintr" { target { ! ia32 } } }  */
+/* { dg-additional-options "-musermsr -mcmpccxadd -mprefetchi -muintr" { target { ! ia32 } } }  */
 
 /* Test that the intrinsics in <x86gprintrin.h> compile without optimization.
    All of them are defined as inline functions that reference the proper
 #define __inline
 
 #include <x86gprintrin.h>
+
+#define _CONCAT(x,y) x ## y
+
+#define test_0(func, type, imm)                  \
+  type _CONCAT(_0,func) (int const I)    \
+           { return func (imm);  }
+
+#define test_1(func, type, op1_type)   \
+  type _CONCAT(_1,func) (op1_type A)    \
+       { return func (A); }
+
+#define test_1r(func, type, op1_type, imm)         \
+  type _CONCAT(_1r,func) (op1_type A, int const I)    \
+       { return func (imm, A); }
+
+#define test_2(func, type, op1_type,  op2_type)            \
+    type _CONCAT(_2,func) (op1_type A, op2_type B)    \
+      { return func (A, B);  }
+
+/* usermsrintrin.h */
+#ifdef __x86_64__
+test_0 (_urdmsr, unsigned long long, 1)
+test_1 (_urdmsr, unsigned long long, unsigned long long)
+test_1r (_uwrmsr, void, unsigned long long, 1)
+test_2 (_uwrmsr, void, unsigned long long, unsigned long long)
+#endif
index 94cfc583dc90d207f57cd5e9214c2cad654f5393..c3c794730205f1314d4a077582bde7482aad861d 100644 (file)
 #define extern
 #define __inline
 
+#define _CONCAT(x,y) x ## y
+
+#define test_0(func, type, imm)                  \
+  type _CONCAT(_0,func) (int const I)    \
+           { return func (imm);  }
+
+#define test_1(func, type, op1_type)   \
+  type _CONCAT(_1,func) (op1_type A)    \
+       { return func (A); }
+
+#define test_1r(func, type, op1_type, imm)         \
+  type _CONCAT(_1r,func) (op1_type A, int const I)    \
+       { return func (imm, A); }
+
+#define test_2(func, type, op1_type,  op2_type)            \
+    type _CONCAT(_2,func) (op1_type A, op2_type B)    \
+      { return func (A, B);  }
+
 #ifndef DIFFERENT_PRAGMAS
 #ifdef __x86_64__
-#pragma GCC target ("adx,bmi,bmi2,cmpccxadd,fsgsbase,fxsr,hreset,lwp,lzcnt,popcnt,prefetchi,raoint,rdrnd,rdseed,tbm,rtm,serialize,tsxldtrk,uintr,xsaveopt")
+#pragma GCC target ("adx,bmi,bmi2,cmpccxadd,fsgsbase,fxsr,hreset,lwp,lzcnt,popcnt,prefetchi,raoint,rdrnd,rdseed,tbm,rtm,serialize,tsxldtrk,uintr,usermsr,xsaveopt")
 #else
 #pragma GCC target ("adx,bmi,bmi2,fsgsbase,fxsr,hreset,lwp,lzcnt,popcnt,raoint,rdrnd,rdseed,tbm,rtm,serialize,tsxldtrk,xsaveopt")
 #endif
 
 /* x86intrin.h (LWP/BMI/BMI2/TBM/LZCNT). */
 #ifdef DIFFERENT_PRAGMAS
+#ifdef __x86_64__
+#pragma GCC target ("lwp,bmi,bmi2,tbm,lzcnt,usermsr")
+#else
 #pragma GCC target ("lwp,bmi,bmi2,tbm,lzcnt")
 #endif
+#endif
 #include <x86gprintrin.h>
+
+/* usermsrintrin.h */
+#ifdef __x86_64__
+test_0 (_urdmsr, unsigned long long, 1)
+test_1 (_urdmsr, unsigned long long, unsigned long long)
+test_1r (_uwrmsr, void, unsigned long long, 1)
+test_2 (_uwrmsr, void, unsigned long long, unsigned long long)
+#endif
index 95f3e0a003cec8a81c4efe9d07d0533ebca2a757..ef126ea76c27c2c4a9021d4e74d02f26981e9ea9 100644 (file)
 #define __builtin_ia32_cmpccxadd(A, B, C, D) __builtin_ia32_cmpccxadd(A, B, C, 1)
 #define __builtin_ia32_cmpccxadd64(A, B, C, D) __builtin_ia32_cmpccxadd64(A, B, C, 1)
 
+/* usermsrintrin.h */
+#define __builtin_ia32_urdmsr(A) __builtin_ia32_urdmsr(1)
+#define __builtin_ia32_uwrmsr(A, B) __builtin_ia32_uwrmsr(1, B)
+
 #ifdef __x86_64__
-#pragma GCC target ("adx,bmi,bmi2,clflushopt,clwb,clzero,cmpccxadd,enqcmd,fsgsbase,fxsr,hreset,lwp,lzcnt,mwaitx,pconfig,pku,popcnt,prefetchi,raoint,rdpid,rdrnd,rdseed,tbm,rtm,serialize,sgx,tsxldtrk,uintr,xsavec,xsaveopt,xsaves,wbnoinvd")
+#pragma GCC target ("adx,bmi,bmi2,clflushopt,clwb,clzero,cmpccxadd,enqcmd,fsgsbase,fxsr,hreset,lwp,lzcnt,mwaitx,pconfig,pku,popcnt,prefetchi,raoint,rdpid,rdrnd,rdseed,tbm,rtm,serialize,sgx,tsxldtrk,uintr,usermsr,xsavec,xsaveopt,xsaves,wbnoinvd")
 #else
 #pragma GCC target ("adx,bmi,bmi2,clflushopt,clwb,clzero,enqcmd,fsgsbase,fxsr,hreset,lwp,lzcnt,mwaitx,pconfig,pku,popcnt,raoint,rdpid,rdrnd,rdseed,tbm,rtm,serialize,sgx,tsxldtrk,xsavec,xsaveopt,xsaves,wbnoinvd")
 #endif