This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, middle-end]: Implement lrint and llrint functions as built-ins


Hello!

This patch implements lrint and llrint functions as built-in intrinsic functions. Attached to this message is only a middle-end part. In a followup message, an x87 implementation will be attached.

This patch was bootstrapped and regtested (together with x87 implementation) on i686-pc-linux-gnu, c and c++. A testcase that checks new built-ins is also implemented.

OK for mainline?

2005-03-21 Uros Bizjak <uros@kss-loka.si>

   * optabs.h (enum optab_index): Add new OTI_lrint and OTI_llrint.
   (lrint_optab, llrint_optab): Define corresponding macros.
   * optabs.c (init_optabs): Initialize lrint_optab and llrint_optab.
   * genopinit.c (optabs): Implement lrint_optab using lrintsi2
   pattern and llrint_optab using llrintdi2 patterns.
   * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_LRINT{,F,L}
   using lrint_optab and BUILT_IN_LLRINT{,F,L} using llrint_optab.
   (expand_builtin): Expand BUILT_IN_LRINT{,F,L} and
   BUILT_IN_LLRINT{,F,L} using expand_builtin_mathfn if
   flag_unsafe_math_optimizations is set.

testsuite:

* gcc.dg/builtins-46.c: Also check lrint* and llrint*.

Uros.

Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.443
diff -u -p -r1.443 builtins.c
--- builtins.c	20 Mar 2005 15:54:32 -0000	1.443
+++ builtins.c	21 Mar 2005 10:26:19 -0000
@@ -1758,6 +1758,14 @@ expand_builtin_mathfn (tree exp, rtx tar
     case BUILT_IN_RINTF:
     case BUILT_IN_RINTL:
       builtin_optab = rint_optab; break;
+    case BUILT_IN_LRINT:
+    case BUILT_IN_LRINTF:
+    case BUILT_IN_LRINTL:
+      builtin_optab = lrint_optab; break;
+    case BUILT_IN_LLRINT:
+    case BUILT_IN_LLRINTF:
+    case BUILT_IN_LLRINTL:
+      builtin_optab = llrint_optab; break;
     default:
       gcc_unreachable ();
     }
@@ -5261,6 +5269,12 @@ expand_builtin (tree exp, rtx target, rt
     case BUILT_IN_RINT:
     case BUILT_IN_RINTF:
     case BUILT_IN_RINTL:
+    case BUILT_IN_LRINT:
+    case BUILT_IN_LRINTF:
+    case BUILT_IN_LRINTL:
+    case BUILT_IN_LLRINT:
+    case BUILT_IN_LLRINTF:
+    case BUILT_IN_LLRINTL:
       target = expand_builtin_mathfn (exp, target, subtarget);
       if (target)
 	return target;
Index: genopinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genopinit.c,v
retrieving revision 1.87
diff -u -p -r1.87 genopinit.c
--- genopinit.c	12 Feb 2005 11:34:21 -0000	1.87
+++ genopinit.c	21 Mar 2005 10:26:21 -0000
@@ -124,6 +124,8 @@ static const char * const optabs[] =
   "btrunc_optab->handlers[$A].insn_code = CODE_FOR_$(btrunc$a2$)",
   "nearbyint_optab->handlers[$A].insn_code = CODE_FOR_$(nearbyint$a2$)",
   "rint_optab->handlers[$A].insn_code = CODE_FOR_$(rint$a2$)",
+  "lrint_optab->handlers[$A].insn_code = CODE_FOR_$(lrint$a2$)",
+  "llrint_optab->handlers[$A].insn_code = CODE_FOR_$(llrint$a2$)",
   "sincos_optab->handlers[$A].insn_code = CODE_FOR_$(sincos$a3$)",
   "sin_optab->handlers[$A].insn_code = CODE_FOR_$(sin$a2$)",
   "asin_optab->handlers[$A].insn_code = CODE_FOR_$(asin$a2$)",
Index: optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.265
diff -u -p -r1.265 optabs.c
--- optabs.c	16 Mar 2005 18:29:23 -0000	1.265
+++ optabs.c	21 Mar 2005 10:26:21 -0000
@@ -5033,6 +5033,8 @@ init_optabs (void)
   btrunc_optab = init_optab (UNKNOWN);
   nearbyint_optab = init_optab (UNKNOWN);
   rint_optab = init_optab (UNKNOWN);
+  lrint_optab = init_optab (UNKNOWN);
+  llrint_optab = init_optab (UNKNOWN);
   sincos_optab = init_optab (UNKNOWN);
   sin_optab = init_optab (UNKNOWN);
   asin_optab = init_optab (UNKNOWN);
Index: optabs.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.h,v
retrieving revision 1.50
diff -u -p -r1.50 optabs.h
--- optabs.h	16 Mar 2005 18:29:25 -0000	1.50
+++ optabs.h	21 Mar 2005 10:26:21 -0000
@@ -191,6 +191,8 @@ enum optab_index
   OTI_round,
   OTI_nearbyint,
   OTI_rint,
+  OTI_lrint,
+  OTI_llrint,
   /* Tangent */
   OTI_tan,
   /* Inverse tangent */
@@ -317,6 +319,8 @@ extern GTY(()) optab optab_table[OTI_MAX
 #define round_optab (optab_table[OTI_round])
 #define nearbyint_optab (optab_table[OTI_nearbyint])
 #define rint_optab (optab_table[OTI_rint])
+#define lrint_optab (optab_table[OTI_lrint])
+#define llrint_optab (optab_table[OTI_llrint])
 #define tan_optab (optab_table[OTI_tan])
 #define atan_optab (optab_table[OTI_atan])
 #define copysign_optab (optab_table[OTI_copysign])
Index: testsuite/gcc.dg/builtins-46.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/builtins-46.c,v
retrieving revision 1.1
diff -u -p -r1.1 builtins-46.c
--- testsuite/gcc.dg/builtins-46.c	4 Sep 2004 07:55:12 -0000	1.1
+++ testsuite/gcc.dg/builtins-46.c	21 Mar 2005 10:26:31 -0000
@@ -1,6 +1,7 @@
 /* Copyright (C) 2004 Free Software Foundation.
 
-   Check that rint, rintf, rintl, floor, floorf, floorl,
+   Check that rint, rintf, rintl, lrint, lrintf, lrintl,
+   llrint, llrintf, llrintl, floor, floorf, floorl,
    ceil, ceilf, ceill, trunc, truncf, truncl,
    nearbyint, nearbyintf and nearbyintl
    built-in functions compile.
@@ -11,18 +12,24 @@
 /* { dg-options "-O2 -ffast-math" } */
 
 extern double rint(double);
+extern long int lrint(double);
+extern long long int llrint(double);
 extern double floor(double);
 extern double ceil(double);
 extern double trunc(double);
 extern double nearbyint(double);
 
 extern float rintf(float);
+extern long int lrintf(float);
+extern long long int llrintf(float);
 extern float floorf(float);
 extern float ceilf(float);
 extern float truncf(float);
 extern float nearbyintf(float);
 
 extern long double rintl(long double);
+extern long int lrintl(long double);
+extern long long int llrintl(long double);
 extern long double floorl(long double);
 extern long double ceill(long double);
 extern long double truncl(long double);
@@ -34,6 +41,16 @@ double test1(double x)
   return rint(x);
 }
 
+long int test11(double x)
+{
+  return lrint(x);
+}
+
+long long int test12(double x)
+{
+  return llrint(x);
+}
+
 double test2(double x)
 {
   return floor(x);
@@ -59,6 +76,16 @@ float test1f(float x)
   return rintf(x);
 }
 
+long int test11f(float x)
+{
+  return lrintf(x);
+}
+
+long long int test12f(float x)
+{
+  return llrintf(x);
+}
+
 float test2f(float x)
 {
   return floorf(x);
@@ -84,6 +111,16 @@ long double test1l(long double x)
   return rintl(x);
 }
 
+long int test11l(long double x)
+{
+  return lrintl(x);
+}
+
+long long int test12l(long double x)
+{
+  return llrintl(x);
+}
+
 long double test2l(long double x)
 {
   return floorl(x);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]