BRE12
msvc_armv7.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
19 */
20 
21 #if !defined(__TBB_machine_H) || defined(__TBB_msvc_armv7_H)
22 #error Do not #include this internal file directly; use public TBB headers instead.
23 #endif
24 
25 #define __TBB_msvc_armv7_H
26 
27 #include <intrin.h>
28 #include <float.h>
29 
30 #define __TBB_WORDSIZE 4
31 
32 #define __TBB_ENDIANNESS __TBB_ENDIAN_UNSUPPORTED
33 
34 #if defined(TBB_WIN32_USE_CL_BUILTINS)
35 // We can test this on _M_IX86
36 #pragma intrinsic(_ReadWriteBarrier)
37 #pragma intrinsic(_mm_mfence)
38 #define __TBB_compiler_fence() _ReadWriteBarrier()
39 #define __TBB_full_memory_fence() _mm_mfence()
40 #define __TBB_control_consistency_helper() __TBB_compiler_fence()
41 #define __TBB_acquire_consistency_helper() __TBB_compiler_fence()
42 #define __TBB_release_consistency_helper() __TBB_compiler_fence()
43 #else
44 //Now __dmb(_ARM_BARRIER_SY) is used for both compiler and memory fences
45 //This might be changed later after testing
46 #define __TBB_compiler_fence() __dmb(_ARM_BARRIER_SY)
47 #define __TBB_full_memory_fence() __dmb(_ARM_BARRIER_SY)
48 #define __TBB_control_consistency_helper() __TBB_compiler_fence()
49 #define __TBB_acquire_consistency_helper() __TBB_full_memory_fence()
50 #define __TBB_release_consistency_helper() __TBB_full_memory_fence()
51 #endif
52 
53 //--------------------------------------------------
54 // Compare and swap
55 //--------------------------------------------------
56 
65 #define __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(S,T,F) \
66 inline T __TBB_machine_cmpswp##S( volatile void *ptr, T value, T comparand ) { \
67  return _InterlockedCompareExchange##F(reinterpret_cast<volatile T *>(ptr),value,comparand); \
68 } \
69 
70 #define __TBB_MACHINE_DEFINE_ATOMICS_FETCHADD(S,T,F) \
71 inline T __TBB_machine_fetchadd##S( volatile void *ptr, T value ) { \
72  return _InterlockedExchangeAdd##F(reinterpret_cast<volatile T *>(ptr),value); \
73 } \
74 
75 __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(1,char,8)
76 __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(2,short,16)
77 __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(4,long,)
78 __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(8,__int64,64)
79 __TBB_MACHINE_DEFINE_ATOMICS_FETCHADD(4,long,)
80 #if defined(TBB_WIN32_USE_CL_BUILTINS)
81 // No _InterlockedExchangeAdd64 intrinsic on _M_IX86
82 #define __TBB_64BIT_ATOMICS 0
83 #else
84 __TBB_MACHINE_DEFINE_ATOMICS_FETCHADD(8,__int64,64)
85 #endif
86 
87 inline void __TBB_machine_pause (int32_t delay )
88 {
89  while(delay>0)
90  {
91  __TBB_compiler_fence();
92  delay--;
93  }
94 }
95 
96 // API to retrieve/update FPU control setting
97 #define __TBB_CPU_CTL_ENV_PRESENT 1
98 
99 namespace tbb {
100 namespace internal {
101 
102 template <typename T, size_t S>
103 struct machine_load_store_relaxed {
104  static inline T load ( const volatile T& location ) {
105  const T value = location;
106 
107  /*
108  * An extra memory barrier is required for errata #761319
109  * Please see http://infocenter.arm.com/help/topic/com.arm.doc.uan0004a
110  */
111  __TBB_acquire_consistency_helper();
112  return value;
113  }
114 
115  static inline void store ( volatile T& location, T value ) {
116  location = value;
117  }
118 };
119 
120 class cpu_ctl_env {
121 private:
122  unsigned int my_ctl;
123 public:
124  bool operator!=( const cpu_ctl_env& ctl ) const { return my_ctl != ctl.my_ctl; }
125  void get_env() { my_ctl = _control87(0, 0); }
126  void set_env() const { _control87( my_ctl, ~0U ); }
127 };
128 
129 } // namespace internal
130 } // namespaces tbb
131 
132 // Machine specific atomic operations
133 #define __TBB_CompareAndSwap4(P,V,C) __TBB_machine_cmpswp4(P,V,C)
134 #define __TBB_CompareAndSwap8(P,V,C) __TBB_machine_cmpswp8(P,V,C)
135 #define __TBB_Pause(V) __TBB_machine_pause(V)
136 
137 // Use generics for some things
138 #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE 1
139 #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1
140 #define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD 1
141 #define __TBB_USE_GENERIC_PART_WORD_FETCH_STORE 1
142 #define __TBB_USE_GENERIC_FETCH_STORE 1
143 #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1
144 #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1
145 
146 #if defined(TBB_WIN32_USE_CL_BUILTINS)
147 #if !__TBB_WIN8UI_SUPPORT
148 extern "C" __declspec(dllimport) int __stdcall SwitchToThread( void );
149 #define __TBB_Yield() SwitchToThread()
150 #else
151 #include<thread>
152 #define __TBB_Yield() std::this_thread::yield()
153 #endif
154 #else
155 #define __TBB_Yield() __yield()
156 #endif
157 
158 // Machine specific atomic operations
159 #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V)
160 #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V)
161 
162 template <typename T1,typename T2>
163 inline void __TBB_machine_OR( T1 *operand, T2 addend ) {
164  _InterlockedOr((long volatile *)operand, (long)addend);
165 }
166 
167 template <typename T1,typename T2>
168 inline void __TBB_machine_AND( T1 *operand, T2 addend ) {
169  _InterlockedAnd((long volatile *)operand, (long)addend);
170 }
171 
Definition: _flow_graph_async_msg_impl.h:32
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44