OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "cpu.h" | 28 #include "cpu.h" |
29 | 29 |
| 30 #if V8_CC_MSVC |
| 31 #include <intrin.h> // __cpuid() |
| 32 #endif |
| 33 |
30 #include <algorithm> | 34 #include <algorithm> |
31 #include <cctype> | 35 #include <cctype> |
32 #include <cstdio> | 36 #include <cstdio> |
33 #include <cstdlib> | 37 #include <cstdlib> |
34 #include <cstring> | 38 #include <cstring> |
35 | 39 |
36 #include "checks.h" | 40 #include "checks.h" |
37 | 41 |
38 namespace v8 { | 42 namespace v8 { |
39 namespace internal { | 43 namespace internal { |
40 | 44 |
41 #if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 | 45 #if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
42 | 46 |
43 #if V8_CC_MSVC | 47 // Define __cpuid() for non-MSVC compilers. |
44 | 48 #if !V8_CC_MSVC |
45 #include <intrin.h> // NOLINT | |
46 | |
47 #elif defined(__i386__) && defined(__pic__) | |
48 | 49 |
49 static V8_INLINE(void __cpuid(int cpu_info[4], int info_type)) { | 50 static V8_INLINE(void __cpuid(int cpu_info[4], int info_type)) { |
| 51 #if defined(__i386__) && defined(__pic__) |
| 52 // Make sure to preserve ebx, which contains the pointer |
| 53 // to the GOT in case we're generating PIC. |
50 __asm__ volatile ( | 54 __asm__ volatile ( |
51 "mov %%ebx, %%edi\n" | 55 "mov %%ebx, %%edi\n\t" |
52 "cpuid\n" | 56 "cpuid\n\t" |
53 "xchg %%edi, %%ebx\n" | 57 "xchg %%edi, %%ebx\n\t" |
54 : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) | 58 : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
55 : "a"(info_type) | 59 : "a"(info_type) |
56 ); | 60 ); |
57 } | 61 #else |
58 | |
59 #else // !V8_CC_MSVC || (!defined(__i386__) && !defined(__pic__)) | |
60 | |
61 static V8_INLINE(void __cpuid(int cpu_info[4], int info_type)) { | |
62 __asm__ volatile ( | 62 __asm__ volatile ( |
63 "cpuid \n\t" | 63 "cpuid \n\t" |
64 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) | 64 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
65 : "a"(info_type) | 65 : "a"(info_type) |
66 ); | 66 ); |
| 67 #endif // defined(__i386__) && defined(__pic__) |
67 } | 68 } |
68 | 69 |
69 #endif | 70 #endif // !V8_CC_MSVC |
70 | 71 |
71 #elif V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS | 72 #elif V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS |
72 | 73 |
73 #if V8_HOST_ARCH_ARM | 74 #if V8_HOST_ARCH_ARM |
74 | 75 |
75 // See <uapi/asm/hwcap.h> kernel header. | 76 // See <uapi/asm/hwcap.h> kernel header. |
76 /* | 77 /* |
77 * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP | 78 * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP |
78 */ | 79 */ |
79 #define HWCAP_SWP (1 << 0) | 80 #define HWCAP_SWP (1 << 0) |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // facility is universally available on the MIPS architectures, | 438 // facility is universally available on the MIPS architectures, |
438 // so it's up to individual OSes to provide such. | 439 // so it's up to individual OSes to provide such. |
439 CPUInfo cpu_info; | 440 CPUInfo cpu_info; |
440 char* cpu_model = cpu_info.ExtractField("cpu model"); | 441 char* cpu_model = cpu_info.ExtractField("cpu model"); |
441 has_fpu_ = HasListItem(cpu_model, "FPU"); | 442 has_fpu_ = HasListItem(cpu_model, "FPU"); |
442 delete[] cpu_model; | 443 delete[] cpu_model; |
443 #endif | 444 #endif |
444 } | 445 } |
445 | 446 |
446 } } // namespace v8::internal | 447 } } // namespace v8::internal |
OLD | NEW |