annotate m4/exponentd.m4 @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16358
a712776b11ce maint: spelling fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
1 # exponentd.m4 serial 3
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 dnl Copyright (C) 2007-2008, 2010-2019 Free Software Foundation, Inc.
10286
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
6 AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
7 [
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
8 AC_CACHE_CHECK([where to find the exponent in a 'double'],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
9 [gl_cv_cc_double_expbit0],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
10 [
13579
da9779900713 Modernize AC_TRY_RUN invocations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
11 AC_RUN_IFELSE(
da9779900713 Modernize AC_TRY_RUN invocations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
12 [AC_LANG_SOURCE([[
10286
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
13 #include <float.h>
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
14 #include <stddef.h>
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
15 #include <stdio.h>
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
16 #include <string.h>
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
17 #define NWORDS \
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
18 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
19 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
20 static unsigned int ored_words[NWORDS];
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
21 static unsigned int anded_words[NWORDS];
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
22 static void add_to_ored_words (double x)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
23 {
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
24 memory_double m;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
25 size_t i;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
26 /* Clear it first, in case sizeof (double) < sizeof (memory_double). */
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
27 memset (&m, 0, sizeof (memory_double));
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
28 m.value = x;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
29 for (i = 0; i < NWORDS; i++)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
30 {
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
31 ored_words[i] |= m.word[i];
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
32 anded_words[i] &= m.word[i];
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
33 }
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
34 }
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
35 int main ()
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
36 {
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
37 size_t j;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
38 FILE *fp = fopen ("conftest.out", "w");
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
39 if (fp == NULL)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
40 return 1;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
41 for (j = 0; j < NWORDS; j++)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
42 anded_words[j] = ~ (unsigned int) 0;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
43 add_to_ored_words (0.25);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
44 add_to_ored_words (0.5);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
45 add_to_ored_words (1.0);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
46 add_to_ored_words (2.0);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
47 add_to_ored_words (4.0);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
48 /* Remove bits that are common (e.g. if representation of the first mantissa
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
49 bit is explicit). */
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
50 for (j = 0; j < NWORDS; j++)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
51 ored_words[j] &= ~anded_words[j];
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
52 /* Now find the nonzero word. */
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
53 for (j = 0; j < NWORDS; j++)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
54 if (ored_words[j] != 0)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
55 break;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
56 if (j < NWORDS)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
57 {
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
58 size_t i;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
59 for (i = j + 1; i < NWORDS; i++)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
60 if (ored_words[i] != 0)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
61 {
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
62 fprintf (fp, "unknown");
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
63 return (fclose (fp) != 0);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
64 }
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
65 for (i = 0; ; i++)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
66 if ((ored_words[j] >> i) & 1)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
67 {
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
68 fprintf (fp, "word %d bit %d", (int) j, (int) i);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
69 return (fclose (fp) != 0);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
70 }
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
71 }
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
72 fprintf (fp, "unknown");
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
73 return (fclose (fp) != 0);
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
74 }
13579
da9779900713 Modernize AC_TRY_RUN invocations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
75 ]])],
10286
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
76 [gl_cv_cc_double_expbit0=`cat conftest.out`],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
77 [gl_cv_cc_double_expbit0="unknown"],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
78 [
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
79 dnl On ARM, there are two 'double' floating-point formats, used by
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
80 dnl different sets of instructions: The older FPA instructions assume
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
81 dnl that they are stored in big-endian word order, while the words
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
82 dnl (like integer types) are stored in little-endian byte order.
16358
a712776b11ce maint: spelling fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
83 dnl The newer VFP instructions assume little-endian order
a712776b11ce maint: spelling fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
84 dnl consistently.
10286
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
85 AC_EGREP_CPP([mixed_endianness], [
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
86 #if defined arm || defined __arm || defined __arm__
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
87 mixed_endianness
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
88 #endif
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
89 ],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
90 [gl_cv_cc_double_expbit0="unknown"],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
91 [
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
92 pushdef([AC_MSG_CHECKING],[:])dnl
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
93 pushdef([AC_MSG_RESULT],[:])dnl
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
94 pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
95 AC_C_BIGENDIAN(
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
96 [gl_cv_cc_double_expbit0="word 0 bit 20"],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
97 [gl_cv_cc_double_expbit0="word 1 bit 20"],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
98 [gl_cv_cc_double_expbit0="unknown"])
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
99 popdef([AC_MSG_RESULT_UNQUOTED])dnl
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
100 popdef([AC_MSG_RESULT])dnl
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
101 popdef([AC_MSG_CHECKING])dnl
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
102 ])
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
103 ])
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
104 rm -f conftest.out
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
105 ])
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
106 case "$gl_cv_cc_double_expbit0" in
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
107 word*bit*)
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
108 word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
109 bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
110 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
111 [Define as the word index where to find the exponent of 'double'.])
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
112 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
113 [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
114 ;;
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
115 esac
12944217dba7 Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
116 ])