Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Side by Side Diff: runtime/vm/cpu_ia32.cc

Issue 120723003: Refactors CPU feature detection. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Cleanup Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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
7 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
8 7
9 #include "vm/cpu.h" 8 #include "vm/cpu.h"
10 9
10 #include "vm/assembler.h"
11 #include "vm/constants_ia32.h" 11 #include "vm/constants_ia32.h"
12 #include "vm/cpuinfo.h"
12 #include "vm/heap.h" 13 #include "vm/heap.h"
13 #include "vm/isolate.h" 14 #include "vm/isolate.h"
14 #include "vm/object.h" 15 #include "vm/object.h"
15 16
16 namespace dart { 17 namespace dart {
17 18
19 DEFINE_FLAG(bool, use_sse41, true, "Use SSE 4.1 if available");
20
18 void CPU::FlushICache(uword start, uword size) { 21 void CPU::FlushICache(uword start, uword size) {
19 // Nothing to be done here. 22 // Nothing to be done here.
20 } 23 }
21 24
22 25
23 const char* CPU::Id() { 26 const char* CPU::Id() {
24 return "ia32"; 27 return "ia32";
25 } 28 }
26 29
30
31 bool CPUFeatures::sse2_supported_ = false;
32 bool CPUFeatures::sse4_1_supported_ = false;
33 char CPUFeatures::hardware_[HARDWARE_LEN] = {0};
34 #ifdef DEBUG
35 bool CPUFeatures::initialized_ = false;
36 #endif
37
38
39 bool CPUFeatures::sse2_supported() {
40 DEBUG_ASSERT(initialized_);
41 return sse2_supported_;
42 }
43
44
45 bool CPUFeatures::sse4_1_supported() {
46 DEBUG_ASSERT(initialized_);
47 return sse4_1_supported_ && FLAG_use_sse41;
48 }
49
50
51 char* CPUFeatures::hardware() {
52 DEBUG_ASSERT(initialized_);
53 return hardware_;
54 }
55
56
57 #define __ assembler.
58
59 void CPUFeatures::InitOnce() {
60 Assembler assembler;
61 __ pushl(EBP);
62 __ pushl(EBX);
63 __ movl(EBP, ESP);
64 // Get feature information in ECX:EDX and return it in EDX:EAX.
65 __ movl(EAX, Immediate(1));
66 __ cpuid();
67 __ movl(EAX, EDX);
68 __ movl(EDX, ECX);
69 __ movl(ESP, EBP);
70 __ popl(EBX);
71 __ popl(EBP);
72 __ ret();
73
74 const Code& code =
75 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
76 Instructions& instructions = Instructions::Handle(code.instructions());
77 typedef uint64_t (*DetectCPUFeatures)();
78 uint64_t features =
79 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
80 sse2_supported_ = (features & kSSE2BitMask) != 0;
81 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
82
83 CpuInfo::Read();
84 CpuInfo::GetCpuModel(hardware_, HARDWARE_LEN);
85
86 #ifdef DEBUG
87 initialized_ = true;
88 #endif
89 }
90
91 #undef __
92
27 } // namespace dart 93 } // namespace dart
28 94
29 #endif // defined TARGET_ARCH_IA32 95 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698