annotate m4/exponentl.m4 @ 29977:2bffa79ac8ee

Move macros for finding floating-point exponents into separate M4 files.
author Ben Pfaff <blp@cs.stanford.edu>
date Wed, 23 Jul 2008 21:34:48 -0700
parents
children 90ea94356c75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29977
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
1 # exponentl.m4 serial 1
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
2 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
2bffa79ac8ee 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
2bffa79ac8ee 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,
2bffa79ac8ee 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.
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
6 AC_DEFUN([gl_LONG_DOUBLE_EXPONENT_LOCATION],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
7 [
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
8 AC_REQUIRE([AC_C_BIGENDIAN])
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
9 AC_CACHE_CHECK([where to find the exponent in a 'long double'],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
10 [gl_cv_cc_long_double_expbit0],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
11 [
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
12 AC_TRY_RUN([
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
13 #include <float.h>
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
14 #include <stddef.h>
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
15 #include <stdio.h>
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
16 #include <string.h>
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
17 #define NWORDS \
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
18 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
19 typedef union { long double value; unsigned int word[NWORDS]; }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
20 memory_long_double;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
21 static unsigned int ored_words[NWORDS];
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
22 static unsigned int anded_words[NWORDS];
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
23 static void add_to_ored_words (long double x)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
24 {
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
25 memory_long_double m;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
26 size_t i;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
27 /* Clear it first, in case
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
28 sizeof (long double) < sizeof (memory_long_double). */
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
29 memset (&m, 0, sizeof (memory_long_double));
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
30 m.value = x;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
31 for (i = 0; i < NWORDS; i++)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
32 {
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
33 ored_words[i] |= m.word[i];
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
34 anded_words[i] &= m.word[i];
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
35 }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
36 }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
37 int main ()
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
38 {
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
39 size_t j;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
40 FILE *fp = fopen ("conftest.out", "w");
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
41 if (fp == NULL)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
42 return 1;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
43 for (j = 0; j < NWORDS; j++)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
44 anded_words[j] = ~ (unsigned int) 0;
2bffa79ac8ee 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 (0.25L);
2bffa79ac8ee 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 (0.5L);
2bffa79ac8ee 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 (1.0L);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
48 add_to_ored_words (2.0L);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
49 add_to_ored_words (4.0L);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
50 /* Remove bits that are common (e.g. if representation of the first mantissa
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
51 bit is explicit). */
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
52 for (j = 0; j < NWORDS; j++)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
53 ored_words[j] &= ~anded_words[j];
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
54 /* Now find the nonzero word. */
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
55 for (j = 0; j < NWORDS; j++)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
56 if (ored_words[j] != 0)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
57 break;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
58 if (j < NWORDS)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
59 {
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
60 size_t i;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
61 for (i = j + 1; i < NWORDS; i++)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
62 if (ored_words[i] != 0)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
63 {
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
64 fprintf (fp, "unknown");
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
65 return (fclose (fp) != 0);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
66 }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
67 for (i = 0; ; i++)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
68 if ((ored_words[j] >> i) & 1)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
69 {
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
70 fprintf (fp, "word %d bit %d", (int) j, (int) i);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
71 return (fclose (fp) != 0);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
72 }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
73 }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
74 fprintf (fp, "unknown");
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
75 return (fclose (fp) != 0);
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
76 }
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
77 ],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
78 [gl_cv_cc_long_double_expbit0=`cat conftest.out`],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
79 [gl_cv_cc_long_double_expbit0="unknown"],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
80 [
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
81 dnl When cross-compiling, we don't know. It depends on the
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
82 dnl ABI and compiler version. There are too many cases.
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
83 gl_cv_cc_long_double_expbit0="unknown"
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
84 ])
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
85 rm -f conftest.out
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
86 ])
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
87 case "$gl_cv_cc_long_double_expbit0" in
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
88 word*bit*)
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
89 word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
90 bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
91 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
92 [Define as the word index where to find the exponent of 'long double'.])
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
93 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
94 [Define as the bit index in the word where to find bit 0 of the exponent of 'long double'.])
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
95 ;;
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
96 esac
2bffa79ac8ee Move macros for finding floating-point exponents into separate M4 files.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
97 ])