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

Side by Side Diff: runtime/vm/cpu_x64.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) 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 6
7 #if defined(TARGET_ARCH_X64) 7 #if defined(TARGET_ARCH_X64)
8 8
9 #include "vm/cpu.h" 9 #include "vm/cpu.h"
10 10
11 #include "vm/assembler.h"
11 #include "vm/constants_x64.h" 12 #include "vm/constants_x64.h"
13 #include "vm/cpuinfo.h"
12 #include "vm/heap.h" 14 #include "vm/heap.h"
13 #include "vm/isolate.h" 15 #include "vm/isolate.h"
14 #include "vm/object.h" 16 #include "vm/object.h"
15 17
16 namespace dart { 18 namespace dart {
17 19
20 DEFINE_FLAG(bool, use_sse41, true, "Use SSE 4.1 if available");
21
22
18 void CPU::FlushICache(uword start, uword size) { 23 void CPU::FlushICache(uword start, uword size) {
19 // Nothing to be done here. 24 // Nothing to be done here.
20 } 25 }
21 26
22 27
23 const char* CPU::Id() { 28 const char* CPU::Id() {
24 return "x64"; 29 return "x64";
25 } 30 }
26 31
32
33 bool CPUFeatures::sse4_1_supported_ = false;
34 char CPUFeatures::hardware_[HARDWARE_LEN] = {0};
35 #ifdef DEBUG
36 bool CPUFeatures::initialized_ = false;
37 #endif
38
39
40 bool CPUFeatures::sse4_1_supported() {
41 DEBUG_ASSERT(initialized_);
42 return sse4_1_supported_ && FLAG_use_sse41;
43 }
44
45
46 char* CPUFeatures::hardware() {
47 DEBUG_ASSERT(initialized_);
48 return hardware_;
49 }
50
51
52 #define __ assembler.
53 void CPUFeatures::InitOnce() {
54 Assembler assembler;
55 __ pushq(RBP);
56 __ pushq(RBX);
57 __ movq(RBP, RSP);
58 // Get feature information in ECX:EDX and return it in RAX.
59 // Note that cpuid operates the same in 64-bit and 32-bit mode.
60 __ movq(RAX, Immediate(1));
61 __ cpuid();
62 __ movl(RAX, RCX); // Zero extended.
63 __ shlq(RAX, Immediate(32));
64 __ movl(RCX, RDX); // Zero extended.
65 __ orq(RAX, RCX);
66 __ movq(RSP, RBP);
67 __ popq(RBX);
68 __ popq(RBP);
69 __ ret();
70
71 const Code& code =
72 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
73 Instructions& instructions = Instructions::Handle(code.instructions());
74 typedef uint64_t (*DetectCPUFeatures)();
75 uint64_t features =
76 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
77 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
78
79 CpuInfo::Read();
80 CpuInfo::GetCpuModel(hardware_, HARDWARE_LEN);
81
82 #ifdef DEBUG
83 initialized_ = true;
84 #endif
85 }
86 #undef __
87
27 } // namespace dart 88 } // namespace dart
28 89
29 #endif // defined TARGET_ARCH_X64 90 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698