cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cpu.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef _CPU_H_
5 #define _CPU_H_
6 
11 /* disable conditional expressions is constant */
12 #ifdef _MSC_VER
13 #pragma warning( disable : 4127 )
14 #endif
15 
17 #ifndef INT16_MAX
18 #define INT16_MAX 32767
19 #endif
20 #ifndef INT16_MIN
21 #define INT16_MIN (-INT16_MAX - 1)
22 #endif
23 
24 #if INT_MAX == INT16_MAX
25 typedef int int16;
26 #elif SHRT_MAX == INT16_MAX
27 typedef short int int16;
28 #else
29 #error failed to define int16, please report this to gary@pa.uky.edu
30 #endif
31 
32 #ifndef UINT16_MAX
33 #define UINT16_MAX 65535
34 #endif
35 
36 #if UINT_MAX == UINT16_MAX
37 typedef unsigned int uint16;
38 #elif USHRT_MAX == UINT16_MAX
39 typedef unsigned short int uint16;
40 #else
41 #error failed to define uint16, please report this to gary@pa.uky.edu
42 #endif
43 
44 #ifndef INT32_MAX
45 #define INT32_MAX 2147483647L
46 #endif
47 #ifndef INT32_MIN
48 #define INT32_MIN (-INT32_MAX - 1)
49 #endif
50 
51 #if LONG_MAX == INT32_MAX
52 typedef long int int32;
53 #elif INT_MAX == INT32_MAX
54 typedef int int32;
55 #else
56 #error failed to define int32, please report this to gary@pa.uky.edu
57 #endif
58 
59 #ifndef UINT32_MAX
60 #define UINT32_MAX 4294967295UL
61 #endif
62 
63 #if ULONG_MAX == UINT32_MAX
64 typedef unsigned long int uint32;
65 #elif UINT_MAX == UINT32_MAX
66 typedef unsigned int uint32;
67 #else
68 #error failed to define uint32, please report this to gary@pa.uky.edu
69 #endif
70 
71 #if LONG_MAX > INT32_MAX
72 
73 /* this will only be defined on LP64 systems
74  * ILP32 systems may have long long support, but that is not
75  * part of the ISO/ANSI standard, so we don't use it here... */
76 
77 /* INT64_MAX, etc, may be defined as long long, so avoid system definitions! */
78 
79 #undef INT64_MAX
80 #define INT64_MAX 9223372036854775807L
81 
82 #undef INT64_MIN
83 #define INT64_MIN (-INT64_MAX - 1L)
84 
85 #if LONG_MAX == INT64_MAX
86 #define HAVE_INT64 1
87 typedef long int int64;
88 #endif
89 
90 #endif
91 
92 #if ULONG_MAX > UINT32_MAX
93 
94 #undef UINT64_MAX
95 #define UINT64_MAX 18446744073709551615UL
96 
97 #if ULONG_MAX == UINT64_MAX
98 #define HAVE_UINT64 1
99 typedef unsigned long int uint64;
100 #endif
101 
102 #endif
103 
104 /* make sure __func__ is defined, this can be removed once C++0x is in effect */
105 #ifdef __GNUC__
106 #if __STDC_VERSION__ < 199901L
107 #if __GNUC__ >= 2
108 #define __func__ __FUNCTION__
109 #else
110 #define __func__ "<unknown>"
111 #endif
112 #endif
113 #else
114 #undef __func__
115 #define __func__ DEBUG_ENTRY.name()
116 #endif
117 
118 /* safe, small, numbers for the float and double */
121 /*FLT_MAX is 3.40e38 on wintel, so BIGFLOAT is 3.40e36 */
122 const realnum BIGFLOAT = (realnum)(FLT_MAX/100.f);
124 const realnum SMALLFLOAT = (realnum)(FLT_MIN*100.f);
125 
127 const double BIGDOUBLE = DBL_MAX/100.;
128 const double SMALLDOUBLE = DBL_MIN*100.;
129 
130 const int STDLEN = 16;
131 
141 
142 FILE* open_data( const char* fname, const char* mode, access_scheme scheme=AS_DATA_ONLY );
143 
144 /* this class is deliberately kept global so that the constructor is executed before
145  * any of the user code; this assures a correct FP environment right from the start */
146 EXTERN class t_cpu
147 {
150  union
151  {
152  char c[4];
153  int32 i;
154  } endian;
155 
157 # ifdef HAVE_INT64
158  int64 Double_SNaN_Value;
159 # else
161 # endif
162 
163 # ifdef __unix
164  struct sigaction p_action;
165  struct sigaction p_default;
166 # endif
167 
170 
176  vector<string> chSearchPath;
178 
179  void enable_traps() const;
180  static void signal_handler(int sig);
181 public:
182  t_cpu();
183 
184  bool big_endian() const { return ( endian.i == 0x12345678 ); }
185  bool little_endian() const { return ( endian.i == 0x78563412 ); }
186 
187 # ifdef __unix
188  const struct sigaction* action() const { return &p_action; }
189  const struct sigaction* deflt() const { return &p_default; }
190 # endif
191 
192  void setAssertAbort(bool val)
193  {
194  p_lgAssertAbort = val;
195 #ifdef CATCH_SIGNAL
196 # ifdef __unix
197  if( val )
198  sigaction( SIGABRT, deflt(), NULL );
199  else
200  sigaction( SIGABRT, action(), NULL );
201 # endif
202 # ifdef _MSC_VER
203  if( val )
204  signal( SIGABRT, SIG_DFL );
205  else
206  signal( SIGABRT, &signal_handler );
207 # endif
208 #endif
209  }
210  bool lgAssertAbort() const { return p_lgAssertAbort; }
211 
212  long nCPU() const { return n_avail_CPU; }
213  const char *host_name() const { return HostName; }
214  void printDataPath() const;
215 
216  friend FILE* open_data( const char* fname, const char* mode, access_scheme scheme );
217 
218  friend void set_NaN(sys_float &x);
219  friend void set_NaN(sys_float x[], long n);
220  friend void set_NaN(double &x);
221  friend void set_NaN(double x[], long n);
222 } cpu;
223 
225 void set_NaN(sys_float &x);
226 void set_NaN(sys_float x[], /* x[n] */
227  long n);
228 void set_NaN(double &x);
229 void set_NaN(double x[], /* x[n] */
230  long n);
231 
233 bool MyIsnan(sys_float &x);
234 bool MyIsnan(double &x);
235 
257 #ifdef cray
258 #ifndef __cray
259 #define __cray 1
260 #endif
261 #endif
262 
264 #ifdef __x86_64
265 #ifndef __amd64
266 #define __amd64 1
267 #endif
268 #endif
269 
270 #if defined(_ARCH_PPC) || defined(__POWERPC__) || defined(__powerpc__) || defined(PPC)
271 #ifndef __ppc__
272 #define __ppc__ 1
273 #endif
274 #endif
275 
281 #if defined(unix) || defined(__unix__)
282 #ifndef __unix
283 #define __unix 1
284 #endif
285 #endif
286 
288 #ifdef __ECC
289 #ifndef __ICC
290 #define __ICC __ECC
291 #endif
292 #endif
293 
295 #undef __GNUC_EXCL__
296 #if defined(__GNUC__) && ! ( defined(__ICC) || defined(__PATHSCALE__) )
297 #define __GNUC_EXCL__ 1
298 #endif
299 
300 /* Apply compiler directive saying that current routine does not
301  return as modifier, as in "NORETURN void MyExit() { ... }" */
302 #ifdef _MSC_VER
303 #define NORETURN __declspec(noreturn) /*@noreturn@*/
304 #elif defined(__GNUC__) || ( defined(__INTEL_COMPILER) && defined(__linux) )
305 #define NORETURN __attribute__ ((noreturn)) /*@noreturn@*/
306 #else
307 #define NORETURN /*@noreturn@*/
308 #endif
309 
310 /* Define __COMP and __COMP_VER macros for all systems */
311 /* the Intel compiler */
312 /* this needs to be before g++ since icc also sets __GNUC__ */
313 #if defined __INTEL_COMPILER
314 # define __COMP "icc"
315 # define __COMP_VER __INTEL_COMPILER
316 
317 /* PathScale EKOPath compiler */
318 /* this needs to be before g++ since pathCC also sets __GNUC__ */
319 #elif defined __PATHSCALE__
320 # define __COMP "pathCC"
321 # define __COMP_VER __PATHCC__ * 100 + __PATHCC_MINOR__ * 10 + __PATHCC_PATCHLEVEL__
322 
323 /* g++ */
324 #elif defined __GNUC__
325 # define __COMP "g++"
326 # if defined(__GNUC_PATCHLEVEL__)
327 # define __COMP_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
328 # else
329 # define __COMP_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
330 # endif
331 
332 #elif defined __PGI
333 # define __COMP "Portland Group Compiler"
334 /* this works under pgcc, but not pgCC; there doesn't seem to be an alternative... */
335 # if defined(__PGIC__)
336 # define __COMP_VER (__PGIC__ * 100 + __PGIC_MINOR__ * 10 + __PGIC_PATCHLEVEL__)
337 # else
338 # define __COMP_VER 0
339 # endif
340 
341 /* SGI MIPSpro */
342 /* this needs to be after g++, since g++ under IRIX also sets _COMPILER_VERSION */
343 #elif defined(__sgi) && defined(_COMPILER_VERSION)
344 # define __COMP "MIPSpro"
345 # define __COMP_VER _COMPILER_VERSION
346 
347 /* HP */
348 #elif defined __HP_aCC
349 # define __COMP "HP aCC"
350 # define __COMP_VER __HP_aCC
351 
352 /* DEC - this one may be broken for C++, no way to test it... */
353 #elif defined __DECC
354 # define __COMP "DEC CC"
355 # define __COMP_VER __DECC_VER
356 
357 /* MS VS */
358 #elif defined _MSC_VER
359 # define __COMP "vs"
360 # define __COMP_VER _MSC_VER
361 
362 /* Sun */
363 #elif defined __SUNPRO_CC
364 # define __COMP "Sun Workshop"
365 # define __COMP_VER __SUNPRO_CC
366 
367 /* unknown */
368 #else
369 #define __COMP "unknown"
370 #define __COMP_VER 0
371 #endif
372 
373 /* ---------------------------- OS ---------------------------- */
374 /* linux */
375 #if defined __linux
376 # if defined __i386
377 # define __OS "Linux (IA32)"
378 # elif defined __amd64
379 # define __OS "Linux (AMD64)"
380 # elif defined __ia64
381 # define __OS "Linux (IA64)"
382 # elif defined __ppc__
383 # define __OS "Linux (PowerPC)"
384 # else
385 # define __OS "Linux (other)"
386 # endif
387 
388 /* macintosh */
389 #elif defined macintosh
390 # define __OS "Mac OS 9"
391 
392 /* macintosh */
393 #elif defined __MACOSX__
394 # define __OS "Mac OS X"
395 
396 /* apple mac, ... */
397 #elif defined __APPLE__
398 # define __OS "Apple MacOS"
399 
400 /* HP */
401 #elif defined hpux
402 # define __OS "HP-UX"
403 
404 /* Sun */
405 #elif defined __sun
406 # define __OS "Solaris"
407 
408 /* IBM AIX */
409 #elif defined _AIX
410 # define __OS "AIX"
411 
412 /* Compaq alpha */
413 #elif defined ultrix
414 # define __OS "Ultrix"
415 
416 /* the BSD variants */
417 #elif defined __FreeBSD__
418 # define __OS "FreeBSD"
419 
420 #elif defined __NetBSD__
421 # define __OS "NetBSD"
422 
423 #elif defined __OpenBSD__
424 # define __OS "OpenBSD"
425 
426 /* Windows64 */
427 /* this needs to be before _WIN32 since Windows64 also sets _WIN32 */
428 #elif defined _WIN64
429 # define __OS "Win64"
430 
431 /* Windows */
432 #elif defined _WIN32
433 # define __OS "Win32"
434 
435 /* Cygwin */
436 #elif defined __CYGWIN__
437 # define __OS "Cygwin"
438 
439 /* SGI */
440 #elif defined __sgi
441 # define __OS "IRIX"
442 
443 /* unknown */
444 #else
445 # define __OS "unknown"
446 #endif
447 
448 #if !defined(HAVE_POWI)
449 #if defined(__alpha) && !defined(__linux)
450 #define HAVE_POWI 1
451 #else
452 #define HAVE_POWI 0
453 #endif
454 #endif
455 
456 /* don't perform this check when we are generating dependencies */
457 #ifndef MM
458 /* bomb out if the compiler is broken.... */
459 #if defined(__GNUC_EXCL__) && ((__GNUC__ == 2 && __GNUC_MINOR__ == 96) || (__GNUC__ == 3 && __GNUC_MINOR__ == 4))
460 #error "This g++ version cannot compile Cloudy and must not be used!"
461 #error "Please update g++ to a functional version."
462 #error "See http://cloud9.pa.uky.edu/trac/cloudy/wiki/CompilingCloudy for more details"
463 #endif
464 #endif
465 
466 #ifdef _MSC_VER
467 #pragma warning( default : 4127 )/* disable warning that conditional expression is constant*/
468 #endif
469 
470 #endif /* _CPU_H_ */

Generated for cloudy by doxygen 1.8.1.2