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

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

Issue 10990028: Add code for CPU feature detection and use it to detect SSE3 and SSE 4.1. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 8 years, 2 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
« no previous file with comments | « runtime/vm/assembler_ia32.h ('k') | runtime/vm/assembler_x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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/heap.h" 9 #include "vm/heap.h"
10 #include "vm/memory_region.h" 10 #include "vm/memory_region.h"
11 #include "vm/runtime_entry.h" 11 #include "vm/runtime_entry.h"
12 #include "vm/stub_code.h" 12 #include "vm/stub_code.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message."); 16 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message.");
17 DEFINE_FLAG(bool, code_comments, false, 17 DEFINE_FLAG(bool, code_comments, false,
18 "Include comments into code and disassembly"); 18 "Include comments into code and disassembly");
19 DEFINE_FLAG(bool, use_sse41, true, "Use SSE 4.1 if available");
20
21
22 bool CPUFeatures::sse3_supported_ = false;
23 bool CPUFeatures::sse4_1_supported_ = false;
24 #ifdef DEBUG
25 bool CPUFeatures::initialized_ = false;
26 #endif
27
28 bool CPUFeatures::sse3_supported() {
29 DEBUG_ASSERT(initialized_);
30 return sse3_supported_;
31 }
32
33
34 bool CPUFeatures::sse4_1_supported() {
35 DEBUG_ASSERT(initialized_);
36 return sse4_1_supported_;
37 }
38
39
40 #define __ assembler.
41
42 void CPUFeatures::InitOnce() {
43 Assembler assembler;
44 __ pushl(EBP);
45 __ pushl(EBX);
46 __ movl(EBP, ESP);
47 // Get feature information in ECX:EDX and return it in EDX:EAX.
48 __ movl(EAX, Immediate(1));
49 __ cpuid();
50 __ movl(EAX, EDX);
51 __ movl(EDX, ECX);
52 __ movl(ESP, EBP);
53 __ popl(EBX);
54 __ popl(EBP);
55 __ ret();
56
57 const Code& code =
58 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
59 Instructions& instructions = Instructions::Handle(code.instructions());
60 typedef uint64_t (*DetectCPUFeatures)();
61 uint64_t features =
62 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
63 sse3_supported_ = (features & kSSE3BitMask) != 0;
64 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
65 #ifdef DEBUG
66 initialized_ = true;
67 #endif
68 }
69
70 #undef __
19 71
20 72
21 class DirectCallRelocation : public AssemblerFixup { 73 class DirectCallRelocation : public AssemblerFixup {
22 public: 74 public:
23 void Process(const MemoryRegion& region, int position) { 75 void Process(const MemoryRegion& region, int position) {
24 // Direct calls are relative to the following instruction on x86. 76 // Direct calls are relative to the following instruction on x86.
25 int32_t pointer = region.Load<int32_t>(position); 77 int32_t pointer = region.Load<int32_t>(position);
26 int32_t delta = region.start() + position + sizeof(int32_t); 78 int32_t delta = region.start() + position + sizeof(int32_t);
27 region.Store<int32_t>(position, pointer - delta); 79 region.Store<int32_t>(position, pointer - delta);
28 } 80 }
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 1352
1301 1353
1302 void Assembler::cmpxchgl(const Address& address, Register reg) { 1354 void Assembler::cmpxchgl(const Address& address, Register reg) {
1303 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1355 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1304 EmitUint8(0x0F); 1356 EmitUint8(0x0F);
1305 EmitUint8(0xB1); 1357 EmitUint8(0xB1);
1306 EmitOperand(reg, address); 1358 EmitOperand(reg, address);
1307 } 1359 }
1308 1360
1309 1361
1362 void Assembler::cpuid() {
1363 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1364 EmitUint8(0x0F);
1365 EmitUint8(0xA2);
1366 }
1367
1368
1310 void Assembler::CompareRegisters(Register a, Register b) { 1369 void Assembler::CompareRegisters(Register a, Register b) {
1311 cmpl(a, b); 1370 cmpl(a, b);
1312 } 1371 }
1313 1372
1314 1373
1315 void Assembler::MoveRegister(Register to, Register from) { 1374 void Assembler::MoveRegister(Register to, Register from) {
1316 if (to != from) { 1375 if (to != from) {
1317 movl(to, from); 1376 movl(to, from);
1318 } 1377 }
1319 } 1378 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 1900
1842 const char* Assembler::XmmRegisterName(XmmRegister reg) { 1901 const char* Assembler::XmmRegisterName(XmmRegister reg) {
1843 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); 1902 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters));
1844 return xmm_reg_names[reg]; 1903 return xmm_reg_names[reg];
1845 } 1904 }
1846 1905
1847 1906
1848 } // namespace dart 1907 } // namespace dart
1849 1908
1850 #endif // defined TARGET_ARCH_IA32 1909 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/assembler_ia32.h ('k') | runtime/vm/assembler_x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698