From: Matthew Fortune <[email protected]>

The XBurst MXU (Matrix Unit) extension is an application-specific
extension implemented by XBurst processors. Add -mmxu and -mno-mxu as
MIPS target options, analogously to the MCU ASE.

GCC does not currently generate MXU instructions. The option records
the selected state in TARGET_MXU, defines __mips_mxu, emits .module mxu,
and passes the option to an assembler with XBurst MXU support. This
allows MXU instructions to be used in inline assembly.

As with -mmcu, define -mmxu as a Target option. ASM_SPEC forwards
-mmxu and -mno-mxu to the assembler.

This replaces the reverted commit b5404c42dde
("MIPS: Add -mmxu and -mno-mxu driver pass through").

gcc/ChangeLog:

        * config/mips/mips.cc (mips_file_start): Emit .module mxu.
        * config/mips/mips.h (TARGET_CPU_CPP_BINUTILS): Define
        __mips_mxu when TARGET_MXU.
        (ASM_SPEC): Pass -mmxu and -mno-mxu to the assembler.
        * config/mips/mips.opt (mmxu): New target option.
        * doc/invoke.texi (MIPS Options): Document -mmxu and
        -mno-mxu.

gcc/testsuite/ChangeLog:

        * gcc.target/mips/mips.exp (mips_option_groups): Recognize
        the MXU option group.
        (mips-dg-init): Detect the default MXU state.
        * gcc.target/mips/mxu-compile-no.c: New test.
        * gcc.target/mips/mxu-compile.c: New test.
        * gcc.target/mips/mxu-driver-no.c: New test.
        * gcc.target/mips/mxu-driver.c: New test.

Based on the commit 9acbf0b0efdfcc27e30b1db7a707dbe9cc6b64eb
from https://github.com/MIPS/gcc

Signed-off-by: Matthew Fortune <[email protected]>
Signed-off-by: Faraz Shahbazker <[email protected]>
Signed-off-by: Aleksandar Rakic <[email protected]>
Signed-off-by: Eldar Osmanovic <[email protected]>
---
 gcc/config/mips/mips.cc                        |  2 ++
 gcc/config/mips/mips.h                         |  4 ++++
 gcc/config/mips/mips.opt                       |  4 ++++
 gcc/doc/invoke.texi                            | 12 +++++++++++-
 gcc/testsuite/gcc.target/mips/mips.exp         |  7 +++++++
 gcc/testsuite/gcc.target/mips/mxu-compile-no.c | 14 ++++++++++++++
 gcc/testsuite/gcc.target/mips/mxu-compile.c    | 14 ++++++++++++++
 gcc/testsuite/gcc.target/mips/mxu-driver-no.c  | 11 +++++++++++
 gcc/testsuite/gcc.target/mips/mxu-driver.c     | 11 +++++++++++
 9 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/mips/mxu-compile-no.c
 create mode 100644 gcc/testsuite/gcc.target/mips/mxu-compile.c
 create mode 100644 gcc/testsuite/gcc.target/mips/mxu-driver-no.c
 create mode 100644 gcc/testsuite/gcc.target/mips/mxu-driver.c

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index e5477646793..6ea55a4d0f7 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -10541,6 +10541,8 @@ mips_file_start (void)
     fputs ("\t.module\teva\n", asm_out_file);
   if (TARGET_MCU)
     fputs ("\t.module\tmcu\n", asm_out_file);
+  if (TARGET_MXU)
+    fputs ("\t.module\tmxu\n", asm_out_file);
   if (TARGET_MDMX)
     fputs ("\t.module\tmdmx\n", asm_out_file);
   if (TARGET_MIPS3D)
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index 48a562f2d39..c9f79b082c5 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -500,6 +500,9 @@ struct mips_cpu_info {
       if (TARGET_MCU)                                                  \
        builtin_define ("__mips_mcu");                                  \
                                                                        \
+      if (TARGET_MXU)                                                  \
+       builtin_define ("__mips_mxu");                                  \
+                                                                       \
       if (TARGET_EVA)                                                  \
        builtin_define ("__mips_eva");                                  \
                                                                        \
@@ -1490,6 +1493,7 @@ struct mips_cpu_info {
 %{mloongson-ext2} %{mno-loongson-ext2} \
 %{msmartmips} %{mno-smartmips} \
 %{mmt} %{mno-mt} \
+%{mmxu} %{mno-mxu} \
 %{mfix-r5900} %{mno-fix-r5900} \
 %{mfix-rm7000} %{mno-fix-rm7000} \
 %{mfix-vr4120} %{mfix-vr4130} \
diff --git a/gcc/config/mips/mips.opt b/gcc/config/mips/mips.opt
index eb14761ea27..5135bed42ea 100644
--- a/gcc/config/mips/mips.opt
+++ b/gcc/config/mips/mips.opt
@@ -332,6 +332,10 @@ mmt
 Target Var(TARGET_MT)
 Allow the use of MT instructions.
 
+mmxu
+Target Var(TARGET_MXU)
+Use XBurst MXU instructions.
+
 mno-float
 Target RejectNegative Var(TARGET_NO_FLOAT) Condition(TARGET_SUPPORTS_NO_FLOAT)
 Prevent the use of all floating-point operations.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 78052b229a5..afb9c2e5c2f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1232,7 +1232,7 @@ Objective-C and Objective-C++ Dialects}.
 -mmicromips  -mmsa
 -mloongson-mmi  -mloongson-ext  -mloongson-ext2
 -mfpu=@var{fpu-type}
--msmartmips  -mpaired-single  -mdmx  -mips3d  -mmt  -mllsc
+-msmartmips  -mpaired-single  -mdmx  -mips3d  -mmt  -mmxu  -mllsc
 -mlong64  -mlong32  -msym32
 -G@var{num}  -mno-local-sdata  -mno-extern-sdata  -mno-gopt
 -membedded-data  -muninit-const-in-rodata
@@ -29430,6 +29430,16 @@ Use (do not use) MT Multithreading instructions.
 @itemx -mno-mcu
 Use (do not use) the MIPS MCU ASE instructions.
 
+@opindex mmxu
+@opindex mno-mxu
+@item -mmxu
+@itemx -mno-mxu
+Use (do not use) the XBurst MXU (Matrix Unit) extension instructions.
+GCC does not currently generate MXU instructions, but @option{-mmxu}
+enables the use of MXU instructions in inline assembly, defines the
+preprocessor macro @code{__mips_mxu}, and passes the option to the
+assembler.  This option requires an assembler with XBurst MXU support.
+
 @opindex meva
 @opindex mno-eva
 @item -meva
diff --git a/gcc/testsuite/gcc.target/mips/mips.exp 
b/gcc/testsuite/gcc.target/mips/mips.exp
index 9492b1dcaf8..1dd4d8bbdb6 100644
--- a/gcc/testsuite/gcc.target/mips/mips.exp
+++ b/gcc/testsuite/gcc.target/mips/mips.exp
@@ -299,6 +299,7 @@ foreach option {
     mcount-ra-address
     odd-spreg
     msa
+    mxu
     loongson-mmi
     loongson-ext
     loongson-ext2
@@ -899,6 +900,12 @@ proc mips-dg-init {} {
            "-mno-msa"
            #endif
 
+           #ifdef __mips_mxu
+           "-mmxu"
+           #else
+           "-mno-mxu"
+           #endif
+
            #ifdef __mips_loongson_mmi
            "-mloongson-mmi"
            #else
diff --git a/gcc/testsuite/gcc.target/mips/mxu-compile-no.c 
b/gcc/testsuite/gcc.target/mips/mxu-compile-no.c
new file mode 100644
index 00000000000..1045467d0b5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/mxu-compile-no.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-mno-mxu" } */
+
+#ifdef __mips_mxu
+#error __mips_mxu is defined
+#endif
+
+int
+main (void)
+{
+  return 0;
+}
+
+/* { dg-final { scan-assembler-not "\t\\.module\tmxu\n" } } */
diff --git a/gcc/testsuite/gcc.target/mips/mxu-compile.c 
b/gcc/testsuite/gcc.target/mips/mxu-compile.c
new file mode 100644
index 00000000000..598b7b9bd0f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/mxu-compile.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-mmxu" } */
+
+#ifndef __mips_mxu
+#error __mips_mxu is not defined
+#endif
+
+int
+main (void)
+{
+  return 0;
+}
+
+/* { dg-final { scan-assembler "\t\\.module\tmxu\n" } } */
diff --git a/gcc/testsuite/gcc.target/mips/mxu-driver-no.c 
b/gcc/testsuite/gcc.target/mips/mxu-driver-no.c
new file mode 100644
index 00000000000..3946e0a62f9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/mxu-driver-no.c
@@ -0,0 +1,11 @@
+/* { dg-do assemble } */
+/* { dg-additional-options "-mno-mxu -###" } */
+
+int
+main (void)
+{
+  return 0;
+}
+
+/* { dg-message ".*/.*as .* -mno-mxu" "assembler options" { target *-*-* } 0 } 
*/
+/* { dg-excess-errors "" } */
diff --git a/gcc/testsuite/gcc.target/mips/mxu-driver.c 
b/gcc/testsuite/gcc.target/mips/mxu-driver.c
new file mode 100644
index 00000000000..0ff56ceb0ea
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/mxu-driver.c
@@ -0,0 +1,11 @@
+/* { dg-do assemble } */
+/* { dg-additional-options "-mmxu -###" } */
+
+int
+main (void)
+{
+  return 0;
+}
+
+/* { dg-message ".*/.*as .* -mmxu" "assembler options" { target *-*-* } 0 } */
+/* { dg-excess-errors "" } */
-- 
2.43.0

Reply via email to