]> git.sesse.net Git - casparcg/blob - tbb30_20100406oss/include/tbb/machine/windows_intel64.h
2.0.2: Updated to boost 1.48.
[casparcg] / tbb30_20100406oss / include / tbb / machine / windows_intel64.h
1 /*
2     Copyright 2005-2010 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 #ifndef __TBB_machine_H
30 #error Do not include this file directly; include tbb_machine.h instead
31 #endif
32
33 #include <intrin.h>
34 #if !defined(__INTEL_COMPILER)
35 #pragma intrinsic(_InterlockedOr64)
36 #pragma intrinsic(_InterlockedAnd64)
37 #pragma intrinsic(_InterlockedCompareExchange)
38 #pragma intrinsic(_InterlockedCompareExchange64)
39 #pragma intrinsic(_InterlockedExchangeAdd)
40 #pragma intrinsic(_InterlockedExchangeAdd64)
41 #pragma intrinsic(_InterlockedExchange)
42 #pragma intrinsic(_InterlockedExchange64)
43 #endif /* !defined(__INTEL_COMPILER) */
44
45 #if defined(__INTEL_COMPILER)
46 #define __TBB_release_consistency_helper() __asm { __asm nop }
47 inline void __TBB_rel_acq_fence() { __asm { __asm mfence } }
48 #elif _MSC_VER >= 1300
49 extern "C" void _ReadWriteBarrier();
50 #pragma intrinsic(_ReadWriteBarrier)
51 #define __TBB_release_consistency_helper() _ReadWriteBarrier()
52 #pragma intrinsic(_mm_mfence)
53 inline void __TBB_rel_acq_fence() { _mm_mfence(); }
54 #endif
55
56 #define __TBB_WORDSIZE 8
57 #define __TBB_BIG_ENDIAN 0
58
59 // ATTENTION: if you ever change argument types in machine-specific primitives,
60 // please take care of atomic_word<> specializations in tbb/atomic.h
61 extern "C" {
62     __int8 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp1 (volatile void *ptr, __int8 value, __int8 comparand );
63     __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd1 (volatile void *ptr, __int8 addend );
64     __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore1 (volatile void *ptr, __int8 value );
65     __int16 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp2 (volatile void *ptr, __int16 value, __int16 comparand );
66     __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd2 (volatile void *ptr, __int16 addend );
67     __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore2 (volatile void *ptr, __int16 value );
68     void __TBB_EXPORTED_FUNC __TBB_machine_pause (__int32 delay );
69 }
70
71
72 #if !__INTEL_COMPILER
73 extern "C" unsigned char _BitScanReverse64( unsigned long* i, unsigned __int64 w );
74 #pragma intrinsic(_BitScanReverse64)
75 #endif
76
77 inline __int64 __TBB_machine_lg( unsigned __int64 i ) {
78 #if __INTEL_COMPILER
79     unsigned __int64 j;
80     __asm
81     {
82         bsr rax, i
83         mov j, rax
84     }
85 #else
86     unsigned long j;
87     _BitScanReverse64( &j, i );
88 #endif
89     return j;
90 }
91
92 inline void __TBB_machine_OR( volatile void *operand, intptr_t addend ) {
93     _InterlockedOr64((__int64*)operand, addend); 
94 }
95
96 inline void __TBB_machine_AND( volatile void *operand, intptr_t addend ) {
97     _InterlockedAnd64((__int64*)operand, addend); 
98 }
99
100 #define __TBB_CompareAndSwap1(P,V,C) __TBB_machine_cmpswp1(P,V,C)
101 #define __TBB_CompareAndSwap2(P,V,C) __TBB_machine_cmpswp2(P,V,C)
102 #define __TBB_CompareAndSwap4(P,V,C) _InterlockedCompareExchange( (long*) P , V , C ) 
103 #define __TBB_CompareAndSwap8(P,V,C) _InterlockedCompareExchange64( (__int64*) P , V , C )
104 #define __TBB_CompareAndSwapW(P,V,C) _InterlockedCompareExchange64( (__int64*) P , V , C )
105
106 #define __TBB_FetchAndAdd1(P,V) __TBB_machine_fetchadd1(P,V)
107 #define __TBB_FetchAndAdd2(P,V) __TBB_machine_fetchadd2(P,V)
108 #define __TBB_FetchAndAdd4(P,V) _InterlockedExchangeAdd((long*) P , V )
109 #define __TBB_FetchAndAdd8(P,V) _InterlockedExchangeAdd64((__int64*) P , V )
110 #define __TBB_FetchAndAddW(P,V) _InterlockedExchangeAdd64((__int64*) P , V )
111
112 #define __TBB_FetchAndStore1(P,V) __TBB_machine_fetchstore1(P,V)
113 #define __TBB_FetchAndStore2(P,V) __TBB_machine_fetchstore2(P,V)
114 #define __TBB_FetchAndStore4(P,V) _InterlockedExchange((long*) P , V )
115 #define __TBB_FetchAndStore8(P,V) _InterlockedExchange64((__int64*) P , V )
116 #define __TBB_FetchAndStoreW(P,V) _InterlockedExchange64((__int64*) P , V ) 
117
118 // Not used if wordsize == 8
119 #undef __TBB_Store8
120 #undef __TBB_Load8
121
122 #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V)
123 #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V)
124
125 extern "C" __declspec(dllimport) int __stdcall SwitchToThread( void );
126 #define __TBB_Yield()  SwitchToThread()
127 #define __TBB_Pause(V) __TBB_machine_pause(V)
128 #define __TBB_Log2(V)    __TBB_machine_lg(V)
129
130 // Use generic definitions from tbb_machine.h
131 #undef __TBB_TryLockByte
132 #undef __TBB_LockByte