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

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

Issue 120723003: Refactors CPU feature detection. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/cpu.h"
9 #include "vm/heap.h" 10 #include "vm/heap.h"
10 #include "vm/memory_region.h" 11 #include "vm/memory_region.h"
11 #include "vm/runtime_entry.h" 12 #include "vm/runtime_entry.h"
12 #include "vm/stack_frame.h" 13 #include "vm/stack_frame.h"
13 #include "vm/stub_code.h" 14 #include "vm/stub_code.h"
14 15
15 namespace dart { 16 namespace dart {
16 17
17 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message."); 18 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message.");
18 DEFINE_FLAG(bool, use_sse41, true, "Use SSE 4.1 if available");
19 DECLARE_FLAG(bool, inline_alloc); 19 DECLARE_FLAG(bool, inline_alloc);
20 20
21 21
22 bool CPUFeatures::sse4_1_supported_ = false;
23 #ifdef DEBUG
24 bool CPUFeatures::initialized_ = false;
25 #endif
26
27 bool CPUFeatures::sse4_1_supported() {
28 DEBUG_ASSERT(initialized_);
29 return sse4_1_supported_ && FLAG_use_sse41;
30 }
31
32
33 #define __ assembler.
34
35 void CPUFeatures::InitOnce() {
36 Assembler assembler;
37 __ pushq(RBP);
38 __ pushq(RBX);
39 __ movq(RBP, RSP);
40 // Get feature information in ECX:EDX and return it in RAX.
41 // Note that cpuid operates the same in 64-bit and 32-bit mode.
42 __ movq(RAX, Immediate(1));
43 __ cpuid();
44 __ movl(RAX, RCX); // Zero extended.
45 __ shlq(RAX, Immediate(32));
46 __ movl(RCX, RDX); // Zero extended.
47 __ orq(RAX, RCX);
48 __ movq(RSP, RBP);
49 __ popq(RBX);
50 __ popq(RBP);
51 __ ret();
52
53 const Code& code =
54 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
55 Instructions& instructions = Instructions::Handle(code.instructions());
56 typedef uint64_t (*DetectCPUFeatures)();
57 uint64_t features =
58 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
59 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
60 #ifdef DEBUG
61 initialized_ = true;
62 #endif
63 }
64
65 #undef __
66
67
68 Assembler::Assembler(bool use_far_branches) 22 Assembler::Assembler(bool use_far_branches)
69 : buffer_(), 23 : buffer_(),
70 object_pool_(GrowableObjectArray::Handle()), 24 object_pool_(GrowableObjectArray::Handle()),
71 patchable_pool_entries_(), 25 patchable_pool_entries_(),
72 prologue_offset_(-1), 26 prologue_offset_(-1),
73 comments_() { 27 comments_() {
74 // Far branching mode is only needed and implemented for MIPS and ARM. 28 // Far branching mode is only needed and implemented for MIPS and ARM.
75 ASSERT(!use_far_branches); 29 ASSERT(!use_far_branches);
76 if (Isolate::Current() != Dart::vm_isolate()) { 30 if (Isolate::Current() != Dart::vm_isolate()) {
77 object_pool_ = GrowableObjectArray::New(Heap::kOld); 31 object_pool_ = GrowableObjectArray::New(Heap::kOld);
(...skipping 3220 matching lines...) Expand 10 before | Expand all | Expand 10 after
3298 3252
3299 3253
3300 const char* Assembler::FpuRegisterName(FpuRegister reg) { 3254 const char* Assembler::FpuRegisterName(FpuRegister reg) {
3301 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); 3255 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters));
3302 return xmm_reg_names[reg]; 3256 return xmm_reg_names[reg];
3303 } 3257 }
3304 3258
3305 } // namespace dart 3259 } // namespace dart
3306 3260
3307 #endif // defined TARGET_ARCH_X64 3261 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/assembler_x64.h ('k') | runtime/vm/cpu.h » ('j') | runtime/vm/cpuinfo_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698