1960
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1960
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "f77-fcn.h" |
2317
|
28 #include "lo-error.h" |
|
29 #include "mach-info.h" |
1960
|
30 |
|
31 extern "C" |
|
32 { |
3887
|
33 double F77_FUNC (d1mach, D1MACH) (const int&); |
1960
|
34 } |
|
35 |
2317
|
36 oct_mach_info *oct_mach_info::instance = 0; |
1960
|
37 |
|
38 union equiv |
|
39 { |
|
40 double d; |
|
41 int i[2]; |
|
42 }; |
|
43 |
|
44 struct |
|
45 float_params |
|
46 { |
2317
|
47 oct_mach_info::float_format fp_fmt; |
1960
|
48 equiv fp_par[4]; |
|
49 }; |
|
50 |
|
51 #define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2) \ |
|
52 do \ |
|
53 { \ |
|
54 fp.fp_fmt = (fmt); \ |
|
55 fp.fp_par[0].i[0] = (sm1); fp.fp_par[0].i[1] = (sm2); \ |
|
56 fp.fp_par[1].i[0] = (lrg1); fp.fp_par[1].i[1] = (lrg2); \ |
|
57 fp.fp_par[2].i[0] = (rt1); fp.fp_par[2].i[1] = (rt2); \ |
|
58 fp.fp_par[3].i[0] = (dv1); fp.fp_par[3].i[1] = (dv2); \ |
|
59 } \ |
|
60 while (0) |
|
61 |
|
62 static int |
|
63 equiv_compare (const equiv *std, const equiv *v, int len) |
|
64 { |
|
65 int i; |
|
66 for (i = 0; i < len; i++) |
|
67 if (v[i].i[0] != std[i].i[0] || v[i].i[1] != std[i].i[1]) |
|
68 return 0; |
|
69 return 1; |
|
70 } |
|
71 |
2317
|
72 void |
2926
|
73 oct_mach_info::init_float_format (void) const |
1960
|
74 { |
4605
|
75 #if defined (CRAY) |
|
76 |
|
77 // XXX FIXME XXX -- this should be determined automatically. |
|
78 |
|
79 native_float_fmt = oct_mach_info::flt_fmt_cray; |
|
80 |
|
81 #else |
|
82 |
1960
|
83 float_params fp[5]; |
|
84 |
4574
|
85 INIT_FLT_PAR (fp[0], oct_mach_info::flt_fmt_ieee_big_endian, |
1960
|
86 1048576, 0, |
|
87 2146435071, -1, |
|
88 1017118720, 0, |
|
89 1018167296, 0); |
|
90 |
4574
|
91 INIT_FLT_PAR (fp[1], oct_mach_info::flt_fmt_ieee_little_endian, |
1960
|
92 0, 1048576, |
|
93 -1, 2146435071, |
|
94 0, 1017118720, |
|
95 0, 1018167296); |
|
96 |
4574
|
97 INIT_FLT_PAR (fp[2], oct_mach_info::flt_fmt_vax_d, |
1960
|
98 128, 0, |
|
99 -32769, -1, |
|
100 9344, 0, |
|
101 9344, 0); |
|
102 |
4574
|
103 INIT_FLT_PAR (fp[3], oct_mach_info::flt_fmt_vax_g, |
1960
|
104 16, 0, |
|
105 -32769, -1, |
|
106 15552, 0, |
|
107 15552, 0); |
|
108 |
4574
|
109 INIT_FLT_PAR (fp[4], oct_mach_info::flt_fmt_unknown, |
1960
|
110 0, 0, |
|
111 0, 0, |
|
112 0, 0, |
|
113 0, 0); |
|
114 |
|
115 equiv mach_fp_par[4]; |
|
116 |
3887
|
117 mach_fp_par[0].d = F77_FUNC (d1mach, D1MACH) (1); |
|
118 mach_fp_par[1].d = F77_FUNC (d1mach, D1MACH) (2); |
|
119 mach_fp_par[2].d = F77_FUNC (d1mach, D1MACH) (3); |
|
120 mach_fp_par[3].d = F77_FUNC (d1mach, D1MACH) (4); |
1960
|
121 |
|
122 int i = 0; |
|
123 do |
|
124 { |
|
125 if (equiv_compare (fp[i].fp_par, mach_fp_par, 4)) |
|
126 { |
2317
|
127 native_float_fmt = fp[i].fp_fmt; |
1960
|
128 break; |
|
129 } |
|
130 } |
4574
|
131 while (fp[++i].fp_fmt != oct_mach_info::flt_fmt_unknown); |
4605
|
132 |
|
133 #endif |
2317
|
134 } |
|
135 |
|
136 void |
2926
|
137 oct_mach_info::ten_little_endians (void) const |
2317
|
138 { |
|
139 // Are we little or big endian? From Harbison & Steele. |
|
140 |
|
141 union |
|
142 { |
|
143 long l; |
|
144 char c[sizeof (long)]; |
|
145 } u; |
|
146 |
|
147 u.l = 1; |
|
148 |
|
149 big_chief = (u.c[sizeof (long) - 1] == 1); |
|
150 } |
|
151 |
|
152 oct_mach_info::oct_mach_info (void) |
|
153 { |
|
154 init_float_format (); |
|
155 ten_little_endians (); |
|
156 } |
|
157 |
2926
|
158 bool |
|
159 oct_mach_info::instance_ok (void) |
|
160 { |
|
161 bool retval = true; |
|
162 |
|
163 if (! instance) |
|
164 instance = new oct_mach_info (); |
|
165 |
|
166 if (! instance) |
|
167 { |
|
168 (*current_liboctave_error_handler) |
|
169 ("unable to create command history object!"); |
|
170 |
|
171 retval = false; |
|
172 } |
|
173 |
|
174 return retval; |
|
175 } |
|
176 |
2317
|
177 oct_mach_info::float_format |
|
178 oct_mach_info::native_float_format (void) |
|
179 { |
2926
|
180 return (instance_ok ()) |
4574
|
181 ? instance->native_float_fmt : oct_mach_info::flt_fmt_unknown; |
2317
|
182 } |
|
183 |
|
184 bool |
|
185 oct_mach_info::words_big_endian (void) |
|
186 { |
2926
|
187 return (instance_ok ()) |
|
188 ? instance->big_chief : false; |
2317
|
189 } |
|
190 |
|
191 bool |
|
192 oct_mach_info::words_little_endian (void) |
|
193 { |
2926
|
194 return (instance_ok ()) |
|
195 ? (! instance->big_chief) : false; |
2317
|
196 } |
|
197 |
|
198 oct_mach_info::float_format |
3504
|
199 oct_mach_info::string_to_float_format (const std::string& s) |
2317
|
200 { |
4574
|
201 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
1960
|
202 |
2317
|
203 if (s == "native" || s == "n") |
5015
|
204 retval = oct_mach_info::native_float_format (); |
2317
|
205 else if (s == "ieee-be" || s == "b") |
4574
|
206 retval = oct_mach_info::flt_fmt_ieee_big_endian; |
2317
|
207 else if (s == "ieee-le" || s == "l") |
4574
|
208 retval = oct_mach_info::flt_fmt_ieee_little_endian; |
2317
|
209 else if (s == "vaxd" || s == "d") |
4574
|
210 retval = oct_mach_info::flt_fmt_vax_d; |
2759
|
211 else if (s == "vaxg" || s == "g") |
4574
|
212 retval = oct_mach_info::flt_fmt_vax_g; |
2317
|
213 else if (s == "cray" || s == "c") |
4574
|
214 retval = oct_mach_info::flt_fmt_cray; |
2317
|
215 else if (s == "unknown") |
4574
|
216 retval = oct_mach_info::flt_fmt_unknown; |
2317
|
217 else |
|
218 (*current_liboctave_error_handler) |
|
219 ("invalid architecture type specified"); |
|
220 |
|
221 return retval; |
|
222 } |
|
223 |
3504
|
224 std::string |
2317
|
225 oct_mach_info::float_format_as_string (float_format flt_fmt) |
|
226 { |
3504
|
227 std::string retval = "unknown"; |
2317
|
228 |
|
229 switch (flt_fmt) |
|
230 { |
4574
|
231 case flt_fmt_ieee_big_endian: |
2317
|
232 retval = "ieee_big_endian"; |
|
233 break; |
|
234 |
4574
|
235 case flt_fmt_ieee_little_endian: |
2317
|
236 retval = "ieee_little_endian"; |
|
237 break; |
|
238 |
4574
|
239 case flt_fmt_vax_d: |
2317
|
240 retval = "vax_d_float"; |
|
241 break; |
|
242 |
4574
|
243 case flt_fmt_vax_g: |
2317
|
244 retval = "vax_g_float"; |
|
245 break; |
|
246 |
4574
|
247 case flt_fmt_cray: |
2317
|
248 retval = "cray"; |
|
249 break; |
|
250 |
|
251 default: |
|
252 break; |
|
253 } |
|
254 |
|
255 return retval; |
1960
|
256 } |
|
257 |
|
258 /* |
|
259 ;;; Local Variables: *** |
|
260 ;;; mode: C++ *** |
|
261 ;;; End: *** |
|
262 */ |