| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 module gets enough CPU information to optimize the | 5 // This module gets enough CPU information to optimize the |
| 6 // atomicops module on x86. | 6 // atomicops module on x86. |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp)) | 33 : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp)) |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #if defined(cpuid) // initialize the struct only on x86 | 36 #if defined(cpuid) // initialize the struct only on x86 |
| 37 | 37 |
| 38 // Set the flags so that code will run correctly and conservatively, so even | 38 // Set the flags so that code will run correctly and conservatively, so even |
| 39 // if we haven't been initialized yet, we're probably single threaded, and our | 39 // if we haven't been initialized yet, we're probably single threaded, and our |
| 40 // default values should hopefully be pretty safe. | 40 // default values should hopefully be pretty safe. |
| 41 struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = { | 41 struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = { |
| 42 false, // bug can't exist before process spawns multiple threads | 42 false, // bug can't exist before process spawns multiple threads |
| 43 false, // no SSE2 | |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 namespace { | 45 namespace { |
| 47 | 46 |
| 48 // Initialize the AtomicOps_Internalx86CPUFeatures struct. | 47 // Initialize the AtomicOps_Internalx86CPUFeatures struct. |
| 49 void AtomicOps_Internalx86CPUFeaturesInit() { | 48 void AtomicOps_Internalx86CPUFeaturesInit() { |
| 50 uint32_t eax; | 49 uint32_t eax; |
| 51 uint32_t ebx; | 50 uint32_t ebx; |
| 52 uint32_t ecx; | 51 uint32_t ecx; |
| 53 uint32_t edx; | 52 uint32_t edx; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 75 // non-locked read-modify-write instruction. Rev F has this bug in | 74 // non-locked read-modify-write instruction. Rev F has this bug in |
| 76 // pre-release versions, but not in versions released to customers, | 75 // pre-release versions, but not in versions released to customers, |
| 77 // so we test only for Rev E, which is family 15, model 32..63 inclusive. | 76 // so we test only for Rev E, which is family 15, model 32..63 inclusive. |
| 78 if (strcmp(vendor, "AuthenticAMD") == 0 && // AMD | 77 if (strcmp(vendor, "AuthenticAMD") == 0 && // AMD |
| 79 family == 15 && | 78 family == 15 && |
| 80 32 <= model && model <= 63) { | 79 32 <= model && model <= 63) { |
| 81 AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true; | 80 AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true; |
| 82 } else { | 81 } else { |
| 83 AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false; | 82 AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false; |
| 84 } | 83 } |
| 85 | |
| 86 // edx bit 26 is SSE2 which we use to tell use whether we can use mfence | |
| 87 AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1); | |
| 88 } | 84 } |
| 89 | 85 |
| 90 class AtomicOpsx86Initializer { | 86 class AtomicOpsx86Initializer { |
| 91 public: | 87 public: |
| 92 AtomicOpsx86Initializer() { | 88 AtomicOpsx86Initializer() { |
| 93 AtomicOps_Internalx86CPUFeaturesInit(); | 89 AtomicOps_Internalx86CPUFeaturesInit(); |
| 94 } | 90 } |
| 95 }; | 91 }; |
| 96 | 92 |
| 97 // A global to get use initialized on startup via static initialization :/ | 93 // A global to get use initialized on startup via static initialization :/ |
| 98 AtomicOpsx86Initializer g_initer; | 94 AtomicOpsx86Initializer g_initer; |
| 99 | 95 |
| 100 } // namespace | 96 } // namespace |
| 101 | 97 |
| 102 #endif // if x86 | 98 #endif // if x86 |
| 103 | 99 |
| 104 #endif // ifdef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_ | 100 #endif // ifdef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_ |
| OLD | NEW |