Re: [PATCH v2,rs6000] Add built-in function support for compare bytes instruction

2017-05-09 Thread Segher Boessenkool
Hi Kelvin,

On Mon, May 08, 2017 at 11:04:59AM -0600, Kelvin Nilsen wrote:
> +  /* If any supplied arguments are wider than 32 bits, resolve to
> +  64-bit variant of built-in function.  */
> +  if ((arg1_mode == TImode) || (arg1_mode == DImode) ||
> +   (arg2_mode == TImode) || (arg2_mode == DImode))

Use GET_MODE_PRECISION instead?  Or GET_MODE_BITSIZE, not sure which
is better here.

The rest of the patch looks fine to me.


Segher


[PATCH v2,rs6000] Add built-in function support for compare bytes instruction

2017-05-08 Thread Kelvin Nilsen

This patch adds support for the compare bytes instruction, which has
been available in the rs6000 architecture since Power6.  Thank you to
Segher Boessenkool for feedback on the original submission of this
patch.  The following refinements have been incorporated:

1. Changed the implementation and documentation to present a single
overloaded function that handles either 32-bit or 64-bit arguments.

2. Corrected the spelling of compare in the comment describing the
RS6000_BTM_CMPB macro.  In response to reviewer question of whether
this line is too long: it is not.  It only appears that way due to
alignment of tabs in the diff output.

The patch has been bootstrapped and tested on powerpc64le-unknown-linux
and powerpc-unknown-linux (big-endian, with both -m32 and -m64 target
options) with no regressions.

Is this ok for the trunk?

gcc/testsuite/ChangeLog:

2017-05-08  Kelvin Nilsen  

* gcc.target/powerpc/cmpb-1.c: New test.
* gcc.target/powerpc/cmpb-2.c: New test.
* gcc.target/powerpc/cmpb-3.c: New test.
* gcc.target/powerpc/cmpb32-1.c: New test.
* gcc.target/powerpc/cmpb32-2.c: New test.

gcc/ChangeLog:

2017-05-08  Kelvin Nilsen  

* config/rs6000/rs6000-c.c (altivec_overloaded_builtins): Add
array entries to represent two legal parameterizations of the
overloaded __builtin_cmpb function, as represented by the
P6_OV_BUILTIN_CMPB constant.
(altivec_resolve_overloaded_builtin): Add special case handling
for the __builtin_cmpb function, as represented by the
P6_OV_BUILTIN_CMPB constant.
* config/rs6000/rs6000-builtin.def (BU_P6_2): New macro.
(BU_P6_64BIT_2): New macro.
(BU_P6_OVERLOAD_2): New macro
(CMPB_32): Add 32-bit compare-bytes support for 32-bit only targets.
(CMPB): Add 64-bit compare-bytes support for 32-bit and 64-bit targets.
(CMPB): Add overload support to represent both 32-bit and 64-bit
compare-bytes function.
* config/rs6000/rs6000.c (rs6000_builtin_mask_calculate): Add
support for TARGET_CMPB.
* config/rs6000/rs6000.h: Add support for RS6000_BTM_CMPB.
* doc/extend.texi (PowerPC AltiVec Built-in Functions): Add
documentation of the __builtin_cmpb overloaded built-in function.

Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 247069)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -3788,6 +3788,7 @@ HOST_WIDE_INT
 rs6000_builtin_mask_calculate (void)
 {
   return (((TARGET_ALTIVEC)? RS6000_BTM_ALTIVEC   : 0)
+ | ((TARGET_CMPB)  ? RS6000_BTM_CMPB  : 0)
  | ((TARGET_VSX)   ? RS6000_BTM_VSX   : 0)
  | ((TARGET_SPE)   ? RS6000_BTM_SPE   : 0)
  | ((TARGET_PAIRED_FLOAT)  ? RS6000_BTM_PAIRED: 0)
Index: gcc/config/rs6000/rs6000.h
===
--- gcc/config/rs6000/rs6000.h  (revision 247069)
+++ gcc/config/rs6000/rs6000.h  (working copy)
@@ -2717,6 +2717,7 @@ extern int frame_pointer_needed;
aren't in target_flags.  */
 #define RS6000_BTM_ALWAYS  0   /* Always enabled.  */
 #define RS6000_BTM_ALTIVEC MASK_ALTIVEC/* VMX/altivec vectors.  */
+#define RS6000_BTM_CMPBMASK_CMPB   /* ISA 2.05: compare 
bytes.  */
 #define RS6000_BTM_VSX MASK_VSX/* VSX (vector/scalar).  */
 #define RS6000_BTM_P8_VECTOR   MASK_P8_VECTOR  /* ISA 2.07 vector.  */
 #define RS6000_BTM_P9_VECTOR   MASK_P9_VECTOR  /* ISA 3.0 vector.  */
Index: gcc/config/rs6000/rs6000-c.c
===
--- gcc/config/rs6000/rs6000-c.c(revision 247069)
+++ gcc/config/rs6000/rs6000-c.c(working copy)
@@ -5348,6 +5348,11 @@ const struct altivec_builtin_types altivec_overloa
 RS6000_BTI_unsigned_V1TI, RS6000_BTI_unsigned_V1TI,
 RS6000_BTI_unsigned_V1TI, 0 },
 
+  { P6_OV_BUILTIN_CMPB, P6_BUILTIN_CMPB_32,
+RS6000_BTI_UINTSI, RS6000_BTI_UINTSI, RS6000_BTI_UINTSI, 0 },
+  { P6_OV_BUILTIN_CMPB, P6_BUILTIN_CMPB,
+RS6000_BTI_UINTDI, RS6000_BTI_UINTDI, RS6000_BTI_UINTDI, 0 },
+
   { P8V_BUILTIN_VEC_VUPKHSW, P8V_BUILTIN_VUPKHSW,
 RS6000_BTI_V2DI, RS6000_BTI_V4SI, 0, 0 },
   { P8V_BUILTIN_VEC_VUPKHSW, P8V_BUILTIN_VUPKHSW,
@@ -6409,25 +6414,76 @@ altivec_resolve_overloaded_builtin (location_t loc
 for (desc = altivec_overloaded_builtins;
 desc->code && desc->code != fcode; desc++)
   continue;
-
-/* For arguments after the last, we have RS6000_BTI_NOT_OPAQUE in
-   the opX fields.  */
-for (; desc->code == fcode; desc++)
+
+/* Need to special case __builtin_cmp because the overloaded forms
+   of this function take (unsigned int, unsigned int) or (unsigned
+   long long int, unsigned long long int).  Since C co