Imported Upstream version 1.3.14
[debian/gzip] / m4 / exponentd.m4
1 # exponentd.m4 serial 1
2 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6 AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
7 [
8   AC_CACHE_CHECK([where to find the exponent in a 'double'],
9     [gl_cv_cc_double_expbit0],
10     [
11       AC_TRY_RUN([
12 #include <float.h>
13 #include <stddef.h>
14 #include <stdio.h>
15 #include <string.h>
16 #define NWORDS \
17   ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
18 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
19 static unsigned int ored_words[NWORDS];
20 static unsigned int anded_words[NWORDS];
21 static void add_to_ored_words (double x)
22 {
23   memory_double m;
24   size_t i;
25   /* Clear it first, in case sizeof (double) < sizeof (memory_double).  */
26   memset (&m, 0, sizeof (memory_double));
27   m.value = x;
28   for (i = 0; i < NWORDS; i++)
29     {
30       ored_words[i] |= m.word[i];
31       anded_words[i] &= m.word[i];
32     }
33 }
34 int main ()
35 {
36   size_t j;
37   FILE *fp = fopen ("conftest.out", "w");
38   if (fp == NULL)
39     return 1;
40   for (j = 0; j < NWORDS; j++)
41     anded_words[j] = ~ (unsigned int) 0;
42   add_to_ored_words (0.25);
43   add_to_ored_words (0.5);
44   add_to_ored_words (1.0);
45   add_to_ored_words (2.0);
46   add_to_ored_words (4.0);
47   /* Remove bits that are common (e.g. if representation of the first mantissa
48      bit is explicit).  */
49   for (j = 0; j < NWORDS; j++)
50     ored_words[j] &= ~anded_words[j];
51   /* Now find the nonzero word.  */
52   for (j = 0; j < NWORDS; j++)
53     if (ored_words[j] != 0)
54       break;
55   if (j < NWORDS)
56     {
57       size_t i;
58       for (i = j + 1; i < NWORDS; i++)
59         if (ored_words[i] != 0)
60           {
61             fprintf (fp, "unknown");
62             return (fclose (fp) != 0);
63           }
64       for (i = 0; ; i++)
65         if ((ored_words[j] >> i) & 1)
66           {
67             fprintf (fp, "word %d bit %d", (int) j, (int) i);
68             return (fclose (fp) != 0);
69           }
70     }
71   fprintf (fp, "unknown");
72   return (fclose (fp) != 0);
73 }
74         ],
75         [gl_cv_cc_double_expbit0=`cat conftest.out`],
76         [gl_cv_cc_double_expbit0="unknown"],
77         [
78           dnl On ARM, there are two 'double' floating-point formats, used by
79           dnl different sets of instructions: The older FPA instructions assume
80           dnl that they are stored in big-endian word order, while the words
81           dnl (like integer types) are stored in little-endian byte order.
82           dnl The newer VFP instructions assume little-endian order consistenly.
83           AC_EGREP_CPP([mixed_endianness], [
84 #if defined arm || defined __arm || defined __arm__
85   mixed_endianness
86 #endif
87             ],
88             [gl_cv_cc_double_expbit0="unknown"],
89             [
90               pushdef([AC_MSG_CHECKING],[:])dnl
91               pushdef([AC_MSG_RESULT],[:])dnl
92               pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
93               AC_C_BIGENDIAN(
94                 [gl_cv_cc_double_expbit0="word 0 bit 20"],
95                 [gl_cv_cc_double_expbit0="word 1 bit 20"],
96                 [gl_cv_cc_double_expbit0="unknown"])
97               popdef([AC_MSG_RESULT_UNQUOTED])dnl
98               popdef([AC_MSG_RESULT])dnl
99               popdef([AC_MSG_CHECKING])dnl
100             ])
101         ])
102       rm -f conftest.out
103     ])
104   case "$gl_cv_cc_double_expbit0" in
105     word*bit*)
106       word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
107       bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
108       AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
109         [Define as the word index where to find the exponent of 'double'.])
110       AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
111         [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])
112       ;;
113   esac
114 ])