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]

Re: [PATCH]: helper macros for math builtins


 > From: Roger Sayle <roger@eyesopen.com>
 > 
 > On Fri, 5 Mar 2004, Kaveh R. Ghazi wrote:
 > > 2004-03-05  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 > >
 > > 	* tree.h (BUILTIN_EXP10_P, BUILTIN_EXPONENT_P, BUILTIN_SQRT_P,
 > > 	BUILTIN_CBRT_P, BUILTIN_ROOT_P): New macros.
 > >
 > > 	* builtins.c (fold_builtin_logarithm, fold_builtin): Use new
 > > 	macros.
 > > 	* fold-const.c (fold_mathfn_compare, fold): Likewise.
 > 
 > This is OK for mainline.

Thanks, here's the testsuite update.  While in there I added comments
and fixed an inconsistent macro name.  The new cases are for
sqrt(expN(x)) and pow(expN(x), y).  The rest of the previous patch
touched code that should already have testcases.

Tested via C-only bootstrap plus "make check" and installed.

		--Kaveh


2004-03-06  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* gcc.dg/torture/builtin-explog-1.c: Add comments for each test.
	Rename LOGPOW -> LOG_POW.
	(SQRT_EXP, POW_EXP): New.

diff -rup orig/egcc-CVS20040305/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c egcc-CVS20040305/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c
--- orig/egcc-CVS20040305/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c	2004-03-04 20:01:50.000000000 -0500
+++ egcc-CVS20040305/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c	2004-03-06 12:32:29.275449000 -0500
@@ -37,6 +37,7 @@ PROTOTYPE2(pow)
 void test(double d1, double d2, float f1, float f2,
 	  long double ld1, long double ld2)
 {
+  /* Test logN(1) -> 0.  */
 #define LOG_1(LOG) \
  extern void link_failure_##LOG##_1(void); \
  if (LOG(1.0) != 0.0 || LOG##f(1.0F) != 0.0F || LOG##l(1.0L) != 0.0L) \
@@ -46,6 +47,7 @@ void test(double d1, double d2, float f1
   LOG_1(log2);
   LOG_1(log10);
   
+  /* Test logN(N) -> 1.  */
 #define LOG_N(LOG, BASE) \
  extern void link_failure_##LOG##_N(void); \
  if (LOG(BASE) != 1.0 || LOG##f(BASE##F) != 1.0F || LOG##l(BASE##L) != 1.0L) \
@@ -55,6 +57,7 @@ void test(double d1, double d2, float f1
   LOG_N(log2, 2.0);
   LOG_N(log10, 10.0);
 
+  /* Test logN(expN(x)) -> x.  */
 #define LOGEXP_SAME(LOG, EXP) \
  extern void link_failure_##LOG##_##EXP##_same(void); \
  if (LOG(EXP(d1)) != d1 || LOG##f(EXP##f(f1)) != f1 \
@@ -65,6 +68,7 @@ void test(double d1, double d2, float f1
   LOGEXP_SAME(log10,exp10);
   LOGEXP_SAME(log10,pow10);
 
+  /* Test logN(expM(x)) -> x*logN(M).  */
 #define LOGEXP(LOG, EXP, BASE) \
  extern void link_failure_##LOG##_##EXP(void); \
  if (LOG(EXP(d1)) != d1*LOG(BASE) || LOG##f(EXP##f(f1)) != f1*LOG##f(BASE##F) \
@@ -83,6 +87,7 @@ void test(double d1, double d2, float f1
   LOGEXP(log10,exp10,10.0);
   LOGEXP(log10,pow10,10.0);
   
+  /* Test logN(sqrt(x)) -> 0.5*logN(x).  */
 #define LOG_SQRT(LOG) \
  extern void link_failure_##LOG##_sqrt(void); \
  if (LOG(sqrt(d1)) != 0.5*LOG(d1) || LOG##f(sqrtf(f1)) != 0.5F*LOG##f(f1) \
@@ -92,6 +97,18 @@ void test(double d1, double d2, float f1
   LOG_SQRT(log2);
   LOG_SQRT(log10);
   
+  /* Test sqrt(expN(x)) -> expN(x*0.5).  */
+#define SQRT_EXP(EXP) \
+ extern void link_failure_sqrt_##EXP(void); \
+ if (sqrt(EXP(d1)) != EXP(d1*0.5) || sqrtf(EXP##f(f1)) != EXP##f(f1*0.5F) \
+  || sqrtl(EXP##l(ld1)) != EXP##l(ld1*0.5L)) link_failure_sqrt_##EXP()
+    
+  SQRT_EXP(exp);
+  SQRT_EXP(exp2);
+  SQRT_EXP(exp10);
+  SQRT_EXP(pow10);
+  
+  /* Test logN(cbrt(x)) -> (1/3)*logN(x).  */
 #define LOG_CBRT(LOG) \
  extern void link_failure_##LOG##_cbrt(void); \
  if (LOG(cbrt(d1)) != (1.0/3)*LOG(d1) \
@@ -102,15 +119,28 @@ void test(double d1, double d2, float f1
   LOG_CBRT(log2);
   LOG_CBRT(log10);
   
-#define LOGPOW(LOG, POW) \
+  /* Test logN(pow(x,y)) -> y*logN(x).  */
+#define LOG_POW(LOG, POW) \
  extern void link_failure_##LOG##_##POW(void); \
  if (LOG(POW(d1,d2)) != d2*LOG(d1) || LOG##f(POW##f(f1,f2)) != f2*LOG##f(f1) \
   || LOG##l(POW##l(ld1,ld2)) != ld2*LOG##l(ld1)) link_failure_##LOG##_##POW()
   
-  LOGPOW(log,pow);
-  LOGPOW(log2,pow);
-  LOGPOW(log10,pow);
+  LOG_POW(log,pow);
+  LOG_POW(log2,pow);
+  LOG_POW(log10,pow);
+
+  /* Test pow(expN(x),y)) -> expN(x*y).  */
+#define POW_EXP(POW, EXP) \
+ extern void link_failure_##POW##_##EXP(void); \
+ if (POW(EXP(d1),d2) != EXP(d1*d2) || POW##f(EXP##f(f1),f2) != EXP##f(f1*f2) \
+  || POW##l(EXP##l(ld1),ld2) != EXP##l(ld1*ld2)) link_failure_##POW##_##EXP()
+  
+  POW_EXP(pow, exp);
+  POW_EXP(pow, exp2);
+  POW_EXP(pow, exp10);
+  POW_EXP(pow, pow10);
 
+  /* Test expN(0) -> 1.  */
 #define EXP_0(EXP) \
  extern void link_failure_##EXP##_0(void); \
  if (EXP(0.0) != 1.0 || EXP##f(0.0F) != 1.0F || EXP##l(0.0L) != 1.0L) \
@@ -121,6 +151,7 @@ void test(double d1, double d2, float f1
   EXP_0(exp10);
   EXP_0(pow10);
   
+  /* Test expN(1) -> N.  */
 #define EXP_N(EXP, BASE) \
  extern void link_failure_##EXP##_N(void); \
  if (EXP(1.0) != BASE || EXP##f(1.0F) != BASE##F || EXP##l(1.0L) != BASE##L) \
@@ -131,6 +162,7 @@ void test(double d1, double d2, float f1
   EXP_N(exp10, 10.0);
   EXP_N(pow10, 10.0);
 
+  /* Test expN(integer) -> N*N*N*...  */
 #define EXP_INT(EXP, BASE) \
  extern void link_failure_##EXP##_INT(void); \
  if (EXP(5.0) < (BASE)*(BASE)*(BASE)*(BASE)*(BASE) - PREC \
@@ -146,6 +178,7 @@ void test(double d1, double d2, float f1
   EXP_INT(exp10, 10.0);
   EXP_INT(pow10, 10.0);
 
+  /* Test expN(logN(x)) -> x.  */
 #define EXPLOG_SAME(EXP, LOG) \
  extern void link_failure_##EXP##_##LOG##_same(void); \
  if (EXP(LOG(d1)) != d1 || EXP##f(LOG##f(f1)) != f1 \
@@ -156,6 +189,7 @@ void test(double d1, double d2, float f1
   EXPLOG_SAME(exp10, log10);
   EXPLOG_SAME(pow10, log10);
 
+  /* Test expN(x)*expN(y)) -> expN(x+y).  */
 #define EXPXEXP(EXP) \
  extern void link_failure_##EXP##X##EXP(void); \
  if (EXP(d1)*EXP(d2) != EXP(d1+d2) || EXP##f(f1)*EXP##f(f2) != EXP##f(f1+f2) \
@@ -166,6 +200,8 @@ void test(double d1, double d2, float f1
   EXPXEXP(exp10);
   EXPXEXP(pow10);
 
+  /* Test x/expN(y) -> x*expN(-y).  */
+  /* Test expN(x)/expN(y) -> expN(x-y).  */
 #define DIVEXP(EXP) \
  extern void link_failure_div1_##EXP(void); \
  if (d1/EXP(d2) != d1*EXP(-d2) || f1/EXP##f(f2) != f1*EXP##f(-f2) \


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