Debian Codegraph @

m4/exponentl.m4

raw
1 # exponentl.m4
2 # serial 8
3 dnl Copyright (C) 2007-2026 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_LONG_DOUBLE_EXPONENT_LOCATION],
9 [
10 AC_REQUIRE([gl_BIGENDIAN])
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 AC_CACHE_CHECK([where to find the exponent in a 'long double'],
13 [gl_cv_cc_long_double_expbit0],
14 [
15 AC_RUN_IFELSE(
16 [AC_LANG_SOURCE([[
17 #include <float.h>
18 #include <stddef.h>
19 #include <stdio.h>
20 #include <string.h>
21 #define NWORDS \
22 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
23 typedef union { long double value; unsigned int word[NWORDS]; }
24 memory_long_double;
25 static unsigned int ored_words[NWORDS];
26 static unsigned int anded_words[NWORDS];
27 static void add_to_ored_words (long double *x)
28 {
29 memory_long_double m;
30 size_t i;
31 /* Clear it first, in case
32 sizeof (long double) < sizeof (memory_long_double). */
33 memset (&m, 0, sizeof (memory_long_double));
34 m.value = *x;
35 for (i = 0; i < NWORDS; i++)
36 {
37 ored_words[i] |= m.word[i];
38 anded_words[i] &= m.word[i];
39 }
40 }
41 int main ()
42 {
43 static long double samples[5] = { 0.25L, 0.5L, 1.0L, 2.0L, 4.0L };
44 size_t j;
45 FILE *fp = fopen ("conftest.out", "w");
46 if (fp == NULL)
47 return 1;
48 for (j = 0; j < NWORDS; j++)
49 anded_words[j] = ~ (unsigned int) 0;
50 for (j = 0; j < 5; j++)
51 add_to_ored_words (&samples[j]);
52 /* Remove bits that are common (e.g. if representation of the first mantissa
53 bit is explicit). */
54 for (j = 0; j < NWORDS; j++)
55 ored_words[j] &= ~anded_words[j];
56 /* Now find the nonzero word. */
57 for (j = 0; j < NWORDS; j++)
58 if (ored_words[j] != 0)
59 break;
60 if (j < NWORDS)
61 {
62 size_t i;
63 for (i = j + 1; i < NWORDS; i++)
64 if (ored_words[i] != 0)
65 {
66 fprintf (fp, "unknown");
67 return (fclose (fp) != 0);
68 }
69 for (i = 0; ; i++)
70 if ((ored_words[j] >> i) & 1)
71 {
72 fprintf (fp, "word %d bit %d", (int) j, (int) i);
73 return (fclose (fp) != 0);
74 }
75 }
76 fprintf (fp, "unknown");
77 return (fclose (fp) != 0);
78 }
79 ]])],
80 [gl_cv_cc_long_double_expbit0=`cat conftest.out`],
81 [gl_cv_cc_long_double_expbit0="unknown"],
82 [
83 dnl When cross-compiling, in general we don't know. It depends on the
84 dnl ABI and compiler version. But we know the results for specific
85 dnl CPUs.
86 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
87 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
88 gl_DOUBLE_EXPONENT_LOCATION
89 gl_cv_cc_long_double_expbit0="$gl_cv_cc_double_expbit0"
90 if test "$gl_cv_cc_double_expbit0" = unknown; then
91 case "$host_cpu" in
92 arm*)
93 # See the comments in exponentd.m4.
94 ;;
95 aarch64 | sh4)
96 # little-endian IEEE 754 double-precision
97 gl_cv_cc_long_double_expbit0='word 1 bit 20'
98 ;;
99 hppa*)
100 # big-endian IEEE 754 double-precision
101 gl_cv_cc_long_double_expbit0='word 0 bit 20'
102 ;;
103 mips*)
104 AC_COMPILE_IFELSE(
105 [AC_LANG_PROGRAM([[
106 #if defined _MIPSEB /* equivalent: __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ */
107 int big;
108 #else
109 #error little
110 #endif
111 ]], [[]])
112 ],
113 [# big-endian IEEE 754 double-precision
114 gl_cv_cc_long_double_expbit0='word 0 bit 20'
115 ],
116 [# little-endian IEEE 754 double-precision
117 gl_cv_cc_long_double_expbit0='word 1 bit 20'
118 ])
119 ;;
120 esac
121 fi
122 else
123 case "$host_cpu" in
124 changequote(,)dnl
125 i[34567]86 | x86_64 | ia64*)
126 changequote([,])dnl
127 # 80-bits "extended precision"
128 gl_cv_cc_long_double_expbit0='word 2 bit 0'
129 ;;
130 m68k*)
131 # big-endian, 80-bits padded to 96 bits, non-IEEE exponent
132 gl_cv_cc_long_double_expbit0='word 0 bit 16'
133 ;;
134 alpha* | aarch64 | loongarch64 | riscv32 | riscv64 | sh4)
135 # little-endian IEEE 754 quadruple-precision
136 gl_cv_cc_long_double_expbit0='word 3 bit 16'
137 ;;
138 s390* | sparc | sparc64)
139 # big-endian IEEE 754 quadruple-precision
140 gl_cv_cc_long_double_expbit0='word 0 bit 16'
141 ;;
142 arm*)
143 AC_COMPILE_IFELSE(
144 [AC_LANG_PROGRAM([[
145 #if defined _ARMEL
146 int little;
147 #else
148 #error big
149 #endif
150 ]], [[]])
151 ],
152 [# little-endian IEEE 754 quadruple-precision
153 gl_cv_cc_long_double_expbit0='word 3 bit 16'
154 ],
155 [# big-endian IEEE 754 quadruple-precision
156 gl_cv_cc_long_double_expbit0='word 0 bit 16'
157 ])
158 ;;
159 mips*)
160 AC_COMPILE_IFELSE(
161 [AC_LANG_PROGRAM([[
162 #if defined _MIPSEB /* equivalent: __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ */
163 int big;
164 #else
165 #error little
166 #endif
167 ]], [[]])
168 ],
169 [# big-endian IEEE 754 quadruple-precision
170 gl_cv_cc_long_double_expbit0='word 0 bit 16'
171 ],
172 [# little-endian IEEE 754 quadruple-precision
173 gl_cv_cc_long_double_expbit0='word 3 bit 16'
174 ])
175 ;;
176 powerpc64le)
177 # little-endian double-double
178 gl_cv_cc_long_double_expbit0='word 1 bit 20'
179 ;;
180 powerpc* | rs6000)
181 # big-endian double-double
182 gl_cv_cc_long_double_expbit0='word 0 bit 20'
183 ;;
184 *)
185 gl_cv_cc_long_double_expbit0="unknown"
186 ;;
187 esac
188 fi
189 ])
190 rm -f conftest.out
191 ])
192 case "$gl_cv_cc_long_double_expbit0" in
193 word*bit*)
194 word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
195 bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
196 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
197 [Define as the word index where to find the exponent of 'long double'.])
198 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
199 [Define as the bit index in the word where to find bit 0 of the exponent of 'long double'.])
200 ;;
201 esac
202 ])