This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

Use static initializers for constant variables in libm-test.inc


libm-test.inc has various variables such as plus_infty and
min_subnorm_value that are used in tests and initialized dynamically
in the initialize function.

I guess this predates being able to be sure the compiler has built-in
functions such as __builtin_inf and __builtin_nan that can be used in
static initializers.  But since GCC 3.3 such functions are available
(and, similarly, -0.0 in source code can be relied upon to produce a
negative constant zero, and various tests use that directly instead of
minus_zero).

With tests in data tables rather than directly inside functions, it
will be necessary for appropriate expressions for these values, usable
in static initializers (so not references to other variables), to be
used where these values are test inputs or outputs.  Thus all such
values will need corresponding static initializers readily available.

This patch does a first step of defining these variables using static
initializers.  My proposal for moving tests into tables is then that
these static initializers are factored out into macros such as
MIN_VALUE_INIT, with gen-libm-test.pl knowing to make appropriate
substitutions when processing tests for tables.  (Once all tests are
defined through tables rather than code, it will then be possible to
eliminate the indirection and variables, and just make the variable
names themselves into macros for the initializers.)

Tested x86_64 and x86.

2013-05-03  Joseph Myers  <joseph@codesourcery.com>

	* math/libm-test.inc (plus_zero): Make const.  Add initializer.
	(minus_zero): Likewise.
	(plus_infty): Likewise.
	(minus_infty): Likewise.
	(qnan_value): Likewise.
	(max_value): Likewise.
	(min_value): Likewise.
	(min_subnorm_value): Likewise.
	(initialize): Do not initialize those variables dynamically.

diff --git a/math/libm-test.inc b/math/libm-test.inc
index 7597547..c58bd45 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -231,9 +231,25 @@ static int output_max_error;	/* Should the maximal errors printed?  */
 static int output_points;	/* Should the single function results printed?  */
 static int ignore_max_ulp;	/* Should we ignore max_ulp?  */
 
-static FLOAT minus_zero, plus_zero;
-static FLOAT plus_infty, minus_infty, qnan_value, max_value, min_value;
-static FLOAT min_subnorm_value;
+static const FLOAT plus_zero = CHOOSE (0.0L, 0.0, 0.0f,
+				       0.0L, 0.0, 0.0f);
+static const FLOAT minus_zero = CHOOSE (-0.0L, -0.0, -0.0f,
+					-0.0L, -0.0, -0.0f);
+static const FLOAT plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF,
+					HUGE_VALL, HUGE_VAL, HUGE_VALF);
+static const FLOAT minus_infty = CHOOSE (-HUGE_VALL, -HUGE_VAL, -HUGE_VALF,
+					 -HUGE_VALL, -HUGE_VAL, -HUGE_VALF);
+static const FLOAT qnan_value = FUNC (__builtin_nan) ("");
+static const FLOAT max_value = CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX,
+				       LDBL_MAX, DBL_MAX, FLT_MAX);
+static const FLOAT min_value = CHOOSE (LDBL_MIN, DBL_MIN, FLT_MIN,
+				       LDBL_MIN, DBL_MIN, FLT_MIN);
+static const FLOAT min_subnorm_value = CHOOSE (__LDBL_DENORM_MIN__,
+					       __DBL_DENORM_MIN__,
+					       __FLT_DENORM_MIN__,
+					       __LDBL_DENORM_MIN__,
+					       __DBL_DENORM_MIN__,
+					       __FLT_DENORM_MIN__);
 
 static FLOAT max_error, real_max_error, imag_max_error;
 
@@ -13814,33 +13830,6 @@ initialize (void)
 {
   fpstack_test ("start *init*");
 
-  plus_zero = 0.0;
-  qnan_value = FUNC (__builtin_nan) ("");
-  minus_zero = FUNC (copysign) (0.0, -1.0);
-  plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF,
-		       HUGE_VALL, HUGE_VAL, HUGE_VALF);
-  minus_infty = CHOOSE (-HUGE_VALL, -HUGE_VAL, -HUGE_VALF,
-			-HUGE_VALL, -HUGE_VAL, -HUGE_VALF);
-  max_value = CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX,
-		      LDBL_MAX, DBL_MAX, FLT_MAX);
-  min_value = CHOOSE (LDBL_MIN, DBL_MIN, FLT_MIN,
-		      LDBL_MIN, DBL_MIN, FLT_MIN);
-  min_subnorm_value = CHOOSE (__LDBL_DENORM_MIN__,
-			      __DBL_DENORM_MIN__,
-			      __FLT_DENORM_MIN__,
-			      __LDBL_DENORM_MIN__,
-			      __DBL_DENORM_MIN__,
-			      __FLT_DENORM_MIN__);
-
-  (void) &plus_zero;
-  (void) &qnan_value;
-  (void) &minus_zero;
-  (void) &plus_infty;
-  (void) &minus_infty;
-  (void) &max_value;
-  (void) &min_value;
-  (void) &min_subnorm_value;
-
   /* Clear all exceptions.  From now on we must not get random exceptions.  */
   feclearexcept (FE_ALL_EXCEPT);
   errno = 0;

-- 
Joseph S. Myers
joseph@codesourcery.com


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