Mercurial > hg > octave-nkf
annotate liboctave/system/mach-info.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 1996-2015 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 |
1960 | 78 float_params fp[5]; |
79 | |
4574 | 80 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
|
81 1048576, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
82 2146435071, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 1017118720, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 1018167296, 0); |
1960 | 85 |
4574 | 86 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
|
87 0, 1048576, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 -1, 2146435071, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 0, 1017118720, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 0, 1018167296); |
1960 | 91 |
4574 | 92 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
|
93 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
94 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 0, 0); |
1960 | 97 |
98 equiv mach_fp_par[4]; | |
99 | |
3887 | 100 mach_fp_par[0].d = F77_FUNC (d1mach, D1MACH) (1); |
101 mach_fp_par[1].d = F77_FUNC (d1mach, D1MACH) (2); | |
102 mach_fp_par[2].d = F77_FUNC (d1mach, D1MACH) (3); | |
103 mach_fp_par[3].d = F77_FUNC (d1mach, D1MACH) (4); | |
1960 | 104 |
105 int i = 0; | |
106 do | |
107 { | |
108 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
|
109 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
110 retval = fp[i].fp_fmt; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
111 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
112 } |
1960 | 113 } |
4574 | 114 while (fp[++i].fp_fmt != oct_mach_info::flt_fmt_unknown); |
4605 | 115 |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
116 return retval; |
2317 | 117 } |
118 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
119 static bool |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
120 ten_little_endians (void) |
2317 | 121 { |
122 // Are we little or big endian? From Harbison & Steele. | |
123 | |
124 union | |
125 { | |
126 long l; | |
127 char c[sizeof (long)]; | |
128 } u; | |
129 | |
130 u.l = 1; | |
131 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
132 return (u.c[sizeof (long) - 1] == 1); |
2317 | 133 } |
134 | |
135 oct_mach_info::oct_mach_info (void) | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
136 : native_float_fmt (get_float_format ()), |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
137 big_chief (ten_little_endians ()) { } |
2317 | 138 |
2926 | 139 bool |
140 oct_mach_info::instance_ok (void) | |
141 { | |
142 bool retval = true; | |
143 | |
144 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
145 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
146 instance = new oct_mach_info (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
147 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
148 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
149 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
|
150 } |
2926 | 151 |
152 if (! instance) | |
153 { | |
154 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
155 ("unable to create command history object!"); |
2926 | 156 |
157 retval = false; | |
158 } | |
159 | |
160 return retval; | |
161 } | |
162 | |
2317 | 163 oct_mach_info::float_format |
164 oct_mach_info::native_float_format (void) | |
165 { | |
2926 | 166 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
167 ? instance->native_float_fmt : oct_mach_info::flt_fmt_unknown; |
2317 | 168 } |
169 | |
170 bool | |
171 oct_mach_info::words_big_endian (void) | |
172 { | |
2926 | 173 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
174 ? instance->big_chief : false; |
2317 | 175 } |
176 | |
177 bool | |
178 oct_mach_info::words_little_endian (void) | |
179 { | |
2926 | 180 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
181 ? (! instance->big_chief) : false; |
2317 | 182 } |
183 | |
184 oct_mach_info::float_format | |
3504 | 185 oct_mach_info::string_to_float_format (const std::string& s) |
2317 | 186 { |
4574 | 187 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
1960 | 188 |
2317 | 189 if (s == "native" || s == "n") |
5015 | 190 retval = oct_mach_info::native_float_format (); |
2317 | 191 else if (s == "ieee-be" || s == "b") |
4574 | 192 retval = oct_mach_info::flt_fmt_ieee_big_endian; |
2317 | 193 else if (s == "ieee-le" || s == "l") |
4574 | 194 retval = oct_mach_info::flt_fmt_ieee_little_endian; |
2317 | 195 else if (s == "unknown") |
4574 | 196 retval = oct_mach_info::flt_fmt_unknown; |
2317 | 197 else |
198 (*current_liboctave_error_handler) | |
199 ("invalid architecture type specified"); | |
200 | |
201 return retval; | |
202 } | |
203 | |
3504 | 204 std::string |
2317 | 205 oct_mach_info::float_format_as_string (float_format flt_fmt) |
206 { | |
3504 | 207 std::string retval = "unknown"; |
2317 | 208 |
209 switch (flt_fmt) | |
210 { | |
4574 | 211 case flt_fmt_ieee_big_endian: |
14488
aa490c112c88
Normalize floating point format string conversions
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
212 retval = "ieee-be"; |
2317 | 213 break; |
214 | |
4574 | 215 case flt_fmt_ieee_little_endian: |
14488
aa490c112c88
Normalize floating point format string conversions
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
216 retval = "ieee-le"; |
2317 | 217 break; |
218 | |
219 default: | |
220 break; | |
221 } | |
222 | |
223 return retval; | |
1960 | 224 } |