OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project 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 <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "atomicops.h" | 10 #include "atomicops.h" |
11 #include "platform.h" | 11 #include "utils.h" |
12 | 12 |
13 // This file only makes sense with atomicops_internals_x86_gcc.h -- it | 13 // This file only makes sense with atomicops_internals_x86_gcc.h -- it |
14 // depends on structs that are defined in that file. If atomicops.h | 14 // depends on structs that are defined in that file. If atomicops.h |
15 // doesn't sub-include that file, then we aren't needed, and shouldn't | 15 // doesn't sub-include that file, then we aren't needed, and shouldn't |
16 // try to do anything. | 16 // try to do anything. |
17 #ifdef V8_ATOMICOPS_INTERNALS_X86_GCC_H_ | 17 #ifdef V8_ATOMICOPS_INTERNALS_X86_GCC_H_ |
18 | 18 |
19 // Inline cpuid instruction. In PIC compilations, %ebx contains the address | 19 // Inline cpuid instruction. In PIC compilations, %ebx contains the address |
20 // of the global offset table. To avoid breaking such executables, this code | 20 // of the global offset table. To avoid breaking such executables, this code |
21 // must preserve that register's value across cpuid instructions. | 21 // must preserve that register's value across cpuid instructions. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 using v8::internal::AtomicOps_Internalx86CPUFeatures; | 55 using v8::internal::AtomicOps_Internalx86CPUFeatures; |
56 | 56 |
57 uint32_t eax = 0; | 57 uint32_t eax = 0; |
58 uint32_t ebx = 0; | 58 uint32_t ebx = 0; |
59 uint32_t ecx = 0; | 59 uint32_t ecx = 0; |
60 uint32_t edx = 0; | 60 uint32_t edx = 0; |
61 | 61 |
62 // Get vendor string (issue CPUID with eax = 0) | 62 // Get vendor string (issue CPUID with eax = 0) |
63 cpuid(eax, ebx, ecx, edx, 0); | 63 cpuid(eax, ebx, ecx, edx, 0); |
64 char vendor[13]; | 64 char vendor[13]; |
65 v8::internal::OS::MemCopy(vendor, &ebx, 4); | 65 v8::internal::MemCopy(vendor, &ebx, 4); |
66 v8::internal::OS::MemCopy(vendor + 4, &edx, 4); | 66 v8::internal::MemCopy(vendor + 4, &edx, 4); |
67 v8::internal::OS::MemCopy(vendor + 8, &ecx, 4); | 67 v8::internal::MemCopy(vendor + 8, &ecx, 4); |
68 vendor[12] = 0; | 68 vendor[12] = 0; |
69 | 69 |
70 // get feature flags in ecx/edx, and family/model in eax | 70 // get feature flags in ecx/edx, and family/model in eax |
71 cpuid(eax, ebx, ecx, edx, 1); | 71 cpuid(eax, ebx, ecx, edx, 1); |
72 | 72 |
73 int family = (eax >> 8) & 0xf; // family and model fields | 73 int family = (eax >> 8) & 0xf; // family and model fields |
74 int model = (eax >> 4) & 0xf; | 74 int model = (eax >> 4) & 0xf; |
75 if (family == 0xf) { // use extended family and model fields | 75 if (family == 0xf) { // use extended family and model fields |
76 family += (eax >> 20) & 0xff; | 76 family += (eax >> 20) & 0xff; |
77 model += ((eax >> 16) & 0xf) << 4; | 77 model += ((eax >> 16) & 0xf) << 4; |
(...skipping 25 matching lines...) Expand all Loading... |
103 | 103 |
104 | 104 |
105 // A global to get use initialized on startup via static initialization :/ | 105 // A global to get use initialized on startup via static initialization :/ |
106 AtomicOpsx86Initializer g_initer; | 106 AtomicOpsx86Initializer g_initer; |
107 | 107 |
108 } // namespace | 108 } // namespace |
109 | 109 |
110 #endif // if x86 | 110 #endif // if x86 |
111 | 111 |
112 #endif // ifdef V8_ATOMICOPS_INTERNALS_X86_GCC_H_ | 112 #endif // ifdef V8_ATOMICOPS_INTERNALS_X86_GCC_H_ |
OLD | NEW |