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

Side by Side Diff: runtime/vm/assembler_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) 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_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/cpu.h"
10 #include "vm/heap.h" 11 #include "vm/heap.h"
11 #include "vm/memory_region.h" 12 #include "vm/memory_region.h"
12 #include "vm/runtime_entry.h" 13 #include "vm/runtime_entry.h"
13 #include "vm/stack_frame.h" 14 #include "vm/stack_frame.h"
14 #include "vm/stub_code.h" 15 #include "vm/stub_code.h"
15 16
16 namespace dart { 17 namespace dart {
17 18
18 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message."); 19 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message.");
19 DEFINE_FLAG(bool, use_sse41, true, "Use SSE 4.1 if available");
20 DECLARE_FLAG(bool, inline_alloc); 20 DECLARE_FLAG(bool, inline_alloc);
21 21
22 22
23 bool CPUFeatures::sse2_supported_ = false;
24 bool CPUFeatures::sse4_1_supported_ = false;
25 #ifdef DEBUG
26 bool CPUFeatures::initialized_ = false;
27 #endif
28
29
30 bool CPUFeatures::sse2_supported() {
31 DEBUG_ASSERT(initialized_);
32 return sse2_supported_;
33 }
34
35
36 bool CPUFeatures::sse4_1_supported() {
37 DEBUG_ASSERT(initialized_);
38 return sse4_1_supported_ && FLAG_use_sse41;
39 }
40
41
42 #define __ assembler.
43
44 void CPUFeatures::InitOnce() {
45 Assembler assembler;
46 __ pushl(EBP);
47 __ pushl(EBX);
48 __ movl(EBP, ESP);
49 // Get feature information in ECX:EDX and return it in EDX:EAX.
50 __ movl(EAX, Immediate(1));
51 __ cpuid();
52 __ movl(EAX, EDX);
53 __ movl(EDX, ECX);
54 __ movl(ESP, EBP);
55 __ popl(EBX);
56 __ popl(EBP);
57 __ ret();
58
59 const Code& code =
60 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
61 Instructions& instructions = Instructions::Handle(code.instructions());
62 typedef uint64_t (*DetectCPUFeatures)();
63 uint64_t features =
64 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
65 sse2_supported_ = (features & kSSE2BitMask) != 0;
66 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
67 #ifdef DEBUG
68 initialized_ = true;
69 #endif
70 }
71
72 #undef __
73
74
75 class DirectCallRelocation : public AssemblerFixup { 23 class DirectCallRelocation : public AssemblerFixup {
76 public: 24 public:
77 void Process(const MemoryRegion& region, intptr_t position) { 25 void Process(const MemoryRegion& region, intptr_t position) {
78 // Direct calls are relative to the following instruction on x86. 26 // Direct calls are relative to the following instruction on x86.
79 int32_t pointer = region.Load<int32_t>(position); 27 int32_t pointer = region.Load<int32_t>(position);
80 int32_t delta = region.start() + position + sizeof(int32_t); 28 int32_t delta = region.start() + position + sizeof(int32_t);
81 region.Store<int32_t>(position, pointer - delta); 29 region.Store<int32_t>(position, pointer - delta);
82 } 30 }
83 }; 31 };
84 32
(...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 2471
2524 const char* Assembler::FpuRegisterName(FpuRegister reg) { 2472 const char* Assembler::FpuRegisterName(FpuRegister reg) {
2525 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); 2473 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters));
2526 return xmm_reg_names[reg]; 2474 return xmm_reg_names[reg];
2527 } 2475 }
2528 2476
2529 2477
2530 } // namespace dart 2478 } // namespace dart
2531 2479
2532 #endif // defined TARGET_ARCH_IA32 2480 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698