public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/dmf004)] Add saturating subtract built-in.
@ 2022-11-17 21:53 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2022-11-17 21:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:28e4cc47506f1fef8111353e34357a0214aa905f

commit 28e4cc47506f1fef8111353e34357a0214aa905f
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Nov 11 19:45:57 2022 -0500

    Add saturating subtract built-in.
    
    This patch adds support for a saturating subtract built-in function that may be
    added to a future PowerPC processor.  Note, if it is added, the name of the
    built-in function may change before GCC 13 is released.  If the name changes, we
    will submit a patch changing the name.
    
    I did add support for providing dense math built-in functions, even though at
    present, we have not added any new built-in functions for dense math.
    
    2022-11-11   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs6000-builtin.cc (rs6000_invalid_builtin): Add support
            for flagging invalid use of future built-in functions.
            (rs6000_builtin_is_supported): Add support for future built-in
            functions.
            * config/rs6000/rs6000-builtins.def (__builtin_saturate_subtract32): New
            built-in function for -mcpu=future.
            (__builtin_saturate_subtract64): Likewise.
            * config/rs6000/rs6000-gen-builtins.cc (enum bif_stanza): Add stanzas
            for -mcpu=future built-ins.
            (stanza_map): Likewise.
            (enable_string): Likewise.
            (struct attrinfo): Likewise.
            (parse_bif_attrs): Likewise.
            (write_decls): Likewise.
            * config/rs6000/rs6000.md (sat_sub<mode>3): Add saturating subtract
            built-in insn declarations.
            (sat_sub<mode>3_dot): Likewise.
            (sat_sub<mode>3_dot2): Likewise.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/subfus-1.c: New test.
            * gcc.target/powerpc/subfus-2.c: Likewise.
            * lib/target-supports.exp (check_effective_target_powerpc_subfus_ok):
            New effective target.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc         | 17 ++++++++
 gcc/config/rs6000/rs6000-builtins.def       | 11 ++++++
 gcc/config/rs6000/rs6000-gen-builtins.cc    | 35 ++++++++++++++---
 gcc/config/rs6000/rs6000.md                 | 60 +++++++++++++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-1.c | 32 +++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-2.c | 32 +++++++++++++++
 gcc/testsuite/lib/target-supports.exp       | 16 ++++++++
 7 files changed, 198 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc
index f4eba184db8..1ac00e4b26c 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -139,6 +139,17 @@ rs6000_invalid_builtin (enum rs6000_gen_builtins fncode)
     case ENB_MMA:
       error ("%qs requires the %qs option", name, "-mmma");
       break;
+    case ENB_FUTURE:
+      error ("%qs requires the %qs option", name, "-mcpu=future");
+      break;
+    case ENB_FUTURE_64:
+      error ("%qs requires the %qs option and either the %qs or %qs option",
+	     name, "-mcpu=future", "-m64", "-mpowerpc64");
+      break;
+    case ENB_DM:
+      error ("%qs requires the %qs or %qs options", name, "-mcpu=future",
+	     "-mdense-math");
+      break;
     default:
     case ENB_ALWAYS:
       gcc_unreachable ();
@@ -194,6 +205,12 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins fncode)
       return TARGET_HTM;
     case ENB_MMA:
       return TARGET_MMA;
+    case ENB_FUTURE:
+      return TARGET_FUTURE;
+    case ENB_FUTURE_64:
+      return TARGET_FUTURE && TARGET_POWERPC64;
+    case ENB_DM:
+      return TARGET_DENSE_MATH;
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def
index f76f54793d7..ee141c1d99e 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -139,6 +139,8 @@
 ;   endian   Needs special handling for endianness
 ;   ibmld    Restrict usage to the case when TFmode is IBM-128
 ;   ibm128   Restrict usage to the case where __ibm128 is supported or if ibmld
+;   future   Restrict usage to future instructions
+;   dm       Restrict usage to dense math
 ;
 ; Each attribute corresponds to extra processing required when
 ; the built-in is expanded.  All such special processing should
@@ -4108,3 +4110,12 @@
 
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
     STXVP nothing {mma,pair}
+
+[future]
+  const signed int __builtin_saturate_subtract32 (signed int, signed int);
+  SAT_SUBSI sat_subsi3 {}
+
+[future-64]
+  const signed long __builtin_saturate_subtract64 (signed long, signed long);
+  SAT_SUBDI sat_subdi3 {}
+
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.cc b/gcc/config/rs6000/rs6000-gen-builtins.cc
index 0bd7a535e5f..f4020141243 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.cc
+++ b/gcc/config/rs6000/rs6000-gen-builtins.cc
@@ -233,6 +233,9 @@ enum bif_stanza
  BSTZ_P10,
  BSTZ_P10_64,
  BSTZ_MMA,
+ BSTZ_FUTURE,
+ BSTZ_FUTURE_64,
+ BSTZ_DM,
  NUMBIFSTANZAS
 };
 
@@ -266,7 +269,10 @@ static stanza_entry stanza_map[NUMBIFSTANZAS] =
     { "htm",		BSTZ_HTM	},
     { "power10",	BSTZ_P10	},
     { "power10-64",	BSTZ_P10_64	},
-    { "mma",		BSTZ_MMA	}
+    { "mma",		BSTZ_MMA	},
+    { "future",		BSTZ_FUTURE	},
+    { "future-64",	BSTZ_FUTURE_64	},
+    { "dm",		BSTZ_DM		},
   };
 
 static const char *enable_string[NUMBIFSTANZAS] =
@@ -291,7 +297,10 @@ static const char *enable_string[NUMBIFSTANZAS] =
     "ENB_HTM",
     "ENB_P10",
     "ENB_P10_64",
-    "ENB_MMA"
+    "ENB_MMA",
+    "ENB_FUTURE",
+    "ENB_FUTURE_64",
+    "ENB_DM",
   };
 
 /* Function modifiers provide special handling for const, pure, and fpmath
@@ -395,6 +404,8 @@ struct attrinfo
   bool isendian;
   bool isibmld;
   bool isibm128;
+  bool isfuture;
+  bool isdm;
 };
 
 /* Fields associated with a function prototype (bif or overload).  */
@@ -1477,7 +1488,8 @@ parse_bif_attrs (attrinfo *attrptr)
 	"ldvec = %d, stvec = %d, reve = %d, pred = %d, htm = %d, "
 	"htmspr = %d, htmcr = %d, mma = %d, quad = %d, pair = %d, "
 	"mmaint = %d, no32bit = %d, 32bit = %d, cpu = %d, ldstmask = %d, "
-	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d.\n",
+	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d,",
+	"future = %d, dm = %d.\n",
 	attrptr->isinit, attrptr->isset, attrptr->isextract,
 	attrptr->isnosoft, attrptr->isldvec, attrptr->isstvec,
 	attrptr->isreve, attrptr->ispred, attrptr->ishtm, attrptr->ishtmspr,
@@ -1485,7 +1497,7 @@ parse_bif_attrs (attrinfo *attrptr)
 	attrptr->ismmaint, attrptr->isno32bit, attrptr->is32bit,
 	attrptr->iscpu, attrptr->isldstmask, attrptr->islxvrse,
 	attrptr->islxvrze, attrptr->isendian, attrptr->isibmld,
-	attrptr->isibm128);
+	attrptr->isibm128, attrptr->isfuture, attrptr->isdm);
 #endif
 
   return PC_OK;
@@ -2257,7 +2269,10 @@ write_decls (void)
   fprintf (header_file, "  ENB_HTM,\n");
   fprintf (header_file, "  ENB_P10,\n");
   fprintf (header_file, "  ENB_P10_64,\n");
-  fprintf (header_file, "  ENB_MMA\n");
+  fprintf (header_file, "  ENB_MMA,\n");
+  fprintf (header_file, "  ENB_FUTURE,\n");
+  fprintf (header_file, "  ENB_FUTURE_64,\n");
+  fprintf (header_file, "  ENB_DM\n");
   fprintf (header_file, "};\n\n");
 
   fprintf (header_file, "#define PPC_MAXRESTROPNDS 3\n");
@@ -2301,6 +2316,8 @@ write_decls (void)
   fprintf (header_file, "#define bif_endian_bit\t\t(0x00200000)\n");
   fprintf (header_file, "#define bif_ibmld_bit\t\t(0x00400000)\n");
   fprintf (header_file, "#define bif_ibm128_bit\t\t(0x00800000)\n");
+  fprintf (header_file, "#define bif_future_bit\t\t(0x01000000)\n");
+  fprintf (header_file, "#define bif_dm_bit\t\t(0x02000000)\n");
   fprintf (header_file, "\n");
   fprintf (header_file,
 	   "#define bif_is_init(x)\t\t((x).bifattrs & bif_init_bit)\n");
@@ -2350,6 +2367,10 @@ write_decls (void)
 	   "#define bif_is_ibmld(x)\t((x).bifattrs & bif_ibmld_bit)\n");
   fprintf (header_file,
 	   "#define bif_is_ibm128(x)\t((x).bifattrs & bif_ibm128_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_future(x)\t((x).bifattrs & bif_future_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_dm(x)\t((x).bifattrs & bif_dm_bit)\n");
   fprintf (header_file, "\n");
 
   fprintf (header_file,
@@ -2548,6 +2569,10 @@ write_bif_static_init (void)
 	fprintf (init_file, " | bif_ibmld_bit");
       if (bifp->attrs.isibm128)
 	fprintf (init_file, " | bif_ibm128_bit");
+      if (bifp->attrs.isfuture)
+	fprintf (init_file, " | bif_future_bit");
+      if (bifp->attrs.isdm)
+	fprintf (init_file, " | bif_dm_bit");
       fprintf (init_file, ",\n");
       fprintf (init_file, "      /* restr_opnd */\t{%d, %d, %d},\n",
 	       bifp->proto.restr_opnd[0], bifp->proto.restr_opnd[1],
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 4a5007dc539..e9dfb138603 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -15499,6 +15499,66 @@
 }
   [(set_attr "type" "load")])
 \f
+;; Signed saturation.
+
+;; The subfus instruction is defined as: SUBFUS RT,L,RA,RB.  The extended
+;; mnemonic that we use (subdus and subwus) has the arguments RA and RB
+;; reversed (so it becomes a subtract instead of subtract from).
+
+(define_insn "sat_sub<mode>3"
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
+	(ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
+		      (match_operand:GPR 2 "gpc_reg_operand" "r")))]
+  "TARGET_FUTURE"
+  "sub<wd>us %0,%1,%2"
+  [(set_attr "type" "add")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (clobber (match_scratch:GPR 0 "=r,r"))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot2"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+\f
 
 (include "sync.md")
 (include "vector.md")
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-1.c b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
new file mode 100644
index 00000000000..68007e96cce
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 32-bit
+   subtracts.  */
+
+int do_sat_int  (int  a, int  b)
+{
+  return __builtin_saturate_subtract32 (a, b);		/* subwus  */
+}
+
+int do_sat_int_dot  (int  a, int  b, int  *p)
+{
+  int  r = __builtin_saturate_subtract32 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+
+  return r;
+}
+
+void do_sat_int_dot2  (int  a, int  b, int  *p, int *q)
+{
+  if (__builtin_saturate_subtract32 (a, b))		/* subwus.  */
+    *p = 0;
+
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler     {\msubwus\M} } } */
+/* { dg-final { scan-assembler-not {\msubf\M}   } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-2.c b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
new file mode 100644
index 00000000000..56e6d237900
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
@@ -0,0 +1,32 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 64-bit
+   subtracts.  */
+
+long do_sat_long  (long  a, long  b)
+{
+  return __builtin_saturate_subtract64 (a, b);		/* subwus  */
+}
+
+long do_sat_long_dot  (long  a, long  b, long  *p)
+{
+  long  r = __builtin_saturate_subtract64 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+
+  return r;
+}
+
+void do_sat_long_dot2  (long  a, long  b, long  *p, long *q)
+{
+  if (__builtin_saturate_subtract64 (a, b))		/* subwus.  */
+    *p = 0;
+
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler     {\msubdus\M} } } */
+/* { dg-final { scan-assembler-not {\msubf\M}   } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index b70ebf963f9..8af840d1d3b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6553,6 +6553,22 @@ proc check_effective_target_powerpc_dense_math_ok { } {
 	} "-mcpu=future"]
 }
 
+# Return 1 if this is a PowerPC target supporting -mcpu=future which enables
+# the saturating subtract instruction.
+proc check_effective_target_powerpc_subfus_ok { } {
+	return [check_no_compiler_messages_nocache powerpc_subfus_ok assembly {
+		int test (int a, int b)
+		{
+		#ifndef _ARCH_PWR_FUTURE
+		#error "target does not have saturating subtract support."
+		#else
+		/* Make sure we have saturating subtract support.  */
+		  return __builtin_saturate_subtract32 (a, b);
+		#endif
+		}
+	} "-mcpu=future"]
+}
+
 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
 # software emulation on power7/power8 systems or hardware support on power9.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gcc(refs/users/meissner/heads/dmf004)] Add saturating subtract built-in.
@ 2022-11-17 21:53 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2022-11-17 21:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:08e21237623cb6b52a4bb9920cadb20c344629ae

commit 08e21237623cb6b52a4bb9920cadb20c344629ae
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Nov 11 18:15:09 2022 -0500

    Add saturating subtract built-in.
    
    This patch adds support for a saturating subtract built-in function that may be
    added to a future PowerPC processor.  Note, if it is added, the name of the
    built-in function may change before GCC 13 is released.  If the name changes, we
    will submit a patch changing the name.
    
    I did add support for providing dense math built-in functions, even though at
    present, we have not added any new built-in functions for dense math.
    
    2022-11-11   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs6000-builtin.cc (rs6000_invalid_builtin): Add support
            for flagging invalid use of future built-in functions.
            (rs6000_builtin_is_supported): Add support for future built-in
            functions.
            * config/rs6000/rs6000-builtins.def (__builtin_saturate_subtract32): New
            built-in function for -mcpu=future.
            (__builtin_saturate_subtract64): Likewise.
            * config/rs6000/rs6000-gen-builtins.cc (enum bif_stanza): Add stanzas
            for -mcpu=future built-ins.
            (stanza_map): Likewise.
            (enable_string): Likewise.
            (struct attrinfo): Likewise.
            (parse_bif_attrs): Likewise.
            (write_decls): Likewise.
            * config/rs6000/rs6000.md (sat_sub<mode>3): Add saturating subtract
            built-in insn declarations.
            (sat_sub<mode>3_dot): Likewise.
            (sat_sub<mode>3_dot2): Likewise.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/subfus-1.c: New test.
            * gcc.target/powerpc/subfus-2.c: Likewise.
            * lib/target-supports.exp (check_effective_target_powerpc_subfus_ok):
            New effective target.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc         | 17 ++++++++
 gcc/config/rs6000/rs6000-builtins.def       | 11 ++++++
 gcc/config/rs6000/rs6000-gen-builtins.cc    | 35 ++++++++++++++---
 gcc/config/rs6000/rs6000.md                 | 60 +++++++++++++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-1.c | 31 +++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-2.c | 31 +++++++++++++++
 gcc/testsuite/lib/target-supports.exp       | 16 ++++++++
 7 files changed, 196 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc
index f4eba184db8..1ac00e4b26c 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -139,6 +139,17 @@ rs6000_invalid_builtin (enum rs6000_gen_builtins fncode)
     case ENB_MMA:
       error ("%qs requires the %qs option", name, "-mmma");
       break;
+    case ENB_FUTURE:
+      error ("%qs requires the %qs option", name, "-mcpu=future");
+      break;
+    case ENB_FUTURE_64:
+      error ("%qs requires the %qs option and either the %qs or %qs option",
+	     name, "-mcpu=future", "-m64", "-mpowerpc64");
+      break;
+    case ENB_DM:
+      error ("%qs requires the %qs or %qs options", name, "-mcpu=future",
+	     "-mdense-math");
+      break;
     default:
     case ENB_ALWAYS:
       gcc_unreachable ();
@@ -194,6 +205,12 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins fncode)
       return TARGET_HTM;
     case ENB_MMA:
       return TARGET_MMA;
+    case ENB_FUTURE:
+      return TARGET_FUTURE;
+    case ENB_FUTURE_64:
+      return TARGET_FUTURE && TARGET_POWERPC64;
+    case ENB_DM:
+      return TARGET_DENSE_MATH;
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def
index f76f54793d7..ee141c1d99e 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -139,6 +139,8 @@
 ;   endian   Needs special handling for endianness
 ;   ibmld    Restrict usage to the case when TFmode is IBM-128
 ;   ibm128   Restrict usage to the case where __ibm128 is supported or if ibmld
+;   future   Restrict usage to future instructions
+;   dm       Restrict usage to dense math
 ;
 ; Each attribute corresponds to extra processing required when
 ; the built-in is expanded.  All such special processing should
@@ -4108,3 +4110,12 @@
 
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
     STXVP nothing {mma,pair}
+
+[future]
+  const signed int __builtin_saturate_subtract32 (signed int, signed int);
+  SAT_SUBSI sat_subsi3 {}
+
+[future-64]
+  const signed long __builtin_saturate_subtract64 (signed long, signed long);
+  SAT_SUBDI sat_subdi3 {}
+
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.cc b/gcc/config/rs6000/rs6000-gen-builtins.cc
index 0bd7a535e5f..f4020141243 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.cc
+++ b/gcc/config/rs6000/rs6000-gen-builtins.cc
@@ -233,6 +233,9 @@ enum bif_stanza
  BSTZ_P10,
  BSTZ_P10_64,
  BSTZ_MMA,
+ BSTZ_FUTURE,
+ BSTZ_FUTURE_64,
+ BSTZ_DM,
  NUMBIFSTANZAS
 };
 
@@ -266,7 +269,10 @@ static stanza_entry stanza_map[NUMBIFSTANZAS] =
     { "htm",		BSTZ_HTM	},
     { "power10",	BSTZ_P10	},
     { "power10-64",	BSTZ_P10_64	},
-    { "mma",		BSTZ_MMA	}
+    { "mma",		BSTZ_MMA	},
+    { "future",		BSTZ_FUTURE	},
+    { "future-64",	BSTZ_FUTURE_64	},
+    { "dm",		BSTZ_DM		},
   };
 
 static const char *enable_string[NUMBIFSTANZAS] =
@@ -291,7 +297,10 @@ static const char *enable_string[NUMBIFSTANZAS] =
     "ENB_HTM",
     "ENB_P10",
     "ENB_P10_64",
-    "ENB_MMA"
+    "ENB_MMA",
+    "ENB_FUTURE",
+    "ENB_FUTURE_64",
+    "ENB_DM",
   };
 
 /* Function modifiers provide special handling for const, pure, and fpmath
@@ -395,6 +404,8 @@ struct attrinfo
   bool isendian;
   bool isibmld;
   bool isibm128;
+  bool isfuture;
+  bool isdm;
 };
 
 /* Fields associated with a function prototype (bif or overload).  */
@@ -1477,7 +1488,8 @@ parse_bif_attrs (attrinfo *attrptr)
 	"ldvec = %d, stvec = %d, reve = %d, pred = %d, htm = %d, "
 	"htmspr = %d, htmcr = %d, mma = %d, quad = %d, pair = %d, "
 	"mmaint = %d, no32bit = %d, 32bit = %d, cpu = %d, ldstmask = %d, "
-	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d.\n",
+	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d,",
+	"future = %d, dm = %d.\n",
 	attrptr->isinit, attrptr->isset, attrptr->isextract,
 	attrptr->isnosoft, attrptr->isldvec, attrptr->isstvec,
 	attrptr->isreve, attrptr->ispred, attrptr->ishtm, attrptr->ishtmspr,
@@ -1485,7 +1497,7 @@ parse_bif_attrs (attrinfo *attrptr)
 	attrptr->ismmaint, attrptr->isno32bit, attrptr->is32bit,
 	attrptr->iscpu, attrptr->isldstmask, attrptr->islxvrse,
 	attrptr->islxvrze, attrptr->isendian, attrptr->isibmld,
-	attrptr->isibm128);
+	attrptr->isibm128, attrptr->isfuture, attrptr->isdm);
 #endif
 
   return PC_OK;
@@ -2257,7 +2269,10 @@ write_decls (void)
   fprintf (header_file, "  ENB_HTM,\n");
   fprintf (header_file, "  ENB_P10,\n");
   fprintf (header_file, "  ENB_P10_64,\n");
-  fprintf (header_file, "  ENB_MMA\n");
+  fprintf (header_file, "  ENB_MMA,\n");
+  fprintf (header_file, "  ENB_FUTURE,\n");
+  fprintf (header_file, "  ENB_FUTURE_64,\n");
+  fprintf (header_file, "  ENB_DM\n");
   fprintf (header_file, "};\n\n");
 
   fprintf (header_file, "#define PPC_MAXRESTROPNDS 3\n");
@@ -2301,6 +2316,8 @@ write_decls (void)
   fprintf (header_file, "#define bif_endian_bit\t\t(0x00200000)\n");
   fprintf (header_file, "#define bif_ibmld_bit\t\t(0x00400000)\n");
   fprintf (header_file, "#define bif_ibm128_bit\t\t(0x00800000)\n");
+  fprintf (header_file, "#define bif_future_bit\t\t(0x01000000)\n");
+  fprintf (header_file, "#define bif_dm_bit\t\t(0x02000000)\n");
   fprintf (header_file, "\n");
   fprintf (header_file,
 	   "#define bif_is_init(x)\t\t((x).bifattrs & bif_init_bit)\n");
@@ -2350,6 +2367,10 @@ write_decls (void)
 	   "#define bif_is_ibmld(x)\t((x).bifattrs & bif_ibmld_bit)\n");
   fprintf (header_file,
 	   "#define bif_is_ibm128(x)\t((x).bifattrs & bif_ibm128_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_future(x)\t((x).bifattrs & bif_future_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_dm(x)\t((x).bifattrs & bif_dm_bit)\n");
   fprintf (header_file, "\n");
 
   fprintf (header_file,
@@ -2548,6 +2569,10 @@ write_bif_static_init (void)
 	fprintf (init_file, " | bif_ibmld_bit");
       if (bifp->attrs.isibm128)
 	fprintf (init_file, " | bif_ibm128_bit");
+      if (bifp->attrs.isfuture)
+	fprintf (init_file, " | bif_future_bit");
+      if (bifp->attrs.isdm)
+	fprintf (init_file, " | bif_dm_bit");
       fprintf (init_file, ",\n");
       fprintf (init_file, "      /* restr_opnd */\t{%d, %d, %d},\n",
 	       bifp->proto.restr_opnd[0], bifp->proto.restr_opnd[1],
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 4a5007dc539..e9dfb138603 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -15499,6 +15499,66 @@
 }
   [(set_attr "type" "load")])
 \f
+;; Signed saturation.
+
+;; The subfus instruction is defined as: SUBFUS RT,L,RA,RB.  The extended
+;; mnemonic that we use (subdus and subwus) has the arguments RA and RB
+;; reversed (so it becomes a subtract instead of subtract from).
+
+(define_insn "sat_sub<mode>3"
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
+	(ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
+		      (match_operand:GPR 2 "gpc_reg_operand" "r")))]
+  "TARGET_FUTURE"
+  "sub<wd>us %0,%1,%2"
+  [(set_attr "type" "add")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (clobber (match_scratch:GPR 0 "=r,r"))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot2"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+\f
 
 (include "sync.md")
 (include "vector.md")
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-1.c b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
new file mode 100644
index 00000000000..dd2cde47570
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 32-bit
+   subtracts.  */
+
+int do_sat_int  (int  a, int  b)
+{
+  return __builtin_saturate_subtract32 (a, b);		/* subwus  */
+}
+
+int do_sat_int_dot  (int  a, int  b, int  *p)
+{
+  int  r = __builtin_saturate_subtract32 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+  return r;
+}
+
+void do_sat_int_dot2  (int  a, int  b, int  *p, int *q)
+{
+  if (__builtin_saturate_subtract32 (a, b))		/* subwus.  */
+    *p = 0;
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler-times {\msubwus\M}    1 } } */
+/* { dg-final { scan-assembler-times {\msubwus[.]\M} 2 } } */
+/* { dg-final { scan-assembler-not   {\msubf\M}        } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-2.c b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
new file mode 100644
index 00000000000..c9511fe22cd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
@@ -0,0 +1,31 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 64-bit
+   subtracts.  */
+
+long do_sat_long  (long  a, long  b)
+{
+  return __builtin_saturate_subtract64 (a, b);		/* subwus  */
+}
+
+long do_sat_long_dot  (long  a, long  b, long  *p)
+{
+  long  r = __builtin_saturate_subtract64 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+  return r;
+}
+
+void do_sat_long_dot2  (long  a, long  b, long  *p, long *q)
+{
+  if (__builtin_saturate_subtract64 (a, b))		/* subwus.  */
+    *p = 0;
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler-times {\msubdus\M}    1 } } */
+/* { dg-final { scan-assembler-times {\msubdus[.]\M} 2 } } */
+/* { dg-final { scan-assembler-not   {\msubf\M}        } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index b70ebf963f9..8af840d1d3b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6553,6 +6553,22 @@ proc check_effective_target_powerpc_dense_math_ok { } {
 	} "-mcpu=future"]
 }
 
+# Return 1 if this is a PowerPC target supporting -mcpu=future which enables
+# the saturating subtract instruction.
+proc check_effective_target_powerpc_subfus_ok { } {
+	return [check_no_compiler_messages_nocache powerpc_subfus_ok assembly {
+		int test (int a, int b)
+		{
+		#ifndef _ARCH_PWR_FUTURE
+		#error "target does not have saturating subtract support."
+		#else
+		/* Make sure we have saturating subtract support.  */
+		  return __builtin_saturate_subtract32 (a, b);
+		#endif
+		}
+	} "-mcpu=future"]
+}
+
 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
 # software emulation on power7/power8 systems or hardware support on power9.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gcc(refs/users/meissner/heads/dmf004)] Add saturating subtract built-in.
@ 2022-11-12  0:46 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2022-11-12  0:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:694e282516d28933354db5824ad07c16785c8a36

commit 694e282516d28933354db5824ad07c16785c8a36
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Nov 11 19:45:57 2022 -0500

    Add saturating subtract built-in.
    
    This patch adds support for a saturating subtract built-in function that may be
    added to a future PowerPC processor.  Note, if it is added, the name of the
    built-in function may change before GCC 13 is released.  If the name changes, we
    will submit a patch changing the name.
    
    I did add support for providing dense math built-in functions, even though at
    present, we have not added any new built-in functions for dense math.
    
    2022-11-11   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs6000-builtin.cc (rs6000_invalid_builtin): Add support
            for flagging invalid use of future built-in functions.
            (rs6000_builtin_is_supported): Add support for future built-in
            functions.
            * config/rs6000/rs6000-builtins.def (__builtin_saturate_subtract32): New
            built-in function for -mcpu=future.
            (__builtin_saturate_subtract64): Likewise.
            * config/rs6000/rs6000-gen-builtins.cc (enum bif_stanza): Add stanzas
            for -mcpu=future built-ins.
            (stanza_map): Likewise.
            (enable_string): Likewise.
            (struct attrinfo): Likewise.
            (parse_bif_attrs): Likewise.
            (write_decls): Likewise.
            * config/rs6000/rs6000.md (sat_sub<mode>3): Add saturating subtract
            built-in insn declarations.
            (sat_sub<mode>3_dot): Likewise.
            (sat_sub<mode>3_dot2): Likewise.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/subfus-1.c: New test.
            * gcc.target/powerpc/subfus-2.c: Likewise.
            * lib/target-supports.exp (check_effective_target_powerpc_subfus_ok):
            New effective target.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc         | 17 ++++++++
 gcc/config/rs6000/rs6000-builtins.def       | 11 ++++++
 gcc/config/rs6000/rs6000-gen-builtins.cc    | 35 ++++++++++++++---
 gcc/config/rs6000/rs6000.md                 | 60 +++++++++++++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-1.c | 32 +++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-2.c | 32 +++++++++++++++
 gcc/testsuite/lib/target-supports.exp       | 16 ++++++++
 7 files changed, 198 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc
index f4eba184db8..1ac00e4b26c 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -139,6 +139,17 @@ rs6000_invalid_builtin (enum rs6000_gen_builtins fncode)
     case ENB_MMA:
       error ("%qs requires the %qs option", name, "-mmma");
       break;
+    case ENB_FUTURE:
+      error ("%qs requires the %qs option", name, "-mcpu=future");
+      break;
+    case ENB_FUTURE_64:
+      error ("%qs requires the %qs option and either the %qs or %qs option",
+	     name, "-mcpu=future", "-m64", "-mpowerpc64");
+      break;
+    case ENB_DM:
+      error ("%qs requires the %qs or %qs options", name, "-mcpu=future",
+	     "-mdense-math");
+      break;
     default:
     case ENB_ALWAYS:
       gcc_unreachable ();
@@ -194,6 +205,12 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins fncode)
       return TARGET_HTM;
     case ENB_MMA:
       return TARGET_MMA;
+    case ENB_FUTURE:
+      return TARGET_FUTURE;
+    case ENB_FUTURE_64:
+      return TARGET_FUTURE && TARGET_POWERPC64;
+    case ENB_DM:
+      return TARGET_DENSE_MATH;
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def
index f76f54793d7..ee141c1d99e 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -139,6 +139,8 @@
 ;   endian   Needs special handling for endianness
 ;   ibmld    Restrict usage to the case when TFmode is IBM-128
 ;   ibm128   Restrict usage to the case where __ibm128 is supported or if ibmld
+;   future   Restrict usage to future instructions
+;   dm       Restrict usage to dense math
 ;
 ; Each attribute corresponds to extra processing required when
 ; the built-in is expanded.  All such special processing should
@@ -4108,3 +4110,12 @@
 
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
     STXVP nothing {mma,pair}
+
+[future]
+  const signed int __builtin_saturate_subtract32 (signed int, signed int);
+  SAT_SUBSI sat_subsi3 {}
+
+[future-64]
+  const signed long __builtin_saturate_subtract64 (signed long, signed long);
+  SAT_SUBDI sat_subdi3 {}
+
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.cc b/gcc/config/rs6000/rs6000-gen-builtins.cc
index 0bd7a535e5f..f4020141243 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.cc
+++ b/gcc/config/rs6000/rs6000-gen-builtins.cc
@@ -233,6 +233,9 @@ enum bif_stanza
  BSTZ_P10,
  BSTZ_P10_64,
  BSTZ_MMA,
+ BSTZ_FUTURE,
+ BSTZ_FUTURE_64,
+ BSTZ_DM,
  NUMBIFSTANZAS
 };
 
@@ -266,7 +269,10 @@ static stanza_entry stanza_map[NUMBIFSTANZAS] =
     { "htm",		BSTZ_HTM	},
     { "power10",	BSTZ_P10	},
     { "power10-64",	BSTZ_P10_64	},
-    { "mma",		BSTZ_MMA	}
+    { "mma",		BSTZ_MMA	},
+    { "future",		BSTZ_FUTURE	},
+    { "future-64",	BSTZ_FUTURE_64	},
+    { "dm",		BSTZ_DM		},
   };
 
 static const char *enable_string[NUMBIFSTANZAS] =
@@ -291,7 +297,10 @@ static const char *enable_string[NUMBIFSTANZAS] =
     "ENB_HTM",
     "ENB_P10",
     "ENB_P10_64",
-    "ENB_MMA"
+    "ENB_MMA",
+    "ENB_FUTURE",
+    "ENB_FUTURE_64",
+    "ENB_DM",
   };
 
 /* Function modifiers provide special handling for const, pure, and fpmath
@@ -395,6 +404,8 @@ struct attrinfo
   bool isendian;
   bool isibmld;
   bool isibm128;
+  bool isfuture;
+  bool isdm;
 };
 
 /* Fields associated with a function prototype (bif or overload).  */
@@ -1477,7 +1488,8 @@ parse_bif_attrs (attrinfo *attrptr)
 	"ldvec = %d, stvec = %d, reve = %d, pred = %d, htm = %d, "
 	"htmspr = %d, htmcr = %d, mma = %d, quad = %d, pair = %d, "
 	"mmaint = %d, no32bit = %d, 32bit = %d, cpu = %d, ldstmask = %d, "
-	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d.\n",
+	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d,",
+	"future = %d, dm = %d.\n",
 	attrptr->isinit, attrptr->isset, attrptr->isextract,
 	attrptr->isnosoft, attrptr->isldvec, attrptr->isstvec,
 	attrptr->isreve, attrptr->ispred, attrptr->ishtm, attrptr->ishtmspr,
@@ -1485,7 +1497,7 @@ parse_bif_attrs (attrinfo *attrptr)
 	attrptr->ismmaint, attrptr->isno32bit, attrptr->is32bit,
 	attrptr->iscpu, attrptr->isldstmask, attrptr->islxvrse,
 	attrptr->islxvrze, attrptr->isendian, attrptr->isibmld,
-	attrptr->isibm128);
+	attrptr->isibm128, attrptr->isfuture, attrptr->isdm);
 #endif
 
   return PC_OK;
@@ -2257,7 +2269,10 @@ write_decls (void)
   fprintf (header_file, "  ENB_HTM,\n");
   fprintf (header_file, "  ENB_P10,\n");
   fprintf (header_file, "  ENB_P10_64,\n");
-  fprintf (header_file, "  ENB_MMA\n");
+  fprintf (header_file, "  ENB_MMA,\n");
+  fprintf (header_file, "  ENB_FUTURE,\n");
+  fprintf (header_file, "  ENB_FUTURE_64,\n");
+  fprintf (header_file, "  ENB_DM\n");
   fprintf (header_file, "};\n\n");
 
   fprintf (header_file, "#define PPC_MAXRESTROPNDS 3\n");
@@ -2301,6 +2316,8 @@ write_decls (void)
   fprintf (header_file, "#define bif_endian_bit\t\t(0x00200000)\n");
   fprintf (header_file, "#define bif_ibmld_bit\t\t(0x00400000)\n");
   fprintf (header_file, "#define bif_ibm128_bit\t\t(0x00800000)\n");
+  fprintf (header_file, "#define bif_future_bit\t\t(0x01000000)\n");
+  fprintf (header_file, "#define bif_dm_bit\t\t(0x02000000)\n");
   fprintf (header_file, "\n");
   fprintf (header_file,
 	   "#define bif_is_init(x)\t\t((x).bifattrs & bif_init_bit)\n");
@@ -2350,6 +2367,10 @@ write_decls (void)
 	   "#define bif_is_ibmld(x)\t((x).bifattrs & bif_ibmld_bit)\n");
   fprintf (header_file,
 	   "#define bif_is_ibm128(x)\t((x).bifattrs & bif_ibm128_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_future(x)\t((x).bifattrs & bif_future_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_dm(x)\t((x).bifattrs & bif_dm_bit)\n");
   fprintf (header_file, "\n");
 
   fprintf (header_file,
@@ -2548,6 +2569,10 @@ write_bif_static_init (void)
 	fprintf (init_file, " | bif_ibmld_bit");
       if (bifp->attrs.isibm128)
 	fprintf (init_file, " | bif_ibm128_bit");
+      if (bifp->attrs.isfuture)
+	fprintf (init_file, " | bif_future_bit");
+      if (bifp->attrs.isdm)
+	fprintf (init_file, " | bif_dm_bit");
       fprintf (init_file, ",\n");
       fprintf (init_file, "      /* restr_opnd */\t{%d, %d, %d},\n",
 	       bifp->proto.restr_opnd[0], bifp->proto.restr_opnd[1],
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 4a5007dc539..e9dfb138603 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -15499,6 +15499,66 @@
 }
   [(set_attr "type" "load")])
 \f
+;; Signed saturation.
+
+;; The subfus instruction is defined as: SUBFUS RT,L,RA,RB.  The extended
+;; mnemonic that we use (subdus and subwus) has the arguments RA and RB
+;; reversed (so it becomes a subtract instead of subtract from).
+
+(define_insn "sat_sub<mode>3"
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
+	(ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
+		      (match_operand:GPR 2 "gpc_reg_operand" "r")))]
+  "TARGET_FUTURE"
+  "sub<wd>us %0,%1,%2"
+  [(set_attr "type" "add")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (clobber (match_scratch:GPR 0 "=r,r"))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot2"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+\f
 
 (include "sync.md")
 (include "vector.md")
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-1.c b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
new file mode 100644
index 00000000000..68007e96cce
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 32-bit
+   subtracts.  */
+
+int do_sat_int  (int  a, int  b)
+{
+  return __builtin_saturate_subtract32 (a, b);		/* subwus  */
+}
+
+int do_sat_int_dot  (int  a, int  b, int  *p)
+{
+  int  r = __builtin_saturate_subtract32 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+
+  return r;
+}
+
+void do_sat_int_dot2  (int  a, int  b, int  *p, int *q)
+{
+  if (__builtin_saturate_subtract32 (a, b))		/* subwus.  */
+    *p = 0;
+
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler     {\msubwus\M} } } */
+/* { dg-final { scan-assembler-not {\msubf\M}   } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-2.c b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
new file mode 100644
index 00000000000..56e6d237900
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
@@ -0,0 +1,32 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 64-bit
+   subtracts.  */
+
+long do_sat_long  (long  a, long  b)
+{
+  return __builtin_saturate_subtract64 (a, b);		/* subwus  */
+}
+
+long do_sat_long_dot  (long  a, long  b, long  *p)
+{
+  long  r = __builtin_saturate_subtract64 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+
+  return r;
+}
+
+void do_sat_long_dot2  (long  a, long  b, long  *p, long *q)
+{
+  if (__builtin_saturate_subtract64 (a, b))		/* subwus.  */
+    *p = 0;
+
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler     {\msubdus\M} } } */
+/* { dg-final { scan-assembler-not {\msubf\M}   } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index b70ebf963f9..8af840d1d3b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6553,6 +6553,22 @@ proc check_effective_target_powerpc_dense_math_ok { } {
 	} "-mcpu=future"]
 }
 
+# Return 1 if this is a PowerPC target supporting -mcpu=future which enables
+# the saturating subtract instruction.
+proc check_effective_target_powerpc_subfus_ok { } {
+	return [check_no_compiler_messages_nocache powerpc_subfus_ok assembly {
+		int test (int a, int b)
+		{
+		#ifndef _ARCH_PWR_FUTURE
+		#error "target does not have saturating subtract support."
+		#else
+		/* Make sure we have saturating subtract support.  */
+		  return __builtin_saturate_subtract32 (a, b);
+		#endif
+		}
+	} "-mcpu=future"]
+}
+
 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
 # software emulation on power7/power8 systems or hardware support on power9.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gcc(refs/users/meissner/heads/dmf004)] Add saturating subtract built-in.
@ 2022-11-11 23:15 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2022-11-11 23:15 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a0ba0af6b6612cf8f86c8abf30e1057cfa99803e

commit a0ba0af6b6612cf8f86c8abf30e1057cfa99803e
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Nov 11 18:15:09 2022 -0500

    Add saturating subtract built-in.
    
    This patch adds support for a saturating subtract built-in function that may be
    added to a future PowerPC processor.  Note, if it is added, the name of the
    built-in function may change before GCC 13 is released.  If the name changes, we
    will submit a patch changing the name.
    
    I did add support for providing dense math built-in functions, even though at
    present, we have not added any new built-in functions for dense math.
    
    2022-11-11   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs6000-builtin.cc (rs6000_invalid_builtin): Add support
            for flagging invalid use of future built-in functions.
            (rs6000_builtin_is_supported): Add support for future built-in
            functions.
            * config/rs6000/rs6000-builtins.def (__builtin_saturate_subtract32): New
            built-in function for -mcpu=future.
            (__builtin_saturate_subtract64): Likewise.
            * config/rs6000/rs6000-gen-builtins.cc (enum bif_stanza): Add stanzas
            for -mcpu=future built-ins.
            (stanza_map): Likewise.
            (enable_string): Likewise.
            (struct attrinfo): Likewise.
            (parse_bif_attrs): Likewise.
            (write_decls): Likewise.
            * config/rs6000/rs6000.md (sat_sub<mode>3): Add saturating subtract
            built-in insn declarations.
            (sat_sub<mode>3_dot): Likewise.
            (sat_sub<mode>3_dot2): Likewise.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/subfus-1.c: New test.
            * gcc.target/powerpc/subfus-2.c: Likewise.
            * lib/target-supports.exp (check_effective_target_powerpc_subfus_ok):
            New effective target.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc         | 17 ++++++++
 gcc/config/rs6000/rs6000-builtins.def       | 11 ++++++
 gcc/config/rs6000/rs6000-gen-builtins.cc    | 35 ++++++++++++++---
 gcc/config/rs6000/rs6000.md                 | 60 +++++++++++++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-1.c | 31 +++++++++++++++
 gcc/testsuite/gcc.target/powerpc/subfus-2.c | 31 +++++++++++++++
 gcc/testsuite/lib/target-supports.exp       | 16 ++++++++
 7 files changed, 196 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc
index f4eba184db8..1ac00e4b26c 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -139,6 +139,17 @@ rs6000_invalid_builtin (enum rs6000_gen_builtins fncode)
     case ENB_MMA:
       error ("%qs requires the %qs option", name, "-mmma");
       break;
+    case ENB_FUTURE:
+      error ("%qs requires the %qs option", name, "-mcpu=future");
+      break;
+    case ENB_FUTURE_64:
+      error ("%qs requires the %qs option and either the %qs or %qs option",
+	     name, "-mcpu=future", "-m64", "-mpowerpc64");
+      break;
+    case ENB_DM:
+      error ("%qs requires the %qs or %qs options", name, "-mcpu=future",
+	     "-mdense-math");
+      break;
     default:
     case ENB_ALWAYS:
       gcc_unreachable ();
@@ -194,6 +205,12 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins fncode)
       return TARGET_HTM;
     case ENB_MMA:
       return TARGET_MMA;
+    case ENB_FUTURE:
+      return TARGET_FUTURE;
+    case ENB_FUTURE_64:
+      return TARGET_FUTURE && TARGET_POWERPC64;
+    case ENB_DM:
+      return TARGET_DENSE_MATH;
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def
index f76f54793d7..ee141c1d99e 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -139,6 +139,8 @@
 ;   endian   Needs special handling for endianness
 ;   ibmld    Restrict usage to the case when TFmode is IBM-128
 ;   ibm128   Restrict usage to the case where __ibm128 is supported or if ibmld
+;   future   Restrict usage to future instructions
+;   dm       Restrict usage to dense math
 ;
 ; Each attribute corresponds to extra processing required when
 ; the built-in is expanded.  All such special processing should
@@ -4108,3 +4110,12 @@
 
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
     STXVP nothing {mma,pair}
+
+[future]
+  const signed int __builtin_saturate_subtract32 (signed int, signed int);
+  SAT_SUBSI sat_subsi3 {}
+
+[future-64]
+  const signed long __builtin_saturate_subtract64 (signed long, signed long);
+  SAT_SUBDI sat_subdi3 {}
+
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.cc b/gcc/config/rs6000/rs6000-gen-builtins.cc
index 0bd7a535e5f..f4020141243 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.cc
+++ b/gcc/config/rs6000/rs6000-gen-builtins.cc
@@ -233,6 +233,9 @@ enum bif_stanza
  BSTZ_P10,
  BSTZ_P10_64,
  BSTZ_MMA,
+ BSTZ_FUTURE,
+ BSTZ_FUTURE_64,
+ BSTZ_DM,
  NUMBIFSTANZAS
 };
 
@@ -266,7 +269,10 @@ static stanza_entry stanza_map[NUMBIFSTANZAS] =
     { "htm",		BSTZ_HTM	},
     { "power10",	BSTZ_P10	},
     { "power10-64",	BSTZ_P10_64	},
-    { "mma",		BSTZ_MMA	}
+    { "mma",		BSTZ_MMA	},
+    { "future",		BSTZ_FUTURE	},
+    { "future-64",	BSTZ_FUTURE_64	},
+    { "dm",		BSTZ_DM		},
   };
 
 static const char *enable_string[NUMBIFSTANZAS] =
@@ -291,7 +297,10 @@ static const char *enable_string[NUMBIFSTANZAS] =
     "ENB_HTM",
     "ENB_P10",
     "ENB_P10_64",
-    "ENB_MMA"
+    "ENB_MMA",
+    "ENB_FUTURE",
+    "ENB_FUTURE_64",
+    "ENB_DM",
   };
 
 /* Function modifiers provide special handling for const, pure, and fpmath
@@ -395,6 +404,8 @@ struct attrinfo
   bool isendian;
   bool isibmld;
   bool isibm128;
+  bool isfuture;
+  bool isdm;
 };
 
 /* Fields associated with a function prototype (bif or overload).  */
@@ -1477,7 +1488,8 @@ parse_bif_attrs (attrinfo *attrptr)
 	"ldvec = %d, stvec = %d, reve = %d, pred = %d, htm = %d, "
 	"htmspr = %d, htmcr = %d, mma = %d, quad = %d, pair = %d, "
 	"mmaint = %d, no32bit = %d, 32bit = %d, cpu = %d, ldstmask = %d, "
-	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d.\n",
+	"lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d,",
+	"future = %d, dm = %d.\n",
 	attrptr->isinit, attrptr->isset, attrptr->isextract,
 	attrptr->isnosoft, attrptr->isldvec, attrptr->isstvec,
 	attrptr->isreve, attrptr->ispred, attrptr->ishtm, attrptr->ishtmspr,
@@ -1485,7 +1497,7 @@ parse_bif_attrs (attrinfo *attrptr)
 	attrptr->ismmaint, attrptr->isno32bit, attrptr->is32bit,
 	attrptr->iscpu, attrptr->isldstmask, attrptr->islxvrse,
 	attrptr->islxvrze, attrptr->isendian, attrptr->isibmld,
-	attrptr->isibm128);
+	attrptr->isibm128, attrptr->isfuture, attrptr->isdm);
 #endif
 
   return PC_OK;
@@ -2257,7 +2269,10 @@ write_decls (void)
   fprintf (header_file, "  ENB_HTM,\n");
   fprintf (header_file, "  ENB_P10,\n");
   fprintf (header_file, "  ENB_P10_64,\n");
-  fprintf (header_file, "  ENB_MMA\n");
+  fprintf (header_file, "  ENB_MMA,\n");
+  fprintf (header_file, "  ENB_FUTURE,\n");
+  fprintf (header_file, "  ENB_FUTURE_64,\n");
+  fprintf (header_file, "  ENB_DM\n");
   fprintf (header_file, "};\n\n");
 
   fprintf (header_file, "#define PPC_MAXRESTROPNDS 3\n");
@@ -2301,6 +2316,8 @@ write_decls (void)
   fprintf (header_file, "#define bif_endian_bit\t\t(0x00200000)\n");
   fprintf (header_file, "#define bif_ibmld_bit\t\t(0x00400000)\n");
   fprintf (header_file, "#define bif_ibm128_bit\t\t(0x00800000)\n");
+  fprintf (header_file, "#define bif_future_bit\t\t(0x01000000)\n");
+  fprintf (header_file, "#define bif_dm_bit\t\t(0x02000000)\n");
   fprintf (header_file, "\n");
   fprintf (header_file,
 	   "#define bif_is_init(x)\t\t((x).bifattrs & bif_init_bit)\n");
@@ -2350,6 +2367,10 @@ write_decls (void)
 	   "#define bif_is_ibmld(x)\t((x).bifattrs & bif_ibmld_bit)\n");
   fprintf (header_file,
 	   "#define bif_is_ibm128(x)\t((x).bifattrs & bif_ibm128_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_future(x)\t((x).bifattrs & bif_future_bit)\n");
+  fprintf (header_file,
+	   "#define bif_is_dm(x)\t((x).bifattrs & bif_dm_bit)\n");
   fprintf (header_file, "\n");
 
   fprintf (header_file,
@@ -2548,6 +2569,10 @@ write_bif_static_init (void)
 	fprintf (init_file, " | bif_ibmld_bit");
       if (bifp->attrs.isibm128)
 	fprintf (init_file, " | bif_ibm128_bit");
+      if (bifp->attrs.isfuture)
+	fprintf (init_file, " | bif_future_bit");
+      if (bifp->attrs.isdm)
+	fprintf (init_file, " | bif_dm_bit");
       fprintf (init_file, ",\n");
       fprintf (init_file, "      /* restr_opnd */\t{%d, %d, %d},\n",
 	       bifp->proto.restr_opnd[0], bifp->proto.restr_opnd[1],
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 4a5007dc539..e9dfb138603 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -15499,6 +15499,66 @@
 }
   [(set_attr "type" "load")])
 \f
+;; Signed saturation.
+
+;; The subfus instruction is defined as: SUBFUS RT,L,RA,RB.  The extended
+;; mnemonic that we use (subdus and subwus) has the arguments RA and RB
+;; reversed (so it becomes a subtract instead of subtract from).
+
+(define_insn "sat_sub<mode>3"
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
+	(ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
+		      (match_operand:GPR 2 "gpc_reg_operand" "r")))]
+  "TARGET_FUTURE"
+  "sub<wd>us %0,%1,%2"
+  [(set_attr "type" "add")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (clobber (match_scratch:GPR 0 "=r,r"))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+
+(define_insn_and_split "*sat_sub<mode>3_dot2"
+  [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
+	(compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
+				  (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
+		    (const_int 0)))
+   (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))]
+  "TARGET_FUTURE"
+  "@
+   sub<wd>us. %0,%1,%2
+   #"
+  "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
+  [(set (match_dup 0)
+	(ss_minus:GPR (match_dup 1)
+		      (match_dup 2)))
+   (set (match_dup 3)
+	(compare:CC (match_dup 0)
+		    (const_int 0)))]
+  ""
+  [(set_attr "type" "add")
+   (set_attr "dot" "yes")
+   (set_attr "length" "4,8")])
+\f
 
 (include "sync.md")
 (include "vector.md")
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-1.c b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
new file mode 100644
index 00000000000..dd2cde47570
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-1.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 32-bit
+   subtracts.  */
+
+int do_sat_int  (int  a, int  b)
+{
+  return __builtin_saturate_subtract32 (a, b);		/* subwus  */
+}
+
+int do_sat_int_dot  (int  a, int  b, int  *p)
+{
+  int  r = __builtin_saturate_subtract32 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+  return r;
+}
+
+void do_sat_int_dot2  (int  a, int  b, int  *p, int *q)
+{
+  if (__builtin_saturate_subtract32 (a, b))		/* subwus.  */
+    *p = 0;
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler-times {\msubwus\M}    1 } } */
+/* { dg-final { scan-assembler-times {\msubwus[.]\M} 2 } } */
+/* { dg-final { scan-assembler-not   {\msubf\M}        } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-2.c b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
new file mode 100644
index 00000000000..c9511fe22cd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/subfus-2.c
@@ -0,0 +1,31 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-require-effective-target powerpc_subfus_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the saturating subtract built-in generates subwus for 64-bit
+   subtracts.  */
+
+long do_sat_long  (long  a, long  b)
+{
+  return __builtin_saturate_subtract64 (a, b);		/* subwus  */
+}
+
+long do_sat_long_dot  (long  a, long  b, long  *p)
+{
+  long  r = __builtin_saturate_subtract64 (a, b);	/* subwus.  */
+  if (r == 0)
+    *p = 0;
+  return r;
+}
+
+void do_sat_long_dot2  (long  a, long  b, long  *p, long *q)
+{
+  if (__builtin_saturate_subtract64 (a, b))		/* subwus.  */
+    *p = 0;
+  *q = a + b;
+  return;
+}
+
+/* { dg-final { scan-assembler-times {\msubdus\M}    1 } } */
+/* { dg-final { scan-assembler-times {\msubdus[.]\M} 2 } } */
+/* { dg-final { scan-assembler-not   {\msubf\M}        } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index b70ebf963f9..8af840d1d3b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6553,6 +6553,22 @@ proc check_effective_target_powerpc_dense_math_ok { } {
 	} "-mcpu=future"]
 }
 
+# Return 1 if this is a PowerPC target supporting -mcpu=future which enables
+# the saturating subtract instruction.
+proc check_effective_target_powerpc_subfus_ok { } {
+	return [check_no_compiler_messages_nocache powerpc_subfus_ok assembly {
+		int test (int a, int b)
+		{
+		#ifndef _ARCH_PWR_FUTURE
+		#error "target does not have saturating subtract support."
+		#else
+		/* Make sure we have saturating subtract support.  */
+		  return __builtin_saturate_subtract32 (a, b);
+		#endif
+		}
+	} "-mcpu=future"]
+}
+
 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
 # software emulation on power7/power8 systems or hardware support on power9.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-17 21:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 21:53 [gcc(refs/users/meissner/heads/dmf004)] Add saturating subtract built-in Michael Meissner
  -- strict thread matches above, loose matches on Subject: below --
2022-11-17 21:53 Michael Meissner
2022-11-12  0:46 Michael Meissner
2022-11-11 23:15 Michael Meissner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).