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

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: simplified, because there is no code in snapshots 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
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 #ifdef DEBUG
30 ASSERT(initialized_);
31 #endif
32 return sse3_supported_;
33 }
34
35
36 bool CPUFeatures::sse4_1_supported() {
37 #ifdef DEBUG
38 ASSERT(initialized_);
39 #endif
40 return sse4_1_supported_;
41 }
42
43
44 #define __ assembler.
45
46 void CPUFeatures::InitOnce() {
47 Assembler assembler;
48 __ pushl(EBP);
49 __ pushl(EBX);
50 __ movl(EBP, ESP);
51 // Get feature information in ECX:EDX and return it in EDX:EAX.
52 __ movl(EAX, Immediate(1));
53 __ cpuid();
54 __ movl(EAX, EDX);
55 __ movl(EDX, ECX);
56 __ movl(ESP, EBP);
57 __ popl(EBX);
58 __ popl(EBP);
59 __ ret();
60
61 const Code& code =
62 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
63 Instructions& instructions = Instructions::Handle(code.instructions());
64 typedef uint64_t (*DetectCPUFeatures)();
65 uint64_t features =
66 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
67 sse3_supported_ = (features & kSSE3BitMask) != 0;
68 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
69 #ifdef DEBUG
70 initialized_ = true;
71 #endif
72 }
73
74 #undef __
19 75
20 76
21 class DirectCallRelocation : public AssemblerFixup { 77 class DirectCallRelocation : public AssemblerFixup {
22 public: 78 public:
23 void Process(const MemoryRegion& region, int position) { 79 void Process(const MemoryRegion& region, int position) {
24 // Direct calls are relative to the following instruction on x86. 80 // Direct calls are relative to the following instruction on x86.
25 int32_t pointer = region.Load<int32_t>(position); 81 int32_t pointer = region.Load<int32_t>(position);
26 int32_t delta = region.start() + position + sizeof(int32_t); 82 int32_t delta = region.start() + position + sizeof(int32_t);
27 region.Store<int32_t>(position, pointer - delta); 83 region.Store<int32_t>(position, pointer - delta);
28 } 84 }
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 1356
1301 1357
1302 void Assembler::cmpxchgl(const Address& address, Register reg) { 1358 void Assembler::cmpxchgl(const Address& address, Register reg) {
1303 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1359 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1304 EmitUint8(0x0F); 1360 EmitUint8(0x0F);
1305 EmitUint8(0xB1); 1361 EmitUint8(0xB1);
1306 EmitOperand(reg, address); 1362 EmitOperand(reg, address);
1307 } 1363 }
1308 1364
1309 1365
1366 void Assembler::cpuid() {
1367 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1368 EmitUint8(0x0F);
1369 EmitUint8(0xA2);
1370 }
1371
1372
1310 void Assembler::CompareRegisters(Register a, Register b) { 1373 void Assembler::CompareRegisters(Register a, Register b) {
1311 cmpl(a, b); 1374 cmpl(a, b);
1312 } 1375 }
1313 1376
1314 1377
1315 void Assembler::MoveRegister(Register to, Register from) { 1378 void Assembler::MoveRegister(Register to, Register from) {
1316 if (to != from) { 1379 if (to != from) {
1317 movl(to, from); 1380 movl(to, from);
1318 } 1381 }
1319 } 1382 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 1904
1842 const char* Assembler::XmmRegisterName(XmmRegister reg) { 1905 const char* Assembler::XmmRegisterName(XmmRegister reg) {
1843 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); 1906 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters));
1844 return xmm_reg_names[reg]; 1907 return xmm_reg_names[reg];
1845 } 1908 }
1846 1909
1847 1910
1848 } // namespace dart 1911 } // namespace dart
1849 1912
1850 #endif // defined TARGET_ARCH_IA32 1913 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698