| OLD | NEW |
| 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 #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 __ pushq(RBP); |
| 45 __ pushq(RBX); |
| 46 __ movq(RBP, RSP); |
| 47 // Get feature information in ECX:EDX and return it in RAX. |
| 48 // Note that cpuid operates the same in 64-bit and 32-bit mode. |
| 49 __ movq(RAX, Immediate(1)); |
| 50 __ cpuid(); |
| 51 __ movl(RAX, RCX); // Zero extended. |
| 52 __ shlq(RAX, Immediate(32)); |
| 53 __ movl(RCX, RDX); // Zero extended. |
| 54 __ orq(RAX, RCX); |
| 55 __ movq(RSP, RBP); |
| 56 __ popq(RBX); |
| 57 __ popq(RBP); |
| 58 __ ret(); |
| 59 |
| 60 const Code& code = |
| 61 Code::Handle(Code::FinalizeCode("DetectCPUFeatures", &assembler)); |
| 62 Instructions& instructions = Instructions::Handle(code.instructions()); |
| 63 typedef uint64_t (*DetectCPUFeatures)(); |
| 64 uint64_t features = |
| 65 reinterpret_cast<DetectCPUFeatures>(instructions.EntryPoint())(); |
| 66 sse3_supported_ = (features & kSSE3BitMask) != 0; |
| 67 sse4_1_supported_ = (features & kSSE4_1BitMask) != 0; |
| 68 #ifdef DEBUG |
| 69 initialized_ = true; |
| 70 #endif |
| 71 } |
| 72 |
| 73 #undef __ |
| 19 | 74 |
| 20 | 75 |
| 21 void Assembler::InitializeMemoryWithBreakpoints(uword data, int length) { | 76 void Assembler::InitializeMemoryWithBreakpoints(uword data, int length) { |
| 22 memset(reinterpret_cast<void*>(data), Instr::kBreakPointInstruction, length); | 77 memset(reinterpret_cast<void*>(data), Instr::kBreakPointInstruction, length); |
| 23 } | 78 } |
| 24 | 79 |
| 25 | 80 |
| 26 void Assembler::call(Register reg) { | 81 void Assembler::call(Register reg) { |
| 27 AssemblerBuffer::EnsureCapacity ensured(&buffer_); | 82 AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 28 Operand operand(reg); | 83 Operand operand(reg); |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 | 1521 |
| 1467 void Assembler::cmpxchgq(const Address& address, Register reg) { | 1522 void Assembler::cmpxchgq(const Address& address, Register reg) { |
| 1468 AssemblerBuffer::EnsureCapacity ensured(&buffer_); | 1523 AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1469 EmitOperandREX(reg, address, REX_W); | 1524 EmitOperandREX(reg, address, REX_W); |
| 1470 EmitUint8(0x0F); | 1525 EmitUint8(0x0F); |
| 1471 EmitUint8(0xB1); | 1526 EmitUint8(0xB1); |
| 1472 EmitOperand(reg & 7, address); | 1527 EmitOperand(reg & 7, address); |
| 1473 } | 1528 } |
| 1474 | 1529 |
| 1475 | 1530 |
| 1531 void Assembler::cpuid() { |
| 1532 AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1533 EmitUint8(0x0F); |
| 1534 EmitUint8(0xA2); |
| 1535 } |
| 1536 |
| 1537 |
| 1476 void Assembler::CompareRegisters(Register a, Register b) { | 1538 void Assembler::CompareRegisters(Register a, Register b) { |
| 1477 cmpq(a, b); | 1539 cmpq(a, b); |
| 1478 } | 1540 } |
| 1479 | 1541 |
| 1480 | 1542 |
| 1481 void Assembler::MoveRegister(Register to, Register from) { | 1543 void Assembler::MoveRegister(Register to, Register from) { |
| 1482 if (to != from) { | 1544 if (to != from) { |
| 1483 movq(to, from); | 1545 movq(to, from); |
| 1484 } | 1546 } |
| 1485 } | 1547 } |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 | 2049 |
| 1988 const char* Assembler::XmmRegisterName(XmmRegister reg) { | 2050 const char* Assembler::XmmRegisterName(XmmRegister reg) { |
| 1989 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); | 2051 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); |
| 1990 return xmm_reg_names[reg]; | 2052 return xmm_reg_names[reg]; |
| 1991 } | 2053 } |
| 1992 | 2054 |
| 1993 | 2055 |
| 1994 } // namespace dart | 2056 } // namespace dart |
| 1995 | 2057 |
| 1996 #endif // defined TARGET_ARCH_X64 | 2058 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |