00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef KMP_OS_H
00048 #define KMP_OS_H
00049
00050 #include <stdlib.h>
00051
00052 #define KMP_FTN_PLAIN 1
00053 #define KMP_FTN_APPEND 2
00054 #define KMP_FTN_UPPER 3
00055
00056
00057
00058
00059
00060 #define KMP_PTR_SKIP (sizeof(void*))
00061
00062
00063
00064 #define KMP_OFF 0
00065 #define KMP_ON 1
00066
00067 #define KMP_MEM_CONS_VOLATILE 0
00068 #define KMP_MEM_CONS_FENCE 1
00069
00070 #ifndef KMP_MEM_CONS_MODEL
00071 # define KMP_MEM_CONS_MODEL KMP_MEM_CONS_VOLATILE
00072 #endif
00073
00074
00075
00076 #define KMP_OS_LINUX 0
00077 #define KMP_OS_DARWIN 0
00078 #define KMP_OS_WINDOWS 0
00079 #define KMP_OS_UNIX 0
00080
00081 #define KMP_ARCH_X86 0
00082 #define KMP_ARCH_X86_64 0
00083
00084 #ifdef _WIN32
00085 # undef KMP_OS_WINDOWS
00086 # define KMP_OS_WINDOWS 1
00087 #endif
00088
00089 #if ( defined __APPLE__ && defined __MACH__ )
00090 # undef KMP_OS_DARWIN
00091 # define KMP_OS_DARWIN 1
00092 #endif
00093
00094 #if ( defined __linux )
00095 # undef KMP_OS_LINUX
00096 # define KMP_OS_LINUX 1
00097 #endif
00098
00099 #if (1 != KMP_OS_LINUX + KMP_OS_DARWIN + KMP_OS_WINDOWS)
00100 # error Unknown OS
00101 #endif
00102
00103 #if KMP_OS_LINUX || KMP_OS_DARWIN
00104 # undef KMP_OS_UNIX
00105 # define KMP_OS_UNIX 1
00106 #endif
00107
00108 #if KMP_OS_WINDOWS
00109 # if defined _M_AMD64
00110 # undef KMP_ARCH_X86_64
00111 # define KMP_ARCH_X86_64 1
00112 # else
00113 # undef KMP_ARCH_X86
00114 # define KMP_ARCH_X86 1
00115 # endif
00116 #endif
00117
00118 #if KMP_OS_UNIX
00119 # if defined __x86_64
00120 # undef KMP_ARCH_X86_64
00121 # define KMP_ARCH_X86_64 1
00122 # else
00123 # undef KMP_ARCH_X86
00124 # define KMP_ARCH_X86 1
00125 # endif
00126 #endif
00127
00128 #if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64)
00129 # error Unknown or unsupported architecture
00130 #endif
00131
00132 #if KMP_OS_WINDOWS
00133 # if defined KMP_WIN_CDECL || !defined GUIDEDLL_EXPORTS
00134 # define USE_FTN_CDECL KMP_FTN_UPPER
00135 # endif
00136
00137 # define KMP_FTN KMP_FTN_PLAIN
00138 # define USE_FTN_EXTRA KMP_FTN_PLAIN
00139 # if KMP_ARCH_X86
00140 # if defined KMP_WIN_STDCALL || !defined GUIDEDLL_EXPORTS
00141 # define USE_FTN_STDCALL KMP_FTN_UPPER
00142 # endif
00143 # endif
00144 typedef char kmp_int8;
00145 typedef unsigned char kmp_uint8;
00146 typedef short kmp_int16;
00147 typedef unsigned short kmp_uint16;
00148 typedef int kmp_int32;
00149 typedef unsigned int kmp_uint32;
00150 # define KMP_INT32_SPEC "d"
00151 # define KMP_UINT32_SPEC "u"
00152 # ifndef KMP_STRUCT64
00153 typedef __int64 kmp_int64;
00154 typedef unsigned __int64 kmp_uint64;
00155 #define KMP_INT64_SPEC "I64d"
00156 #define KMP_UINT64_SPEC "I64u"
00157 # else
00158 struct kmp_struct64 {
00159 kmp_int32 a,b;
00160 };
00161 typedef struct kmp_struct64 kmp_int64;
00162 typedef struct kmp_struct64 kmp_uint64;
00163
00164 # endif
00165 # if KMP_ARCH_X86_64
00166 # define KMP_INTPTR 1
00167 typedef __int64 kmp_intptr_t;
00168 typedef unsigned __int64 kmp_uintptr_t;
00169 # define KMP_INTPTR_SPEC "I64d"
00170 # define KMP_UINTPTR_SPEC "I64u"
00171 # endif
00172 #endif
00173
00174 #if KMP_OS_UNIX
00175 # define KMP_FTN KMP_FTN_PLAIN
00176 # define USE_FTN_CDECL KMP_FTN_PLAIN
00177 # define USE_FTN_EXTRA KMP_FTN_APPEND
00178 typedef char kmp_int8;
00179 typedef unsigned char kmp_uint8;
00180 typedef short kmp_int16;
00181 typedef unsigned short kmp_uint16;
00182 typedef int kmp_int32;
00183 typedef unsigned int kmp_uint32;
00184 typedef long long kmp_int64;
00185 typedef unsigned long long kmp_uint64;
00186 # define KMP_INT32_SPEC "d"
00187 # define KMP_UINT32_SPEC "u"
00188 # define KMP_INT64_SPEC "lld"
00189 # define KMP_UINT64_SPEC "llu"
00190 #endif
00191
00192 #if KMP_ARCH_X86
00193 # define KMP_SIZE_T_SPEC KMP_UINT32_SPEC
00194 #elif KMP_ARCH_X86_64
00195 # define KMP_SIZE_T_SPEC KMP_UINT64_SPEC
00196 #else
00197 # error "Can't determine size_t printf format specifier."
00198 #endif
00199
00200 #if KMP_ARCH_X86
00201 # define KMP_SIZE_T_MAX (0xFFFFFFFF)
00202 #else
00203 # define KMP_SIZE_T_MAX (0xFFFFFFFFFFFFFFFF)
00204 #endif
00205
00206 typedef size_t kmp_size_t;
00207 typedef float kmp_real32;
00208 typedef double kmp_real64;
00209
00210 #ifndef KMP_INTPTR
00211 # define KMP_INTPTR 1
00212 typedef long kmp_intptr_t;
00213 typedef unsigned long kmp_uintptr_t;
00214 # define KMP_INTPTR_SPEC "ld"
00215 # define KMP_UINTPTR_SPEC "lu"
00216 #endif
00217
00218 #ifdef KMP_I8
00219 typedef kmp_int64 kmp_int;
00220 typedef kmp_uint64 kmp_uint;
00221 # define KMP_INT_SPEC KMP_INT64_SPEC
00222 # define KMP_UINT_SPEC KMP_UINT64_SPEC
00223 # define KMP_INT_MAX ((kmp_int64)0x7FFFFFFFFFFFFFFFLL)
00224 # define KMP_INT_MIN ((kmp_int64)0x8000000000000000LL)
00225 #else
00226 typedef kmp_int32 kmp_int;
00227 typedef kmp_uint32 kmp_uint;
00228 # define KMP_INT_SPEC KMP_INT32_SPEC
00229 # define KMP_UINT_SPEC KMP_UINT32_SPEC
00230 # define KMP_INT_MAX ((kmp_int32)0x7FFFFFFF)
00231 # define KMP_INT_MIN ((kmp_int64)0x80000000)
00232 #endif
00233
00234 #ifdef __cplusplus
00235
00236
00237
00238 template< typename T >
00239 struct traits_t {
00240 typedef T signed_t;
00241 typedef T unsigned_t;
00242 typedef T floating_t;
00243 static char const * spec;
00244 };
00245
00246 template<>
00247 struct traits_t< signed int > {
00248 typedef signed int signed_t;
00249 typedef unsigned int unsigned_t;
00250 typedef double floating_t;
00251 static char const * spec;
00252 };
00253
00254 template<>
00255 struct traits_t< unsigned int > {
00256 typedef signed int signed_t;
00257 typedef unsigned int unsigned_t;
00258 typedef double floating_t;
00259 static char const * spec;
00260 };
00261
00262 template<>
00263 struct traits_t< signed long long > {
00264 typedef signed long long signed_t;
00265 typedef unsigned long long unsigned_t;
00266 typedef long double floating_t;
00267 static char const * spec;
00268 };
00269
00270 template<>
00271 struct traits_t< unsigned long long > {
00272 typedef signed long long signed_t;
00273 typedef unsigned long long unsigned_t;
00274 typedef long double floating_t;
00275 static char const * spec;
00276 };
00277
00278 #endif // __cplusplus
00279
00280 #if KMP_OS_WINDOWS
00281 # define KMP_STDCALL __stdcall
00282 #endif
00283
00284 #ifndef KMP_STDCALL
00285 # define KMP_STDCALL
00286 #endif
00287
00288 #define KMP_EXPORT extern
00289
00290 #if __GNUC__ == 4
00291 #define __forceinline __inline
00292 #endif
00293
00294 #define PAGE_SIZE (0x4000)
00295 #define PAGE_ALIGNED(_addr) ( ! ((size_t) _addr & \
00296 (size_t)(PAGE_SIZE - 1)))
00297 #define ALIGN_TO_PAGE(x) (void *)(((size_t)(x)) & ~((size_t)(PAGE_SIZE - 1)))
00298
00299
00300
00301 #ifdef __cplusplus
00302 extern "C" {
00303 #endif // __cplusplus
00304
00305
00306 #ifndef CACHE_LINE
00307 #define CACHE_LINE 128
00308 #else
00309 #if ( CACHE_LINE < 64 ) && ! defined( KMP_OS_DARWIN )
00310
00311 #warning CACHE_LINE is too small.
00312 #endif
00313 #endif
00314
00315
00316 #if !defined KMP_PERF_V19
00317 # define KMP_PERF_V19 KMP_ON
00318 #endif
00319
00320
00321 #if !defined KMP_PERF_V106
00322 # define KMP_PERF_V106 KMP_ON
00323 #endif
00324
00325 #define KMP_CACHE_PREFETCH(ADDR)
00326
00327
00328
00329 #if KMP_OS_UNIX && defined(__GNUC__)
00330 # define KMP_DO_ALIGN(bytes) __attribute__((aligned(bytes)))
00331 # define KMP_ALIGN_CACHE __attribute__((aligned(CACHE_LINE)))
00332 # define KMP_ALIGN(bytes) __attribute__((aligned(bytes)))
00333 #else
00334 # define KMP_DO_ALIGN(bytes) __declspec( align(bytes) )
00335 # define KMP_ALIGN_CACHE __declspec( align(CACHE_LINE) )
00336 # define KMP_ALIGN(bytes) __declspec( align(bytes) )
00337 #endif
00338
00339 #if defined(__MIC__) || defined(__MIC2__)
00340 #define KMP_MIC 1
00341
00342 # if __MIC2__
00343 #define KMP_MIC1 0
00344 # else
00345 #define KMP_MIC1 1
00346 # endif
00347 #else
00348 #define KMP_MIC 0
00349 #define KMP_MIC1 0
00350 #endif
00351
00352
00353 enum kmp_mem_fence_type {
00354 kmp_no_fence,
00355 kmp_acquire_fence,
00356 kmp_release_fence,
00357 kmp_full_fence
00358 };
00359
00360
00361 #if KMP_MIC
00362
00363 # define KMP_TEST_THEN_INC32( ADDR ) __sync_fetch_and_add( (kmp_int32*)(ADDR), 1 )
00364
00365 # define KMP_TEST_THEN_INC_ACQ32( ADDR ) __sync_fetch_and_add( (kmp_int32*)(ADDR), 1 )
00366
00367 # define KMP_TEST_THEN_INC64( ADDR ) __sync_fetch_and_add( (kmp_int64*)(ADDR), 1LL )
00368
00369 # define KMP_TEST_THEN_INC_ACQ64( ADDR ) __sync_fetch_and_add( (kmp_int64*)(ADDR), 1LL )
00370
00371 # define KMP_TEST_THEN_ADD4_32( ADDR ) __sync_fetch_and_add( (kmp_int32*)(ADDR), 4 )
00372
00373 # define KMP_TEST_THEN_ADD4_ACQ32( ADDR ) __sync_fetch_and_add( (kmp_int32*)(ADDR), 4 )
00374
00375 # define KMP_TEST_THEN_ADD4_64( ADDR ) __sync_fetch_and_add( (kmp_int64*)(ADDR), 4LL )
00376
00377 # define KMP_TEST_THEN_ADD4_ACQ64( ADDR ) __sync_fetch_and_add( (kmp_int64*)(ADDR), 4LL )
00378
00379 # define KMP_TEST_THEN_DEC32( ADDR ) __sync_fetch_and_sub( (kmp_int32*)(ADDR), 1 )
00380
00381 # define KMP_TEST_THEN_DEC_ACQ32( ADDR ) __sync_fetch_and_sub( (kmp_int32*)(ADDR), 1 )
00382
00383 # define KMP_TEST_THEN_DEC64( ADDR ) __sync_fetch_and_sub( (kmp_int64*)(ADDR), 1LL )
00384
00385 # define KMP_TEST_THEN_DEC_ACQ64( ADDR ) __sync_fetch_and_sub( (kmp_int64*)(ADDR), 1LL )
00386
00387 # define KMP_TEST_THEN_ADD32( ADDR, INCR ) __sync_fetch_and_add( (kmp_int32*)(ADDR), (INCR) )
00388
00389 # define KMP_TEST_THEN_ADD64( ADDR, INCR ) __sync_fetch_and_add( (kmp_int64*)(ADDR), (INCR) )
00390
00391 # define KMP_COMPARE_AND_STORE_ACQ32(p,cv,sv) __sync_bool_compare_and_swap((volatile kmp_uint32*)(p),(kmp_uint32)(cv),(kmp_uint32)(sv))
00392 # define KMP_COMPARE_AND_STORE_REL32(p,cv,sv) __sync_bool_compare_and_swap((volatile kmp_uint32*)(p),(kmp_uint32)(cv),(kmp_uint32)(sv))
00393 # define KMP_COMPARE_AND_STORE_ACQ64(p,cv,sv) __sync_bool_compare_and_swap((volatile kmp_uint64*)(p),(kmp_uint64)(cv),(kmp_uint64)(sv))
00394 # define KMP_COMPARE_AND_STORE_REL64(p,cv,sv) __sync_bool_compare_and_swap((volatile kmp_uint64*)(p),(kmp_uint64)(cv),(kmp_uint64)(sv))
00395 # define KMP_COMPARE_AND_STORE_PTR(p,cv,sv) __sync_bool_compare_and_swap((volatile kmp_uint64*)(p),(kmp_uint64)(cv),(kmp_uint64)(sv))
00396
00397 #endif
00398
00399 #if ! defined KMP_TEST_THEN_INC32
00400 # define KMP_TEST_THEN_INC32( ADDR ) ( __kmp_test_then_add32( (ADDR), 1 ) )
00401 #endif
00402 #if ! defined KMP_TEST_THEN_INC_ACQ32
00403 # define KMP_TEST_THEN_INC_ACQ32( ADDR ) ( __kmp_test_then_add32( (ADDR), 1 ) )
00404 #endif
00405
00406 #if ! defined KMP_TEST_THEN_INC64
00407 # define KMP_TEST_THEN_INC64( ADDR ) ( __kmp_test_then_add64( (ADDR), 1LL ) )
00408 #endif
00409 #if ! defined KMP_TEST_THEN_INC_ACQ64
00410 # define KMP_TEST_THEN_INC_ACQ64( ADDR ) ( __kmp_test_then_add64( (ADDR), 1LL ) )
00411 #endif
00412
00413 #if ! defined KMP_TEST_THEN_ADD4_32
00414 # define KMP_TEST_THEN_ADD4_32( ADDR ) ( __kmp_test_then_add32( (ADDR), 4 ) )
00415 #endif
00416 #if ! defined KMP_TEST_THEN_ADD4_ACQ32
00417 # define KMP_TEST_THEN_ADD4_ACQ32( ADDR ) ( __kmp_test_then_add32( (ADDR), 4 ) )
00418 #endif
00419
00420 #if ! defined KMP_TEST_THEN_ADD4_64
00421 # define KMP_TEST_THEN_ADD4_64( ADDR ) ( __kmp_test_then_add64( (ADDR), 4LL ) )
00422 #endif
00423 #if ! defined KMP_TEST_THEN_ADD4_ACQ64
00424 # define KMP_TEST_THEN_ADD4_ACQ64( ADDR ) ( __kmp_test_then_add64( (ADDR), 4LL ) )
00425 #endif
00426
00427 #if ! defined KMP_TEST_THEN_DEC32
00428 # define KMP_TEST_THEN_DEC32( ADDR ) ( __kmp_test_then_add32( (ADDR), -1 ) )
00429 #endif
00430 #if !defined KMP_TEST_THEN_DEC_ACQ32
00431 # define KMP_TEST_THEN_DEC_ACQ32( ADDR ) ( __kmp_test_then_add32( (ADDR), -1 ) )
00432 #endif
00433
00434 #if !defined KMP_TEST_THEN_DEC64
00435 # define KMP_TEST_THEN_DEC64( ADDR ) ( __kmp_test_then_add64( (ADDR), -1LL ) )
00436 #endif
00437 #if !defined KMP_TEST_THEN_DEC_ACQ64
00438 # define KMP_TEST_THEN_DEC_ACQ64( ADDR ) ( __kmp_test_then_add64( (ADDR), -1LL ) )
00439 #endif
00440
00441 #if !defined KMP_TEST_THEN_ADD32
00442 # define KMP_TEST_THEN_ADD32( ADDR, INCR ) ( __kmp_test_then_add32( (ADDR), (INCR) ) )
00443 #endif
00444
00445 #if !defined KMP_TEST_THEN_ADD64
00446 # define KMP_TEST_THEN_ADD64( ADDR, INCR ) ( __kmp_test_then_add64( (ADDR), (INCR) ) )
00447 #endif
00448
00449
00450
00451 #if KMP_OS_WINDOWS
00452 # ifdef __ABSOFT_WIN
00453 # define KMP_MB() asm ("nop")
00454 # define KMP_IMB() asm ("nop")
00455 # else
00456 # define KMP_MB()
00457 # define KMP_IMB()
00458 # endif
00459 #endif
00460
00461 #ifndef KMP_MB
00462 # define KMP_MB()
00463 #endif
00464
00465 #ifndef KMP_IMB
00466 # define KMP_IMB()
00467 #endif
00468
00469 #ifndef KMP_ST4_REL
00470 # define KMP_ST4_REL(A,D) ( *(A) = (D) )
00471 #endif
00472
00473 #ifndef KMP_ST8_REL
00474 # define KMP_ST8_REL(A,D) ( *(A) = (D) )
00475 #endif
00476
00477 #ifndef KMP_LD4_ACQ
00478 # define KMP_LD4_ACQ(A) ( *(A) )
00479 #endif
00480
00481 #ifndef KMP_LD8_ACQ
00482 # define KMP_LD8_ACQ(A) ( *(A) )
00483 #endif
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 #define TCR_4(a) (a)
00501 #define TCW_4(a,b) (a) = (b)
00502 #define TCR_8(a) (a)
00503 #define TCW_8(a,b) (a) = (b)
00504 #define TCR_SYNC_4(a) (a)
00505 #define TCW_SYNC_4(a,b) (a) = (b)
00506 #define TCX_SYNC_4(a,b,c) KMP_COMPARE_AND_STORE_REL32((volatile kmp_int32 *)(volatile void *)&(a), (kmp_int32)(b), (kmp_int32)(c))
00507 #define TCR_SYNC_8(a) (a)
00508 #define TCW_SYNC_8(a,b) (a) = (b)
00509 #define TCX_SYNC_8(a,b,c) KMP_COMPARE_AND_STORE_REL64((volatile kmp_int64 *)(volatile void *)&(a), (kmp_int64)(b), (kmp_int64)(c))
00510 #define TC_IGNORE(stmt); stmt;
00511
00512 #if KMP_ARCH_X86
00513
00514 #define TCR_PTR(a) ((void *)TCR_4(a))
00515 #define TCW_PTR(a,b) TCW_4((a),(b))
00516 #define TCR_SYNC_PTR(a) ((void *)TCR_SYNC_4(a))
00517 #define TCW_SYNC_PTR(a,b) TCW_SYNC_4((a),(b))
00518 #define TCX_SYNC_PTR(a,b,c) ((void *)TCX_SYNC_4((a),(b),(c)))
00519
00520 #else
00521
00522 #define TCR_PTR(a) ((void *)TCR_8(a))
00523 #define TCW_PTR(a,b) TCW_8((a),(b))
00524 #define TCR_SYNC_PTR(a) ((void *)TCR_SYNC_8(a))
00525 #define TCW_SYNC_PTR(a,b) TCW_SYNC_8((a),(b))
00526 #define TCX_SYNC_PTR(a,b,c) ((void *)TCX_SYNC_8((a),(b),(c)))
00527
00528 #endif
00529
00530
00531
00532
00533
00534
00535
00536 #ifndef FTN_TRUE
00537 # define FTN_TRUE TRUE
00538 #endif
00539
00540 #ifndef FTN_FALSE
00541 # define FTN_FALSE FALSE
00542 #endif
00543
00544 typedef void (*microtask_t)( int *gtid, int *npr, ... );
00545
00546 #ifdef USE_VOLATILE_CAST
00547 # define VOLATILE_CAST(x) (volatile x)
00548 #else
00549 # define VOLATILE_CAST(x) (x)
00550 #endif
00551
00552 #ifdef KMP_I8
00553 # define KMP_WAIT_YIELD __kmp_wait_yield_8
00554 # define KMP_EQ __kmp_eq_8
00555 # define KMP_NEQ __kmp_neq_8
00556 # define KMP_LT __kmp_lt_8
00557 # define KMP_GE __kmp_ge_8
00558 # define KMP_LE __kmp_le_8
00559 #else
00560 # define KMP_WAIT_YIELD __kmp_wait_yield_4
00561 # define KMP_EQ __kmp_eq_4
00562 # define KMP_NEQ __kmp_neq_4
00563 # define KMP_LT __kmp_lt_4
00564 # define KMP_GE __kmp_ge_4
00565 # define KMP_LE __kmp_le_4
00566 #endif
00567
00568
00569 #if KMP_ARCH_X86_64 && KMP_OS_LINUX
00570 # define STATIC_EFI2_WORKAROUND
00571 #else
00572 # define STATIC_EFI2_WORKAROUND static
00573 #endif
00574
00575
00576 #ifndef KMP_USE_BGET
00577 #define KMP_USE_BGET 1
00578 #endif
00579
00580
00581
00582 enum kmp_warnings_level {
00583 kmp_warnings_off = 0,
00584 kmp_warnings_low,
00585 kmp_warnings_explicit = 6,
00586 kmp_warnings_verbose
00587 };
00588
00589 #ifdef __cplusplus
00590 }
00591 #endif // __cplusplus
00592
00593 #endif