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

Side by Side Diff: src/x64/lithium-codegen-x64.cc

Issue 148593004: A64: Synchronize with r18084. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 | « src/x64/lithium-codegen-x64.h ('k') | src/x64/lithium-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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 #ifdef _MSC_VER 104 #ifdef _MSC_VER
105 void LCodeGen::MakeSureStackPagesMapped(int offset) { 105 void LCodeGen::MakeSureStackPagesMapped(int offset) {
106 const int kPageSize = 4 * KB; 106 const int kPageSize = 4 * KB;
107 for (offset -= kPageSize; offset > 0; offset -= kPageSize) { 107 for (offset -= kPageSize; offset > 0; offset -= kPageSize) {
108 __ movq(Operand(rsp, offset), rax); 108 __ movq(Operand(rsp, offset), rax);
109 } 109 }
110 } 110 }
111 #endif 111 #endif
112 112
113 113
114 void LCodeGen::SaveCallerDoubles() {
115 ASSERT(info()->saves_caller_doubles());
116 ASSERT(NeedsEagerFrame());
117 Comment(";;; Save clobbered callee double registers");
118 int count = 0;
119 BitVector* doubles = chunk()->allocated_double_registers();
120 BitVector::Iterator save_iterator(doubles);
121 while (!save_iterator.Done()) {
122 __ movsd(MemOperand(rsp, count * kDoubleSize),
123 XMMRegister::FromAllocationIndex(save_iterator.Current()));
124 save_iterator.Advance();
125 count++;
126 }
127 }
128
129
130 void LCodeGen::RestoreCallerDoubles() {
131 ASSERT(info()->saves_caller_doubles());
132 ASSERT(NeedsEagerFrame());
133 Comment(";;; Restore clobbered callee double registers");
134 BitVector* doubles = chunk()->allocated_double_registers();
135 BitVector::Iterator save_iterator(doubles);
136 int count = 0;
137 while (!save_iterator.Done()) {
138 __ movsd(XMMRegister::FromAllocationIndex(save_iterator.Current()),
139 MemOperand(rsp, count * kDoubleSize));
140 save_iterator.Advance();
141 count++;
142 }
143 }
144
145
114 bool LCodeGen::GeneratePrologue() { 146 bool LCodeGen::GeneratePrologue() {
115 ASSERT(is_generating()); 147 ASSERT(is_generating());
116 148
117 if (info()->IsOptimizing()) { 149 if (info()->IsOptimizing()) {
118 ProfileEntryHookStub::MaybeCallEntryHook(masm_); 150 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
119 151
120 #ifdef DEBUG 152 #ifdef DEBUG
121 if (strlen(FLAG_stop_at) > 0 && 153 if (strlen(FLAG_stop_at) > 0 &&
122 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { 154 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
123 __ int3(); 155 __ int3();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 __ j(not_zero, &loop); 198 __ j(not_zero, &loop);
167 __ pop(rax); 199 __ pop(rax);
168 } else { 200 } else {
169 __ subq(rsp, Immediate(slots * kPointerSize)); 201 __ subq(rsp, Immediate(slots * kPointerSize));
170 #ifdef _MSC_VER 202 #ifdef _MSC_VER
171 MakeSureStackPagesMapped(slots * kPointerSize); 203 MakeSureStackPagesMapped(slots * kPointerSize);
172 #endif 204 #endif
173 } 205 }
174 206
175 if (info()->saves_caller_doubles()) { 207 if (info()->saves_caller_doubles()) {
176 Comment(";;; Save clobbered callee double registers"); 208 SaveCallerDoubles();
177 int count = 0;
178 BitVector* doubles = chunk()->allocated_double_registers();
179 BitVector::Iterator save_iterator(doubles);
180 while (!save_iterator.Done()) {
181 __ movsd(MemOperand(rsp, count * kDoubleSize),
182 XMMRegister::FromAllocationIndex(save_iterator.Current()));
183 save_iterator.Advance();
184 count++;
185 }
186 } 209 }
187 } 210 }
188 211
189 // Possibly allocate a local context. 212 // Possibly allocate a local context.
190 int heap_slots = info_->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; 213 int heap_slots = info_->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
191 if (heap_slots > 0) { 214 if (heap_slots > 0) {
192 Comment(";;; Allocate local context"); 215 Comment(";;; Allocate local context");
193 // Argument to NewContext is the function, which is still in rdi. 216 // Argument to NewContext is the function, which is still in rdi.
194 __ push(rdi); 217 __ push(rdi);
195 if (heap_slots <= FastNewContextStub::kMaximumSlots) { 218 if (heap_slots <= FastNewContextStub::kMaximumSlots) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 __ bind(&jump_table_[i].label); 277 __ bind(&jump_table_[i].label);
255 Address entry = jump_table_[i].address; 278 Address entry = jump_table_[i].address;
256 Deoptimizer::BailoutType type = jump_table_[i].bailout_type; 279 Deoptimizer::BailoutType type = jump_table_[i].bailout_type;
257 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); 280 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type);
258 if (id == Deoptimizer::kNotDeoptimizationEntry) { 281 if (id == Deoptimizer::kNotDeoptimizationEntry) {
259 Comment(";;; jump table entry %d.", i); 282 Comment(";;; jump table entry %d.", i);
260 } else { 283 } else {
261 Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); 284 Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id);
262 } 285 }
263 if (jump_table_[i].needs_frame) { 286 if (jump_table_[i].needs_frame) {
287 ASSERT(!info()->saves_caller_doubles());
264 __ Move(kScratchRegister, ExternalReference::ForDeoptEntry(entry)); 288 __ Move(kScratchRegister, ExternalReference::ForDeoptEntry(entry));
265 if (needs_frame.is_bound()) { 289 if (needs_frame.is_bound()) {
266 __ jmp(&needs_frame); 290 __ jmp(&needs_frame);
267 } else { 291 } else {
268 __ bind(&needs_frame); 292 __ bind(&needs_frame);
269 __ movq(rsi, MemOperand(rbp, StandardFrameConstants::kContextOffset)); 293 __ movq(rsi, MemOperand(rbp, StandardFrameConstants::kContextOffset));
270 __ push(rbp); 294 __ push(rbp);
271 __ movq(rbp, rsp); 295 __ movq(rbp, rsp);
272 __ push(rsi); 296 __ push(rsi);
273 // This variant of deopt can only be used with stubs. Since we don't 297 // This variant of deopt can only be used with stubs. Since we don't
274 // have a function pointer to install in the stack frame that we're 298 // have a function pointer to install in the stack frame that we're
275 // building, install a special marker there instead. 299 // building, install a special marker there instead.
276 ASSERT(info()->IsStub()); 300 ASSERT(info()->IsStub());
277 __ Move(rsi, Smi::FromInt(StackFrame::STUB)); 301 __ Move(rsi, Smi::FromInt(StackFrame::STUB));
278 __ push(rsi); 302 __ push(rsi);
279 __ movq(rsi, MemOperand(rsp, kPointerSize)); 303 __ movq(rsi, MemOperand(rsp, kPointerSize));
280 __ call(kScratchRegister); 304 __ call(kScratchRegister);
281 } 305 }
282 } else { 306 } else {
307 if (info()->saves_caller_doubles()) {
308 ASSERT(info()->IsStub());
309 RestoreCallerDoubles();
310 }
283 __ call(entry, RelocInfo::RUNTIME_ENTRY); 311 __ call(entry, RelocInfo::RUNTIME_ENTRY);
284 } 312 }
285 } 313 }
286 return !is_aborted(); 314 return !is_aborted();
287 } 315 }
288 316
289 317
290 bool LCodeGen::GenerateDeferredCode() { 318 bool LCodeGen::GenerateDeferredCode() {
291 ASSERT(is_generating()); 319 ASSERT(is_generating());
292 if (deferred_.length() > 0) { 320 if (deferred_.length() > 0) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 if (info()->ShouldTrapOnDeopt()) { 735 if (info()->ShouldTrapOnDeopt()) {
708 Label done; 736 Label done;
709 if (cc != no_condition) { 737 if (cc != no_condition) {
710 __ j(NegateCondition(cc), &done, Label::kNear); 738 __ j(NegateCondition(cc), &done, Label::kNear);
711 } 739 }
712 __ int3(); 740 __ int3();
713 __ bind(&done); 741 __ bind(&done);
714 } 742 }
715 743
716 ASSERT(info()->IsStub() || frame_is_built_); 744 ASSERT(info()->IsStub() || frame_is_built_);
717 if (cc == no_condition && frame_is_built_) { 745 // Go through jump table if we need to handle condition, build frame, or
746 // restore caller doubles.
747 if (cc == no_condition && frame_is_built_ &&
748 !info()->saves_caller_doubles()) {
718 __ call(entry, RelocInfo::RUNTIME_ENTRY); 749 __ call(entry, RelocInfo::RUNTIME_ENTRY);
719 } else { 750 } else {
720 // We often have several deopts to the same entry, reuse the last 751 // We often have several deopts to the same entry, reuse the last
721 // jump entry if this is the case. 752 // jump entry if this is the case.
722 if (jump_table_.is_empty() || 753 if (jump_table_.is_empty() ||
723 jump_table_.last().address != entry || 754 jump_table_.last().address != entry ||
724 jump_table_.last().needs_frame != !frame_is_built_ || 755 jump_table_.last().needs_frame != !frame_is_built_ ||
725 jump_table_.last().bailout_type != bailout_type) { 756 jump_table_.last().bailout_type != bailout_type) {
726 Deoptimizer::JumpTableEntry table_entry(entry, 757 Deoptimizer::JumpTableEntry table_entry(entry,
727 bailout_type, 758 bailout_type,
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 Comment("Unreachable code."); 1774 Comment("Unreachable code.");
1744 __ int3(); 1775 __ int3();
1745 } 1776 }
1746 } 1777 }
1747 1778
1748 1779
1749 void LCodeGen::DoAddI(LAddI* instr) { 1780 void LCodeGen::DoAddI(LAddI* instr) {
1750 LOperand* left = instr->left(); 1781 LOperand* left = instr->left();
1751 LOperand* right = instr->right(); 1782 LOperand* right = instr->right();
1752 1783
1784 Representation target_rep = instr->hydrogen()->representation();
1785 bool is_q = target_rep.IsSmi() || target_rep.IsExternal();
1786
1753 if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) { 1787 if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) {
1754 if (right->IsConstantOperand()) { 1788 if (right->IsConstantOperand()) {
1755 int32_t offset = ToInteger32(LConstantOperand::cast(right)); 1789 int32_t offset = ToInteger32(LConstantOperand::cast(right));
1756 __ leal(ToRegister(instr->result()), 1790 if (is_q) {
1757 MemOperand(ToRegister(left), offset)); 1791 __ lea(ToRegister(instr->result()),
1792 MemOperand(ToRegister(left), offset));
1793 } else {
1794 __ leal(ToRegister(instr->result()),
1795 MemOperand(ToRegister(left), offset));
1796 }
1758 } else { 1797 } else {
1759 Operand address(ToRegister(left), ToRegister(right), times_1, 0); 1798 Operand address(ToRegister(left), ToRegister(right), times_1, 0);
1760 if (instr->hydrogen()->representation().IsSmi()) { 1799 if (is_q) {
1761 __ lea(ToRegister(instr->result()), address); 1800 __ lea(ToRegister(instr->result()), address);
1762 } else { 1801 } else {
1763 __ leal(ToRegister(instr->result()), address); 1802 __ leal(ToRegister(instr->result()), address);
1764 } 1803 }
1765 } 1804 }
1766 } else { 1805 } else {
1767 if (right->IsConstantOperand()) { 1806 if (right->IsConstantOperand()) {
1768 __ addl(ToRegister(left), 1807 if (is_q) {
1769 Immediate(ToInteger32(LConstantOperand::cast(right)))); 1808 __ addq(ToRegister(left),
1809 Immediate(ToInteger32(LConstantOperand::cast(right))));
1810 } else {
1811 __ addl(ToRegister(left),
1812 Immediate(ToInteger32(LConstantOperand::cast(right))));
1813 }
1770 } else if (right->IsRegister()) { 1814 } else if (right->IsRegister()) {
1771 if (instr->hydrogen_value()->representation().IsSmi()) { 1815 if (is_q) {
1772 __ addq(ToRegister(left), ToRegister(right)); 1816 __ addq(ToRegister(left), ToRegister(right));
1773 } else { 1817 } else {
1774 __ addl(ToRegister(left), ToRegister(right)); 1818 __ addl(ToRegister(left), ToRegister(right));
1775 } 1819 }
1776 } else { 1820 } else {
1777 if (instr->hydrogen_value()->representation().IsSmi()) { 1821 if (is_q) {
1778 __ addq(ToRegister(left), ToOperand(right)); 1822 __ addq(ToRegister(left), ToOperand(right));
1779 } else { 1823 } else {
1780 __ addl(ToRegister(left), ToOperand(right)); 1824 __ addl(ToRegister(left), ToOperand(right));
1781 } 1825 }
1782 } 1826 }
1783 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { 1827 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1784 DeoptimizeIf(overflow, instr->environment()); 1828 DeoptimizeIf(overflow, instr->environment());
1785 } 1829 }
1786 } 1830 }
1787 } 1831 }
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 if (FLAG_trace && info()->IsOptimizing()) { 2694 if (FLAG_trace && info()->IsOptimizing()) {
2651 // Preserve the return value on the stack and rely on the runtime call 2695 // Preserve the return value on the stack and rely on the runtime call
2652 // to return the value in the same register. We're leaving the code 2696 // to return the value in the same register. We're leaving the code
2653 // managed by the register allocator and tearing down the frame, it's 2697 // managed by the register allocator and tearing down the frame, it's
2654 // safe to write to the context register. 2698 // safe to write to the context register.
2655 __ push(rax); 2699 __ push(rax);
2656 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); 2700 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
2657 __ CallRuntime(Runtime::kTraceExit, 1); 2701 __ CallRuntime(Runtime::kTraceExit, 1);
2658 } 2702 }
2659 if (info()->saves_caller_doubles()) { 2703 if (info()->saves_caller_doubles()) {
2660 ASSERT(NeedsEagerFrame()); 2704 RestoreCallerDoubles();
2661 BitVector* doubles = chunk()->allocated_double_registers();
2662 BitVector::Iterator save_iterator(doubles);
2663 int count = 0;
2664 while (!save_iterator.Done()) {
2665 __ movsd(XMMRegister::FromAllocationIndex(save_iterator.Current()),
2666 MemOperand(rsp, count * kDoubleSize));
2667 save_iterator.Advance();
2668 count++;
2669 }
2670 } 2705 }
2671 int no_frame_start = -1; 2706 int no_frame_start = -1;
2672 if (NeedsEagerFrame()) { 2707 if (NeedsEagerFrame()) {
2673 __ movq(rsp, rbp); 2708 __ movq(rsp, rbp);
2674 __ pop(rbp); 2709 __ pop(rbp);
2675 no_frame_start = masm_->pc_offset(); 2710 no_frame_start = masm_->pc_offset();
2676 } 2711 }
2677 if (instr->has_constant_parameter_count()) { 2712 if (instr->has_constant_parameter_count()) {
2678 __ Ret((ToInteger32(instr->constant_parameter_count()) + 1) * kPointerSize, 2713 __ Ret((ToInteger32(instr->constant_parameter_count()) + 1) * kPointerSize,
2679 rcx); 2714 rcx);
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
3691 MathPowStub stub(MathPowStub::INTEGER); 3726 MathPowStub stub(MathPowStub::INTEGER);
3692 __ CallStub(&stub); 3727 __ CallStub(&stub);
3693 } else { 3728 } else {
3694 ASSERT(exponent_type.IsDouble()); 3729 ASSERT(exponent_type.IsDouble());
3695 MathPowStub stub(MathPowStub::DOUBLE); 3730 MathPowStub stub(MathPowStub::DOUBLE);
3696 __ CallStub(&stub); 3731 __ CallStub(&stub);
3697 } 3732 }
3698 } 3733 }
3699 3734
3700 3735
3701 void LCodeGen::DoRandom(LRandom* instr) {
3702 // Assert that register size is twice the size of each seed.
3703 static const int kSeedSize = sizeof(uint32_t);
3704 STATIC_ASSERT(kPointerSize == 2 * kSeedSize);
3705
3706 // Load native context
3707 Register global_object = ToRegister(instr->global_object());
3708 Register native_context = global_object;
3709 __ movq(native_context, FieldOperand(
3710 global_object, GlobalObject::kNativeContextOffset));
3711
3712 // Load state (FixedArray of the native context's random seeds)
3713 static const int kRandomSeedOffset =
3714 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
3715 Register state = native_context;
3716 __ movq(state, FieldOperand(native_context, kRandomSeedOffset));
3717
3718 // Load state[0].
3719 Register state0 = ToRegister(instr->scratch());
3720 __ movl(state0, FieldOperand(state, ByteArray::kHeaderSize));
3721 // Load state[1].
3722 Register state1 = ToRegister(instr->scratch2());
3723 __ movl(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize));
3724
3725 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
3726 Register scratch3 = ToRegister(instr->scratch3());
3727 __ movzxwl(scratch3, state0);
3728 __ imull(scratch3, scratch3, Immediate(18273));
3729 __ shrl(state0, Immediate(16));
3730 __ addl(state0, scratch3);
3731 // Save state[0].
3732 __ movl(FieldOperand(state, ByteArray::kHeaderSize), state0);
3733
3734 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
3735 __ movzxwl(scratch3, state1);
3736 __ imull(scratch3, scratch3, Immediate(36969));
3737 __ shrl(state1, Immediate(16));
3738 __ addl(state1, scratch3);
3739 // Save state[1].
3740 __ movl(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1);
3741
3742 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
3743 Register random = state0;
3744 __ shll(random, Immediate(14));
3745 __ andl(state1, Immediate(0x3FFFF));
3746 __ addl(random, state1);
3747
3748 // Convert 32 random bits in rax to 0.(32 random bits) in a double
3749 // by computing:
3750 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
3751 XMMRegister result = ToDoubleRegister(instr->result());
3752 XMMRegister scratch4 = double_scratch0();
3753 __ movq(scratch3, V8_INT64_C(0x4130000000000000)); // 1.0 x 2^20 as double
3754 __ movq(scratch4, scratch3);
3755 __ movd(result, random);
3756 __ xorps(result, scratch4);
3757 __ subsd(result, scratch4);
3758 }
3759
3760
3761 void LCodeGen::DoMathExp(LMathExp* instr) { 3736 void LCodeGen::DoMathExp(LMathExp* instr) {
3762 XMMRegister input = ToDoubleRegister(instr->value()); 3737 XMMRegister input = ToDoubleRegister(instr->value());
3763 XMMRegister result = ToDoubleRegister(instr->result()); 3738 XMMRegister result = ToDoubleRegister(instr->result());
3764 XMMRegister temp0 = double_scratch0(); 3739 XMMRegister temp0 = double_scratch0();
3765 Register temp1 = ToRegister(instr->temp1()); 3740 Register temp1 = ToRegister(instr->temp1());
3766 Register temp2 = ToRegister(instr->temp2()); 3741 Register temp2 = ToRegister(instr->temp2());
3767 3742
3768 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); 3743 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2);
3769 } 3744 }
3770 3745
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after
5664 FixedArray::kHeaderSize - kPointerSize)); 5639 FixedArray::kHeaderSize - kPointerSize));
5665 __ bind(&done); 5640 __ bind(&done);
5666 } 5641 }
5667 5642
5668 5643
5669 #undef __ 5644 #undef __
5670 5645
5671 } } // namespace v8::internal 5646 } } // namespace v8::internal
5672 5647
5673 #endif // V8_TARGET_ARCH_X64 5648 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/lithium-codegen-x64.h ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698