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