Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
gcc_ia32_common.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef __TBB_machine_gcc_ia32_common_H
22 #define __TBB_machine_gcc_ia32_common_H
23 
24 #ifndef __TBB_Log2
25 //TODO: Add a higher-level function, e.g. tbb::internal::log2(), into tbb_stddef.h, which
26 //uses __TBB_Log2 and contains the assert and remove the assert from here and all other
27 //platform-specific headers.
28 template <typename T>
29 static inline intptr_t __TBB_machine_lg( T x ) {
30  __TBB_ASSERT(x>0, "The logarithm of a non-positive value is undefined.");
31  uintptr_t j, i = x;
32  __asm__("bsr %1,%0" : "=r"(j) : "r"(i));
33  return j;
34 }
35 #define __TBB_Log2(V) __TBB_machine_lg(V)
36 #endif /* !__TBB_Log2 */
37 
38 #ifndef __TBB_Pause
39 //TODO: check if raising a ratio of pause instructions to loop control instructions
40 //(via e.g. loop unrolling) gives any benefit for HT. E.g, the current implementation
41 //does about 2 CPU-consuming instructions for every pause instruction. Perhaps for
42 //high pause counts it should use an unrolled loop to raise the ratio, and thus free
43 //up more integer cycles for the other hyperthread. On the other hand, if the loop is
44 //unrolled too far, it won't fit in the core's loop cache, and thus take away
45 //instruction decode slots from the other hyperthread.
46 
47 //TODO: check if use of gcc __builtin_ia32_pause intrinsic gives a "some how" better performing code
48 static inline void __TBB_machine_pause( int32_t delay ) {
49  for (int32_t i = 0; i < delay; i++) {
50  __asm__ __volatile__("pause;");
51  }
52  return;
53 }
54 #define __TBB_Pause(V) __TBB_machine_pause(V)
55 #endif /* !__TBB_Pause */
56 
57 namespace tbb { namespace internal { typedef uint64_t machine_tsc_t; } }
59 #if __INTEL_COMPILER
60  return _rdtsc();
61 #else
62  tbb::internal::uint32_t hi, lo;
63  __asm__ __volatile__("rdtsc" : "=d"(hi), "=a"(lo));
64  return (tbb::internal::machine_tsc_t( hi ) << 32) | lo;
65 #endif
66 }
67 #define __TBB_time_stamp() __TBB_machine_time_stamp()
68 
69 // API to retrieve/update FPU control setting
70 #ifndef __TBB_CPU_CTL_ENV_PRESENT
71 #define __TBB_CPU_CTL_ENV_PRESENT 1
72 namespace tbb {
73 namespace internal {
74 class cpu_ctl_env {
75 private:
76  int mxcsr;
77  short x87cw;
78  static const int MXCSR_CONTROL_MASK = ~0x3f; /* all except last six status bits */
79 public:
80  bool operator!=( const cpu_ctl_env& ctl ) const { return mxcsr != ctl.mxcsr || x87cw != ctl.x87cw; }
81  void get_env() {
82  #if __TBB_ICC_12_0_INL_ASM_FSTCW_BROKEN
83  cpu_ctl_env loc_ctl;
84  __asm__ __volatile__ (
85  "stmxcsr %0\n\t"
86  "fstcw %1"
87  : "=m"(loc_ctl.mxcsr), "=m"(loc_ctl.x87cw)
88  );
89  *this = loc_ctl;
90  #else
91  __asm__ __volatile__ (
92  "stmxcsr %0\n\t"
93  "fstcw %1"
94  : "=m"(mxcsr), "=m"(x87cw)
95  );
96  #endif
98  }
99  void set_env() const {
100  __asm__ __volatile__ (
101  "ldmxcsr %0\n\t"
102  "fldcw %1"
103  : : "m"(mxcsr), "m"(x87cw)
104  );
105  }
106 };
107 } // namespace internal
108 } // namespace tbb
109 #endif /* !__TBB_CPU_CTL_ENV_PRESENT */
110 
111 #include "gcc_itsx.h"
112 
113 #endif /* __TBB_machine_gcc_ia32_common_H */
static intptr_t __TBB_machine_lg(T x)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static tbb::internal::machine_tsc_t __TBB_machine_time_stamp()
static const int MXCSR_CONTROL_MASK
static void __TBB_machine_pause(int32_t delay)
uint64_t machine_tsc_t
The graph class.
bool operator!=(const cpu_ctl_env &ctl) const

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.