| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 | 75 |
| 76 namespace v8 { | 76 namespace v8 { |
| 77 namespace internal { | 77 namespace internal { |
| 78 | 78 |
| 79 | 79 |
| 80 static Mutex* limit_mutex = NULL; | 80 static Mutex* limit_mutex = NULL; |
| 81 | 81 |
| 82 | 82 |
| 83 #ifdef __arm__ | 83 #ifdef __arm__ |
| 84 static bool CPUInfoContainsString(const char * search_string) { | |
| 85 const char* file_name = "/proc/cpuinfo"; | |
| 86 // This is written as a straight shot one pass parser | |
| 87 // and not using STL string and ifstream because, | |
| 88 // on Linux, it's reading from a (non-mmap-able) | |
| 89 // character special device. | |
| 90 FILE* f = NULL; | |
| 91 const char* what = search_string; | |
| 92 | |
| 93 if (NULL == (f = fopen(file_name, "r"))) { | |
| 94 OS::PrintError("Failed to open /proc/cpuinfo\n"); | |
| 95 return false; | |
| 96 } | |
| 97 | |
| 98 int k; | |
| 99 while (EOF != (k = fgetc(f))) { | |
| 100 if (k == *what) { | |
| 101 ++what; | |
| 102 while ((*what != '\0') && (*what == fgetc(f))) { | |
| 103 ++what; | |
| 104 } | |
| 105 if (*what == '\0') { | |
| 106 fclose(f); | |
| 107 return true; | |
| 108 } else { | |
| 109 what = search_string; | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 fclose(f); | |
| 114 | |
| 115 // Did not find string in the proc file. | |
| 116 return false; | |
| 117 } | |
| 118 | |
| 119 | |
| 120 bool OS::ArmCpuHasFeature(CpuFeature feature) { | |
| 121 const char* search_string = NULL; | |
| 122 // Simple detection of VFP at runtime for Linux. | |
| 123 // It is based on /proc/cpuinfo, which reveals hardware configuration | |
| 124 // to user-space applications. According to ARM (mid 2009), no similar | |
| 125 // facility is universally available on the ARM architectures, | |
| 126 // so it's up to individual OSes to provide such. | |
| 127 switch (feature) { | |
| 128 case VFP3: | |
| 129 search_string = "vfpv3"; | |
| 130 break; | |
| 131 case NEON: | |
| 132 search_string = "neon"; | |
| 133 break; | |
| 134 case ARMv7: | |
| 135 search_string = "ARMv7"; | |
| 136 break; | |
| 137 case SUDIV: | |
| 138 search_string = "idiva"; | |
| 139 break; | |
| 140 case VFP32DREGS: | |
| 141 // This case is handled specially below. | |
| 142 break; | |
| 143 default: | |
| 144 UNREACHABLE(); | |
| 145 } | |
| 146 | |
| 147 if (feature == VFP32DREGS) { | |
| 148 return ArmCpuHasFeature(VFP3) && !CPUInfoContainsString("d16"); | |
| 149 } | |
| 150 | |
| 151 if (CPUInfoContainsString(search_string)) { | |
| 152 return true; | |
| 153 } | |
| 154 | |
| 155 if (feature == VFP3) { | |
| 156 // Some old kernels will report vfp not vfpv3. Here we make a last attempt | |
| 157 // to detect vfpv3 by checking for vfp *and* neon, since neon is only | |
| 158 // available on architectures with vfpv3. | |
| 159 // Checking neon on its own is not enough as it is possible to have neon | |
| 160 // without vfp. | |
| 161 if (CPUInfoContainsString("vfp") && CPUInfoContainsString("neon")) { | |
| 162 return true; | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 return false; | |
| 167 } | |
| 168 | |
| 169 | |
| 170 CpuImplementer OS::GetCpuImplementer() { | |
| 171 static bool use_cached_value = false; | |
| 172 static CpuImplementer cached_value = UNKNOWN_IMPLEMENTER; | |
| 173 if (use_cached_value) { | |
| 174 return cached_value; | |
| 175 } | |
| 176 if (CPUInfoContainsString("CPU implementer\t: 0x41")) { | |
| 177 cached_value = ARM_IMPLEMENTER; | |
| 178 } else if (CPUInfoContainsString("CPU implementer\t: 0x51")) { | |
| 179 cached_value = QUALCOMM_IMPLEMENTER; | |
| 180 } else { | |
| 181 cached_value = UNKNOWN_IMPLEMENTER; | |
| 182 } | |
| 183 use_cached_value = true; | |
| 184 return cached_value; | |
| 185 } | |
| 186 | |
| 187 | |
| 188 CpuPart OS::GetCpuPart(CpuImplementer implementer) { | |
| 189 static bool use_cached_value = false; | |
| 190 static CpuPart cached_value = CPU_UNKNOWN; | |
| 191 if (use_cached_value) { | |
| 192 return cached_value; | |
| 193 } | |
| 194 if (implementer == ARM_IMPLEMENTER) { | |
| 195 if (CPUInfoContainsString("CPU part\t: 0xc0f")) { | |
| 196 cached_value = CORTEX_A15; | |
| 197 } else if (CPUInfoContainsString("CPU part\t: 0xc0c")) { | |
| 198 cached_value = CORTEX_A12; | |
| 199 } else if (CPUInfoContainsString("CPU part\t: 0xc09")) { | |
| 200 cached_value = CORTEX_A9; | |
| 201 } else if (CPUInfoContainsString("CPU part\t: 0xc08")) { | |
| 202 cached_value = CORTEX_A8; | |
| 203 } else if (CPUInfoContainsString("CPU part\t: 0xc07")) { | |
| 204 cached_value = CORTEX_A7; | |
| 205 } else if (CPUInfoContainsString("CPU part\t: 0xc05")) { | |
| 206 cached_value = CORTEX_A5; | |
| 207 } else { | |
| 208 cached_value = CPU_UNKNOWN; | |
| 209 } | |
| 210 } else { | |
| 211 cached_value = CPU_UNKNOWN; | |
| 212 } | |
| 213 use_cached_value = true; | |
| 214 return cached_value; | |
| 215 } | |
| 216 | |
| 217 | 84 |
| 218 bool OS::ArmUsingHardFloat() { | 85 bool OS::ArmUsingHardFloat() { |
| 219 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify | 86 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify |
| 220 // the Floating Point ABI used (PCS stands for Procedure Call Standard). | 87 // the Floating Point ABI used (PCS stands for Procedure Call Standard). |
| 221 // We use these as well as a couple of other defines to statically determine | 88 // We use these as well as a couple of other defines to statically determine |
| 222 // what FP ABI used. | 89 // what FP ABI used. |
| 223 // GCC versions 4.4 and below don't support hard-fp. | 90 // GCC versions 4.4 and below don't support hard-fp. |
| 224 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or | 91 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or |
| 225 // __ARM_PCS_VFP. | 92 // __ARM_PCS_VFP. |
| 226 | 93 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 249 "http://code.google.com/p/v8/issues/detail?id=2140" | 116 "http://code.google.com/p/v8/issues/detail?id=2140" |
| 250 | 117 |
| 251 #endif | 118 #endif |
| 252 #endif | 119 #endif |
| 253 #undef GCC_VERSION | 120 #undef GCC_VERSION |
| 254 } | 121 } |
| 255 | 122 |
| 256 #endif // def __arm__ | 123 #endif // def __arm__ |
| 257 | 124 |
| 258 | 125 |
| 259 #ifdef __mips__ | |
| 260 bool OS::MipsCpuHasFeature(CpuFeature feature) { | |
| 261 const char* search_string = NULL; | |
| 262 const char* file_name = "/proc/cpuinfo"; | |
| 263 // Simple detection of FPU at runtime for Linux. | |
| 264 // It is based on /proc/cpuinfo, which reveals hardware configuration | |
| 265 // to user-space applications. According to MIPS (early 2010), no similar | |
| 266 // facility is universally available on the MIPS architectures, | |
| 267 // so it's up to individual OSes to provide such. | |
| 268 // | |
| 269 // This is written as a straight shot one pass parser | |
| 270 // and not using STL string and ifstream because, | |
| 271 // on Linux, it's reading from a (non-mmap-able) | |
| 272 // character special device. | |
| 273 | |
| 274 switch (feature) { | |
| 275 case FPU: | |
| 276 search_string = "FPU"; | |
| 277 break; | |
| 278 default: | |
| 279 UNREACHABLE(); | |
| 280 } | |
| 281 | |
| 282 FILE* f = NULL; | |
| 283 const char* what = search_string; | |
| 284 | |
| 285 if (NULL == (f = fopen(file_name, "r"))) { | |
| 286 OS::PrintError("Failed to open /proc/cpuinfo\n"); | |
| 287 return false; | |
| 288 } | |
| 289 | |
| 290 int k; | |
| 291 while (EOF != (k = fgetc(f))) { | |
| 292 if (k == *what) { | |
| 293 ++what; | |
| 294 while ((*what != '\0') && (*what == fgetc(f))) { | |
| 295 ++what; | |
| 296 } | |
| 297 if (*what == '\0') { | |
| 298 fclose(f); | |
| 299 return true; | |
| 300 } else { | |
| 301 what = search_string; | |
| 302 } | |
| 303 } | |
| 304 } | |
| 305 fclose(f); | |
| 306 | |
| 307 // Did not find string in the proc file. | |
| 308 return false; | |
| 309 } | |
| 310 #endif // def __mips__ | |
| 311 | |
| 312 | |
| 313 const char* OS::LocalTimezone(double time) { | 126 const char* OS::LocalTimezone(double time) { |
| 314 if (std::isnan(time)) return ""; | 127 if (std::isnan(time)) return ""; |
| 315 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | 128 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); |
| 316 struct tm* t = localtime(&tv); | 129 struct tm* t = localtime(&tv); |
| 317 if (NULL == t) return ""; | 130 if (NULL == t) return ""; |
| 318 return t->tm_zone; | 131 return t->tm_zone; |
| 319 } | 132 } |
| 320 | 133 |
| 321 | 134 |
| 322 double OS::LocalTimeOffset() { | 135 double OS::LocalTimeOffset() { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 limit_mutex = CreateMutex(); | 575 limit_mutex = CreateMutex(); |
| 763 } | 576 } |
| 764 | 577 |
| 765 | 578 |
| 766 void OS::TearDown() { | 579 void OS::TearDown() { |
| 767 delete limit_mutex; | 580 delete limit_mutex; |
| 768 } | 581 } |
| 769 | 582 |
| 770 | 583 |
| 771 } } // namespace v8::internal | 584 } } // namespace v8::internal |
| OLD | NEW |