00001
00002
00005
00006 #ifdef _MSC_VER
00007 #pragma warning( disable : 4127 )
00008 #endif
00009
00012 #ifndef _CPU_H_
00013 #define _CPU_H_
00014
00016 #ifndef INT16_MAX
00017 #define INT16_MAX 32767
00018 #endif
00019 #ifndef INT16_MIN
00020 #define INT16_MIN (-INT16_MAX - 1)
00021 #endif
00022
00023 #if INT_MAX == INT16_MAX
00024 typedef int int16;
00025 #elif SHRT_MAX == INT16_MAX
00026 typedef short int int16;
00027 #else
00028 #error failed to define int16, please report this to gary@pa.uky.edu
00029 #endif
00030
00031 #ifndef UINT16_MAX
00032 #define UINT16_MAX 65535
00033 #endif
00034
00035 #if UINT_MAX == UINT16_MAX
00036 typedef unsigned int uint16;
00037 #elif USHRT_MAX == UINT16_MAX
00038 typedef unsigned short int uint16;
00039 #else
00040 #error failed to define uint16, please report this to gary@pa.uky.edu
00041 #endif
00042
00043 #ifndef INT32_MAX
00044 #define INT32_MAX 2147483647L
00045 #endif
00046 #ifndef INT32_MIN
00047 #define INT32_MIN (-INT32_MAX - 1)
00048 #endif
00049
00050 #if LONG_MAX == INT32_MAX
00051 typedef long int int32;
00052 #elif INT_MAX == INT32_MAX
00053 typedef int int32;
00054 #else
00055 #error failed to define int32, please report this to gary@pa.uky.edu
00056 #endif
00057
00058 #ifndef UINT32_MAX
00059 #define UINT32_MAX 4294967295UL
00060 #endif
00061
00062 #if ULONG_MAX == UINT32_MAX
00063 typedef unsigned long int uint32;
00064 #elif UINT_MAX == UINT32_MAX
00065 typedef unsigned int uint32;
00066 #else
00067 #error failed to define uint32, please report this to gary@pa.uky.edu
00068 #endif
00069
00070 #if LONG_MAX > INT32_MAX
00071
00072
00073
00074
00075
00076
00077
00078 #undef INT64_MAX
00079 #define INT64_MAX 9223372036854775807L
00080
00081 #undef INT64_MIN
00082 #define INT64_MIN (-INT64_MAX - 1L)
00083
00084 #if LONG_MAX == INT64_MAX
00085 #define HAVE_INT64 1
00086 typedef long int int64;
00087 #endif
00088
00089 #endif
00090
00091 #if ULONG_MAX > UINT32_MAX
00092
00093 #undef UINT64_MAX
00094 #define UINT64_MAX 18446744073709551615UL
00095
00096 #if ULONG_MAX == UINT64_MAX
00097 #define HAVE_UINT64 1
00098 typedef unsigned long int uint64;
00099 #endif
00100
00101 #endif
00102
00103
00106
00107 const float BIGFLOAT = FLT_MAX/100.f;
00109 const float SMALLFLOAT = FLT_MIN*100.f;
00110
00112 const double BIGDOUBLE = DBL_MAX/100.;
00113 const double SMALLDOUBLE = DBL_MIN*100.;
00114
00115 const int STDLEN = 16;
00116
00117
00118
00119 EXTERN class t_cpu
00120 {
00123 union
00124 {
00125 char c[4];
00126 int32 i;
00127 } endian;
00128
00129 int32 Float_SNaN_Value;
00130 # ifdef HAVE_INT64
00131 int64 Double_SNaN_Value;
00132 # else
00133 int32 Double_SNaN_Value[2];
00134 # endif
00135
00137 long n_avail_CPU;
00139 char HostName[STDLEN];
00140
00141 void enable_traps() const;
00142 public:
00143 t_cpu();
00144
00145 bool big_endian() const { return ( endian.i == 0x12345678 ); }
00146 bool little_endian() const { return ( endian.i == 0x78563412 ); }
00147
00148 long nCPU() const { return n_avail_CPU; }
00149 const char *host_name() const { return HostName; }
00150
00151 friend inline void set_nanf(float &x);
00152 friend inline void set_nanf(float x[], long n);
00153 friend inline void set_nan(double &x);
00154 friend inline void set_nan(double x[], long n);
00155 } cpu;
00156
00157
00158
00164 inline void set_nanf(float &x)
00165 {
00166 if( sizeof(float) == 4 )
00167 *reinterpret_cast<int32*>(&x) = cpu.Float_SNaN_Value;
00168 else
00169 x = -FLT_MAX;
00170 }
00171
00172
00173 inline void set_nan(float &x) { set_nanf( x ); }
00174
00175 inline void set_nanf(float x[],
00176 long n)
00177 {
00178 long i;
00179
00180 if( sizeof(float) == 4 )
00181 {
00182 int32 *y = reinterpret_cast<int32*>(x);
00183 for( i=0; i < n; i++ )
00184 *y++ = cpu.Float_SNaN_Value;
00185 }
00186 else
00187 {
00188 for( i=0; i < n; i++ )
00189 x[i] = -FLT_MAX;
00190 }
00191 }
00192
00193
00194 inline void set_nan(float x[], long n) { set_nanf( x, n ); }
00195
00196 inline void set_nan(double &x)
00197 {
00198 if( sizeof(double) == 8 )
00199 {
00200 # ifdef HAVE_INT64
00201 *reinterpret_cast<int64*>(&x) = cpu.Double_SNaN_Value;
00202 # else
00203 int32 *y = reinterpret_cast<int32*>(&x);
00204 *y++ = cpu.Double_SNaN_Value[0];
00205 *y = cpu.Double_SNaN_Value[1];
00206 # endif
00207 }
00208 else
00209 x = -DBL_MAX;
00210 }
00211
00212 inline void set_nan(double x[],
00213 long n)
00214 {
00215 long i;
00216
00217 if( sizeof(double) == 8 )
00218 {
00219 # ifdef HAVE_INT64
00220 int64 *y = reinterpret_cast<int64*>(x);
00221 for( i=0; i < n; i++ )
00222 *y++ = cpu.Double_SNaN_Value;
00223 # else
00224 int32 *y = reinterpret_cast<int32*>(x);
00225 for( i=0; i < n; i++ )
00226 {
00227 *y++ = cpu.Double_SNaN_Value[0];
00228 *y++ = cpu.Double_SNaN_Value[1];
00229 }
00230 # endif
00231 }
00232 else
00233 {
00234 for( i=0; i < n; i++ )
00235 x[i] = -DBL_MAX;
00236 }
00237 }
00238
00240 inline int MyIsnanf(float &x)
00241 {
00242 if( sizeof(float) == 4 && FLT_MAX_EXP-FLT_MIN_EXP+3 == 256 )
00243 {
00244 int32 *p = reinterpret_cast<int32*>(&x);
00245 int32 r = *p & 0x7f800000; r ^= 0x7f800000;
00246 int32 s = *p & 0x007fffff;
00247 return ( r == 0 && s != 0 );
00248 }
00249 else
00250
00251 return false;
00252 }
00253
00254
00255 inline int MyIsnan(float &x) { return MyIsnanf( x ); }
00256
00258 inline int MyIsnan(double &x)
00259 {
00260 if( sizeof(double) == 8 && DBL_MAX_EXP-DBL_MIN_EXP+3 == 2048 )
00261 {
00262 # ifdef HAVE_INT64
00263 int64 *p = reinterpret_cast<int64*>(&x);
00264 int64 r = *p & 0x7ff0000000000000; r ^= 0x7ff0000000000000;
00265 int64 s = *p & 0x000fffffffffffff;
00266 return ( r == 0 && s != 0 );
00267 # else
00268 int32 *p = reinterpret_cast<int32*>(&x);
00269 if( cpu.little_endian() )
00270 {
00271 int32 r = p[1] & 0x7ff00000; r ^= 0x7ff00000;
00272 int32 s = p[1] & 0x000fffff; s |= p[0];
00273 return ( r == 0 && s != 0 );
00274 }
00275 else if( cpu.big_endian() )
00276 {
00277 int32 r = p[0] & 0x7ff00000; r ^= 0x7ff00000;
00278 int32 s = p[0] & 0x000fffff; s |= p[1];
00279 return ( r == 0 && s != 0 );
00280 }
00281 else
00282
00283 return false;
00284 # endif
00285 }
00286 else
00287
00288 return false;
00289 }
00290
00291
00292
00314 #ifdef cray
00315 #ifndef __cray
00316 #define __cray 1
00317 #endif
00318 #endif
00319
00321 #ifdef __x86_64
00322 #ifndef __amd64
00323 #define __amd64 1
00324 #endif
00325 #endif
00326
00327 #if defined(_ARCH_PPC) || defined(__POWERPC__) || defined(__powerpc__) || defined(PPC)
00328 #ifndef __ppc__
00329 #define __ppc__ 1
00330 #endif
00331 #endif
00332
00338 #if defined(unix) || defined(__unix__)
00339 #ifndef __unix
00340 #define __unix 1
00341 #endif
00342 #endif
00343
00345 #ifdef __ECC
00346 #ifndef __ICC
00347 #define __ICC __ECC
00348 #endif
00349 #endif
00350
00352 #undef __GNUC_EXCL__
00353 #if defined(__GNUC__) && ! ( defined(__ICC) || defined(__PATHSCALE__) )
00354 #define __GNUC_EXCL__ 1
00355 #endif
00356
00357
00358
00359 #ifdef _MSC_VER
00360 #define NORETURN __declspec(noreturn)
00361 #elif defined(__GNUC__) || ( defined(__INTEL_COMPILER) && defined(__linux) )
00362 #define NORETURN __attribute__ ((noreturn))
00363 #else
00364 #define NORETURN
00365 #endif
00366
00367
00368
00369
00370 #if defined __INTEL_COMPILER
00371 # define __COMP "icc"
00372 # define __COMP_VER __INTEL_COMPILER
00373
00374
00375
00376 #elif defined __PATHSCALE__
00377 # define __COMP "pathCC"
00378 # define __COMP_VER __PATHCC__ * 100 + __PATHCC_MINOR__ * 10 + __PATHCC_PATCHLEVEL__
00379
00380
00381 #elif defined __GNUC__
00382 # define __COMP "g++"
00383 # if defined(__GNUC_PATCHLEVEL__)
00384 # define __COMP_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
00385 # else
00386 # define __COMP_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
00387 # endif
00388
00389 #elif defined __PGI
00390 # define __COMP "Portland Group Compiler"
00391
00392 # if defined(__PGIC__)
00393 # define __COMP_VER (__PGIC__ * 100 + __PGIC_MINOR__ * 10 + __PGIC_PATCHLEVEL__)
00394 # else
00395 # define __COMP_VER 0
00396 # endif
00397
00398
00399
00400 #elif defined(__sgi) && defined(_COMPILER_VERSION)
00401 # define __COMP "MIPSpro"
00402 # define __COMP_VER _COMPILER_VERSION
00403
00404
00405 #elif defined __HP_aCC
00406 # define __COMP "HP aCC"
00407 # define __COMP_VER __HP_aCC
00408
00409
00410 #elif defined __DECC
00411 # define __COMP "DEC CC"
00412 # define __COMP_VER __DECC_VER
00413
00414
00415 #elif defined _MSC_VER
00416 # define __COMP "vs"
00417 # define __COMP_VER _MSC_VER
00418
00419
00420 #elif defined __SUNPRO_CC
00421 # define __COMP "Sun Workshop"
00422 # define __COMP_VER __SUNPRO_CC
00423
00424
00425 #else
00426 #define __COMP "unknown"
00427 #define __COMP_VER 0
00428 #endif
00429
00430
00431
00432 #if defined __linux
00433 # if defined __i386
00434 # define __OS "Linux (IA32)"
00435 # elif defined __amd64
00436 # define __OS "Linux (AMD64)"
00437 # elif defined __ia64
00438 # define __OS "Linux (IA64)"
00439 # elif defined __ppc__
00440 # define __OS "Linux (PowerPC)"
00441 # else
00442 # define __OS "Linux (other)"
00443 # endif
00444
00445
00446 #elif defined macintosh
00447 # define __OS "Mac OS 9"
00448
00449
00450 #elif defined __MACOSX__
00451 # define __OS "Mac OS X"
00452
00453
00454 #elif defined __APPLE__
00455 # define __OS "Apple MacOS"
00456
00457
00458 #elif defined hpux
00459 # define __OS "HP-UX"
00460
00461
00462 #elif defined __sun
00463 # define __OS "Solaris"
00464
00465
00466 #elif defined _AIX
00467 # define __OS "AIX"
00468
00469
00470 #elif defined ultrix
00471 # define __OS "Ultrix"
00472
00473
00474 #elif defined __FreeBSD__
00475 # define __OS "FreeBSD"
00476
00477 #elif defined __NetBSD__
00478 # define __OS "NetBSD"
00479
00480 #elif defined __OpenBSD__
00481 # define __OS "OpenBSD"
00482
00483
00484
00485 #elif defined _WIN64
00486 # define __OS "Win64"
00487
00488
00489 #elif defined _WIN32
00490 # define __OS "Win32"
00491
00492
00493 #elif defined __CYGWIN__
00494 # define __OS "Cygwin"
00495
00496
00497 #elif defined __sgi
00498 # define __OS "IRIX"
00499
00500
00501 #else
00502 # define __OS "unknown"
00503 #endif
00504
00505 #if !defined(HAVE_POWI)
00506 #if defined(__alpha) && !defined(__linux)
00507 #define HAVE_POWI 1
00508 #else
00509 #define HAVE_POWI 0
00510 #endif
00511 #endif
00512
00513 #if !defined(BROKEN_COMPILER)
00514 #if defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 96)
00515 #define BROKEN_COMPILER 1
00516 #else
00517 #define BROKEN_COMPILER 0
00518 #endif
00519 #endif
00520
00521 #endif // defined _CPU_H_
00522
00523 #ifdef _MSC_VER
00524 #pragma warning( default : 4127 )
00525 #endif