Patchwork [middle,end] : Introduce BUILT_IN_I{CEIL_FLOOR_ROUND_RINT} FP-to-int conversion functions

login
register
mail settings
Submitter Uros Bizjak
Date Aug. 12, 2011, 12:15 p.m.
Message ID <CAFULd4Z0KiO_Lw-5d1rCjEDn8PVppvM6UsKQ1J5SNi9aOA7-Ng@mail.gmail.com>
Download mbox | patch
Permalink /patch/109833/
State New
Headers show

Comments

Uros Bizjak - Aug. 12, 2011, 12:15 p.m.
On Thu, Aug 11, 2011 at 2:50 PM, Richard Guenther <rguenther@suse.de> wrote:

>> Currently, conversion from floating point to integer on 64bit targets
>> goes through DImode temporary, due to missing BUILT_IN_ICEIL (and
>> other) builtins that can convert directly from FP to integer.

> Please document those in doc/extend.texi and make sure they do not
> leak into the global namespace as ifloor, etc., but are only available
> as __builtin_ifloor, etc..  Please also add at least a testcase
> that excercises expanding all of the variants - like by simply
> writing wrappers with the non-__builtin_ name variant like

Attached patch adds testcases for all conversion builtins. The gcc.dg
one tests that we are always able to link executable correctly, no
matter if target implements convresion optabs or not, the
gcc.target/i386 test exercises x86 specific code generation paths and
check if these builtins leak anything with -ffast-math.

2011-08-12  Uros Bizjak  <ubizjak@gmail.com>

	* gcc.dg/builtins-67.c: New test.
	* gcc.target/i386/conversion.c: Ditto.

Tested on x86_64-pc-linux-gnu {,-m32}. OK for mainline?

Uros.
Richard Guenther - Aug. 12, 2011, 12:18 p.m.
On Fri, 12 Aug 2011, Uros Bizjak wrote:

> On Thu, Aug 11, 2011 at 2:50 PM, Richard Guenther <rguenther@suse.de> wrote:
> 
> >> Currently, conversion from floating point to integer on 64bit targets
> >> goes through DImode temporary, due to missing BUILT_IN_ICEIL (and
> >> other) builtins that can convert directly from FP to integer.
> 
> > Please document those in doc/extend.texi and make sure they do not
> > leak into the global namespace as ifloor, etc., but are only available
> > as __builtin_ifloor, etc..  Please also add at least a testcase
> > that excercises expanding all of the variants - like by simply
> > writing wrappers with the non-__builtin_ name variant like
> 
> Attached patch adds testcases for all conversion builtins. The gcc.dg
> one tests that we are always able to link executable correctly, no
> matter if target implements convresion optabs or not, the
> gcc.target/i386 test exercises x86 specific code generation paths and
> check if these builtins leak anything with -ffast-math.
> 
> 2011-08-12  Uros Bizjak  <ubizjak@gmail.com>
> 
> 	* gcc.dg/builtins-67.c: New test.
> 	* gcc.target/i386/conversion.c: Ditto.
> 
> Tested on x86_64-pc-linux-gnu {,-m32}. OK for mainline?

Ok.

Thanks,
Richard.
Uros Bizjak - Aug. 12, 2011, 12:27 p.m.
On Fri, Aug 12, 2011 at 2:18 PM, Richard Guenther <rguenther@suse.de> wrote:

>> Attached patch adds testcases for all conversion builtins. The gcc.dg
>> one tests that we are always able to link executable correctly, no
>> matter if target implements convresion optabs or not, the
>> gcc.target/i386 test exercises x86 specific code generation paths and
>> check if these builtins leak anything with -ffast-math.
>>
>> 2011-08-12  Uros Bizjak  <ubizjak@gmail.com>
>>
>>       * gcc.dg/builtins-67.c: New test.
>>       * gcc.target/i386/conversion.c: Ditto.
>>
>> Tested on x86_64-pc-linux-gnu {,-m32}. OK for mainline?

Just FTR, attached was older version of the patch,

#include "builtins-config.h"

is needed in gcc.dg/builtins-67.c

and

#include "../../gcc.dg/builtins-config.h"

in gcc.target/i386/conversion.c.

Uros.

Patch

Index: gcc.target/i386/conversion.c
===================================================================
--- gcc.target/i386/conversion.c	(revision 0)
+++ gcc.target/i386/conversion.c	(revision 0)
@@ -0,0 +1,54 @@ 
+/* Check that conversion functions don't leak into global namespace.  */
+
+/* { dg-do link } */
+/* { dg-options "-ffast-math" }  */
+
+int ifloor (double a) { return __builtin_ifloor (a); }
+#ifdef HAVE_C99_RUNTIME
+int ifloorf (float a) { return __builtin_ifloorf (a); }
+int ifloorl (long double a) { return __builtin_ifloorl (a); }
+#endif
+
+long lfloor (double a) { return __builtin_lfloor (a); }
+#ifdef HAVE_C99_RUNTIME
+long lfloorf (float a) { return __builtin_lfloorf (a); }
+long lfloorl (long double a) { return __builtin_lfloorl (a); }
+#endif
+
+long long llfloor (double a) { return __builtin_llfloor (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llfloorf (float a) { return __builtin_llfloorf (a); }
+long long llfloorl (long double a) { return __builtin_llfloorl (a); }
+#endif
+
+int iceil (double a) { return __builtin_iceil (a); }
+#ifdef HAVE_C99_RUNTIME
+int iceilf (float a) { return __builtin_iceilf (a); }
+int iceill (long double a) { return __builtin_iceill (a); }
+#endif
+
+long lceil (double a) { return __builtin_lceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long lceilf (float a) { return __builtin_lceilf (a); }
+long lceill (long double a) { return __builtin_lceill (a); }
+#endif
+
+long long llceil (double a) { return __builtin_llceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llceilf (float a) { return __builtin_llceilf (a); }
+long long llceill (long double a) { return __builtin_llceill (a); }
+#endif
+
+int iround (double a) { return __builtin_iround (a); }
+#ifdef HAVE_C99_RUNTIME
+int iroundf (float a) { return __builtin_iroundf (a); }
+int iroundl (long double a) { return __builtin_iroundl (a); }
+#endif
+
+int irint (double a) { return __builtin_irint (a); }
+#ifdef HAVE_C99_RUNTIME
+int irintf (float a) { return __builtin_irintf (a); }
+int irintl (long double a) { return __builtin_irintl (a); }
+#endif
+
+int main () { return 0; }
Index: gcc.dg/builtins-67.c
===================================================================
--- gcc.dg/builtins-67.c	(revision 0)
+++ gcc.dg/builtins-67.c	(revision 0)
@@ -0,0 +1,71 @@ 
+/* Check that conversion functions link correctly with -ffast-math.  */
+
+/* { dg-do link } */
+/* { dg-options "-ffast-math -lm" }  */
+
+
+double floor (double);
+float floorf (float);
+long double floorl (long double);
+
+double ceil (double);
+float ceilf (float);
+long double ceill (long double);
+
+double round (double);
+float roundf (float);
+long double roundl (long double);
+
+double rint (double);
+float rintf (float);
+long double rintl (long double);
+
+int ifloor (double a) { return (int) floor (a); }
+#ifdef HAVE_C99_RUNTIME
+int ifloorf (float a) { return (int) floorf (a); }
+int ifloorl (long double a) { return (int) floorl (a); }
+#endif
+
+long lfloor (double a) { return (long) floor (a); }
+#ifdef HAVE_C99_RUNTIME
+long lfloorf (float a) { return (long) floorf (a); }
+long lfloorl (long double a) { return (long) floorl (a); }
+#endif
+
+long long llfloor (double a) { return (long long) floor (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llfloorf (float a) { return (long long) floorf (a); }
+long long llfloorl (long double a) { return (long long) floorl (a); }
+#endif
+
+int iceil (double a) { return (int) ceil (a); }
+#ifdef HAVE_C99_RUNTIME
+int iceilf (float a) { return (int) ceilf (a); }
+int iceill (long double a) { return (int) ceill (a); }
+#endif
+
+long lceil (double a) { return (long) ceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long lceilf (float a) { return (long) ceilf (a); }
+long lceill (long double a) { return (long) ceill (a); }
+#endif
+
+long long llceil (double a) { return (long long) ceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llceilf (float a) { return (long long) ceilf (a); }
+long long llceill (long double a) { return (long long) ceill (a); }
+#endif
+
+int iround (double a) { return (int) round (a); }
+#ifdef HAVE_C99_RUNTIME
+int iroundf (float a) { return (int) roundf (a); }
+int iroundl (long double a) { return (int) roundl (a); }
+#endif
+
+int irint (double a) { return (int) rint (a); }
+#ifdef HAVE_C99_RUNTIME
+int irintf (float a) { return (int) rintf (a); }
+int irintl (long double a) { return (int) rintl (a); }
+#endif
+
+int main () { return 0; }