]> git.sesse.net Git - casparcg/blob - tbb/include/tbb/machine/windows_intel64.h
2.0. Updated tbb library.
[casparcg] / tbb / include / tbb / machine / windows_intel64.h
1 /*
2     Copyright 2005-2011 Intel Corporation.  All Rights Reserved.
3
4     This file is part of Threading Building Blocks.
5
6     Threading Building Blocks is free software; you can redistribute it
7     and/or modify it under the terms of the GNU General Public License
8     version 2 as published by the Free Software Foundation.
9
10     Threading Building Blocks is distributed in the hope that it will be
11     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with Threading Building Blocks; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19     As a special exception, you may use this file as part of a free software
20     library without restriction.  Specifically, if other files instantiate
21     templates or use macros or inline functions from this file, or you compile
22     this file and link it with other files to produce an executable, this
23     file does not by itself cause the resulting executable to be covered by
24     the GNU General Public License.  This exception does not however
25     invalidate any other reasons why the executable file might be covered by
26     the GNU General Public License.
27 */
28
29 #if !defined(__TBB_machine_H) || defined(__TBB_machine_windows_intel64_H)
30 #error Do not include this file directly; include tbb_machine.h instead
31 #endif
32
33 #define __TBB_machine_windows_intel64_H
34
35 #define __TBB_WORDSIZE 8
36 #define __TBB_BIG_ENDIAN 0
37
38 #include <intrin.h>
39
40 #if !__INTEL_COMPILER
41     #pragma intrinsic(_InterlockedOr64)
42     #pragma intrinsic(_InterlockedAnd64)
43     #pragma intrinsic(_InterlockedCompareExchange)
44     #pragma intrinsic(_InterlockedCompareExchange64)
45     #pragma intrinsic(_InterlockedExchangeAdd)
46     #pragma intrinsic(_InterlockedExchangeAdd64)
47     #pragma intrinsic(_InterlockedExchange)
48     #pragma intrinsic(_InterlockedExchange64)
49 #endif /* !defined(__INTEL_COMPILER) */
50
51 #if __INTEL_COMPILER
52     #define __TBB_compiler_fence()    __asm { __asm nop }
53     #define __TBB_full_memory_fence() __asm { __asm mfence }
54 #elif _MSC_VER >= 1300
55     extern "C" void _ReadWriteBarrier();
56     #pragma intrinsic(_ReadWriteBarrier)
57     #pragma intrinsic(_mm_mfence)
58     #define __TBB_compiler_fence()    _ReadWriteBarrier()
59     #define __TBB_full_memory_fence() _mm_mfence()
60 #endif
61
62 #define __TBB_control_consistency_helper() __TBB_compiler_fence()
63 #define __TBB_acquire_consistency_helper() __TBB_compiler_fence()
64 #define __TBB_release_consistency_helper() __TBB_compiler_fence()
65
66 // ATTENTION: if you ever change argument types in machine-specific primitives,
67 // please take care of atomic_word<> specializations in tbb/atomic.h
68 extern "C" {
69     __int8 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp1 (volatile void *ptr, __int8 value, __int8 comparand );
70     __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd1 (volatile void *ptr, __int8 addend );
71     __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore1 (volatile void *ptr, __int8 value );
72     __int16 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp2 (volatile void *ptr, __int16 value, __int16 comparand );
73     __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd2 (volatile void *ptr, __int16 addend );
74     __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore2 (volatile void *ptr, __int16 value );
75     void __TBB_EXPORTED_FUNC __TBB_machine_pause (__int32 delay );
76 }
77
78 inline long __TBB_machine_cmpswp4 (volatile void *ptr, __int32 value, __int32 comparand ) {
79     return _InterlockedCompareExchange( (long*)ptr, value, comparand );
80 }
81 inline long __TBB_machine_fetchadd4 (volatile void *ptr, __int32 addend ) {
82     return _InterlockedExchangeAdd( (long*)ptr, addend );
83 }
84 inline long __TBB_machine_fetchstore4 (volatile void *ptr, __int32 value ) {
85     return _InterlockedExchange( (long*)ptr, value );
86 }
87
88 inline __int64 __TBB_machine_cmpswp8 (volatile void *ptr, __int64 value, __int64 comparand ) {
89     return _InterlockedCompareExchange64( (__int64*)ptr, value, comparand );
90 }
91 inline __int64 __TBB_machine_fetchadd8 (volatile void *ptr, __int64 addend ) {
92     return _InterlockedExchangeAdd64( (__int64*)ptr, addend );
93 }
94 inline __int64 __TBB_machine_fetchstore8 (volatile void *ptr, __int64 value ) {
95     return _InterlockedExchange64( (__int64*)ptr, value );
96 }
97
98 #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE   1
99 #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE    1
100 #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE        1
101
102 #if !__INTEL_COMPILER
103 extern "C" unsigned char _BitScanReverse64( unsigned long* i, unsigned __int64 w );
104 #pragma intrinsic(_BitScanReverse64)
105 #endif
106
107 inline __int64 __TBB_machine_lg( unsigned __int64 i ) {
108 #if __INTEL_COMPILER
109     unsigned __int64 j;
110     __asm
111     {
112         bsr rax, i
113         mov j, rax
114     }
115 #else
116     unsigned long j;
117     _BitScanReverse64( &j, i );
118 #endif
119     return j;
120 }
121
122 inline void __TBB_machine_OR( volatile void *operand, intptr_t addend ) {
123     _InterlockedOr64((__int64*)operand, addend); 
124 }
125
126 inline void __TBB_machine_AND( volatile void *operand, intptr_t addend ) {
127     _InterlockedAnd64((__int64*)operand, addend); 
128 }
129
130 #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V)
131 #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V)
132
133 extern "C" __declspec(dllimport) int __stdcall SwitchToThread( void );
134 #define __TBB_Yield()  SwitchToThread()
135 #define __TBB_Pause(V) __TBB_machine_pause(V)
136 #define __TBB_Log2(V)  __TBB_machine_lg(V)
137
138 // API to retrieve/update FPU control setting
139 #define __TBB_CPU_CTL_ENV_PRESENT 1
140
141 struct __TBB_cpu_ctl_env_t {
142     int     mxcsr;
143     short   x87cw;
144 };
145
146 extern "C" {
147     void __TBB_EXPORTED_FUNC __TBB_get_cpu_ctl_env ( __TBB_cpu_ctl_env_t* );
148     void __TBB_EXPORTED_FUNC __TBB_set_cpu_ctl_env ( const __TBB_cpu_ctl_env_t* );
149 }