erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 31 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "ia32/lithium-codegen-ia32.h" |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 33 | #include "ic.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "code-stubs.h" |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 35 | #include "deoptimizer.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 37 | #include "codegen.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 38 | #include "hydrogen-osr.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
| 43 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 44 | static SaveFPRegsMode GetSaveFPRegsMode() { |
| 45 | // We don't need to save floating point regs when generating the snapshot |
| 46 | return CpuFeatures::IsSafeForSnapshot(SSE2) ? kSaveFPRegs : kDontSaveFPRegs; |
| 47 | } |
| 48 | |
| 49 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 50 | // When invoking builtins, we need to record the safepoint in the middle of |
| 51 | // the invoke instruction sequence generated by the macro assembler. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 52 | class SafepointGenerator V8_FINAL : public CallWrapper { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | public: |
| 54 | SafepointGenerator(LCodeGen* codegen, |
| 55 | LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 56 | Safepoint::DeoptMode mode) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 57 | : codegen_(codegen), |
| 58 | pointers_(pointers), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 59 | deopt_mode_(mode) {} |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 60 | virtual ~SafepointGenerator() {} |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 61 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 62 | virtual void BeforeCall(int call_size) const V8_OVERRIDE {} |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 63 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 64 | virtual void AfterCall() const V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 65 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | private: |
| 69 | LCodeGen* codegen_; |
| 70 | LPointerMap* pointers_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 71 | Safepoint::DeoptMode deopt_mode_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | |
| 75 | #define __ masm()-> |
| 76 | |
| 77 | bool LCodeGen::GenerateCode() { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 78 | LPhase phase("Z_Code generation", chunk()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 79 | ASSERT(is_unused()); |
| 80 | status_ = GENERATING; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 81 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 82 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 83 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 84 | // the frame (that is done in GeneratePrologue). |
| 85 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 86 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 87 | support_aligned_spilled_doubles_ = info()->IsOptimizing(); |
| 88 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 89 | dynamic_frame_alignment_ = info()->IsOptimizing() && |
| 90 | ((chunk()->num_double_slots() > 2 && |
| 91 | !chunk()->graph()->is_recursive()) || |
| 92 | !info()->osr_ast_id().IsNone()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 93 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 94 | return GeneratePrologue() && |
| 95 | GenerateBody() && |
| 96 | GenerateDeferredCode() && |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 97 | GenerateJumpTable() && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 98 | GenerateSafepointTable(); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 103 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 104 | code->set_stack_slots(GetStackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 105 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 106 | if (FLAG_weak_embedded_maps_in_optimized_code) { |
| 107 | RegisterDependentCodeForEmbeddedMaps(code); |
| 108 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 109 | PopulateDeoptimizationData(code); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 110 | if (!info()->IsStub()) { |
| 111 | Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(code); |
| 112 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 113 | info()->CommitDependencies(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 117 | void LCodeGen::Abort(BailoutReason reason) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 118 | info()->set_bailout_reason(reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 119 | status_ = ABORTED; |
| 120 | } |
| 121 | |
| 122 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 123 | #ifdef _MSC_VER |
| 124 | void LCodeGen::MakeSureStackPagesMapped(int offset) { |
| 125 | const int kPageSize = 4 * KB; |
| 126 | for (offset -= kPageSize; offset > 0; offset -= kPageSize) { |
| 127 | __ mov(Operand(esp, offset), eax); |
| 128 | } |
| 129 | } |
| 130 | #endif |
| 131 | |
| 132 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 133 | bool LCodeGen::GeneratePrologue() { |
| 134 | ASSERT(is_generating()); |
| 135 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 136 | if (info()->IsOptimizing()) { |
| 137 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 138 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 139 | #ifdef DEBUG |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 140 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 141 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 142 | __ int3(); |
| 143 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 144 | #endif |
| 145 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 146 | // Strict mode functions and builtins need to replace the receiver |
| 147 | // with undefined when called as functions (without an explicit |
| 148 | // receiver object). ecx is zero for method calls and non-zero for |
| 149 | // function calls. |
| 150 | if (!info_->is_classic_mode() || info_->is_native()) { |
| 151 | Label ok; |
| 152 | __ test(ecx, Operand(ecx)); |
| 153 | __ j(zero, &ok, Label::kNear); |
| 154 | // +1 for return address. |
| 155 | int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize; |
| 156 | __ mov(Operand(esp, receiver_offset), |
| 157 | Immediate(isolate()->factory()->undefined_value())); |
| 158 | __ bind(&ok); |
| 159 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 160 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 161 | if (support_aligned_spilled_doubles_ && dynamic_frame_alignment_) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 162 | // Move state of dynamic frame alignment into edx. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 163 | __ Set(edx, Immediate(kNoAlignmentPadding)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 164 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 165 | Label do_not_pad, align_loop; |
| 166 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 167 | // Align esp + 4 to a multiple of 2 * kPointerSize. |
| 168 | __ test(esp, Immediate(kPointerSize)); |
| 169 | __ j(not_zero, &do_not_pad, Label::kNear); |
| 170 | __ push(Immediate(0)); |
| 171 | __ mov(ebx, esp); |
| 172 | __ mov(edx, Immediate(kAlignmentPaddingPushed)); |
| 173 | // Copy arguments, receiver, and return address. |
| 174 | __ mov(ecx, Immediate(scope()->num_parameters() + 2)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 175 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 176 | __ bind(&align_loop); |
| 177 | __ mov(eax, Operand(ebx, 1 * kPointerSize)); |
| 178 | __ mov(Operand(ebx, 0), eax); |
| 179 | __ add(Operand(ebx), Immediate(kPointerSize)); |
| 180 | __ dec(ecx); |
| 181 | __ j(not_zero, &align_loop, Label::kNear); |
| 182 | __ mov(Operand(ebx, 0), Immediate(kAlignmentZapValue)); |
| 183 | __ bind(&do_not_pad); |
| 184 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 185 | } |
| 186 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 187 | info()->set_prologue_offset(masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 188 | if (NeedsEagerFrame()) { |
| 189 | ASSERT(!frame_is_built_); |
| 190 | frame_is_built_ = true; |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 191 | __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 192 | info()->AddNoFrameRange(0, masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 193 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 194 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 195 | if (info()->IsOptimizing() && |
| 196 | dynamic_frame_alignment_ && |
| 197 | FLAG_debug_code) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 198 | __ test(esp, Immediate(kPointerSize)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 199 | __ Assert(zero, kFrameIsExpectedToBeAligned); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 200 | } |
| 201 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 202 | // Reserve space for the stack slots needed by the code. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 203 | int slots = GetStackSlotCount(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 204 | ASSERT(slots != 0 || !info()->IsOptimizing()); |
| 205 | if (slots > 0) { |
| 206 | if (slots == 1) { |
| 207 | if (dynamic_frame_alignment_) { |
| 208 | __ push(edx); |
| 209 | } else { |
| 210 | __ push(Immediate(kNoAlignmentPadding)); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 211 | } |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 212 | } else { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 213 | if (FLAG_debug_code) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 214 | __ sub(Operand(esp), Immediate(slots * kPointerSize)); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 215 | #ifdef _MSC_VER |
| 216 | MakeSureStackPagesMapped(slots * kPointerSize); |
| 217 | #endif |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 218 | __ push(eax); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 219 | __ mov(Operand(eax), Immediate(slots)); |
| 220 | Label loop; |
| 221 | __ bind(&loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 222 | __ mov(MemOperand(esp, eax, times_4, 0), |
| 223 | Immediate(kSlotsZapValue)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 224 | __ dec(eax); |
| 225 | __ j(not_zero, &loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 226 | __ pop(eax); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 227 | } else { |
| 228 | __ sub(Operand(esp), Immediate(slots * kPointerSize)); |
| 229 | #ifdef _MSC_VER |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 230 | MakeSureStackPagesMapped(slots * kPointerSize); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 231 | #endif |
| 232 | } |
| 233 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 234 | if (support_aligned_spilled_doubles_) { |
| 235 | Comment(";;; Store dynamic frame alignment tag for spilled doubles"); |
| 236 | // Store dynamic frame alignment state in the first local. |
| 237 | int offset = JavaScriptFrameConstants::kDynamicAlignmentStateOffset; |
| 238 | if (dynamic_frame_alignment_) { |
| 239 | __ mov(Operand(ebp, offset), edx); |
| 240 | } else { |
| 241 | __ mov(Operand(ebp, offset), Immediate(kNoAlignmentPadding)); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | if (info()->saves_caller_doubles() && CpuFeatures::IsSupported(SSE2)) { |
| 247 | Comment(";;; Save clobbered callee double registers"); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 248 | CpuFeatureScope scope(masm(), SSE2); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 249 | int count = 0; |
| 250 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 251 | BitVector::Iterator save_iterator(doubles); |
| 252 | while (!save_iterator.Done()) { |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 253 | __ movsd(MemOperand(esp, count * kDoubleSize), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 254 | XMMRegister::FromAllocationIndex(save_iterator.Current())); |
| 255 | save_iterator.Advance(); |
| 256 | count++; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 257 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 261 | // Possibly allocate a local context. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 262 | int heap_slots = info_->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 263 | if (heap_slots > 0) { |
| 264 | Comment(";;; Allocate local context"); |
| 265 | // Argument to NewContext is the function, which is still in edi. |
| 266 | __ push(edi); |
| 267 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 268 | FastNewContextStub stub(heap_slots); |
| 269 | __ CallStub(&stub); |
| 270 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 271 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 272 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 273 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 274 | // Context is returned in both eax and esi. It replaces the context |
| 275 | // passed to us. It's saved in the stack and kept live in esi. |
| 276 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 277 | |
| 278 | // Copy parameters into context if necessary. |
| 279 | int num_parameters = scope()->num_parameters(); |
| 280 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 281 | Variable* var = scope()->parameter(i); |
| 282 | if (var->IsContextSlot()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 283 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 284 | (num_parameters - 1 - i) * kPointerSize; |
| 285 | // Load parameter from stack. |
| 286 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 287 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 288 | int context_offset = Context::SlotOffset(var->index()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 289 | __ mov(Operand(esi, context_offset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 290 | // Update the write barrier. This clobbers eax and ebx. |
| 291 | __ RecordWriteContextSlot(esi, |
| 292 | context_offset, |
| 293 | eax, |
| 294 | ebx, |
| 295 | kDontSaveFPRegs); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | Comment(";;; End allocate local context"); |
| 299 | } |
| 300 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 301 | // Trace the call. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 302 | if (FLAG_trace && info()->IsOptimizing()) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 303 | // We have not executed any compiled code yet, so esi still holds the |
| 304 | // incoming context. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 305 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 306 | } |
| 307 | return !is_aborted(); |
| 308 | } |
| 309 | |
| 310 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 311 | void LCodeGen::GenerateOsrPrologue() { |
| 312 | // Generate the OSR entry prologue at the first unknown OSR value, or if there |
| 313 | // are none, at the OSR entrypoint instruction. |
| 314 | if (osr_pc_offset_ >= 0) return; |
| 315 | |
| 316 | osr_pc_offset_ = masm()->pc_offset(); |
| 317 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 318 | // Move state of dynamic frame alignment into edx. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 319 | __ Set(edx, Immediate(kNoAlignmentPadding)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 320 | |
| 321 | if (support_aligned_spilled_doubles_ && dynamic_frame_alignment_) { |
| 322 | Label do_not_pad, align_loop; |
| 323 | // Align ebp + 4 to a multiple of 2 * kPointerSize. |
| 324 | __ test(ebp, Immediate(kPointerSize)); |
| 325 | __ j(zero, &do_not_pad, Label::kNear); |
| 326 | __ push(Immediate(0)); |
| 327 | __ mov(ebx, esp); |
| 328 | __ mov(edx, Immediate(kAlignmentPaddingPushed)); |
| 329 | |
| 330 | // Move all parts of the frame over one word. The frame consists of: |
| 331 | // unoptimized frame slots, alignment state, context, frame pointer, return |
| 332 | // address, receiver, and the arguments. |
| 333 | __ mov(ecx, Immediate(scope()->num_parameters() + |
| 334 | 5 + graph()->osr()->UnoptimizedFrameSlots())); |
| 335 | |
| 336 | __ bind(&align_loop); |
| 337 | __ mov(eax, Operand(ebx, 1 * kPointerSize)); |
| 338 | __ mov(Operand(ebx, 0), eax); |
| 339 | __ add(Operand(ebx), Immediate(kPointerSize)); |
| 340 | __ dec(ecx); |
| 341 | __ j(not_zero, &align_loop, Label::kNear); |
| 342 | __ mov(Operand(ebx, 0), Immediate(kAlignmentZapValue)); |
| 343 | __ sub(Operand(ebp), Immediate(kPointerSize)); |
| 344 | __ bind(&do_not_pad); |
| 345 | } |
| 346 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 347 | // Save the first local, which is overwritten by the alignment state. |
| 348 | Operand alignment_loc = MemOperand(ebp, -3 * kPointerSize); |
| 349 | __ push(alignment_loc); |
| 350 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 351 | // Set the dynamic frame alignment state. |
| 352 | __ mov(alignment_loc, edx); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 353 | |
| 354 | // Adjust the frame size, subsuming the unoptimized frame into the |
| 355 | // optimized frame. |
| 356 | int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
| 357 | ASSERT(slots >= 1); |
| 358 | __ sub(esp, Immediate((slots - 1) * kPointerSize)); |
| 359 | } |
| 360 | |
| 361 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 362 | void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
| 363 | if (!CpuFeatures::IsSupported(SSE2)) FlushX87StackIfNecessary(instr); |
| 364 | } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 365 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 366 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 367 | void LCodeGen::GenerateBodyInstructionPost(LInstruction* instr) { |
| 368 | if (!CpuFeatures::IsSupported(SSE2)) { |
| 369 | if (instr->IsGoto()) { |
| 370 | x87_stack_.LeavingBlock(current_block_, LGoto::cast(instr)); |
| 371 | } else if (FLAG_debug_code && FLAG_enable_slow_asserts && |
| 372 | !instr->IsGap() && !instr->IsReturn()) { |
| 373 | if (instr->ClobbersDoubleRegisters()) { |
| 374 | if (instr->HasDoubleRegisterResult()) { |
| 375 | ASSERT_EQ(1, x87_stack_.depth()); |
| 376 | } else { |
| 377 | ASSERT_EQ(0, x87_stack_.depth()); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 378 | } |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 379 | } |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 380 | __ VerifyX87StackDepth(x87_stack_.depth()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 381 | } |
| 382 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 386 | bool LCodeGen::GenerateJumpTable() { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 387 | Label needs_frame; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 388 | if (jump_table_.length() > 0) { |
| 389 | Comment(";;; -------------------- Jump table --------------------"); |
| 390 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 391 | for (int i = 0; i < jump_table_.length(); i++) { |
| 392 | __ bind(&jump_table_[i].label); |
| 393 | Address entry = jump_table_[i].address; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 394 | Deoptimizer::BailoutType type = jump_table_[i].bailout_type; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 395 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 396 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 397 | Comment(";;; jump table entry %d.", i); |
| 398 | } else { |
| 399 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 400 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 401 | if (jump_table_[i].needs_frame) { |
| 402 | __ push(Immediate(ExternalReference::ForDeoptEntry(entry))); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 403 | if (needs_frame.is_bound()) { |
| 404 | __ jmp(&needs_frame); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 405 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 406 | __ bind(&needs_frame); |
| 407 | __ push(MemOperand(ebp, StandardFrameConstants::kContextOffset)); |
| 408 | // This variant of deopt can only be used with stubs. Since we don't |
| 409 | // have a function pointer to install in the stack frame that we're |
| 410 | // building, install a special marker there instead. |
| 411 | ASSERT(info()->IsStub()); |
| 412 | __ push(Immediate(Smi::FromInt(StackFrame::STUB))); |
| 413 | // Push a PC inside the function so that the deopt code can find where |
| 414 | // the deopt comes from. It doesn't have to be the precise return |
| 415 | // address of a "calling" LAZY deopt, it only has to be somewhere |
| 416 | // inside the code body. |
| 417 | Label push_approx_pc; |
| 418 | __ call(&push_approx_pc); |
| 419 | __ bind(&push_approx_pc); |
| 420 | // Push the continuation which was stashed were the ebp should |
| 421 | // be. Replace it with the saved ebp. |
| 422 | __ push(MemOperand(esp, 3 * kPointerSize)); |
| 423 | __ mov(MemOperand(esp, 4 * kPointerSize), ebp); |
| 424 | __ lea(ebp, MemOperand(esp, 4 * kPointerSize)); |
| 425 | __ ret(0); // Call the continuation without clobbering registers. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 426 | } |
| 427 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 428 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | return !is_aborted(); |
| 432 | } |
| 433 | |
| 434 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 435 | bool LCodeGen::GenerateDeferredCode() { |
| 436 | ASSERT(is_generating()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 437 | if (deferred_.length() > 0) { |
| 438 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 439 | LDeferredCode* code = deferred_[i]; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 440 | X87Stack copy(code->x87_stack()); |
| 441 | x87_stack_ = copy; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 442 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 443 | HValue* value = |
| 444 | instructions_->at(code->instruction_index())->hydrogen_value(); |
| 445 | RecordAndWritePosition(value->position()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 446 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 447 | Comment(";;; <@%d,#%d> " |
| 448 | "-------------------- Deferred %s --------------------", |
| 449 | code->instruction_index(), |
| 450 | code->instr()->hydrogen_value()->id(), |
| 451 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 452 | __ bind(code->entry()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 453 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 454 | Comment(";;; Build frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 455 | ASSERT(!frame_is_built_); |
| 456 | ASSERT(info()->IsStub()); |
| 457 | frame_is_built_ = true; |
| 458 | // Build the frame in such a way that esi isn't trashed. |
| 459 | __ push(ebp); // Caller's frame pointer. |
| 460 | __ push(Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 461 | __ push(Immediate(Smi::FromInt(StackFrame::STUB))); |
| 462 | __ lea(ebp, Operand(esp, 2 * kPointerSize)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 463 | Comment(";;; Deferred code"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 464 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 465 | code->Generate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 466 | if (NeedsDeferredFrame()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 467 | __ bind(code->done()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 468 | Comment(";;; Destroy frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 469 | ASSERT(frame_is_built_); |
| 470 | frame_is_built_ = false; |
| 471 | __ mov(esp, ebp); |
| 472 | __ pop(ebp); |
| 473 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 474 | __ jmp(code->exit()); |
| 475 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | // Deferred code is the last part of the instruction sequence. Mark |
| 479 | // the generated code as done unless we bailed out. |
| 480 | if (!is_aborted()) status_ = DONE; |
| 481 | return !is_aborted(); |
| 482 | } |
| 483 | |
| 484 | |
| 485 | bool LCodeGen::GenerateSafepointTable() { |
| 486 | ASSERT(is_done()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 487 | if (!info()->IsStub()) { |
| 488 | // For lazy deoptimization we need space to patch a call after every call. |
| 489 | // Ensure there is always space for such patching, even if the code ends |
| 490 | // in a call. |
| 491 | int target_offset = masm()->pc_offset() + Deoptimizer::patch_size(); |
| 492 | while (masm()->pc_offset() < target_offset) { |
| 493 | masm()->nop(); |
| 494 | } |
| 495 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 496 | safepoints_.Emit(masm(), GetStackSlotCount()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 497 | return !is_aborted(); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | Register LCodeGen::ToRegister(int index) const { |
| 502 | return Register::FromAllocationIndex(index); |
| 503 | } |
| 504 | |
| 505 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 506 | X87Register LCodeGen::ToX87Register(int index) const { |
| 507 | return X87Register::FromAllocationIndex(index); |
| 508 | } |
| 509 | |
| 510 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 511 | XMMRegister LCodeGen::ToDoubleRegister(int index) const { |
| 512 | return XMMRegister::FromAllocationIndex(index); |
| 513 | } |
| 514 | |
| 515 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 516 | void LCodeGen::X87LoadForUsage(X87Register reg) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 517 | ASSERT(x87_stack_.Contains(reg)); |
| 518 | x87_stack_.Fxch(reg); |
| 519 | x87_stack_.pop(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 523 | void LCodeGen::X87LoadForUsage(X87Register reg1, X87Register reg2) { |
| 524 | ASSERT(x87_stack_.Contains(reg1)); |
| 525 | ASSERT(x87_stack_.Contains(reg2)); |
| 526 | x87_stack_.Fxch(reg1, 1); |
| 527 | x87_stack_.Fxch(reg2); |
| 528 | x87_stack_.pop(); |
| 529 | x87_stack_.pop(); |
| 530 | } |
| 531 | |
| 532 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 533 | void LCodeGen::X87Stack::Fxch(X87Register reg, int other_slot) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 534 | ASSERT(is_mutable_); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 535 | ASSERT(Contains(reg) && stack_depth_ > other_slot); |
| 536 | int i = ArrayIndex(reg); |
| 537 | int st = st2idx(i); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 538 | if (st != other_slot) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 539 | int other_i = st2idx(other_slot); |
| 540 | X87Register other = stack_[other_i]; |
| 541 | stack_[other_i] = reg; |
| 542 | stack_[i] = other; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 543 | if (st == 0) { |
| 544 | __ fxch(other_slot); |
| 545 | } else if (other_slot == 0) { |
| 546 | __ fxch(st); |
| 547 | } else { |
| 548 | __ fxch(st); |
| 549 | __ fxch(other_slot); |
| 550 | __ fxch(st); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 556 | int LCodeGen::X87Stack::st2idx(int pos) { |
| 557 | return stack_depth_ - pos - 1; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 561 | int LCodeGen::X87Stack::ArrayIndex(X87Register reg) { |
| 562 | for (int i = 0; i < stack_depth_; i++) { |
| 563 | if (stack_[i].is(reg)) return i; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 564 | } |
| 565 | UNREACHABLE(); |
| 566 | return -1; |
| 567 | } |
| 568 | |
| 569 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 570 | bool LCodeGen::X87Stack::Contains(X87Register reg) { |
| 571 | for (int i = 0; i < stack_depth_; i++) { |
| 572 | if (stack_[i].is(reg)) return true; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 573 | } |
| 574 | return false; |
| 575 | } |
| 576 | |
| 577 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 578 | void LCodeGen::X87Stack::Free(X87Register reg) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 579 | ASSERT(is_mutable_); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 580 | ASSERT(Contains(reg)); |
| 581 | int i = ArrayIndex(reg); |
| 582 | int st = st2idx(i); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 583 | if (st > 0) { |
| 584 | // keep track of how fstp(i) changes the order of elements |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 585 | int tos_i = st2idx(0); |
| 586 | stack_[i] = stack_[tos_i]; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 587 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 588 | pop(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 589 | __ fstp(st); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | void LCodeGen::X87Mov(X87Register dst, Operand src, X87OperandType opts) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 594 | if (x87_stack_.Contains(dst)) { |
| 595 | x87_stack_.Fxch(dst); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 596 | __ fstp(0); |
| 597 | } else { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 598 | x87_stack_.push(dst); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 599 | } |
| 600 | X87Fld(src, opts); |
| 601 | } |
| 602 | |
| 603 | |
| 604 | void LCodeGen::X87Fld(Operand src, X87OperandType opts) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 605 | ASSERT(!src.is_reg_only()); |
| 606 | switch (opts) { |
| 607 | case kX87DoubleOperand: |
| 608 | __ fld_d(src); |
| 609 | break; |
| 610 | case kX87FloatOperand: |
| 611 | __ fld_s(src); |
| 612 | break; |
| 613 | case kX87IntOperand: |
| 614 | __ fild_s(src); |
| 615 | break; |
| 616 | default: |
| 617 | UNREACHABLE(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 622 | void LCodeGen::X87Mov(Operand dst, X87Register src, X87OperandType opts) { |
| 623 | ASSERT(!dst.is_reg_only()); |
| 624 | x87_stack_.Fxch(src); |
| 625 | switch (opts) { |
| 626 | case kX87DoubleOperand: |
| 627 | __ fst_d(dst); |
| 628 | break; |
| 629 | case kX87IntOperand: |
| 630 | __ fist_s(dst); |
| 631 | break; |
| 632 | default: |
| 633 | UNREACHABLE(); |
| 634 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 638 | void LCodeGen::X87Stack::PrepareToWrite(X87Register reg) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 639 | ASSERT(is_mutable_); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 640 | if (Contains(reg)) { |
| 641 | Free(reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 642 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 643 | // Mark this register as the next register to write to |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 644 | stack_[stack_depth_] = reg; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 648 | void LCodeGen::X87Stack::CommitWrite(X87Register reg) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 649 | ASSERT(is_mutable_); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 650 | // Assert the reg is prepared to write, but not on the virtual stack yet |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 651 | ASSERT(!Contains(reg) && stack_[stack_depth_].is(reg) && |
| 652 | stack_depth_ < X87Register::kNumAllocatableRegisters); |
| 653 | stack_depth_++; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | |
| 657 | void LCodeGen::X87PrepareBinaryOp( |
| 658 | X87Register left, X87Register right, X87Register result) { |
| 659 | // You need to use DefineSameAsFirst for x87 instructions |
| 660 | ASSERT(result.is(left)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 661 | x87_stack_.Fxch(right, 1); |
| 662 | x87_stack_.Fxch(left); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 666 | void LCodeGen::X87Stack::FlushIfNecessary(LInstruction* instr, LCodeGen* cgen) { |
| 667 | if (stack_depth_ > 0 && instr->ClobbersDoubleRegisters()) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 668 | bool double_inputs = instr->HasDoubleRegisterInput(); |
| 669 | |
| 670 | // Flush stack from tos down, since FreeX87() will mess with tos |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 671 | for (int i = stack_depth_-1; i >= 0; i--) { |
| 672 | X87Register reg = stack_[i]; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 673 | // Skip registers which contain the inputs for the next instruction |
| 674 | // when flushing the stack |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 675 | if (double_inputs && instr->IsDoubleInput(reg, cgen)) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 676 | continue; |
| 677 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 678 | Free(reg); |
| 679 | if (i < stack_depth_-1) i++; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 682 | if (instr->IsReturn()) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 683 | while (stack_depth_ > 0) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 684 | __ fstp(0); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 685 | stack_depth_--; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 686 | } |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 687 | if (FLAG_debug_code && FLAG_enable_slow_asserts) __ VerifyX87StackDepth(0); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | |
| 692 | void LCodeGen::X87Stack::LeavingBlock(int current_block_id, LGoto* goto_instr) { |
| 693 | ASSERT(stack_depth_ <= 1); |
| 694 | // If ever used for new stubs producing two pairs of doubles joined into two |
| 695 | // phis this assert hits. That situation is not handled, since the two stacks |
| 696 | // might have st0 and st1 swapped. |
| 697 | if (current_block_id + 1 != goto_instr->block_id()) { |
| 698 | // If we have a value on the x87 stack on leaving a block, it must be a |
| 699 | // phi input. If the next block we compile is not the join block, we have |
| 700 | // to discard the stack state. |
| 701 | stack_depth_ = 0; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
| 705 | |
| 706 | void LCodeGen::EmitFlushX87ForDeopt() { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 707 | // The deoptimizer does not support X87 Registers. But as long as we |
| 708 | // deopt from a stub its not a problem, since we will re-materialize the |
| 709 | // original stub inputs, which can't be double registers. |
| 710 | ASSERT(info()->IsStub()); |
| 711 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
| 712 | __ pushfd(); |
| 713 | __ VerifyX87StackDepth(x87_stack_.depth()); |
| 714 | __ popfd(); |
| 715 | } |
| 716 | for (int i = 0; i < x87_stack_.depth(); i++) __ fstp(0); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 720 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 721 | ASSERT(op->IsRegister()); |
| 722 | return ToRegister(op->index()); |
| 723 | } |
| 724 | |
| 725 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 726 | X87Register LCodeGen::ToX87Register(LOperand* op) const { |
| 727 | ASSERT(op->IsDoubleRegister()); |
| 728 | return ToX87Register(op->index()); |
| 729 | } |
| 730 | |
| 731 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | XMMRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 733 | ASSERT(op->IsDoubleRegister()); |
| 734 | return ToDoubleRegister(op->index()); |
| 735 | } |
| 736 | |
| 737 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 738 | int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 739 | return ToRepresentation(op, Representation::Integer32()); |
| 740 | } |
| 741 | |
| 742 | |
| 743 | int32_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| 744 | const Representation& r) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 745 | HConstant* constant = chunk_->LookupConstant(op); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 746 | int32_t value = constant->Integer32Value(); |
| 747 | if (r.IsInteger32()) return value; |
| 748 | ASSERT(r.IsSmiOrTagged()); |
| 749 | return reinterpret_cast<int32_t>(Smi::FromInt(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 753 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 754 | HConstant* constant = chunk_->LookupConstant(op); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 755 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 756 | return constant->handle(isolate()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 760 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 761 | HConstant* constant = chunk_->LookupConstant(op); |
| 762 | ASSERT(constant->HasDoubleValue()); |
| 763 | return constant->DoubleValue(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 767 | ExternalReference LCodeGen::ToExternalReference(LConstantOperand* op) const { |
| 768 | HConstant* constant = chunk_->LookupConstant(op); |
| 769 | ASSERT(constant->HasExternalReferenceValue()); |
| 770 | return constant->ExternalReferenceValue(); |
| 771 | } |
| 772 | |
| 773 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 774 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 775 | return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 779 | bool LCodeGen::IsSmi(LConstantOperand* op) const { |
| 780 | return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
| 781 | } |
| 782 | |
| 783 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 784 | static int ArgumentsOffsetWithoutFrame(int index) { |
| 785 | ASSERT(index < 0); |
| 786 | return -(index + 1) * kPointerSize + kPCOnStackSize; |
| 787 | } |
| 788 | |
| 789 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 790 | Operand LCodeGen::ToOperand(LOperand* op) const { |
| 791 | if (op->IsRegister()) return Operand(ToRegister(op)); |
| 792 | if (op->IsDoubleRegister()) return Operand(ToDoubleRegister(op)); |
| 793 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 794 | if (NeedsEagerFrame()) { |
| 795 | return Operand(ebp, StackSlotOffset(op->index())); |
| 796 | } else { |
| 797 | // Retrieve parameter without eager stack-frame relative to the |
| 798 | // stack-pointer. |
| 799 | return Operand(esp, ArgumentsOffsetWithoutFrame(op->index())); |
| 800 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 804 | Operand LCodeGen::HighOperand(LOperand* op) { |
| 805 | ASSERT(op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 806 | if (NeedsEagerFrame()) { |
| 807 | return Operand(ebp, StackSlotOffset(op->index()) + kPointerSize); |
| 808 | } else { |
| 809 | // Retrieve parameter without eager stack-frame relative to the |
| 810 | // stack-pointer. |
| 811 | return Operand( |
| 812 | esp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); |
| 813 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 817 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 818 | Translation* translation) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 819 | if (environment == NULL) return; |
| 820 | |
| 821 | // The translation includes one command per value in the environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 822 | int translation_size = environment->translation_size(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 823 | // The output frame height does not include the parameters. |
| 824 | int height = translation_size - environment->parameter_count(); |
| 825 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 826 | WriteTranslation(environment->outer(), translation); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 827 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 828 | !info()->closure().is_identical_to(environment->closure()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 829 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 830 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 831 | : Translation::kSelfLiteralId; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 832 | switch (environment->frame_type()) { |
| 833 | case JS_FUNCTION: |
| 834 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 835 | break; |
| 836 | case JS_CONSTRUCT: |
| 837 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 838 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 839 | case JS_GETTER: |
| 840 | ASSERT(translation_size == 1); |
| 841 | ASSERT(height == 0); |
| 842 | translation->BeginGetterStubFrame(closure_id); |
| 843 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 844 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 845 | ASSERT(translation_size == 2); |
| 846 | ASSERT(height == 0); |
| 847 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 848 | break; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 849 | case ARGUMENTS_ADAPTOR: |
| 850 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 851 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 852 | case STUB: |
| 853 | translation->BeginCompiledStubFrame(); |
| 854 | break; |
| 855 | default: |
| 856 | UNREACHABLE(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 857 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 858 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 859 | int object_index = 0; |
| 860 | int dematerialized_index = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 861 | for (int i = 0; i < translation_size; ++i) { |
| 862 | LOperand* value = environment->values()->at(i); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 863 | AddToTranslation(environment, |
| 864 | translation, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 865 | value, |
| 866 | environment->HasTaggedValueAt(i), |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 867 | environment->HasUint32ValueAt(i), |
| 868 | &object_index, |
| 869 | &dematerialized_index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
| 873 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 874 | void LCodeGen::AddToTranslation(LEnvironment* environment, |
| 875 | Translation* translation, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 876 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 877 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 878 | bool is_uint32, |
| 879 | int* object_index_pointer, |
| 880 | int* dematerialized_index_pointer) { |
| 881 | if (op == LEnvironment::materialization_marker()) { |
| 882 | int object_index = (*object_index_pointer)++; |
| 883 | if (environment->ObjectIsDuplicateAt(object_index)) { |
| 884 | int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
| 885 | translation->DuplicateObject(dupe_of); |
| 886 | return; |
| 887 | } |
| 888 | int object_length = environment->ObjectLengthAt(object_index); |
| 889 | if (environment->ObjectIsArgumentsAt(object_index)) { |
| 890 | translation->BeginArgumentsObject(object_length); |
| 891 | } else { |
| 892 | translation->BeginCapturedObject(object_length); |
| 893 | } |
| 894 | int dematerialized_index = *dematerialized_index_pointer; |
| 895 | int env_offset = environment->translation_size() + dematerialized_index; |
| 896 | *dematerialized_index_pointer += object_length; |
| 897 | for (int i = 0; i < object_length; ++i) { |
| 898 | LOperand* value = environment->values()->at(env_offset + i); |
| 899 | AddToTranslation(environment, |
| 900 | translation, |
| 901 | value, |
| 902 | environment->HasTaggedValueAt(env_offset + i), |
| 903 | environment->HasUint32ValueAt(env_offset + i), |
| 904 | object_index_pointer, |
| 905 | dematerialized_index_pointer); |
| 906 | } |
| 907 | return; |
| 908 | } |
| 909 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 910 | if (op->IsStackSlot()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 911 | if (is_tagged) { |
| 912 | translation->StoreStackSlot(op->index()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 913 | } else if (is_uint32) { |
| 914 | translation->StoreUint32StackSlot(op->index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 915 | } else { |
| 916 | translation->StoreInt32StackSlot(op->index()); |
| 917 | } |
| 918 | } else if (op->IsDoubleStackSlot()) { |
| 919 | translation->StoreDoubleStackSlot(op->index()); |
| 920 | } else if (op->IsArgument()) { |
| 921 | ASSERT(is_tagged); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 922 | int src_index = GetStackSlotCount() + op->index(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 923 | translation->StoreStackSlot(src_index); |
| 924 | } else if (op->IsRegister()) { |
| 925 | Register reg = ToRegister(op); |
| 926 | if (is_tagged) { |
| 927 | translation->StoreRegister(reg); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 928 | } else if (is_uint32) { |
| 929 | translation->StoreUint32Register(reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 930 | } else { |
| 931 | translation->StoreInt32Register(reg); |
| 932 | } |
| 933 | } else if (op->IsDoubleRegister()) { |
| 934 | XMMRegister reg = ToDoubleRegister(op); |
| 935 | translation->StoreDoubleRegister(reg); |
| 936 | } else if (op->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 937 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 938 | int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 939 | translation->StoreLiteral(src_index); |
| 940 | } else { |
| 941 | UNREACHABLE(); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 946 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 947 | RelocInfo::Mode mode, |
| 948 | LInstruction* instr, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 949 | SafepointMode safepoint_mode) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 950 | ASSERT(instr != NULL); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 951 | __ call(code, mode); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 952 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 953 | |
| 954 | // Signal that we don't inline smi code before these stubs in the |
| 955 | // optimizing code generator. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 956 | if (code->kind() == Code::BINARY_OP_IC || |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 957 | code->kind() == Code::COMPARE_IC) { |
| 958 | __ nop(); |
| 959 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 963 | void LCodeGen::CallCode(Handle<Code> code, |
| 964 | RelocInfo::Mode mode, |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 965 | LInstruction* instr) { |
| 966 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 970 | void LCodeGen::CallRuntime(const Runtime::Function* fun, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 971 | int argc, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 972 | LInstruction* instr, |
| 973 | SaveFPRegsMode save_doubles) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 974 | ASSERT(instr != NULL); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 975 | ASSERT(instr->HasPointerMap()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 976 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 977 | __ CallRuntime(fun, argc, save_doubles); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 978 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 979 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 980 | |
| 981 | ASSERT(info()->is_calling()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 985 | void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 986 | if (context->IsRegister()) { |
| 987 | if (!ToRegister(context).is(esi)) { |
| 988 | __ mov(esi, ToRegister(context)); |
| 989 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 990 | } else if (context->IsStackSlot()) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 991 | __ mov(esi, ToOperand(context)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 992 | } else if (context->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 993 | HConstant* constant = |
| 994 | chunk_->LookupConstant(LConstantOperand::cast(context)); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 995 | __ LoadObject(esi, Handle<Object>::cast(constant->handle(isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 996 | } else { |
| 997 | UNREACHABLE(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 998 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 1002 | int argc, |
| 1003 | LInstruction* instr, |
| 1004 | LOperand* context) { |
| 1005 | LoadContextFromDeferred(context); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1006 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1007 | __ CallRuntimeSaveDoubles(id); |
| 1008 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1009 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1010 | |
| 1011 | ASSERT(info()->is_calling()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1015 | void LCodeGen::RegisterEnvironmentForDeoptimization( |
| 1016 | LEnvironment* environment, Safepoint::DeoptMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1017 | if (!environment->HasBeenRegistered()) { |
| 1018 | // Physical stack frame layout: |
| 1019 | // -x ............. -4 0 ..................................... y |
| 1020 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 1021 | |
| 1022 | // Layout of the environment: |
| 1023 | // 0 ..................................................... size-1 |
| 1024 | // [parameters] [locals] [expression stack including arguments] |
| 1025 | |
| 1026 | // Layout of the translation: |
| 1027 | // 0 ........................................................ size - 1 + 4 |
| 1028 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 1029 | // |>------------ translation_size ------------<| |
| 1030 | |
| 1031 | int frame_count = 0; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1032 | int jsframe_count = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1033 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 1034 | ++frame_count; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1035 | if (e->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1036 | ++jsframe_count; |
| 1037 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1038 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1039 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1040 | WriteTranslation(environment, &translation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | int deoptimization_index = deoptimizations_.length(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1042 | int pc_offset = masm()->pc_offset(); |
| 1043 | environment->Register(deoptimization_index, |
| 1044 | translation.index(), |
| 1045 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1046 | deoptimizations_.Add(environment, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 1051 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 1052 | LEnvironment* environment, |
| 1053 | Deoptimizer::BailoutType bailout_type) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1054 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1055 | ASSERT(environment->HasBeenRegistered()); |
| 1056 | int id = environment->deoptimization_index(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1057 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1058 | Address entry = |
| 1059 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1060 | if (entry == NULL) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1061 | Abort(kBailoutWasNotPrepared); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1062 | return; |
| 1063 | } |
| 1064 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1065 | if (DeoptEveryNTimes()) { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1066 | ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1067 | Label no_deopt; |
| 1068 | __ pushfd(); |
| 1069 | __ push(eax); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1070 | __ mov(eax, Operand::StaticVariable(count)); |
| 1071 | __ sub(eax, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1072 | __ j(not_zero, &no_deopt, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1073 | if (FLAG_trap_on_deopt) __ int3(); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1074 | __ mov(eax, Immediate(FLAG_deopt_every_n_times)); |
| 1075 | __ mov(Operand::StaticVariable(count), eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1076 | __ pop(eax); |
| 1077 | __ popfd(); |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 1078 | ASSERT(frame_is_built_); |
| 1079 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1080 | __ bind(&no_deopt); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1081 | __ mov(Operand::StaticVariable(count), eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1082 | __ pop(eax); |
| 1083 | __ popfd(); |
| 1084 | } |
| 1085 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1086 | // Before Instructions which can deopt, we normally flush the x87 stack. But |
| 1087 | // we can have inputs or outputs of the current instruction on the stack, |
| 1088 | // thus we need to flush them here from the physical stack to leave it in a |
| 1089 | // consistent state. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1090 | if (x87_stack_.depth() > 0) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1091 | Label done; |
| 1092 | if (cc != no_condition) __ j(NegateCondition(cc), &done, Label::kNear); |
| 1093 | EmitFlushX87ForDeopt(); |
| 1094 | __ bind(&done); |
| 1095 | } |
| 1096 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1097 | if (info()->ShouldTrapOnDeopt()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1098 | Label done; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1099 | if (cc != no_condition) __ j(NegateCondition(cc), &done, Label::kNear); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1100 | __ int3(); |
| 1101 | __ bind(&done); |
| 1102 | } |
| 1103 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1104 | ASSERT(info()->IsStub() || frame_is_built_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1105 | if (cc == no_condition && frame_is_built_) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1106 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1107 | } else { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1108 | // We often have several deopts to the same entry, reuse the last |
| 1109 | // jump entry if this is the case. |
| 1110 | if (jump_table_.is_empty() || |
| 1111 | jump_table_.last().address != entry || |
| 1112 | jump_table_.last().needs_frame != !frame_is_built_ || |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 1113 | jump_table_.last().bailout_type != bailout_type) { |
| 1114 | Deoptimizer::JumpTableEntry table_entry(entry, |
| 1115 | bailout_type, |
| 1116 | !frame_is_built_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1117 | jump_table_.Add(table_entry, zone()); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1118 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1119 | if (cc == no_condition) { |
| 1120 | __ jmp(&jump_table_.last().label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1121 | } else { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1122 | __ j(cc, &jump_table_.last().label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1123 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 1128 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 1129 | LEnvironment* environment) { |
| 1130 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 1131 | ? Deoptimizer::LAZY |
| 1132 | : Deoptimizer::EAGER; |
| 1133 | DeoptimizeIf(cc, environment, bailout_type); |
| 1134 | } |
| 1135 | |
| 1136 | |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1137 | void LCodeGen::RegisterDependentCodeForEmbeddedMaps(Handle<Code> code) { |
| 1138 | ZoneList<Handle<Map> > maps(1, zone()); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 1139 | ZoneList<Handle<JSObject> > objects(1, zone()); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1140 | int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 1141 | for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 1142 | if (Code::IsWeakEmbeddedObject(code->kind(), it.rinfo()->target_object())) { |
| 1143 | if (it.rinfo()->target_object()->IsMap()) { |
| 1144 | Handle<Map> map(Map::cast(it.rinfo()->target_object())); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1145 | maps.Add(map, zone()); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 1146 | } else if (it.rinfo()->target_object()->IsJSObject()) { |
| 1147 | Handle<JSObject> object(JSObject::cast(it.rinfo()->target_object())); |
| 1148 | objects.Add(object, zone()); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | #ifdef VERIFY_HEAP |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 1153 | // This disables verification of weak embedded objects after full GC. |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1154 | // AddDependentCode can cause a GC, which would observe the state where |
| 1155 | // this code is not yet in the depended code lists of the embedded maps. |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 1156 | NoWeakObjectVerificationScope disable_verification_of_embedded_objects; |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1157 | #endif |
| 1158 | for (int i = 0; i < maps.length(); i++) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 1159 | maps.at(i)->AddDependentCode(DependentCode::kWeaklyEmbeddedGroup, code); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1160 | } |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 1161 | for (int i = 0; i < objects.length(); i++) { |
| 1162 | AddWeakObjectToCodeDependency(isolate()->heap(), objects.at(i), code); |
| 1163 | } |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1167 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 1168 | int length = deoptimizations_.length(); |
| 1169 | if (length == 0) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1170 | Handle<DeoptimizationInputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1171 | factory()->NewDeoptimizationInputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1172 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 1173 | Handle<ByteArray> translations = |
| 1174 | translations_.CreateByteArray(isolate()->factory()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1175 | data->SetTranslationByteArray(*translations); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 1177 | |
| 1178 | Handle<FixedArray> literals = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1179 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1180 | { AllowDeferredHandleDereference copy_handles; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1181 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 1182 | literals->set(i, *deoptimization_literals_[i]); |
| 1183 | } |
| 1184 | data->SetLiteralArray(*literals); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1185 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1186 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1187 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1188 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 1189 | |
| 1190 | // Populate the deoptimization entries. |
| 1191 | for (int i = 0; i < length; i++) { |
| 1192 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1193 | data->SetAstId(i, env->ast_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1194 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 1195 | data->SetArgumentsStackHeight(i, |
| 1196 | Smi::FromInt(env->arguments_stack_height())); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1197 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1198 | } |
| 1199 | code->set_deoptimization_data(*data); |
| 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 1204 | int result = deoptimization_literals_.length(); |
| 1205 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 1206 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 1207 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1208 | deoptimization_literals_.Add(literal, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1209 | return result; |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 1214 | ASSERT(deoptimization_literals_.length() == 0); |
| 1215 | |
| 1216 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 1217 | chunk()->inlined_closures(); |
| 1218 | |
| 1219 | for (int i = 0, length = inlined_closures->length(); |
| 1220 | i < length; |
| 1221 | i++) { |
| 1222 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 1223 | } |
| 1224 | |
| 1225 | inlined_function_count_ = deoptimization_literals_.length(); |
| 1226 | } |
| 1227 | |
| 1228 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1229 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 1230 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 1231 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 1232 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 1233 | } else { |
| 1234 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 1235 | RecordSafepointWithRegisters( |
| 1236 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1241 | void LCodeGen::RecordSafepoint( |
| 1242 | LPointerMap* pointers, |
| 1243 | Safepoint::Kind kind, |
| 1244 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1245 | Safepoint::DeoptMode deopt_mode) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1246 | ASSERT(kind == expected_safepoint_kind_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1247 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1248 | Safepoint safepoint = |
| 1249 | safepoints_.DefineSafepoint(masm(), kind, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1250 | for (int i = 0; i < operands->length(); i++) { |
| 1251 | LOperand* pointer = operands->at(i); |
| 1252 | if (pointer->IsStackSlot()) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 1253 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1254 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1255 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1256 | } |
| 1257 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | |
| 1261 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1262 | Safepoint::DeoptMode mode) { |
| 1263 | RecordSafepoint(pointers, Safepoint::kSimple, 0, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1267 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode mode) { |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1268 | LPointerMap empty_pointers(zone()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1269 | RecordSafepoint(&empty_pointers, mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1273 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 1274 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1275 | Safepoint::DeoptMode mode) { |
| 1276 | RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1280 | void LCodeGen::RecordAndWritePosition(int position) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1281 | if (position == RelocInfo::kNoPosition) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1282 | masm()->positions_recorder()->RecordPosition(position); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1283 | masm()->positions_recorder()->WriteRecordedPositions(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1287 | static const char* LabelType(LLabel* label) { |
| 1288 | if (label->is_loop_header()) return " (loop header)"; |
| 1289 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 1290 | return ""; |
| 1291 | } |
| 1292 | |
| 1293 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1294 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1295 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1296 | current_instruction_, |
| 1297 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1298 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1299 | LabelType(label)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1300 | __ bind(label->label()); |
| 1301 | current_block_ = label->block_id(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1302 | DoGap(label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1307 | resolver_.Resolve(move); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | |
| 1311 | void LCodeGen::DoGap(LGap* gap) { |
| 1312 | for (int i = LGap::FIRST_INNER_POSITION; |
| 1313 | i <= LGap::LAST_INNER_POSITION; |
| 1314 | i++) { |
| 1315 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 1316 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 1317 | if (move != NULL) DoParallelMove(move); |
| 1318 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1322 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 1323 | DoGap(instr); |
| 1324 | } |
| 1325 | |
| 1326 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1327 | void LCodeGen::DoParameter(LParameter* instr) { |
| 1328 | // Nothing to do. |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | void LCodeGen::DoCallStub(LCallStub* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1333 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1334 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 1335 | switch (instr->hydrogen()->major_key()) { |
| 1336 | case CodeStub::RegExpConstructResult: { |
| 1337 | RegExpConstructResultStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1338 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | case CodeStub::RegExpExec: { |
| 1342 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1343 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1344 | break; |
| 1345 | } |
| 1346 | case CodeStub::SubString: { |
| 1347 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1348 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1349 | break; |
| 1350 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1351 | case CodeStub::StringCompare: { |
| 1352 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1353 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | break; |
| 1355 | } |
| 1356 | case CodeStub::TranscendentalCache: { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1357 | TranscendentalCacheStub stub(instr->transcendental_type(), |
| 1358 | TranscendentalCacheStub::TAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1359 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1360 | break; |
| 1361 | } |
| 1362 | default: |
| 1363 | UNREACHABLE(); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1369 | GenerateOsrPrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | void LCodeGen::DoModI(LModI* instr) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1374 | HMod* hmod = instr->hydrogen(); |
| 1375 | HValue* left = hmod->left(); |
| 1376 | HValue* right = hmod->right(); |
| 1377 | if (hmod->HasPowerOf2Divisor()) { |
| 1378 | // TODO(svenpanne) We should really do the strength reduction on the |
| 1379 | // Hydrogen level. |
| 1380 | Register left_reg = ToRegister(instr->left()); |
| 1381 | ASSERT(left_reg.is(ToRegister(instr->result()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1382 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1383 | // Note: The code below even works when right contains kMinInt. |
| 1384 | int32_t divisor = Abs(right->GetInteger32Constant()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1385 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1386 | Label left_is_not_negative, done; |
| 1387 | if (left->CanBeNegative()) { |
| 1388 | __ test(left_reg, Operand(left_reg)); |
| 1389 | __ j(not_sign, &left_is_not_negative, Label::kNear); |
| 1390 | __ neg(left_reg); |
| 1391 | __ and_(left_reg, divisor - 1); |
| 1392 | __ neg(left_reg); |
| 1393 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1394 | DeoptimizeIf(zero, instr->environment()); |
| 1395 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1396 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1397 | } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1398 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1399 | __ bind(&left_is_not_negative); |
| 1400 | __ and_(left_reg, divisor - 1); |
| 1401 | __ bind(&done); |
| 1402 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1403 | } else if (hmod->fixed_right_arg().has_value) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1404 | Register left_reg = ToRegister(instr->left()); |
| 1405 | ASSERT(left_reg.is(ToRegister(instr->result()))); |
| 1406 | Register right_reg = ToRegister(instr->right()); |
| 1407 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1408 | int32_t divisor = hmod->fixed_right_arg().value; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1409 | ASSERT(IsPowerOf2(divisor)); |
| 1410 | |
| 1411 | // Check if our assumption of a fixed right operand still holds. |
| 1412 | __ cmp(right_reg, Immediate(divisor)); |
| 1413 | DeoptimizeIf(not_equal, instr->environment()); |
| 1414 | |
| 1415 | Label left_is_not_negative, done; |
| 1416 | if (left->CanBeNegative()) { |
| 1417 | __ test(left_reg, Operand(left_reg)); |
| 1418 | __ j(not_sign, &left_is_not_negative, Label::kNear); |
| 1419 | __ neg(left_reg); |
| 1420 | __ and_(left_reg, divisor - 1); |
| 1421 | __ neg(left_reg); |
| 1422 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1423 | DeoptimizeIf(zero, instr->environment()); |
| 1424 | } |
| 1425 | __ jmp(&done, Label::kNear); |
| 1426 | } |
| 1427 | |
| 1428 | __ bind(&left_is_not_negative); |
| 1429 | __ and_(left_reg, divisor - 1); |
| 1430 | __ bind(&done); |
| 1431 | |
| 1432 | } else { |
| 1433 | Register left_reg = ToRegister(instr->left()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1434 | ASSERT(left_reg.is(eax)); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1435 | Register right_reg = ToRegister(instr->right()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1436 | ASSERT(!right_reg.is(eax)); |
| 1437 | ASSERT(!right_reg.is(edx)); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1438 | Register result_reg = ToRegister(instr->result()); |
| 1439 | ASSERT(result_reg.is(edx)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1440 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1441 | Label done; |
| 1442 | // Check for x % 0, idiv would signal a divide error. We have to |
| 1443 | // deopt in this case because we can't return a NaN. |
| 1444 | if (right->CanBeZero()) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1445 | __ test(right_reg, Operand(right_reg)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1446 | DeoptimizeIf(zero, instr->environment()); |
| 1447 | } |
| 1448 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1449 | // Check for kMinInt % -1, idiv would signal a divide error. We |
| 1450 | // have to deopt if we care about -0, because we can't return that. |
| 1451 | if (left->RangeCanInclude(kMinInt) && right->RangeCanInclude(-1)) { |
| 1452 | Label no_overflow_possible; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1453 | __ cmp(left_reg, kMinInt); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1454 | __ j(not_equal, &no_overflow_possible, Label::kNear); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1455 | __ cmp(right_reg, -1); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1456 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1457 | DeoptimizeIf(equal, instr->environment()); |
| 1458 | } else { |
| 1459 | __ j(not_equal, &no_overflow_possible, Label::kNear); |
| 1460 | __ Set(result_reg, Immediate(0)); |
| 1461 | __ jmp(&done, Label::kNear); |
| 1462 | } |
| 1463 | __ bind(&no_overflow_possible); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1466 | // Sign extend dividend in eax into edx:eax. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1467 | __ cdq(); |
| 1468 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1469 | // If we care about -0, test if the dividend is <0 and the result is 0. |
| 1470 | if (left->CanBeNegative() && |
| 1471 | hmod->CanBeZero() && |
| 1472 | hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1473 | Label positive_left; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1474 | __ test(left_reg, Operand(left_reg)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1475 | __ j(not_sign, &positive_left, Label::kNear); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1476 | __ idiv(right_reg); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1477 | __ test(result_reg, Operand(result_reg)); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1478 | DeoptimizeIf(zero, instr->environment()); |
| 1479 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1480 | __ bind(&positive_left); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1481 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1482 | __ idiv(right_reg); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1483 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | void LCodeGen::DoDivI(LDivI* instr) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1489 | if (!instr->is_flooring() && instr->hydrogen()->HasPowerOf2Divisor()) { |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1490 | Register dividend = ToRegister(instr->left()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1491 | int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant(); |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1492 | int32_t test_value = 0; |
| 1493 | int32_t power = 0; |
| 1494 | |
| 1495 | if (divisor > 0) { |
| 1496 | test_value = divisor - 1; |
| 1497 | power = WhichPowerOf2(divisor); |
| 1498 | } else { |
| 1499 | // Check for (0 / -x) that will produce negative zero. |
| 1500 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1501 | __ test(dividend, Operand(dividend)); |
| 1502 | DeoptimizeIf(zero, instr->environment()); |
| 1503 | } |
| 1504 | // Check for (kMinInt / -1). |
| 1505 | if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1506 | __ cmp(dividend, kMinInt); |
| 1507 | DeoptimizeIf(zero, instr->environment()); |
| 1508 | } |
| 1509 | test_value = - divisor - 1; |
| 1510 | power = WhichPowerOf2(-divisor); |
| 1511 | } |
| 1512 | |
| 1513 | if (test_value != 0) { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1514 | if (instr->hydrogen()->CheckFlag( |
| 1515 | HInstruction::kAllUsesTruncatingToInt32)) { |
| 1516 | Label done, negative; |
| 1517 | __ cmp(dividend, 0); |
| 1518 | __ j(less, &negative, Label::kNear); |
| 1519 | __ sar(dividend, power); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1520 | if (divisor < 0) __ neg(dividend); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1521 | __ jmp(&done, Label::kNear); |
| 1522 | |
| 1523 | __ bind(&negative); |
| 1524 | __ neg(dividend); |
| 1525 | __ sar(dividend, power); |
| 1526 | if (divisor > 0) __ neg(dividend); |
| 1527 | __ bind(&done); |
| 1528 | return; // Don't fall through to "__ neg" below. |
| 1529 | } else { |
| 1530 | // Deoptimize if remainder is not 0. |
| 1531 | __ test(dividend, Immediate(test_value)); |
| 1532 | DeoptimizeIf(not_zero, instr->environment()); |
| 1533 | __ sar(dividend, power); |
| 1534 | } |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | if (divisor < 0) __ neg(dividend); |
| 1538 | |
| 1539 | return; |
| 1540 | } |
| 1541 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1542 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1543 | ASSERT(ToRegister(instr->result()).is(eax)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1544 | ASSERT(ToRegister(instr->left()).is(eax)); |
| 1545 | ASSERT(!ToRegister(instr->right()).is(eax)); |
| 1546 | ASSERT(!ToRegister(instr->right()).is(edx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1547 | |
| 1548 | Register left_reg = eax; |
| 1549 | |
| 1550 | // Check for x / 0. |
| 1551 | Register right_reg = ToRegister(right); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1552 | if (instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1553 | __ test(right_reg, ToOperand(right)); |
| 1554 | DeoptimizeIf(zero, instr->environment()); |
| 1555 | } |
| 1556 | |
| 1557 | // Check for (0 / -x) that will produce negative zero. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1558 | if (instr->hydrogen_value()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1559 | Label left_not_zero; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1560 | __ test(left_reg, Operand(left_reg)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1561 | __ j(not_zero, &left_not_zero, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1562 | __ test(right_reg, ToOperand(right)); |
| 1563 | DeoptimizeIf(sign, instr->environment()); |
| 1564 | __ bind(&left_not_zero); |
| 1565 | } |
| 1566 | |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1567 | // Check for (kMinInt / -1). |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1568 | if (instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1569 | Label left_not_min_int; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1570 | __ cmp(left_reg, kMinInt); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1571 | __ j(not_zero, &left_not_min_int, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1572 | __ cmp(right_reg, -1); |
| 1573 | DeoptimizeIf(zero, instr->environment()); |
| 1574 | __ bind(&left_not_min_int); |
| 1575 | } |
| 1576 | |
| 1577 | // Sign extend to edx. |
| 1578 | __ cdq(); |
| 1579 | __ idiv(right_reg); |
| 1580 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1581 | if (instr->is_flooring()) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1582 | Label done; |
| 1583 | __ test(edx, edx); |
| 1584 | __ j(zero, &done, Label::kNear); |
| 1585 | __ xor_(edx, right_reg); |
| 1586 | __ sar(edx, 31); |
| 1587 | __ add(eax, edx); |
| 1588 | __ bind(&done); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1589 | } else if (!instr->hydrogen()->CheckFlag( |
| 1590 | HInstruction::kAllUsesTruncatingToInt32)) { |
| 1591 | // Deoptimize if remainder is not 0. |
| 1592 | __ test(edx, Operand(edx)); |
| 1593 | DeoptimizeIf(not_zero, instr->environment()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1594 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1598 | void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1599 | ASSERT(instr->right()->IsConstantOperand()); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1600 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1601 | Register dividend = ToRegister(instr->left()); |
| 1602 | int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1603 | Register result = ToRegister(instr->result()); |
| 1604 | |
| 1605 | switch (divisor) { |
| 1606 | case 0: |
| 1607 | DeoptimizeIf(no_condition, instr->environment()); |
| 1608 | return; |
| 1609 | |
| 1610 | case 1: |
| 1611 | __ Move(result, dividend); |
| 1612 | return; |
| 1613 | |
| 1614 | case -1: |
| 1615 | __ Move(result, dividend); |
| 1616 | __ neg(result); |
| 1617 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1618 | DeoptimizeIf(zero, instr->environment()); |
| 1619 | } |
| 1620 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1621 | DeoptimizeIf(overflow, instr->environment()); |
| 1622 | } |
| 1623 | return; |
| 1624 | } |
| 1625 | |
| 1626 | uint32_t divisor_abs = abs(divisor); |
| 1627 | if (IsPowerOf2(divisor_abs)) { |
| 1628 | int32_t power = WhichPowerOf2(divisor_abs); |
| 1629 | if (divisor < 0) { |
| 1630 | // Input[dividend] is clobbered. |
| 1631 | // The sequence is tedious because neg(dividend) might overflow. |
| 1632 | __ mov(result, dividend); |
| 1633 | __ sar(dividend, 31); |
| 1634 | __ neg(result); |
| 1635 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1636 | DeoptimizeIf(zero, instr->environment()); |
| 1637 | } |
| 1638 | __ shl(dividend, 32 - power); |
| 1639 | __ sar(result, power); |
| 1640 | __ not_(dividend); |
| 1641 | // Clear result.sign if dividend.sign is set. |
| 1642 | __ and_(result, dividend); |
| 1643 | } else { |
| 1644 | __ Move(result, dividend); |
| 1645 | __ sar(result, power); |
| 1646 | } |
| 1647 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1648 | ASSERT(ToRegister(instr->left()).is(eax)); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1649 | ASSERT(ToRegister(instr->result()).is(edx)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1650 | Register scratch = ToRegister(instr->temp()); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1651 | |
| 1652 | // Find b which: 2^b < divisor_abs < 2^(b+1). |
| 1653 | unsigned b = 31 - CompilerIntrinsics::CountLeadingZeros(divisor_abs); |
| 1654 | unsigned shift = 32 + b; // Precision +1bit (effectively). |
| 1655 | double multiplier_f = |
| 1656 | static_cast<double>(static_cast<uint64_t>(1) << shift) / divisor_abs; |
| 1657 | int64_t multiplier; |
| 1658 | if (multiplier_f - floor(multiplier_f) < 0.5) { |
| 1659 | multiplier = static_cast<int64_t>(floor(multiplier_f)); |
| 1660 | } else { |
| 1661 | multiplier = static_cast<int64_t>(floor(multiplier_f)) + 1; |
| 1662 | } |
| 1663 | // The multiplier is a uint32. |
| 1664 | ASSERT(multiplier > 0 && |
| 1665 | multiplier < (static_cast<int64_t>(1) << 32)); |
| 1666 | __ mov(scratch, dividend); |
| 1667 | if (divisor < 0 && |
| 1668 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1669 | __ test(dividend, dividend); |
| 1670 | DeoptimizeIf(zero, instr->environment()); |
| 1671 | } |
| 1672 | __ mov(edx, static_cast<int32_t>(multiplier)); |
| 1673 | __ imul(edx); |
| 1674 | if (static_cast<int32_t>(multiplier) < 0) { |
| 1675 | __ add(edx, scratch); |
| 1676 | } |
| 1677 | Register reg_lo = eax; |
| 1678 | Register reg_byte_scratch = scratch; |
| 1679 | if (!reg_byte_scratch.is_byte_register()) { |
| 1680 | __ xchg(reg_lo, reg_byte_scratch); |
| 1681 | reg_lo = scratch; |
| 1682 | reg_byte_scratch = eax; |
| 1683 | } |
| 1684 | if (divisor < 0) { |
| 1685 | __ xor_(reg_byte_scratch, reg_byte_scratch); |
| 1686 | __ cmp(reg_lo, 0x40000000); |
| 1687 | __ setcc(above, reg_byte_scratch); |
| 1688 | __ neg(edx); |
| 1689 | __ sub(edx, reg_byte_scratch); |
| 1690 | } else { |
| 1691 | __ xor_(reg_byte_scratch, reg_byte_scratch); |
| 1692 | __ cmp(reg_lo, 0xC0000000); |
| 1693 | __ setcc(above_equal, reg_byte_scratch); |
| 1694 | __ add(edx, reg_byte_scratch); |
| 1695 | } |
| 1696 | __ sar(edx, shift - 32); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1701 | void LCodeGen::DoMulI(LMulI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1702 | Register left = ToRegister(instr->left()); |
| 1703 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1704 | |
| 1705 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1706 | __ mov(ToRegister(instr->temp()), left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | if (right->IsConstantOperand()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1710 | // Try strength reductions on the multiplication. |
| 1711 | // All replacement instructions are at most as long as the imul |
| 1712 | // and have better latency. |
| 1713 | int constant = ToInteger32(LConstantOperand::cast(right)); |
| 1714 | if (constant == -1) { |
| 1715 | __ neg(left); |
| 1716 | } else if (constant == 0) { |
| 1717 | __ xor_(left, Operand(left)); |
| 1718 | } else if (constant == 2) { |
| 1719 | __ add(left, Operand(left)); |
| 1720 | } else if (!instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1721 | // If we know that the multiplication can't overflow, it's safe to |
| 1722 | // use instructions that don't set the overflow flag for the |
| 1723 | // multiplication. |
| 1724 | switch (constant) { |
| 1725 | case 1: |
| 1726 | // Do nothing. |
| 1727 | break; |
| 1728 | case 3: |
| 1729 | __ lea(left, Operand(left, left, times_2, 0)); |
| 1730 | break; |
| 1731 | case 4: |
| 1732 | __ shl(left, 2); |
| 1733 | break; |
| 1734 | case 5: |
| 1735 | __ lea(left, Operand(left, left, times_4, 0)); |
| 1736 | break; |
| 1737 | case 8: |
| 1738 | __ shl(left, 3); |
| 1739 | break; |
| 1740 | case 9: |
| 1741 | __ lea(left, Operand(left, left, times_8, 0)); |
| 1742 | break; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1743 | case 16: |
| 1744 | __ shl(left, 4); |
| 1745 | break; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1746 | default: |
| 1747 | __ imul(left, left, constant); |
| 1748 | break; |
| 1749 | } |
| 1750 | } else { |
| 1751 | __ imul(left, left, constant); |
| 1752 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1753 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1754 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1755 | __ SmiUntag(left); |
| 1756 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1757 | __ imul(left, ToOperand(right)); |
| 1758 | } |
| 1759 | |
| 1760 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1761 | DeoptimizeIf(overflow, instr->environment()); |
| 1762 | } |
| 1763 | |
| 1764 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1765 | // Bail out if the result is supposed to be negative zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1766 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | __ test(left, Operand(left)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1768 | __ j(not_zero, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | if (right->IsConstantOperand()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1770 | if (ToInteger32(LConstantOperand::cast(right)) < 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1771 | DeoptimizeIf(no_condition, instr->environment()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1772 | } else if (ToInteger32(LConstantOperand::cast(right)) == 0) { |
| 1773 | __ cmp(ToRegister(instr->temp()), Immediate(0)); |
| 1774 | DeoptimizeIf(less, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | } |
| 1776 | } else { |
| 1777 | // Test the non-zero operand for negative sign. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1778 | __ or_(ToRegister(instr->temp()), ToOperand(right)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1779 | DeoptimizeIf(sign, instr->environment()); |
| 1780 | } |
| 1781 | __ bind(&done); |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | void LCodeGen::DoBitI(LBitI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1787 | LOperand* left = instr->left(); |
| 1788 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1789 | ASSERT(left->Equals(instr->result())); |
| 1790 | ASSERT(left->IsRegister()); |
| 1791 | |
| 1792 | if (right->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1793 | int32_t right_operand = |
| 1794 | ToRepresentation(LConstantOperand::cast(right), |
| 1795 | instr->hydrogen()->representation()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1796 | switch (instr->op()) { |
| 1797 | case Token::BIT_AND: |
| 1798 | __ and_(ToRegister(left), right_operand); |
| 1799 | break; |
| 1800 | case Token::BIT_OR: |
| 1801 | __ or_(ToRegister(left), right_operand); |
| 1802 | break; |
| 1803 | case Token::BIT_XOR: |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1804 | if (right_operand == int32_t(~0)) { |
| 1805 | __ not_(ToRegister(left)); |
| 1806 | } else { |
| 1807 | __ xor_(ToRegister(left), right_operand); |
| 1808 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1809 | break; |
| 1810 | default: |
| 1811 | UNREACHABLE(); |
| 1812 | break; |
| 1813 | } |
| 1814 | } else { |
| 1815 | switch (instr->op()) { |
| 1816 | case Token::BIT_AND: |
| 1817 | __ and_(ToRegister(left), ToOperand(right)); |
| 1818 | break; |
| 1819 | case Token::BIT_OR: |
| 1820 | __ or_(ToRegister(left), ToOperand(right)); |
| 1821 | break; |
| 1822 | case Token::BIT_XOR: |
| 1823 | __ xor_(ToRegister(left), ToOperand(right)); |
| 1824 | break; |
| 1825 | default: |
| 1826 | UNREACHABLE(); |
| 1827 | break; |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | |
| 1833 | void LCodeGen::DoShiftI(LShiftI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1834 | LOperand* left = instr->left(); |
| 1835 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1836 | ASSERT(left->Equals(instr->result())); |
| 1837 | ASSERT(left->IsRegister()); |
| 1838 | if (right->IsRegister()) { |
| 1839 | ASSERT(ToRegister(right).is(ecx)); |
| 1840 | |
| 1841 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1842 | case Token::ROR: |
| 1843 | __ ror_cl(ToRegister(left)); |
| 1844 | if (instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1845 | __ test(ToRegister(left), ToRegister(left)); |
| 1846 | DeoptimizeIf(sign, instr->environment()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1847 | } |
| 1848 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1849 | case Token::SAR: |
| 1850 | __ sar_cl(ToRegister(left)); |
| 1851 | break; |
| 1852 | case Token::SHR: |
| 1853 | __ shr_cl(ToRegister(left)); |
| 1854 | if (instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1855 | __ test(ToRegister(left), ToRegister(left)); |
| 1856 | DeoptimizeIf(sign, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1857 | } |
| 1858 | break; |
| 1859 | case Token::SHL: |
| 1860 | __ shl_cl(ToRegister(left)); |
| 1861 | break; |
| 1862 | default: |
| 1863 | UNREACHABLE(); |
| 1864 | break; |
| 1865 | } |
| 1866 | } else { |
| 1867 | int value = ToInteger32(LConstantOperand::cast(right)); |
| 1868 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1869 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1870 | case Token::ROR: |
| 1871 | if (shift_count == 0 && instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1872 | __ test(ToRegister(left), ToRegister(left)); |
| 1873 | DeoptimizeIf(sign, instr->environment()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1874 | } else { |
| 1875 | __ ror(ToRegister(left), shift_count); |
| 1876 | } |
| 1877 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1878 | case Token::SAR: |
| 1879 | if (shift_count != 0) { |
| 1880 | __ sar(ToRegister(left), shift_count); |
| 1881 | } |
| 1882 | break; |
| 1883 | case Token::SHR: |
| 1884 | if (shift_count == 0 && instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1885 | __ test(ToRegister(left), ToRegister(left)); |
| 1886 | DeoptimizeIf(sign, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1887 | } else { |
| 1888 | __ shr(ToRegister(left), shift_count); |
| 1889 | } |
| 1890 | break; |
| 1891 | case Token::SHL: |
| 1892 | if (shift_count != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1893 | if (instr->hydrogen_value()->representation().IsSmi() && |
| 1894 | instr->can_deopt()) { |
| 1895 | if (shift_count != 1) { |
| 1896 | __ shl(ToRegister(left), shift_count - 1); |
| 1897 | } |
| 1898 | __ SmiTag(ToRegister(left)); |
| 1899 | DeoptimizeIf(overflow, instr->environment()); |
| 1900 | } else { |
| 1901 | __ shl(ToRegister(left), shift_count); |
| 1902 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1903 | } |
| 1904 | break; |
| 1905 | default: |
| 1906 | UNREACHABLE(); |
| 1907 | break; |
| 1908 | } |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | |
| 1913 | void LCodeGen::DoSubI(LSubI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1914 | LOperand* left = instr->left(); |
| 1915 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1916 | ASSERT(left->Equals(instr->result())); |
| 1917 | |
| 1918 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1919 | __ sub(ToOperand(left), |
| 1920 | ToImmediate(right, instr->hydrogen()->representation())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1921 | } else { |
| 1922 | __ sub(ToRegister(left), ToOperand(right)); |
| 1923 | } |
| 1924 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1925 | DeoptimizeIf(overflow, instr->environment()); |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | void LCodeGen::DoConstantI(LConstantI* instr) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1931 | __ Set(ToRegister(instr->result()), Immediate(instr->value())); |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | void LCodeGen::DoConstantS(LConstantS* instr) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1936 | __ Set(ToRegister(instr->result()), Immediate(instr->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | |
| 1940 | void LCodeGen::DoConstantD(LConstantD* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1941 | double v = instr->value(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1942 | uint64_t int_val = BitCast<uint64_t, double>(v); |
| 1943 | int32_t lower = static_cast<int32_t>(int_val); |
| 1944 | int32_t upper = static_cast<int32_t>(int_val >> (kBitsPerInt)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1945 | ASSERT(instr->result()->IsDoubleRegister()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1946 | |
| 1947 | if (!CpuFeatures::IsSafeForSnapshot(SSE2)) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1948 | __ push(Immediate(upper)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1949 | __ push(Immediate(lower)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1950 | X87Register reg = ToX87Register(instr->result()); |
| 1951 | X87Mov(reg, Operand(esp, 0)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1952 | __ add(Operand(esp), Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1953 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1954 | CpuFeatureScope scope1(masm(), SSE2); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1955 | XMMRegister res = ToDoubleRegister(instr->result()); |
| 1956 | if (int_val == 0) { |
| 1957 | __ xorps(res, res); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1958 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1959 | Register temp = ToRegister(instr->temp()); |
| 1960 | if (CpuFeatures::IsSupported(SSE4_1)) { |
| 1961 | CpuFeatureScope scope2(masm(), SSE4_1); |
| 1962 | if (lower != 0) { |
| 1963 | __ Set(temp, Immediate(lower)); |
| 1964 | __ movd(res, Operand(temp)); |
| 1965 | __ Set(temp, Immediate(upper)); |
| 1966 | __ pinsrd(res, Operand(temp), 1); |
| 1967 | } else { |
| 1968 | __ xorps(res, res); |
| 1969 | __ Set(temp, Immediate(upper)); |
| 1970 | __ pinsrd(res, Operand(temp), 1); |
| 1971 | } |
| 1972 | } else { |
| 1973 | __ Set(temp, Immediate(upper)); |
| 1974 | __ movd(res, Operand(temp)); |
| 1975 | __ psllq(res, 32); |
| 1976 | if (lower != 0) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1977 | XMMRegister xmm_scratch = double_scratch0(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1978 | __ Set(temp, Immediate(lower)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1979 | __ movd(xmm_scratch, Operand(temp)); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1980 | __ orps(res, xmm_scratch); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1981 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1982 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1988 | void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1989 | __ lea(ToRegister(instr->result()), Operand::StaticVariable(instr->value())); |
| 1990 | } |
| 1991 | |
| 1992 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1993 | void LCodeGen::DoConstantT(LConstantT* instr) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1994 | Register reg = ToRegister(instr->result()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1995 | Handle<Object> handle = instr->value(isolate()); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1996 | AllowDeferredHandleDereference smi_check; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1997 | __ LoadObject(reg, handle); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2001 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 2002 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2003 | Register map = ToRegister(instr->value()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2004 | __ EnumLength(result, map); |
| 2005 | } |
| 2006 | |
| 2007 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2008 | void LCodeGen::DoElementsKind(LElementsKind* instr) { |
| 2009 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2010 | Register input = ToRegister(instr->value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2011 | |
| 2012 | // Load map into |result|. |
| 2013 | __ mov(result, FieldOperand(input, HeapObject::kMapOffset)); |
| 2014 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 2015 | // but the following masking takes care of that anyway. |
| 2016 | __ mov(result, FieldOperand(result, Map::kBitField2Offset)); |
| 2017 | // Retrieve elements_kind from bit field 2. |
| 2018 | __ and_(result, Map::kElementsKindMask); |
| 2019 | __ shr(result, Map::kElementsKindShift); |
| 2020 | } |
| 2021 | |
| 2022 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2023 | void LCodeGen::DoValueOf(LValueOf* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2024 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2025 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2026 | Register map = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2027 | ASSERT(input.is(result)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2028 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2029 | Label done; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2030 | |
| 2031 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2032 | // If the object is a smi return the object. |
| 2033 | __ JumpIfSmi(input, &done, Label::kNear); |
| 2034 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2035 | |
| 2036 | // If the object is not a value type, return the object. |
| 2037 | __ CmpObjectType(input, JS_VALUE_TYPE, map); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2038 | __ j(not_equal, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2039 | __ mov(result, FieldOperand(input, JSValue::kValueOffset)); |
| 2040 | |
| 2041 | __ bind(&done); |
| 2042 | } |
| 2043 | |
| 2044 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2045 | void LCodeGen::DoDateField(LDateField* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2046 | Register object = ToRegister(instr->date()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2047 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2048 | Register scratch = ToRegister(instr->temp()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2049 | Smi* index = instr->index(); |
| 2050 | Label runtime, done; |
| 2051 | ASSERT(object.is(result)); |
| 2052 | ASSERT(object.is(eax)); |
| 2053 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2054 | __ test(object, Immediate(kSmiTagMask)); |
| 2055 | DeoptimizeIf(zero, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2056 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2057 | DeoptimizeIf(not_equal, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2058 | |
| 2059 | if (index->value() == 0) { |
| 2060 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
| 2061 | } else { |
| 2062 | if (index->value() < JSDate::kFirstUncachedField) { |
| 2063 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 2064 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 2065 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 2066 | __ j(not_equal, &runtime, Label::kNear); |
| 2067 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 2068 | kPointerSize * index->value())); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2069 | __ jmp(&done, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2070 | } |
| 2071 | __ bind(&runtime); |
| 2072 | __ PrepareCallCFunction(2, scratch); |
| 2073 | __ mov(Operand(esp, 0), object); |
| 2074 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 2075 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 2076 | __ bind(&done); |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2081 | Operand LCodeGen::BuildSeqStringOperand(Register string, |
| 2082 | LOperand* index, |
| 2083 | String::Encoding encoding) { |
| 2084 | if (index->IsConstantOperand()) { |
| 2085 | int offset = ToRepresentation(LConstantOperand::cast(index), |
| 2086 | Representation::Integer32()); |
| 2087 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2088 | offset *= kUC16Size; |
| 2089 | } |
| 2090 | STATIC_ASSERT(kCharSize == 1); |
| 2091 | return FieldOperand(string, SeqString::kHeaderSize + offset); |
| 2092 | } |
| 2093 | return FieldOperand( |
| 2094 | string, ToRegister(index), |
| 2095 | encoding == String::ONE_BYTE_ENCODING ? times_1 : times_2, |
| 2096 | SeqString::kHeaderSize); |
| 2097 | } |
| 2098 | |
| 2099 | |
| 2100 | void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 2101 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 2102 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2103 | Register string = ToRegister(instr->string()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2104 | |
| 2105 | if (FLAG_debug_code) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2106 | __ push(string); |
| 2107 | __ mov(string, FieldOperand(string, HeapObject::kMapOffset)); |
| 2108 | __ movzx_b(string, FieldOperand(string, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2109 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2110 | __ and_(string, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2111 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 2112 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2113 | __ cmp(string, Immediate(encoding == String::ONE_BYTE_ENCODING |
| 2114 | ? one_byte_seq_type : two_byte_seq_type)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2115 | __ Check(equal, kUnexpectedStringType); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2116 | __ pop(string); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2119 | Operand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2120 | if (encoding == String::ONE_BYTE_ENCODING) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2121 | __ movzx_b(result, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2122 | } else { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2123 | __ movzx_w(result, operand); |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | |
| 2128 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 2129 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 2130 | Register string = ToRegister(instr->string()); |
| 2131 | |
| 2132 | if (FLAG_debug_code) { |
| 2133 | __ push(string); |
| 2134 | __ mov(string, FieldOperand(string, HeapObject::kMapOffset)); |
| 2135 | __ movzx_b(string, FieldOperand(string, Map::kInstanceTypeOffset)); |
| 2136 | |
| 2137 | __ and_(string, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
| 2138 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 2139 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 2140 | __ cmp(string, Immediate(encoding == String::ONE_BYTE_ENCODING |
| 2141 | ? one_byte_seq_type : two_byte_seq_type)); |
| 2142 | __ Check(equal, kUnexpectedStringType); |
| 2143 | __ pop(string); |
| 2144 | } |
| 2145 | |
| 2146 | Operand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 2147 | if (instr->value()->IsConstantOperand()) { |
| 2148 | int value = ToRepresentation(LConstantOperand::cast(instr->value()), |
| 2149 | Representation::Integer32()); |
| 2150 | ASSERT_LE(0, value); |
| 2151 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 2152 | ASSERT_LE(value, String::kMaxOneByteCharCode); |
| 2153 | __ mov_b(operand, static_cast<int8_t>(value)); |
| 2154 | } else { |
| 2155 | ASSERT_LE(value, String::kMaxUtf16CodeUnit); |
| 2156 | __ mov_w(operand, static_cast<int16_t>(value)); |
| 2157 | } |
| 2158 | } else { |
| 2159 | Register value = ToRegister(instr->value()); |
| 2160 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 2161 | __ mov_b(operand, value); |
| 2162 | } else { |
| 2163 | __ mov_w(operand, value); |
| 2164 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2165 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2169 | void LCodeGen::DoThrow(LThrow* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2170 | __ push(ToOperand(instr->value())); |
| 2171 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 2172 | CallRuntime(Runtime::kThrow, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2173 | |
| 2174 | if (FLAG_debug_code) { |
| 2175 | Comment("Unreachable code."); |
| 2176 | __ int3(); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | void LCodeGen::DoAddI(LAddI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2182 | LOperand* left = instr->left(); |
| 2183 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2184 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2185 | if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) { |
| 2186 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2187 | int32_t offset = ToRepresentation(LConstantOperand::cast(right), |
| 2188 | instr->hydrogen()->representation()); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2189 | __ lea(ToRegister(instr->result()), MemOperand(ToRegister(left), offset)); |
| 2190 | } else { |
| 2191 | Operand address(ToRegister(left), ToRegister(right), times_1, 0); |
| 2192 | __ lea(ToRegister(instr->result()), address); |
| 2193 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2194 | } else { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2195 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2196 | __ add(ToOperand(left), |
| 2197 | ToImmediate(right, instr->hydrogen()->representation())); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2198 | } else { |
| 2199 | __ add(ToRegister(left), ToOperand(right)); |
| 2200 | } |
| 2201 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 2202 | DeoptimizeIf(overflow, instr->environment()); |
| 2203 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2208 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2209 | CpuFeatureScope scope(masm(), SSE2); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2210 | LOperand* left = instr->left(); |
| 2211 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2212 | ASSERT(left->Equals(instr->result())); |
| 2213 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2214 | if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2215 | Label return_left; |
| 2216 | Condition condition = (operation == HMathMinMax::kMathMin) |
| 2217 | ? less_equal |
| 2218 | : greater_equal; |
| 2219 | if (right->IsConstantOperand()) { |
| 2220 | Operand left_op = ToOperand(left); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2221 | Immediate immediate = ToImmediate(LConstantOperand::cast(instr->right()), |
| 2222 | instr->hydrogen()->representation()); |
| 2223 | __ cmp(left_op, immediate); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2224 | __ j(condition, &return_left, Label::kNear); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2225 | __ mov(left_op, immediate); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2226 | } else { |
| 2227 | Register left_reg = ToRegister(left); |
| 2228 | Operand right_op = ToOperand(right); |
| 2229 | __ cmp(left_reg, right_op); |
| 2230 | __ j(condition, &return_left, Label::kNear); |
| 2231 | __ mov(left_reg, right_op); |
| 2232 | } |
| 2233 | __ bind(&return_left); |
| 2234 | } else { |
| 2235 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
| 2236 | Label check_nan_left, check_zero, return_left, return_right; |
| 2237 | Condition condition = (operation == HMathMinMax::kMathMin) ? below : above; |
| 2238 | XMMRegister left_reg = ToDoubleRegister(left); |
| 2239 | XMMRegister right_reg = ToDoubleRegister(right); |
| 2240 | __ ucomisd(left_reg, right_reg); |
| 2241 | __ j(parity_even, &check_nan_left, Label::kNear); // At least one NaN. |
| 2242 | __ j(equal, &check_zero, Label::kNear); // left == right. |
| 2243 | __ j(condition, &return_left, Label::kNear); |
| 2244 | __ jmp(&return_right, Label::kNear); |
| 2245 | |
| 2246 | __ bind(&check_zero); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2247 | XMMRegister xmm_scratch = double_scratch0(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2248 | __ xorps(xmm_scratch, xmm_scratch); |
| 2249 | __ ucomisd(left_reg, xmm_scratch); |
| 2250 | __ j(not_equal, &return_left, Label::kNear); // left == right != 0. |
| 2251 | // At this point, both left and right are either 0 or -0. |
| 2252 | if (operation == HMathMinMax::kMathMin) { |
| 2253 | __ orpd(left_reg, right_reg); |
| 2254 | } else { |
| 2255 | // Since we operate on +0 and/or -0, addsd and andsd have the same effect. |
| 2256 | __ addsd(left_reg, right_reg); |
| 2257 | } |
| 2258 | __ jmp(&return_left, Label::kNear); |
| 2259 | |
| 2260 | __ bind(&check_nan_left); |
| 2261 | __ ucomisd(left_reg, left_reg); // NaN check. |
| 2262 | __ j(parity_even, &return_left, Label::kNear); // left == NaN. |
| 2263 | __ bind(&return_right); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 2264 | __ movaps(left_reg, right_reg); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2265 | |
| 2266 | __ bind(&return_left); |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2271 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2272 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 2273 | CpuFeatureScope scope(masm(), SSE2); |
| 2274 | XMMRegister left = ToDoubleRegister(instr->left()); |
| 2275 | XMMRegister right = ToDoubleRegister(instr->right()); |
| 2276 | XMMRegister result = ToDoubleRegister(instr->result()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2277 | switch (instr->op()) { |
| 2278 | case Token::ADD: |
| 2279 | __ addsd(left, right); |
| 2280 | break; |
| 2281 | case Token::SUB: |
| 2282 | __ subsd(left, right); |
| 2283 | break; |
| 2284 | case Token::MUL: |
| 2285 | __ mulsd(left, right); |
| 2286 | break; |
| 2287 | case Token::DIV: |
| 2288 | __ divsd(left, right); |
| 2289 | // Don't delete this mov. It may improve performance on some CPUs, |
| 2290 | // when there is a mulsd depending on the result |
| 2291 | __ movaps(left, left); |
| 2292 | break; |
| 2293 | case Token::MOD: { |
| 2294 | // Pass two doubles as arguments on the stack. |
| 2295 | __ PrepareCallCFunction(4, eax); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2296 | __ movsd(Operand(esp, 0 * kDoubleSize), left); |
| 2297 | __ movsd(Operand(esp, 1 * kDoubleSize), right); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2298 | __ CallCFunction( |
| 2299 | ExternalReference::double_fp_operation(Token::MOD, isolate()), |
| 2300 | 4); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2301 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2302 | // Return value is in st(0) on ia32. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2303 | // Store it into the result register. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2304 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
| 2305 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2306 | __ movsd(result, Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2307 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 2308 | break; |
| 2309 | } |
| 2310 | default: |
| 2311 | UNREACHABLE(); |
| 2312 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2313 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2314 | } else { |
| 2315 | X87Register left = ToX87Register(instr->left()); |
| 2316 | X87Register right = ToX87Register(instr->right()); |
| 2317 | X87Register result = ToX87Register(instr->result()); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2318 | if (instr->op() != Token::MOD) { |
| 2319 | X87PrepareBinaryOp(left, right, result); |
| 2320 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2321 | switch (instr->op()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2322 | case Token::ADD: |
| 2323 | __ fadd_i(1); |
| 2324 | break; |
| 2325 | case Token::SUB: |
| 2326 | __ fsub_i(1); |
| 2327 | break; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2328 | case Token::MUL: |
| 2329 | __ fmul_i(1); |
| 2330 | break; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2331 | case Token::DIV: |
| 2332 | __ fdiv_i(1); |
| 2333 | break; |
| 2334 | case Token::MOD: { |
| 2335 | // Pass two doubles as arguments on the stack. |
| 2336 | __ PrepareCallCFunction(4, eax); |
| 2337 | X87Mov(Operand(esp, 1 * kDoubleSize), right); |
| 2338 | X87Mov(Operand(esp, 0), left); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 2339 | X87Free(right); |
| 2340 | ASSERT(left.is(result)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2341 | X87PrepareToWrite(result); |
| 2342 | __ CallCFunction( |
| 2343 | ExternalReference::double_fp_operation(Token::MOD, isolate()), |
| 2344 | 4); |
| 2345 | |
| 2346 | // Return value is in st(0) on ia32. |
| 2347 | X87CommitWrite(result); |
| 2348 | break; |
| 2349 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2350 | default: |
| 2351 | UNREACHABLE(); |
| 2352 | break; |
| 2353 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | |
| 2358 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2359 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 2360 | ASSERT(ToRegister(instr->left()).is(edx)); |
| 2361 | ASSERT(ToRegister(instr->right()).is(eax)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2362 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2363 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2364 | BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2365 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2366 | __ nop(); // Signals no inlined code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2370 | template<class InstrType> |
| 2371 | void LCodeGen::EmitBranch(InstrType instr, Condition cc) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2372 | int left_block = instr->TrueDestination(chunk_); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2373 | int right_block = instr->FalseDestination(chunk_); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2374 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2375 | int next_block = GetNextEmittedBlock(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2376 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2377 | if (right_block == left_block || cc == no_condition) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2378 | EmitGoto(left_block); |
| 2379 | } else if (left_block == next_block) { |
| 2380 | __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 2381 | } else if (right_block == next_block) { |
| 2382 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2383 | } else { |
| 2384 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2385 | __ jmp(chunk_->GetAssemblyLabel(right_block)); |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2390 | template<class InstrType> |
| 2391 | void LCodeGen::EmitFalseBranch(InstrType instr, Condition cc) { |
| 2392 | int false_block = instr->FalseDestination(chunk_); |
| 2393 | if (cc == no_condition) { |
| 2394 | __ jmp(chunk_->GetAssemblyLabel(false_block)); |
| 2395 | } else { |
| 2396 | __ j(cc, chunk_->GetAssemblyLabel(false_block)); |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2401 | void LCodeGen::DoBranch(LBranch* instr) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2402 | Representation r = instr->hydrogen()->value()->representation(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2403 | if (r.IsSmiOrInteger32()) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2404 | Register reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2405 | __ test(reg, Operand(reg)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2406 | EmitBranch(instr, not_zero); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2407 | } else if (r.IsDouble()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2408 | ASSERT(!info()->IsStub()); |
| 2409 | CpuFeatureScope scope(masm(), SSE2); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2410 | XMMRegister reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2411 | XMMRegister xmm_scratch = double_scratch0(); |
| 2412 | __ xorps(xmm_scratch, xmm_scratch); |
| 2413 | __ ucomisd(reg, xmm_scratch); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2414 | EmitBranch(instr, not_equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2415 | } else { |
| 2416 | ASSERT(r.IsTagged()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2417 | Register reg = ToRegister(instr->value()); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2418 | HType type = instr->hydrogen()->value()->type(); |
| 2419 | if (type.IsBoolean()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2420 | ASSERT(!info()->IsStub()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2421 | __ cmp(reg, factory()->true_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2422 | EmitBranch(instr, equal); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2423 | } else if (type.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2424 | ASSERT(!info()->IsStub()); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2425 | __ test(reg, Operand(reg)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2426 | EmitBranch(instr, not_equal); |
| 2427 | } else if (type.IsJSArray()) { |
| 2428 | ASSERT(!info()->IsStub()); |
| 2429 | EmitBranch(instr, no_condition); |
| 2430 | } else if (type.IsHeapNumber()) { |
| 2431 | ASSERT(!info()->IsStub()); |
| 2432 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2433 | XMMRegister xmm_scratch = double_scratch0(); |
| 2434 | __ xorps(xmm_scratch, xmm_scratch); |
| 2435 | __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2436 | EmitBranch(instr, not_equal); |
| 2437 | } else if (type.IsString()) { |
| 2438 | ASSERT(!info()->IsStub()); |
| 2439 | __ cmp(FieldOperand(reg, String::kLengthOffset), Immediate(0)); |
| 2440 | EmitBranch(instr, not_equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2441 | } else { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2442 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2443 | if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2444 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2445 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2446 | // undefined -> false. |
| 2447 | __ cmp(reg, factory()->undefined_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2448 | __ j(equal, instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2449 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2450 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2451 | // true -> true. |
| 2452 | __ cmp(reg, factory()->true_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2453 | __ j(equal, instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2454 | // false -> false. |
| 2455 | __ cmp(reg, factory()->false_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2456 | __ j(equal, instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2457 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2458 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2459 | // 'null' -> false. |
| 2460 | __ cmp(reg, factory()->null_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2461 | __ j(equal, instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 2465 | // Smis: 0 -> false, all other -> true. |
| 2466 | __ test(reg, Operand(reg)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2467 | __ j(equal, instr->FalseLabel(chunk_)); |
| 2468 | __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2469 | } else if (expected.NeedsMap()) { |
| 2470 | // If we need a map later and have a Smi -> deopt. |
| 2471 | __ test(reg, Immediate(kSmiTagMask)); |
| 2472 | DeoptimizeIf(zero, instr->environment()); |
| 2473 | } |
| 2474 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2475 | Register map = no_reg; // Keep the compiler happy. |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2476 | if (expected.NeedsMap()) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2477 | map = ToRegister(instr->temp()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2478 | ASSERT(!map.is(reg)); |
| 2479 | __ mov(map, FieldOperand(reg, HeapObject::kMapOffset)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2480 | |
| 2481 | if (expected.CanBeUndetectable()) { |
| 2482 | // Undetectable -> false. |
| 2483 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 2484 | 1 << Map::kIsUndetectable); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2485 | __ j(not_zero, instr->FalseLabel(chunk_)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2486 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2490 | // spec object -> true. |
| 2491 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2492 | __ j(above_equal, instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 2496 | // String value -> false iff empty. |
| 2497 | Label not_string; |
| 2498 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 2499 | __ j(above_equal, ¬_string, Label::kNear); |
| 2500 | __ cmp(FieldOperand(reg, String::kLengthOffset), Immediate(0)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2501 | __ j(not_zero, instr->TrueLabel(chunk_)); |
| 2502 | __ jmp(instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2503 | __ bind(¬_string); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2506 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2507 | // Symbol value -> true. |
| 2508 | __ CmpInstanceType(map, SYMBOL_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2509 | __ j(equal, instr->TrueLabel(chunk_)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2512 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2513 | // heap number -> false iff +0, -0, or NaN. |
| 2514 | Label not_heap_number; |
| 2515 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 2516 | factory()->heap_number_map()); |
| 2517 | __ j(not_equal, ¬_heap_number, Label::kNear); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2518 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 2519 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2520 | XMMRegister xmm_scratch = double_scratch0(); |
| 2521 | __ xorps(xmm_scratch, xmm_scratch); |
| 2522 | __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset)); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2523 | } else { |
| 2524 | __ fldz(); |
| 2525 | __ fld_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
| 2526 | __ FCmp(); |
| 2527 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2528 | __ j(zero, instr->FalseLabel(chunk_)); |
| 2529 | __ jmp(instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2530 | __ bind(¬_heap_number); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2533 | if (!expected.IsGeneric()) { |
| 2534 | // We've seen something for the first time -> deopt. |
| 2535 | // This can only happen if we are not generic already. |
| 2536 | DeoptimizeIf(no_condition, instr->environment()); |
| 2537 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2543 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2544 | if (!IsNextEmittedBlock(block)) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2545 | __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 2550 | void LCodeGen::DoClobberDoubles(LClobberDoubles* instr) { |
| 2551 | } |
| 2552 | |
| 2553 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2554 | void LCodeGen::DoGoto(LGoto* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2555 | EmitGoto(instr->block_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | |
| 2559 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
| 2560 | Condition cond = no_condition; |
| 2561 | switch (op) { |
| 2562 | case Token::EQ: |
| 2563 | case Token::EQ_STRICT: |
| 2564 | cond = equal; |
| 2565 | break; |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2566 | case Token::NE: |
| 2567 | case Token::NE_STRICT: |
| 2568 | cond = not_equal; |
| 2569 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2570 | case Token::LT: |
| 2571 | cond = is_unsigned ? below : less; |
| 2572 | break; |
| 2573 | case Token::GT: |
| 2574 | cond = is_unsigned ? above : greater; |
| 2575 | break; |
| 2576 | case Token::LTE: |
| 2577 | cond = is_unsigned ? below_equal : less_equal; |
| 2578 | break; |
| 2579 | case Token::GTE: |
| 2580 | cond = is_unsigned ? above_equal : greater_equal; |
| 2581 | break; |
| 2582 | case Token::IN: |
| 2583 | case Token::INSTANCEOF: |
| 2584 | default: |
| 2585 | UNREACHABLE(); |
| 2586 | } |
| 2587 | return cond; |
| 2588 | } |
| 2589 | |
| 2590 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2591 | void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2592 | LOperand* left = instr->left(); |
| 2593 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2594 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2595 | |
| 2596 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2597 | // We can statically evaluate the comparison. |
| 2598 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2599 | double right_val = ToDouble(LConstantOperand::cast(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2600 | int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
| 2601 | instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2602 | EmitGoto(next_block); |
| 2603 | } else { |
| 2604 | if (instr->is_double()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2605 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 2606 | CpuFeatureScope scope(masm(), SSE2); |
| 2607 | __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 2608 | } else { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2609 | X87LoadForUsage(ToX87Register(right), ToX87Register(left)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2610 | __ FCmp(); |
| 2611 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2612 | // Don't base result on EFLAGS when a NaN is involved. Instead |
| 2613 | // jump to the false block. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2614 | __ j(parity_even, instr->FalseLabel(chunk_)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2615 | } else { |
| 2616 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2617 | __ cmp(ToOperand(left), |
| 2618 | ToImmediate(right, instr->hydrogen()->representation())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2619 | } else if (left->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2620 | __ cmp(ToOperand(right), |
| 2621 | ToImmediate(left, instr->hydrogen()->representation())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2622 | // We transposed the operands. Reverse the condition. |
| 2623 | cc = ReverseCondition(cc); |
| 2624 | } else { |
| 2625 | __ cmp(ToRegister(left), ToOperand(right)); |
| 2626 | } |
| 2627 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2628 | EmitBranch(instr, cc); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2629 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 2633 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2634 | Register left = ToRegister(instr->left()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2635 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2636 | if (instr->right()->IsConstantOperand()) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2637 | Handle<Object> right = ToHandle(LConstantOperand::cast(instr->right())); |
| 2638 | __ CmpObject(left, right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2639 | } else { |
| 2640 | Operand right = ToOperand(instr->right()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2641 | __ cmp(left, right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2642 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2643 | EmitBranch(instr, equal); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2647 | void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2648 | if (instr->hydrogen()->representation().IsTagged()) { |
| 2649 | Register input_reg = ToRegister(instr->object()); |
| 2650 | __ cmp(input_reg, factory()->the_hole_value()); |
| 2651 | EmitBranch(instr, equal); |
| 2652 | return; |
| 2653 | } |
| 2654 | |
| 2655 | bool use_sse2 = CpuFeatures::IsSupported(SSE2); |
| 2656 | if (use_sse2) { |
| 2657 | CpuFeatureScope scope(masm(), SSE2); |
| 2658 | XMMRegister input_reg = ToDoubleRegister(instr->object()); |
| 2659 | __ ucomisd(input_reg, input_reg); |
| 2660 | EmitFalseBranch(instr, parity_odd); |
| 2661 | } else { |
| 2662 | // Put the value to the top of stack |
| 2663 | X87Register src = ToX87Register(instr->object()); |
| 2664 | X87LoadForUsage(src); |
| 2665 | __ fld(0); |
| 2666 | __ fld(0); |
| 2667 | __ FCmp(); |
| 2668 | Label ok; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2669 | __ j(parity_even, &ok, Label::kNear); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2670 | __ fstp(0); |
| 2671 | EmitFalseBranch(instr, no_condition); |
| 2672 | __ bind(&ok); |
| 2673 | } |
| 2674 | |
| 2675 | |
| 2676 | __ sub(esp, Immediate(kDoubleSize)); |
| 2677 | if (use_sse2) { |
| 2678 | CpuFeatureScope scope(masm(), SSE2); |
| 2679 | XMMRegister input_reg = ToDoubleRegister(instr->object()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2680 | __ movsd(MemOperand(esp, 0), input_reg); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2681 | } else { |
| 2682 | __ fstp_d(MemOperand(esp, 0)); |
| 2683 | } |
| 2684 | |
| 2685 | __ add(esp, Immediate(kDoubleSize)); |
| 2686 | int offset = sizeof(kHoleNanUpper32); |
| 2687 | __ cmp(MemOperand(esp, -offset), Immediate(kHoleNanUpper32)); |
| 2688 | EmitBranch(instr, equal); |
| 2689 | } |
| 2690 | |
| 2691 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2692 | void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
| 2693 | Representation rep = instr->hydrogen()->value()->representation(); |
| 2694 | ASSERT(!rep.IsInteger32()); |
| 2695 | Register scratch = ToRegister(instr->temp()); |
| 2696 | |
| 2697 | if (rep.IsDouble()) { |
| 2698 | CpuFeatureScope use_sse2(masm(), SSE2); |
| 2699 | XMMRegister value = ToDoubleRegister(instr->value()); |
| 2700 | XMMRegister xmm_scratch = double_scratch0(); |
| 2701 | __ xorps(xmm_scratch, xmm_scratch); |
| 2702 | __ ucomisd(xmm_scratch, value); |
| 2703 | EmitFalseBranch(instr, not_equal); |
| 2704 | __ movmskpd(scratch, value); |
| 2705 | __ test(scratch, Immediate(1)); |
| 2706 | EmitBranch(instr, not_zero); |
| 2707 | } else { |
| 2708 | Register value = ToRegister(instr->value()); |
| 2709 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 2710 | __ CheckMap(value, map, instr->FalseLabel(chunk()), DO_SMI_CHECK); |
| 2711 | __ cmp(FieldOperand(value, HeapNumber::kExponentOffset), |
| 2712 | Immediate(0x80000000)); |
| 2713 | EmitFalseBranch(instr, not_equal); |
| 2714 | __ cmp(FieldOperand(value, HeapNumber::kMantissaOffset), |
| 2715 | Immediate(0x00000000)); |
| 2716 | EmitBranch(instr, equal); |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2721 | Condition LCodeGen::EmitIsObject(Register input, |
| 2722 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2723 | Label* is_not_object, |
| 2724 | Label* is_object) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2725 | __ JumpIfSmi(input, is_not_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2726 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2727 | __ cmp(input, isolate()->factory()->null_value()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2728 | __ j(equal, is_object); |
| 2729 | |
| 2730 | __ mov(temp1, FieldOperand(input, HeapObject::kMapOffset)); |
| 2731 | // Undetectable objects behave like undefined. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2732 | __ test_b(FieldOperand(temp1, Map::kBitFieldOffset), |
| 2733 | 1 << Map::kIsUndetectable); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2734 | __ j(not_zero, is_not_object); |
| 2735 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2736 | __ movzx_b(temp1, FieldOperand(temp1, Map::kInstanceTypeOffset)); |
| 2737 | __ cmp(temp1, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2738 | __ j(below, is_not_object); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2739 | __ cmp(temp1, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2740 | return below_equal; |
| 2741 | } |
| 2742 | |
| 2743 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2744 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2745 | Register reg = ToRegister(instr->value()); |
| 2746 | Register temp = ToRegister(instr->temp()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2747 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2748 | Condition true_cond = EmitIsObject( |
| 2749 | reg, temp, instr->FalseLabel(chunk_), instr->TrueLabel(chunk_)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2750 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2751 | EmitBranch(instr, true_cond); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2755 | Condition LCodeGen::EmitIsString(Register input, |
| 2756 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2757 | Label* is_not_string, |
| 2758 | SmiCheck check_needed = INLINE_SMI_CHECK) { |
| 2759 | if (check_needed == INLINE_SMI_CHECK) { |
| 2760 | __ JumpIfSmi(input, is_not_string); |
| 2761 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2762 | |
| 2763 | Condition cond = masm_->IsObjectStringType(input, temp1, temp1); |
| 2764 | |
| 2765 | return cond; |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2770 | Register reg = ToRegister(instr->value()); |
| 2771 | Register temp = ToRegister(instr->temp()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2772 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2773 | SmiCheck check_needed = |
| 2774 | instr->hydrogen()->value()->IsHeapObject() |
| 2775 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2776 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2777 | Condition true_cond = EmitIsString( |
| 2778 | reg, temp, instr->FalseLabel(chunk_), check_needed); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2779 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2780 | EmitBranch(instr, true_cond); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2784 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2785 | Operand input = ToOperand(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2786 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2787 | __ test(input, Immediate(kSmiTagMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2788 | EmitBranch(instr, zero); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2792 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2793 | Register input = ToRegister(instr->value()); |
| 2794 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2795 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2796 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2797 | STATIC_ASSERT(kSmiTag == 0); |
| 2798 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2799 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2800 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
| 2801 | __ test_b(FieldOperand(temp, Map::kBitFieldOffset), |
| 2802 | 1 << Map::kIsUndetectable); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2803 | EmitBranch(instr, not_zero); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2807 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2808 | switch (op) { |
| 2809 | case Token::EQ_STRICT: |
| 2810 | case Token::EQ: |
| 2811 | return equal; |
| 2812 | case Token::LT: |
| 2813 | return less; |
| 2814 | case Token::GT: |
| 2815 | return greater; |
| 2816 | case Token::LTE: |
| 2817 | return less_equal; |
| 2818 | case Token::GTE: |
| 2819 | return greater_equal; |
| 2820 | default: |
| 2821 | UNREACHABLE(); |
| 2822 | return no_condition; |
| 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | |
| 2827 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 2828 | Token::Value op = instr->op(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2829 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2830 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2831 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2832 | |
| 2833 | Condition condition = ComputeCompareCondition(op); |
| 2834 | __ test(eax, Operand(eax)); |
| 2835 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2836 | EmitBranch(instr, condition); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2840 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2841 | InstanceType from = instr->from(); |
| 2842 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2843 | if (from == FIRST_TYPE) return to; |
| 2844 | ASSERT(from == to || to == LAST_TYPE); |
| 2845 | return from; |
| 2846 | } |
| 2847 | |
| 2848 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2849 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2850 | InstanceType from = instr->from(); |
| 2851 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2852 | if (from == to) return equal; |
| 2853 | if (to == LAST_TYPE) return above_equal; |
| 2854 | if (from == FIRST_TYPE) return below_equal; |
| 2855 | UNREACHABLE(); |
| 2856 | return equal; |
| 2857 | } |
| 2858 | |
| 2859 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2860 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2861 | Register input = ToRegister(instr->value()); |
| 2862 | Register temp = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2863 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2864 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2865 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2866 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2867 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2868 | __ CmpObjectType(input, TestType(instr->hydrogen()), temp); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2869 | EmitBranch(instr, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2873 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2874 | Register input = ToRegister(instr->value()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2875 | Register result = ToRegister(instr->result()); |
| 2876 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2877 | __ AssertString(input); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2878 | |
| 2879 | __ mov(result, FieldOperand(input, String::kHashFieldOffset)); |
| 2880 | __ IndexFromHash(result, result); |
| 2881 | } |
| 2882 | |
| 2883 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2884 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2885 | LHasCachedArrayIndexAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2886 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2887 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2888 | __ test(FieldOperand(input, String::kHashFieldOffset), |
| 2889 | Immediate(String::kContainsCachedArrayIndexMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2890 | EmitBranch(instr, equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | |
| 2894 | // Branches to a label or falls through with the answer in the z flag. Trashes |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2895 | // the temp registers, but not the input. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2896 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2897 | Label* is_false, |
| 2898 | Handle<String>class_name, |
| 2899 | Register input, |
| 2900 | Register temp, |
| 2901 | Register temp2) { |
| 2902 | ASSERT(!input.is(temp)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2903 | ASSERT(!input.is(temp2)); |
| 2904 | ASSERT(!temp.is(temp2)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2905 | __ JumpIfSmi(input, is_false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2906 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2907 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2908 | // Assuming the following assertions, we can use the same compares to test |
| 2909 | // for both being a function type and being in the object type range. |
| 2910 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2911 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2912 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2913 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2914 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2915 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2916 | __ CmpObjectType(input, FIRST_SPEC_OBJECT_TYPE, temp); |
| 2917 | __ j(below, is_false); |
| 2918 | __ j(equal, is_true); |
| 2919 | __ CmpInstanceType(temp, LAST_SPEC_OBJECT_TYPE); |
| 2920 | __ j(equal, is_true); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2921 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2922 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2923 | // actual type and do a signed compare with the width of the type range. |
| 2924 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2925 | __ movzx_b(temp2, FieldOperand(temp, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2926 | __ sub(Operand(temp2), Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2927 | __ cmp(Operand(temp2), Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2928 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2929 | __ j(above, is_false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2932 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2933 | // Check if the constructor in the map is a function. |
| 2934 | __ mov(temp, FieldOperand(temp, Map::kConstructorOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2935 | // Objects with a non-function constructor have class 'Object'. |
| 2936 | __ CmpObjectType(temp, JS_FUNCTION_TYPE, temp2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2937 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2938 | __ j(not_equal, is_true); |
| 2939 | } else { |
| 2940 | __ j(not_equal, is_false); |
| 2941 | } |
| 2942 | |
| 2943 | // temp now contains the constructor function. Grab the |
| 2944 | // instance class name from there. |
| 2945 | __ mov(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2946 | __ mov(temp, FieldOperand(temp, |
| 2947 | SharedFunctionInfo::kInstanceClassNameOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2948 | // The class name we are testing against is internalized since it's a literal. |
| 2949 | // The name in the constructor is internalized because of the way the context |
| 2950 | // is booted. This routine isn't expected to work for random API-created |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2951 | // classes and it doesn't have to because you can't access it with natives |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2952 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2953 | // identity comparison. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2954 | __ cmp(temp, class_name); |
| 2955 | // End with the answer in the z flag. |
| 2956 | } |
| 2957 | |
| 2958 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2959 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2960 | Register input = ToRegister(instr->value()); |
| 2961 | Register temp = ToRegister(instr->temp()); |
| 2962 | Register temp2 = ToRegister(instr->temp2()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2963 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2964 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2965 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2966 | EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2967 | class_name, input, temp, temp2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2968 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2969 | EmitBranch(instr, equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | |
| 2973 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2974 | Register reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2975 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2976 | EmitBranch(instr, equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | |
| 2980 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2981 | // Object and function are in fixed registers defined by the stub. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2982 | ASSERT(ToRegister(instr->context()).is(esi)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2983 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2984 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2985 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2986 | Label true_value, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2987 | __ test(eax, Operand(eax)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2988 | __ j(zero, &true_value, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2989 | __ mov(ToRegister(instr->result()), factory()->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2990 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2991 | __ bind(&true_value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2992 | __ mov(ToRegister(instr->result()), factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2993 | __ bind(&done); |
| 2994 | } |
| 2995 | |
| 2996 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2997 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2998 | class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2999 | public: |
| 3000 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3001 | LInstanceOfKnownGlobal* instr, |
| 3002 | const X87Stack& x87_stack) |
| 3003 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3004 | virtual void Generate() V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3005 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3006 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3007 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3008 | Label* map_check() { return &map_check_; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3009 | private: |
| 3010 | LInstanceOfKnownGlobal* instr_; |
| 3011 | Label map_check_; |
| 3012 | }; |
| 3013 | |
| 3014 | DeferredInstanceOfKnownGlobal* deferred; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3015 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr, x87_stack_); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3016 | |
| 3017 | Label done, false_result; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3018 | Register object = ToRegister(instr->value()); |
| 3019 | Register temp = ToRegister(instr->temp()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3020 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3021 | // A Smi is not an instance of anything. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3022 | __ JumpIfSmi(object, &false_result, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3023 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3024 | // This is the inlined call site instanceof cache. The two occurences of the |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3025 | // hole value will be patched to the last map/result pair generated by the |
| 3026 | // instanceof stub. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3027 | Label cache_miss; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3028 | Register map = ToRegister(instr->temp()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3029 | __ mov(map, FieldOperand(object, HeapObject::kMapOffset)); |
| 3030 | __ bind(deferred->map_check()); // Label for calculating code patching. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3031 | Handle<Cell> cache_cell = factory()->NewCell(factory()->the_hole_value()); |
| 3032 | __ cmp(map, Operand::ForCell(cache_cell)); // Patched to cached map. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3033 | __ j(not_equal, &cache_miss, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3034 | __ mov(eax, factory()->the_hole_value()); // Patched to either true or false. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3035 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3036 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3037 | // The inlined call site cache did not match. Check for null and string |
| 3038 | // before calling the deferred code. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3039 | __ bind(&cache_miss); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3040 | // Null is not an instance of anything. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3041 | __ cmp(object, factory()->null_value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3042 | __ j(equal, &false_result, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3043 | |
| 3044 | // String values are not instances of anything. |
| 3045 | Condition is_string = masm_->IsObjectStringType(object, temp, temp); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3046 | __ j(is_string, &false_result, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3047 | |
| 3048 | // Go to the deferred code. |
| 3049 | __ jmp(deferred->entry()); |
| 3050 | |
| 3051 | __ bind(&false_result); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3052 | __ mov(ToRegister(instr->result()), factory()->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3053 | |
| 3054 | // Here result has either true or false. Deferred code also produces true or |
| 3055 | // false object. |
| 3056 | __ bind(deferred->exit()); |
| 3057 | __ bind(&done); |
| 3058 | } |
| 3059 | |
| 3060 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3061 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 3062 | Label* map_check) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3063 | PushSafepointRegistersScope scope(this); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3064 | |
| 3065 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 3066 | flags = static_cast<InstanceofStub::Flags>( |
| 3067 | flags | InstanceofStub::kArgsInRegisters); |
| 3068 | flags = static_cast<InstanceofStub::Flags>( |
| 3069 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 3070 | flags = static_cast<InstanceofStub::Flags>( |
| 3071 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 3072 | InstanceofStub stub(flags); |
| 3073 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3074 | // Get the temp register reserved by the instruction. This needs to be a |
| 3075 | // register which is pushed last by PushSafepointRegisters as top of the |
| 3076 | // stack is used to pass the offset to the location of the map check to |
| 3077 | // the stub. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3078 | Register temp = ToRegister(instr->temp()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3079 | ASSERT(MacroAssembler::SafepointRegisterStackIndex(temp) == 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3080 | __ LoadHeapObject(InstanceofStub::right(), instr->function()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3081 | static const int kAdditionalDelta = 13; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3082 | int delta = masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3083 | __ mov(temp, Immediate(delta)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3084 | __ StoreToSafepointRegisterSlot(temp, temp); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3085 | CallCodeGeneric(stub.GetCode(isolate()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3086 | RelocInfo::CODE_TARGET, |
| 3087 | instr, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3088 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3089 | // Get the deoptimization index of the LLazyBailout-environment that |
| 3090 | // corresponds to this instruction. |
| 3091 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3092 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
| 3093 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3094 | // Put the result value into the eax slot and restore all registers. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3095 | __ StoreToSafepointRegisterSlot(eax, eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3099 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 3100 | Token::Value op = instr->op(); |
| 3101 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3102 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3103 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3104 | |
| 3105 | Condition condition = ComputeCompareCondition(op); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3106 | Label true_value, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3107 | __ test(eax, Operand(eax)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3108 | __ j(condition, &true_value, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3109 | __ mov(ToRegister(instr->result()), factory()->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3110 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3111 | __ bind(&true_value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3112 | __ mov(ToRegister(instr->result()), factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3113 | __ bind(&done); |
| 3114 | } |
| 3115 | |
| 3116 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3117 | void LCodeGen::EmitReturn(LReturn* instr, bool dynamic_frame_alignment) { |
| 3118 | int extra_value_count = dynamic_frame_alignment ? 2 : 1; |
| 3119 | |
| 3120 | if (instr->has_constant_parameter_count()) { |
| 3121 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 3122 | if (dynamic_frame_alignment && FLAG_debug_code) { |
| 3123 | __ cmp(Operand(esp, |
| 3124 | (parameter_count + extra_value_count) * kPointerSize), |
| 3125 | Immediate(kAlignmentZapValue)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3126 | __ Assert(equal, kExpectedAlignmentMarker); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3127 | } |
| 3128 | __ Ret((parameter_count + extra_value_count) * kPointerSize, ecx); |
| 3129 | } else { |
| 3130 | Register reg = ToRegister(instr->parameter_count()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3131 | // The argument count parameter is a smi |
| 3132 | __ SmiUntag(reg); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3133 | Register return_addr_reg = reg.is(ecx) ? ebx : ecx; |
| 3134 | if (dynamic_frame_alignment && FLAG_debug_code) { |
| 3135 | ASSERT(extra_value_count == 2); |
| 3136 | __ cmp(Operand(esp, reg, times_pointer_size, |
| 3137 | extra_value_count * kPointerSize), |
| 3138 | Immediate(kAlignmentZapValue)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3139 | __ Assert(equal, kExpectedAlignmentMarker); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | // emit code to restore stack based on instr->parameter_count() |
| 3143 | __ pop(return_addr_reg); // save return address |
| 3144 | if (dynamic_frame_alignment) { |
| 3145 | __ inc(reg); // 1 more for alignment |
| 3146 | } |
| 3147 | __ shl(reg, kPointerSizeLog2); |
| 3148 | __ add(esp, reg); |
| 3149 | __ jmp(return_addr_reg); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3154 | void LCodeGen::DoReturn(LReturn* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3155 | if (FLAG_trace && info()->IsOptimizing()) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3156 | // Preserve the return value on the stack and rely on the runtime call |
| 3157 | // to return the value in the same register. We're leaving the code |
| 3158 | // managed by the register allocator and tearing down the frame, it's |
| 3159 | // safe to write to the context register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3160 | __ push(eax); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3161 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3162 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 3163 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3164 | if (info()->saves_caller_doubles() && CpuFeatures::IsSupported(SSE2)) { |
| 3165 | ASSERT(NeedsEagerFrame()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3166 | CpuFeatureScope scope(masm(), SSE2); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3167 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 3168 | BitVector::Iterator save_iterator(doubles); |
| 3169 | int count = 0; |
| 3170 | while (!save_iterator.Done()) { |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3171 | __ movsd(XMMRegister::FromAllocationIndex(save_iterator.Current()), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3172 | MemOperand(esp, count * kDoubleSize)); |
| 3173 | save_iterator.Advance(); |
| 3174 | count++; |
| 3175 | } |
| 3176 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3177 | if (dynamic_frame_alignment_) { |
| 3178 | // Fetch the state of the dynamic frame alignment. |
| 3179 | __ mov(edx, Operand(ebp, |
| 3180 | JavaScriptFrameConstants::kDynamicAlignmentStateOffset)); |
| 3181 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3182 | int no_frame_start = -1; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3183 | if (NeedsEagerFrame()) { |
| 3184 | __ mov(esp, ebp); |
| 3185 | __ pop(ebp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3186 | no_frame_start = masm_->pc_offset(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3187 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3188 | if (dynamic_frame_alignment_) { |
| 3189 | Label no_padding; |
| 3190 | __ cmp(edx, Immediate(kNoAlignmentPadding)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3191 | __ j(equal, &no_padding, Label::kNear); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3192 | |
| 3193 | EmitReturn(instr, true); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3194 | __ bind(&no_padding); |
| 3195 | } |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3196 | |
| 3197 | EmitReturn(instr, false); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3198 | if (no_frame_start != -1) { |
| 3199 | info()->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 3200 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3204 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3205 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3206 | __ mov(result, Operand::ForCell(instr->hydrogen()->cell().handle())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3207 | if (instr->hydrogen()->RequiresHoleCheck()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3208 | __ cmp(result, factory()->the_hole_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3209 | DeoptimizeIf(equal, instr->environment()); |
| 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3214 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 3215 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3216 | ASSERT(ToRegister(instr->global_object()).is(edx)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3217 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 3218 | |
| 3219 | __ mov(ecx, instr->name()); |
| 3220 | RelocInfo::Mode mode = instr->for_typeof() ? RelocInfo::CODE_TARGET : |
| 3221 | RelocInfo::CODE_TARGET_CONTEXT; |
| 3222 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3223 | CallCode(ic, mode, instr); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3227 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 3228 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3229 | Handle<PropertyCell> cell_handle = instr->hydrogen()->cell().handle(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3230 | |
| 3231 | // If the cell we are storing to contains the hole it could have |
| 3232 | // been deleted from the property dictionary. In that case, we need |
| 3233 | // to update the property details in the property dictionary to mark |
| 3234 | // it as no longer deleted. We deoptimize in that case. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3235 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3236 | __ cmp(Operand::ForCell(cell_handle), factory()->the_hole_value()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3237 | DeoptimizeIf(equal, instr->environment()); |
| 3238 | } |
| 3239 | |
| 3240 | // Store the value. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3241 | __ mov(Operand::ForCell(cell_handle), value); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3242 | // Cells are always rescanned, so no write barrier here. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3246 | void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { |
| 3247 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 3248 | ASSERT(ToRegister(instr->global_object()).is(edx)); |
| 3249 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 3250 | |
| 3251 | __ mov(ecx, instr->name()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3252 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3253 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3254 | : isolate()->builtins()->StoreIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3255 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3259 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3260 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3261 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3262 | __ mov(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3263 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3264 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3265 | __ cmp(result, factory()->the_hole_value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3266 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3267 | DeoptimizeIf(equal, instr->environment()); |
| 3268 | } else { |
| 3269 | Label is_not_hole; |
| 3270 | __ j(not_equal, &is_not_hole, Label::kNear); |
| 3271 | __ mov(result, factory()->undefined_value()); |
| 3272 | __ bind(&is_not_hole); |
| 3273 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3274 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | |
| 3278 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 3279 | Register context = ToRegister(instr->context()); |
| 3280 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3281 | |
| 3282 | Label skip_assignment; |
| 3283 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3284 | Operand target = ContextOperand(context, instr->slot_index()); |
| 3285 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3286 | __ cmp(target, factory()->the_hole_value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3287 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3288 | DeoptimizeIf(equal, instr->environment()); |
| 3289 | } else { |
| 3290 | __ j(not_equal, &skip_assignment, Label::kNear); |
| 3291 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3292 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3293 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3294 | __ mov(target, value); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3295 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3296 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3297 | instr->hydrogen()->value()->IsHeapObject() |
| 3298 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3299 | Register temp = ToRegister(instr->temp()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3300 | int offset = Context::SlotOffset(instr->slot_index()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3301 | __ RecordWriteContextSlot(context, |
| 3302 | offset, |
| 3303 | value, |
| 3304 | temp, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3305 | GetSaveFPRegsMode(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3306 | EMIT_REMEMBERED_SET, |
| 3307 | check_needed); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3308 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3309 | |
| 3310 | __ bind(&skip_assignment); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3314 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3315 | HObjectAccess access = instr->hydrogen()->access(); |
| 3316 | int offset = access.offset(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3317 | |
| 3318 | if (access.IsExternalMemory()) { |
| 3319 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3320 | MemOperand operand = instr->object()->IsConstantOperand() |
| 3321 | ? MemOperand::StaticVariable(ToExternalReference( |
| 3322 | LConstantOperand::cast(instr->object()))) |
| 3323 | : MemOperand(ToRegister(instr->object()), offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3324 | __ Load(result, operand, access.representation()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3325 | return; |
| 3326 | } |
| 3327 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3328 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3329 | if (FLAG_track_double_fields && |
| 3330 | instr->hydrogen()->representation().IsDouble()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3331 | if (CpuFeatures::IsSupported(SSE2)) { |
| 3332 | CpuFeatureScope scope(masm(), SSE2); |
| 3333 | XMMRegister result = ToDoubleRegister(instr->result()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3334 | __ movsd(result, FieldOperand(object, offset)); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3335 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3336 | X87Mov(ToX87Register(instr->result()), FieldOperand(object, offset)); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3337 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3338 | return; |
| 3339 | } |
| 3340 | |
| 3341 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3342 | if (!access.IsInobject()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3343 | __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3344 | object = result; |
| 3345 | } |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3346 | __ Load(result, FieldOperand(object, offset), access.representation()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3350 | void LCodeGen::EmitPushTaggedOperand(LOperand* operand) { |
| 3351 | ASSERT(!operand->IsDoubleRegister()); |
| 3352 | if (operand->IsConstantOperand()) { |
| 3353 | Handle<Object> object = ToHandle(LConstantOperand::cast(operand)); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 3354 | AllowDeferredHandleDereference smi_check; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3355 | if (object->IsSmi()) { |
| 3356 | __ Push(Handle<Smi>::cast(object)); |
| 3357 | } else { |
| 3358 | __ PushHeapObject(Handle<HeapObject>::cast(object)); |
| 3359 | } |
| 3360 | } else if (operand->IsRegister()) { |
| 3361 | __ push(ToRegister(operand)); |
| 3362 | } else { |
| 3363 | __ push(ToOperand(operand)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3368 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3369 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3370 | ASSERT(ToRegister(instr->object()).is(edx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3371 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 3372 | |
| 3373 | __ mov(ecx, instr->name()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3374 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3375 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3379 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 3380 | Register function = ToRegister(instr->function()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3381 | Register temp = ToRegister(instr->temp()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3382 | Register result = ToRegister(instr->result()); |
| 3383 | |
| 3384 | // Check that the function really is a function. |
| 3385 | __ CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 3386 | DeoptimizeIf(not_equal, instr->environment()); |
| 3387 | |
| 3388 | // Check whether the function has an instance prototype. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3389 | Label non_instance; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3390 | __ test_b(FieldOperand(result, Map::kBitFieldOffset), |
| 3391 | 1 << Map::kHasNonInstancePrototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3392 | __ j(not_zero, &non_instance, Label::kNear); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3393 | |
| 3394 | // Get the prototype or initial map from the function. |
| 3395 | __ mov(result, |
| 3396 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3397 | |
| 3398 | // Check that the function has a prototype or an initial map. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3399 | __ cmp(Operand(result), Immediate(factory()->the_hole_value())); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3400 | DeoptimizeIf(equal, instr->environment()); |
| 3401 | |
| 3402 | // If the function does not have an initial map, we're done. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3403 | Label done; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3404 | __ CmpObjectType(result, MAP_TYPE, temp); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3405 | __ j(not_equal, &done, Label::kNear); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3406 | |
| 3407 | // Get the prototype from the initial map. |
| 3408 | __ mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3409 | __ jmp(&done, Label::kNear); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3410 | |
| 3411 | // Non-instance prototype: Fetch prototype from constructor field |
| 3412 | // in the function's map. |
| 3413 | __ bind(&non_instance); |
| 3414 | __ mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 3415 | |
| 3416 | // All done. |
| 3417 | __ bind(&done); |
| 3418 | } |
| 3419 | |
| 3420 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3421 | void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 3422 | Register result = ToRegister(instr->result()); |
| 3423 | __ LoadRoot(result, instr->index()); |
| 3424 | } |
| 3425 | |
| 3426 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3427 | void LCodeGen::DoLoadExternalArrayPointer( |
| 3428 | LLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3429 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3430 | Register input = ToRegister(instr->object()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3431 | __ mov(result, FieldOperand(input, |
| 3432 | ExternalArray::kExternalPointerOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3436 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 3437 | Register arguments = ToRegister(instr->arguments()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3438 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3439 | if (instr->length()->IsConstantOperand() && |
| 3440 | instr->index()->IsConstantOperand()) { |
| 3441 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3442 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 3443 | int index = (const_length - const_index) + 1; |
| 3444 | __ mov(result, Operand(arguments, index * kPointerSize)); |
| 3445 | } else { |
| 3446 | Register length = ToRegister(instr->length()); |
| 3447 | Operand index = ToOperand(instr->index()); |
| 3448 | // There are two words between the frame pointer and the last argument. |
| 3449 | // Subtracting from length accounts for one of them add one more. |
| 3450 | __ sub(length, index); |
| 3451 | __ mov(result, Operand(arguments, length, times_4, kPointerSize)); |
| 3452 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3456 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3457 | ElementsKind elements_kind = instr->elements_kind(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 3458 | LOperand* key = instr->key(); |
| 3459 | if (!key->IsConstantOperand() && |
| 3460 | ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(), |
| 3461 | elements_kind)) { |
| 3462 | __ SmiUntag(ToRegister(key)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3463 | } |
| 3464 | Operand operand(BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3465 | instr->elements(), |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 3466 | key, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3467 | instr->hydrogen()->key()->representation(), |
| 3468 | elements_kind, |
| 3469 | 0, |
| 3470 | instr->additional_index())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3471 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3472 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3473 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3474 | XMMRegister result(ToDoubleRegister(instr->result())); |
| 3475 | __ movss(result, operand); |
| 3476 | __ cvtss2sd(result, result); |
| 3477 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3478 | X87Mov(ToX87Register(instr->result()), operand, kX87FloatOperand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3479 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3480 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3481 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3482 | CpuFeatureScope scope(masm(), SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3483 | __ movsd(ToDoubleRegister(instr->result()), operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3484 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3485 | X87Mov(ToX87Register(instr->result()), operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3486 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3487 | } else { |
| 3488 | Register result(ToRegister(instr->result())); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3489 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3490 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3491 | __ movsx_b(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3492 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3493 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3494 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3495 | __ movzx_b(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3496 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3497 | case EXTERNAL_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3498 | __ movsx_w(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3499 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3500 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3501 | __ movzx_w(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3502 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3503 | case EXTERNAL_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3504 | __ mov(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3505 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3506 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3507 | __ mov(result, operand); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3508 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3509 | __ test(result, Operand(result)); |
| 3510 | DeoptimizeIf(negative, instr->environment()); |
| 3511 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3512 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3513 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3514 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3515 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3516 | case FAST_ELEMENTS: |
| 3517 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3518 | case FAST_HOLEY_SMI_ELEMENTS: |
| 3519 | case FAST_HOLEY_ELEMENTS: |
| 3520 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3521 | case DICTIONARY_ELEMENTS: |
| 3522 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3523 | UNREACHABLE(); |
| 3524 | break; |
| 3525 | } |
| 3526 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3530 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3531 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3532 | int offset = FixedDoubleArray::kHeaderSize - kHeapObjectTag + |
| 3533 | sizeof(kHoleNanLower32); |
| 3534 | Operand hole_check_operand = BuildFastArrayOperand( |
| 3535 | instr->elements(), instr->key(), |
| 3536 | instr->hydrogen()->key()->representation(), |
| 3537 | FAST_DOUBLE_ELEMENTS, |
| 3538 | offset, |
| 3539 | instr->additional_index()); |
| 3540 | __ cmp(hole_check_operand, Immediate(kHoleNanUpper32)); |
| 3541 | DeoptimizeIf(equal, instr->environment()); |
| 3542 | } |
| 3543 | |
| 3544 | Operand double_load_operand = BuildFastArrayOperand( |
| 3545 | instr->elements(), |
| 3546 | instr->key(), |
| 3547 | instr->hydrogen()->key()->representation(), |
| 3548 | FAST_DOUBLE_ELEMENTS, |
| 3549 | FixedDoubleArray::kHeaderSize - kHeapObjectTag, |
| 3550 | instr->additional_index()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3551 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3552 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3553 | XMMRegister result = ToDoubleRegister(instr->result()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3554 | __ movsd(result, double_load_operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3555 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3556 | X87Mov(ToX87Register(instr->result()), double_load_operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3557 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | |
| 3561 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3562 | Register result = ToRegister(instr->result()); |
| 3563 | |
| 3564 | // Load the result. |
| 3565 | __ mov(result, |
| 3566 | BuildFastArrayOperand(instr->elements(), |
| 3567 | instr->key(), |
| 3568 | instr->hydrogen()->key()->representation(), |
| 3569 | FAST_ELEMENTS, |
| 3570 | FixedArray::kHeaderSize - kHeapObjectTag, |
| 3571 | instr->additional_index())); |
| 3572 | |
| 3573 | // Check for the hole value. |
| 3574 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3575 | if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { |
| 3576 | __ test(result, Immediate(kSmiTagMask)); |
| 3577 | DeoptimizeIf(not_equal, instr->environment()); |
| 3578 | } else { |
| 3579 | __ cmp(result, factory()->the_hole_value()); |
| 3580 | DeoptimizeIf(equal, instr->environment()); |
| 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3587 | if (instr->is_external()) { |
| 3588 | DoLoadKeyedExternalArray(instr); |
| 3589 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3590 | DoLoadKeyedFixedDoubleArray(instr); |
| 3591 | } else { |
| 3592 | DoLoadKeyedFixedArray(instr); |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | |
| 3597 | Operand LCodeGen::BuildFastArrayOperand( |
| 3598 | LOperand* elements_pointer, |
| 3599 | LOperand* key, |
| 3600 | Representation key_representation, |
| 3601 | ElementsKind elements_kind, |
| 3602 | uint32_t offset, |
| 3603 | uint32_t additional_index) { |
| 3604 | Register elements_pointer_reg = ToRegister(elements_pointer); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3605 | int element_shift_size = ElementsKindToShiftSize(elements_kind); |
| 3606 | int shift_size = element_shift_size; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3607 | if (key->IsConstantOperand()) { |
| 3608 | int constant_value = ToInteger32(LConstantOperand::cast(key)); |
| 3609 | if (constant_value & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3610 | Abort(kArrayIndexConstantValueTooBig); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3611 | } |
| 3612 | return Operand(elements_pointer_reg, |
| 3613 | ((constant_value + additional_index) << shift_size) |
| 3614 | + offset); |
| 3615 | } else { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 3616 | // Take the tag bit into account while computing the shift size. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3617 | if (key_representation.IsSmi() && (shift_size >= 1)) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 3618 | shift_size -= kSmiTagSize; |
| 3619 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3620 | ScaleFactor scale_factor = static_cast<ScaleFactor>(shift_size); |
| 3621 | return Operand(elements_pointer_reg, |
| 3622 | ToRegister(key), |
| 3623 | scale_factor, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3624 | offset + (additional_index << element_shift_size)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3629 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3630 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3631 | ASSERT(ToRegister(instr->object()).is(edx)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3632 | ASSERT(ToRegister(instr->key()).is(ecx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3633 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3634 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3635 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | |
| 3639 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 3640 | Register result = ToRegister(instr->result()); |
| 3641 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3642 | if (instr->hydrogen()->from_inlined()) { |
| 3643 | __ lea(result, Operand(esp, -2 * kPointerSize)); |
| 3644 | } else { |
| 3645 | // Check for arguments adapter frame. |
| 3646 | Label done, adapted; |
| 3647 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3648 | __ mov(result, Operand(result, StandardFrameConstants::kContextOffset)); |
| 3649 | __ cmp(Operand(result), |
| 3650 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3651 | __ j(equal, &adapted, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3652 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3653 | // No arguments adaptor frame. |
| 3654 | __ mov(result, Operand(ebp)); |
| 3655 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3656 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3657 | // Arguments adaptor frame present. |
| 3658 | __ bind(&adapted); |
| 3659 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3660 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3661 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3662 | // frame below the adaptor frame if adapted. |
| 3663 | __ bind(&done); |
| 3664 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | |
| 3668 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3669 | Operand elem = ToOperand(instr->elements()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3670 | Register result = ToRegister(instr->result()); |
| 3671 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3672 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3673 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3674 | // If no arguments adaptor frame the number of arguments is fixed. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3675 | __ cmp(ebp, elem); |
| 3676 | __ mov(result, Immediate(scope()->num_parameters())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3677 | __ j(equal, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3678 | |
| 3679 | // Arguments adaptor frame present. Get argument length from there. |
| 3680 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3681 | __ mov(result, Operand(result, |
| 3682 | ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3683 | __ SmiUntag(result); |
| 3684 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3685 | // Argument length is in result register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3686 | __ bind(&done); |
| 3687 | } |
| 3688 | |
| 3689 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3690 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3691 | Register receiver = ToRegister(instr->receiver()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3692 | Register function = ToRegister(instr->function()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3693 | Register scratch = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3694 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3695 | // If the receiver is null or undefined, we have to pass the global |
| 3696 | // object as a receiver to normal functions. Values have to be |
| 3697 | // passed unchanged to builtins and strict-mode functions. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3698 | Label global_object, receiver_ok; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3699 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3700 | |
| 3701 | // Do not transform the receiver to object for strict mode |
| 3702 | // functions. |
| 3703 | __ mov(scratch, |
| 3704 | FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3705 | __ test_b(FieldOperand(scratch, SharedFunctionInfo::kStrictModeByteOffset), |
| 3706 | 1 << SharedFunctionInfo::kStrictModeBitWithinByte); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3707 | __ j(not_equal, &receiver_ok, dist); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3708 | |
| 3709 | // Do not transform the receiver to object for builtins. |
| 3710 | __ test_b(FieldOperand(scratch, SharedFunctionInfo::kNativeByteOffset), |
| 3711 | 1 << SharedFunctionInfo::kNativeBitWithinByte); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3712 | __ j(not_equal, &receiver_ok, dist); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3713 | |
| 3714 | // Normal function. Replace undefined or null with global receiver. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3715 | __ cmp(receiver, factory()->null_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3716 | __ j(equal, &global_object, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3717 | __ cmp(receiver, factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3718 | __ j(equal, &global_object, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3719 | |
| 3720 | // The receiver should be a JS object. |
| 3721 | __ test(receiver, Immediate(kSmiTagMask)); |
| 3722 | DeoptimizeIf(equal, instr->environment()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3723 | __ CmpObjectType(receiver, FIRST_SPEC_OBJECT_TYPE, scratch); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3724 | DeoptimizeIf(below, instr->environment()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3725 | __ jmp(&receiver_ok, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3726 | |
| 3727 | __ bind(&global_object); |
| 3728 | // TODO(kmillikin): We have a hydrogen value for the global object. See |
| 3729 | // if it's better to use it than to explicitly fetch it from the context |
| 3730 | // here. |
| 3731 | __ mov(receiver, Operand(ebp, StandardFrameConstants::kContextOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3732 | __ mov(receiver, ContextOperand(receiver, Context::GLOBAL_OBJECT_INDEX)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3733 | __ mov(receiver, |
| 3734 | FieldOperand(receiver, JSGlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3735 | __ bind(&receiver_ok); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | |
| 3739 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3740 | Register receiver = ToRegister(instr->receiver()); |
| 3741 | Register function = ToRegister(instr->function()); |
| 3742 | Register length = ToRegister(instr->length()); |
| 3743 | Register elements = ToRegister(instr->elements()); |
| 3744 | ASSERT(receiver.is(eax)); // Used for parameter count. |
| 3745 | ASSERT(function.is(edi)); // Required by InvokeFunction. |
| 3746 | ASSERT(ToRegister(instr->result()).is(eax)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3747 | |
| 3748 | // Copy the arguments to this function possibly from the |
| 3749 | // adaptor frame below it. |
| 3750 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3751 | __ cmp(length, kArgumentsLimit); |
| 3752 | DeoptimizeIf(above, instr->environment()); |
| 3753 | |
| 3754 | __ push(receiver); |
| 3755 | __ mov(receiver, length); |
| 3756 | |
| 3757 | // Loop through the arguments pushing them onto the execution |
| 3758 | // stack. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3759 | Label invoke, loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3760 | // length is a small non-negative integer, due to the test above. |
| 3761 | __ test(length, Operand(length)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3762 | __ j(zero, &invoke, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3763 | __ bind(&loop); |
| 3764 | __ push(Operand(elements, length, times_pointer_size, 1 * kPointerSize)); |
| 3765 | __ dec(length); |
| 3766 | __ j(not_zero, &loop); |
| 3767 | |
| 3768 | // Invoke the function. |
| 3769 | __ bind(&invoke); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3770 | ASSERT(instr->HasPointerMap()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3771 | LPointerMap* pointers = instr->pointer_map(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3772 | SafepointGenerator safepoint_generator( |
| 3773 | this, pointers, Safepoint::kLazyDeopt); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3774 | ParameterCount actual(eax); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3775 | __ InvokeFunction(function, actual, CALL_FUNCTION, |
| 3776 | safepoint_generator, CALL_AS_METHOD); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3780 | void LCodeGen::DoDebugBreak(LDebugBreak* instr) { |
| 3781 | __ int3(); |
| 3782 | } |
| 3783 | |
| 3784 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3785 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3786 | LOperand* argument = instr->value(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3787 | EmitPushTaggedOperand(argument); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3791 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3792 | __ Drop(instr->count()); |
| 3793 | } |
| 3794 | |
| 3795 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3796 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3797 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3798 | __ mov(result, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3802 | void LCodeGen::DoContext(LContext* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3803 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 3804 | if (info()->IsOptimizing()) { |
| 3805 | __ mov(result, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 3806 | } else { |
| 3807 | // If there is no frame, the context must be in esi. |
| 3808 | ASSERT(result.is(esi)); |
| 3809 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | |
| 3813 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 3814 | Register context = ToRegister(instr->context()); |
| 3815 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3816 | __ mov(result, |
| 3817 | Operand(context, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3821 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3822 | ASSERT(ToRegister(instr->context()).is(esi)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3823 | __ push(esi); // The context is the first argument. |
| 3824 | __ push(Immediate(instr->hydrogen()->pairs())); |
| 3825 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->flags()))); |
| 3826 | CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 3827 | } |
| 3828 | |
| 3829 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3830 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
| 3831 | Register context = ToRegister(instr->context()); |
| 3832 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3833 | __ mov(result, |
| 3834 | Operand(context, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | |
| 3838 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3839 | Register global = ToRegister(instr->global()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3840 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3841 | __ mov(result, FieldOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | |
| 3845 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3846 | int formal_parameter_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3847 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3848 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3849 | CallKind call_kind, |
| 3850 | EDIState edi_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3851 | bool dont_adapt_arguments = |
| 3852 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3853 | bool can_invoke_directly = |
| 3854 | dont_adapt_arguments || formal_parameter_count == arity; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3855 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3856 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3857 | if (edi_state == EDI_UNINITIALIZED) { |
| 3858 | __ LoadHeapObject(edi, function); |
| 3859 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3860 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3861 | // Change context. |
| 3862 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3863 | |
| 3864 | // Set eax to arguments count if adaption is not needed. Assumes that eax |
| 3865 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3866 | if (dont_adapt_arguments) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3867 | __ mov(eax, arity); |
| 3868 | } |
| 3869 | |
| 3870 | // Invoke function directly. |
| 3871 | __ SetCallKind(ecx, call_kind); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3872 | if (function.is_identical_to(info()->closure())) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3873 | __ CallSelf(); |
| 3874 | } else { |
| 3875 | __ call(FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 3876 | } |
| 3877 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3878 | } else { |
| 3879 | // We need to adapt arguments. |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 3880 | LPointerMap* pointers = instr->pointer_map(); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3881 | SafepointGenerator generator( |
| 3882 | this, pointers, Safepoint::kLazyDeopt); |
| 3883 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3884 | ParameterCount expected(formal_parameter_count); |
| 3885 | __ InvokeFunction( |
| 3886 | function, expected, count, CALL_FUNCTION, generator, call_kind); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3887 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | |
| 3891 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
| 3892 | ASSERT(ToRegister(instr->result()).is(eax)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3893 | CallKnownFunction(instr->hydrogen()->function(), |
| 3894 | instr->hydrogen()->formal_parameter_count(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3895 | instr->arity(), |
| 3896 | instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3897 | CALL_AS_METHOD, |
| 3898 | EDI_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3902 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3903 | Register input_reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3904 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3905 | factory()->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3906 | DeoptimizeIf(not_equal, instr->environment()); |
| 3907 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3908 | Label slow, allocated, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3909 | Register tmp = input_reg.is(eax) ? ecx : eax; |
| 3910 | Register tmp2 = tmp.is(ecx) ? edx : input_reg.is(ecx) ? edx : ecx; |
| 3911 | |
| 3912 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3913 | PushSafepointRegistersScope scope(this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3914 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3915 | __ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3916 | // Check the sign of the argument. If the argument is positive, just |
| 3917 | // return it. We do not need to patch the stack since |input| and |
| 3918 | // |result| are the same register and |input| will be restored |
| 3919 | // unchanged by popping safepoint registers. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3920 | __ test(tmp, Immediate(HeapNumber::kSignMask)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3921 | __ j(zero, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3922 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3923 | __ AllocateHeapNumber(tmp, tmp2, no_reg, &slow); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3924 | __ jmp(&allocated, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3925 | |
| 3926 | // Slow case: Call the runtime system to do the number allocation. |
| 3927 | __ bind(&slow); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3928 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, |
| 3929 | instr, instr->context()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3930 | // Set the pointer to the new heap number in tmp. |
| 3931 | if (!tmp.is(eax)) __ mov(tmp, eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3932 | // Restore input_reg after call to runtime. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3933 | __ LoadFromSafepointRegisterSlot(input_reg, input_reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3934 | |
| 3935 | __ bind(&allocated); |
| 3936 | __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 3937 | __ and_(tmp2, ~HeapNumber::kSignMask); |
| 3938 | __ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2); |
| 3939 | __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
| 3940 | __ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3941 | __ StoreToSafepointRegisterSlot(input_reg, tmp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3942 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3943 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3947 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3948 | Register input_reg = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3949 | __ test(input_reg, Operand(input_reg)); |
| 3950 | Label is_positive; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3951 | __ j(not_sign, &is_positive, Label::kNear); |
| 3952 | __ neg(input_reg); // Sets flags. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3953 | DeoptimizeIf(negative, instr->environment()); |
| 3954 | __ bind(&is_positive); |
| 3955 | } |
| 3956 | |
| 3957 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3958 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3959 | // Class for deferred case. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3960 | class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3961 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3962 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, |
| 3963 | LMathAbs* instr, |
| 3964 | const X87Stack& x87_stack) |
| 3965 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3966 | virtual void Generate() V8_OVERRIDE { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3967 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3968 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3969 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3970 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3971 | LMathAbs* instr_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3972 | }; |
| 3973 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3974 | ASSERT(instr->value()->Equals(instr->result())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3975 | Representation r = instr->hydrogen()->value()->representation(); |
| 3976 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3977 | CpuFeatureScope scope(masm(), SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3978 | if (r.IsDouble()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3979 | XMMRegister scratch = double_scratch0(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3980 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3981 | __ xorps(scratch, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3982 | __ subsd(scratch, input_reg); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 3983 | __ andps(input_reg, scratch); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3984 | } else if (r.IsSmiOrInteger32()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3985 | EmitIntegerMathAbs(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3986 | } else { // Tagged case. |
| 3987 | DeferredMathAbsTaggedHeapNumber* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3988 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr, x87_stack_); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3989 | Register input_reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3990 | // Smi check. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3991 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3992 | EmitIntegerMathAbs(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3993 | __ bind(deferred->exit()); |
| 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3998 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3999 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4000 | XMMRegister xmm_scratch = double_scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4001 | Register output_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4002 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4003 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4004 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4005 | CpuFeatureScope scope(masm(), SSE4_1); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4006 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4007 | // Deoptimize on negative zero. |
| 4008 | Label non_zero; |
| 4009 | __ xorps(xmm_scratch, xmm_scratch); // Zero the register. |
| 4010 | __ ucomisd(input_reg, xmm_scratch); |
| 4011 | __ j(not_equal, &non_zero, Label::kNear); |
| 4012 | __ movmskpd(output_reg, input_reg); |
| 4013 | __ test(output_reg, Immediate(1)); |
| 4014 | DeoptimizeIf(not_zero, instr->environment()); |
| 4015 | __ bind(&non_zero); |
| 4016 | } |
| 4017 | __ roundsd(xmm_scratch, input_reg, Assembler::kRoundDown); |
| 4018 | __ cvttsd2si(output_reg, Operand(xmm_scratch)); |
| 4019 | // Overflow is signalled with minint. |
| 4020 | __ cmp(output_reg, 0x80000000u); |
| 4021 | DeoptimizeIf(equal, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4022 | } else { |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4023 | Label negative_sign, done; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4024 | // Deoptimize on unordered. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4025 | __ xorps(xmm_scratch, xmm_scratch); // Zero the register. |
| 4026 | __ ucomisd(input_reg, xmm_scratch); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4027 | DeoptimizeIf(parity_even, instr->environment()); |
| 4028 | __ j(below, &negative_sign, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4029 | |
| 4030 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4031 | // Check for negative zero. |
| 4032 | Label positive_sign; |
| 4033 | __ j(above, &positive_sign, Label::kNear); |
| 4034 | __ movmskpd(output_reg, input_reg); |
| 4035 | __ test(output_reg, Immediate(1)); |
| 4036 | DeoptimizeIf(not_zero, instr->environment()); |
| 4037 | __ Set(output_reg, Immediate(0)); |
| 4038 | __ jmp(&done, Label::kNear); |
| 4039 | __ bind(&positive_sign); |
| 4040 | } |
| 4041 | |
| 4042 | // Use truncating instruction (OK because input is positive). |
| 4043 | __ cvttsd2si(output_reg, Operand(input_reg)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4044 | // Overflow is signalled with minint. |
| 4045 | __ cmp(output_reg, 0x80000000u); |
| 4046 | DeoptimizeIf(equal, instr->environment()); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4047 | __ jmp(&done, Label::kNear); |
| 4048 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4049 | // Non-zero negative reaches here. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4050 | __ bind(&negative_sign); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4051 | // Truncate, then compare and compensate. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4052 | __ cvttsd2si(output_reg, Operand(input_reg)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4053 | __ Cvtsi2sd(xmm_scratch, output_reg); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4054 | __ ucomisd(input_reg, xmm_scratch); |
| 4055 | __ j(equal, &done, Label::kNear); |
| 4056 | __ sub(output_reg, Immediate(1)); |
| 4057 | DeoptimizeIf(overflow, instr->environment()); |
| 4058 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4059 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4060 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4063 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4064 | void LCodeGen::DoMathRound(LMathRound* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4065 | CpuFeatureScope scope(masm(), SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4066 | Register output_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4067 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4068 | XMMRegister xmm_scratch = double_scratch0(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4069 | XMMRegister input_temp = ToDoubleRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4070 | ExternalReference one_half = ExternalReference::address_of_one_half(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4071 | ExternalReference minus_one_half = |
| 4072 | ExternalReference::address_of_minus_one_half(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4073 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4074 | Label done, round_to_zero, below_one_half, do_not_compensate; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4075 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
| 4076 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4077 | __ movsd(xmm_scratch, Operand::StaticVariable(one_half)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4078 | __ ucomisd(xmm_scratch, input_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4079 | __ j(above, &below_one_half, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4080 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4081 | // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). |
| 4082 | __ addsd(xmm_scratch, input_reg); |
| 4083 | __ cvttsd2si(output_reg, Operand(xmm_scratch)); |
| 4084 | // Overflow is signalled with minint. |
| 4085 | __ cmp(output_reg, 0x80000000u); |
| 4086 | __ RecordComment("D2I conversion overflow"); |
| 4087 | DeoptimizeIf(equal, instr->environment()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4088 | __ jmp(&done, dist); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4089 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4090 | __ bind(&below_one_half); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4091 | __ movsd(xmm_scratch, Operand::StaticVariable(minus_one_half)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4092 | __ ucomisd(xmm_scratch, input_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4093 | __ j(below_equal, &round_to_zero, Label::kNear); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4094 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4095 | // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
| 4096 | // compare and compensate. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 4097 | __ movaps(input_temp, input_reg); // Do not alter input_reg. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4098 | __ subsd(input_temp, xmm_scratch); |
| 4099 | __ cvttsd2si(output_reg, Operand(input_temp)); |
| 4100 | // Catch minint due to overflow, and to prevent overflow when compensating. |
| 4101 | __ cmp(output_reg, 0x80000000u); |
| 4102 | __ RecordComment("D2I conversion overflow"); |
| 4103 | DeoptimizeIf(equal, instr->environment()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4104 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4105 | __ Cvtsi2sd(xmm_scratch, output_reg); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4106 | __ ucomisd(xmm_scratch, input_temp); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4107 | __ j(equal, &done, dist); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4108 | __ sub(output_reg, Immediate(1)); |
| 4109 | // No overflow because we already ruled out minint. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4110 | __ jmp(&done, dist); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4111 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4112 | __ bind(&round_to_zero); |
| 4113 | // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if |
| 4114 | // we can ignore the difference between a result of -0 and +0. |
| 4115 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4116 | // If the sign is positive, we return +0. |
| 4117 | __ movmskpd(output_reg, input_reg); |
| 4118 | __ test(output_reg, Immediate(1)); |
| 4119 | __ RecordComment("Minus zero"); |
| 4120 | DeoptimizeIf(not_zero, instr->environment()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4121 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4122 | __ Set(output_reg, Immediate(0)); |
| 4123 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4127 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4128 | CpuFeatureScope scope(masm(), SSE2); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4129 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4130 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
| 4131 | __ sqrtsd(input_reg, input_reg); |
| 4132 | } |
| 4133 | |
| 4134 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4135 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4136 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4137 | XMMRegister xmm_scratch = double_scratch0(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4138 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4139 | Register scratch = ToRegister(instr->temp()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4140 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4141 | |
| 4142 | // Note that according to ECMA-262 15.8.2.13: |
| 4143 | // Math.pow(-Infinity, 0.5) == Infinity |
| 4144 | // Math.sqrt(-Infinity) == NaN |
| 4145 | Label done, sqrt; |
| 4146 | // Check base for -Infinity. According to IEEE-754, single-precision |
| 4147 | // -Infinity has the highest 9 bits set and the lowest 23 bits cleared. |
| 4148 | __ mov(scratch, 0xFF800000); |
| 4149 | __ movd(xmm_scratch, scratch); |
| 4150 | __ cvtss2sd(xmm_scratch, xmm_scratch); |
| 4151 | __ ucomisd(input_reg, xmm_scratch); |
| 4152 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 4153 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 4154 | __ j(not_equal, &sqrt, Label::kNear); |
| 4155 | __ j(carry, &sqrt, Label::kNear); |
| 4156 | // If input is -Infinity, return Infinity. |
| 4157 | __ xorps(input_reg, input_reg); |
| 4158 | __ subsd(input_reg, xmm_scratch); |
| 4159 | __ jmp(&done, Label::kNear); |
| 4160 | |
| 4161 | // Square root. |
| 4162 | __ bind(&sqrt); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4163 | __ xorps(xmm_scratch, xmm_scratch); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 4164 | __ addsd(input_reg, xmm_scratch); // Convert -0 to +0. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4165 | __ sqrtsd(input_reg, input_reg); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4166 | __ bind(&done); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | |
| 4170 | void LCodeGen::DoPower(LPower* instr) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4171 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4172 | // Having marked this as a call, we can use any registers. |
| 4173 | // Just make sure that the input/output registers are the expected ones. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4174 | ASSERT(!instr->right()->IsDoubleRegister() || |
| 4175 | ToDoubleRegister(instr->right()).is(xmm1)); |
| 4176 | ASSERT(!instr->right()->IsRegister() || |
| 4177 | ToRegister(instr->right()).is(eax)); |
| 4178 | ASSERT(ToDoubleRegister(instr->left()).is(xmm2)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4179 | ASSERT(ToDoubleRegister(instr->result()).is(xmm3)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4180 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4181 | if (exponent_type.IsSmi()) { |
| 4182 | MathPowStub stub(MathPowStub::TAGGED); |
| 4183 | __ CallStub(&stub); |
| 4184 | } else if (exponent_type.IsTagged()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4185 | Label no_deopt; |
| 4186 | __ JumpIfSmi(eax, &no_deopt); |
| 4187 | __ CmpObjectType(eax, HEAP_NUMBER_TYPE, ecx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4188 | DeoptimizeIf(not_equal, instr->environment()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4189 | __ bind(&no_deopt); |
| 4190 | MathPowStub stub(MathPowStub::TAGGED); |
| 4191 | __ CallStub(&stub); |
| 4192 | } else if (exponent_type.IsInteger32()) { |
| 4193 | MathPowStub stub(MathPowStub::INTEGER); |
| 4194 | __ CallStub(&stub); |
| 4195 | } else { |
| 4196 | ASSERT(exponent_type.IsDouble()); |
| 4197 | MathPowStub stub(MathPowStub::DOUBLE); |
| 4198 | __ CallStub(&stub); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4199 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4203 | void LCodeGen::DoRandom(LRandom* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4204 | CpuFeatureScope scope(masm(), SSE2); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4205 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4206 | // Assert that the register size is indeed the size of each seed. |
| 4207 | static const int kSeedSize = sizeof(uint32_t); |
| 4208 | STATIC_ASSERT(kPointerSize == kSeedSize); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4209 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4210 | // Load native context |
| 4211 | Register global_object = ToRegister(instr->global_object()); |
| 4212 | Register native_context = global_object; |
| 4213 | __ mov(native_context, FieldOperand( |
| 4214 | global_object, GlobalObject::kNativeContextOffset)); |
| 4215 | |
| 4216 | // Load state (FixedArray of the native context's random seeds) |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4217 | static const int kRandomSeedOffset = |
| 4218 | FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4219 | Register state = native_context; |
| 4220 | __ mov(state, FieldOperand(native_context, kRandomSeedOffset)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4221 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4222 | // Load state[0]. |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4223 | Register state0 = ToRegister(instr->scratch()); |
| 4224 | __ mov(state0, FieldOperand(state, ByteArray::kHeaderSize)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4225 | // Load state[1]. |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4226 | Register state1 = ToRegister(instr->scratch2()); |
| 4227 | __ mov(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4228 | |
| 4229 | // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4230 | Register scratch3 = ToRegister(instr->scratch3()); |
| 4231 | __ movzx_w(scratch3, state0); |
| 4232 | __ imul(scratch3, scratch3, 18273); |
| 4233 | __ shr(state0, 16); |
| 4234 | __ add(state0, scratch3); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4235 | // Save state[0]. |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4236 | __ mov(FieldOperand(state, ByteArray::kHeaderSize), state0); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4237 | |
| 4238 | // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4239 | __ movzx_w(scratch3, state1); |
| 4240 | __ imul(scratch3, scratch3, 36969); |
| 4241 | __ shr(state1, 16); |
| 4242 | __ add(state1, scratch3); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4243 | // Save state[1]. |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4244 | __ mov(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4245 | |
| 4246 | // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4247 | Register random = state0; |
| 4248 | __ shl(random, 14); |
| 4249 | __ and_(state1, Immediate(0x3FFFF)); |
| 4250 | __ add(random, state1); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4251 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4252 | // Convert 32 random bits in random to 0.(32 random bits) in a double |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4253 | // by computing: |
| 4254 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4255 | XMMRegister result = ToDoubleRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4256 | XMMRegister scratch4 = double_scratch0(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4257 | __ mov(scratch3, Immediate(0x49800000)); // 1.0 x 2^20 as single. |
| 4258 | __ movd(scratch4, scratch3); |
| 4259 | __ movd(result, random); |
| 4260 | __ cvtss2sd(scratch4, scratch4); |
| 4261 | __ xorps(result, scratch4); |
| 4262 | __ subsd(result, scratch4); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4266 | void LCodeGen::DoMathLog(LMathLog* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4267 | CpuFeatureScope scope(masm(), SSE2); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4268 | ASSERT(instr->value()->Equals(instr->result())); |
| 4269 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4270 | XMMRegister xmm_scratch = double_scratch0(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4271 | Label positive, done, zero; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4272 | __ xorps(xmm_scratch, xmm_scratch); |
| 4273 | __ ucomisd(input_reg, xmm_scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4274 | __ j(above, &positive, Label::kNear); |
| 4275 | __ j(equal, &zero, Label::kNear); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4276 | ExternalReference nan = |
| 4277 | ExternalReference::address_of_canonical_non_hole_nan(); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4278 | __ movsd(input_reg, Operand::StaticVariable(nan)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4279 | __ jmp(&done, Label::kNear); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4280 | __ bind(&zero); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4281 | ExternalReference ninf = |
| 4282 | ExternalReference::address_of_negative_infinity(); |
| 4283 | __ movsd(input_reg, Operand::StaticVariable(ninf)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4284 | __ jmp(&done, Label::kNear); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4285 | __ bind(&positive); |
| 4286 | __ fldln2(); |
| 4287 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4288 | __ movsd(Operand(esp, 0), input_reg); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4289 | __ fld_d(Operand(esp, 0)); |
| 4290 | __ fyl2x(); |
| 4291 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4292 | __ movsd(input_reg, Operand(esp, 0)); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4293 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 4294 | __ bind(&done); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4298 | void LCodeGen::DoMathExp(LMathExp* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4299 | CpuFeatureScope scope(masm(), SSE2); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4300 | XMMRegister input = ToDoubleRegister(instr->value()); |
| 4301 | XMMRegister result = ToDoubleRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4302 | XMMRegister temp0 = double_scratch0(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4303 | Register temp1 = ToRegister(instr->temp1()); |
| 4304 | Register temp2 = ToRegister(instr->temp2()); |
| 4305 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4306 | MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4310 | void LCodeGen::DoMathTan(LMathTan* instr) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4311 | ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4312 | // Set the context register to a GC-safe fake value. Clobbering it is |
| 4313 | // OK because this instruction is marked as a call. |
| 4314 | __ Set(esi, Immediate(0)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4315 | TranscendentalCacheStub stub(TranscendentalCache::TAN, |
| 4316 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4317 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4321 | void LCodeGen::DoMathCos(LMathCos* instr) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4322 | ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4323 | // Set the context register to a GC-safe fake value. Clobbering it is |
| 4324 | // OK because this instruction is marked as a call. |
| 4325 | __ Set(esi, Immediate(0)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4326 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 4327 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4328 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4332 | void LCodeGen::DoMathSin(LMathSin* instr) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4333 | ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4334 | // Set the context register to a GC-safe fake value. Clobbering it is |
| 4335 | // OK because this instruction is marked as a call. |
| 4336 | __ Set(esi, Immediate(0)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4337 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 4338 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4339 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4343 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 4344 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4345 | ASSERT(ToRegister(instr->function()).is(edi)); |
| 4346 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4347 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4348 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 4349 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4350 | LPointerMap* pointers = instr->pointer_map(); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4351 | SafepointGenerator generator( |
| 4352 | this, pointers, Safepoint::kLazyDeopt); |
| 4353 | ParameterCount count(instr->arity()); |
| 4354 | __ InvokeFunction(edi, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
| 4355 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4356 | CallKnownFunction(known_function, |
| 4357 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4358 | instr->arity(), |
| 4359 | instr, |
| 4360 | CALL_AS_METHOD, |
| 4361 | EDI_CONTAINS_TARGET); |
| 4362 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4366 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4367 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4368 | ASSERT(ToRegister(instr->key()).is(ecx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4369 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4370 | |
| 4371 | int arity = instr->arity(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4372 | Handle<Code> ic = |
| 4373 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arity); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4374 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | |
| 4378 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4379 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4380 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4381 | |
| 4382 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4383 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 4384 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4385 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4386 | __ mov(ecx, instr->name()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4387 | CallCode(ic, mode, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | |
| 4391 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4392 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4393 | ASSERT(ToRegister(instr->function()).is(edi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4394 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4395 | |
| 4396 | int arity = instr->arity(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4397 | CallFunctionStub stub(arity, NO_CALL_FUNCTION_FLAGS); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 4398 | if (instr->hydrogen()->IsTailCall()) { |
| 4399 | if (NeedsEagerFrame()) __ leave(); |
| 4400 | __ jmp(stub.GetCode(isolate()), RelocInfo::CODE_TARGET); |
| 4401 | } else { |
| 4402 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4403 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | |
| 4407 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4408 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4409 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4410 | |
| 4411 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4412 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
| 4413 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4414 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4415 | __ mov(ecx, instr->name()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4416 | CallCode(ic, mode, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | |
| 4420 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 4421 | ASSERT(ToRegister(instr->result()).is(eax)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4422 | CallKnownFunction(instr->hydrogen()->target(), |
| 4423 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4424 | instr->arity(), |
| 4425 | instr, |
| 4426 | CALL_AS_FUNCTION, |
| 4427 | EDI_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | |
| 4431 | void LCodeGen::DoCallNew(LCallNew* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4432 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4433 | ASSERT(ToRegister(instr->constructor()).is(edi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4434 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4435 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4436 | // No cell in ebx for construct type feedback in optimized code |
| 4437 | Handle<Object> undefined_value(isolate()->factory()->undefined_value()); |
| 4438 | __ mov(ebx, Immediate(undefined_value)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4439 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4440 | __ Set(eax, Immediate(instr->arity())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4441 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4445 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
| 4446 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4447 | ASSERT(ToRegister(instr->constructor()).is(edi)); |
| 4448 | ASSERT(ToRegister(instr->result()).is(eax)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4449 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4450 | __ Set(eax, Immediate(instr->arity())); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4451 | __ mov(ebx, instr->hydrogen()->property_cell()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4452 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4453 | AllocationSiteOverrideMode override_mode = |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4454 | (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4455 | ? DISABLE_ALLOCATION_SITES |
| 4456 | : DONT_OVERRIDE; |
| 4457 | ContextCheckMode context_mode = CONTEXT_CHECK_NOT_REQUIRED; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4458 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4459 | if (instr->arity() == 0) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4460 | ArrayNoArgumentConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4461 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4462 | } else if (instr->arity() == 1) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4463 | Label done; |
| 4464 | if (IsFastPackedElementsKind(kind)) { |
| 4465 | Label packed_case; |
| 4466 | // We might need a change here |
| 4467 | // look at the first argument |
| 4468 | __ mov(ecx, Operand(esp, 0)); |
| 4469 | __ test(ecx, ecx); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4470 | __ j(zero, &packed_case, Label::kNear); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4471 | |
| 4472 | ElementsKind holey_kind = GetHoleyElementsKind(kind); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4473 | ArraySingleArgumentConstructorStub stub(holey_kind, context_mode, |
| 4474 | override_mode); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4475 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4476 | __ jmp(&done, Label::kNear); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4477 | __ bind(&packed_case); |
| 4478 | } |
| 4479 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4480 | ArraySingleArgumentConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4481 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4482 | __ bind(&done); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4483 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4484 | ArrayNArgumentsConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4485 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4486 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4490 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4491 | ASSERT(ToRegister(instr->context()).is(esi)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4492 | CallRuntime(instr->function(), instr->arity(), instr, instr->save_doubles()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4496 | void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 4497 | Register function = ToRegister(instr->function()); |
| 4498 | Register code_object = ToRegister(instr->code_object()); |
| 4499 | __ lea(code_object, FieldOperand(code_object, Code::kHeaderSize)); |
| 4500 | __ mov(FieldOperand(function, JSFunction::kCodeEntryOffset), code_object); |
| 4501 | } |
| 4502 | |
| 4503 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4504 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 4505 | Register result = ToRegister(instr->result()); |
| 4506 | Register base = ToRegister(instr->base_object()); |
| 4507 | __ lea(result, Operand(base, instr->offset())); |
| 4508 | } |
| 4509 | |
| 4510 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4511 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4512 | Representation representation = instr->representation(); |
| 4513 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4514 | HObjectAccess access = instr->hydrogen()->access(); |
| 4515 | int offset = access.offset(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4516 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4517 | if (access.IsExternalMemory()) { |
| 4518 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4519 | MemOperand operand = instr->object()->IsConstantOperand() |
| 4520 | ? MemOperand::StaticVariable( |
| 4521 | ToExternalReference(LConstantOperand::cast(instr->object()))) |
| 4522 | : MemOperand(ToRegister(instr->object()), offset); |
| 4523 | if (instr->value()->IsConstantOperand()) { |
| 4524 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 4525 | __ mov(operand, Immediate(ToInteger32(operand_value))); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4526 | } else { |
| 4527 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4528 | __ Store(value, operand, representation); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4529 | } |
| 4530 | return; |
| 4531 | } |
| 4532 | |
| 4533 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4534 | Handle<Map> transition = instr->transition(); |
| 4535 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4536 | if (FLAG_track_fields && representation.IsSmi()) { |
| 4537 | if (instr->value()->IsConstantOperand()) { |
| 4538 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4539 | if (!IsSmi(operand_value)) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4540 | DeoptimizeIf(no_condition, instr->environment()); |
| 4541 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4542 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4543 | } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) { |
| 4544 | if (instr->value()->IsConstantOperand()) { |
| 4545 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
| 4546 | if (IsInteger32(operand_value)) { |
| 4547 | DeoptimizeIf(no_condition, instr->environment()); |
| 4548 | } |
| 4549 | } else { |
| 4550 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 4551 | Register value = ToRegister(instr->value()); |
| 4552 | __ test(value, Immediate(kSmiTagMask)); |
| 4553 | DeoptimizeIf(zero, instr->environment()); |
| 4554 | } |
| 4555 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4556 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
| 4557 | ASSERT(transition.is_null()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4558 | ASSERT(access.IsInobject()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4559 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4560 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4561 | CpuFeatureScope scope(masm(), SSE2); |
| 4562 | XMMRegister value = ToDoubleRegister(instr->value()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4563 | __ movsd(FieldOperand(object, offset), value); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4564 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 4565 | X87Register value = ToX87Register(instr->value()); |
| 4566 | X87Mov(FieldOperand(object, offset), value); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4567 | } |
| 4568 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4569 | } |
| 4570 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4571 | if (!transition.is_null()) { |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4572 | if (!instr->hydrogen()->NeedsWriteBarrierForMap()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4573 | __ mov(FieldOperand(object, HeapObject::kMapOffset), transition); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4574 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4575 | Register temp = ToRegister(instr->temp()); |
| 4576 | Register temp_map = ToRegister(instr->temp_map()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4577 | __ mov(temp_map, transition); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4578 | __ mov(FieldOperand(object, HeapObject::kMapOffset), temp_map); |
| 4579 | // Update the write barrier for the map field. |
| 4580 | __ RecordWriteField(object, |
| 4581 | HeapObject::kMapOffset, |
| 4582 | temp_map, |
| 4583 | temp, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4584 | GetSaveFPRegsMode(), |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4585 | OMIT_REMEMBERED_SET, |
| 4586 | OMIT_SMI_CHECK); |
| 4587 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | // Do the store. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4591 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4592 | instr->hydrogen()->value()->IsHeapObject() |
| 4593 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4594 | |
| 4595 | Register write_register = object; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4596 | if (!access.IsInobject()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4597 | write_register = ToRegister(instr->temp()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4598 | __ mov(write_register, FieldOperand(object, JSObject::kPropertiesOffset)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4601 | MemOperand operand = FieldOperand(write_register, offset); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4602 | if (instr->value()->IsConstantOperand()) { |
| 4603 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4604 | if (operand_value->IsRegister()) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4605 | Register value = ToRegister(operand_value); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4606 | __ Store(value, operand, representation); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 4607 | } else if (representation.IsInteger32()) { |
| 4608 | Immediate immediate = ToImmediate(operand_value, representation); |
| 4609 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4610 | __ mov(operand, immediate); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4611 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4612 | Handle<Object> handle_value = ToHandle(operand_value); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4613 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4614 | __ mov(operand, handle_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4615 | } |
| 4616 | } else { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4617 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4618 | __ Store(value, operand, representation); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 4622 | Register value = ToRegister(instr->value()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4623 | Register temp = access.IsInobject() ? ToRegister(instr->temp()) : object; |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4624 | // Update the write barrier for the object for in-object properties. |
| 4625 | __ RecordWriteField(write_register, |
| 4626 | offset, |
| 4627 | value, |
| 4628 | temp, |
| 4629 | GetSaveFPRegsMode(), |
| 4630 | EMIT_REMEMBERED_SET, |
| 4631 | check_needed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | |
| 4636 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4637 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4638 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 4639 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 4640 | |
| 4641 | __ mov(ecx, instr->name()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4642 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4643 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 4644 | : isolate()->builtins()->StoreIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4645 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4649 | void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) { |
| 4650 | if (FLAG_debug_code && check->hydrogen()->skip_check()) { |
| 4651 | Label done; |
| 4652 | __ j(NegateCondition(cc), &done, Label::kNear); |
| 4653 | __ int3(); |
| 4654 | __ bind(&done); |
| 4655 | } else { |
| 4656 | DeoptimizeIf(cc, check->environment()); |
| 4657 | } |
| 4658 | } |
| 4659 | |
| 4660 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4661 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4662 | if (instr->hydrogen()->skip_check() && !FLAG_debug_code) return; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4663 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4664 | if (instr->index()->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4665 | Immediate immediate = |
| 4666 | ToImmediate(LConstantOperand::cast(instr->index()), |
| 4667 | instr->hydrogen()->length()->representation()); |
| 4668 | __ cmp(ToOperand(instr->length()), immediate); |
| 4669 | Condition condition = |
| 4670 | instr->hydrogen()->allow_equality() ? below : below_equal; |
| 4671 | ApplyCheckIf(condition, instr); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4672 | } else { |
| 4673 | __ cmp(ToRegister(instr->index()), ToOperand(instr->length())); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4674 | Condition condition = |
| 4675 | instr->hydrogen()->allow_equality() ? above : above_equal; |
| 4676 | ApplyCheckIf(condition, instr); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4677 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4681 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4682 | ElementsKind elements_kind = instr->elements_kind(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4683 | LOperand* key = instr->key(); |
| 4684 | if (!key->IsConstantOperand() && |
| 4685 | ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(), |
| 4686 | elements_kind)) { |
| 4687 | __ SmiUntag(ToRegister(key)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4688 | } |
| 4689 | Operand operand(BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4690 | instr->elements(), |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4691 | key, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4692 | instr->hydrogen()->key()->representation(), |
| 4693 | elements_kind, |
| 4694 | 0, |
| 4695 | instr->additional_index())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4696 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4697 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 4698 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4699 | XMMRegister xmm_scratch = double_scratch0(); |
| 4700 | __ cvtsd2ss(xmm_scratch, ToDoubleRegister(instr->value())); |
| 4701 | __ movss(operand, xmm_scratch); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4702 | } else { |
| 4703 | __ fld(0); |
| 4704 | __ fstp_s(operand); |
| 4705 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4706 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4707 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 4708 | CpuFeatureScope scope(masm(), SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4709 | __ movsd(operand, ToDoubleRegister(instr->value())); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4710 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 4711 | X87Mov(operand, ToX87Register(instr->value())); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4712 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4713 | } else { |
| 4714 | Register value = ToRegister(instr->value()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4715 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4716 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4717 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 4718 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4719 | __ mov_b(operand, value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4720 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4721 | case EXTERNAL_SHORT_ELEMENTS: |
| 4722 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4723 | __ mov_w(operand, value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4724 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4725 | case EXTERNAL_INT_ELEMENTS: |
| 4726 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4727 | __ mov(operand, value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4728 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4729 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4730 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4731 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4732 | case FAST_ELEMENTS: |
| 4733 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4734 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4735 | case FAST_HOLEY_ELEMENTS: |
| 4736 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4737 | case DICTIONARY_ELEMENTS: |
| 4738 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4739 | UNREACHABLE(); |
| 4740 | break; |
| 4741 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4742 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4746 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4747 | ExternalReference canonical_nan_reference = |
| 4748 | ExternalReference::address_of_canonical_non_hole_nan(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4749 | Operand double_store_operand = BuildFastArrayOperand( |
| 4750 | instr->elements(), |
| 4751 | instr->key(), |
| 4752 | instr->hydrogen()->key()->representation(), |
| 4753 | FAST_DOUBLE_ELEMENTS, |
| 4754 | FixedDoubleArray::kHeaderSize - kHeapObjectTag, |
| 4755 | instr->additional_index()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4756 | |
| 4757 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 4758 | CpuFeatureScope scope(masm(), SSE2); |
| 4759 | XMMRegister value = ToDoubleRegister(instr->value()); |
| 4760 | |
| 4761 | if (instr->NeedsCanonicalization()) { |
| 4762 | Label have_value; |
| 4763 | |
| 4764 | __ ucomisd(value, value); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4765 | __ j(parity_odd, &have_value, Label::kNear); // NaN. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4766 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4767 | __ movsd(value, Operand::StaticVariable(canonical_nan_reference)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4768 | __ bind(&have_value); |
| 4769 | } |
| 4770 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4771 | __ movsd(double_store_operand, value); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4772 | } else { |
| 4773 | // Can't use SSE2 in the serializer |
| 4774 | if (instr->hydrogen()->IsConstantHoleStore()) { |
| 4775 | // This means we should store the (double) hole. No floating point |
| 4776 | // registers required. |
| 4777 | double nan_double = FixedDoubleArray::hole_nan_as_double(); |
| 4778 | uint64_t int_val = BitCast<uint64_t, double>(nan_double); |
| 4779 | int32_t lower = static_cast<int32_t>(int_val); |
| 4780 | int32_t upper = static_cast<int32_t>(int_val >> (kBitsPerInt)); |
| 4781 | |
| 4782 | __ mov(double_store_operand, Immediate(lower)); |
| 4783 | Operand double_store_operand2 = BuildFastArrayOperand( |
| 4784 | instr->elements(), |
| 4785 | instr->key(), |
| 4786 | instr->hydrogen()->key()->representation(), |
| 4787 | FAST_DOUBLE_ELEMENTS, |
| 4788 | FixedDoubleArray::kHeaderSize - kHeapObjectTag + kPointerSize, |
| 4789 | instr->additional_index()); |
| 4790 | __ mov(double_store_operand2, Immediate(upper)); |
| 4791 | } else { |
| 4792 | Label no_special_nan_handling; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 4793 | X87Register value = ToX87Register(instr->value()); |
| 4794 | X87Fxch(value); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4795 | |
| 4796 | if (instr->NeedsCanonicalization()) { |
| 4797 | __ fld(0); |
| 4798 | __ fld(0); |
| 4799 | __ FCmp(); |
| 4800 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4801 | __ j(parity_odd, &no_special_nan_handling, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4802 | __ sub(esp, Immediate(kDoubleSize)); |
| 4803 | __ fst_d(MemOperand(esp, 0)); |
| 4804 | __ cmp(MemOperand(esp, sizeof(kHoleNanLower32)), |
| 4805 | Immediate(kHoleNanUpper32)); |
| 4806 | __ add(esp, Immediate(kDoubleSize)); |
| 4807 | Label canonicalize; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4808 | __ j(not_equal, &canonicalize, Label::kNear); |
| 4809 | __ jmp(&no_special_nan_handling, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4810 | __ bind(&canonicalize); |
| 4811 | __ fstp(0); |
| 4812 | __ fld_d(Operand::StaticVariable(canonical_nan_reference)); |
| 4813 | } |
| 4814 | |
| 4815 | __ bind(&no_special_nan_handling); |
| 4816 | __ fst_d(double_store_operand); |
| 4817 | } |
| 4818 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | |
| 4822 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4823 | Register elements = ToRegister(instr->elements()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4824 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 4825 | |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4826 | Operand operand = BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4827 | instr->elements(), |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4828 | instr->key(), |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4829 | instr->hydrogen()->key()->representation(), |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4830 | FAST_ELEMENTS, |
| 4831 | FixedArray::kHeaderSize - kHeapObjectTag, |
| 4832 | instr->additional_index()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4833 | if (instr->value()->IsRegister()) { |
| 4834 | __ mov(operand, ToRegister(instr->value())); |
| 4835 | } else { |
| 4836 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4837 | if (IsSmi(operand_value)) { |
| 4838 | Immediate immediate = ToImmediate(operand_value, Representation::Smi()); |
| 4839 | __ mov(operand, immediate); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4840 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4841 | ASSERT(!IsInteger32(operand_value)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4842 | Handle<Object> handle_value = ToHandle(operand_value); |
| 4843 | __ mov(operand, handle_value); |
| 4844 | } |
| 4845 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4846 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4847 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4848 | ASSERT(instr->value()->IsRegister()); |
| 4849 | Register value = ToRegister(instr->value()); |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4850 | ASSERT(!instr->key()->IsConstantOperand()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4851 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4852 | instr->hydrogen()->value()->IsHeapObject() |
| 4853 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4854 | // Compute address of modified element and store it into key register. |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4855 | __ lea(key, operand); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4856 | __ RecordWrite(elements, |
| 4857 | key, |
| 4858 | value, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4859 | GetSaveFPRegsMode(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4860 | EMIT_REMEMBERED_SET, |
| 4861 | check_needed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4862 | } |
| 4863 | } |
| 4864 | |
| 4865 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4866 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4867 | // By cases...external, fast-double, fast |
| 4868 | if (instr->is_external()) { |
| 4869 | DoStoreKeyedExternalArray(instr); |
| 4870 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4871 | DoStoreKeyedFixedDoubleArray(instr); |
| 4872 | } else { |
| 4873 | DoStoreKeyedFixedArray(instr); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4874 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4878 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4879 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4880 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 4881 | ASSERT(ToRegister(instr->key()).is(ecx)); |
| 4882 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 4883 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4884 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4885 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4886 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4887 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4891 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4892 | Register object = ToRegister(instr->object()); |
| 4893 | Register temp = ToRegister(instr->temp()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4894 | Label no_memento_found; |
| 4895 | __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4896 | DeoptimizeIf(equal, instr->environment()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4897 | __ bind(&no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4901 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4902 | Register object_reg = ToRegister(instr->object()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4903 | |
| 4904 | Handle<Map> from_map = instr->original_map(); |
| 4905 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4906 | ElementsKind from_kind = instr->from_kind(); |
| 4907 | ElementsKind to_kind = instr->to_kind(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4908 | |
| 4909 | Label not_applicable; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4910 | bool is_simple_map_transition = |
| 4911 | IsSimpleMapChangeTransition(from_kind, to_kind); |
| 4912 | Label::Distance branch_distance = |
| 4913 | is_simple_map_transition ? Label::kNear : Label::kFar; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4914 | __ cmp(FieldOperand(object_reg, HeapObject::kMapOffset), from_map); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4915 | __ j(not_equal, ¬_applicable, branch_distance); |
| 4916 | if (is_simple_map_transition) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4917 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4918 | __ mov(FieldOperand(object_reg, HeapObject::kMapOffset), |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4919 | Immediate(to_map)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4920 | // Write barrier. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4921 | ASSERT_NE(instr->temp(), NULL); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4922 | __ RecordWriteForMap(object_reg, to_map, new_map_reg, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4923 | ToRegister(instr->temp()), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4924 | kDontSaveFPRegs); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4925 | } else { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4926 | PushSafepointRegistersScope scope(this); |
| 4927 | if (!object_reg.is(eax)) { |
| 4928 | __ push(object_reg); |
| 4929 | } |
| 4930 | LoadContextFromDeferred(instr->context()); |
| 4931 | if (!object_reg.is(eax)) { |
| 4932 | __ pop(eax); |
| 4933 | } |
| 4934 | __ mov(ebx, to_map); |
| 4935 | TransitionElementsKindStub stub(from_kind, to_kind); |
| 4936 | __ CallStub(&stub); |
| 4937 | RecordSafepointWithRegisters( |
| 4938 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4939 | } |
| 4940 | __ bind(¬_applicable); |
| 4941 | } |
| 4942 | |
| 4943 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4944 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4945 | class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4946 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4947 | DeferredStringCharCodeAt(LCodeGen* codegen, |
| 4948 | LStringCharCodeAt* instr, |
| 4949 | const X87Stack& x87_stack) |
| 4950 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4951 | virtual void Generate() V8_OVERRIDE { |
| 4952 | codegen()->DoDeferredStringCharCodeAt(instr_); |
| 4953 | } |
| 4954 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4955 | private: |
| 4956 | LStringCharCodeAt* instr_; |
| 4957 | }; |
| 4958 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4959 | DeferredStringCharCodeAt* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4960 | new(zone()) DeferredStringCharCodeAt(this, instr, x87_stack_); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4961 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4962 | StringCharLoadGenerator::Generate(masm(), |
| 4963 | factory(), |
| 4964 | ToRegister(instr->string()), |
| 4965 | ToRegister(instr->index()), |
| 4966 | ToRegister(instr->result()), |
| 4967 | deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4968 | __ bind(deferred->exit()); |
| 4969 | } |
| 4970 | |
| 4971 | |
| 4972 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4973 | Register string = ToRegister(instr->string()); |
| 4974 | Register result = ToRegister(instr->result()); |
| 4975 | |
| 4976 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4977 | // result register contain a valid pointer because it is already |
| 4978 | // contained in the register pointer map. |
| 4979 | __ Set(result, Immediate(0)); |
| 4980 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4981 | PushSafepointRegistersScope scope(this); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4982 | __ push(string); |
| 4983 | // Push the index as a smi. This is safe because of the checks in |
| 4984 | // DoStringCharCodeAt above. |
| 4985 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 4986 | if (instr->index()->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4987 | Immediate immediate = ToImmediate(LConstantOperand::cast(instr->index()), |
| 4988 | Representation::Smi()); |
| 4989 | __ push(immediate); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4990 | } else { |
| 4991 | Register index = ToRegister(instr->index()); |
| 4992 | __ SmiTag(index); |
| 4993 | __ push(index); |
| 4994 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4995 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAt, 2, |
| 4996 | instr, instr->context()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4997 | __ AssertSmi(eax); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4998 | __ SmiUntag(eax); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4999 | __ StoreToSafepointRegisterSlot(result, eax); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5003 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5004 | class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5005 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5006 | DeferredStringCharFromCode(LCodeGen* codegen, |
| 5007 | LStringCharFromCode* instr, |
| 5008 | const X87Stack& x87_stack) |
| 5009 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5010 | virtual void Generate() V8_OVERRIDE { |
| 5011 | codegen()->DoDeferredStringCharFromCode(instr_); |
| 5012 | } |
| 5013 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5014 | private: |
| 5015 | LStringCharFromCode* instr_; |
| 5016 | }; |
| 5017 | |
| 5018 | DeferredStringCharFromCode* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5019 | new(zone()) DeferredStringCharFromCode(this, instr, x87_stack_); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5020 | |
| 5021 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 5022 | Register char_code = ToRegister(instr->char_code()); |
| 5023 | Register result = ToRegister(instr->result()); |
| 5024 | ASSERT(!char_code.is(result)); |
| 5025 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5026 | __ cmp(char_code, String::kMaxOneByteCharCode); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5027 | __ j(above, deferred->entry()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5028 | __ Set(result, Immediate(factory()->single_character_string_cache())); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5029 | __ mov(result, FieldOperand(result, |
| 5030 | char_code, times_pointer_size, |
| 5031 | FixedArray::kHeaderSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5032 | __ cmp(result, factory()->undefined_value()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5033 | __ j(equal, deferred->entry()); |
| 5034 | __ bind(deferred->exit()); |
| 5035 | } |
| 5036 | |
| 5037 | |
| 5038 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 5039 | Register char_code = ToRegister(instr->char_code()); |
| 5040 | Register result = ToRegister(instr->result()); |
| 5041 | |
| 5042 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5043 | // result register contain a valid pointer because it is already |
| 5044 | // contained in the register pointer map. |
| 5045 | __ Set(result, Immediate(0)); |
| 5046 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5047 | PushSafepointRegistersScope scope(this); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5048 | __ SmiTag(char_code); |
| 5049 | __ push(char_code); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5050 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5051 | __ StoreToSafepointRegisterSlot(result, eax); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5055 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5056 | ASSERT(ToRegister(instr->context()).is(esi)); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 5057 | if (FLAG_new_string_add) { |
| 5058 | ASSERT(ToRegister(instr->left()).is(edx)); |
| 5059 | ASSERT(ToRegister(instr->right()).is(eax)); |
| 5060 | NewStringAddStub stub(instr->hydrogen()->flags(), |
| 5061 | isolate()->heap()->GetPretenureMode()); |
| 5062 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 5063 | } else { |
| 5064 | EmitPushTaggedOperand(instr->left()); |
| 5065 | EmitPushTaggedOperand(instr->right()); |
| 5066 | StringAddStub stub(instr->hydrogen()->flags()); |
| 5067 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 5068 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5072 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5073 | LOperand* input = instr->value(); |
| 5074 | LOperand* output = instr->result(); |
| 5075 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 5076 | ASSERT(output->IsDoubleRegister()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5077 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5078 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5079 | __ Cvtsi2sd(ToDoubleRegister(output), ToOperand(input)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5080 | } else if (input->IsRegister()) { |
| 5081 | Register input_reg = ToRegister(input); |
| 5082 | __ push(input_reg); |
| 5083 | X87Mov(ToX87Register(output), Operand(esp, 0), kX87IntOperand); |
| 5084 | __ pop(input_reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5085 | } else { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5086 | X87Mov(ToX87Register(output), ToOperand(input), kX87IntOperand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5087 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5091 | void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) { |
| 5092 | Register input = ToRegister(instr->value()); |
| 5093 | __ SmiTag(input); |
| 5094 | if (!instr->hydrogen()->value()->HasRange() || |
| 5095 | !instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 5096 | DeoptimizeIf(overflow, instr->environment()); |
| 5097 | } |
| 5098 | } |
| 5099 | |
| 5100 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5101 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5102 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5103 | LOperand* output = instr->result(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 5104 | if (CpuFeatures::IsSupported(SSE2)) { |
| 5105 | CpuFeatureScope scope(masm(), SSE2); |
| 5106 | LOperand* temp = instr->temp(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5107 | |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 5108 | __ LoadUint32(ToDoubleRegister(output), |
| 5109 | ToRegister(input), |
| 5110 | ToDoubleRegister(temp)); |
| 5111 | } else { |
| 5112 | X87Register res = ToX87Register(output); |
| 5113 | X87PrepareToWrite(res); |
| 5114 | __ LoadUint32NoSSE2(ToRegister(input)); |
| 5115 | X87CommitWrite(res); |
| 5116 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | |
machenbach@chromium.org | ed29eb2 | 2013-10-31 13:30:00 +0000 | [diff] [blame] | 5120 | void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) { |
| 5121 | Register input = ToRegister(instr->value()); |
| 5122 | if (!instr->hydrogen()->value()->HasRange() || |
| 5123 | !instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 5124 | __ test(input, Immediate(0xc0000000)); |
| 5125 | DeoptimizeIf(not_zero, instr->environment()); |
| 5126 | } |
| 5127 | __ SmiTag(input); |
| 5128 | } |
| 5129 | |
| 5130 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5131 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5132 | class DeferredNumberTagI V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5133 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5134 | DeferredNumberTagI(LCodeGen* codegen, |
| 5135 | LNumberTagI* instr, |
| 5136 | const X87Stack& x87_stack) |
| 5137 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5138 | virtual void Generate() V8_OVERRIDE { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5139 | codegen()->DoDeferredNumberTagI(instr_, instr_->value(), SIGNED_INT32); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5140 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5141 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5142 | private: |
| 5143 | LNumberTagI* instr_; |
| 5144 | }; |
| 5145 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5146 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5147 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5148 | Register reg = ToRegister(input); |
| 5149 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5150 | DeferredNumberTagI* deferred = |
| 5151 | new(zone()) DeferredNumberTagI(this, instr, x87_stack_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5152 | __ SmiTag(reg); |
| 5153 | __ j(overflow, deferred->entry()); |
| 5154 | __ bind(deferred->exit()); |
| 5155 | } |
| 5156 | |
| 5157 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5158 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5159 | class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5160 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5161 | DeferredNumberTagU(LCodeGen* codegen, |
| 5162 | LNumberTagU* instr, |
| 5163 | const X87Stack& x87_stack) |
| 5164 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5165 | virtual void Generate() V8_OVERRIDE { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5166 | codegen()->DoDeferredNumberTagI(instr_, instr_->value(), UNSIGNED_INT32); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5167 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5168 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5169 | private: |
| 5170 | LNumberTagU* instr_; |
| 5171 | }; |
| 5172 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5173 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5174 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5175 | Register reg = ToRegister(input); |
| 5176 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5177 | DeferredNumberTagU* deferred = |
| 5178 | new(zone()) DeferredNumberTagU(this, instr, x87_stack_); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5179 | __ cmp(reg, Immediate(Smi::kMaxValue)); |
| 5180 | __ j(above, deferred->entry()); |
| 5181 | __ SmiTag(reg); |
| 5182 | __ bind(deferred->exit()); |
| 5183 | } |
| 5184 | |
| 5185 | |
| 5186 | void LCodeGen::DoDeferredNumberTagI(LInstruction* instr, |
| 5187 | LOperand* value, |
| 5188 | IntegerSignedness signedness) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5189 | Label slow; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5190 | Register reg = ToRegister(value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5191 | Register tmp = reg.is(eax) ? ecx : eax; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5192 | XMMRegister xmm_scratch = double_scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5193 | |
| 5194 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5195 | PushSafepointRegistersScope scope(this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5196 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5197 | Label done; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5198 | |
| 5199 | if (signedness == SIGNED_INT32) { |
| 5200 | // There was overflow, so bits 30 and 31 of the original integer |
| 5201 | // disagree. Try to allocate a heap number in new space and store |
| 5202 | // the value in there. If that fails, call the runtime system. |
| 5203 | __ SmiUntag(reg); |
| 5204 | __ xor_(reg, 0x80000000); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5205 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5206 | CpuFeatureScope feature_scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5207 | __ Cvtsi2sd(xmm_scratch, Operand(reg)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5208 | } else { |
| 5209 | __ push(reg); |
| 5210 | __ fild_s(Operand(esp, 0)); |
| 5211 | __ pop(reg); |
| 5212 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5213 | } else { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5214 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5215 | CpuFeatureScope feature_scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5216 | __ LoadUint32(xmm_scratch, reg, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5217 | ToDoubleRegister(LNumberTagU::cast(instr)->temp())); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5218 | } else { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5219 | // There's no fild variant for unsigned values, so zero-extend to a 64-bit |
| 5220 | // int manually. |
| 5221 | __ push(Immediate(0)); |
| 5222 | __ push(reg); |
| 5223 | __ fild_d(Operand(esp, 0)); |
| 5224 | __ pop(reg); |
| 5225 | __ pop(reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5226 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5229 | if (FLAG_inline_new) { |
| 5230 | __ AllocateHeapNumber(reg, tmp, no_reg, &slow); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5231 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | // Slow case: Call the runtime system to do the number allocation. |
| 5235 | __ bind(&slow); |
| 5236 | |
| 5237 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 5238 | // register is stored, as this register is in the pointer map, but contains an |
| 5239 | // integer value. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5240 | __ StoreToSafepointRegisterSlot(reg, Immediate(0)); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5241 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 5242 | // the environment's HContext or HInlinedContext value. |
| 5243 | // They only call Runtime::kAllocateHeapNumber. |
| 5244 | // The corresponding HChange instructions are added in a phase that does |
| 5245 | // not have easy access to the local context. |
| 5246 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 5247 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 5248 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5249 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5250 | if (!reg.is(eax)) __ mov(reg, eax); |
| 5251 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5252 | // Done. Put the value in xmm_scratch into the value of the allocated heap |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5253 | // number. |
| 5254 | __ bind(&done); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5255 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5256 | CpuFeatureScope feature_scope(masm(), SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5257 | __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), xmm_scratch); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5258 | } else { |
| 5259 | __ fstp_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
| 5260 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5261 | __ StoreToSafepointRegisterSlot(reg, reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | |
| 5265 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5266 | class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5267 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5268 | DeferredNumberTagD(LCodeGen* codegen, |
| 5269 | LNumberTagD* instr, |
| 5270 | const X87Stack& x87_stack) |
| 5271 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5272 | virtual void Generate() V8_OVERRIDE { |
| 5273 | codegen()->DoDeferredNumberTagD(instr_); |
| 5274 | } |
| 5275 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5276 | private: |
| 5277 | LNumberTagD* instr_; |
| 5278 | }; |
| 5279 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5280 | Register reg = ToRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5281 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5282 | bool use_sse2 = CpuFeatures::IsSupported(SSE2); |
| 5283 | if (!use_sse2) { |
| 5284 | // Put the value to the top of stack |
| 5285 | X87Register src = ToX87Register(instr->value()); |
| 5286 | X87LoadForUsage(src); |
| 5287 | } |
| 5288 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5289 | DeferredNumberTagD* deferred = |
| 5290 | new(zone()) DeferredNumberTagD(this, instr, x87_stack_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5291 | if (FLAG_inline_new) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5292 | Register tmp = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5293 | __ AllocateHeapNumber(reg, tmp, no_reg, deferred->entry()); |
| 5294 | } else { |
| 5295 | __ jmp(deferred->entry()); |
| 5296 | } |
| 5297 | __ bind(deferred->exit()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5298 | if (use_sse2) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5299 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5300 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5301 | __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), input_reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5302 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5303 | __ fstp_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5304 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | |
| 5308 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 5309 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5310 | // result register contain a valid pointer because it is already |
| 5311 | // contained in the register pointer map. |
| 5312 | Register reg = ToRegister(instr->result()); |
| 5313 | __ Set(reg, Immediate(0)); |
| 5314 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5315 | PushSafepointRegistersScope scope(this); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5316 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 5317 | // the environment's HContext or HInlinedContext value. |
| 5318 | // They only call Runtime::kAllocateHeapNumber. |
| 5319 | // The corresponding HChange instructions are added in a phase that does |
| 5320 | // not have easy access to the local context. |
| 5321 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 5322 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5323 | RecordSafepointWithRegisters( |
| 5324 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5325 | __ StoreToSafepointRegisterSlot(reg, eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | |
| 5329 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5330 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5331 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5332 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
| 5333 | __ SmiTag(ToRegister(input)); |
| 5334 | } |
| 5335 | |
| 5336 | |
| 5337 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5338 | LOperand* input = instr->value(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5339 | Register result = ToRegister(input); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5340 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5341 | if (instr->needs_check()) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5342 | __ test(result, Immediate(kSmiTagMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5343 | DeoptimizeIf(not_zero, instr->environment()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5344 | } else { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5345 | __ AssertSmi(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5346 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5347 | __ SmiUntag(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5351 | void LCodeGen::EmitNumberUntagDNoSSE2(Register input_reg, |
| 5352 | Register temp_reg, |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5353 | X87Register res_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5354 | bool can_convert_undefined_to_nan, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5355 | bool deoptimize_on_minus_zero, |
| 5356 | LEnvironment* env, |
| 5357 | NumberUntagDMode mode) { |
| 5358 | Label load_smi, done; |
| 5359 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5360 | X87PrepareToWrite(res_reg); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5361 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5362 | // Smi check. |
| 5363 | __ JumpIfSmi(input_reg, &load_smi, Label::kNear); |
| 5364 | |
| 5365 | // Heap number map check. |
| 5366 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5367 | factory()->heap_number_map()); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5368 | if (!can_convert_undefined_to_nan) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5369 | DeoptimizeIf(not_equal, env); |
| 5370 | } else { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5371 | Label heap_number, convert; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5372 | __ j(equal, &heap_number, Label::kNear); |
| 5373 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5374 | // Convert undefined (or hole) to NaN. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5375 | __ cmp(input_reg, factory()->undefined_value()); |
| 5376 | DeoptimizeIf(not_equal, env); |
| 5377 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5378 | __ bind(&convert); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5379 | ExternalReference nan = |
| 5380 | ExternalReference::address_of_canonical_non_hole_nan(); |
| 5381 | __ fld_d(Operand::StaticVariable(nan)); |
| 5382 | __ jmp(&done, Label::kNear); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5383 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5384 | __ bind(&heap_number); |
| 5385 | } |
| 5386 | // Heap number to x87 conversion. |
| 5387 | __ fld_d(FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 5388 | if (deoptimize_on_minus_zero) { |
| 5389 | __ fldz(); |
| 5390 | __ FCmp(); |
| 5391 | __ fld_d(FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 5392 | __ j(not_zero, &done, Label::kNear); |
| 5393 | |
| 5394 | // Use general purpose registers to check if we have -0.0 |
| 5395 | __ mov(temp_reg, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 5396 | __ test(temp_reg, Immediate(HeapNumber::kSignMask)); |
| 5397 | __ j(zero, &done, Label::kNear); |
| 5398 | |
| 5399 | // Pop FPU stack before deoptimizing. |
| 5400 | __ fstp(0); |
| 5401 | DeoptimizeIf(not_zero, env); |
| 5402 | } |
| 5403 | __ jmp(&done, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5404 | } else { |
| 5405 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
| 5406 | } |
| 5407 | |
| 5408 | __ bind(&load_smi); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5409 | // Clobbering a temp is faster than re-tagging the |
| 5410 | // input register since we avoid dependencies. |
| 5411 | __ mov(temp_reg, input_reg); |
| 5412 | __ SmiUntag(temp_reg); // Untag smi before converting to float. |
| 5413 | __ push(temp_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5414 | __ fild_s(Operand(esp, 0)); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5415 | __ add(esp, Immediate(kPointerSize)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5416 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5417 | X87CommitWrite(res_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5421 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5422 | Register temp_reg, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5423 | XMMRegister result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5424 | bool can_convert_undefined_to_nan, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5425 | bool deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5426 | LEnvironment* env, |
| 5427 | NumberUntagDMode mode) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5428 | Label convert, load_smi, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5429 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5430 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5431 | // Smi check. |
| 5432 | __ JumpIfSmi(input_reg, &load_smi, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5433 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5434 | // Heap number map check. |
| 5435 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5436 | factory()->heap_number_map()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5437 | if (can_convert_undefined_to_nan) { |
| 5438 | __ j(not_equal, &convert, Label::kNear); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 5439 | } else { |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 5440 | DeoptimizeIf(not_equal, env); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 5441 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5442 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5443 | // Heap number to XMM conversion. |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5444 | __ movsd(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5445 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5446 | if (deoptimize_on_minus_zero) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5447 | XMMRegister xmm_scratch = double_scratch0(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5448 | __ xorps(xmm_scratch, xmm_scratch); |
| 5449 | __ ucomisd(result_reg, xmm_scratch); |
| 5450 | __ j(not_zero, &done, Label::kNear); |
| 5451 | __ movmskpd(temp_reg, result_reg); |
| 5452 | __ test_b(temp_reg, 1); |
| 5453 | DeoptimizeIf(not_zero, env); |
| 5454 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5455 | __ jmp(&done, Label::kNear); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5456 | |
| 5457 | if (can_convert_undefined_to_nan) { |
| 5458 | __ bind(&convert); |
| 5459 | |
| 5460 | // Convert undefined (and hole) to NaN. |
| 5461 | __ cmp(input_reg, factory()->undefined_value()); |
| 5462 | DeoptimizeIf(not_equal, env); |
| 5463 | |
| 5464 | ExternalReference nan = |
| 5465 | ExternalReference::address_of_canonical_non_hole_nan(); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5466 | __ movsd(result_reg, Operand::StaticVariable(nan)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5467 | __ jmp(&done, Label::kNear); |
| 5468 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5469 | } else { |
| 5470 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5471 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5472 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5473 | __ bind(&load_smi); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5474 | // Smi to XMM conversion. Clobbering a temp is faster than re-tagging the |
| 5475 | // input register since we avoid dependencies. |
| 5476 | __ mov(temp_reg, input_reg); |
| 5477 | __ SmiUntag(temp_reg); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5478 | __ Cvtsi2sd(result_reg, Operand(temp_reg)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5479 | __ bind(&done); |
| 5480 | } |
| 5481 | |
| 5482 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5483 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, Label* done) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5484 | Register input_reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5485 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5486 | if (instr->truncating()) { |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 5487 | Label no_heap_number, check_bools, check_false; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5488 | |
| 5489 | // Heap number map check. |
| 5490 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5491 | factory()->heap_number_map()); |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 5492 | __ j(not_equal, &no_heap_number, Label::kNear); |
| 5493 | __ TruncateHeapNumberToI(input_reg, input_reg); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5494 | __ jmp(done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5495 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 5496 | __ bind(&no_heap_number); |
| 5497 | // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 5498 | // for truncating conversions. |
| 5499 | __ cmp(input_reg, factory()->undefined_value()); |
| 5500 | __ j(not_equal, &check_bools, Label::kNear); |
| 5501 | __ Set(input_reg, Immediate(0)); |
| 5502 | __ jmp(done); |
| 5503 | |
| 5504 | __ bind(&check_bools); |
| 5505 | __ cmp(input_reg, factory()->true_value()); |
| 5506 | __ j(not_equal, &check_false, Label::kNear); |
| 5507 | __ Set(input_reg, Immediate(1)); |
| 5508 | __ jmp(done); |
| 5509 | |
| 5510 | __ bind(&check_false); |
| 5511 | __ cmp(input_reg, factory()->false_value()); |
| 5512 | __ RecordComment("Deferred TaggedToI: cannot truncate"); |
| 5513 | DeoptimizeIf(not_equal, instr->environment()); |
| 5514 | __ Set(input_reg, Immediate(0)); |
| 5515 | __ jmp(done); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5516 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5517 | Label bailout; |
| 5518 | XMMRegister scratch = (instr->temp() != NULL) |
| 5519 | ? ToDoubleRegister(instr->temp()) |
| 5520 | : no_xmm_reg; |
| 5521 | __ TaggedToI(input_reg, input_reg, scratch, |
| 5522 | instr->hydrogen()->GetMinusZeroMode(), &bailout); |
| 5523 | __ jmp(done); |
| 5524 | __ bind(&bailout); |
| 5525 | DeoptimizeIf(no_condition, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5526 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | |
| 5530 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5531 | class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5532 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5533 | DeferredTaggedToI(LCodeGen* codegen, |
| 5534 | LTaggedToI* instr, |
| 5535 | const X87Stack& x87_stack) |
| 5536 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5537 | virtual void Generate() V8_OVERRIDE { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5538 | codegen()->DoDeferredTaggedToI(instr_, done()); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5539 | } |
| 5540 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5541 | private: |
| 5542 | LTaggedToI* instr_; |
| 5543 | }; |
| 5544 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5545 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5546 | ASSERT(input->IsRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5547 | Register input_reg = ToRegister(input); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5548 | ASSERT(input_reg.is(ToRegister(instr->result()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5549 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5550 | if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 5551 | __ SmiUntag(input_reg); |
| 5552 | } else { |
| 5553 | DeferredTaggedToI* deferred = |
| 5554 | new(zone()) DeferredTaggedToI(this, instr, x87_stack_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5555 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5556 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 5557 | __ SmiUntag(input_reg); |
| 5558 | __ bind(deferred->exit()); |
| 5559 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5563 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5564 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5565 | ASSERT(input->IsRegister()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5566 | LOperand* temp = instr->temp(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5567 | ASSERT(temp->IsRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5568 | LOperand* result = instr->result(); |
| 5569 | ASSERT(result->IsDoubleRegister()); |
| 5570 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5571 | Register input_reg = ToRegister(input); |
| 5572 | bool deoptimize_on_minus_zero = |
| 5573 | instr->hydrogen()->deoptimize_on_minus_zero(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5574 | Register temp_reg = ToRegister(temp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5575 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5576 | HValue* value = instr->hydrogen()->value(); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5577 | NumberUntagDMode mode = value->representation().IsSmi() |
| 5578 | ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5579 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5580 | if (CpuFeatures::IsSupported(SSE2)) { |
| 5581 | CpuFeatureScope scope(masm(), SSE2); |
| 5582 | XMMRegister result_reg = ToDoubleRegister(result); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5583 | EmitNumberUntagD(input_reg, |
| 5584 | temp_reg, |
| 5585 | result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5586 | instr->hydrogen()->can_convert_undefined_to_nan(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5587 | deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5588 | instr->environment(), |
| 5589 | mode); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5590 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5591 | EmitNumberUntagDNoSSE2(input_reg, |
| 5592 | temp_reg, |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5593 | ToX87Register(instr->result()), |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5594 | instr->hydrogen()->can_convert_undefined_to_nan(), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5595 | deoptimize_on_minus_zero, |
| 5596 | instr->environment(), |
| 5597 | mode); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5598 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | |
| 5602 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5603 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5604 | ASSERT(input->IsDoubleRegister()); |
| 5605 | LOperand* result = instr->result(); |
| 5606 | ASSERT(result->IsRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5607 | Register result_reg = ToRegister(result); |
| 5608 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5609 | if (instr->truncating()) { |
| 5610 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 5611 | CpuFeatureScope scope(masm(), SSE2); |
| 5612 | XMMRegister input_reg = ToDoubleRegister(input); |
| 5613 | __ TruncateDoubleToI(result_reg, input_reg); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5614 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5615 | X87Register input_reg = ToX87Register(input); |
| 5616 | X87Fxch(input_reg); |
| 5617 | __ TruncateX87TOSToI(result_reg); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5618 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5619 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5620 | Label bailout, done; |
| 5621 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 5622 | CpuFeatureScope scope(masm(), SSE2); |
| 5623 | XMMRegister input_reg = ToDoubleRegister(input); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5624 | XMMRegister xmm_scratch = double_scratch0(); |
| 5625 | __ DoubleToI(result_reg, input_reg, xmm_scratch, |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5626 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5627 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5628 | X87Register input_reg = ToX87Register(input); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5629 | X87Fxch(input_reg); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5630 | __ X87TOSToI(result_reg, instr->hydrogen()->GetMinusZeroMode(), |
| 5631 | &bailout, Label::kNear); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5632 | } |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5633 | __ jmp(&done, Label::kNear); |
| 5634 | __ bind(&bailout); |
| 5635 | DeoptimizeIf(no_condition, instr->environment()); |
| 5636 | __ bind(&done); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5637 | } |
| 5638 | } |
| 5639 | |
| 5640 | |
| 5641 | void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 5642 | LOperand* input = instr->value(); |
| 5643 | ASSERT(input->IsDoubleRegister()); |
| 5644 | LOperand* result = instr->result(); |
| 5645 | ASSERT(result->IsRegister()); |
| 5646 | Register result_reg = ToRegister(result); |
| 5647 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5648 | Label bailout, done; |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5649 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 5650 | CpuFeatureScope scope(masm(), SSE2); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5651 | XMMRegister input_reg = ToDoubleRegister(input); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5652 | XMMRegister xmm_scratch = double_scratch0(); |
| 5653 | __ DoubleToI(result_reg, input_reg, xmm_scratch, |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5654 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5655 | } else { |
| 5656 | X87Register input_reg = ToX87Register(input); |
| 5657 | X87Fxch(input_reg); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5658 | __ X87TOSToI(result_reg, instr->hydrogen()->GetMinusZeroMode(), |
| 5659 | &bailout, Label::kNear); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5660 | } |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5661 | __ jmp(&done, Label::kNear); |
| 5662 | __ bind(&bailout); |
| 5663 | DeoptimizeIf(no_condition, instr->environment()); |
| 5664 | __ bind(&done); |
| 5665 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5666 | __ SmiTag(result_reg); |
| 5667 | DeoptimizeIf(overflow, instr->environment()); |
| 5668 | } |
| 5669 | |
| 5670 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5671 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5672 | LOperand* input = instr->value(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5673 | __ test(ToOperand(input), Immediate(kSmiTagMask)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5674 | DeoptimizeIf(not_zero, instr->environment()); |
| 5675 | } |
| 5676 | |
| 5677 | |
| 5678 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5679 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 5680 | LOperand* input = instr->value(); |
| 5681 | __ test(ToOperand(input), Immediate(kSmiTagMask)); |
| 5682 | DeoptimizeIf(zero, instr->environment()); |
| 5683 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | |
| 5687 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5688 | Register input = ToRegister(instr->value()); |
| 5689 | Register temp = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5690 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5691 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5692 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5693 | if (instr->hydrogen()->is_interval_check()) { |
| 5694 | InstanceType first; |
| 5695 | InstanceType last; |
| 5696 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5697 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5698 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 5699 | static_cast<int8_t>(first)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5700 | |
| 5701 | // If there is only one type in the interval check for equality. |
| 5702 | if (first == last) { |
| 5703 | DeoptimizeIf(not_equal, instr->environment()); |
| 5704 | } else { |
| 5705 | DeoptimizeIf(below, instr->environment()); |
| 5706 | // Omit check for the last type. |
| 5707 | if (last != LAST_TYPE) { |
| 5708 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 5709 | static_cast<int8_t>(last)); |
| 5710 | DeoptimizeIf(above, instr->environment()); |
| 5711 | } |
| 5712 | } |
| 5713 | } else { |
| 5714 | uint8_t mask; |
| 5715 | uint8_t tag; |
| 5716 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5717 | |
| 5718 | if (IsPowerOf2(mask)) { |
| 5719 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 5720 | __ test_b(FieldOperand(temp, Map::kInstanceTypeOffset), mask); |
| 5721 | DeoptimizeIf(tag == 0 ? not_zero : zero, instr->environment()); |
| 5722 | } else { |
| 5723 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5724 | __ and_(temp, mask); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5725 | __ cmp(temp, tag); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5726 | DeoptimizeIf(not_equal, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5727 | } |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5732 | void LCodeGen::DoCheckValue(LCheckValue* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5733 | Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5734 | if (instr->hydrogen()->object_in_new_space()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5735 | Register reg = ToRegister(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5736 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5737 | __ cmp(reg, Operand::ForCell(cell)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5738 | } else { |
| 5739 | Operand operand = ToOperand(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5740 | __ cmp(operand, object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5741 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5742 | DeoptimizeIf(not_equal, instr->environment()); |
| 5743 | } |
| 5744 | |
| 5745 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5746 | void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5747 | { |
| 5748 | PushSafepointRegistersScope scope(this); |
| 5749 | __ push(object); |
| 5750 | __ xor_(esi, esi); |
| 5751 | __ CallRuntimeSaveDoubles(Runtime::kMigrateInstance); |
| 5752 | RecordSafepointWithRegisters( |
| 5753 | instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); |
| 5754 | |
| 5755 | __ test(eax, Immediate(kSmiTagMask)); |
| 5756 | } |
| 5757 | DeoptimizeIf(zero, instr->environment()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5761 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5762 | class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5763 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5764 | DeferredCheckMaps(LCodeGen* codegen, |
| 5765 | LCheckMaps* instr, |
| 5766 | Register object, |
| 5767 | const X87Stack& x87_stack) |
| 5768 | : LDeferredCode(codegen, x87_stack), instr_(instr), object_(object) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5769 | SetExit(check_maps()); |
| 5770 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5771 | virtual void Generate() V8_OVERRIDE { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5772 | codegen()->DoDeferredInstanceMigration(instr_, object_); |
| 5773 | } |
| 5774 | Label* check_maps() { return &check_maps_; } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5775 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5776 | private: |
| 5777 | LCheckMaps* instr_; |
| 5778 | Label check_maps_; |
| 5779 | Register object_; |
| 5780 | }; |
| 5781 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5782 | if (instr->hydrogen()->CanOmitMapChecks()) return; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5783 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5784 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5785 | ASSERT(input->IsRegister()); |
| 5786 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5787 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5788 | DeferredCheckMaps* deferred = NULL; |
| 5789 | if (instr->hydrogen()->has_migration_target()) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5790 | deferred = new(zone()) DeferredCheckMaps(this, instr, reg, x87_stack_); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5791 | __ bind(deferred->check_maps()); |
| 5792 | } |
| 5793 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5794 | UniqueSet<Map> map_set = instr->hydrogen()->map_set(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5795 | Label success; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5796 | for (int i = 0; i < map_set.size() - 1; i++) { |
| 5797 | Handle<Map> map = map_set.at(i).handle(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5798 | __ CompareMap(reg, map); |
| 5799 | __ j(equal, &success, Label::kNear); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5800 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5801 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5802 | Handle<Map> map = map_set.at(map_set.size() - 1).handle(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5803 | __ CompareMap(reg, map); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5804 | if (instr->hydrogen()->has_migration_target()) { |
| 5805 | __ j(not_equal, deferred->entry()); |
| 5806 | } else { |
| 5807 | DeoptimizeIf(not_equal, instr->environment()); |
| 5808 | } |
| 5809 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5810 | __ bind(&success); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5814 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5815 | CpuFeatureScope scope(masm(), SSE2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5816 | XMMRegister value_reg = ToDoubleRegister(instr->unclamped()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5817 | XMMRegister xmm_scratch = double_scratch0(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5818 | Register result_reg = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5819 | __ ClampDoubleToUint8(value_reg, xmm_scratch, result_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | |
| 5823 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5824 | ASSERT(instr->unclamped()->Equals(instr->result())); |
| 5825 | Register value_reg = ToRegister(instr->result()); |
| 5826 | __ ClampUint8(value_reg); |
| 5827 | } |
| 5828 | |
| 5829 | |
| 5830 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5831 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5832 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5833 | ASSERT(instr->unclamped()->Equals(instr->result())); |
| 5834 | Register input_reg = ToRegister(instr->unclamped()); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5835 | XMMRegister temp_xmm_reg = ToDoubleRegister(instr->temp_xmm()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5836 | XMMRegister xmm_scratch = double_scratch0(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5837 | Label is_smi, done, heap_number; |
| 5838 | |
| 5839 | __ JumpIfSmi(input_reg, &is_smi); |
| 5840 | |
| 5841 | // Check for heap number |
| 5842 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5843 | factory()->heap_number_map()); |
| 5844 | __ j(equal, &heap_number, Label::kNear); |
| 5845 | |
| 5846 | // Check for undefined. Undefined is converted to zero for clamping |
| 5847 | // conversions. |
| 5848 | __ cmp(input_reg, factory()->undefined_value()); |
| 5849 | DeoptimizeIf(not_equal, instr->environment()); |
| 5850 | __ mov(input_reg, 0); |
| 5851 | __ jmp(&done, Label::kNear); |
| 5852 | |
| 5853 | // Heap number |
| 5854 | __ bind(&heap_number); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5855 | __ movsd(xmm_scratch, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5856 | __ ClampDoubleToUint8(xmm_scratch, temp_xmm_reg, input_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5857 | __ jmp(&done, Label::kNear); |
| 5858 | |
| 5859 | // smi |
| 5860 | __ bind(&is_smi); |
| 5861 | __ SmiUntag(input_reg); |
| 5862 | __ ClampUint8(input_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5863 | __ bind(&done); |
| 5864 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5865 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5866 | |
| 5867 | void LCodeGen::DoClampTToUint8NoSSE2(LClampTToUint8NoSSE2* instr) { |
| 5868 | Register input_reg = ToRegister(instr->unclamped()); |
| 5869 | Register result_reg = ToRegister(instr->result()); |
| 5870 | Register scratch = ToRegister(instr->scratch()); |
| 5871 | Register scratch2 = ToRegister(instr->scratch2()); |
| 5872 | Register scratch3 = ToRegister(instr->scratch3()); |
| 5873 | Label is_smi, done, heap_number, valid_exponent, |
| 5874 | largest_value, zero_result, maybe_nan_or_infinity; |
| 5875 | |
| 5876 | __ JumpIfSmi(input_reg, &is_smi); |
| 5877 | |
| 5878 | // Check for heap number |
| 5879 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5880 | factory()->heap_number_map()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5881 | __ j(equal, &heap_number, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5882 | |
| 5883 | // Check for undefined. Undefined is converted to zero for clamping |
| 5884 | // conversions. |
| 5885 | __ cmp(input_reg, factory()->undefined_value()); |
| 5886 | DeoptimizeIf(not_equal, instr->environment()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5887 | __ jmp(&zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5888 | |
| 5889 | // Heap number |
| 5890 | __ bind(&heap_number); |
| 5891 | |
| 5892 | // Surprisingly, all of the hand-crafted bit-manipulations below are much |
| 5893 | // faster than the x86 FPU built-in instruction, especially since "banker's |
| 5894 | // rounding" would be additionally very expensive |
| 5895 | |
| 5896 | // Get exponent word. |
| 5897 | __ mov(scratch, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 5898 | __ mov(scratch3, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
| 5899 | |
| 5900 | // Test for negative values --> clamp to zero |
| 5901 | __ test(scratch, scratch); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5902 | __ j(negative, &zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5903 | |
| 5904 | // Get exponent alone in scratch2. |
| 5905 | __ mov(scratch2, scratch); |
| 5906 | __ and_(scratch2, HeapNumber::kExponentMask); |
| 5907 | __ shr(scratch2, HeapNumber::kExponentShift); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5908 | __ j(zero, &zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5909 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias - 1)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5910 | __ j(negative, &zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5911 | |
| 5912 | const uint32_t non_int8_exponent = 7; |
| 5913 | __ cmp(scratch2, Immediate(non_int8_exponent + 1)); |
| 5914 | // If the exponent is too big, check for special values. |
| 5915 | __ j(greater, &maybe_nan_or_infinity, Label::kNear); |
| 5916 | |
| 5917 | __ bind(&valid_exponent); |
| 5918 | // Exponent word in scratch, exponent in scratch2. We know that 0 <= exponent |
| 5919 | // < 7. The shift bias is the number of bits to shift the mantissa such that |
| 5920 | // with an exponent of 7 such the that top-most one is in bit 30, allowing |
| 5921 | // detection the rounding overflow of a 255.5 to 256 (bit 31 goes from 0 to |
| 5922 | // 1). |
| 5923 | int shift_bias = (30 - HeapNumber::kExponentShift) - 7 - 1; |
| 5924 | __ lea(result_reg, MemOperand(scratch2, shift_bias)); |
| 5925 | // Here result_reg (ecx) is the shift, scratch is the exponent word. Get the |
| 5926 | // top bits of the mantissa. |
| 5927 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 5928 | // Put back the implicit 1 of the mantissa |
| 5929 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 5930 | // Shift up to round |
| 5931 | __ shl_cl(scratch); |
| 5932 | // Use "banker's rounding" to spec: If fractional part of number is 0.5, then |
| 5933 | // use the bit in the "ones" place and add it to the "halves" place, which has |
| 5934 | // the effect of rounding to even. |
| 5935 | __ mov(scratch2, scratch); |
| 5936 | const uint32_t one_half_bit_shift = 30 - sizeof(uint8_t) * 8; |
| 5937 | const uint32_t one_bit_shift = one_half_bit_shift + 1; |
| 5938 | __ and_(scratch2, Immediate((1 << one_bit_shift) - 1)); |
| 5939 | __ cmp(scratch2, Immediate(1 << one_half_bit_shift)); |
| 5940 | Label no_round; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5941 | __ j(less, &no_round, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5942 | Label round_up; |
| 5943 | __ mov(scratch2, Immediate(1 << one_half_bit_shift)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5944 | __ j(greater, &round_up, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5945 | __ test(scratch3, scratch3); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5946 | __ j(not_zero, &round_up, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5947 | __ mov(scratch2, scratch); |
| 5948 | __ and_(scratch2, Immediate(1 << one_bit_shift)); |
| 5949 | __ shr(scratch2, 1); |
| 5950 | __ bind(&round_up); |
| 5951 | __ add(scratch, scratch2); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5952 | __ j(overflow, &largest_value, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5953 | __ bind(&no_round); |
| 5954 | __ shr(scratch, 23); |
| 5955 | __ mov(result_reg, scratch); |
| 5956 | __ jmp(&done, Label::kNear); |
| 5957 | |
| 5958 | __ bind(&maybe_nan_or_infinity); |
| 5959 | // Check for NaN/Infinity, all other values map to 255 |
| 5960 | __ cmp(scratch2, Immediate(HeapNumber::kInfinityOrNanExponent + 1)); |
| 5961 | __ j(not_equal, &largest_value, Label::kNear); |
| 5962 | |
| 5963 | // Check for NaN, which differs from Infinity in that at least one mantissa |
| 5964 | // bit is set. |
| 5965 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 5966 | __ or_(scratch, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5967 | __ j(not_zero, &zero_result, Label::kNear); // M!=0 --> NaN |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5968 | // Infinity -> Fall through to map to 255. |
| 5969 | |
| 5970 | __ bind(&largest_value); |
| 5971 | __ mov(result_reg, Immediate(255)); |
| 5972 | __ jmp(&done, Label::kNear); |
| 5973 | |
| 5974 | __ bind(&zero_result); |
| 5975 | __ xor_(result_reg, result_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5976 | __ jmp(&done, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5977 | |
| 5978 | // smi |
| 5979 | __ bind(&is_smi); |
| 5980 | if (!input_reg.is(result_reg)) { |
| 5981 | __ mov(result_reg, input_reg); |
| 5982 | } |
| 5983 | __ SmiUntag(result_reg); |
| 5984 | __ ClampUint8(result_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5985 | __ bind(&done); |
| 5986 | } |
| 5987 | |
| 5988 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5989 | void LCodeGen::DoAllocate(LAllocate* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5990 | class DeferredAllocate V8_FINAL : public LDeferredCode { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5991 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5992 | DeferredAllocate(LCodeGen* codegen, |
| 5993 | LAllocate* instr, |
| 5994 | const X87Stack& x87_stack) |
| 5995 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5996 | virtual void Generate() V8_OVERRIDE { |
| 5997 | codegen()->DoDeferredAllocate(instr_); |
| 5998 | } |
| 5999 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6000 | private: |
| 6001 | LAllocate* instr_; |
| 6002 | }; |
| 6003 | |
| 6004 | DeferredAllocate* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 6005 | new(zone()) DeferredAllocate(this, instr, x87_stack_); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6006 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6007 | Register result = ToRegister(instr->result()); |
| 6008 | Register temp = ToRegister(instr->temp()); |
| 6009 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 6010 | // Allocate memory for the object. |
| 6011 | AllocationFlags flags = TAG_OBJECT; |
| 6012 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 6013 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 6014 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 6015 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 6016 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 6017 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6018 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 6019 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 6020 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 6021 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6022 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 6023 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 6024 | if (instr->size()->IsConstantOperand()) { |
| 6025 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 6026 | __ Allocate(size, result, temp, no_reg, deferred->entry(), flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6027 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 6028 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6029 | __ Allocate(size, result, temp, no_reg, deferred->entry(), flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | __ bind(deferred->exit()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 6033 | |
| 6034 | if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 6035 | if (instr->size()->IsConstantOperand()) { |
| 6036 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 6037 | __ mov(temp, (size / kPointerSize) - 1); |
| 6038 | } else { |
| 6039 | temp = ToRegister(instr->size()); |
| 6040 | __ shr(temp, kPointerSizeLog2); |
| 6041 | __ dec(temp); |
| 6042 | } |
| 6043 | Label loop; |
| 6044 | __ bind(&loop); |
| 6045 | __ mov(FieldOperand(result, temp, times_pointer_size, 0), |
| 6046 | isolate()->factory()->one_pointer_filler_map()); |
| 6047 | __ dec(temp); |
| 6048 | __ j(not_zero, &loop); |
| 6049 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | |
| 6053 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6054 | Register result = ToRegister(instr->result()); |
| 6055 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6056 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 6057 | // result register contain a valid pointer because it is already |
| 6058 | // contained in the register pointer map. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6059 | __ Set(result, Immediate(Smi::FromInt(0))); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6060 | |
| 6061 | PushSafepointRegistersScope scope(this); |
| 6062 | if (instr->size()->IsRegister()) { |
| 6063 | Register size = ToRegister(instr->size()); |
| 6064 | ASSERT(!size.is(result)); |
| 6065 | __ SmiTag(ToRegister(instr->size())); |
| 6066 | __ push(size); |
| 6067 | } else { |
| 6068 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 6069 | __ push(Immediate(Smi::FromInt(size))); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6070 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6071 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 6072 | int flags = AllocateDoubleAlignFlag::encode( |
| 6073 | instr->hydrogen()->MustAllocateDoubleAligned()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 6074 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 6075 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 6076 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 6077 | flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 6078 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 6079 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 6080 | flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6081 | } else { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 6082 | flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6083 | } |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 6084 | __ push(Immediate(Smi::FromInt(flags))); |
| 6085 | |
| 6086 | CallRuntimeFromDeferred( |
| 6087 | Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 6088 | __ StoreToSafepointRegisterSlot(result, eax); |
| 6089 | } |
| 6090 | |
| 6091 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6092 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6093 | ASSERT(ToRegister(instr->value()).is(eax)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6094 | __ push(eax); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6095 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6099 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6100 | ASSERT(ToRegister(instr->context()).is(esi)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6101 | Label materialized; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6102 | // Registers will be used as follows: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6103 | // ecx = literals array. |
| 6104 | // ebx = regexp literal. |
| 6105 | // eax = regexp literal clone. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6106 | // esi = context. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 6107 | int literal_offset = |
| 6108 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
| 6109 | __ LoadHeapObject(ecx, instr->hydrogen()->literals()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6110 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6111 | __ cmp(ebx, factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6112 | __ j(not_equal, &materialized, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6113 | |
| 6114 | // Create regexp literal using runtime function |
| 6115 | // Result will be in eax. |
| 6116 | __ push(ecx); |
| 6117 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 6118 | __ push(Immediate(instr->hydrogen()->pattern())); |
| 6119 | __ push(Immediate(instr->hydrogen()->flags())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6120 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6121 | __ mov(ebx, eax); |
| 6122 | |
| 6123 | __ bind(&materialized); |
| 6124 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 6125 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 6126 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6127 | __ jmp(&allocated, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6128 | |
| 6129 | __ bind(&runtime_allocate); |
| 6130 | __ push(ebx); |
| 6131 | __ push(Immediate(Smi::FromInt(size))); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6132 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6133 | __ pop(ebx); |
| 6134 | |
| 6135 | __ bind(&allocated); |
| 6136 | // Copy the content into the newly allocated memory. |
| 6137 | // (Unroll copy loop once for better throughput). |
| 6138 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 6139 | __ mov(edx, FieldOperand(ebx, i)); |
| 6140 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 6141 | __ mov(FieldOperand(eax, i), edx); |
| 6142 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 6143 | } |
| 6144 | if ((size % (2 * kPointerSize)) != 0) { |
| 6145 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 6146 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | |
| 6151 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6152 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6153 | // Use the fast case closure allocation code that allocates in new |
| 6154 | // space for nested functions that don't need literals cloning. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 6155 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6156 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
| 6157 | FastNewClosureStub stub(instr->hydrogen()->language_mode(), |
| 6158 | instr->hydrogen()->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 6159 | __ mov(ebx, Immediate(instr->hydrogen()->shared_info())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6160 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6161 | } else { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6162 | __ push(esi); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6163 | __ push(Immediate(instr->hydrogen()->shared_info())); |
| 6164 | __ push(Immediate(pretenure ? factory()->true_value() |
| 6165 | : factory()->false_value())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6166 | CallRuntime(Runtime::kNewClosure, 3, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | |
| 6171 | void LCodeGen::DoTypeof(LTypeof* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6172 | ASSERT(ToRegister(instr->context()).is(esi)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6173 | LOperand* input = instr->value(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6174 | EmitPushTaggedOperand(input); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6175 | CallRuntime(Runtime::kTypeof, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6179 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6180 | Register input = ToRegister(instr->value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6181 | Condition final_branch_condition = EmitTypeofIs(instr, input); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6182 | if (final_branch_condition != no_condition) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6183 | EmitBranch(instr, final_branch_condition); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6184 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6188 | Condition LCodeGen::EmitTypeofIs(LTypeofIsAndBranch* instr, Register input) { |
| 6189 | Label* true_label = instr->TrueLabel(chunk_); |
| 6190 | Label* false_label = instr->FalseLabel(chunk_); |
| 6191 | Handle<String> type_name = instr->type_literal(); |
| 6192 | int left_block = instr->TrueDestination(chunk_); |
| 6193 | int right_block = instr->FalseDestination(chunk_); |
| 6194 | int next_block = GetNextEmittedBlock(); |
| 6195 | |
| 6196 | Label::Distance true_distance = left_block == next_block ? Label::kNear |
| 6197 | : Label::kFar; |
| 6198 | Label::Distance false_distance = right_block == next_block ? Label::kNear |
| 6199 | : Label::kFar; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6200 | Condition final_branch_condition = no_condition; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6201 | if (type_name->Equals(heap()->number_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6202 | __ JumpIfSmi(input, true_label, true_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6203 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6204 | factory()->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6205 | final_branch_condition = equal; |
| 6206 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6207 | } else if (type_name->Equals(heap()->string_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6208 | __ JumpIfSmi(input, false_label, false_distance); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 6209 | __ CmpObjectType(input, FIRST_NONSTRING_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6210 | __ j(above_equal, false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6211 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 6212 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 6213 | final_branch_condition = zero; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6214 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6215 | } else if (type_name->Equals(heap()->symbol_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6216 | __ JumpIfSmi(input, false_label, false_distance); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6217 | __ CmpObjectType(input, SYMBOL_TYPE, input); |
| 6218 | final_branch_condition = equal; |
| 6219 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6220 | } else if (type_name->Equals(heap()->boolean_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6221 | __ cmp(input, factory()->true_value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6222 | __ j(equal, true_label, true_distance); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6223 | __ cmp(input, factory()->false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6224 | final_branch_condition = equal; |
| 6225 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6226 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6227 | __ cmp(input, factory()->null_value()); |
| 6228 | final_branch_condition = equal; |
| 6229 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6230 | } else if (type_name->Equals(heap()->undefined_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6231 | __ cmp(input, factory()->undefined_value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6232 | __ j(equal, true_label, true_distance); |
| 6233 | __ JumpIfSmi(input, false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6234 | // Check for undetectable objects => true. |
| 6235 | __ mov(input, FieldOperand(input, HeapObject::kMapOffset)); |
| 6236 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 6237 | 1 << Map::kIsUndetectable); |
| 6238 | final_branch_condition = not_zero; |
| 6239 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6240 | } else if (type_name->Equals(heap()->function_string())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6241 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6242 | __ JumpIfSmi(input, false_label, false_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6243 | __ CmpObjectType(input, JS_FUNCTION_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6244 | __ j(equal, true_label, true_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6245 | __ CmpInstanceType(input, JS_FUNCTION_PROXY_TYPE); |
| 6246 | final_branch_condition = equal; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6247 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6248 | } else if (type_name->Equals(heap()->object_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6249 | __ JumpIfSmi(input, false_label, false_distance); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6250 | if (!FLAG_harmony_typeof) { |
| 6251 | __ cmp(input, factory()->null_value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6252 | __ j(equal, true_label, true_distance); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6253 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6254 | __ CmpObjectType(input, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6255 | __ j(below, false_label, false_distance); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6256 | __ CmpInstanceType(input, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6257 | __ j(above, false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6258 | // Check for undetectable objects => false. |
| 6259 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 6260 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 6261 | final_branch_condition = zero; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6262 | |
| 6263 | } else { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 6264 | __ jmp(false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6265 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6266 | return final_branch_condition; |
| 6267 | } |
| 6268 | |
| 6269 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6270 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6271 | Register temp = ToRegister(instr->temp()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6272 | |
| 6273 | EmitIsConstructCall(temp); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6274 | EmitBranch(instr, equal); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6275 | } |
| 6276 | |
| 6277 | |
| 6278 | void LCodeGen::EmitIsConstructCall(Register temp) { |
| 6279 | // Get the frame pointer for the calling frame. |
| 6280 | __ mov(temp, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 6281 | |
| 6282 | // Skip the arguments adaptor frame if it exists. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6283 | Label check_frame_marker; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6284 | __ cmp(Operand(temp, StandardFrameConstants::kContextOffset), |
| 6285 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6286 | __ j(not_equal, &check_frame_marker, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6287 | __ mov(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset)); |
| 6288 | |
| 6289 | // Check the marker in the calling frame. |
| 6290 | __ bind(&check_frame_marker); |
| 6291 | __ cmp(Operand(temp, StandardFrameConstants::kMarkerOffset), |
| 6292 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 6293 | } |
| 6294 | |
| 6295 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6296 | void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 6297 | if (!info()->IsStub()) { |
| 6298 | // Ensure that we have enough space after the previous lazy-bailout |
| 6299 | // instruction for patching the code here. |
| 6300 | int current_pc = masm()->pc_offset(); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6301 | if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
| 6302 | int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 6303 | __ Nop(padding_size); |
| 6304 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6305 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 6306 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6310 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6311 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6312 | ASSERT(instr->HasEnvironment()); |
| 6313 | LEnvironment* env = instr->environment(); |
| 6314 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 6315 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | |
| 6319 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 6320 | Deoptimizer::BailoutType type = instr->hydrogen()->type(); |
| 6321 | // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the |
| 6322 | // needed return address), even though the implementation of LAZY and EAGER is |
| 6323 | // now identical. When LAZY is eventually completely folded into EAGER, remove |
| 6324 | // the special case below. |
| 6325 | if (info()->IsStub() && type == Deoptimizer::EAGER) { |
| 6326 | type = Deoptimizer::LAZY; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 6327 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 6328 | Comment(";;; deoptimize: %s", instr->hydrogen()->reason()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 6329 | DeoptimizeIf(no_condition, instr->environment(), type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6333 | void LCodeGen::DoDummy(LDummy* instr) { |
| 6334 | // Nothing to see here, move on! |
| 6335 | } |
| 6336 | |
| 6337 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 6338 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 6339 | // Nothing to see here, move on! |
| 6340 | } |
| 6341 | |
| 6342 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6343 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6344 | PushSafepointRegistersScope scope(this); |
| 6345 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 6346 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 6347 | RecordSafepointWithLazyDeopt( |
| 6348 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 6349 | ASSERT(instr->HasEnvironment()); |
| 6350 | LEnvironment* env = instr->environment(); |
| 6351 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6352 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6353 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6354 | |
| 6355 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 6356 | class DeferredStackCheck V8_FINAL : public LDeferredCode { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6357 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 6358 | DeferredStackCheck(LCodeGen* codegen, |
| 6359 | LStackCheck* instr, |
| 6360 | const X87Stack& x87_stack) |
| 6361 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 6362 | virtual void Generate() V8_OVERRIDE { |
| 6363 | codegen()->DoDeferredStackCheck(instr_); |
| 6364 | } |
| 6365 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6366 | private: |
| 6367 | LStackCheck* instr_; |
| 6368 | }; |
| 6369 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6370 | ASSERT(instr->HasEnvironment()); |
| 6371 | LEnvironment* env = instr->environment(); |
| 6372 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 6373 | // prepare for lazy deoptimization explicitly here. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6374 | if (instr->hydrogen()->is_function_entry()) { |
| 6375 | // Perform stack overflow check. |
| 6376 | Label done; |
| 6377 | ExternalReference stack_limit = |
| 6378 | ExternalReference::address_of_stack_limit(isolate()); |
| 6379 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 6380 | __ j(above_equal, &done, Label::kNear); |
| 6381 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6382 | ASSERT(instr->context()->IsRegister()); |
| 6383 | ASSERT(ToRegister(instr->context()).is(esi)); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 6384 | CallCode(isolate()->builtins()->StackCheck(), |
| 6385 | RelocInfo::CODE_TARGET, |
| 6386 | instr); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6387 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6388 | __ bind(&done); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6389 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 6390 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6391 | } else { |
| 6392 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 6393 | // Perform stack overflow check if this goto needs it before jumping. |
| 6394 | DeferredStackCheck* deferred_stack_check = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 6395 | new(zone()) DeferredStackCheck(this, instr, x87_stack_); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6396 | ExternalReference stack_limit = |
| 6397 | ExternalReference::address_of_stack_limit(isolate()); |
| 6398 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 6399 | __ j(below, deferred_stack_check->entry()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6400 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6401 | __ bind(instr->done_label()); |
| 6402 | deferred_stack_check->SetExit(instr->done_label()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6403 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 6404 | // Don't record a deoptimization index for the safepoint here. |
| 6405 | // This will be done explicitly when emitting call and the safepoint in |
| 6406 | // the deferred code. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6407 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 6412 | // This is a pseudo-instruction that ensures that the environment here is |
| 6413 | // properly registered for deoptimization and records the assembler's PC |
| 6414 | // offset. |
| 6415 | LEnvironment* environment = instr->environment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6416 | |
| 6417 | // If the environment were already registered, we would have no way of |
| 6418 | // backpatching it with the spill slot operands. |
| 6419 | ASSERT(!environment->HasBeenRegistered()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6420 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6421 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 6422 | GenerateOsrPrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6426 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6427 | ASSERT(ToRegister(instr->context()).is(esi)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6428 | __ cmp(eax, isolate()->factory()->undefined_value()); |
| 6429 | DeoptimizeIf(equal, instr->environment()); |
| 6430 | |
| 6431 | __ cmp(eax, isolate()->factory()->null_value()); |
| 6432 | DeoptimizeIf(equal, instr->environment()); |
| 6433 | |
| 6434 | __ test(eax, Immediate(kSmiTagMask)); |
| 6435 | DeoptimizeIf(zero, instr->environment()); |
| 6436 | |
| 6437 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 6438 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 6439 | DeoptimizeIf(below_equal, instr->environment()); |
| 6440 | |
| 6441 | Label use_cache, call_runtime; |
| 6442 | __ CheckEnumCache(&call_runtime); |
| 6443 | |
| 6444 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6445 | __ jmp(&use_cache, Label::kNear); |
| 6446 | |
| 6447 | // Get the set of properties to enumerate. |
| 6448 | __ bind(&call_runtime); |
| 6449 | __ push(eax); |
| 6450 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 6451 | |
| 6452 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6453 | isolate()->factory()->meta_map()); |
| 6454 | DeoptimizeIf(not_equal, instr->environment()); |
| 6455 | __ bind(&use_cache); |
| 6456 | } |
| 6457 | |
| 6458 | |
| 6459 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 6460 | Register map = ToRegister(instr->map()); |
| 6461 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6462 | Label load_cache, done; |
| 6463 | __ EnumLength(result, map); |
| 6464 | __ cmp(result, Immediate(Smi::FromInt(0))); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6465 | __ j(not_equal, &load_cache, Label::kNear); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6466 | __ mov(result, isolate()->factory()->empty_fixed_array()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6467 | __ jmp(&done, Label::kNear); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6468 | |
| 6469 | __ bind(&load_cache); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6470 | __ LoadInstanceDescriptors(map, result); |
| 6471 | __ mov(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 6472 | FieldOperand(result, DescriptorArray::kEnumCacheOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6473 | __ mov(result, |
| 6474 | FieldOperand(result, FixedArray::SizeFor(instr->idx()))); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6475 | __ bind(&done); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6476 | __ test(result, result); |
| 6477 | DeoptimizeIf(equal, instr->environment()); |
| 6478 | } |
| 6479 | |
| 6480 | |
| 6481 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 6482 | Register object = ToRegister(instr->value()); |
| 6483 | __ cmp(ToRegister(instr->map()), |
| 6484 | FieldOperand(object, HeapObject::kMapOffset)); |
| 6485 | DeoptimizeIf(not_equal, instr->environment()); |
| 6486 | } |
| 6487 | |
| 6488 | |
| 6489 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 6490 | Register object = ToRegister(instr->object()); |
| 6491 | Register index = ToRegister(instr->index()); |
| 6492 | |
| 6493 | Label out_of_object, done; |
| 6494 | __ cmp(index, Immediate(0)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6495 | __ j(less, &out_of_object, Label::kNear); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6496 | __ mov(object, FieldOperand(object, |
| 6497 | index, |
| 6498 | times_half_pointer_size, |
| 6499 | JSObject::kHeaderSize)); |
| 6500 | __ jmp(&done, Label::kNear); |
| 6501 | |
| 6502 | __ bind(&out_of_object); |
| 6503 | __ mov(object, FieldOperand(object, JSObject::kPropertiesOffset)); |
| 6504 | __ neg(index); |
| 6505 | // Index is now equal to out of object property index plus 1. |
| 6506 | __ mov(object, FieldOperand(object, |
| 6507 | index, |
| 6508 | times_half_pointer_size, |
| 6509 | FixedArray::kHeaderSize - kPointerSize)); |
| 6510 | __ bind(&done); |
| 6511 | } |
| 6512 | |
| 6513 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6514 | #undef __ |
| 6515 | |
| 6516 | } } // namespace v8::internal |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 6517 | |
| 6518 | #endif // V8_TARGET_ARCH_IA32 |