master
1/****************************************************************
2Copyright (C) 1997, 1998 Lucent Technologies
3All Rights Reserved
4
5Permission to use, copy, modify, and distribute this software and
6its documentation for any purpose and without fee is hereby
7granted, provided that the above copyright notice appear in all
8copies and that both that the copyright notice and this
9permission notice and warranty disclaimer appear in supporting
10documentation, and that the name of Lucent or any of its entities
11not be used in advertising or publicity pertaining to
12distribution of the software without specific, written prior
13permission.
14
15LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22THIS SOFTWARE.
23****************************************************************/
24
25/* Try to deduce arith.h from arithmetic properties. */
26#ifdef MINGW_BUILD_GEN
27
28#include <stdio.h>
29
30 static int dalign;
31 typedef struct
32Akind {
33 char *name;
34 int kind;
35 } Akind;
36
37 static Akind
38IEEE_8087 = { "IEEE_8087", 1 },
39IEEE_MC68k = { "IEEE_MC68k", 2 },
40IBM = { "IBM", 3 },
41VAX = { "VAX", 4 },
42CRAY = { "CRAY", 5};
43
44 static Akind *
45Lcheck(void)
46{
47 union {
48 double d;
49 long L[2];
50 } u;
51 struct {
52 double d;
53 long L;
54 } x[2];
55
56 if (sizeof(x) > 2*(sizeof(double) + sizeof(long)))
57 dalign = 1;
58 u.L[0] = u.L[1] = 0;
59 u.d = 1e13;
60 if (u.L[0] == 1117925532 && u.L[1] == -448790528)
61 return &IEEE_MC68k;
62 if (u.L[1] == 1117925532 && u.L[0] == -448790528)
63 return &IEEE_8087;
64 if (u.L[0] == -2065213935 && u.L[1] == 10752)
65 return &VAX;
66 if (u.L[0] == 1267827943 && u.L[1] == 704643072)
67 return &IBM;
68 return 0;
69 }
70
71 static Akind *
72icheck(void)
73{
74 union {
75 double d;
76 int L[2];
77 } u;
78 struct {
79 double d;
80 int L;
81 } x[2];
82
83 if (sizeof(x) > 2*(sizeof(double) + sizeof(int)))
84 dalign = 1;
85 u.L[0] = u.L[1] = 0;
86 u.d = 1e13;
87 if (u.L[0] == 1117925532 && u.L[1] == -448790528)
88 return &IEEE_MC68k;
89 if (u.L[1] == 1117925532 && u.L[0] == -448790528)
90 return &IEEE_8087;
91 if (u.L[0] == -2065213935 && u.L[1] == 10752)
92 return &VAX;
93 if (u.L[0] == 1267827943 && u.L[1] == 704643072)
94 return &IBM;
95 return 0;
96 }
97
98 static Akind *
99ccheck(int ac, char **av)
100{
101 union {
102 double d;
103 long L;
104 } u;
105 long Cray1;
106
107 /* Cray1 = 4617762693716115456 -- without overflow on non-Crays */
108 /* The next three tests should always be true. */
109 Cray1 = ac >= -2 ? 4617762 : 0;
110 if (ac >= -1)
111 Cray1 = 1000000*Cray1 + 693716;
112 if (av || ac >= 0)
113 Cray1 = 1000000*Cray1 + 115456;
114 u.d = 1e13;
115 if (u.L == Cray1)
116 return &CRAY;
117 return 0;
118 }
119
120 static int
121fzcheck(void)
122{
123 double a, b;
124 int i;
125
126 a = 1.;
127 b = .1;
128 for(i = 155;; b *= b, i >>= 1) {
129 if (i & 1) {
130 a *= b;
131 if (i == 1)
132 break;
133 }
134 }
135 b = a * a;
136 return b == 0.;
137 }
138
139 int
140main(int argc, char **argv)
141{
142 Akind *a = 0;
143 int Ldef = 0;
144 FILE *f;
145
146#ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */
147 f = fopen("arith.h", "w");
148 if (!f) {
149 printf("Cannot open arith.h\n");
150 return 1;
151 }
152#else
153 f = stdout;
154#endif
155
156 if (sizeof(double) == 2*sizeof(long))
157 a = Lcheck();
158 else if (sizeof(double) == 2*sizeof(int)) {
159 Ldef = 1;
160 a = icheck();
161 }
162 else if (sizeof(double) == sizeof(long))
163 a = ccheck(argc, argv);
164 if (a) {
165 fprintf(f, "#define %s\n#define Arith_Kind_ASL %d\n",
166 a->name, a->kind);
167 if (Ldef)
168 fprintf(f, "#define Long int\n#define Intcast (int)(long)\n");
169 if (dalign)
170 fprintf(f, "#define Double_Align\n");
171 if (sizeof(char*) == 8)
172 fprintf(f, "#define X64_bit_pointers\n");
173#ifndef NO_LONG_LONG
174 if (sizeof(long long) < 8)
175#endif
176 fprintf(f, "#define NO_LONG_LONG\n");
177 if (a->kind <= 2 && fzcheck())
178 fprintf(f, "#define Sudden_Underflow\n");
179 return 0;
180 }
181 fprintf(f, "/* Unknown arithmetic */\n");
182 return 1;
183 }
184#endif /* MINGW_BUILD_GEN */
185