3 dnl Copyright (C) 2007-2008, 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN_ONCE([gl_DOUBLE_EXPONENT_LOCATION],
9 AC_CACHE_CHECK([where to find the exponent in a 'double'],
10 [gl_cv_cc_double_expbit0],
19 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
20 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
21 static unsigned int ored_words[NWORDS];
22 static unsigned int anded_words[NWORDS];
23 static void add_to_ored_words (double x)
27 /* Clear it first, in case sizeof (double) < sizeof (memory_double). */
28 memset (&m, 0, sizeof (memory_double));
30 for (i = 0; i < NWORDS; i++)
32 ored_words[i] |= m.word[i];
33 anded_words[i] &= m.word[i];
39 FILE *fp = fopen ("conftest.out", "w");
42 for (j = 0; j < NWORDS; j++)
43 anded_words[j] = ~ (unsigned int) 0;
44 add_to_ored_words (0.25);
45 add_to_ored_words (0.5);
46 add_to_ored_words (1.0);
47 add_to_ored_words (2.0);
48 add_to_ored_words (4.0);
49 /* Remove bits that are common (e.g. if representation of the first mantissa
51 for (j = 0; j < NWORDS; j++)
52 ored_words[j] &= ~anded_words[j];
53 /* Now find the nonzero word. */
54 for (j = 0; j < NWORDS; j++)
55 if (ored_words[j] != 0)
60 for (i = j + 1; i < NWORDS; i++)
61 if (ored_words[i] != 0)
63 fprintf (fp, "unknown");
64 return (fclose (fp) != 0);
67 if ((ored_words[j] >> i) & 1)
69 fprintf (fp, "word %d bit %d", (int) j, (int) i);
70 return (fclose (fp) != 0);
73 fprintf (fp, "unknown");
74 return (fclose (fp) != 0);
77 [gl_cv_cc_double_expbit0=`cat conftest.out`],
78 [gl_cv_cc_double_expbit0="unknown"],
80 dnl On ARM, there are two 'double' floating-point formats, used by
81 dnl different sets of instructions: The older FPA instructions assume
82 dnl that they are stored in big-endian word order, while the words
83 dnl (like integer types) are stored in little-endian byte order.
84 dnl The newer VFP instructions assume little-endian order
86 AC_EGREP_CPP([mixed_endianness], [
87 #if defined arm || defined __arm || defined __arm__
91 [gl_cv_cc_double_expbit0="unknown"],
93 pushdef([AC_MSG_CHECKING],[:])dnl
94 pushdef([AC_MSG_RESULT],[:])dnl
95 pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
97 [gl_cv_cc_double_expbit0="word 0 bit 20"],
98 [gl_cv_cc_double_expbit0="word 1 bit 20"],
99 [gl_cv_cc_double_expbit0="unknown"])
100 popdef([AC_MSG_RESULT_UNQUOTED])dnl
101 popdef([AC_MSG_RESULT])dnl
102 popdef([AC_MSG_CHECKING])dnl
107 case "$gl_cv_cc_double_expbit0" in
109 word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
110 bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
111 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
112 [Define as the word index where to find the exponent of 'double'.])
113 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
114 [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])