OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
9 #include "vm/cpu_arm.h" | 9 #include "vm/cpu_arm.h" |
10 | 10 |
11 #include "vm/assembler.h" | 11 #include "vm/assembler.h" |
12 #include "vm/cpuinfo.h" | 12 #include "vm/cpuinfo.h" |
13 #include "vm/heap.h" | 13 #include "vm/heap.h" |
14 #include "vm/isolate.h" | 14 #include "vm/isolate.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 #include "vm/simulator.h" | 16 #include "vm/simulator.h" |
17 | 17 |
18 #if !defined(USING_SIMULATOR) | 18 #if !defined(USING_SIMULATOR) |
19 #include <sys/syscall.h> /* NOLINT */ | 19 #include <sys/syscall.h> /* NOLINT */ |
20 #include <unistd.h> /* NOLINT */ | 20 #include <unistd.h> /* NOLINT */ |
21 #endif | 21 #endif |
22 | 22 |
23 // ARM version differences. | 23 // ARM version differences. |
24 // We support three major 32-bit ARM ISA versions: ARMv5TE, ARMv6 and variants, | 24 // We support three major 32-bit ARM ISA versions: ARMv5TE, ARMv6 and variants, |
25 // and ARMv7 and variants. For each of these we detect the presence of vfp, | 25 // and ARMv7 and variants. For each of these we detect the presence of vfp, |
26 // neon, and integer division instructions. Considering ARMv5TE as the baseline, | 26 // neon, and integer division instructions. Considering ARMv5TE as the baseline, |
27 // later versions add the following features/instructions that we use: | 27 // later versions add the following features/instructions that we use: |
28 // | 28 // |
29 // ARMv6: | 29 // ARMv6: |
30 // - PC read offset in store instructions is 8 rather than 12, matching the | 30 // - PC read offset in store instructions is 8 rather than 12, matching the |
(...skipping 23 matching lines...) Expand all Loading... |
54 // of ldrd and strd, these instructions are emulated with two load or store | 54 // of ldrd and strd, these instructions are emulated with two load or store |
55 // instructions on ARMv5TE. On ARMv6 and on, we assume that the kernel is | 55 // instructions on ARMv5TE. On ARMv6 and on, we assume that the kernel is |
56 // set up to fixup unaligned accesses. This can be verified by checking | 56 // set up to fixup unaligned accesses. This can be verified by checking |
57 // /proc/cpu/alignment on modern Linux systems. | 57 // /proc/cpu/alignment on modern Linux systems. |
58 | 58 |
59 namespace dart { | 59 namespace dart { |
60 | 60 |
61 #if defined(TARGET_ARCH_ARM_5TE) | 61 #if defined(TARGET_ARCH_ARM_5TE) |
62 DEFINE_FLAG(bool, use_vfp, false, "Use vfp instructions if supported"); | 62 DEFINE_FLAG(bool, use_vfp, false, "Use vfp instructions if supported"); |
63 DEFINE_FLAG(bool, use_neon, false, "Use neon instructions if supported"); | 63 DEFINE_FLAG(bool, use_neon, false, "Use neon instructions if supported"); |
64 DEFINE_FLAG(bool, use_integer_division, false, | 64 DEFINE_FLAG(bool, |
| 65 use_integer_division, |
| 66 false, |
65 "Use integer division instruction if supported"); | 67 "Use integer division instruction if supported"); |
66 #elif defined(TARGET_ARCH_ARM_6) | 68 #elif defined(TARGET_ARCH_ARM_6) |
67 DEFINE_FLAG(bool, use_vfp, true, "Use vfp instructions if supported"); | 69 DEFINE_FLAG(bool, use_vfp, true, "Use vfp instructions if supported"); |
68 DEFINE_FLAG(bool, use_neon, false, "Use neon instructions if supported"); | 70 DEFINE_FLAG(bool, use_neon, false, "Use neon instructions if supported"); |
69 DEFINE_FLAG(bool, use_integer_division, false, | 71 DEFINE_FLAG(bool, |
| 72 use_integer_division, |
| 73 false, |
70 "Use integer division instruction if supported"); | 74 "Use integer division instruction if supported"); |
71 #else | 75 #else |
72 DEFINE_FLAG(bool, use_vfp, true, "Use vfp instructions if supported"); | 76 DEFINE_FLAG(bool, use_vfp, true, "Use vfp instructions if supported"); |
73 DEFINE_FLAG(bool, use_neon, true, "Use neon instructions if supported"); | 77 DEFINE_FLAG(bool, use_neon, true, "Use neon instructions if supported"); |
74 DEFINE_FLAG(bool, use_integer_division, true, | 78 DEFINE_FLAG(bool, |
| 79 use_integer_division, |
| 80 true, |
75 "Use integer division instruction if supported"); | 81 "Use integer division instruction if supported"); |
76 #endif | 82 #endif |
77 | 83 |
78 #if defined(USING_SIMULATOR) | 84 #if defined(USING_SIMULATOR) |
79 #if defined(TARGET_ARCH_ARM_5TE) | 85 #if defined(TARGET_ARCH_ARM_5TE) |
80 DEFINE_FLAG(bool, sim_use_hardfp, false, "Use the softfp ABI."); | 86 DEFINE_FLAG(bool, sim_use_hardfp, false, "Use the softfp ABI."); |
81 #else | 87 #else |
82 DEFINE_FLAG(bool, sim_use_hardfp, true, "Use the softfp ABI."); | 88 DEFINE_FLAG(bool, sim_use_hardfp, true, "Use the softfp ABI."); |
83 #endif | 89 #endif |
84 #endif | 90 #endif |
85 | 91 |
86 void CPU::FlushICache(uword start, uword size) { | 92 void CPU::FlushICache(uword start, uword size) { |
87 #if TARGET_OS_IOS | 93 #if TARGET_OS_IOS |
88 // Precompilation never patches code so there should be no I cache flushes. | 94 // Precompilation never patches code so there should be no I cache flushes. |
89 UNREACHABLE(); | 95 UNREACHABLE(); |
90 #endif | 96 #endif |
91 | 97 |
92 #if !defined(USING_SIMULATOR) && !TARGET_OS_IOS | 98 #if !defined(USING_SIMULATOR) && !TARGET_OS_IOS |
93 // Nothing to do. Flushing no instructions. | 99 // Nothing to do. Flushing no instructions. |
94 if (size == 0) { | 100 if (size == 0) { |
95 return; | 101 return; |
96 } | 102 } |
97 | 103 |
98 // ARM recommends using the gcc intrinsic __clear_cache on Linux, and the | 104 // ARM recommends using the gcc intrinsic __clear_cache on Linux, and the |
99 // library call cacheflush from unistd.h on Android: | 105 // library call cacheflush from unistd.h on Android: |
100 // blogs.arm.com/software-enablement/141-caches-and-self-modifying-code/ | 106 // blogs.arm.com/software-enablement/141-caches-and-self-modifying-code/ |
101 #if defined(__linux__) && !defined(ANDROID) | 107 #if defined(__linux__) && !defined(ANDROID) |
102 extern void __clear_cache(char*, char*); | 108 extern void __clear_cache(char*, char*); |
103 char* beg = reinterpret_cast<char*>(start); | 109 char* beg = reinterpret_cast<char*>(start); |
104 char* end = reinterpret_cast<char*>(start + size); | 110 char* end = reinterpret_cast<char*>(start + size); |
105 ::__clear_cache(beg, end); | 111 ::__clear_cache(beg, end); |
106 #elif defined(ANDROID) | 112 #elif defined(ANDROID) |
107 cacheflush(start, start + size, 0); | 113 cacheflush(start, start + size, 0); |
108 #else | 114 #else |
109 #error FlushICache only tested/supported on Linux and Android | 115 #error FlushICache only tested/supported on Linux and Android |
110 #endif | 116 #endif |
111 #endif | 117 #endif |
112 } | 118 } |
113 | 119 |
114 | 120 |
115 const char* CPU::Id() { | 121 const char* CPU::Id() { |
116 return | 122 return |
117 #if defined(USING_SIMULATOR) | 123 #if defined(USING_SIMULATOR) |
118 "sim" | 124 "sim" |
119 #endif // defined(USING_SIMULATOR) | 125 #endif // defined(USING_SIMULATOR) |
120 "arm"; | 126 "arm"; |
121 } | 127 } |
122 | 128 |
123 | 129 |
124 bool HostCPUFeatures::integer_division_supported_ = false; | 130 bool HostCPUFeatures::integer_division_supported_ = false; |
125 bool HostCPUFeatures::vfp_supported_ = false; | 131 bool HostCPUFeatures::vfp_supported_ = false; |
126 bool HostCPUFeatures::neon_supported_ = false; | 132 bool HostCPUFeatures::neon_supported_ = false; |
127 bool HostCPUFeatures::hardfp_supported_ = false; | 133 bool HostCPUFeatures::hardfp_supported_ = false; |
128 const char* HostCPUFeatures::hardware_ = NULL; | 134 const char* HostCPUFeatures::hardware_ = NULL; |
129 ARMVersion HostCPUFeatures::arm_version_ = ARMvUnknown; | 135 ARMVersion HostCPUFeatures::arm_version_ = ARMvUnknown; |
130 intptr_t HostCPUFeatures::store_pc_read_offset_ = 8; | 136 intptr_t HostCPUFeatures::store_pc_read_offset_ = 8; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 202 |
197 // Has integer division. | 203 // Has integer division. |
198 // Special cases: | 204 // Special cases: |
199 // - Qualcomm Krait CPUs (QCT APQ8064) in Nexus 4 and 7 incorrectly report | 205 // - Qualcomm Krait CPUs (QCT APQ8064) in Nexus 4 and 7 incorrectly report |
200 // that they lack integer division. | 206 // that they lack integer division. |
201 // - Marvell Armada 370/XP incorrectly reports that it has integer division. | 207 // - Marvell Armada 370/XP incorrectly reports that it has integer division. |
202 // - The Pixel lacks integer division even though ARMv8 requires it in A32. | 208 // - The Pixel lacks integer division even though ARMv8 requires it in A32. |
203 bool is_krait = CpuInfo::FieldContains(kCpuInfoHardware, "QCT APQ8064"); | 209 bool is_krait = CpuInfo::FieldContains(kCpuInfoHardware, "QCT APQ8064"); |
204 bool is_armada_370xp = | 210 bool is_armada_370xp = |
205 CpuInfo::FieldContains(kCpuInfoHardware, "Marvell Armada 370/XP"); | 211 CpuInfo::FieldContains(kCpuInfoHardware, "Marvell Armada 370/XP"); |
206 bool is_pixel = | 212 bool is_pixel = CpuInfo::FieldContains(kCpuInfoHardware, "MSM8996pro"); |
207 CpuInfo::FieldContains(kCpuInfoHardware, "MSM8996pro"); | |
208 if (is_krait) { | 213 if (is_krait) { |
209 integer_division_supported_ = FLAG_use_integer_division; | 214 integer_division_supported_ = FLAG_use_integer_division; |
210 } else if (is_armada_370xp || is_pixel) { | 215 } else if (is_armada_370xp || is_pixel) { |
211 integer_division_supported_ = false; | 216 integer_division_supported_ = false; |
212 } else { | 217 } else { |
213 integer_division_supported_ = | 218 integer_division_supported_ = |
214 (CpuInfo::FieldContains(kCpuInfoFeatures, "idiva") || is_arm64) && | 219 (CpuInfo::FieldContains(kCpuInfoFeatures, "idiva") || is_arm64) && |
215 FLAG_use_integer_division; | 220 FLAG_use_integer_division; |
216 } | 221 } |
217 neon_supported_ = | 222 neon_supported_ = |
218 (CpuInfo::FieldContains(kCpuInfoFeatures, "neon") || is_arm64) && | 223 (CpuInfo::FieldContains(kCpuInfoFeatures, "neon") || is_arm64) && |
219 FLAG_use_vfp && FLAG_use_neon; | 224 FLAG_use_vfp && FLAG_use_neon; |
220 | 225 |
221 // Use the cross-compiler's predefined macros to determine whether we should | 226 // Use the cross-compiler's predefined macros to determine whether we should |
222 // use the hard or soft float ABI. | 227 // use the hard or soft float ABI. |
223 #if defined(__ARM_PCS_VFP) | 228 #if defined(__ARM_PCS_VFP) |
224 hardfp_supported_ = true; | 229 hardfp_supported_ = true; |
225 #else | 230 #else |
226 hardfp_supported_ = false; | 231 hardfp_supported_ = false; |
227 #endif | 232 #endif |
228 | 233 |
229 #if defined(DEBUG) | 234 #if defined(DEBUG) |
230 initialized_ = true; | 235 initialized_ = true; |
231 #endif | 236 #endif |
232 } | 237 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 ASSERT(hardware_ != NULL); | 280 ASSERT(hardware_ != NULL); |
276 free(const_cast<char*>(hardware_)); | 281 free(const_cast<char*>(hardware_)); |
277 hardware_ = NULL; | 282 hardware_ = NULL; |
278 CpuInfo::Cleanup(); | 283 CpuInfo::Cleanup(); |
279 } | 284 } |
280 #endif // !defined(USING_SIMULATOR) | 285 #endif // !defined(USING_SIMULATOR) |
281 | 286 |
282 } // namespace dart | 287 } // namespace dart |
283 | 288 |
284 #endif // defined TARGET_ARCH_ARM | 289 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |