Debian Codegraph @

m4/exponentd.m4

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