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] tan and atan builtin functions


The following adds initial support for tan, tanf, tanl, atan, atanf
and atanl mathematical functions as GCC builtins.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except treelang (including ada) and
regression checked with a top-level "make -k check" with no new
failures.

Ok for mainline?


2003-05-20  Roger Sayle  <roger@eyesopen.com>

	* builtins.def: Defome atan, atanf, atanl, tan, tanf and tanl
	builtin functions (and their __builtin_* variants).
	* builtins.c (mathfn_built_in): Handle tan{,f,l} and atan{,f,l}.
	(expand_builtin): Don't expand tan{,f,l} or atan{,f,l} when not
	optimizing.

	* doc/extend.texi: Document new tan and atan builtins, and
	their float and long double variants.

	* gcc.dg/builtins-1.c: Add tests for tan and atan.
	* gcc.dg/builtins-4.c: Add test for fmod.


Index: builtins.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.def,v
retrieving revision 1.52
diff -c -3 -p -r1.52 builtins.def
*** builtins.def	4 May 2003 22:18:17 -0000	1.52
--- builtins.def	20 May 2003 14:40:48 -0000
*************** DEF_LIB_BUILTIN(BUILT_IN_LOG,
*** 495,500 ****
--- 495,510 ----
  				: (flag_unsafe_math_optimizations
  				   ? ATTR_CONST_NOTHROW_LIST
  				   : ATTR_PURE_NOTHROW_LIST))
+ DEF_LIB_BUILTIN(BUILT_IN_TAN,
+ 		"__builtin_tan",
+ 		BT_FN_DOUBLE_DOUBLE,
+ 		flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
+ 					       : ATTR_PURE_NOTHROW_LIST)
+ DEF_LIB_BUILTIN(BUILT_IN_ATAN,
+ 		"__builtin_atan",
+ 		BT_FN_DOUBLE_DOUBLE,
+ 		flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
+ 					       : ATTR_PURE_NOTHROW_LIST)
  DEF_LIB_BUILTIN(BUILT_IN_POW,
  		"__builtin_pow",
  		BT_FN_DOUBLE_DOUBLE_DOUBLE,
*************** DEF_C99_C90RES_BUILTIN(BUILT_IN_LOGF,
*** 547,552 ****
--- 557,572 ----
  				       : (flag_unsafe_math_optimizations
  					  ? ATTR_CONST_NOTHROW_LIST
  					  : ATTR_PURE_NOTHROW_LIST))
+ DEF_C99_C90RES_BUILTIN(BUILT_IN_TANF,
+ 		       "__builtin_tanf",
+ 		       BT_FN_FLOAT_FLOAT,
+ 		       flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
+ 						      : ATTR_PURE_NOTHROW_LIST)
+ DEF_C99_C90RES_BUILTIN(BUILT_IN_ATANF,
+ 		       "__builtin_atanf",
+ 		       BT_FN_FLOAT_FLOAT,
+ 		       flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
+ 						      : ATTR_PURE_NOTHROW_LIST)
  DEF_C99_C90RES_BUILTIN(BUILT_IN_POWF,
  		       "__builtin_powf",
  		       BT_FN_FLOAT_FLOAT_FLOAT,
*************** DEF_C99_C90RES_BUILTIN(BUILT_IN_LOGL,
*** 599,604 ****
--- 619,634 ----
  				       : (flag_unsafe_math_optimizations
  					  ? ATTR_CONST_NOTHROW_LIST
  					  : ATTR_PURE_NOTHROW_LIST))
+ DEF_C99_C90RES_BUILTIN(BUILT_IN_TANL,
+ 		       "__builtin_tanl",
+ 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE,
+ 		       flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
+ 						      : ATTR_PURE_NOTHROW_LIST)
+ DEF_C99_C90RES_BUILTIN(BUILT_IN_ATANL,
+ 		       "__builtin_atanl",
+ 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE,
+ 		       flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
+ 						      : ATTR_PURE_NOTHROW_LIST)
  DEF_C99_C90RES_BUILTIN(BUILT_IN_POWL,
  		       "__builtin_powl",
  		       BT_FN_LONG_DOUBLE_LONG_DOUBLE_LONG_DOUBLE,
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.202
diff -c -3 -p -r1.202 builtins.c
*** builtins.c	18 May 2003 22:50:25 -0000	1.202
--- builtins.c	20 May 2003 14:40:49 -0000
*************** mathfn_built_in (type, fn)
*** 1503,1508 ****
--- 1503,1518 ----
        case BUILT_IN_LOGL:
  	fcode = BUILT_IN_LOG;
  	break;
+       case BUILT_IN_TAN:
+       case BUILT_IN_TANF:
+       case BUILT_IN_TANL:
+ 	fcode = BUILT_IN_TAN;
+ 	break;
+       case BUILT_IN_ATAN:
+       case BUILT_IN_ATANF:
+       case BUILT_IN_ATANL:
+ 	fcode = BUILT_IN_ATAN;
+ 	break;
        case BUILT_IN_FLOOR:
        case BUILT_IN_FLOORF:
        case BUILT_IN_FLOORL:
*************** mathfn_built_in (type, fn)
*** 1559,1564 ****
--- 1569,1584 ----
        case BUILT_IN_LOGL:
  	fcode = BUILT_IN_LOGF;
  	break;
+       case BUILT_IN_TAN:
+       case BUILT_IN_TANF:
+       case BUILT_IN_TANL:
+ 	fcode = BUILT_IN_TANF;
+ 	break;
+       case BUILT_IN_ATAN:
+       case BUILT_IN_ATANF:
+       case BUILT_IN_ATANL:
+ 	fcode = BUILT_IN_ATANF;
+ 	break;
        case BUILT_IN_FLOOR:
        case BUILT_IN_FLOORF:
        case BUILT_IN_FLOORL:
*************** mathfn_built_in (type, fn)
*** 1615,1620 ****
--- 1635,1650 ----
        case BUILT_IN_LOGL:
  	fcode = BUILT_IN_LOGL;
  	break;
+       case BUILT_IN_TAN:
+       case BUILT_IN_TANF:
+       case BUILT_IN_TANL:
+ 	fcode = BUILT_IN_TANL;
+ 	break;
+       case BUILT_IN_ATAN:
+       case BUILT_IN_ATANF:
+       case BUILT_IN_ATANL:
+ 	fcode = BUILT_IN_ATANL;
+ 	break;
        case BUILT_IN_FLOOR:
        case BUILT_IN_FLOORF:
        case BUILT_IN_FLOORL:
*************** expand_builtin (exp, target, subtarget,
*** 4295,4300 ****
--- 4325,4336 ----
        case BUILT_IN_LOG:
        case BUILT_IN_LOGF:
        case BUILT_IN_LOGL:
+       case BUILT_IN_TAN:
+       case BUILT_IN_TANF:
+       case BUILT_IN_TANL:
+       case BUILT_IN_ATAN:
+       case BUILT_IN_ATANF:
+       case BUILT_IN_ATANL:
        case BUILT_IN_POW:
        case BUILT_IN_POWF:
        case BUILT_IN_POWL:
Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.138
diff -c -3 -p -r1.138 extend.texi
*** doc/extend.texi	5 May 2003 23:12:37 -0000	1.138
--- doc/extend.texi	20 May 2003 14:40:50 -0000
*************** v4si f (v4si a, v4si b, v4si c)
*** 4579,4587 ****
--- 4579,4590 ----
  @findex abort
  @findex abs
  @findex alloca
+ @findex atan
  @findex atan2
  @findex atan2f
  @findex atan2l
+ @findex atanf
+ @findex atanl
  @findex bcmp
  @findex bzero
  @findex calloc
*************** v4si f (v4si a, v4si b, v4si c)
*** 4671,4676 ****
--- 4674,4682 ----
  @findex strrchr
  @findex strspn
  @findex strstr
+ @findex tan
+ @findex tanf
+ @findex tanl
  @findex trunc
  @findex truncf
  @findex truncl
*************** are handled as built-in functions
*** 4720,4735 ****
  except in strict ISO C90 mode (@option{-ansi} or @option{-std=c89}).

  There are also built-in versions of the ISO C99 functions @code{atan2f},
! @code{atan2l}, @code{ceilf}, @code{ceill}, @code{cosf}, @code{cosl},
  @code{expf}, @code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf},
  @code{floorl}, @code{fmodf}, @code{fmodl},
  @code{logf}, @code{logl}, @code{powf}, @code{powl},
! @code{sinf}, @code{sinl}, @code{sqrtf} and @code{sqrtl}
  that are recognized in any mode since ISO C90 reserves these names for
  the purpose to which ISO C99 puts them.  All these functions have
  corresponding versions prefixed with @code{__builtin_}.

! The ISO C90 functions @code{abort}, @code{abs}, @code{atan2},
  @code{calloc}, @code{ceil}, @code{cos}, @code{exit},
  @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
  @code{fprintf}, @code{fputs}, @code{labs}, @code{log}, @code{malloc},
--- 4726,4743 ----
  except in strict ISO C90 mode (@option{-ansi} or @option{-std=c89}).

  There are also built-in versions of the ISO C99 functions @code{atan2f},
! @code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
! @code{cosf}, @code{cosl},
  @code{expf}, @code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf},
  @code{floorl}, @code{fmodf}, @code{fmodl},
  @code{logf}, @code{logl}, @code{powf}, @code{powl},
! @code{sinf}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
! @code{tanf} and @code{tanl}
  that are recognized in any mode since ISO C90 reserves these names for
  the purpose to which ISO C99 puts them.  All these functions have
  corresponding versions prefixed with @code{__builtin_}.

! The ISO C90 functions @code{abort}, @code{abs}, @code{atan}, @code{atan2},
  @code{calloc}, @code{ceil}, @code{cos}, @code{exit},
  @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
  @code{fprintf}, @code{fputs}, @code{labs}, @code{log}, @code{malloc},
*************** The ISO C90 functions @code{abort}, @cod
*** 4739,4745 ****
  @code{strcat}, @code{strchr}, @code{strcmp},
  @code{strcpy}, @code{strcspn}, @code{strlen}, @code{strncat}, @code{strncmp},
  @code{strncpy}, @code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
! @code{vprintf} and @code{vsprintf}
  are all recognized as built-in functions unless
  @option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
  is specified for an individual function).  All of these functions have
--- 4747,4753 ----
  @code{strcat}, @code{strchr}, @code{strcmp},
  @code{strcpy}, @code{strcspn}, @code{strlen}, @code{strncat}, @code{strncmp},
  @code{strncpy}, @code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
! @code{tan}, @code{vprintf} and @code{vsprintf}
  are all recognized as built-in functions unless
  @option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
  is specified for an individual function).  All of these functions have


Index: builtins-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/builtins-1.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 builtins-1.c
*** builtins-1.c	4 Aug 2002 02:08:20 -0000	1.1
--- builtins-1.c	20 May 2003 14:45:59 -0000
*************** double test2(double x) { return __builti
*** 13,28 ****
--- 13,34 ----
  double test3(double x) { return __builtin_sin(x); }
  double test4(double x) { return __builtin_exp(x); }
  double test5(double x) { return __builtin_log(x); }
+ double test6(double x) { return __builtin_tan(x); }
+ double test7(double x) { return __builtin_atan(x); }

  float test1f(float x) { return __builtin_sqrtf(x); }
  float test2f(float x) { return __builtin_cosf(x); }
  float test3f(float x) { return __builtin_sinf(x); }
  float test4f(float x) { return __builtin_expf(x); }
  float test5f(float x) { return __builtin_logf(x); }
+ float test6f(float x) { return __builtin_tanf(x); }
+ float test7f(float x) { return __builtin_atanf(x); }

  long double test1l(long double x) { return __builtin_sqrtl(x); }
  long double test2l(long double x) { return __builtin_cosl(x); }
  long double test3l(long double x) { return __builtin_sinl(x); }
  long double test4l(long double x) { return __builtin_expl(x); }
  long double test5l(long double x) { return __builtin_logl(x); }
+ long double test6l(long double x) { return __builtin_tanl(x); }
+ long double test7l(long double x) { return __builtin_atanl(x); }

Index: builtins-4.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/builtins-4.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 builtins-4.c
*** builtins-4.c	7 Feb 2003 22:37:57 -0000	1.1
--- builtins-4.c	20 May 2003 14:45:59 -0000
***************
*** 10,21 ****
--- 10,25 ----

  double test1(double x, double y) { return __builtin_pow(x,y); }
  double test2(double x, double y) { return __builtin_atan2(x,y); }
+ double test3(double x, double y) { return __builtin_fmod(x,y); }

  float test1f(float x, float y) { return __builtin_powf(x,y); }
  float test2f(float x, float y) { return __builtin_atan2f(x,y); }
+ float test3f(float x, float y) { return __builtin_fmodf(x,y); }

  long double test1l(long double x, long double y)
  { return __builtin_powl(x,y); }
  long double test2l(long double x, long double y)
  { return __builtin_atan2l(x,y); }
+ long double test3l(long double x, long double y)
+ { return __builtin_fmodl(x,y); }


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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