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

Side by Side Diff: runtime/vm/assembler_x64.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_X64) 6 #if defined(TARGET_ARCH_X64)
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 bool CPUFeatures::initialized_ = false;
25
26
27 bool CPUFeatures::sse3_supported() {
28 ASSERT(initialized_);
29 return sse3_supported_;
30 }
31
32
33 bool CPUFeatures::sse4_1_supported() {
34 ASSERT(initialized_);
35 return sse4_1_supported_;
36 }
37
38
39 #define __ assembler.
40
41 void CPUFeatures::InitOnce() {
42 Assembler assembler;
43 __ pushq(RBP);
44 __ pushq(RBX);
45 __ movq(RBP, RSP);
46 // Get feature information in ECX:EDX and return it in RAX.
srdjan 2012/09/25 17:12:25 RCX, RDX ?
Florian Schneider 2012/09/26 09:03:16 That is intentional according to the spec: cpuid o
47 __ movq(RAX, Immediate(1));
48 __ cpuid();
49 __ movl(RAX, RCX); // Zero extended.
50 __ shlq(RAX, Immediate(32));
51 __ movl(RCX, RDX); // Zero extended.
52 __ orq(RAX, RCX);
53 __ movq(RSP, RBP);
54 __ popq(RBX);
55 __ popq(RBP);
56 __ ret();
57
58 const Code& code =
59 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler));
60 Instructions& instructions = Instructions::Handle(code.instructions());
61 typedef uint64_t (*DetectCPUFeatures)();
62 uint64_t features =
63 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())();
64 sse3_supported_ = (features & kSSE3BitMask) != 0;
65 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0;
66 initialized_ = true;
67 }
68
69 #undef __
19 70
20 71
21 void Assembler::InitializeMemoryWithBreakpoints(uword data, int length) { 72 void Assembler::InitializeMemoryWithBreakpoints(uword data, int length) {
22 memset(reinterpret_cast<void*>(data), Instr::kBreakPointInstruction, length); 73 memset(reinterpret_cast<void*>(data), Instr::kBreakPointInstruction, length);
23 } 74 }
24 75
25 76
26 void Assembler::call(Register reg) { 77 void Assembler::call(Register reg) {
27 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 78 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
28 Operand operand(reg); 79 Operand operand(reg);
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 1517
1467 void Assembler::cmpxchgq(const Address& address, Register reg) { 1518 void Assembler::cmpxchgq(const Address& address, Register reg) {
1468 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1519 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1469 EmitOperandREX(reg, address, REX_W); 1520 EmitOperandREX(reg, address, REX_W);
1470 EmitUint8(0x0F); 1521 EmitUint8(0x0F);
1471 EmitUint8(0xB1); 1522 EmitUint8(0xB1);
1472 EmitOperand(reg & 7, address); 1523 EmitOperand(reg & 7, address);
1473 } 1524 }
1474 1525
1475 1526
1527 void Assembler::cpuid() {
1528 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1529 EmitUint8(0x0F);
1530 EmitUint8(0xA2);
1531 }
1532
1533
1476 void Assembler::CompareRegisters(Register a, Register b) { 1534 void Assembler::CompareRegisters(Register a, Register b) {
1477 cmpq(a, b); 1535 cmpq(a, b);
1478 } 1536 }
1479 1537
1480 1538
1481 void Assembler::MoveRegister(Register to, Register from) { 1539 void Assembler::MoveRegister(Register to, Register from) {
1482 if (to != from) { 1540 if (to != from) {
1483 movq(to, from); 1541 movq(to, from);
1484 } 1542 }
1485 } 1543 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 2045
1988 const char* Assembler::XmmRegisterName(XmmRegister reg) { 2046 const char* Assembler::XmmRegisterName(XmmRegister reg) {
1989 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); 2047 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters));
1990 return xmm_reg_names[reg]; 2048 return xmm_reg_names[reg];
1991 } 2049 }
1992 2050
1993 2051
1994 } // namespace dart 2052 } // namespace dart
1995 2053
1996 #endif // defined TARGET_ARCH_X64 2054 #endif // defined TARGET_ARCH_X64
OLDNEW
« runtime/vm/assembler_x64.h ('K') | « runtime/vm/assembler_x64.h ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698