Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: base/atomicops_internals_x86_gcc.h

Issue 291993003: base atomicops: Drop SSE2 detection, we always require SSE2 starting in m35. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweak Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/atomicops_internals_x86_gcc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file is an internal atomic implementation, use base/atomicops.h instead. 5 // This file is an internal atomic implementation, use base/atomicops.h instead.
6 6
7 #ifndef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_ 7 #ifndef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_
8 #define BASE_ATOMICOPS_INTERNALS_X86_GCC_H_ 8 #define BASE_ATOMICOPS_INTERNALS_X86_GCC_H_
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 11
12 // This struct is not part of the public API of this module; clients may not 12 // This struct is not part of the public API of this module; clients may not
13 // use it. (However, it's exported via BASE_EXPORT because clients implicitly 13 // use it. (However, it's exported via BASE_EXPORT because clients implicitly
14 // do use it at link time by inlining these functions.) 14 // do use it at link time by inlining these functions.)
15 // Features of this x86. Values may not be correct before main() is run, 15 // Features of this x86. Values may not be correct before main() is run,
16 // but are set conservatively. 16 // but are set conservatively.
17 struct AtomicOps_x86CPUFeatureStruct { 17 struct AtomicOps_x86CPUFeatureStruct {
18 bool has_amd_lock_mb_bug; // Processor has AMD memory-barrier bug; do lfence 18 bool has_amd_lock_mb_bug; // Processor has AMD memory-barrier bug; do lfence
19 // after acquire compare-and-swap. 19 // after acquire compare-and-swap.
20 bool has_sse2; // Processor has SSE2.
21 }; 20 };
22 BASE_EXPORT extern struct AtomicOps_x86CPUFeatureStruct 21 BASE_EXPORT extern struct AtomicOps_x86CPUFeatureStruct
23 AtomicOps_Internalx86CPUFeatures; 22 AtomicOps_Internalx86CPUFeatures;
24 23
25 #define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") 24 #define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory")
26 25
27 namespace base { 26 namespace base {
28 namespace subtle { 27 namespace subtle {
29 28
30 // 32-bit low-level operations on any platform. 29 // 32-bit low-level operations on any platform.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, 84 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
86 Atomic32 old_value, 85 Atomic32 old_value,
87 Atomic32 new_value) { 86 Atomic32 new_value) {
88 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 87 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
89 } 88 }
90 89
91 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { 90 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
92 *ptr = value; 91 *ptr = value;
93 } 92 }
94 93
95 #if defined(__x86_64__)
96
97 // 64-bit implementations of memory barrier can be simpler, because it
98 // "mfence" is guaranteed to exist.
99 inline void MemoryBarrier() { 94 inline void MemoryBarrier() {
100 __asm__ __volatile__("mfence" : : : "memory"); 95 __asm__ __volatile__("mfence" : : : "memory");
101 } 96 }
102 97
103 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { 98 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
104 *ptr = value; 99 *ptr = value;
105 MemoryBarrier(); 100 MemoryBarrier();
106 } 101 }
107 102
108 #else
109
110 inline void MemoryBarrier() {
111 if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
112 __asm__ __volatile__("mfence" : : : "memory");
113 } else { // mfence is faster but not present on PIII
114 Atomic32 x = 0;
115 NoBarrier_AtomicExchange(&x, 0); // acts as a barrier on PIII
116 }
117 }
118
119 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
120 if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
121 *ptr = value;
122 __asm__ __volatile__("mfence" : : : "memory");
123 } else {
124 NoBarrier_AtomicExchange(ptr, value);
125 // acts as a barrier on PIII
126 }
127 }
128 #endif
129
130 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { 103 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
131 ATOMICOPS_COMPILER_BARRIER(); 104 ATOMICOPS_COMPILER_BARRIER();
132 *ptr = value; // An x86 store acts as a release barrier. 105 *ptr = value; // An x86 store acts as a release barrier.
133 // See comments in Atomic64 version of Release_Store(), below. 106 // See comments in Atomic64 version of Release_Store(), below.
134 } 107 }
135 108
136 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { 109 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
137 return *ptr; 110 return *ptr;
138 } 111 }
139 112
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 233 }
261 234
262 #endif // defined(__x86_64__) 235 #endif // defined(__x86_64__)
263 236
264 } // namespace base::subtle 237 } // namespace base::subtle
265 } // namespace base 238 } // namespace base
266 239
267 #undef ATOMICOPS_COMPILER_BARRIER 240 #undef ATOMICOPS_COMPILER_BARRIER
268 241
269 #endif // BASE_ATOMICOPS_INTERNALS_X86_GCC_H_ 242 #endif // BASE_ATOMICOPS_INTERNALS_X86_GCC_H_
OLDNEW
« no previous file with comments | « no previous file | base/atomicops_internals_x86_gcc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698