* [PATCH, rs6000] Add builtins to convert from float/double to int/long using current rounding mode
@ 2017-09-06 16:24 Carl Love
2017-09-06 21:14 ` Pat Haugen
0 siblings, 1 reply; 3+ messages in thread
From: Carl Love @ 2017-09-06 16:24 UTC (permalink / raw)
To: gcc-patches, David Edelsohn, Segher Boessenkool; +Cc: Bill Schmidt, cel
GCC Maintainers:
The following patch adds support for a couple of requested builtins that
convert from float/double to int / long using the current rounding
mode.
The patch has been tested on powerpc64le-unknown-linux-gnu (Power 8 LE).
Please let me know if the following patch is acceptable. Thanks.
Carl Love
-----------------------------------------------------------------------
gcc/ChangeLog:
2017-09-06 Carl Love <cel@us.ibm.com>
* config/rs6000/rs6000-builtin.def (FCTID, FCTIW): Add BU_P7_MISC_1
macro expansion for builtins.
* config/rs6000/rs6000.md (fctid, fctiw): Add define_insn for the
fctid and fctiw instructions.
gcc/testsuite/ChangeLog:
2017-09-06 Carl Love <cel@us.ibm.com>
* gcc.target/powerpc/builtin-fctid-fctiw-runnable.c: New test file
for the __builtin_fctid and __builtin_fctiw builtins.
---
gcc/config/rs6000/rs6000-builtin.def | 2 +
gcc/config/rs6000/rs6000.md | 18 +++
.../powerpc/builtin-fctid-fctiw-runnable.c | 138 +++++++++++++++++++++
3 files changed, 158 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c
diff --git a/gcc/config/rs6000/rs6000-builtin.def b/gcc/config/rs6000/rs6000-builtin.def
index 850164a..7affa30 100644
--- a/gcc/config/rs6000/rs6000-builtin.def
+++ b/gcc/config/rs6000/rs6000-builtin.def
@@ -2231,6 +2231,8 @@ BU_DFP_MISC_2 (DSCRIQ, "dscriq", CONST, dfp_dscri_td)
/* 1 argument BCD functions added in ISA 2.06. */
BU_P7_MISC_1 (CDTBCD, "cdtbcd", CONST, cdtbcd)
BU_P7_MISC_1 (CBCDTD, "cbcdtd", CONST, cbcdtd)
+BU_P7_MISC_1 (FCTID, "fctid", CONST, fctid)
+BU_P7_MISC_1 (FCTIW, "fctiw", CONST, fctiw)
/* 2 argument BCD functions added in ISA 2.06. */
BU_P7_MISC_2 (ADDG6S, "addg6s", CONST, addg6s)
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 20873ac..a5cbef5 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -14054,6 +14054,24 @@
[(set_attr "type" "integer")
(set_attr "length" "4")])
+(define_insn "fctid"
+ [(set (match_operand:DI 0 "register_operand" "=r")
+ (unspec:DI [(match_operand:DF 1 "register_operand" "f")]
+ UNSPEC_FCTID))]
+ ""
+ "fctid %1,%1; mfvsrd %0,%1"
+ [(set_attr "type" "two")
+ (set_attr "length" "8")])
+
+(define_insn "fctiw"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+ (unspec:SI [(match_operand:DF 1 "register_operand" "f")]
+ UNSPEC_FCTIW))]
+ ""
+ "fctiw %1,%1; mfvsrd %0,%1; extsw %0,%0"
+ [(set_attr "type" "integer")
+ (set_attr "length" "4")])
+
(define_int_iterator UNSPEC_DIV_EXTEND [UNSPEC_DIVE
UNSPEC_DIVEO
UNSPEC_DIVEU
diff --git a/gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c b/gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c
new file mode 100644
index 0000000..79c5341
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c
@@ -0,0 +1,138 @@
+/* { dg-do run { target { powerpc*-*-linux* } } } */
+/* { dg-require-effective-target powerpc_p8vector_ok } */
+/* { dg-options "-mcpu=power8" } */
+
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
+void abort (void);
+
+long
+test_bi_lrint_1 (float __A)
+{
+ return (__builtin_fctid (__A));
+}
+long
+test_bi_lrint_2 (double __A)
+{
+ return (__builtin_fctid (__A));
+}
+
+int
+test_bi_rint_1 (float __A)
+{
+ return (__builtin_fctiw (__A));
+}
+
+int
+test_bi_rint_2 (double __A)
+{
+ return (__builtin_fctiw (__A));
+}
+
+
+int main( void)
+{
+ signed long lx, expected_l;
+ double dy;
+
+ signed int x, expected_i;
+ float y;
+
+ dy = 1.45;
+ expected_l = 1;
+ lx = __builtin_fctid (dy);
+
+ if( lx != expected_l)
+#ifdef DEBUG
+ printf("ERROR: __builtin_fctid(dy= %f) = %ld, expected %ld\n",
+ dy, lx, expected_l);
+#else
+ abort();
+#endif
+
+ dy = 3.51;
+ expected_l = 4;
+ lx = __builtin_fctid (dy);
+
+ if( lx != expected_l)
+#ifdef DEBUG
+ printf("ERROR: __builtin_fctid(dy= %f) = %ld, expected %ld\n",
+ dy, lx, expected_l);
+#else
+ abort();
+#endif
+
+ dy = 5.57;
+ expected_i = 6;
+ x = __builtin_fctiw (dy);
+
+ if( x != expected_i)
+#ifdef DEBUG
+ printf("ERROR: __builtin_fctiw(dy= %f) = %d, expected %d\n",
+ dy, x, expected_i);
+#else
+ abort();
+#endif
+
+ y = 11.47;
+ expected_i = 11;
+ x = __builtin_fctiw (y);
+
+ if( x != expected_i)
+#ifdef DEBUG
+ printf("ERROR: __builtin_fctiw(y = %f) = %d, expected %d\n",
+ y, x, expected_i);
+#else
+ abort();
+#endif
+
+ y = 17.77;
+ expected_l = 18;
+ lx = test_bi_lrint_1 (y);
+
+ if( lx != expected_l)
+#ifdef DEBUG
+ printf("ERROR: function call test_bi_lrint_1 (y = %f) = %ld, expected %ld\n",
+ y, lx, expected_l);
+#else
+ abort();
+#endif
+
+ dy = 7.1;
+ expected_l = 7;
+ lx = test_bi_lrint_2 (dy);
+
+ if( lx != expected_l)
+#ifdef DEBUG
+ printf("ERROR: function call test_bi_lrint_2 (dy = %f) = %ld, expected %ld\n",
+ dy, lx, expected_l);
+#else
+ abort();
+#endif
+
+ y = 0.001;
+ expected_i = 0;
+ x = test_bi_rint_1 (y);
+
+ if( x != expected_i)
+#ifdef DEBUG
+ printf("ERROR: function call test_bi_rint_1 (y = %f) = %d, expected %d\n",
+ y, x, expected_i);
+#else
+ abort();
+#endif
+
+ dy = 0.9999;
+ expected_i = 1;
+ x = test_bi_rint_2 (dy);
+
+ if( x != expected_i)
+#ifdef DEBUG
+ printf("ERROR: function call test_bi_rint_2 (dy = %f) = %d, expected %d\n",
+ dy, x, expected_i);
+#else
+ abort();
+#endif
+}
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH, rs6000] Add builtins to convert from float/double to int/long using current rounding mode
2017-09-06 16:24 [PATCH, rs6000] Add builtins to convert from float/double to int/long using current rounding mode Carl Love
@ 2017-09-06 21:14 ` Pat Haugen
2017-09-06 22:26 ` Carl Love
0 siblings, 1 reply; 3+ messages in thread
From: Pat Haugen @ 2017-09-06 21:14 UTC (permalink / raw)
To: Carl Love, gcc-patches, David Edelsohn, Segher Boessenkool; +Cc: Bill Schmidt
On 09/06/2017 11:24 AM, Carl Love wrote:
> + "fctiw %1,%1; mfvsrd %0,%1; extsw %0,%0"
> + [(set_attr "type" "integer")
> + (set_attr "length" "4")])
Should be type "three" and length "12".
-Pat
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH, rs6000] Add builtins to convert from float/double to int/long using current rounding mode
2017-09-06 21:14 ` Pat Haugen
@ 2017-09-06 22:26 ` Carl Love
0 siblings, 0 replies; 3+ messages in thread
From: Carl Love @ 2017-09-06 22:26 UTC (permalink / raw)
To: Pat Haugen; +Cc: gcc-patches, David Edelsohn, Segher Boessenkool, Bill Schmidt
On Wed, 2017-09-06 at 16:13 -0500, Pat Haugen wrote:
> On 09/06/2017 11:24 AM, Carl Love wrote:
> > + "fctiw %1,%1; mfvsrd %0,%1; extsw %0,%0"
> > + [(set_attr "type" "integer")
> > + (set_attr "length" "4")])
>
> Should be type "three" and length "12".
>
> -Pat
Pat:
Yes, that is wrong in more ways then one. Looks like I posted the wrong
version of the patch. This was the first version which unfortunately
results in generating extra extsw instructions.
I withdraw this patch from consideration.
Carl Love
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-06 22:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-06 16:24 [PATCH, rs6000] Add builtins to convert from float/double to int/long using current rounding mode Carl Love
2017-09-06 21:14 ` Pat Haugen
2017-09-06 22:26 ` Carl Love
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).