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]

[JAVA] Add acos, asin, ceil and floor lang.Math builtins


The following patch adds support for implementing the lang.Math functions
acos, asin, ceil and floor using GCC's mathematical builtins.  When using
-ffast-math this allows acos and asin to be expanded as x87 inline
intrinsics on IA-32, and for floor and ceil with constant arguments to
be constant folded at compile-time.

The following patch has been tested on i686-pc-linux-gnu with a full
bootstrap including java, and tested with a top-level "make -k check"
with no new failures.

Ok for mainline?



2004-04-25  Roger Sayle  <roger@eyesopen.com>

	* builtins.c (java_builtins): Add acos, asin, ceil and floor.
	(initialize_builtins): Likewise, define acos, asin, ceil and floor.

	* java/libjava.lang/MathBuiltin.java: Add tests for acos, asin,
	ceil and floor.


Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/builtins.c,v
retrieving revision 1.22
diff -c -3 -p -r1.22 builtins.c
*** builtins.c	30 Mar 2004 19:19:06 -0000	1.22
--- builtins.c	25 Apr 2004 02:23:08 -0000
*************** static GTY(()) struct builtin_record jav
*** 74,83 ****
--- 74,87 ----
    { { "java.lang.Math" }, { "min" }, min_builtin, 0 },
    { { "java.lang.Math" }, { "max" }, max_builtin, 0 },
    { { "java.lang.Math" }, { "abs" }, abs_builtin, 0 },
+   { { "java.lang.Math" }, { "acos" }, NULL, BUILT_IN_ACOS },
+   { { "java.lang.Math" }, { "asin" }, NULL, BUILT_IN_ASIN },
    { { "java.lang.Math" }, { "atan" }, NULL, BUILT_IN_ATAN },
    { { "java.lang.Math" }, { "atan2" }, NULL, BUILT_IN_ATAN2 },
+   { { "java.lang.Math" }, { "ceil" }, NULL, BUILT_IN_CEIL },
    { { "java.lang.Math" }, { "cos" }, NULL, BUILT_IN_COS },
    { { "java.lang.Math" }, { "exp" }, NULL, BUILT_IN_EXP },
+   { { "java.lang.Math" }, { "floor" }, NULL, BUILT_IN_FLOOR },
    { { "java.lang.Math" }, { "log" }, NULL, BUILT_IN_LOG },
    { { "java.lang.Math" }, { "pow" }, NULL, BUILT_IN_POW },
    { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN },
*************** initialize_builtins (void)
*** 186,199 ****
--- 190,211 ----
    define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
  		  float_ftype_float_float, "fmodf");

+   define_builtin (BUILT_IN_ACOS, "__builtin_acos",
+ 		  double_ftype_double, "_ZN4java4lang4Math4acosEd");
+   define_builtin (BUILT_IN_ASIN, "__builtin_asin",
+ 		  double_ftype_double, "_ZN4java4lang4Math4asinEd");
    define_builtin (BUILT_IN_ATAN, "__builtin_atan",
  		  double_ftype_double, "_ZN4java4lang4Math4atanEd");
    define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
  		  double_ftype_double_double, "_ZN4java4lang4Math5atan2Edd");
+   define_builtin (BUILT_IN_CEIL, "__builtin_ceil",
+ 		  double_ftype_double, "_ZN4java4lang4Math4ceilEd");
    define_builtin (BUILT_IN_COS, "__builtin_cos",
  		  double_ftype_double, "_ZN4java4lang4Math3cosEd");
    define_builtin (BUILT_IN_EXP, "__builtin_exp",
  		  double_ftype_double, "_ZN4java4lang4Math3expEd");
+   define_builtin (BUILT_IN_FLOOR, "__builtin_floor",
+ 		  double_ftype_double, "_ZN4java4lang4Math5floorEd");
    define_builtin (BUILT_IN_LOG, "__builtin_log",
  		  double_ftype_double, "_ZN4java4lang4Math3logEd");
    define_builtin (BUILT_IN_POW, "__builtin_pow",


Index: MathBuiltin.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.lang/MathBuiltin.java,v
retrieving revision 1.1
diff -c -3 -p -r1.1 MathBuiltin.java
*** MathBuiltin.java	8 Jun 2003 18:17:53 -0000	1.1
--- MathBuiltin.java	25 Apr 2004 14:05:50 -0000
*************** class MathBuiltin
*** 5,10 ****
--- 5,20 ----
      return Math.abs(x);
    }

+   static double acos(double x)
+   {
+     return Math.acos(x);
+   }
+
+   static double asin(double x)
+   {
+     return Math.asin(x);
+   }
+
    static double atan(double x)
    {
      return Math.atan(x);
*************** class MathBuiltin
*** 15,20 ****
--- 25,35 ----
      return Math.atan2(x,y);
    }

+   static double ceil(double x)
+   {
+     return Math.ceil(x);
+   }
+
    static double cos(double x)
    {
      return Math.cos(x);
*************** class MathBuiltin
*** 25,30 ****
--- 40,50 ----
      return Math.exp(x);
    }

+   static double floor(double x)
+   {
+     return Math.floor(x);
+   }
+
    static double log(double x)
    {
      return Math.log(x);
*************** class MathBuiltin
*** 62,69 ****

    public static void main(String argv[])
    {
!     double sum = abs (1.0) + atan (1.0) + atan2 (1.0, 1.0) + cos (1.0)
!                  + exp (1.0) + log(1.0) + max(1.0, 1.0) + min (1.0, 1.0)
  		 + pow (1.0, 1.0) + sin (1.0) + sqrt(1.0) + tan(1.0);
    }
  }
--- 82,90 ----

    public static void main(String argv[])
    {
!     double sum = abs (1.0) + acos (1.0) + asin (1.0) + atan (1.0)
! 		 + atan2 (1.0, 1.0) + ceil (1.0) + cos (1.0) + exp (1.0)
! 		 + floor (1.0) + log(1.0) + max(1.0, 1.0) + min (1.0, 1.0)
  		 + pow (1.0, 1.0) + sin (1.0) + sqrt(1.0) + tan(1.0);
    }
  }



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]