2 Copyright 2005-2010 Intel Corporation. All Rights Reserved.
4 This file is part of Threading Building Blocks.
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.
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.
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
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.
29 #ifndef __TBB_machine_H
30 #error Do not include this file directly; include tbb_machine.h instead
36 #include "ppcintrinsics.h"
39 extern "C" void _ReadWriteBarrier();
40 #pragma intrinsic(_ReadWriteBarrier)
41 #define __TBB_release_consistency_helper() _ReadWriteBarrier()
44 inline void __TBB_rel_acq_fence() { __lwsync(); }
46 #define __TBB_WORDSIZE 4
47 #define __TBB_BIG_ENDIAN 1
49 //todo: define __TBB_DECL_FENCED_ATOMICS and define acquire/release primitives to maximize performance
51 typedef __int64 int64_t; //required for definition of Store8/Load8 in atomic.h
52 typedef unsigned char uint8_t; //same reason
54 inline __int32 __TBB_machine_cmpswp4(volatile void *ptr, __int32 value, __int32 comparand )
57 __int32 result = InterlockedCompareExchange((volatile LONG*)ptr, value, comparand);
62 inline __int64 __TBB_machine_cmpswp8(volatile void *ptr, __int64 value, __int64 comparand )
65 __int64 result = InterlockedCompareExchange64((volatile LONG64*)ptr, value, comparand);
70 #pragma optimize( "", off )
71 inline void __TBB_machine_pause (__int32 delay )
73 for (__int32 i=0; i<delay; i++) {;};
75 #pragma optimize( "", on )
78 #define __TBB_CompareAndSwap4(P,V,C) __TBB_machine_cmpswp4(P,V,C)
79 #define __TBB_CompareAndSwap8(P,V,C) __TBB_machine_cmpswp8(P,V,C)
80 #define __TBB_CompareAndSwapW(P,V,C) __TBB_machine_cmpswp4(P,V,C)
81 #define __TBB_Yield() Sleep(0)
82 #define __TBB_Pause(V) __TBB_machine_pause(V)
83 #define __TBB_fence_for_acquire() __lwsync()
84 #define __TBB_fence_for_release() __lwsync()