Mercurial > hg > octave-nkf
annotate liboctave/mach-info.cc @ 15283:a95432e7309c stable release-3-6-3
Version 3.6.3 released.
* configure.ac (AC_INIT): Version is now 3.6.3.
(OCTAVE_RELEASE_DATE): Now 2012-09-04.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 04 Sep 2012 13:17:13 -0400 |
parents | 72c96de7a403 |
children | aa490c112c88 |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 1996-2012 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1960 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1960 | 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" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 #include "singleton-cleanup.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 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
73 static oct_mach_info::float_format |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
74 get_float_format (void) |
1960 | 75 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
76 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
77 |
4605 | 78 #if defined (CRAY) |
79 | |
5775 | 80 // FIXME -- this should be determined automatically. |
4605 | 81 |
82 native_float_fmt = oct_mach_info::flt_fmt_cray; | |
83 | |
84 #else | |
85 | |
1960 | 86 float_params fp[5]; |
87 | |
4574 | 88 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
|
89 1048576, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 2146435071, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 1017118720, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 1018167296, 0); |
1960 | 93 |
4574 | 94 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
|
95 0, 1048576, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 -1, 2146435071, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 0, 1017118720, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 0, 1018167296); |
1960 | 99 |
4574 | 100 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
|
101 128, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 -32769, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 9344, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 9344, 0); |
1960 | 105 |
4574 | 106 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
|
107 16, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
108 -32769, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
109 15552, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
110 15552, 0); |
1960 | 111 |
4574 | 112 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
|
113 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
114 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
116 0, 0); |
1960 | 117 |
118 equiv mach_fp_par[4]; | |
119 | |
3887 | 120 mach_fp_par[0].d = F77_FUNC (d1mach, D1MACH) (1); |
121 mach_fp_par[1].d = F77_FUNC (d1mach, D1MACH) (2); | |
122 mach_fp_par[2].d = F77_FUNC (d1mach, D1MACH) (3); | |
123 mach_fp_par[3].d = F77_FUNC (d1mach, D1MACH) (4); | |
1960 | 124 |
125 int i = 0; | |
126 do | |
127 { | |
128 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
|
129 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
130 retval = fp[i].fp_fmt; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
132 } |
1960 | 133 } |
4574 | 134 while (fp[++i].fp_fmt != oct_mach_info::flt_fmt_unknown); |
4605 | 135 |
136 #endif | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
137 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
138 return retval; |
2317 | 139 } |
140 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
141 static bool |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
142 ten_little_endians (void) |
2317 | 143 { |
144 // Are we little or big endian? From Harbison & Steele. | |
145 | |
146 union | |
147 { | |
148 long l; | |
149 char c[sizeof (long)]; | |
150 } u; | |
151 | |
152 u.l = 1; | |
153 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
154 return (u.c[sizeof (long) - 1] == 1); |
2317 | 155 } |
156 | |
157 oct_mach_info::oct_mach_info (void) | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
158 : native_float_fmt (get_float_format ()), |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
159 big_chief (ten_little_endians ()) { } |
2317 | 160 |
2926 | 161 bool |
162 oct_mach_info::instance_ok (void) | |
163 { | |
164 bool retval = true; | |
165 | |
166 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
167 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
168 instance = new oct_mach_info (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
169 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
170 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
171 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
172 } |
2926 | 173 |
174 if (! instance) | |
175 { | |
176 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
177 ("unable to create command history object!"); |
2926 | 178 |
179 retval = false; | |
180 } | |
181 | |
182 return retval; | |
183 } | |
184 | |
2317 | 185 oct_mach_info::float_format |
186 oct_mach_info::native_float_format (void) | |
187 { | |
2926 | 188 return (instance_ok ()) |
4574 | 189 ? instance->native_float_fmt : oct_mach_info::flt_fmt_unknown; |
2317 | 190 } |
191 | |
192 bool | |
193 oct_mach_info::words_big_endian (void) | |
194 { | |
2926 | 195 return (instance_ok ()) |
196 ? instance->big_chief : false; | |
2317 | 197 } |
198 | |
199 bool | |
200 oct_mach_info::words_little_endian (void) | |
201 { | |
2926 | 202 return (instance_ok ()) |
203 ? (! instance->big_chief) : false; | |
2317 | 204 } |
205 | |
206 oct_mach_info::float_format | |
3504 | 207 oct_mach_info::string_to_float_format (const std::string& s) |
2317 | 208 { |
4574 | 209 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
1960 | 210 |
2317 | 211 if (s == "native" || s == "n") |
5015 | 212 retval = oct_mach_info::native_float_format (); |
2317 | 213 else if (s == "ieee-be" || s == "b") |
4574 | 214 retval = oct_mach_info::flt_fmt_ieee_big_endian; |
2317 | 215 else if (s == "ieee-le" || s == "l") |
4574 | 216 retval = oct_mach_info::flt_fmt_ieee_little_endian; |
2317 | 217 else if (s == "vaxd" || s == "d") |
4574 | 218 retval = oct_mach_info::flt_fmt_vax_d; |
2759 | 219 else if (s == "vaxg" || s == "g") |
4574 | 220 retval = oct_mach_info::flt_fmt_vax_g; |
2317 | 221 else if (s == "cray" || s == "c") |
4574 | 222 retval = oct_mach_info::flt_fmt_cray; |
2317 | 223 else if (s == "unknown") |
4574 | 224 retval = oct_mach_info::flt_fmt_unknown; |
2317 | 225 else |
226 (*current_liboctave_error_handler) | |
227 ("invalid architecture type specified"); | |
228 | |
229 return retval; | |
230 } | |
231 | |
3504 | 232 std::string |
2317 | 233 oct_mach_info::float_format_as_string (float_format flt_fmt) |
234 { | |
3504 | 235 std::string retval = "unknown"; |
2317 | 236 |
237 switch (flt_fmt) | |
238 { | |
4574 | 239 case flt_fmt_ieee_big_endian: |
2317 | 240 retval = "ieee_big_endian"; |
241 break; | |
242 | |
4574 | 243 case flt_fmt_ieee_little_endian: |
2317 | 244 retval = "ieee_little_endian"; |
245 break; | |
246 | |
4574 | 247 case flt_fmt_vax_d: |
2317 | 248 retval = "vax_d_float"; |
249 break; | |
250 | |
4574 | 251 case flt_fmt_vax_g: |
2317 | 252 retval = "vax_g_float"; |
253 break; | |
254 | |
4574 | 255 case flt_fmt_cray: |
2317 | 256 retval = "cray"; |
257 break; | |
258 | |
259 default: | |
260 break; | |
261 } | |
262 | |
263 return retval; | |
1960 | 264 } |