arm: CLI for Custom Datapath Extension (CDE)
authorDennis Zhang <dennis.zh@live.com>
Wed, 8 Apr 2020 14:06:31 +0000 (15:06 +0100)
committerDennis Zhang <dennis.zh@live.com>
Wed, 8 Apr 2020 14:06:31 +0000 (15:06 +0100)
This patch is part of a series that adds support for the Arm Custom
Datapath Extension. It defines the options cdecp0-cdecp7 for CLI to
enable the CDE on corresponding coprocessor 0-7.
It also adds new target supports for CDE feature testsuite.

gcc/ChangeLog:
2020-04-08  Dennis Zhang  <dennis.zhang@arm.com>

* config.gcc: Add arm_cde.h.
* config/arm/arm-c.c (arm_cpu_builtins): Define or undefine
__ARM_FEATURE_CDE and __ARM_FEATURE_CDE_COPROC.
* config/arm/arm-cpus.in (cdecp0, cdecp1, ..., cdecp7): New options.
* config/arm/arm.c (arm_option_reconfigure_globals): Configure
arm_arch_cde and arm_arch_cde_coproc to store the feature bits.
* config/arm/arm.h (TARGET_CDE): New macro.
* config/arm/arm_cde.h: New file.
* doc/invoke.texi: Document CDE options +cdecp[0-7].
* doc/sourcebuild.texi (arm_v8m_main_cde_ok): Document new target
supports option.
(arm_v8m_main_cde_fp, arm_v8_1m_main_cde_mve): Likewise.

gcc/testsuite/ChangeLog:
2020-04-08  Dennis Zhang  <dennis.zhang@arm.com>

* gcc.target/arm/pragma_cde.c: New test.
* lib/target-supports.exp (arm_v8m_main_cde_ok): New target support
option.
(arm_v8m_main_cde_fp, arm_v8_1m_main_cde_mve): Likewise.

12 files changed:
gcc/ChangeLog
gcc/config.gcc
gcc/config/arm/arm-c.c
gcc/config/arm/arm-cpus.in
gcc/config/arm/arm.c
gcc/config/arm/arm.h
gcc/config/arm/arm_cde.h [new file with mode: 0644]
gcc/doc/invoke.texi
gcc/doc/sourcebuild.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/pragma_cde.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp

index d432912a9738f071e586066d0612df50738fed64..ff5c1c5e2a5ecb6035ad875ae8841687fe230c50 100644 (file)
@@ -1,3 +1,18 @@
+2020-04-08  Dennis Zhang  <dennis.zhang@arm.com>
+
+       * config.gcc: Add arm_cde.h.
+       * config/arm/arm-c.c (arm_cpu_builtins): Define or undefine
+       __ARM_FEATURE_CDE and __ARM_FEATURE_CDE_COPROC.
+       * config/arm/arm-cpus.in (cdecp0, cdecp1, ..., cdecp7): New options.
+       * config/arm/arm.c (arm_option_reconfigure_globals): Configure
+       arm_arch_cde and arm_arch_cde_coproc to store the feature bits.
+       * config/arm/arm.h (TARGET_CDE): New macro.
+       * config/arm/arm_cde.h: New file.
+       * doc/invoke.texi: Document CDE options +cdecp[0-7].
+       * doc/sourcebuild.texi (arm_v8m_main_cde_ok): Document new target
+       supports option.
+       (arm_v8m_main_cde_fp, arm_v8_1m_main_cde_mve): Likewise.
+
 2020-04-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/94516
index 13e3cb753e2c6b9b326d182ffb38944fb44454a5..7624c654c513187934d301b7da8c87e073097ad0 100644 (file)
@@ -346,7 +346,7 @@ arc*-*-*)
 arm*-*-*)
        cpu_type=arm
        extra_objs="arm-builtins.o aarch-common.o"
-       extra_headers="mmintrin.h arm_neon.h arm_acle.h arm_fp16.h arm_cmse.h arm_bf16.h arm_mve.h"
+       extra_headers="mmintrin.h arm_neon.h arm_acle.h arm_fp16.h arm_cmse.h arm_bf16.h arm_mve.h arm_cde.h"
        target_type_format_char='%'
        c_target_objs="arm-c.o"
        cxx_target_objs="arm-c.o"
index 73bdb9cfae03f51e6fd5ef260900c0a6bf165486..7e92e8a83aed262c03129cc8e565b8beef6cd3b5 100644 (file)
@@ -237,6 +237,12 @@ arm_cpu_builtins (struct cpp_reader* pfile)
       builtin_define_with_int_value ("__ARM_FEATURE_COPROC", coproc_level);
     }
 
+  def_or_undef_macro (pfile, "__ARM_FEATURE_CDE", TARGET_CDE);
+  cpp_undef (pfile, "__ARM_FEATURE_CDE_COPROC");
+  if (TARGET_CDE)
+    builtin_define_with_int_value ("__ARM_FEATURE_CDE_COPROC",
+                                  arm_arch_cde_coproc);
+
   def_or_undef_macro (pfile, "__ARM_FEATURE_MATMUL_INT8", TARGET_I8MM);
   def_or_undef_macro (pfile, "__ARM_FEATURE_BF16_SCALAR_ARITHMETIC",
                      TARGET_BF16_FP);
index 77b43090d69a599d8806cfcc02037e1bbed6e7a1..fba34e556fbe6285a6c07e50e1dad188e16a44ec 100644 (file)
@@ -211,6 +211,16 @@ define feature i8mm
 # Brain half-precision floating-point extension. Optional from v8.2-A.
 define feature bf16
 
+# Arm Custom Datapath Extension (CDE).
+define feature cdecp0
+define feature cdecp1
+define feature cdecp2
+define feature cdecp3
+define feature cdecp4
+define feature cdecp5
+define feature cdecp6
+define feature cdecp7
+
 # Feature groups.  Conventionally all (or mostly) upper case.
 # ALL_FPU lists all the feature bits associated with the floating-point
 # unit; these will all be removed if the floating-point unit is disabled
@@ -676,6 +686,14 @@ begin arch armv8-m.main
  option fp.dp add FPv5 FP_DBL
  option nofp remove ALL_FP
  option nodsp remove armv7em
+ option cdecp0 add cdecp0
+ option cdecp1 add cdecp1
+ option cdecp2 add cdecp2
+ option cdecp3 add cdecp3
+ option cdecp4 add cdecp4
+ option cdecp5 add cdecp5
+ option cdecp6 add cdecp6
+ option cdecp7 add cdecp7
 end arch armv8-m.main
 
 begin arch armv8-r
@@ -707,6 +725,14 @@ begin arch armv8.1-m.main
  option nofp remove ALL_FP
  option mve add MVE
  option mve.fp add MVE_FP
+ option cdecp0 add cdecp0
+ option cdecp1 add cdecp1
+ option cdecp2 add cdecp2
+ option cdecp3 add cdecp3
+ option cdecp4 add cdecp4
+ option cdecp5 add cdecp5
+ option cdecp6 add cdecp6
+ option cdecp7 add cdecp7
 end arch armv8.1-m.main
 
 begin arch iwmmxt
index cd0a49cdb63690d794981a73e1e7e0d47f6d1987..da0bfbc35501ba40324a38ee9ebc194f43196837 100644 (file)
@@ -1021,6 +1021,13 @@ int arm_arch_i8mm = 0;
 /* Nonzero if chip supports the BFloat16 instructions.  */
 int arm_arch_bf16 = 0;
 
+/* Nonzero if chip supports the Custom Datapath Extension.  */
+int arm_arch_cde = 0;
+int arm_arch_cde_coproc = 0;
+const int arm_arch_cde_coproc_bits[] = {
+  0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80
+};
+
 /* The condition codes of the ARM, and the inverse function.  */
 static const char * const arm_condition_codes[] =
 {
@@ -3740,6 +3747,21 @@ arm_option_reconfigure_globals (void)
       arm_fp16_format = ARM_FP16_FORMAT_IEEE;
     }
 
+  arm_arch_cde = 0;
+  arm_arch_cde_coproc = 0;
+  int cde_bits[] = {isa_bit_cdecp0, isa_bit_cdecp1, isa_bit_cdecp2,
+                   isa_bit_cdecp3, isa_bit_cdecp4, isa_bit_cdecp5,
+                   isa_bit_cdecp6, isa_bit_cdecp7};
+  for (int i = 0, e = ARRAY_SIZE (cde_bits); i < e; i++)
+    {
+      int cde_bit = bitmap_bit_p (arm_active_target.isa, cde_bits[i]);
+      if (cde_bit)
+       {
+         arm_arch_cde |= cde_bit;
+         arm_arch_cde_coproc |= arm_arch_cde_coproc_bits[i];
+       }
+    }
+
   /* And finally, set up some quirks.  */
   arm_arch_no_volatile_ce
     = bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_no_volatile_ce);
index fb55f73c62b800009242947ffd4348003068b42a..343235d0cbc0be4fa7c773da71567d4ae267494b 100644 (file)
@@ -354,6 +354,9 @@ emission of floating point pcs attributes.  */
 /* Nonzero if disallow volatile memory access in IT block.  */
 #define TARGET_NO_VOLATILE_CE          (arm_arch_no_volatile_ce)
 
+/* Nonzero if chip supports the Custom Datapath Extension.  */
+#define TARGET_CDE     (arm_arch_cde && arm_arch8 && !arm_arch_notm)
+
 /* Should constant I be slplit for OP.  */
 #define DONT_EARLY_SPLIT_CONSTANT(i, op) \
                                ((optimize >= 2) \
@@ -568,6 +571,11 @@ extern int arm_arch_i8mm;
 /* Nonzero if chip supports the BFloat16 instructions.  */
 extern int arm_arch_bf16;
 
+/* Nonzero if chip supports the Custom Datapath Extension.  */
+extern int arm_arch_cde;
+extern int arm_arch_cde_coproc;
+extern const int arm_arch_cde_coproc_bits[];
+
 #ifndef TARGET_DEFAULT
 #define TARGET_DEFAULT  (MASK_APCS_FRAME)
 #endif
diff --git a/gcc/config/arm/arm_cde.h b/gcc/config/arm/arm_cde.h
new file mode 100644 (file)
index 0000000..f975754
--- /dev/null
@@ -0,0 +1,40 @@
+/* Arm Custom Datapath Extension (CDE) intrinsics include file.
+
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Arm Ltd.
+
+   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/>.  */
+
+#ifndef _GCC_ARM_CDE_H
+#define _GCC_ARM_CDE_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index e3e652ff6c15b1e953fa133869337c822d0524b9..be7b5bb7d718fd8113b7a04794b6aa0054a8be80 100644 (file)
@@ -18679,6 +18679,10 @@ The single- and double-precision floating-point instructions.
 
 @item +nofp
 Disable the floating-point extension.
+
+@item +cdecp0, +cdecp1, ... , +cdecp7
+Enable the Custom Datapath Extension (CDE) on selected coprocessors according
+to the numbers given in the options in the range 0 to 7.
 @end table
 
 @item  armv8-m.main
@@ -18697,6 +18701,10 @@ The single- and double-precision floating-point instructions.
 
 @item +nofp
 Disable the floating-point extension.
+
+@item +cdecp0, +cdecp1, ... , +cdecp7
+Enable the Custom Datapath Extension (CDE) on selected coprocessors according
+to the numbers given in the options in the range 0 to 7.
 @end table
 
 @item armv8-r
index 91b46cc654ba9a28cf941a2adbebcd99f19a6ba5..26a57e3199b885e895bb14d28d3f9e97bfb3c100 100644 (file)
@@ -1904,6 +1904,21 @@ ARM target supports options to generate instructions from ARMv8.1-M with
 the M-Profile Vector Extension (MVE). Some multilibs may be incompatible
 with these options.
 
+@item arm_v8m_main_cde
+ARM target supports options to generate instructions from ARMv8-M with
+the Custom Datapath Extension (CDE). Some multilibs may be incompatible
+with these options.
+
+@item arm_v8m_main_cde_fp
+ARM target supports options to generate instructions from ARMv8-M with
+the Custom Datapath Extension (CDE) and floating-point (VFP).
+Some multilibs may be incompatible with these options.
+
+@item arm_v8_1m_main_cde_mve
+ARM target supports options to generate instructions from ARMv8.1-M with
+the Custom Datapath Extension (CDE) and M-Profile Vector Extension (MVE).
+Some multilibs may be incompatible with these options.
+
 @item arm_prefer_ldrd_strd
 ARM target prefers @code{LDRD} and @code{STRD} instructions over
 @code{LDM} and @code{STM} instructions.
index 9627b2900fabef687c29ff128c5f40d2d5bb5116..c69c8ce11c010053f8da96fa3dc45935ef808b9b 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-08  Dennis Zhang  <dennis.zhang@arm.com>
+
+       * gcc.target/arm/pragma_cde.c: New test.
+       * lib/target-supports.exp (arm_v8m_main_cde_ok): New target support
+       option.
+       (arm_v8m_main_cde_fp, arm_v8_1m_main_cde_mve): Likewise.
+
 2020-04-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/94325
diff --git a/gcc/testsuite/gcc.target/arm/pragma_cde.c b/gcc/testsuite/gcc.target/arm/pragma_cde.c
new file mode 100644 (file)
index 0000000..b66e22d
--- /dev/null
@@ -0,0 +1,98 @@
+/* Test for CDE #pragma target macros.  */
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_v8m_main_cde_ok } */
+/* { dg-add-options arm_v8m_main_cde } */
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main")
+#ifdef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is defined but should not be"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp0")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x1
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp1")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x2
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp2")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x4
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp3")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x8
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp4")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x10
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp5")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x20
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp6")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x40
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp7")
+#ifndef __ARM_FEATURE_CDE
+#error "__ARM_FEATURE_CDE is not defined but should be"
+#endif
+#if __ARM_FEATURE_CDE_COPROC != 0x80
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
+
+#pragma GCC push_options
+#pragma GCC target ("arch=armv8-m.main+cdecp0+cdecp1")
+#if __ARM_FEATURE_CDE_COPROC != 0x3
+#error "__ARM_FEATURE_CDE_COPROC is not defined as configured"
+#endif
+#pragma GCC pop_options
index 0dfe3ae0651a502ac886cc20f29243bf49ae43cc..050b4ba452fda03bb13c3722e6edc313b25fb1eb 100644 (file)
@@ -5103,6 +5103,65 @@ proc add_options_for_arm_v8_2a_bf16_neon { flags } {
     return "$flags $et_arm_v8_2a_bf16_neon_flags"
 }
 
+# A series of routines are created to 1) check if a given architecture is
+# effective (check_effective_target_*_ok) and then 2) give the corresponding
+# flags that enable the architecture (add_options_for_*).
+# The series includes:
+#   arm_v8m_main_cde: Armv8-m CDE (Custom Datapath Extension).
+#   arm_v8m_main_cde_fp: Armv8-m CDE with FP registers.
+#   arm_v8_1m_main_cde_mve: Armv8.1-m CDE with MVE.
+# Usage:
+#   /* { dg-require-effective-target arm_v8m_main_cde_ok } */
+#   /* { dg-add-options arm_v8m_main_cde } */
+# The tests are valid for Arm.
+
+foreach { armfunc armflag armdef } {
+       arm_v8m_main_cde
+               "-march=armv8-m.main+cdecp0 -mthumb"
+               "defined (__ARM_FEATURE_CDE)"
+       arm_v8m_main_cde_fp
+               "-march=armv8-m.main+fp+cdecp0 -mthumb"
+               "defined (__ARM_FEATURE_CDE) && defined (__ARM_FP)"
+       arm_v8_1m_main_cde_mve
+               "-march=armv8.1-m.main+mve+cdecp0 -mthumb"
+               "defined (__ARM_FEATURE_CDE) && defined (__ARM_FEATURE_MVE)"
+       } {
+    eval [string map [list FUNC $armfunc FLAG $armflag DEF $armdef ] {
+       proc check_effective_target_FUNC_ok_nocache { } {
+           global et_FUNC_flags
+           set et_FUNC_flags ""
+
+           if { ![istarget arm*-*-*] } {
+               return 0;
+           }
+
+           if { [check_no_compiler_messages_nocache FUNC_ok assembly {
+               #if !(DEF)
+               #error "DEF failed"
+               #endif
+           } "FLAG"] } {
+                   set et_FUNC_flags "FLAG"
+                   return 1
+           }
+
+           return 0;
+       }
+
+       proc check_effective_target_FUNC_ok { } {
+           return [check_cached_effective_target FUNC_ok \
+                   check_effective_target_FUNC_ok_nocache]
+       }
+
+       proc add_options_for_FUNC { flags } {
+           if { ! [check_effective_target_FUNC_ok] } {
+               return "$flags"
+           }
+           global et_FUNC_flags
+           return "$flags $et_FUNC_flags"
+       }
+    }]
+}
+
 # Return 1 if the target supports executing ARMv8 NEON instructions, 0
 # otherwise.