Shadowrun: Awakened 29 September 2011 - Build 871
windows_ia32.h
Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
00003 
00004     This file is part of Threading Building Blocks.
00005 
00006     Threading Building Blocks is free software; you can redistribute it
00007     and/or modify it under the terms of the GNU General Public License
00008     version 2 as published by the Free Software Foundation.
00009 
00010     Threading Building Blocks is distributed in the hope that it will be
00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Threading Building Blocks; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019     As a special exception, you may use this file as part of a free software
00020     library without restriction.  Specifically, if other files instantiate
00021     templates or use macros or inline functions from this file, or you compile
00022     this file and link it with other files to produce an executable, this
00023     file does not by itself cause the resulting executable to be covered by
00024     the GNU General Public License.  This exception does not however
00025     invalidate any other reasons why the executable file might be covered by
00026     the GNU General Public License.
00027 */
00028 
00029 #ifndef __TBB_machine_H
00030 #error Do not include this file directly; include tbb_machine.h instead
00031 #endif
00032 
00033 #if defined(__INTEL_COMPILER)
00034 #define __TBB_release_consistency_helper() __asm { __asm nop }
00035 #elif _MSC_VER >= 1300
00036 extern "C" void _ReadWriteBarrier();
00037 #pragma intrinsic(_ReadWriteBarrier)
00038 #define __TBB_release_consistency_helper() _ReadWriteBarrier()
00039 #else
00040 #error Unsupported compiler - need to define __TBB_release_consistency_helper to support it
00041 #endif
00042 
00043 inline void __TBB_rel_acq_fence() { __asm { __asm mfence } }
00044 
00045 #define __TBB_WORDSIZE 4
00046 #define __TBB_BIG_ENDIAN 0
00047 
00048 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
00049     // Workaround for overzealous compiler warnings in /Wp64 mode
00050     #pragma warning (push)
00051     #pragma warning (disable: 4244 4267)
00052 #endif
00053 
00054 extern "C" {
00055     __int64 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp8 (volatile void *ptr, __int64 value, __int64 comparand );
00056     __int64 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd8 (volatile void *ptr, __int64 addend );
00057     __int64 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore8 (volatile void *ptr, __int64 value );
00058     void __TBB_EXPORTED_FUNC __TBB_machine_store8 (volatile void *ptr, __int64 value );
00059     __int64 __TBB_EXPORTED_FUNC __TBB_machine_load8 (const volatile void *ptr);
00060 }
00061 
00062 template <typename T, size_t S>
00063 struct __TBB_machine_load_store {
00064     static inline T load_with_acquire(const volatile T& location) {
00065         T to_return = location;
00066         __TBB_release_consistency_helper();
00067         return to_return;
00068     }
00069 
00070     static inline void store_with_release(volatile T &location, T value) {
00071         __TBB_release_consistency_helper();
00072         location = value;
00073     }
00074 };
00075 
00076 template <typename T>
00077 struct __TBB_machine_load_store<T,8> {
00078     static inline T load_with_acquire(const volatile T& location) {
00079         return __TBB_machine_load8((volatile void *)&location);
00080     }
00081 
00082     static inline void store_with_release(T &location, T value) {
00083         __TBB_machine_store8((volatile void *)&location,(__int64)value);
00084     }
00085 };
00086 
00087 template<typename T>
00088 inline T __TBB_machine_load_with_acquire(const volatile T &location) {
00089     return __TBB_machine_load_store<T,sizeof(T)>::load_with_acquire(location);
00090 }
00091 
00092 template<typename T, typename V>
00093 inline void __TBB_machine_store_with_release(T& location, V value) {
00094     __TBB_machine_load_store<T,sizeof(T)>::store_with_release(location,value);
00095 }
00096 
00098 inline void __TBB_machine_store_with_release(size_t& location, size_t value) {
00099     __TBB_machine_load_store<size_t,sizeof(size_t)>::store_with_release(location,value);
00100 } 
00101 
00102 #define __TBB_load_with_acquire(L) __TBB_machine_load_with_acquire((L))
00103 #define __TBB_store_with_release(L,V) __TBB_machine_store_with_release((L),(V))
00104 
00105 #define __TBB_DEFINE_ATOMICS(S,T,U,A,C) \
00106 static inline T __TBB_machine_cmpswp##S ( volatile void * ptr, U value, U comparand ) { \
00107     T result; \
00108     volatile T *p = (T *)ptr; \
00109     __TBB_release_consistency_helper(); \
00110     __asm \
00111     { \
00112        __asm mov edx, p \
00113        __asm mov C , value \
00114        __asm mov A , comparand \
00115        __asm lock cmpxchg [edx], C \
00116        __asm mov result, A \
00117     } \
00118     __TBB_release_consistency_helper(); \
00119     return result; \
00120 } \
00121 \
00122 static inline T __TBB_machine_fetchadd##S ( volatile void * ptr, U addend ) { \
00123     T result; \
00124     volatile T *p = (T *)ptr; \
00125     __TBB_release_consistency_helper(); \
00126     __asm \
00127     { \
00128         __asm mov edx, p \
00129         __asm mov A, addend \
00130         __asm lock xadd [edx], A \
00131         __asm mov result, A \
00132     } \
00133     __TBB_release_consistency_helper(); \
00134     return result; \
00135 }\
00136 \
00137 static inline T __TBB_machine_fetchstore##S ( volatile void * ptr, U value ) { \
00138     T result; \
00139     volatile T *p = (T *)ptr; \
00140     __TBB_release_consistency_helper(); \
00141     __asm \
00142     { \
00143         __asm mov edx, p \
00144         __asm mov A, value \
00145         __asm lock xchg [edx], A \
00146         __asm mov result, A \
00147     } \
00148     __TBB_release_consistency_helper(); \
00149     return result; \
00150 }
00151 
00152 __TBB_DEFINE_ATOMICS(1, __int8, __int8, al, cl)
00153 __TBB_DEFINE_ATOMICS(2, __int16, __int16, ax, cx)
00154 __TBB_DEFINE_ATOMICS(4, __int32, __int32, eax, ecx)
00155 __TBB_DEFINE_ATOMICS(W, ptrdiff_t, ptrdiff_t, eax, ecx)
00156 
00157 static inline __int32 __TBB_machine_lg( unsigned __int64 i ) {
00158     unsigned __int32 j;
00159     __asm
00160     {
00161         bsr eax, i
00162         mov j, eax
00163     }
00164     return j;
00165 }
00166 
00167 static inline void __TBB_machine_OR( volatile void *operand, __int32 addend ) {
00168    __asm 
00169    {
00170        mov eax, addend
00171        mov edx, [operand]
00172        lock or [edx], eax
00173    }
00174 }
00175 
00176 static inline void __TBB_machine_AND( volatile void *operand, __int32 addend ) {
00177    __asm 
00178    {
00179        mov eax, addend
00180        mov edx, [operand]
00181        lock and [edx], eax
00182    }
00183 }
00184 
00185 static inline void __TBB_machine_pause (__int32 delay ) {
00186     _asm 
00187     {
00188         mov eax, delay
00189       L1: 
00190         pause
00191         add eax, -1
00192         jne L1  
00193     }
00194     return;
00195 }
00196 
00197 #define __TBB_CompareAndSwap1(P,V,C) __TBB_machine_cmpswp1(P,V,C)
00198 #define __TBB_CompareAndSwap2(P,V,C) __TBB_machine_cmpswp2(P,V,C)
00199 #define __TBB_CompareAndSwap4(P,V,C) __TBB_machine_cmpswp4(P,V,C)
00200 #define __TBB_CompareAndSwap8(P,V,C) __TBB_machine_cmpswp8(P,V,C)
00201 #define __TBB_CompareAndSwapW(P,V,C) __TBB_machine_cmpswpW(P,V,C)
00202 
00203 #define __TBB_FetchAndAdd1(P,V) __TBB_machine_fetchadd1(P,V)
00204 #define __TBB_FetchAndAdd2(P,V) __TBB_machine_fetchadd2(P,V)
00205 #define __TBB_FetchAndAdd4(P,V) __TBB_machine_fetchadd4(P,V)
00206 #define __TBB_FetchAndAdd8(P,V) __TBB_machine_fetchadd8(P,V)
00207 #define __TBB_FetchAndAddW(P,V) __TBB_machine_fetchaddW(P,V)
00208 
00209 #define __TBB_FetchAndStore1(P,V) __TBB_machine_fetchstore1(P,V)
00210 #define __TBB_FetchAndStore2(P,V) __TBB_machine_fetchstore2(P,V)
00211 #define __TBB_FetchAndStore4(P,V) __TBB_machine_fetchstore4(P,V)
00212 #define __TBB_FetchAndStore8(P,V) __TBB_machine_fetchstore8(P,V)
00213 #define __TBB_FetchAndStoreW(P,V) __TBB_machine_fetchstoreW(P,V)
00214 
00215 // Should define this: 
00216 #define __TBB_Store8(P,V) __TBB_machine_store8(P,V)
00217 #define __TBB_Load8(P) __TBB_machine_load8(P)
00218 #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V)
00219 #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V)
00220 
00221 // Definition of other functions
00222 extern "C" __declspec(dllimport) int __stdcall SwitchToThread( void );
00223 #define __TBB_Yield()  SwitchToThread()
00224 #define __TBB_Pause(V) __TBB_machine_pause(V)
00225 #define __TBB_Log2(V)    __TBB_machine_lg(V)
00226 
00227 // Use generic definitions from tbb_machine.h
00228 #undef __TBB_TryLockByte
00229 #undef __TBB_LockByte
00230 
00231 #if defined(_MSC_VER)&&_MSC_VER<1400
00232     static inline void* __TBB_machine_get_current_teb () {
00233         void* pteb;
00234         __asm mov eax, fs:[0x18]
00235         __asm mov pteb, eax
00236         return pteb;
00237     }
00238 #endif
00239 
00240 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
00241     #pragma warning (pop)
00242 #endif // warnings 4244, 4267 are back
00243 

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net