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()); |
machenbach@chromium.org | ddf3811 | 2013-12-04 09:42:52 +0000 | [diff] [blame] | 106 | RegisterDependentCodeForEmbeddedMaps(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 107 | PopulateDeoptimizationData(code); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 108 | if (!info()->IsStub()) { |
| 109 | Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(code); |
| 110 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 111 | info()->CommitDependencies(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 115 | void LCodeGen::Abort(BailoutReason reason) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 116 | info()->set_bailout_reason(reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 117 | status_ = ABORTED; |
| 118 | } |
| 119 | |
| 120 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 121 | #ifdef _MSC_VER |
| 122 | void LCodeGen::MakeSureStackPagesMapped(int offset) { |
| 123 | const int kPageSize = 4 * KB; |
| 124 | for (offset -= kPageSize; offset > 0; offset -= kPageSize) { |
| 125 | __ mov(Operand(esp, offset), eax); |
| 126 | } |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 131 | void LCodeGen::SaveCallerDoubles() { |
| 132 | ASSERT(info()->saves_caller_doubles()); |
| 133 | ASSERT(NeedsEagerFrame()); |
| 134 | Comment(";;; Save clobbered callee double registers"); |
| 135 | CpuFeatureScope scope(masm(), SSE2); |
| 136 | int count = 0; |
| 137 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 138 | BitVector::Iterator save_iterator(doubles); |
| 139 | while (!save_iterator.Done()) { |
| 140 | __ movsd(MemOperand(esp, count * kDoubleSize), |
| 141 | XMMRegister::FromAllocationIndex(save_iterator.Current())); |
| 142 | save_iterator.Advance(); |
| 143 | count++; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | |
| 148 | void LCodeGen::RestoreCallerDoubles() { |
| 149 | ASSERT(info()->saves_caller_doubles()); |
| 150 | ASSERT(NeedsEagerFrame()); |
| 151 | Comment(";;; Restore clobbered callee double registers"); |
| 152 | CpuFeatureScope scope(masm(), SSE2); |
| 153 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 154 | BitVector::Iterator save_iterator(doubles); |
| 155 | int count = 0; |
| 156 | while (!save_iterator.Done()) { |
| 157 | __ movsd(XMMRegister::FromAllocationIndex(save_iterator.Current()), |
| 158 | MemOperand(esp, count * kDoubleSize)); |
| 159 | save_iterator.Advance(); |
| 160 | count++; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 165 | bool LCodeGen::GeneratePrologue() { |
| 166 | ASSERT(is_generating()); |
| 167 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 168 | if (info()->IsOptimizing()) { |
| 169 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 170 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 171 | #ifdef DEBUG |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 172 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 173 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 174 | __ int3(); |
| 175 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 176 | #endif |
| 177 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 178 | // Strict mode functions and builtins need to replace the receiver |
| 179 | // with undefined when called as functions (without an explicit |
| 180 | // receiver object). ecx is zero for method calls and non-zero for |
| 181 | // function calls. |
| 182 | if (!info_->is_classic_mode() || info_->is_native()) { |
| 183 | Label ok; |
| 184 | __ test(ecx, Operand(ecx)); |
| 185 | __ j(zero, &ok, Label::kNear); |
| 186 | // +1 for return address. |
| 187 | int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize; |
| 188 | __ mov(Operand(esp, receiver_offset), |
| 189 | Immediate(isolate()->factory()->undefined_value())); |
| 190 | __ bind(&ok); |
| 191 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 192 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 193 | if (support_aligned_spilled_doubles_ && dynamic_frame_alignment_) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 194 | // Move state of dynamic frame alignment into edx. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 195 | __ Set(edx, Immediate(kNoAlignmentPadding)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 196 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 197 | Label do_not_pad, align_loop; |
| 198 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 199 | // Align esp + 4 to a multiple of 2 * kPointerSize. |
| 200 | __ test(esp, Immediate(kPointerSize)); |
| 201 | __ j(not_zero, &do_not_pad, Label::kNear); |
| 202 | __ push(Immediate(0)); |
| 203 | __ mov(ebx, esp); |
| 204 | __ mov(edx, Immediate(kAlignmentPaddingPushed)); |
| 205 | // Copy arguments, receiver, and return address. |
| 206 | __ mov(ecx, Immediate(scope()->num_parameters() + 2)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 207 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 208 | __ bind(&align_loop); |
| 209 | __ mov(eax, Operand(ebx, 1 * kPointerSize)); |
| 210 | __ mov(Operand(ebx, 0), eax); |
| 211 | __ add(Operand(ebx), Immediate(kPointerSize)); |
| 212 | __ dec(ecx); |
| 213 | __ j(not_zero, &align_loop, Label::kNear); |
| 214 | __ mov(Operand(ebx, 0), Immediate(kAlignmentZapValue)); |
| 215 | __ bind(&do_not_pad); |
| 216 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 217 | } |
| 218 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 219 | info()->set_prologue_offset(masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 220 | if (NeedsEagerFrame()) { |
| 221 | ASSERT(!frame_is_built_); |
| 222 | frame_is_built_ = true; |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 223 | __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 224 | info()->AddNoFrameRange(0, masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 225 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 226 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 227 | if (info()->IsOptimizing() && |
| 228 | dynamic_frame_alignment_ && |
| 229 | FLAG_debug_code) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 230 | __ test(esp, Immediate(kPointerSize)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 231 | __ Assert(zero, kFrameIsExpectedToBeAligned); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 232 | } |
| 233 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 234 | // Reserve space for the stack slots needed by the code. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 235 | int slots = GetStackSlotCount(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 236 | ASSERT(slots != 0 || !info()->IsOptimizing()); |
| 237 | if (slots > 0) { |
| 238 | if (slots == 1) { |
| 239 | if (dynamic_frame_alignment_) { |
| 240 | __ push(edx); |
| 241 | } else { |
| 242 | __ push(Immediate(kNoAlignmentPadding)); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 243 | } |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 244 | } else { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 245 | if (FLAG_debug_code) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 246 | __ sub(Operand(esp), Immediate(slots * kPointerSize)); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 247 | #ifdef _MSC_VER |
| 248 | MakeSureStackPagesMapped(slots * kPointerSize); |
| 249 | #endif |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 250 | __ push(eax); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 251 | __ mov(Operand(eax), Immediate(slots)); |
| 252 | Label loop; |
| 253 | __ bind(&loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 254 | __ mov(MemOperand(esp, eax, times_4, 0), |
| 255 | Immediate(kSlotsZapValue)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 256 | __ dec(eax); |
| 257 | __ j(not_zero, &loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 258 | __ pop(eax); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 259 | } else { |
| 260 | __ sub(Operand(esp), Immediate(slots * kPointerSize)); |
| 261 | #ifdef _MSC_VER |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 262 | MakeSureStackPagesMapped(slots * kPointerSize); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 263 | #endif |
| 264 | } |
| 265 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 266 | if (support_aligned_spilled_doubles_) { |
| 267 | Comment(";;; Store dynamic frame alignment tag for spilled doubles"); |
| 268 | // Store dynamic frame alignment state in the first local. |
| 269 | int offset = JavaScriptFrameConstants::kDynamicAlignmentStateOffset; |
| 270 | if (dynamic_frame_alignment_) { |
| 271 | __ mov(Operand(ebp, offset), edx); |
| 272 | } else { |
| 273 | __ mov(Operand(ebp, offset), Immediate(kNoAlignmentPadding)); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (info()->saves_caller_doubles() && CpuFeatures::IsSupported(SSE2)) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 279 | SaveCallerDoubles(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 283 | // Possibly allocate a local context. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 284 | int heap_slots = info_->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 285 | if (heap_slots > 0) { |
| 286 | Comment(";;; Allocate local context"); |
| 287 | // Argument to NewContext is the function, which is still in edi. |
| 288 | __ push(edi); |
| 289 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 290 | FastNewContextStub stub(heap_slots); |
| 291 | __ CallStub(&stub); |
| 292 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 293 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 294 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 295 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 296 | // Context is returned in both eax and esi. It replaces the context |
| 297 | // passed to us. It's saved in the stack and kept live in esi. |
| 298 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 299 | |
| 300 | // Copy parameters into context if necessary. |
| 301 | int num_parameters = scope()->num_parameters(); |
| 302 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 303 | Variable* var = scope()->parameter(i); |
| 304 | if (var->IsContextSlot()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 305 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 306 | (num_parameters - 1 - i) * kPointerSize; |
| 307 | // Load parameter from stack. |
| 308 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 309 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 310 | int context_offset = Context::SlotOffset(var->index()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 311 | __ mov(Operand(esi, context_offset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 312 | // Update the write barrier. This clobbers eax and ebx. |
| 313 | __ RecordWriteContextSlot(esi, |
| 314 | context_offset, |
| 315 | eax, |
| 316 | ebx, |
| 317 | kDontSaveFPRegs); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | Comment(";;; End allocate local context"); |
| 321 | } |
| 322 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 323 | // Trace the call. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 324 | if (FLAG_trace && info()->IsOptimizing()) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 325 | // We have not executed any compiled code yet, so esi still holds the |
| 326 | // incoming context. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 327 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 328 | } |
| 329 | return !is_aborted(); |
| 330 | } |
| 331 | |
| 332 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 333 | void LCodeGen::GenerateOsrPrologue() { |
| 334 | // Generate the OSR entry prologue at the first unknown OSR value, or if there |
| 335 | // are none, at the OSR entrypoint instruction. |
| 336 | if (osr_pc_offset_ >= 0) return; |
| 337 | |
| 338 | osr_pc_offset_ = masm()->pc_offset(); |
| 339 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 340 | // Move state of dynamic frame alignment into edx. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 341 | __ Set(edx, Immediate(kNoAlignmentPadding)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 342 | |
| 343 | if (support_aligned_spilled_doubles_ && dynamic_frame_alignment_) { |
| 344 | Label do_not_pad, align_loop; |
| 345 | // Align ebp + 4 to a multiple of 2 * kPointerSize. |
| 346 | __ test(ebp, Immediate(kPointerSize)); |
| 347 | __ j(zero, &do_not_pad, Label::kNear); |
| 348 | __ push(Immediate(0)); |
| 349 | __ mov(ebx, esp); |
| 350 | __ mov(edx, Immediate(kAlignmentPaddingPushed)); |
| 351 | |
| 352 | // Move all parts of the frame over one word. The frame consists of: |
| 353 | // unoptimized frame slots, alignment state, context, frame pointer, return |
| 354 | // address, receiver, and the arguments. |
| 355 | __ mov(ecx, Immediate(scope()->num_parameters() + |
| 356 | 5 + graph()->osr()->UnoptimizedFrameSlots())); |
| 357 | |
| 358 | __ bind(&align_loop); |
| 359 | __ mov(eax, Operand(ebx, 1 * kPointerSize)); |
| 360 | __ mov(Operand(ebx, 0), eax); |
| 361 | __ add(Operand(ebx), Immediate(kPointerSize)); |
| 362 | __ dec(ecx); |
| 363 | __ j(not_zero, &align_loop, Label::kNear); |
| 364 | __ mov(Operand(ebx, 0), Immediate(kAlignmentZapValue)); |
| 365 | __ sub(Operand(ebp), Immediate(kPointerSize)); |
| 366 | __ bind(&do_not_pad); |
| 367 | } |
| 368 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 369 | // Save the first local, which is overwritten by the alignment state. |
| 370 | Operand alignment_loc = MemOperand(ebp, -3 * kPointerSize); |
| 371 | __ push(alignment_loc); |
| 372 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 373 | // Set the dynamic frame alignment state. |
| 374 | __ mov(alignment_loc, edx); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 375 | |
| 376 | // Adjust the frame size, subsuming the unoptimized frame into the |
| 377 | // optimized frame. |
| 378 | int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
| 379 | ASSERT(slots >= 1); |
| 380 | __ sub(esp, Immediate((slots - 1) * kPointerSize)); |
| 381 | } |
| 382 | |
| 383 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 384 | void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
| 385 | if (!CpuFeatures::IsSupported(SSE2)) FlushX87StackIfNecessary(instr); |
| 386 | } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 387 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 388 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 389 | void LCodeGen::GenerateBodyInstructionPost(LInstruction* instr) { |
| 390 | if (!CpuFeatures::IsSupported(SSE2)) { |
| 391 | if (instr->IsGoto()) { |
| 392 | x87_stack_.LeavingBlock(current_block_, LGoto::cast(instr)); |
| 393 | } else if (FLAG_debug_code && FLAG_enable_slow_asserts && |
| 394 | !instr->IsGap() && !instr->IsReturn()) { |
| 395 | if (instr->ClobbersDoubleRegisters()) { |
| 396 | if (instr->HasDoubleRegisterResult()) { |
| 397 | ASSERT_EQ(1, x87_stack_.depth()); |
| 398 | } else { |
| 399 | ASSERT_EQ(0, x87_stack_.depth()); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 400 | } |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 401 | } |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 402 | __ VerifyX87StackDepth(x87_stack_.depth()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 408 | bool LCodeGen::GenerateJumpTable() { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 409 | Label needs_frame; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 410 | if (jump_table_.length() > 0) { |
| 411 | Comment(";;; -------------------- Jump table --------------------"); |
| 412 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 413 | for (int i = 0; i < jump_table_.length(); i++) { |
| 414 | __ bind(&jump_table_[i].label); |
| 415 | Address entry = jump_table_[i].address; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 416 | Deoptimizer::BailoutType type = jump_table_[i].bailout_type; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 417 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 418 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 419 | Comment(";;; jump table entry %d.", i); |
| 420 | } else { |
| 421 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 422 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 423 | if (jump_table_[i].needs_frame) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 424 | ASSERT(!info()->saves_caller_doubles()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 425 | __ push(Immediate(ExternalReference::ForDeoptEntry(entry))); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 426 | if (needs_frame.is_bound()) { |
| 427 | __ jmp(&needs_frame); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 428 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 429 | __ bind(&needs_frame); |
| 430 | __ push(MemOperand(ebp, StandardFrameConstants::kContextOffset)); |
| 431 | // This variant of deopt can only be used with stubs. Since we don't |
| 432 | // have a function pointer to install in the stack frame that we're |
| 433 | // building, install a special marker there instead. |
| 434 | ASSERT(info()->IsStub()); |
| 435 | __ push(Immediate(Smi::FromInt(StackFrame::STUB))); |
| 436 | // Push a PC inside the function so that the deopt code can find where |
| 437 | // the deopt comes from. It doesn't have to be the precise return |
| 438 | // address of a "calling" LAZY deopt, it only has to be somewhere |
| 439 | // inside the code body. |
| 440 | Label push_approx_pc; |
| 441 | __ call(&push_approx_pc); |
| 442 | __ bind(&push_approx_pc); |
| 443 | // Push the continuation which was stashed were the ebp should |
| 444 | // be. Replace it with the saved ebp. |
| 445 | __ push(MemOperand(esp, 3 * kPointerSize)); |
| 446 | __ mov(MemOperand(esp, 4 * kPointerSize), ebp); |
| 447 | __ lea(ebp, MemOperand(esp, 4 * kPointerSize)); |
| 448 | __ ret(0); // Call the continuation without clobbering registers. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 449 | } |
| 450 | } else { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 451 | if (info()->saves_caller_doubles() && CpuFeatures::IsSupported(SSE2)) { |
| 452 | RestoreCallerDoubles(); |
| 453 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 454 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | return !is_aborted(); |
| 458 | } |
| 459 | |
| 460 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 461 | bool LCodeGen::GenerateDeferredCode() { |
| 462 | ASSERT(is_generating()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 463 | if (deferred_.length() > 0) { |
| 464 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 465 | LDeferredCode* code = deferred_[i]; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 466 | X87Stack copy(code->x87_stack()); |
| 467 | x87_stack_ = copy; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 468 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 469 | HValue* value = |
| 470 | instructions_->at(code->instruction_index())->hydrogen_value(); |
| 471 | RecordAndWritePosition(value->position()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 472 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 473 | Comment(";;; <@%d,#%d> " |
| 474 | "-------------------- Deferred %s --------------------", |
| 475 | code->instruction_index(), |
| 476 | code->instr()->hydrogen_value()->id(), |
| 477 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 478 | __ bind(code->entry()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 479 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 480 | Comment(";;; Build frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 481 | ASSERT(!frame_is_built_); |
| 482 | ASSERT(info()->IsStub()); |
| 483 | frame_is_built_ = true; |
| 484 | // Build the frame in such a way that esi isn't trashed. |
| 485 | __ push(ebp); // Caller's frame pointer. |
| 486 | __ push(Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 487 | __ push(Immediate(Smi::FromInt(StackFrame::STUB))); |
| 488 | __ lea(ebp, Operand(esp, 2 * kPointerSize)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 489 | Comment(";;; Deferred code"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 490 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 491 | code->Generate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 492 | if (NeedsDeferredFrame()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 493 | __ bind(code->done()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 494 | Comment(";;; Destroy frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 495 | ASSERT(frame_is_built_); |
| 496 | frame_is_built_ = false; |
| 497 | __ mov(esp, ebp); |
| 498 | __ pop(ebp); |
| 499 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 500 | __ jmp(code->exit()); |
| 501 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | // Deferred code is the last part of the instruction sequence. Mark |
| 505 | // the generated code as done unless we bailed out. |
| 506 | if (!is_aborted()) status_ = DONE; |
| 507 | return !is_aborted(); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | bool LCodeGen::GenerateSafepointTable() { |
| 512 | ASSERT(is_done()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 513 | if (!info()->IsStub()) { |
| 514 | // For lazy deoptimization we need space to patch a call after every call. |
| 515 | // Ensure there is always space for such patching, even if the code ends |
| 516 | // in a call. |
| 517 | int target_offset = masm()->pc_offset() + Deoptimizer::patch_size(); |
| 518 | while (masm()->pc_offset() < target_offset) { |
| 519 | masm()->nop(); |
| 520 | } |
| 521 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 522 | safepoints_.Emit(masm(), GetStackSlotCount()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 523 | return !is_aborted(); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | Register LCodeGen::ToRegister(int index) const { |
| 528 | return Register::FromAllocationIndex(index); |
| 529 | } |
| 530 | |
| 531 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 532 | X87Register LCodeGen::ToX87Register(int index) const { |
| 533 | return X87Register::FromAllocationIndex(index); |
| 534 | } |
| 535 | |
| 536 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 537 | XMMRegister LCodeGen::ToDoubleRegister(int index) const { |
| 538 | return XMMRegister::FromAllocationIndex(index); |
| 539 | } |
| 540 | |
| 541 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 542 | void LCodeGen::X87LoadForUsage(X87Register reg) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 543 | ASSERT(x87_stack_.Contains(reg)); |
| 544 | x87_stack_.Fxch(reg); |
| 545 | x87_stack_.pop(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 549 | void LCodeGen::X87LoadForUsage(X87Register reg1, X87Register reg2) { |
| 550 | ASSERT(x87_stack_.Contains(reg1)); |
| 551 | ASSERT(x87_stack_.Contains(reg2)); |
| 552 | x87_stack_.Fxch(reg1, 1); |
| 553 | x87_stack_.Fxch(reg2); |
| 554 | x87_stack_.pop(); |
| 555 | x87_stack_.pop(); |
| 556 | } |
| 557 | |
| 558 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 559 | void LCodeGen::X87Stack::Fxch(X87Register reg, int other_slot) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 560 | ASSERT(is_mutable_); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 561 | ASSERT(Contains(reg) && stack_depth_ > other_slot); |
| 562 | int i = ArrayIndex(reg); |
| 563 | int st = st2idx(i); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 564 | if (st != other_slot) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 565 | int other_i = st2idx(other_slot); |
| 566 | X87Register other = stack_[other_i]; |
| 567 | stack_[other_i] = reg; |
| 568 | stack_[i] = other; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 569 | if (st == 0) { |
| 570 | __ fxch(other_slot); |
| 571 | } else if (other_slot == 0) { |
| 572 | __ fxch(st); |
| 573 | } else { |
| 574 | __ fxch(st); |
| 575 | __ fxch(other_slot); |
| 576 | __ fxch(st); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 582 | int LCodeGen::X87Stack::st2idx(int pos) { |
| 583 | return stack_depth_ - pos - 1; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 587 | int LCodeGen::X87Stack::ArrayIndex(X87Register reg) { |
| 588 | for (int i = 0; i < stack_depth_; i++) { |
| 589 | if (stack_[i].is(reg)) return i; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 590 | } |
| 591 | UNREACHABLE(); |
| 592 | return -1; |
| 593 | } |
| 594 | |
| 595 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 596 | bool LCodeGen::X87Stack::Contains(X87Register reg) { |
| 597 | for (int i = 0; i < stack_depth_; i++) { |
| 598 | if (stack_[i].is(reg)) return true; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 599 | } |
| 600 | return false; |
| 601 | } |
| 602 | |
| 603 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 604 | void LCodeGen::X87Stack::Free(X87Register reg) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 605 | ASSERT(is_mutable_); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 606 | ASSERT(Contains(reg)); |
| 607 | int i = ArrayIndex(reg); |
| 608 | int st = st2idx(i); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 609 | if (st > 0) { |
| 610 | // keep track of how fstp(i) changes the order of elements |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 611 | int tos_i = st2idx(0); |
| 612 | stack_[i] = stack_[tos_i]; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 613 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 614 | pop(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 615 | __ fstp(st); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | void LCodeGen::X87Mov(X87Register dst, Operand src, X87OperandType opts) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 620 | if (x87_stack_.Contains(dst)) { |
| 621 | x87_stack_.Fxch(dst); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 622 | __ fstp(0); |
| 623 | } else { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 624 | x87_stack_.push(dst); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 625 | } |
| 626 | X87Fld(src, opts); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | void LCodeGen::X87Fld(Operand src, X87OperandType opts) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 631 | ASSERT(!src.is_reg_only()); |
| 632 | switch (opts) { |
| 633 | case kX87DoubleOperand: |
| 634 | __ fld_d(src); |
| 635 | break; |
| 636 | case kX87FloatOperand: |
| 637 | __ fld_s(src); |
| 638 | break; |
| 639 | case kX87IntOperand: |
| 640 | __ fild_s(src); |
| 641 | break; |
| 642 | default: |
| 643 | UNREACHABLE(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 648 | void LCodeGen::X87Mov(Operand dst, X87Register src, X87OperandType opts) { |
| 649 | ASSERT(!dst.is_reg_only()); |
| 650 | x87_stack_.Fxch(src); |
| 651 | switch (opts) { |
| 652 | case kX87DoubleOperand: |
| 653 | __ fst_d(dst); |
| 654 | break; |
| 655 | case kX87IntOperand: |
| 656 | __ fist_s(dst); |
| 657 | break; |
| 658 | default: |
| 659 | UNREACHABLE(); |
| 660 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 664 | void LCodeGen::X87Stack::PrepareToWrite(X87Register reg) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 665 | ASSERT(is_mutable_); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 666 | if (Contains(reg)) { |
| 667 | Free(reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 668 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 669 | // Mark this register as the next register to write to |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 670 | stack_[stack_depth_] = reg; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 674 | void LCodeGen::X87Stack::CommitWrite(X87Register reg) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 675 | ASSERT(is_mutable_); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 676 | // 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] | 677 | ASSERT(!Contains(reg) && stack_[stack_depth_].is(reg) && |
| 678 | stack_depth_ < X87Register::kNumAllocatableRegisters); |
| 679 | stack_depth_++; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
| 683 | void LCodeGen::X87PrepareBinaryOp( |
| 684 | X87Register left, X87Register right, X87Register result) { |
| 685 | // You need to use DefineSameAsFirst for x87 instructions |
| 686 | ASSERT(result.is(left)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 687 | x87_stack_.Fxch(right, 1); |
| 688 | x87_stack_.Fxch(left); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 692 | void LCodeGen::X87Stack::FlushIfNecessary(LInstruction* instr, LCodeGen* cgen) { |
| 693 | if (stack_depth_ > 0 && instr->ClobbersDoubleRegisters()) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 694 | bool double_inputs = instr->HasDoubleRegisterInput(); |
| 695 | |
| 696 | // Flush stack from tos down, since FreeX87() will mess with tos |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 697 | for (int i = stack_depth_-1; i >= 0; i--) { |
| 698 | X87Register reg = stack_[i]; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 699 | // Skip registers which contain the inputs for the next instruction |
| 700 | // when flushing the stack |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 701 | if (double_inputs && instr->IsDoubleInput(reg, cgen)) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 702 | continue; |
| 703 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 704 | Free(reg); |
| 705 | if (i < stack_depth_-1) i++; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 706 | } |
| 707 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 708 | if (instr->IsReturn()) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 709 | while (stack_depth_ > 0) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 710 | __ fstp(0); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 711 | stack_depth_--; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 712 | } |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 713 | if (FLAG_debug_code && FLAG_enable_slow_asserts) __ VerifyX87StackDepth(0); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | |
| 718 | void LCodeGen::X87Stack::LeavingBlock(int current_block_id, LGoto* goto_instr) { |
| 719 | ASSERT(stack_depth_ <= 1); |
| 720 | // If ever used for new stubs producing two pairs of doubles joined into two |
| 721 | // phis this assert hits. That situation is not handled, since the two stacks |
| 722 | // might have st0 and st1 swapped. |
| 723 | if (current_block_id + 1 != goto_instr->block_id()) { |
| 724 | // If we have a value on the x87 stack on leaving a block, it must be a |
| 725 | // phi input. If the next block we compile is not the join block, we have |
| 726 | // to discard the stack state. |
| 727 | stack_depth_ = 0; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | |
| 732 | void LCodeGen::EmitFlushX87ForDeopt() { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 733 | // The deoptimizer does not support X87 Registers. But as long as we |
| 734 | // deopt from a stub its not a problem, since we will re-materialize the |
| 735 | // original stub inputs, which can't be double registers. |
| 736 | ASSERT(info()->IsStub()); |
| 737 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
| 738 | __ pushfd(); |
| 739 | __ VerifyX87StackDepth(x87_stack_.depth()); |
| 740 | __ popfd(); |
| 741 | } |
| 742 | for (int i = 0; i < x87_stack_.depth(); i++) __ fstp(0); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 746 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 747 | ASSERT(op->IsRegister()); |
| 748 | return ToRegister(op->index()); |
| 749 | } |
| 750 | |
| 751 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 752 | X87Register LCodeGen::ToX87Register(LOperand* op) const { |
| 753 | ASSERT(op->IsDoubleRegister()); |
| 754 | return ToX87Register(op->index()); |
| 755 | } |
| 756 | |
| 757 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 758 | XMMRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 759 | ASSERT(op->IsDoubleRegister()); |
| 760 | return ToDoubleRegister(op->index()); |
| 761 | } |
| 762 | |
| 763 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 764 | int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 765 | return ToRepresentation(op, Representation::Integer32()); |
| 766 | } |
| 767 | |
| 768 | |
| 769 | int32_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| 770 | const Representation& r) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 771 | HConstant* constant = chunk_->LookupConstant(op); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 772 | int32_t value = constant->Integer32Value(); |
| 773 | if (r.IsInteger32()) return value; |
| 774 | ASSERT(r.IsSmiOrTagged()); |
| 775 | return reinterpret_cast<int32_t>(Smi::FromInt(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 779 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 780 | HConstant* constant = chunk_->LookupConstant(op); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 781 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 782 | return constant->handle(isolate()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 786 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 787 | HConstant* constant = chunk_->LookupConstant(op); |
| 788 | ASSERT(constant->HasDoubleValue()); |
| 789 | return constant->DoubleValue(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 793 | ExternalReference LCodeGen::ToExternalReference(LConstantOperand* op) const { |
| 794 | HConstant* constant = chunk_->LookupConstant(op); |
| 795 | ASSERT(constant->HasExternalReferenceValue()); |
| 796 | return constant->ExternalReferenceValue(); |
| 797 | } |
| 798 | |
| 799 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 800 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 801 | return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 805 | bool LCodeGen::IsSmi(LConstantOperand* op) const { |
| 806 | return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
| 807 | } |
| 808 | |
| 809 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 810 | static int ArgumentsOffsetWithoutFrame(int index) { |
| 811 | ASSERT(index < 0); |
| 812 | return -(index + 1) * kPointerSize + kPCOnStackSize; |
| 813 | } |
| 814 | |
| 815 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 816 | Operand LCodeGen::ToOperand(LOperand* op) const { |
| 817 | if (op->IsRegister()) return Operand(ToRegister(op)); |
| 818 | if (op->IsDoubleRegister()) return Operand(ToDoubleRegister(op)); |
| 819 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 820 | if (NeedsEagerFrame()) { |
| 821 | return Operand(ebp, StackSlotOffset(op->index())); |
| 822 | } else { |
| 823 | // Retrieve parameter without eager stack-frame relative to the |
| 824 | // stack-pointer. |
| 825 | return Operand(esp, ArgumentsOffsetWithoutFrame(op->index())); |
| 826 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 830 | Operand LCodeGen::HighOperand(LOperand* op) { |
| 831 | ASSERT(op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 832 | if (NeedsEagerFrame()) { |
| 833 | return Operand(ebp, StackSlotOffset(op->index()) + kPointerSize); |
| 834 | } else { |
| 835 | // Retrieve parameter without eager stack-frame relative to the |
| 836 | // stack-pointer. |
| 837 | return Operand( |
| 838 | esp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); |
| 839 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 843 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 844 | Translation* translation) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 845 | if (environment == NULL) return; |
| 846 | |
| 847 | // The translation includes one command per value in the environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 848 | int translation_size = environment->translation_size(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 849 | // The output frame height does not include the parameters. |
| 850 | int height = translation_size - environment->parameter_count(); |
| 851 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 852 | WriteTranslation(environment->outer(), translation); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 853 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 854 | !info()->closure().is_identical_to(environment->closure()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 855 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 856 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 857 | : Translation::kSelfLiteralId; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 858 | switch (environment->frame_type()) { |
| 859 | case JS_FUNCTION: |
| 860 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 861 | break; |
| 862 | case JS_CONSTRUCT: |
| 863 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 864 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 865 | case JS_GETTER: |
| 866 | ASSERT(translation_size == 1); |
| 867 | ASSERT(height == 0); |
| 868 | translation->BeginGetterStubFrame(closure_id); |
| 869 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 870 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 871 | ASSERT(translation_size == 2); |
| 872 | ASSERT(height == 0); |
| 873 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 874 | break; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 875 | case ARGUMENTS_ADAPTOR: |
| 876 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 877 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 878 | case STUB: |
| 879 | translation->BeginCompiledStubFrame(); |
| 880 | break; |
| 881 | default: |
| 882 | UNREACHABLE(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 883 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 884 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 885 | int object_index = 0; |
| 886 | int dematerialized_index = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 887 | for (int i = 0; i < translation_size; ++i) { |
| 888 | LOperand* value = environment->values()->at(i); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 889 | AddToTranslation(environment, |
| 890 | translation, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 891 | value, |
| 892 | environment->HasTaggedValueAt(i), |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 893 | environment->HasUint32ValueAt(i), |
| 894 | &object_index, |
| 895 | &dematerialized_index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
| 899 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 900 | void LCodeGen::AddToTranslation(LEnvironment* environment, |
| 901 | Translation* translation, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 902 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 903 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 904 | bool is_uint32, |
| 905 | int* object_index_pointer, |
| 906 | int* dematerialized_index_pointer) { |
| 907 | if (op == LEnvironment::materialization_marker()) { |
| 908 | int object_index = (*object_index_pointer)++; |
| 909 | if (environment->ObjectIsDuplicateAt(object_index)) { |
| 910 | int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
| 911 | translation->DuplicateObject(dupe_of); |
| 912 | return; |
| 913 | } |
| 914 | int object_length = environment->ObjectLengthAt(object_index); |
| 915 | if (environment->ObjectIsArgumentsAt(object_index)) { |
| 916 | translation->BeginArgumentsObject(object_length); |
| 917 | } else { |
| 918 | translation->BeginCapturedObject(object_length); |
| 919 | } |
| 920 | int dematerialized_index = *dematerialized_index_pointer; |
| 921 | int env_offset = environment->translation_size() + dematerialized_index; |
| 922 | *dematerialized_index_pointer += object_length; |
| 923 | for (int i = 0; i < object_length; ++i) { |
| 924 | LOperand* value = environment->values()->at(env_offset + i); |
| 925 | AddToTranslation(environment, |
| 926 | translation, |
| 927 | value, |
| 928 | environment->HasTaggedValueAt(env_offset + i), |
| 929 | environment->HasUint32ValueAt(env_offset + i), |
| 930 | object_index_pointer, |
| 931 | dematerialized_index_pointer); |
| 932 | } |
| 933 | return; |
| 934 | } |
| 935 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 936 | if (op->IsStackSlot()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 937 | if (is_tagged) { |
| 938 | translation->StoreStackSlot(op->index()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 939 | } else if (is_uint32) { |
| 940 | translation->StoreUint32StackSlot(op->index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 941 | } else { |
| 942 | translation->StoreInt32StackSlot(op->index()); |
| 943 | } |
| 944 | } else if (op->IsDoubleStackSlot()) { |
| 945 | translation->StoreDoubleStackSlot(op->index()); |
| 946 | } else if (op->IsArgument()) { |
| 947 | ASSERT(is_tagged); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 948 | int src_index = GetStackSlotCount() + op->index(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 949 | translation->StoreStackSlot(src_index); |
| 950 | } else if (op->IsRegister()) { |
| 951 | Register reg = ToRegister(op); |
| 952 | if (is_tagged) { |
| 953 | translation->StoreRegister(reg); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 954 | } else if (is_uint32) { |
| 955 | translation->StoreUint32Register(reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 956 | } else { |
| 957 | translation->StoreInt32Register(reg); |
| 958 | } |
| 959 | } else if (op->IsDoubleRegister()) { |
| 960 | XMMRegister reg = ToDoubleRegister(op); |
| 961 | translation->StoreDoubleRegister(reg); |
| 962 | } else if (op->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 963 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 964 | int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 965 | translation->StoreLiteral(src_index); |
| 966 | } else { |
| 967 | UNREACHABLE(); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 972 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 973 | RelocInfo::Mode mode, |
| 974 | LInstruction* instr, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 975 | SafepointMode safepoint_mode) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 976 | ASSERT(instr != NULL); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 977 | __ call(code, mode); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 978 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 979 | |
| 980 | // Signal that we don't inline smi code before these stubs in the |
| 981 | // optimizing code generator. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 982 | if (code->kind() == Code::BINARY_OP_IC || |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 983 | code->kind() == Code::COMPARE_IC) { |
| 984 | __ nop(); |
| 985 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 989 | void LCodeGen::CallCode(Handle<Code> code, |
| 990 | RelocInfo::Mode mode, |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 991 | LInstruction* instr) { |
| 992 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 996 | void LCodeGen::CallRuntime(const Runtime::Function* fun, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 997 | int argc, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 998 | LInstruction* instr, |
| 999 | SaveFPRegsMode save_doubles) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1000 | ASSERT(instr != NULL); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1001 | ASSERT(instr->HasPointerMap()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1002 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1003 | __ CallRuntime(fun, argc, save_doubles); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1004 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1005 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1006 | |
| 1007 | ASSERT(info()->is_calling()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1011 | void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1012 | if (context->IsRegister()) { |
| 1013 | if (!ToRegister(context).is(esi)) { |
| 1014 | __ mov(esi, ToRegister(context)); |
| 1015 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1016 | } else if (context->IsStackSlot()) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1017 | __ mov(esi, ToOperand(context)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1018 | } else if (context->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1019 | HConstant* constant = |
| 1020 | chunk_->LookupConstant(LConstantOperand::cast(context)); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1021 | __ LoadObject(esi, Handle<Object>::cast(constant->handle(isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1022 | } else { |
| 1023 | UNREACHABLE(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1024 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 1028 | int argc, |
| 1029 | LInstruction* instr, |
| 1030 | LOperand* context) { |
| 1031 | LoadContextFromDeferred(context); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1032 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1033 | __ CallRuntimeSaveDoubles(id); |
| 1034 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1035 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1036 | |
| 1037 | ASSERT(info()->is_calling()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1041 | void LCodeGen::RegisterEnvironmentForDeoptimization( |
| 1042 | LEnvironment* environment, Safepoint::DeoptMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1043 | if (!environment->HasBeenRegistered()) { |
| 1044 | // Physical stack frame layout: |
| 1045 | // -x ............. -4 0 ..................................... y |
| 1046 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 1047 | |
| 1048 | // Layout of the environment: |
| 1049 | // 0 ..................................................... size-1 |
| 1050 | // [parameters] [locals] [expression stack including arguments] |
| 1051 | |
| 1052 | // Layout of the translation: |
| 1053 | // 0 ........................................................ size - 1 + 4 |
| 1054 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 1055 | // |>------------ translation_size ------------<| |
| 1056 | |
| 1057 | int frame_count = 0; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1058 | int jsframe_count = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1059 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 1060 | ++frame_count; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1061 | if (e->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1062 | ++jsframe_count; |
| 1063 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1064 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1065 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1066 | WriteTranslation(environment, &translation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1067 | int deoptimization_index = deoptimizations_.length(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1068 | int pc_offset = masm()->pc_offset(); |
| 1069 | environment->Register(deoptimization_index, |
| 1070 | translation.index(), |
| 1071 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1072 | deoptimizations_.Add(environment, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 1077 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 1078 | LEnvironment* environment, |
| 1079 | Deoptimizer::BailoutType bailout_type) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1080 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1081 | ASSERT(environment->HasBeenRegistered()); |
| 1082 | int id = environment->deoptimization_index(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1083 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1084 | Address entry = |
| 1085 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1086 | if (entry == NULL) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1087 | Abort(kBailoutWasNotPrepared); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1091 | if (DeoptEveryNTimes()) { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1092 | ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1093 | Label no_deopt; |
| 1094 | __ pushfd(); |
| 1095 | __ push(eax); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1096 | __ mov(eax, Operand::StaticVariable(count)); |
| 1097 | __ sub(eax, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1098 | __ j(not_zero, &no_deopt, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1099 | if (FLAG_trap_on_deopt) __ int3(); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1100 | __ mov(eax, Immediate(FLAG_deopt_every_n_times)); |
| 1101 | __ mov(Operand::StaticVariable(count), eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1102 | __ pop(eax); |
| 1103 | __ popfd(); |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 1104 | ASSERT(frame_is_built_); |
| 1105 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1106 | __ bind(&no_deopt); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1107 | __ mov(Operand::StaticVariable(count), eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1108 | __ pop(eax); |
| 1109 | __ popfd(); |
| 1110 | } |
| 1111 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1112 | // Before Instructions which can deopt, we normally flush the x87 stack. But |
| 1113 | // we can have inputs or outputs of the current instruction on the stack, |
| 1114 | // thus we need to flush them here from the physical stack to leave it in a |
| 1115 | // consistent state. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1116 | if (x87_stack_.depth() > 0) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1117 | Label done; |
| 1118 | if (cc != no_condition) __ j(NegateCondition(cc), &done, Label::kNear); |
| 1119 | EmitFlushX87ForDeopt(); |
| 1120 | __ bind(&done); |
| 1121 | } |
| 1122 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1123 | if (info()->ShouldTrapOnDeopt()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1124 | Label done; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1125 | if (cc != no_condition) __ j(NegateCondition(cc), &done, Label::kNear); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1126 | __ int3(); |
| 1127 | __ bind(&done); |
| 1128 | } |
| 1129 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1130 | ASSERT(info()->IsStub() || frame_is_built_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1131 | if (cc == no_condition && frame_is_built_) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1132 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1133 | } else { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1134 | // We often have several deopts to the same entry, reuse the last |
| 1135 | // jump entry if this is the case. |
| 1136 | if (jump_table_.is_empty() || |
| 1137 | jump_table_.last().address != entry || |
| 1138 | jump_table_.last().needs_frame != !frame_is_built_ || |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 1139 | jump_table_.last().bailout_type != bailout_type) { |
| 1140 | Deoptimizer::JumpTableEntry table_entry(entry, |
| 1141 | bailout_type, |
| 1142 | !frame_is_built_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1143 | jump_table_.Add(table_entry, zone()); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1144 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1145 | if (cc == no_condition) { |
| 1146 | __ jmp(&jump_table_.last().label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1147 | } else { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1148 | __ j(cc, &jump_table_.last().label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1149 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 1154 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 1155 | LEnvironment* environment) { |
| 1156 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 1157 | ? Deoptimizer::LAZY |
| 1158 | : Deoptimizer::EAGER; |
| 1159 | DeoptimizeIf(cc, environment, bailout_type); |
| 1160 | } |
| 1161 | |
| 1162 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1163 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 1164 | int length = deoptimizations_.length(); |
| 1165 | if (length == 0) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1166 | Handle<DeoptimizationInputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1167 | factory()->NewDeoptimizationInputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1168 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 1169 | Handle<ByteArray> translations = |
| 1170 | translations_.CreateByteArray(isolate()->factory()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1171 | data->SetTranslationByteArray(*translations); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1172 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 1173 | |
| 1174 | Handle<FixedArray> literals = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1175 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1176 | { AllowDeferredHandleDereference copy_handles; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1177 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 1178 | literals->set(i, *deoptimization_literals_[i]); |
| 1179 | } |
| 1180 | data->SetLiteralArray(*literals); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1181 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1182 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1183 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1184 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 1185 | |
| 1186 | // Populate the deoptimization entries. |
| 1187 | for (int i = 0; i < length; i++) { |
| 1188 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1189 | data->SetAstId(i, env->ast_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1190 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 1191 | data->SetArgumentsStackHeight(i, |
| 1192 | Smi::FromInt(env->arguments_stack_height())); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1193 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1194 | } |
| 1195 | code->set_deoptimization_data(*data); |
| 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 1200 | int result = deoptimization_literals_.length(); |
| 1201 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 1202 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 1203 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1204 | deoptimization_literals_.Add(literal, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1205 | return result; |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 1210 | ASSERT(deoptimization_literals_.length() == 0); |
| 1211 | |
| 1212 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 1213 | chunk()->inlined_closures(); |
| 1214 | |
| 1215 | for (int i = 0, length = inlined_closures->length(); |
| 1216 | i < length; |
| 1217 | i++) { |
| 1218 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 1219 | } |
| 1220 | |
| 1221 | inlined_function_count_ = deoptimization_literals_.length(); |
| 1222 | } |
| 1223 | |
| 1224 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1225 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 1226 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 1227 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 1228 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 1229 | } else { |
| 1230 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 1231 | RecordSafepointWithRegisters( |
| 1232 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1237 | void LCodeGen::RecordSafepoint( |
| 1238 | LPointerMap* pointers, |
| 1239 | Safepoint::Kind kind, |
| 1240 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1241 | Safepoint::DeoptMode deopt_mode) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1242 | ASSERT(kind == expected_safepoint_kind_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1243 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1244 | Safepoint safepoint = |
| 1245 | safepoints_.DefineSafepoint(masm(), kind, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1246 | for (int i = 0; i < operands->length(); i++) { |
| 1247 | LOperand* pointer = operands->at(i); |
| 1248 | if (pointer->IsStackSlot()) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 1249 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1250 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1251 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1252 | } |
| 1253 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1258 | Safepoint::DeoptMode mode) { |
| 1259 | RecordSafepoint(pointers, Safepoint::kSimple, 0, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1263 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode mode) { |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1264 | LPointerMap empty_pointers(zone()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1265 | RecordSafepoint(&empty_pointers, mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1269 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 1270 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1271 | Safepoint::DeoptMode mode) { |
| 1272 | RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1276 | void LCodeGen::RecordAndWritePosition(int position) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1277 | if (position == RelocInfo::kNoPosition) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1278 | masm()->positions_recorder()->RecordPosition(position); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1279 | masm()->positions_recorder()->WriteRecordedPositions(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1283 | static const char* LabelType(LLabel* label) { |
| 1284 | if (label->is_loop_header()) return " (loop header)"; |
| 1285 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 1286 | return ""; |
| 1287 | } |
| 1288 | |
| 1289 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1290 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1291 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1292 | current_instruction_, |
| 1293 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1294 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1295 | LabelType(label)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1296 | __ bind(label->label()); |
| 1297 | current_block_ = label->block_id(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1298 | DoGap(label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | |
| 1302 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1303 | resolver_.Resolve(move); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | void LCodeGen::DoGap(LGap* gap) { |
| 1308 | for (int i = LGap::FIRST_INNER_POSITION; |
| 1309 | i <= LGap::LAST_INNER_POSITION; |
| 1310 | i++) { |
| 1311 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 1312 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 1313 | if (move != NULL) DoParallelMove(move); |
| 1314 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1318 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 1319 | DoGap(instr); |
| 1320 | } |
| 1321 | |
| 1322 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1323 | void LCodeGen::DoParameter(LParameter* instr) { |
| 1324 | // Nothing to do. |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void LCodeGen::DoCallStub(LCallStub* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1329 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1330 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 1331 | switch (instr->hydrogen()->major_key()) { |
| 1332 | case CodeStub::RegExpConstructResult: { |
| 1333 | RegExpConstructResultStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1334 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1335 | break; |
| 1336 | } |
| 1337 | case CodeStub::RegExpExec: { |
| 1338 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1339 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1340 | break; |
| 1341 | } |
| 1342 | case CodeStub::SubString: { |
| 1343 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1344 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1345 | break; |
| 1346 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1347 | case CodeStub::StringCompare: { |
| 1348 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1349 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1350 | break; |
| 1351 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1352 | default: |
| 1353 | UNREACHABLE(); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | |
| 1358 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1359 | GenerateOsrPrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | void LCodeGen::DoModI(LModI* instr) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1364 | HMod* hmod = instr->hydrogen(); |
| 1365 | HValue* left = hmod->left(); |
| 1366 | HValue* right = hmod->right(); |
| 1367 | if (hmod->HasPowerOf2Divisor()) { |
| 1368 | // TODO(svenpanne) We should really do the strength reduction on the |
| 1369 | // Hydrogen level. |
| 1370 | Register left_reg = ToRegister(instr->left()); |
| 1371 | ASSERT(left_reg.is(ToRegister(instr->result()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1373 | // Note: The code below even works when right contains kMinInt. |
| 1374 | int32_t divisor = Abs(right->GetInteger32Constant()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1375 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1376 | Label left_is_not_negative, done; |
| 1377 | if (left->CanBeNegative()) { |
| 1378 | __ test(left_reg, Operand(left_reg)); |
| 1379 | __ j(not_sign, &left_is_not_negative, Label::kNear); |
| 1380 | __ neg(left_reg); |
| 1381 | __ and_(left_reg, divisor - 1); |
| 1382 | __ neg(left_reg); |
| 1383 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1384 | DeoptimizeIf(zero, instr->environment()); |
| 1385 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1386 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1387 | } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1388 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1389 | __ bind(&left_is_not_negative); |
| 1390 | __ and_(left_reg, divisor - 1); |
| 1391 | __ bind(&done); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1392 | } else { |
| 1393 | Register left_reg = ToRegister(instr->left()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1394 | ASSERT(left_reg.is(eax)); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1395 | Register right_reg = ToRegister(instr->right()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1396 | ASSERT(!right_reg.is(eax)); |
| 1397 | ASSERT(!right_reg.is(edx)); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1398 | Register result_reg = ToRegister(instr->result()); |
| 1399 | ASSERT(result_reg.is(edx)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1400 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1401 | Label done; |
| 1402 | // Check for x % 0, idiv would signal a divide error. We have to |
| 1403 | // deopt in this case because we can't return a NaN. |
| 1404 | if (right->CanBeZero()) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1405 | __ test(right_reg, Operand(right_reg)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1406 | DeoptimizeIf(zero, instr->environment()); |
| 1407 | } |
| 1408 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1409 | // Check for kMinInt % -1, idiv would signal a divide error. We |
| 1410 | // have to deopt if we care about -0, because we can't return that. |
| 1411 | if (left->RangeCanInclude(kMinInt) && right->RangeCanInclude(-1)) { |
| 1412 | Label no_overflow_possible; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1413 | __ cmp(left_reg, kMinInt); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1414 | __ j(not_equal, &no_overflow_possible, Label::kNear); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1415 | __ cmp(right_reg, -1); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1416 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1417 | DeoptimizeIf(equal, instr->environment()); |
| 1418 | } else { |
| 1419 | __ j(not_equal, &no_overflow_possible, Label::kNear); |
| 1420 | __ Set(result_reg, Immediate(0)); |
| 1421 | __ jmp(&done, Label::kNear); |
| 1422 | } |
| 1423 | __ bind(&no_overflow_possible); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1426 | // Sign extend dividend in eax into edx:eax. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1427 | __ cdq(); |
| 1428 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1429 | // If we care about -0, test if the dividend is <0 and the result is 0. |
| 1430 | if (left->CanBeNegative() && |
| 1431 | hmod->CanBeZero() && |
| 1432 | hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1433 | Label positive_left; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1434 | __ test(left_reg, Operand(left_reg)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1435 | __ j(not_sign, &positive_left, Label::kNear); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1436 | __ idiv(right_reg); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1437 | __ test(result_reg, Operand(result_reg)); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1438 | DeoptimizeIf(zero, instr->environment()); |
| 1439 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1440 | __ bind(&positive_left); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1441 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1442 | __ idiv(right_reg); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1443 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | void LCodeGen::DoDivI(LDivI* instr) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1449 | if (!instr->is_flooring() && instr->hydrogen()->HasPowerOf2Divisor()) { |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1450 | Register dividend = ToRegister(instr->left()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1451 | int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant(); |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1452 | int32_t test_value = 0; |
| 1453 | int32_t power = 0; |
| 1454 | |
| 1455 | if (divisor > 0) { |
| 1456 | test_value = divisor - 1; |
| 1457 | power = WhichPowerOf2(divisor); |
| 1458 | } else { |
| 1459 | // Check for (0 / -x) that will produce negative zero. |
| 1460 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1461 | __ test(dividend, Operand(dividend)); |
| 1462 | DeoptimizeIf(zero, instr->environment()); |
| 1463 | } |
| 1464 | // Check for (kMinInt / -1). |
| 1465 | if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1466 | __ cmp(dividend, kMinInt); |
| 1467 | DeoptimizeIf(zero, instr->environment()); |
| 1468 | } |
| 1469 | test_value = - divisor - 1; |
| 1470 | power = WhichPowerOf2(-divisor); |
| 1471 | } |
| 1472 | |
| 1473 | if (test_value != 0) { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1474 | if (instr->hydrogen()->CheckFlag( |
| 1475 | HInstruction::kAllUsesTruncatingToInt32)) { |
| 1476 | Label done, negative; |
| 1477 | __ cmp(dividend, 0); |
| 1478 | __ j(less, &negative, Label::kNear); |
| 1479 | __ sar(dividend, power); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1480 | if (divisor < 0) __ neg(dividend); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1481 | __ jmp(&done, Label::kNear); |
| 1482 | |
| 1483 | __ bind(&negative); |
| 1484 | __ neg(dividend); |
| 1485 | __ sar(dividend, power); |
| 1486 | if (divisor > 0) __ neg(dividend); |
| 1487 | __ bind(&done); |
| 1488 | return; // Don't fall through to "__ neg" below. |
| 1489 | } else { |
| 1490 | // Deoptimize if remainder is not 0. |
| 1491 | __ test(dividend, Immediate(test_value)); |
| 1492 | DeoptimizeIf(not_zero, instr->environment()); |
| 1493 | __ sar(dividend, power); |
| 1494 | } |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | if (divisor < 0) __ neg(dividend); |
| 1498 | |
| 1499 | return; |
| 1500 | } |
| 1501 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1502 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1503 | ASSERT(ToRegister(instr->result()).is(eax)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1504 | ASSERT(ToRegister(instr->left()).is(eax)); |
| 1505 | ASSERT(!ToRegister(instr->right()).is(eax)); |
| 1506 | ASSERT(!ToRegister(instr->right()).is(edx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1507 | |
| 1508 | Register left_reg = eax; |
| 1509 | |
| 1510 | // Check for x / 0. |
| 1511 | Register right_reg = ToRegister(right); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1512 | if (instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1513 | __ test(right_reg, ToOperand(right)); |
| 1514 | DeoptimizeIf(zero, instr->environment()); |
| 1515 | } |
| 1516 | |
| 1517 | // Check for (0 / -x) that will produce negative zero. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1518 | if (instr->hydrogen_value()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1519 | Label left_not_zero; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1520 | __ test(left_reg, Operand(left_reg)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1521 | __ j(not_zero, &left_not_zero, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1522 | __ test(right_reg, ToOperand(right)); |
| 1523 | DeoptimizeIf(sign, instr->environment()); |
| 1524 | __ bind(&left_not_zero); |
| 1525 | } |
| 1526 | |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1527 | // Check for (kMinInt / -1). |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1528 | if (instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1529 | Label left_not_min_int; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1530 | __ cmp(left_reg, kMinInt); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1531 | __ j(not_zero, &left_not_min_int, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1532 | __ cmp(right_reg, -1); |
| 1533 | DeoptimizeIf(zero, instr->environment()); |
| 1534 | __ bind(&left_not_min_int); |
| 1535 | } |
| 1536 | |
| 1537 | // Sign extend to edx. |
| 1538 | __ cdq(); |
| 1539 | __ idiv(right_reg); |
| 1540 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1541 | if (instr->is_flooring()) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1542 | Label done; |
| 1543 | __ test(edx, edx); |
| 1544 | __ j(zero, &done, Label::kNear); |
| 1545 | __ xor_(edx, right_reg); |
| 1546 | __ sar(edx, 31); |
| 1547 | __ add(eax, edx); |
| 1548 | __ bind(&done); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1549 | } else if (!instr->hydrogen()->CheckFlag( |
| 1550 | HInstruction::kAllUsesTruncatingToInt32)) { |
| 1551 | // Deoptimize if remainder is not 0. |
| 1552 | __ test(edx, Operand(edx)); |
| 1553 | DeoptimizeIf(not_zero, instr->environment()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1554 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1558 | void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1559 | ASSERT(instr->right()->IsConstantOperand()); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1560 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1561 | Register dividend = ToRegister(instr->left()); |
| 1562 | int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1563 | Register result = ToRegister(instr->result()); |
| 1564 | |
| 1565 | switch (divisor) { |
| 1566 | case 0: |
| 1567 | DeoptimizeIf(no_condition, instr->environment()); |
| 1568 | return; |
| 1569 | |
| 1570 | case 1: |
| 1571 | __ Move(result, dividend); |
| 1572 | return; |
| 1573 | |
| 1574 | case -1: |
| 1575 | __ Move(result, dividend); |
| 1576 | __ neg(result); |
| 1577 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1578 | DeoptimizeIf(zero, instr->environment()); |
| 1579 | } |
| 1580 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1581 | DeoptimizeIf(overflow, instr->environment()); |
| 1582 | } |
| 1583 | return; |
| 1584 | } |
| 1585 | |
| 1586 | uint32_t divisor_abs = abs(divisor); |
| 1587 | if (IsPowerOf2(divisor_abs)) { |
| 1588 | int32_t power = WhichPowerOf2(divisor_abs); |
| 1589 | if (divisor < 0) { |
| 1590 | // Input[dividend] is clobbered. |
| 1591 | // The sequence is tedious because neg(dividend) might overflow. |
| 1592 | __ mov(result, dividend); |
| 1593 | __ sar(dividend, 31); |
| 1594 | __ neg(result); |
| 1595 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1596 | DeoptimizeIf(zero, instr->environment()); |
| 1597 | } |
| 1598 | __ shl(dividend, 32 - power); |
| 1599 | __ sar(result, power); |
| 1600 | __ not_(dividend); |
| 1601 | // Clear result.sign if dividend.sign is set. |
| 1602 | __ and_(result, dividend); |
| 1603 | } else { |
| 1604 | __ Move(result, dividend); |
| 1605 | __ sar(result, power); |
| 1606 | } |
| 1607 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1608 | ASSERT(ToRegister(instr->left()).is(eax)); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1609 | ASSERT(ToRegister(instr->result()).is(edx)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1610 | Register scratch = ToRegister(instr->temp()); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1611 | |
| 1612 | // Find b which: 2^b < divisor_abs < 2^(b+1). |
| 1613 | unsigned b = 31 - CompilerIntrinsics::CountLeadingZeros(divisor_abs); |
| 1614 | unsigned shift = 32 + b; // Precision +1bit (effectively). |
| 1615 | double multiplier_f = |
| 1616 | static_cast<double>(static_cast<uint64_t>(1) << shift) / divisor_abs; |
| 1617 | int64_t multiplier; |
| 1618 | if (multiplier_f - floor(multiplier_f) < 0.5) { |
| 1619 | multiplier = static_cast<int64_t>(floor(multiplier_f)); |
| 1620 | } else { |
| 1621 | multiplier = static_cast<int64_t>(floor(multiplier_f)) + 1; |
| 1622 | } |
| 1623 | // The multiplier is a uint32. |
| 1624 | ASSERT(multiplier > 0 && |
| 1625 | multiplier < (static_cast<int64_t>(1) << 32)); |
| 1626 | __ mov(scratch, dividend); |
| 1627 | if (divisor < 0 && |
| 1628 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1629 | __ test(dividend, dividend); |
| 1630 | DeoptimizeIf(zero, instr->environment()); |
| 1631 | } |
| 1632 | __ mov(edx, static_cast<int32_t>(multiplier)); |
| 1633 | __ imul(edx); |
| 1634 | if (static_cast<int32_t>(multiplier) < 0) { |
| 1635 | __ add(edx, scratch); |
| 1636 | } |
| 1637 | Register reg_lo = eax; |
| 1638 | Register reg_byte_scratch = scratch; |
| 1639 | if (!reg_byte_scratch.is_byte_register()) { |
| 1640 | __ xchg(reg_lo, reg_byte_scratch); |
| 1641 | reg_lo = scratch; |
| 1642 | reg_byte_scratch = eax; |
| 1643 | } |
| 1644 | if (divisor < 0) { |
| 1645 | __ xor_(reg_byte_scratch, reg_byte_scratch); |
| 1646 | __ cmp(reg_lo, 0x40000000); |
| 1647 | __ setcc(above, reg_byte_scratch); |
| 1648 | __ neg(edx); |
| 1649 | __ sub(edx, reg_byte_scratch); |
| 1650 | } else { |
| 1651 | __ xor_(reg_byte_scratch, reg_byte_scratch); |
| 1652 | __ cmp(reg_lo, 0xC0000000); |
| 1653 | __ setcc(above_equal, reg_byte_scratch); |
| 1654 | __ add(edx, reg_byte_scratch); |
| 1655 | } |
| 1656 | __ sar(edx, shift - 32); |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1661 | void LCodeGen::DoMulI(LMulI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1662 | Register left = ToRegister(instr->left()); |
| 1663 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1664 | |
| 1665 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1666 | __ mov(ToRegister(instr->temp()), left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | if (right->IsConstantOperand()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1670 | // Try strength reductions on the multiplication. |
| 1671 | // All replacement instructions are at most as long as the imul |
| 1672 | // and have better latency. |
| 1673 | int constant = ToInteger32(LConstantOperand::cast(right)); |
| 1674 | if (constant == -1) { |
| 1675 | __ neg(left); |
| 1676 | } else if (constant == 0) { |
| 1677 | __ xor_(left, Operand(left)); |
| 1678 | } else if (constant == 2) { |
| 1679 | __ add(left, Operand(left)); |
| 1680 | } else if (!instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1681 | // If we know that the multiplication can't overflow, it's safe to |
| 1682 | // use instructions that don't set the overflow flag for the |
| 1683 | // multiplication. |
| 1684 | switch (constant) { |
| 1685 | case 1: |
| 1686 | // Do nothing. |
| 1687 | break; |
| 1688 | case 3: |
| 1689 | __ lea(left, Operand(left, left, times_2, 0)); |
| 1690 | break; |
| 1691 | case 4: |
| 1692 | __ shl(left, 2); |
| 1693 | break; |
| 1694 | case 5: |
| 1695 | __ lea(left, Operand(left, left, times_4, 0)); |
| 1696 | break; |
| 1697 | case 8: |
| 1698 | __ shl(left, 3); |
| 1699 | break; |
| 1700 | case 9: |
| 1701 | __ lea(left, Operand(left, left, times_8, 0)); |
| 1702 | break; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1703 | case 16: |
| 1704 | __ shl(left, 4); |
| 1705 | break; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1706 | default: |
| 1707 | __ imul(left, left, constant); |
| 1708 | break; |
| 1709 | } |
| 1710 | } else { |
| 1711 | __ imul(left, left, constant); |
| 1712 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1713 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1714 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1715 | __ SmiUntag(left); |
| 1716 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | __ imul(left, ToOperand(right)); |
| 1718 | } |
| 1719 | |
| 1720 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1721 | DeoptimizeIf(overflow, instr->environment()); |
| 1722 | } |
| 1723 | |
| 1724 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1725 | // Bail out if the result is supposed to be negative zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1726 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1727 | __ test(left, Operand(left)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1728 | __ j(not_zero, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1729 | if (right->IsConstantOperand()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1730 | if (ToInteger32(LConstantOperand::cast(right)) < 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1731 | DeoptimizeIf(no_condition, instr->environment()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1732 | } else if (ToInteger32(LConstantOperand::cast(right)) == 0) { |
| 1733 | __ cmp(ToRegister(instr->temp()), Immediate(0)); |
| 1734 | DeoptimizeIf(less, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1735 | } |
| 1736 | } else { |
| 1737 | // Test the non-zero operand for negative sign. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1738 | __ or_(ToRegister(instr->temp()), ToOperand(right)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1739 | DeoptimizeIf(sign, instr->environment()); |
| 1740 | } |
| 1741 | __ bind(&done); |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | |
| 1746 | void LCodeGen::DoBitI(LBitI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1747 | LOperand* left = instr->left(); |
| 1748 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1749 | ASSERT(left->Equals(instr->result())); |
| 1750 | ASSERT(left->IsRegister()); |
| 1751 | |
| 1752 | if (right->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1753 | int32_t right_operand = |
| 1754 | ToRepresentation(LConstantOperand::cast(right), |
| 1755 | instr->hydrogen()->representation()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1756 | switch (instr->op()) { |
| 1757 | case Token::BIT_AND: |
| 1758 | __ and_(ToRegister(left), right_operand); |
| 1759 | break; |
| 1760 | case Token::BIT_OR: |
| 1761 | __ or_(ToRegister(left), right_operand); |
| 1762 | break; |
| 1763 | case Token::BIT_XOR: |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1764 | if (right_operand == int32_t(~0)) { |
| 1765 | __ not_(ToRegister(left)); |
| 1766 | } else { |
| 1767 | __ xor_(ToRegister(left), right_operand); |
| 1768 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | default: |
| 1771 | UNREACHABLE(); |
| 1772 | break; |
| 1773 | } |
| 1774 | } else { |
| 1775 | switch (instr->op()) { |
| 1776 | case Token::BIT_AND: |
| 1777 | __ and_(ToRegister(left), ToOperand(right)); |
| 1778 | break; |
| 1779 | case Token::BIT_OR: |
| 1780 | __ or_(ToRegister(left), ToOperand(right)); |
| 1781 | break; |
| 1782 | case Token::BIT_XOR: |
| 1783 | __ xor_(ToRegister(left), ToOperand(right)); |
| 1784 | break; |
| 1785 | default: |
| 1786 | UNREACHABLE(); |
| 1787 | break; |
| 1788 | } |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | |
| 1793 | void LCodeGen::DoShiftI(LShiftI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1794 | LOperand* left = instr->left(); |
| 1795 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1796 | ASSERT(left->Equals(instr->result())); |
| 1797 | ASSERT(left->IsRegister()); |
| 1798 | if (right->IsRegister()) { |
| 1799 | ASSERT(ToRegister(right).is(ecx)); |
| 1800 | |
| 1801 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1802 | case Token::ROR: |
| 1803 | __ ror_cl(ToRegister(left)); |
| 1804 | if (instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1805 | __ test(ToRegister(left), ToRegister(left)); |
| 1806 | DeoptimizeIf(sign, instr->environment()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1807 | } |
| 1808 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1809 | case Token::SAR: |
| 1810 | __ sar_cl(ToRegister(left)); |
| 1811 | break; |
| 1812 | case Token::SHR: |
| 1813 | __ shr_cl(ToRegister(left)); |
| 1814 | if (instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1815 | __ test(ToRegister(left), ToRegister(left)); |
| 1816 | DeoptimizeIf(sign, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | } |
| 1818 | break; |
| 1819 | case Token::SHL: |
| 1820 | __ shl_cl(ToRegister(left)); |
| 1821 | break; |
| 1822 | default: |
| 1823 | UNREACHABLE(); |
| 1824 | break; |
| 1825 | } |
| 1826 | } else { |
| 1827 | int value = ToInteger32(LConstantOperand::cast(right)); |
| 1828 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1829 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1830 | case Token::ROR: |
| 1831 | if (shift_count == 0 && instr->can_deopt()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1832 | __ test(ToRegister(left), ToRegister(left)); |
| 1833 | DeoptimizeIf(sign, instr->environment()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1834 | } else { |
| 1835 | __ ror(ToRegister(left), shift_count); |
| 1836 | } |
| 1837 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1838 | case Token::SAR: |
| 1839 | if (shift_count != 0) { |
| 1840 | __ sar(ToRegister(left), shift_count); |
| 1841 | } |
| 1842 | break; |
| 1843 | case Token::SHR: |
| 1844 | if (shift_count == 0 && 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()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1847 | } else { |
| 1848 | __ shr(ToRegister(left), shift_count); |
| 1849 | } |
| 1850 | break; |
| 1851 | case Token::SHL: |
| 1852 | if (shift_count != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1853 | if (instr->hydrogen_value()->representation().IsSmi() && |
| 1854 | instr->can_deopt()) { |
| 1855 | if (shift_count != 1) { |
| 1856 | __ shl(ToRegister(left), shift_count - 1); |
| 1857 | } |
| 1858 | __ SmiTag(ToRegister(left)); |
| 1859 | DeoptimizeIf(overflow, instr->environment()); |
| 1860 | } else { |
| 1861 | __ shl(ToRegister(left), shift_count); |
| 1862 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1863 | } |
| 1864 | break; |
| 1865 | default: |
| 1866 | UNREACHABLE(); |
| 1867 | break; |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | |
| 1873 | void LCodeGen::DoSubI(LSubI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1874 | LOperand* left = instr->left(); |
| 1875 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1876 | ASSERT(left->Equals(instr->result())); |
| 1877 | |
| 1878 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1879 | __ sub(ToOperand(left), |
| 1880 | ToImmediate(right, instr->hydrogen()->representation())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1881 | } else { |
| 1882 | __ sub(ToRegister(left), ToOperand(right)); |
| 1883 | } |
| 1884 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1885 | DeoptimizeIf(overflow, instr->environment()); |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | |
| 1890 | void LCodeGen::DoConstantI(LConstantI* instr) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1891 | __ Set(ToRegister(instr->result()), Immediate(instr->value())); |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | void LCodeGen::DoConstantS(LConstantS* instr) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1896 | __ Set(ToRegister(instr->result()), Immediate(instr->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | |
| 1900 | void LCodeGen::DoConstantD(LConstantD* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1901 | double v = instr->value(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1902 | uint64_t int_val = BitCast<uint64_t, double>(v); |
| 1903 | int32_t lower = static_cast<int32_t>(int_val); |
| 1904 | int32_t upper = static_cast<int32_t>(int_val >> (kBitsPerInt)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1905 | ASSERT(instr->result()->IsDoubleRegister()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1906 | |
| 1907 | if (!CpuFeatures::IsSafeForSnapshot(SSE2)) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1908 | __ push(Immediate(upper)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1909 | __ push(Immediate(lower)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1910 | X87Register reg = ToX87Register(instr->result()); |
| 1911 | X87Mov(reg, Operand(esp, 0)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1912 | __ add(Operand(esp), Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1913 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1914 | CpuFeatureScope scope1(masm(), SSE2); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1915 | XMMRegister res = ToDoubleRegister(instr->result()); |
| 1916 | if (int_val == 0) { |
| 1917 | __ xorps(res, res); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1918 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1919 | Register temp = ToRegister(instr->temp()); |
| 1920 | if (CpuFeatures::IsSupported(SSE4_1)) { |
| 1921 | CpuFeatureScope scope2(masm(), SSE4_1); |
| 1922 | if (lower != 0) { |
| 1923 | __ Set(temp, Immediate(lower)); |
| 1924 | __ movd(res, Operand(temp)); |
| 1925 | __ Set(temp, Immediate(upper)); |
| 1926 | __ pinsrd(res, Operand(temp), 1); |
| 1927 | } else { |
| 1928 | __ xorps(res, res); |
| 1929 | __ Set(temp, Immediate(upper)); |
| 1930 | __ pinsrd(res, Operand(temp), 1); |
| 1931 | } |
| 1932 | } else { |
| 1933 | __ Set(temp, Immediate(upper)); |
| 1934 | __ movd(res, Operand(temp)); |
| 1935 | __ psllq(res, 32); |
| 1936 | if (lower != 0) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1937 | XMMRegister xmm_scratch = double_scratch0(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1938 | __ Set(temp, Immediate(lower)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1939 | __ movd(xmm_scratch, Operand(temp)); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1940 | __ orps(res, xmm_scratch); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1941 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1942 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | } |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1948 | void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1949 | __ lea(ToRegister(instr->result()), Operand::StaticVariable(instr->value())); |
| 1950 | } |
| 1951 | |
| 1952 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1953 | void LCodeGen::DoConstantT(LConstantT* instr) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1954 | Register reg = ToRegister(instr->result()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1955 | Handle<Object> handle = instr->value(isolate()); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1956 | AllowDeferredHandleDereference smi_check; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1957 | __ LoadObject(reg, handle); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1961 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1962 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1963 | Register map = ToRegister(instr->value()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1964 | __ EnumLength(result, map); |
| 1965 | } |
| 1966 | |
| 1967 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1968 | void LCodeGen::DoElementsKind(LElementsKind* instr) { |
| 1969 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1970 | Register input = ToRegister(instr->value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1971 | |
| 1972 | // Load map into |result|. |
| 1973 | __ mov(result, FieldOperand(input, HeapObject::kMapOffset)); |
| 1974 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 1975 | // but the following masking takes care of that anyway. |
| 1976 | __ mov(result, FieldOperand(result, Map::kBitField2Offset)); |
| 1977 | // Retrieve elements_kind from bit field 2. |
| 1978 | __ and_(result, Map::kElementsKindMask); |
| 1979 | __ shr(result, Map::kElementsKindShift); |
| 1980 | } |
| 1981 | |
| 1982 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1983 | void LCodeGen::DoValueOf(LValueOf* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1984 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1985 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1986 | Register map = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1987 | ASSERT(input.is(result)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1988 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1989 | Label done; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1990 | |
| 1991 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 1992 | // If the object is a smi return the object. |
| 1993 | __ JumpIfSmi(input, &done, Label::kNear); |
| 1994 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1995 | |
| 1996 | // If the object is not a value type, return the object. |
| 1997 | __ CmpObjectType(input, JS_VALUE_TYPE, map); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1998 | __ j(not_equal, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1999 | __ mov(result, FieldOperand(input, JSValue::kValueOffset)); |
| 2000 | |
| 2001 | __ bind(&done); |
| 2002 | } |
| 2003 | |
| 2004 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2005 | void LCodeGen::DoDateField(LDateField* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2006 | Register object = ToRegister(instr->date()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2007 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2008 | Register scratch = ToRegister(instr->temp()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2009 | Smi* index = instr->index(); |
| 2010 | Label runtime, done; |
| 2011 | ASSERT(object.is(result)); |
| 2012 | ASSERT(object.is(eax)); |
| 2013 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2014 | __ test(object, Immediate(kSmiTagMask)); |
| 2015 | DeoptimizeIf(zero, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2016 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2017 | DeoptimizeIf(not_equal, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2018 | |
| 2019 | if (index->value() == 0) { |
| 2020 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
| 2021 | } else { |
| 2022 | if (index->value() < JSDate::kFirstUncachedField) { |
| 2023 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 2024 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 2025 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 2026 | __ j(not_equal, &runtime, Label::kNear); |
| 2027 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 2028 | kPointerSize * index->value())); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2029 | __ jmp(&done, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2030 | } |
| 2031 | __ bind(&runtime); |
| 2032 | __ PrepareCallCFunction(2, scratch); |
| 2033 | __ mov(Operand(esp, 0), object); |
| 2034 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 2035 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 2036 | __ bind(&done); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2041 | Operand LCodeGen::BuildSeqStringOperand(Register string, |
| 2042 | LOperand* index, |
| 2043 | String::Encoding encoding) { |
| 2044 | if (index->IsConstantOperand()) { |
| 2045 | int offset = ToRepresentation(LConstantOperand::cast(index), |
| 2046 | Representation::Integer32()); |
| 2047 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2048 | offset *= kUC16Size; |
| 2049 | } |
| 2050 | STATIC_ASSERT(kCharSize == 1); |
| 2051 | return FieldOperand(string, SeqString::kHeaderSize + offset); |
| 2052 | } |
| 2053 | return FieldOperand( |
| 2054 | string, ToRegister(index), |
| 2055 | encoding == String::ONE_BYTE_ENCODING ? times_1 : times_2, |
| 2056 | SeqString::kHeaderSize); |
| 2057 | } |
| 2058 | |
| 2059 | |
| 2060 | void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 2061 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 2062 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2063 | Register string = ToRegister(instr->string()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2064 | |
| 2065 | if (FLAG_debug_code) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2066 | __ push(string); |
| 2067 | __ mov(string, FieldOperand(string, HeapObject::kMapOffset)); |
| 2068 | __ movzx_b(string, FieldOperand(string, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2069 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2070 | __ and_(string, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2071 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 2072 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2073 | __ cmp(string, Immediate(encoding == String::ONE_BYTE_ENCODING |
| 2074 | ? one_byte_seq_type : two_byte_seq_type)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2075 | __ Check(equal, kUnexpectedStringType); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2076 | __ pop(string); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2079 | Operand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2080 | if (encoding == String::ONE_BYTE_ENCODING) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2081 | __ movzx_b(result, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2082 | } else { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2083 | __ movzx_w(result, operand); |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | |
| 2088 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 2089 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 2090 | Register string = ToRegister(instr->string()); |
| 2091 | |
| 2092 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2093 | Register value = ToRegister(instr->value()); |
| 2094 | Register index = ToRegister(instr->index()); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2095 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 2096 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2097 | int encoding_mask = |
| 2098 | instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
| 2099 | ? one_byte_seq_type : two_byte_seq_type; |
| 2100 | __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | Operand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 2104 | if (instr->value()->IsConstantOperand()) { |
| 2105 | int value = ToRepresentation(LConstantOperand::cast(instr->value()), |
| 2106 | Representation::Integer32()); |
| 2107 | ASSERT_LE(0, value); |
| 2108 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 2109 | ASSERT_LE(value, String::kMaxOneByteCharCode); |
| 2110 | __ mov_b(operand, static_cast<int8_t>(value)); |
| 2111 | } else { |
| 2112 | ASSERT_LE(value, String::kMaxUtf16CodeUnit); |
| 2113 | __ mov_w(operand, static_cast<int16_t>(value)); |
| 2114 | } |
| 2115 | } else { |
| 2116 | Register value = ToRegister(instr->value()); |
| 2117 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 2118 | __ mov_b(operand, value); |
| 2119 | } else { |
| 2120 | __ mov_w(operand, value); |
| 2121 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2122 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2126 | void LCodeGen::DoThrow(LThrow* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2127 | __ push(ToOperand(instr->value())); |
| 2128 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 2129 | CallRuntime(Runtime::kThrow, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2130 | |
| 2131 | if (FLAG_debug_code) { |
| 2132 | Comment("Unreachable code."); |
| 2133 | __ int3(); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | |
| 2138 | void LCodeGen::DoAddI(LAddI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2139 | LOperand* left = instr->left(); |
| 2140 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2141 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2142 | if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) { |
| 2143 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2144 | int32_t offset = ToRepresentation(LConstantOperand::cast(right), |
| 2145 | instr->hydrogen()->representation()); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2146 | __ lea(ToRegister(instr->result()), MemOperand(ToRegister(left), offset)); |
| 2147 | } else { |
| 2148 | Operand address(ToRegister(left), ToRegister(right), times_1, 0); |
| 2149 | __ lea(ToRegister(instr->result()), address); |
| 2150 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2151 | } else { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2152 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2153 | __ add(ToOperand(left), |
| 2154 | ToImmediate(right, instr->hydrogen()->representation())); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2155 | } else { |
| 2156 | __ add(ToRegister(left), ToOperand(right)); |
| 2157 | } |
| 2158 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 2159 | DeoptimizeIf(overflow, instr->environment()); |
| 2160 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2165 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2166 | CpuFeatureScope scope(masm(), SSE2); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2167 | LOperand* left = instr->left(); |
| 2168 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2169 | ASSERT(left->Equals(instr->result())); |
| 2170 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2171 | if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2172 | Label return_left; |
| 2173 | Condition condition = (operation == HMathMinMax::kMathMin) |
| 2174 | ? less_equal |
| 2175 | : greater_equal; |
| 2176 | if (right->IsConstantOperand()) { |
| 2177 | Operand left_op = ToOperand(left); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2178 | Immediate immediate = ToImmediate(LConstantOperand::cast(instr->right()), |
| 2179 | instr->hydrogen()->representation()); |
| 2180 | __ cmp(left_op, immediate); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2181 | __ j(condition, &return_left, Label::kNear); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2182 | __ mov(left_op, immediate); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2183 | } else { |
| 2184 | Register left_reg = ToRegister(left); |
| 2185 | Operand right_op = ToOperand(right); |
| 2186 | __ cmp(left_reg, right_op); |
| 2187 | __ j(condition, &return_left, Label::kNear); |
| 2188 | __ mov(left_reg, right_op); |
| 2189 | } |
| 2190 | __ bind(&return_left); |
| 2191 | } else { |
| 2192 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
| 2193 | Label check_nan_left, check_zero, return_left, return_right; |
| 2194 | Condition condition = (operation == HMathMinMax::kMathMin) ? below : above; |
| 2195 | XMMRegister left_reg = ToDoubleRegister(left); |
| 2196 | XMMRegister right_reg = ToDoubleRegister(right); |
| 2197 | __ ucomisd(left_reg, right_reg); |
| 2198 | __ j(parity_even, &check_nan_left, Label::kNear); // At least one NaN. |
| 2199 | __ j(equal, &check_zero, Label::kNear); // left == right. |
| 2200 | __ j(condition, &return_left, Label::kNear); |
| 2201 | __ jmp(&return_right, Label::kNear); |
| 2202 | |
| 2203 | __ bind(&check_zero); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2204 | XMMRegister xmm_scratch = double_scratch0(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2205 | __ xorps(xmm_scratch, xmm_scratch); |
| 2206 | __ ucomisd(left_reg, xmm_scratch); |
| 2207 | __ j(not_equal, &return_left, Label::kNear); // left == right != 0. |
| 2208 | // At this point, both left and right are either 0 or -0. |
| 2209 | if (operation == HMathMinMax::kMathMin) { |
| 2210 | __ orpd(left_reg, right_reg); |
| 2211 | } else { |
| 2212 | // Since we operate on +0 and/or -0, addsd and andsd have the same effect. |
| 2213 | __ addsd(left_reg, right_reg); |
| 2214 | } |
| 2215 | __ jmp(&return_left, Label::kNear); |
| 2216 | |
| 2217 | __ bind(&check_nan_left); |
| 2218 | __ ucomisd(left_reg, left_reg); // NaN check. |
| 2219 | __ j(parity_even, &return_left, Label::kNear); // left == NaN. |
| 2220 | __ bind(&return_right); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 2221 | __ movaps(left_reg, right_reg); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2222 | |
| 2223 | __ bind(&return_left); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2228 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2229 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 2230 | CpuFeatureScope scope(masm(), SSE2); |
| 2231 | XMMRegister left = ToDoubleRegister(instr->left()); |
| 2232 | XMMRegister right = ToDoubleRegister(instr->right()); |
| 2233 | XMMRegister result = ToDoubleRegister(instr->result()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2234 | switch (instr->op()) { |
| 2235 | case Token::ADD: |
| 2236 | __ addsd(left, right); |
| 2237 | break; |
| 2238 | case Token::SUB: |
| 2239 | __ subsd(left, right); |
| 2240 | break; |
| 2241 | case Token::MUL: |
| 2242 | __ mulsd(left, right); |
| 2243 | break; |
| 2244 | case Token::DIV: |
| 2245 | __ divsd(left, right); |
| 2246 | // Don't delete this mov. It may improve performance on some CPUs, |
| 2247 | // when there is a mulsd depending on the result |
| 2248 | __ movaps(left, left); |
| 2249 | break; |
| 2250 | case Token::MOD: { |
| 2251 | // Pass two doubles as arguments on the stack. |
| 2252 | __ PrepareCallCFunction(4, eax); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2253 | __ movsd(Operand(esp, 0 * kDoubleSize), left); |
| 2254 | __ movsd(Operand(esp, 1 * kDoubleSize), right); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2255 | __ CallCFunction( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 2256 | ExternalReference::mod_two_doubles_operation(isolate()), |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2257 | 4); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2258 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2259 | // Return value is in st(0) on ia32. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2260 | // Store it into the result register. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2261 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
| 2262 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2263 | __ movsd(result, Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2264 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 2265 | break; |
| 2266 | } |
| 2267 | default: |
| 2268 | UNREACHABLE(); |
| 2269 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2270 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2271 | } else { |
| 2272 | X87Register left = ToX87Register(instr->left()); |
| 2273 | X87Register right = ToX87Register(instr->right()); |
| 2274 | X87Register result = ToX87Register(instr->result()); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2275 | if (instr->op() != Token::MOD) { |
| 2276 | X87PrepareBinaryOp(left, right, result); |
| 2277 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2278 | switch (instr->op()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2279 | case Token::ADD: |
| 2280 | __ fadd_i(1); |
| 2281 | break; |
| 2282 | case Token::SUB: |
| 2283 | __ fsub_i(1); |
| 2284 | break; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2285 | case Token::MUL: |
| 2286 | __ fmul_i(1); |
| 2287 | break; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2288 | case Token::DIV: |
| 2289 | __ fdiv_i(1); |
| 2290 | break; |
| 2291 | case Token::MOD: { |
| 2292 | // Pass two doubles as arguments on the stack. |
| 2293 | __ PrepareCallCFunction(4, eax); |
| 2294 | X87Mov(Operand(esp, 1 * kDoubleSize), right); |
| 2295 | X87Mov(Operand(esp, 0), left); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 2296 | X87Free(right); |
| 2297 | ASSERT(left.is(result)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2298 | X87PrepareToWrite(result); |
| 2299 | __ CallCFunction( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 2300 | ExternalReference::mod_two_doubles_operation(isolate()), |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2301 | 4); |
| 2302 | |
| 2303 | // Return value is in st(0) on ia32. |
| 2304 | X87CommitWrite(result); |
| 2305 | break; |
| 2306 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2307 | default: |
| 2308 | UNREACHABLE(); |
| 2309 | break; |
| 2310 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | |
| 2315 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2316 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 2317 | ASSERT(ToRegister(instr->left()).is(edx)); |
| 2318 | ASSERT(ToRegister(instr->right()).is(eax)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2319 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2320 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2321 | BinaryOpICStub stub(instr->op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2322 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2323 | __ nop(); // Signals no inlined code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2327 | template<class InstrType> |
| 2328 | void LCodeGen::EmitBranch(InstrType instr, Condition cc) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2329 | int left_block = instr->TrueDestination(chunk_); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2330 | int right_block = instr->FalseDestination(chunk_); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2331 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2332 | int next_block = GetNextEmittedBlock(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2333 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2334 | if (right_block == left_block || cc == no_condition) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2335 | EmitGoto(left_block); |
| 2336 | } else if (left_block == next_block) { |
| 2337 | __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 2338 | } else if (right_block == next_block) { |
| 2339 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2340 | } else { |
| 2341 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2342 | __ jmp(chunk_->GetAssemblyLabel(right_block)); |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2347 | template<class InstrType> |
| 2348 | void LCodeGen::EmitFalseBranch(InstrType instr, Condition cc) { |
| 2349 | int false_block = instr->FalseDestination(chunk_); |
| 2350 | if (cc == no_condition) { |
| 2351 | __ jmp(chunk_->GetAssemblyLabel(false_block)); |
| 2352 | } else { |
| 2353 | __ j(cc, chunk_->GetAssemblyLabel(false_block)); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2358 | void LCodeGen::DoBranch(LBranch* instr) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2359 | Representation r = instr->hydrogen()->value()->representation(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2360 | if (r.IsSmiOrInteger32()) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2361 | Register reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2362 | __ test(reg, Operand(reg)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2363 | EmitBranch(instr, not_zero); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2364 | } else if (r.IsDouble()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2365 | ASSERT(!info()->IsStub()); |
| 2366 | CpuFeatureScope scope(masm(), SSE2); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2367 | XMMRegister reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2368 | XMMRegister xmm_scratch = double_scratch0(); |
| 2369 | __ xorps(xmm_scratch, xmm_scratch); |
| 2370 | __ ucomisd(reg, xmm_scratch); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2371 | EmitBranch(instr, not_equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2372 | } else { |
| 2373 | ASSERT(r.IsTagged()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2374 | Register reg = ToRegister(instr->value()); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2375 | HType type = instr->hydrogen()->value()->type(); |
| 2376 | if (type.IsBoolean()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2377 | ASSERT(!info()->IsStub()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2378 | __ cmp(reg, factory()->true_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2379 | EmitBranch(instr, equal); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2380 | } else if (type.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2381 | ASSERT(!info()->IsStub()); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2382 | __ test(reg, Operand(reg)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2383 | EmitBranch(instr, not_equal); |
| 2384 | } else if (type.IsJSArray()) { |
| 2385 | ASSERT(!info()->IsStub()); |
| 2386 | EmitBranch(instr, no_condition); |
| 2387 | } else if (type.IsHeapNumber()) { |
| 2388 | ASSERT(!info()->IsStub()); |
| 2389 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2390 | XMMRegister xmm_scratch = double_scratch0(); |
| 2391 | __ xorps(xmm_scratch, xmm_scratch); |
| 2392 | __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2393 | EmitBranch(instr, not_equal); |
| 2394 | } else if (type.IsString()) { |
| 2395 | ASSERT(!info()->IsStub()); |
| 2396 | __ cmp(FieldOperand(reg, String::kLengthOffset), Immediate(0)); |
| 2397 | EmitBranch(instr, not_equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2398 | } else { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2399 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2400 | if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2401 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2402 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2403 | // undefined -> false. |
| 2404 | __ cmp(reg, factory()->undefined_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2405 | __ j(equal, instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2406 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2407 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2408 | // true -> true. |
| 2409 | __ cmp(reg, factory()->true_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2410 | __ j(equal, instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2411 | // false -> false. |
| 2412 | __ cmp(reg, factory()->false_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2413 | __ j(equal, instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2414 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2415 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2416 | // 'null' -> false. |
| 2417 | __ cmp(reg, factory()->null_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2418 | __ j(equal, instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 2422 | // Smis: 0 -> false, all other -> true. |
| 2423 | __ test(reg, Operand(reg)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2424 | __ j(equal, instr->FalseLabel(chunk_)); |
| 2425 | __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2426 | } else if (expected.NeedsMap()) { |
| 2427 | // If we need a map later and have a Smi -> deopt. |
| 2428 | __ test(reg, Immediate(kSmiTagMask)); |
| 2429 | DeoptimizeIf(zero, instr->environment()); |
| 2430 | } |
| 2431 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2432 | Register map = no_reg; // Keep the compiler happy. |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2433 | if (expected.NeedsMap()) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2434 | map = ToRegister(instr->temp()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2435 | ASSERT(!map.is(reg)); |
| 2436 | __ mov(map, FieldOperand(reg, HeapObject::kMapOffset)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2437 | |
| 2438 | if (expected.CanBeUndetectable()) { |
| 2439 | // Undetectable -> false. |
| 2440 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 2441 | 1 << Map::kIsUndetectable); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2442 | __ j(not_zero, instr->FalseLabel(chunk_)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2443 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2447 | // spec object -> true. |
| 2448 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2449 | __ j(above_equal, instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 2453 | // String value -> false iff empty. |
| 2454 | Label not_string; |
| 2455 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 2456 | __ j(above_equal, ¬_string, Label::kNear); |
| 2457 | __ cmp(FieldOperand(reg, String::kLengthOffset), Immediate(0)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2458 | __ j(not_zero, instr->TrueLabel(chunk_)); |
| 2459 | __ jmp(instr->FalseLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2460 | __ bind(¬_string); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2463 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2464 | // Symbol value -> true. |
| 2465 | __ CmpInstanceType(map, SYMBOL_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2466 | __ j(equal, instr->TrueLabel(chunk_)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2469 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2470 | // heap number -> false iff +0, -0, or NaN. |
| 2471 | Label not_heap_number; |
| 2472 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 2473 | factory()->heap_number_map()); |
| 2474 | __ j(not_equal, ¬_heap_number, Label::kNear); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2475 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 2476 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2477 | XMMRegister xmm_scratch = double_scratch0(); |
| 2478 | __ xorps(xmm_scratch, xmm_scratch); |
| 2479 | __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset)); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2480 | } else { |
| 2481 | __ fldz(); |
| 2482 | __ fld_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
| 2483 | __ FCmp(); |
| 2484 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2485 | __ j(zero, instr->FalseLabel(chunk_)); |
| 2486 | __ jmp(instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2487 | __ bind(¬_heap_number); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2490 | if (!expected.IsGeneric()) { |
| 2491 | // We've seen something for the first time -> deopt. |
| 2492 | // This can only happen if we are not generic already. |
| 2493 | DeoptimizeIf(no_condition, instr->environment()); |
| 2494 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2500 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2501 | if (!IsNextEmittedBlock(block)) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2502 | __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 2507 | void LCodeGen::DoClobberDoubles(LClobberDoubles* instr) { |
| 2508 | } |
| 2509 | |
| 2510 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2511 | void LCodeGen::DoGoto(LGoto* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2512 | EmitGoto(instr->block_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | |
| 2516 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
| 2517 | Condition cond = no_condition; |
| 2518 | switch (op) { |
| 2519 | case Token::EQ: |
| 2520 | case Token::EQ_STRICT: |
| 2521 | cond = equal; |
| 2522 | break; |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2523 | case Token::NE: |
| 2524 | case Token::NE_STRICT: |
| 2525 | cond = not_equal; |
| 2526 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2527 | case Token::LT: |
| 2528 | cond = is_unsigned ? below : less; |
| 2529 | break; |
| 2530 | case Token::GT: |
| 2531 | cond = is_unsigned ? above : greater; |
| 2532 | break; |
| 2533 | case Token::LTE: |
| 2534 | cond = is_unsigned ? below_equal : less_equal; |
| 2535 | break; |
| 2536 | case Token::GTE: |
| 2537 | cond = is_unsigned ? above_equal : greater_equal; |
| 2538 | break; |
| 2539 | case Token::IN: |
| 2540 | case Token::INSTANCEOF: |
| 2541 | default: |
| 2542 | UNREACHABLE(); |
| 2543 | } |
| 2544 | return cond; |
| 2545 | } |
| 2546 | |
| 2547 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2548 | void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2549 | LOperand* left = instr->left(); |
| 2550 | LOperand* right = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2551 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2552 | |
| 2553 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2554 | // We can statically evaluate the comparison. |
| 2555 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2556 | double right_val = ToDouble(LConstantOperand::cast(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2557 | int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
| 2558 | instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2559 | EmitGoto(next_block); |
| 2560 | } else { |
| 2561 | if (instr->is_double()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2562 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 2563 | CpuFeatureScope scope(masm(), SSE2); |
| 2564 | __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 2565 | } else { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2566 | X87LoadForUsage(ToX87Register(right), ToX87Register(left)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2567 | __ FCmp(); |
| 2568 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2569 | // Don't base result on EFLAGS when a NaN is involved. Instead |
| 2570 | // jump to the false block. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2571 | __ j(parity_even, instr->FalseLabel(chunk_)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2572 | } else { |
| 2573 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2574 | __ cmp(ToOperand(left), |
| 2575 | ToImmediate(right, instr->hydrogen()->representation())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2576 | } else if (left->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2577 | __ cmp(ToOperand(right), |
| 2578 | ToImmediate(left, instr->hydrogen()->representation())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2579 | // We transposed the operands. Reverse the condition. |
| 2580 | cc = ReverseCondition(cc); |
| 2581 | } else { |
| 2582 | __ cmp(ToRegister(left), ToOperand(right)); |
| 2583 | } |
| 2584 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2585 | EmitBranch(instr, cc); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2586 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 2590 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2591 | Register left = ToRegister(instr->left()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2592 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2593 | if (instr->right()->IsConstantOperand()) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2594 | Handle<Object> right = ToHandle(LConstantOperand::cast(instr->right())); |
| 2595 | __ CmpObject(left, right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2596 | } else { |
| 2597 | Operand right = ToOperand(instr->right()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2598 | __ cmp(left, right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2599 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2600 | EmitBranch(instr, equal); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2604 | void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2605 | if (instr->hydrogen()->representation().IsTagged()) { |
| 2606 | Register input_reg = ToRegister(instr->object()); |
| 2607 | __ cmp(input_reg, factory()->the_hole_value()); |
| 2608 | EmitBranch(instr, equal); |
| 2609 | return; |
| 2610 | } |
| 2611 | |
| 2612 | bool use_sse2 = CpuFeatures::IsSupported(SSE2); |
| 2613 | if (use_sse2) { |
| 2614 | CpuFeatureScope scope(masm(), SSE2); |
| 2615 | XMMRegister input_reg = ToDoubleRegister(instr->object()); |
| 2616 | __ ucomisd(input_reg, input_reg); |
| 2617 | EmitFalseBranch(instr, parity_odd); |
| 2618 | } else { |
| 2619 | // Put the value to the top of stack |
| 2620 | X87Register src = ToX87Register(instr->object()); |
| 2621 | X87LoadForUsage(src); |
| 2622 | __ fld(0); |
| 2623 | __ fld(0); |
| 2624 | __ FCmp(); |
| 2625 | Label ok; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2626 | __ j(parity_even, &ok, Label::kNear); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2627 | __ fstp(0); |
| 2628 | EmitFalseBranch(instr, no_condition); |
| 2629 | __ bind(&ok); |
| 2630 | } |
| 2631 | |
| 2632 | |
| 2633 | __ sub(esp, Immediate(kDoubleSize)); |
| 2634 | if (use_sse2) { |
| 2635 | CpuFeatureScope scope(masm(), SSE2); |
| 2636 | XMMRegister input_reg = ToDoubleRegister(instr->object()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2637 | __ movsd(MemOperand(esp, 0), input_reg); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2638 | } else { |
| 2639 | __ fstp_d(MemOperand(esp, 0)); |
| 2640 | } |
| 2641 | |
| 2642 | __ add(esp, Immediate(kDoubleSize)); |
| 2643 | int offset = sizeof(kHoleNanUpper32); |
| 2644 | __ cmp(MemOperand(esp, -offset), Immediate(kHoleNanUpper32)); |
| 2645 | EmitBranch(instr, equal); |
| 2646 | } |
| 2647 | |
| 2648 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2649 | void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
| 2650 | Representation rep = instr->hydrogen()->value()->representation(); |
| 2651 | ASSERT(!rep.IsInteger32()); |
| 2652 | Register scratch = ToRegister(instr->temp()); |
| 2653 | |
| 2654 | if (rep.IsDouble()) { |
| 2655 | CpuFeatureScope use_sse2(masm(), SSE2); |
| 2656 | XMMRegister value = ToDoubleRegister(instr->value()); |
| 2657 | XMMRegister xmm_scratch = double_scratch0(); |
| 2658 | __ xorps(xmm_scratch, xmm_scratch); |
| 2659 | __ ucomisd(xmm_scratch, value); |
| 2660 | EmitFalseBranch(instr, not_equal); |
| 2661 | __ movmskpd(scratch, value); |
| 2662 | __ test(scratch, Immediate(1)); |
| 2663 | EmitBranch(instr, not_zero); |
| 2664 | } else { |
| 2665 | Register value = ToRegister(instr->value()); |
| 2666 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 2667 | __ CheckMap(value, map, instr->FalseLabel(chunk()), DO_SMI_CHECK); |
| 2668 | __ cmp(FieldOperand(value, HeapNumber::kExponentOffset), |
| 2669 | Immediate(0x80000000)); |
| 2670 | EmitFalseBranch(instr, not_equal); |
| 2671 | __ cmp(FieldOperand(value, HeapNumber::kMantissaOffset), |
| 2672 | Immediate(0x00000000)); |
| 2673 | EmitBranch(instr, equal); |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2678 | Condition LCodeGen::EmitIsObject(Register input, |
| 2679 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2680 | Label* is_not_object, |
| 2681 | Label* is_object) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2682 | __ JumpIfSmi(input, is_not_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2683 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2684 | __ cmp(input, isolate()->factory()->null_value()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2685 | __ j(equal, is_object); |
| 2686 | |
| 2687 | __ mov(temp1, FieldOperand(input, HeapObject::kMapOffset)); |
| 2688 | // Undetectable objects behave like undefined. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2689 | __ test_b(FieldOperand(temp1, Map::kBitFieldOffset), |
| 2690 | 1 << Map::kIsUndetectable); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2691 | __ j(not_zero, is_not_object); |
| 2692 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2693 | __ movzx_b(temp1, FieldOperand(temp1, Map::kInstanceTypeOffset)); |
| 2694 | __ cmp(temp1, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2695 | __ j(below, is_not_object); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2696 | __ cmp(temp1, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2697 | return below_equal; |
| 2698 | } |
| 2699 | |
| 2700 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2701 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2702 | Register reg = ToRegister(instr->value()); |
| 2703 | Register temp = ToRegister(instr->temp()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2704 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2705 | Condition true_cond = EmitIsObject( |
| 2706 | reg, temp, instr->FalseLabel(chunk_), instr->TrueLabel(chunk_)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2707 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2708 | EmitBranch(instr, true_cond); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2712 | Condition LCodeGen::EmitIsString(Register input, |
| 2713 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2714 | Label* is_not_string, |
| 2715 | SmiCheck check_needed = INLINE_SMI_CHECK) { |
| 2716 | if (check_needed == INLINE_SMI_CHECK) { |
| 2717 | __ JumpIfSmi(input, is_not_string); |
| 2718 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2719 | |
| 2720 | Condition cond = masm_->IsObjectStringType(input, temp1, temp1); |
| 2721 | |
| 2722 | return cond; |
| 2723 | } |
| 2724 | |
| 2725 | |
| 2726 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2727 | Register reg = ToRegister(instr->value()); |
| 2728 | Register temp = ToRegister(instr->temp()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2729 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2730 | SmiCheck check_needed = |
| 2731 | instr->hydrogen()->value()->IsHeapObject() |
| 2732 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2733 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2734 | Condition true_cond = EmitIsString( |
| 2735 | reg, temp, instr->FalseLabel(chunk_), check_needed); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2736 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2737 | EmitBranch(instr, true_cond); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2741 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2742 | Operand input = ToOperand(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2743 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2744 | __ test(input, Immediate(kSmiTagMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2745 | EmitBranch(instr, zero); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2749 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2750 | Register input = ToRegister(instr->value()); |
| 2751 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2752 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2753 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2754 | STATIC_ASSERT(kSmiTag == 0); |
| 2755 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2756 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2757 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
| 2758 | __ test_b(FieldOperand(temp, Map::kBitFieldOffset), |
| 2759 | 1 << Map::kIsUndetectable); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2760 | EmitBranch(instr, not_zero); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2764 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2765 | switch (op) { |
| 2766 | case Token::EQ_STRICT: |
| 2767 | case Token::EQ: |
| 2768 | return equal; |
| 2769 | case Token::LT: |
| 2770 | return less; |
| 2771 | case Token::GT: |
| 2772 | return greater; |
| 2773 | case Token::LTE: |
| 2774 | return less_equal; |
| 2775 | case Token::GTE: |
| 2776 | return greater_equal; |
| 2777 | default: |
| 2778 | UNREACHABLE(); |
| 2779 | return no_condition; |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | |
| 2784 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 2785 | Token::Value op = instr->op(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2786 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2787 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2788 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2789 | |
| 2790 | Condition condition = ComputeCompareCondition(op); |
| 2791 | __ test(eax, Operand(eax)); |
| 2792 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2793 | EmitBranch(instr, condition); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2797 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2798 | InstanceType from = instr->from(); |
| 2799 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2800 | if (from == FIRST_TYPE) return to; |
| 2801 | ASSERT(from == to || to == LAST_TYPE); |
| 2802 | return from; |
| 2803 | } |
| 2804 | |
| 2805 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2806 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2807 | InstanceType from = instr->from(); |
| 2808 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2809 | if (from == to) return equal; |
| 2810 | if (to == LAST_TYPE) return above_equal; |
| 2811 | if (from == FIRST_TYPE) return below_equal; |
| 2812 | UNREACHABLE(); |
| 2813 | return equal; |
| 2814 | } |
| 2815 | |
| 2816 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2817 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2818 | Register input = ToRegister(instr->value()); |
| 2819 | Register temp = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2820 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2821 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2822 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2823 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2824 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2825 | __ CmpObjectType(input, TestType(instr->hydrogen()), temp); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2826 | EmitBranch(instr, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2830 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2831 | Register input = ToRegister(instr->value()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2832 | Register result = ToRegister(instr->result()); |
| 2833 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2834 | __ AssertString(input); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2835 | |
| 2836 | __ mov(result, FieldOperand(input, String::kHashFieldOffset)); |
| 2837 | __ IndexFromHash(result, result); |
| 2838 | } |
| 2839 | |
| 2840 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2841 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2842 | LHasCachedArrayIndexAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2843 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2844 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2845 | __ test(FieldOperand(input, String::kHashFieldOffset), |
| 2846 | Immediate(String::kContainsCachedArrayIndexMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2847 | EmitBranch(instr, equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | |
| 2851 | // 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] | 2852 | // the temp registers, but not the input. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2853 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2854 | Label* is_false, |
| 2855 | Handle<String>class_name, |
| 2856 | Register input, |
| 2857 | Register temp, |
| 2858 | Register temp2) { |
| 2859 | ASSERT(!input.is(temp)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2860 | ASSERT(!input.is(temp2)); |
| 2861 | ASSERT(!temp.is(temp2)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2862 | __ JumpIfSmi(input, is_false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2863 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2864 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2865 | // Assuming the following assertions, we can use the same compares to test |
| 2866 | // for both being a function type and being in the object type range. |
| 2867 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2868 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2869 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2870 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2871 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2872 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2873 | __ CmpObjectType(input, FIRST_SPEC_OBJECT_TYPE, temp); |
| 2874 | __ j(below, is_false); |
| 2875 | __ j(equal, is_true); |
| 2876 | __ CmpInstanceType(temp, LAST_SPEC_OBJECT_TYPE); |
| 2877 | __ j(equal, is_true); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2878 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2879 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2880 | // actual type and do a signed compare with the width of the type range. |
| 2881 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2882 | __ movzx_b(temp2, FieldOperand(temp, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2883 | __ sub(Operand(temp2), Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2884 | __ cmp(Operand(temp2), Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2885 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2886 | __ j(above, is_false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2889 | // 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] | 2890 | // Check if the constructor in the map is a function. |
| 2891 | __ mov(temp, FieldOperand(temp, Map::kConstructorOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2892 | // Objects with a non-function constructor have class 'Object'. |
| 2893 | __ CmpObjectType(temp, JS_FUNCTION_TYPE, temp2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2894 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2895 | __ j(not_equal, is_true); |
| 2896 | } else { |
| 2897 | __ j(not_equal, is_false); |
| 2898 | } |
| 2899 | |
| 2900 | // temp now contains the constructor function. Grab the |
| 2901 | // instance class name from there. |
| 2902 | __ mov(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2903 | __ mov(temp, FieldOperand(temp, |
| 2904 | SharedFunctionInfo::kInstanceClassNameOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2905 | // The class name we are testing against is internalized since it's a literal. |
| 2906 | // The name in the constructor is internalized because of the way the context |
| 2907 | // 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] | 2908 | // 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] | 2909 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2910 | // identity comparison. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2911 | __ cmp(temp, class_name); |
| 2912 | // End with the answer in the z flag. |
| 2913 | } |
| 2914 | |
| 2915 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2916 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2917 | Register input = ToRegister(instr->value()); |
| 2918 | Register temp = ToRegister(instr->temp()); |
| 2919 | Register temp2 = ToRegister(instr->temp2()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2920 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2921 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2922 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2923 | EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2924 | class_name, input, temp, temp2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2925 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2926 | EmitBranch(instr, equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | |
| 2930 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2931 | Register reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2932 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2933 | EmitBranch(instr, equal); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | |
| 2937 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2938 | // Object and function are in fixed registers defined by the stub. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2939 | ASSERT(ToRegister(instr->context()).is(esi)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2940 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2941 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2942 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2943 | Label true_value, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2944 | __ test(eax, Operand(eax)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2945 | __ j(zero, &true_value, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2946 | __ mov(ToRegister(instr->result()), factory()->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2947 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2948 | __ bind(&true_value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2949 | __ mov(ToRegister(instr->result()), factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2950 | __ bind(&done); |
| 2951 | } |
| 2952 | |
| 2953 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2954 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2955 | class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2956 | public: |
| 2957 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2958 | LInstanceOfKnownGlobal* instr, |
| 2959 | const X87Stack& x87_stack) |
| 2960 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2961 | virtual void Generate() V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2962 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2963 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2964 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2965 | Label* map_check() { return &map_check_; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2966 | private: |
| 2967 | LInstanceOfKnownGlobal* instr_; |
| 2968 | Label map_check_; |
| 2969 | }; |
| 2970 | |
| 2971 | DeferredInstanceOfKnownGlobal* deferred; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2972 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr, x87_stack_); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2973 | |
| 2974 | Label done, false_result; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2975 | Register object = ToRegister(instr->value()); |
| 2976 | Register temp = ToRegister(instr->temp()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2977 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2978 | // A Smi is not an instance of anything. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2979 | __ JumpIfSmi(object, &false_result, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2980 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2981 | // 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] | 2982 | // hole value will be patched to the last map/result pair generated by the |
| 2983 | // instanceof stub. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2984 | Label cache_miss; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2985 | Register map = ToRegister(instr->temp()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2986 | __ mov(map, FieldOperand(object, HeapObject::kMapOffset)); |
| 2987 | __ bind(deferred->map_check()); // Label for calculating code patching. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2988 | Handle<Cell> cache_cell = factory()->NewCell(factory()->the_hole_value()); |
| 2989 | __ cmp(map, Operand::ForCell(cache_cell)); // Patched to cached map. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2990 | __ j(not_equal, &cache_miss, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2991 | __ 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] | 2992 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2993 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2994 | // The inlined call site cache did not match. Check for null and string |
| 2995 | // before calling the deferred code. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2996 | __ bind(&cache_miss); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2997 | // Null is not an instance of anything. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2998 | __ cmp(object, factory()->null_value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2999 | __ j(equal, &false_result, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3000 | |
| 3001 | // String values are not instances of anything. |
| 3002 | Condition is_string = masm_->IsObjectStringType(object, temp, temp); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3003 | __ j(is_string, &false_result, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3004 | |
| 3005 | // Go to the deferred code. |
| 3006 | __ jmp(deferred->entry()); |
| 3007 | |
| 3008 | __ bind(&false_result); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3009 | __ mov(ToRegister(instr->result()), factory()->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3010 | |
| 3011 | // Here result has either true or false. Deferred code also produces true or |
| 3012 | // false object. |
| 3013 | __ bind(deferred->exit()); |
| 3014 | __ bind(&done); |
| 3015 | } |
| 3016 | |
| 3017 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3018 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 3019 | Label* map_check) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3020 | PushSafepointRegistersScope scope(this); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3021 | |
| 3022 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 3023 | flags = static_cast<InstanceofStub::Flags>( |
| 3024 | flags | InstanceofStub::kArgsInRegisters); |
| 3025 | flags = static_cast<InstanceofStub::Flags>( |
| 3026 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 3027 | flags = static_cast<InstanceofStub::Flags>( |
| 3028 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 3029 | InstanceofStub stub(flags); |
| 3030 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3031 | // Get the temp register reserved by the instruction. This needs to be a |
| 3032 | // register which is pushed last by PushSafepointRegisters as top of the |
| 3033 | // stack is used to pass the offset to the location of the map check to |
| 3034 | // the stub. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3035 | Register temp = ToRegister(instr->temp()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3036 | ASSERT(MacroAssembler::SafepointRegisterStackIndex(temp) == 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3037 | __ LoadHeapObject(InstanceofStub::right(), instr->function()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3038 | static const int kAdditionalDelta = 13; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3039 | int delta = masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3040 | __ mov(temp, Immediate(delta)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3041 | __ StoreToSafepointRegisterSlot(temp, temp); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3042 | CallCodeGeneric(stub.GetCode(isolate()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3043 | RelocInfo::CODE_TARGET, |
| 3044 | instr, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3045 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3046 | // Get the deoptimization index of the LLazyBailout-environment that |
| 3047 | // corresponds to this instruction. |
| 3048 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3049 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
| 3050 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3051 | // 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] | 3052 | __ StoreToSafepointRegisterSlot(eax, eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3056 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 3057 | Token::Value op = instr->op(); |
| 3058 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3059 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3060 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3061 | |
| 3062 | Condition condition = ComputeCompareCondition(op); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3063 | Label true_value, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3064 | __ test(eax, Operand(eax)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3065 | __ j(condition, &true_value, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3066 | __ mov(ToRegister(instr->result()), factory()->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3067 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3068 | __ bind(&true_value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3069 | __ mov(ToRegister(instr->result()), factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3070 | __ bind(&done); |
| 3071 | } |
| 3072 | |
| 3073 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3074 | void LCodeGen::EmitReturn(LReturn* instr, bool dynamic_frame_alignment) { |
| 3075 | int extra_value_count = dynamic_frame_alignment ? 2 : 1; |
| 3076 | |
| 3077 | if (instr->has_constant_parameter_count()) { |
| 3078 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 3079 | if (dynamic_frame_alignment && FLAG_debug_code) { |
| 3080 | __ cmp(Operand(esp, |
| 3081 | (parameter_count + extra_value_count) * kPointerSize), |
| 3082 | Immediate(kAlignmentZapValue)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3083 | __ Assert(equal, kExpectedAlignmentMarker); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3084 | } |
| 3085 | __ Ret((parameter_count + extra_value_count) * kPointerSize, ecx); |
| 3086 | } else { |
| 3087 | Register reg = ToRegister(instr->parameter_count()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3088 | // The argument count parameter is a smi |
| 3089 | __ SmiUntag(reg); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3090 | Register return_addr_reg = reg.is(ecx) ? ebx : ecx; |
| 3091 | if (dynamic_frame_alignment && FLAG_debug_code) { |
| 3092 | ASSERT(extra_value_count == 2); |
| 3093 | __ cmp(Operand(esp, reg, times_pointer_size, |
| 3094 | extra_value_count * kPointerSize), |
| 3095 | Immediate(kAlignmentZapValue)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3096 | __ Assert(equal, kExpectedAlignmentMarker); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | // emit code to restore stack based on instr->parameter_count() |
| 3100 | __ pop(return_addr_reg); // save return address |
| 3101 | if (dynamic_frame_alignment) { |
| 3102 | __ inc(reg); // 1 more for alignment |
| 3103 | } |
| 3104 | __ shl(reg, kPointerSizeLog2); |
| 3105 | __ add(esp, reg); |
| 3106 | __ jmp(return_addr_reg); |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3111 | void LCodeGen::DoReturn(LReturn* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3112 | if (FLAG_trace && info()->IsOptimizing()) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3113 | // Preserve the return value on the stack and rely on the runtime call |
| 3114 | // to return the value in the same register. We're leaving the code |
| 3115 | // managed by the register allocator and tearing down the frame, it's |
| 3116 | // safe to write to the context register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3117 | __ push(eax); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3118 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3119 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 3120 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3121 | if (info()->saves_caller_doubles() && CpuFeatures::IsSupported(SSE2)) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3122 | RestoreCallerDoubles(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3123 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3124 | if (dynamic_frame_alignment_) { |
| 3125 | // Fetch the state of the dynamic frame alignment. |
| 3126 | __ mov(edx, Operand(ebp, |
| 3127 | JavaScriptFrameConstants::kDynamicAlignmentStateOffset)); |
| 3128 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3129 | int no_frame_start = -1; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3130 | if (NeedsEagerFrame()) { |
| 3131 | __ mov(esp, ebp); |
| 3132 | __ pop(ebp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3133 | no_frame_start = masm_->pc_offset(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3134 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3135 | if (dynamic_frame_alignment_) { |
| 3136 | Label no_padding; |
| 3137 | __ cmp(edx, Immediate(kNoAlignmentPadding)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3138 | __ j(equal, &no_padding, Label::kNear); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3139 | |
| 3140 | EmitReturn(instr, true); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3141 | __ bind(&no_padding); |
| 3142 | } |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3143 | |
| 3144 | EmitReturn(instr, false); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3145 | if (no_frame_start != -1) { |
| 3146 | info()->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 3147 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3151 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3152 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3153 | __ mov(result, Operand::ForCell(instr->hydrogen()->cell().handle())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3154 | if (instr->hydrogen()->RequiresHoleCheck()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3155 | __ cmp(result, factory()->the_hole_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3156 | DeoptimizeIf(equal, instr->environment()); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3161 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 3162 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3163 | ASSERT(ToRegister(instr->global_object()).is(edx)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3164 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 3165 | |
| 3166 | __ mov(ecx, instr->name()); |
| 3167 | RelocInfo::Mode mode = instr->for_typeof() ? RelocInfo::CODE_TARGET : |
| 3168 | RelocInfo::CODE_TARGET_CONTEXT; |
| 3169 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3170 | CallCode(ic, mode, instr); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3174 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 3175 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3176 | Handle<PropertyCell> cell_handle = instr->hydrogen()->cell().handle(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3177 | |
| 3178 | // If the cell we are storing to contains the hole it could have |
| 3179 | // been deleted from the property dictionary. In that case, we need |
| 3180 | // to update the property details in the property dictionary to mark |
| 3181 | // it as no longer deleted. We deoptimize in that case. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3182 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3183 | __ cmp(Operand::ForCell(cell_handle), factory()->the_hole_value()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3184 | DeoptimizeIf(equal, instr->environment()); |
| 3185 | } |
| 3186 | |
| 3187 | // Store the value. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3188 | __ mov(Operand::ForCell(cell_handle), value); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3189 | // Cells are always rescanned, so no write barrier here. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3193 | void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { |
| 3194 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 3195 | ASSERT(ToRegister(instr->global_object()).is(edx)); |
| 3196 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 3197 | |
| 3198 | __ mov(ecx, instr->name()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3199 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3200 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3201 | : isolate()->builtins()->StoreIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3202 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3206 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3207 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3208 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3209 | __ mov(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3210 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3211 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3212 | __ cmp(result, factory()->the_hole_value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3213 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3214 | DeoptimizeIf(equal, instr->environment()); |
| 3215 | } else { |
| 3216 | Label is_not_hole; |
| 3217 | __ j(not_equal, &is_not_hole, Label::kNear); |
| 3218 | __ mov(result, factory()->undefined_value()); |
| 3219 | __ bind(&is_not_hole); |
| 3220 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3221 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | |
| 3225 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 3226 | Register context = ToRegister(instr->context()); |
| 3227 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3228 | |
| 3229 | Label skip_assignment; |
| 3230 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3231 | Operand target = ContextOperand(context, instr->slot_index()); |
| 3232 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3233 | __ cmp(target, factory()->the_hole_value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3234 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3235 | DeoptimizeIf(equal, instr->environment()); |
| 3236 | } else { |
| 3237 | __ j(not_equal, &skip_assignment, Label::kNear); |
| 3238 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3239 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3240 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3241 | __ mov(target, value); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3242 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3243 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3244 | instr->hydrogen()->value()->IsHeapObject() |
| 3245 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3246 | Register temp = ToRegister(instr->temp()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3247 | int offset = Context::SlotOffset(instr->slot_index()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3248 | __ RecordWriteContextSlot(context, |
| 3249 | offset, |
| 3250 | value, |
| 3251 | temp, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3252 | GetSaveFPRegsMode(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3253 | EMIT_REMEMBERED_SET, |
| 3254 | check_needed); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3255 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3256 | |
| 3257 | __ bind(&skip_assignment); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3261 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3262 | HObjectAccess access = instr->hydrogen()->access(); |
| 3263 | int offset = access.offset(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3264 | |
| 3265 | if (access.IsExternalMemory()) { |
| 3266 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3267 | MemOperand operand = instr->object()->IsConstantOperand() |
| 3268 | ? MemOperand::StaticVariable(ToExternalReference( |
| 3269 | LConstantOperand::cast(instr->object()))) |
| 3270 | : MemOperand(ToRegister(instr->object()), offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3271 | __ Load(result, operand, access.representation()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3272 | return; |
| 3273 | } |
| 3274 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3275 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3276 | if (FLAG_track_double_fields && |
| 3277 | instr->hydrogen()->representation().IsDouble()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3278 | if (CpuFeatures::IsSupported(SSE2)) { |
| 3279 | CpuFeatureScope scope(masm(), SSE2); |
| 3280 | XMMRegister result = ToDoubleRegister(instr->result()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3281 | __ movsd(result, FieldOperand(object, offset)); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3282 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3283 | X87Mov(ToX87Register(instr->result()), FieldOperand(object, offset)); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3284 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3285 | return; |
| 3286 | } |
| 3287 | |
| 3288 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3289 | if (!access.IsInobject()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3290 | __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3291 | object = result; |
| 3292 | } |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3293 | __ Load(result, FieldOperand(object, offset), access.representation()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3297 | void LCodeGen::EmitPushTaggedOperand(LOperand* operand) { |
| 3298 | ASSERT(!operand->IsDoubleRegister()); |
| 3299 | if (operand->IsConstantOperand()) { |
| 3300 | Handle<Object> object = ToHandle(LConstantOperand::cast(operand)); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 3301 | AllowDeferredHandleDereference smi_check; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3302 | if (object->IsSmi()) { |
| 3303 | __ Push(Handle<Smi>::cast(object)); |
| 3304 | } else { |
| 3305 | __ PushHeapObject(Handle<HeapObject>::cast(object)); |
| 3306 | } |
| 3307 | } else if (operand->IsRegister()) { |
| 3308 | __ push(ToRegister(operand)); |
| 3309 | } else { |
| 3310 | __ push(ToOperand(operand)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3315 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3316 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3317 | ASSERT(ToRegister(instr->object()).is(edx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3318 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 3319 | |
| 3320 | __ mov(ecx, instr->name()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3321 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3322 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3326 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 3327 | Register function = ToRegister(instr->function()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3328 | Register temp = ToRegister(instr->temp()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3329 | Register result = ToRegister(instr->result()); |
| 3330 | |
| 3331 | // Check that the function really is a function. |
| 3332 | __ CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 3333 | DeoptimizeIf(not_equal, instr->environment()); |
| 3334 | |
| 3335 | // Check whether the function has an instance prototype. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3336 | Label non_instance; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3337 | __ test_b(FieldOperand(result, Map::kBitFieldOffset), |
| 3338 | 1 << Map::kHasNonInstancePrototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3339 | __ j(not_zero, &non_instance, Label::kNear); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3340 | |
| 3341 | // Get the prototype or initial map from the function. |
| 3342 | __ mov(result, |
| 3343 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3344 | |
| 3345 | // Check that the function has a prototype or an initial map. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3346 | __ cmp(Operand(result), Immediate(factory()->the_hole_value())); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3347 | DeoptimizeIf(equal, instr->environment()); |
| 3348 | |
| 3349 | // 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] | 3350 | Label done; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3351 | __ CmpObjectType(result, MAP_TYPE, temp); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3352 | __ j(not_equal, &done, Label::kNear); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3353 | |
| 3354 | // Get the prototype from the initial map. |
| 3355 | __ mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3356 | __ jmp(&done, Label::kNear); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3357 | |
| 3358 | // Non-instance prototype: Fetch prototype from constructor field |
| 3359 | // in the function's map. |
| 3360 | __ bind(&non_instance); |
| 3361 | __ mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 3362 | |
| 3363 | // All done. |
| 3364 | __ bind(&done); |
| 3365 | } |
| 3366 | |
| 3367 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3368 | void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 3369 | Register result = ToRegister(instr->result()); |
| 3370 | __ LoadRoot(result, instr->index()); |
| 3371 | } |
| 3372 | |
| 3373 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3374 | void LCodeGen::DoLoadExternalArrayPointer( |
| 3375 | LLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3376 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3377 | Register input = ToRegister(instr->object()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3378 | __ mov(result, FieldOperand(input, |
| 3379 | ExternalArray::kExternalPointerOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3383 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 3384 | Register arguments = ToRegister(instr->arguments()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3385 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3386 | if (instr->length()->IsConstantOperand() && |
| 3387 | instr->index()->IsConstantOperand()) { |
| 3388 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3389 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 3390 | int index = (const_length - const_index) + 1; |
| 3391 | __ mov(result, Operand(arguments, index * kPointerSize)); |
| 3392 | } else { |
| 3393 | Register length = ToRegister(instr->length()); |
| 3394 | Operand index = ToOperand(instr->index()); |
| 3395 | // There are two words between the frame pointer and the last argument. |
| 3396 | // Subtracting from length accounts for one of them add one more. |
| 3397 | __ sub(length, index); |
| 3398 | __ mov(result, Operand(arguments, length, times_4, kPointerSize)); |
| 3399 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3403 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3404 | ElementsKind elements_kind = instr->elements_kind(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 3405 | LOperand* key = instr->key(); |
| 3406 | if (!key->IsConstantOperand() && |
| 3407 | ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(), |
| 3408 | elements_kind)) { |
| 3409 | __ SmiUntag(ToRegister(key)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3410 | } |
| 3411 | Operand operand(BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3412 | instr->elements(), |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 3413 | key, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3414 | instr->hydrogen()->key()->representation(), |
| 3415 | elements_kind, |
| 3416 | 0, |
| 3417 | instr->additional_index())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3418 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3419 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3420 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3421 | XMMRegister result(ToDoubleRegister(instr->result())); |
| 3422 | __ movss(result, operand); |
| 3423 | __ cvtss2sd(result, result); |
| 3424 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3425 | X87Mov(ToX87Register(instr->result()), operand, kX87FloatOperand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3426 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3427 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3428 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3429 | CpuFeatureScope scope(masm(), SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3430 | __ movsd(ToDoubleRegister(instr->result()), operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3431 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3432 | X87Mov(ToX87Register(instr->result()), operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3433 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3434 | } else { |
| 3435 | Register result(ToRegister(instr->result())); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3436 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3437 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3438 | __ movsx_b(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3439 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3440 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3441 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3442 | __ movzx_b(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3443 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3444 | case EXTERNAL_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3445 | __ movsx_w(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3446 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3447 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3448 | __ movzx_w(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3449 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3450 | case EXTERNAL_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3451 | __ mov(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3452 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3453 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3454 | __ mov(result, operand); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3455 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3456 | __ test(result, Operand(result)); |
| 3457 | DeoptimizeIf(negative, instr->environment()); |
| 3458 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3459 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3460 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3461 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3462 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3463 | case FAST_ELEMENTS: |
| 3464 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3465 | case FAST_HOLEY_SMI_ELEMENTS: |
| 3466 | case FAST_HOLEY_ELEMENTS: |
| 3467 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3468 | case DICTIONARY_ELEMENTS: |
| 3469 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3470 | UNREACHABLE(); |
| 3471 | break; |
| 3472 | } |
| 3473 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3477 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3478 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3479 | int offset = FixedDoubleArray::kHeaderSize - kHeapObjectTag + |
| 3480 | sizeof(kHoleNanLower32); |
| 3481 | Operand hole_check_operand = BuildFastArrayOperand( |
| 3482 | instr->elements(), instr->key(), |
| 3483 | instr->hydrogen()->key()->representation(), |
| 3484 | FAST_DOUBLE_ELEMENTS, |
| 3485 | offset, |
| 3486 | instr->additional_index()); |
| 3487 | __ cmp(hole_check_operand, Immediate(kHoleNanUpper32)); |
| 3488 | DeoptimizeIf(equal, instr->environment()); |
| 3489 | } |
| 3490 | |
| 3491 | Operand double_load_operand = BuildFastArrayOperand( |
| 3492 | instr->elements(), |
| 3493 | instr->key(), |
| 3494 | instr->hydrogen()->key()->representation(), |
| 3495 | FAST_DOUBLE_ELEMENTS, |
| 3496 | FixedDoubleArray::kHeaderSize - kHeapObjectTag, |
| 3497 | instr->additional_index()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3498 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3499 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3500 | XMMRegister result = ToDoubleRegister(instr->result()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3501 | __ movsd(result, double_load_operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3502 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3503 | X87Mov(ToX87Register(instr->result()), double_load_operand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3504 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | |
| 3508 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3509 | Register result = ToRegister(instr->result()); |
| 3510 | |
| 3511 | // Load the result. |
| 3512 | __ mov(result, |
| 3513 | BuildFastArrayOperand(instr->elements(), |
| 3514 | instr->key(), |
| 3515 | instr->hydrogen()->key()->representation(), |
| 3516 | FAST_ELEMENTS, |
| 3517 | FixedArray::kHeaderSize - kHeapObjectTag, |
| 3518 | instr->additional_index())); |
| 3519 | |
| 3520 | // Check for the hole value. |
| 3521 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3522 | if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { |
| 3523 | __ test(result, Immediate(kSmiTagMask)); |
| 3524 | DeoptimizeIf(not_equal, instr->environment()); |
| 3525 | } else { |
| 3526 | __ cmp(result, factory()->the_hole_value()); |
| 3527 | DeoptimizeIf(equal, instr->environment()); |
| 3528 | } |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | |
| 3533 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3534 | if (instr->is_external()) { |
| 3535 | DoLoadKeyedExternalArray(instr); |
| 3536 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3537 | DoLoadKeyedFixedDoubleArray(instr); |
| 3538 | } else { |
| 3539 | DoLoadKeyedFixedArray(instr); |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | |
| 3544 | Operand LCodeGen::BuildFastArrayOperand( |
| 3545 | LOperand* elements_pointer, |
| 3546 | LOperand* key, |
| 3547 | Representation key_representation, |
| 3548 | ElementsKind elements_kind, |
| 3549 | uint32_t offset, |
| 3550 | uint32_t additional_index) { |
| 3551 | Register elements_pointer_reg = ToRegister(elements_pointer); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3552 | int element_shift_size = ElementsKindToShiftSize(elements_kind); |
| 3553 | int shift_size = element_shift_size; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3554 | if (key->IsConstantOperand()) { |
| 3555 | int constant_value = ToInteger32(LConstantOperand::cast(key)); |
| 3556 | if (constant_value & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3557 | Abort(kArrayIndexConstantValueTooBig); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3558 | } |
| 3559 | return Operand(elements_pointer_reg, |
| 3560 | ((constant_value + additional_index) << shift_size) |
| 3561 | + offset); |
| 3562 | } else { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 3563 | // Take the tag bit into account while computing the shift size. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3564 | if (key_representation.IsSmi() && (shift_size >= 1)) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 3565 | shift_size -= kSmiTagSize; |
| 3566 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3567 | ScaleFactor scale_factor = static_cast<ScaleFactor>(shift_size); |
| 3568 | return Operand(elements_pointer_reg, |
| 3569 | ToRegister(key), |
| 3570 | scale_factor, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3571 | offset + (additional_index << element_shift_size)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3576 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3577 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3578 | ASSERT(ToRegister(instr->object()).is(edx)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3579 | ASSERT(ToRegister(instr->key()).is(ecx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3580 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3581 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3582 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 3587 | Register result = ToRegister(instr->result()); |
| 3588 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3589 | if (instr->hydrogen()->from_inlined()) { |
| 3590 | __ lea(result, Operand(esp, -2 * kPointerSize)); |
| 3591 | } else { |
| 3592 | // Check for arguments adapter frame. |
| 3593 | Label done, adapted; |
| 3594 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3595 | __ mov(result, Operand(result, StandardFrameConstants::kContextOffset)); |
| 3596 | __ cmp(Operand(result), |
| 3597 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3598 | __ j(equal, &adapted, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3599 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3600 | // No arguments adaptor frame. |
| 3601 | __ mov(result, Operand(ebp)); |
| 3602 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3603 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3604 | // Arguments adaptor frame present. |
| 3605 | __ bind(&adapted); |
| 3606 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3607 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3608 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3609 | // frame below the adaptor frame if adapted. |
| 3610 | __ bind(&done); |
| 3611 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | |
| 3615 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3616 | Operand elem = ToOperand(instr->elements()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3617 | Register result = ToRegister(instr->result()); |
| 3618 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3619 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3620 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3621 | // If no arguments adaptor frame the number of arguments is fixed. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3622 | __ cmp(ebp, elem); |
| 3623 | __ mov(result, Immediate(scope()->num_parameters())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3624 | __ j(equal, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3625 | |
| 3626 | // Arguments adaptor frame present. Get argument length from there. |
| 3627 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3628 | __ mov(result, Operand(result, |
| 3629 | ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3630 | __ SmiUntag(result); |
| 3631 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3632 | // Argument length is in result register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3633 | __ bind(&done); |
| 3634 | } |
| 3635 | |
| 3636 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3637 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3638 | Register receiver = ToRegister(instr->receiver()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3639 | Register function = ToRegister(instr->function()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3640 | Register scratch = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3641 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3642 | // If the receiver is null or undefined, we have to pass the global |
| 3643 | // object as a receiver to normal functions. Values have to be |
| 3644 | // passed unchanged to builtins and strict-mode functions. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3645 | Label global_object, receiver_ok; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3646 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3647 | |
| 3648 | // Do not transform the receiver to object for strict mode |
| 3649 | // functions. |
| 3650 | __ mov(scratch, |
| 3651 | FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3652 | __ test_b(FieldOperand(scratch, SharedFunctionInfo::kStrictModeByteOffset), |
| 3653 | 1 << SharedFunctionInfo::kStrictModeBitWithinByte); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3654 | __ j(not_equal, &receiver_ok, dist); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3655 | |
| 3656 | // Do not transform the receiver to object for builtins. |
| 3657 | __ test_b(FieldOperand(scratch, SharedFunctionInfo::kNativeByteOffset), |
| 3658 | 1 << SharedFunctionInfo::kNativeBitWithinByte); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3659 | __ j(not_equal, &receiver_ok, dist); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3660 | |
| 3661 | // Normal function. Replace undefined or null with global receiver. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3662 | __ cmp(receiver, factory()->null_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3663 | __ j(equal, &global_object, Label::kNear); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3664 | __ cmp(receiver, factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3665 | __ j(equal, &global_object, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3666 | |
| 3667 | // The receiver should be a JS object. |
| 3668 | __ test(receiver, Immediate(kSmiTagMask)); |
| 3669 | DeoptimizeIf(equal, instr->environment()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3670 | __ CmpObjectType(receiver, FIRST_SPEC_OBJECT_TYPE, scratch); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3671 | DeoptimizeIf(below, instr->environment()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3672 | __ jmp(&receiver_ok, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3673 | |
| 3674 | __ bind(&global_object); |
| 3675 | // TODO(kmillikin): We have a hydrogen value for the global object. See |
| 3676 | // if it's better to use it than to explicitly fetch it from the context |
| 3677 | // here. |
| 3678 | __ mov(receiver, Operand(ebp, StandardFrameConstants::kContextOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3679 | __ mov(receiver, ContextOperand(receiver, Context::GLOBAL_OBJECT_INDEX)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3680 | __ mov(receiver, |
| 3681 | FieldOperand(receiver, JSGlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3682 | __ bind(&receiver_ok); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | |
| 3686 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3687 | Register receiver = ToRegister(instr->receiver()); |
| 3688 | Register function = ToRegister(instr->function()); |
| 3689 | Register length = ToRegister(instr->length()); |
| 3690 | Register elements = ToRegister(instr->elements()); |
| 3691 | ASSERT(receiver.is(eax)); // Used for parameter count. |
| 3692 | ASSERT(function.is(edi)); // Required by InvokeFunction. |
| 3693 | ASSERT(ToRegister(instr->result()).is(eax)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3694 | |
| 3695 | // Copy the arguments to this function possibly from the |
| 3696 | // adaptor frame below it. |
| 3697 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3698 | __ cmp(length, kArgumentsLimit); |
| 3699 | DeoptimizeIf(above, instr->environment()); |
| 3700 | |
| 3701 | __ push(receiver); |
| 3702 | __ mov(receiver, length); |
| 3703 | |
| 3704 | // Loop through the arguments pushing them onto the execution |
| 3705 | // stack. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3706 | Label invoke, loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3707 | // length is a small non-negative integer, due to the test above. |
| 3708 | __ test(length, Operand(length)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3709 | __ j(zero, &invoke, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3710 | __ bind(&loop); |
| 3711 | __ push(Operand(elements, length, times_pointer_size, 1 * kPointerSize)); |
| 3712 | __ dec(length); |
| 3713 | __ j(not_zero, &loop); |
| 3714 | |
| 3715 | // Invoke the function. |
| 3716 | __ bind(&invoke); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3717 | ASSERT(instr->HasPointerMap()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3718 | LPointerMap* pointers = instr->pointer_map(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3719 | SafepointGenerator safepoint_generator( |
| 3720 | this, pointers, Safepoint::kLazyDeopt); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3721 | ParameterCount actual(eax); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3722 | __ InvokeFunction(function, actual, CALL_FUNCTION, |
| 3723 | safepoint_generator, CALL_AS_METHOD); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3727 | void LCodeGen::DoDebugBreak(LDebugBreak* instr) { |
| 3728 | __ int3(); |
| 3729 | } |
| 3730 | |
| 3731 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3732 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3733 | LOperand* argument = instr->value(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3734 | EmitPushTaggedOperand(argument); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3738 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3739 | __ Drop(instr->count()); |
| 3740 | } |
| 3741 | |
| 3742 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3743 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3744 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3745 | __ mov(result, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3749 | void LCodeGen::DoContext(LContext* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3750 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 3751 | if (info()->IsOptimizing()) { |
| 3752 | __ mov(result, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 3753 | } else { |
| 3754 | // If there is no frame, the context must be in esi. |
| 3755 | ASSERT(result.is(esi)); |
| 3756 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | |
| 3760 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 3761 | Register context = ToRegister(instr->context()); |
| 3762 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3763 | __ mov(result, |
| 3764 | Operand(context, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3768 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3769 | ASSERT(ToRegister(instr->context()).is(esi)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3770 | __ push(esi); // The context is the first argument. |
| 3771 | __ push(Immediate(instr->hydrogen()->pairs())); |
| 3772 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->flags()))); |
| 3773 | CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 3774 | } |
| 3775 | |
| 3776 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3777 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
| 3778 | Register context = ToRegister(instr->context()); |
| 3779 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3780 | __ mov(result, |
| 3781 | Operand(context, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | |
| 3785 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3786 | Register global = ToRegister(instr->global()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3787 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3788 | __ mov(result, FieldOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | |
| 3792 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3793 | int formal_parameter_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3794 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3795 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3796 | CallKind call_kind, |
| 3797 | EDIState edi_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3798 | bool dont_adapt_arguments = |
| 3799 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3800 | bool can_invoke_directly = |
| 3801 | dont_adapt_arguments || formal_parameter_count == arity; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3802 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3803 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3804 | if (edi_state == EDI_UNINITIALIZED) { |
| 3805 | __ LoadHeapObject(edi, function); |
| 3806 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3807 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3808 | // Change context. |
| 3809 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3810 | |
| 3811 | // Set eax to arguments count if adaption is not needed. Assumes that eax |
| 3812 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3813 | if (dont_adapt_arguments) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3814 | __ mov(eax, arity); |
| 3815 | } |
| 3816 | |
| 3817 | // Invoke function directly. |
| 3818 | __ SetCallKind(ecx, call_kind); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3819 | if (function.is_identical_to(info()->closure())) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3820 | __ CallSelf(); |
| 3821 | } else { |
| 3822 | __ call(FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 3823 | } |
| 3824 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3825 | } else { |
| 3826 | // We need to adapt arguments. |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 3827 | LPointerMap* pointers = instr->pointer_map(); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3828 | SafepointGenerator generator( |
| 3829 | this, pointers, Safepoint::kLazyDeopt); |
| 3830 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3831 | ParameterCount expected(formal_parameter_count); |
| 3832 | __ InvokeFunction( |
| 3833 | function, expected, count, CALL_FUNCTION, generator, call_kind); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3834 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | |
| 3838 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
| 3839 | ASSERT(ToRegister(instr->result()).is(eax)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3840 | CallKnownFunction(instr->hydrogen()->function(), |
| 3841 | instr->hydrogen()->formal_parameter_count(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3842 | instr->arity(), |
| 3843 | instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3844 | CALL_AS_METHOD, |
| 3845 | EDI_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3849 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3850 | Register input_reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3851 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3852 | factory()->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3853 | DeoptimizeIf(not_equal, instr->environment()); |
| 3854 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3855 | Label slow, allocated, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3856 | Register tmp = input_reg.is(eax) ? ecx : eax; |
| 3857 | Register tmp2 = tmp.is(ecx) ? edx : input_reg.is(ecx) ? edx : ecx; |
| 3858 | |
| 3859 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3860 | PushSafepointRegistersScope scope(this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3861 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3862 | __ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3863 | // Check the sign of the argument. If the argument is positive, just |
| 3864 | // return it. We do not need to patch the stack since |input| and |
| 3865 | // |result| are the same register and |input| will be restored |
| 3866 | // unchanged by popping safepoint registers. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3867 | __ test(tmp, Immediate(HeapNumber::kSignMask)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3868 | __ j(zero, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3869 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3870 | __ AllocateHeapNumber(tmp, tmp2, no_reg, &slow); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3871 | __ jmp(&allocated, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3872 | |
| 3873 | // Slow case: Call the runtime system to do the number allocation. |
| 3874 | __ bind(&slow); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3875 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, |
| 3876 | instr, instr->context()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3877 | // Set the pointer to the new heap number in tmp. |
| 3878 | if (!tmp.is(eax)) __ mov(tmp, eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3879 | // Restore input_reg after call to runtime. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3880 | __ LoadFromSafepointRegisterSlot(input_reg, input_reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3881 | |
| 3882 | __ bind(&allocated); |
| 3883 | __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 3884 | __ and_(tmp2, ~HeapNumber::kSignMask); |
| 3885 | __ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2); |
| 3886 | __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
| 3887 | __ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3888 | __ StoreToSafepointRegisterSlot(input_reg, tmp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3889 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3890 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3894 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3895 | Register input_reg = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3896 | __ test(input_reg, Operand(input_reg)); |
| 3897 | Label is_positive; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3898 | __ j(not_sign, &is_positive, Label::kNear); |
| 3899 | __ neg(input_reg); // Sets flags. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3900 | DeoptimizeIf(negative, instr->environment()); |
| 3901 | __ bind(&is_positive); |
| 3902 | } |
| 3903 | |
| 3904 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3905 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3906 | // Class for deferred case. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3907 | class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3908 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3909 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, |
| 3910 | LMathAbs* instr, |
| 3911 | const X87Stack& x87_stack) |
| 3912 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3913 | virtual void Generate() V8_OVERRIDE { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3914 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3915 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3916 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3917 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3918 | LMathAbs* instr_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3919 | }; |
| 3920 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3921 | ASSERT(instr->value()->Equals(instr->result())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3922 | Representation r = instr->hydrogen()->value()->representation(); |
| 3923 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3924 | CpuFeatureScope scope(masm(), SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3925 | if (r.IsDouble()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3926 | XMMRegister scratch = double_scratch0(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3927 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3928 | __ xorps(scratch, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3929 | __ subsd(scratch, input_reg); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 3930 | __ andps(input_reg, scratch); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3931 | } else if (r.IsSmiOrInteger32()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3932 | EmitIntegerMathAbs(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3933 | } else { // Tagged case. |
| 3934 | DeferredMathAbsTaggedHeapNumber* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3935 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr, x87_stack_); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3936 | Register input_reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3937 | // Smi check. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3938 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3939 | EmitIntegerMathAbs(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3940 | __ bind(deferred->exit()); |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3945 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3946 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3947 | XMMRegister xmm_scratch = double_scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3948 | Register output_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3949 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3950 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3951 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3952 | CpuFeatureScope scope(masm(), SSE4_1); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3953 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3954 | // Deoptimize on negative zero. |
| 3955 | Label non_zero; |
| 3956 | __ xorps(xmm_scratch, xmm_scratch); // Zero the register. |
| 3957 | __ ucomisd(input_reg, xmm_scratch); |
| 3958 | __ j(not_equal, &non_zero, Label::kNear); |
| 3959 | __ movmskpd(output_reg, input_reg); |
| 3960 | __ test(output_reg, Immediate(1)); |
| 3961 | DeoptimizeIf(not_zero, instr->environment()); |
| 3962 | __ bind(&non_zero); |
| 3963 | } |
| 3964 | __ roundsd(xmm_scratch, input_reg, Assembler::kRoundDown); |
| 3965 | __ cvttsd2si(output_reg, Operand(xmm_scratch)); |
| 3966 | // Overflow is signalled with minint. |
| 3967 | __ cmp(output_reg, 0x80000000u); |
| 3968 | DeoptimizeIf(equal, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3969 | } else { |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3970 | Label negative_sign, done; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3971 | // Deoptimize on unordered. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3972 | __ xorps(xmm_scratch, xmm_scratch); // Zero the register. |
| 3973 | __ ucomisd(input_reg, xmm_scratch); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3974 | DeoptimizeIf(parity_even, instr->environment()); |
| 3975 | __ j(below, &negative_sign, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3976 | |
| 3977 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3978 | // Check for negative zero. |
| 3979 | Label positive_sign; |
| 3980 | __ j(above, &positive_sign, Label::kNear); |
| 3981 | __ movmskpd(output_reg, input_reg); |
| 3982 | __ test(output_reg, Immediate(1)); |
| 3983 | DeoptimizeIf(not_zero, instr->environment()); |
| 3984 | __ Set(output_reg, Immediate(0)); |
| 3985 | __ jmp(&done, Label::kNear); |
| 3986 | __ bind(&positive_sign); |
| 3987 | } |
| 3988 | |
| 3989 | // Use truncating instruction (OK because input is positive). |
| 3990 | __ cvttsd2si(output_reg, Operand(input_reg)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3991 | // Overflow is signalled with minint. |
| 3992 | __ cmp(output_reg, 0x80000000u); |
| 3993 | DeoptimizeIf(equal, instr->environment()); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3994 | __ jmp(&done, Label::kNear); |
| 3995 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3996 | // Non-zero negative reaches here. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3997 | __ bind(&negative_sign); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3998 | // Truncate, then compare and compensate. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3999 | __ cvttsd2si(output_reg, Operand(input_reg)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4000 | __ Cvtsi2sd(xmm_scratch, output_reg); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4001 | __ ucomisd(input_reg, xmm_scratch); |
| 4002 | __ j(equal, &done, Label::kNear); |
| 4003 | __ sub(output_reg, Immediate(1)); |
| 4004 | DeoptimizeIf(overflow, instr->environment()); |
| 4005 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4006 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4007 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4010 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4011 | void LCodeGen::DoMathRound(LMathRound* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4012 | CpuFeatureScope scope(masm(), SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4013 | Register output_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4014 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4015 | XMMRegister xmm_scratch = double_scratch0(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4016 | XMMRegister input_temp = ToDoubleRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4017 | ExternalReference one_half = ExternalReference::address_of_one_half(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4018 | ExternalReference minus_one_half = |
| 4019 | ExternalReference::address_of_minus_one_half(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4020 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4021 | Label done, round_to_zero, below_one_half, do_not_compensate; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4022 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
| 4023 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4024 | __ movsd(xmm_scratch, Operand::StaticVariable(one_half)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4025 | __ ucomisd(xmm_scratch, input_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4026 | __ j(above, &below_one_half, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4027 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4028 | // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). |
| 4029 | __ addsd(xmm_scratch, input_reg); |
| 4030 | __ cvttsd2si(output_reg, Operand(xmm_scratch)); |
| 4031 | // Overflow is signalled with minint. |
| 4032 | __ cmp(output_reg, 0x80000000u); |
| 4033 | __ RecordComment("D2I conversion overflow"); |
| 4034 | DeoptimizeIf(equal, instr->environment()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4035 | __ jmp(&done, dist); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4036 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4037 | __ bind(&below_one_half); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4038 | __ movsd(xmm_scratch, Operand::StaticVariable(minus_one_half)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4039 | __ ucomisd(xmm_scratch, input_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4040 | __ j(below_equal, &round_to_zero, Label::kNear); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4041 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4042 | // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
| 4043 | // compare and compensate. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 4044 | __ movaps(input_temp, input_reg); // Do not alter input_reg. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4045 | __ subsd(input_temp, xmm_scratch); |
| 4046 | __ cvttsd2si(output_reg, Operand(input_temp)); |
| 4047 | // Catch minint due to overflow, and to prevent overflow when compensating. |
| 4048 | __ cmp(output_reg, 0x80000000u); |
| 4049 | __ RecordComment("D2I conversion overflow"); |
| 4050 | DeoptimizeIf(equal, instr->environment()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4051 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4052 | __ Cvtsi2sd(xmm_scratch, output_reg); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4053 | __ ucomisd(xmm_scratch, input_temp); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4054 | __ j(equal, &done, dist); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4055 | __ sub(output_reg, Immediate(1)); |
| 4056 | // No overflow because we already ruled out minint. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4057 | __ jmp(&done, dist); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4058 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4059 | __ bind(&round_to_zero); |
| 4060 | // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if |
| 4061 | // we can ignore the difference between a result of -0 and +0. |
| 4062 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4063 | // If the sign is positive, we return +0. |
| 4064 | __ movmskpd(output_reg, input_reg); |
| 4065 | __ test(output_reg, Immediate(1)); |
| 4066 | __ RecordComment("Minus zero"); |
| 4067 | DeoptimizeIf(not_zero, instr->environment()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4068 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4069 | __ Set(output_reg, Immediate(0)); |
| 4070 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4074 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4075 | CpuFeatureScope scope(masm(), SSE2); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4076 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4077 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
| 4078 | __ sqrtsd(input_reg, input_reg); |
| 4079 | } |
| 4080 | |
| 4081 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4082 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4083 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4084 | XMMRegister xmm_scratch = double_scratch0(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4085 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4086 | Register scratch = ToRegister(instr->temp()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4087 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4088 | |
| 4089 | // Note that according to ECMA-262 15.8.2.13: |
| 4090 | // Math.pow(-Infinity, 0.5) == Infinity |
| 4091 | // Math.sqrt(-Infinity) == NaN |
| 4092 | Label done, sqrt; |
| 4093 | // Check base for -Infinity. According to IEEE-754, single-precision |
| 4094 | // -Infinity has the highest 9 bits set and the lowest 23 bits cleared. |
| 4095 | __ mov(scratch, 0xFF800000); |
| 4096 | __ movd(xmm_scratch, scratch); |
| 4097 | __ cvtss2sd(xmm_scratch, xmm_scratch); |
| 4098 | __ ucomisd(input_reg, xmm_scratch); |
| 4099 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 4100 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 4101 | __ j(not_equal, &sqrt, Label::kNear); |
| 4102 | __ j(carry, &sqrt, Label::kNear); |
| 4103 | // If input is -Infinity, return Infinity. |
| 4104 | __ xorps(input_reg, input_reg); |
| 4105 | __ subsd(input_reg, xmm_scratch); |
| 4106 | __ jmp(&done, Label::kNear); |
| 4107 | |
| 4108 | // Square root. |
| 4109 | __ bind(&sqrt); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4110 | __ xorps(xmm_scratch, xmm_scratch); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 4111 | __ addsd(input_reg, xmm_scratch); // Convert -0 to +0. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4112 | __ sqrtsd(input_reg, input_reg); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4113 | __ bind(&done); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | |
| 4117 | void LCodeGen::DoPower(LPower* instr) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4118 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4119 | // Having marked this as a call, we can use any registers. |
| 4120 | // 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] | 4121 | ASSERT(!instr->right()->IsDoubleRegister() || |
| 4122 | ToDoubleRegister(instr->right()).is(xmm1)); |
| 4123 | ASSERT(!instr->right()->IsRegister() || |
| 4124 | ToRegister(instr->right()).is(eax)); |
| 4125 | ASSERT(ToDoubleRegister(instr->left()).is(xmm2)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4126 | ASSERT(ToDoubleRegister(instr->result()).is(xmm3)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4127 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4128 | if (exponent_type.IsSmi()) { |
| 4129 | MathPowStub stub(MathPowStub::TAGGED); |
| 4130 | __ CallStub(&stub); |
| 4131 | } else if (exponent_type.IsTagged()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4132 | Label no_deopt; |
| 4133 | __ JumpIfSmi(eax, &no_deopt); |
| 4134 | __ CmpObjectType(eax, HEAP_NUMBER_TYPE, ecx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4135 | DeoptimizeIf(not_equal, instr->environment()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4136 | __ bind(&no_deopt); |
| 4137 | MathPowStub stub(MathPowStub::TAGGED); |
| 4138 | __ CallStub(&stub); |
| 4139 | } else if (exponent_type.IsInteger32()) { |
| 4140 | MathPowStub stub(MathPowStub::INTEGER); |
| 4141 | __ CallStub(&stub); |
| 4142 | } else { |
| 4143 | ASSERT(exponent_type.IsDouble()); |
| 4144 | MathPowStub stub(MathPowStub::DOUBLE); |
| 4145 | __ CallStub(&stub); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4146 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4150 | void LCodeGen::DoMathLog(LMathLog* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4151 | CpuFeatureScope scope(masm(), SSE2); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4152 | ASSERT(instr->value()->Equals(instr->result())); |
| 4153 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4154 | XMMRegister xmm_scratch = double_scratch0(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4155 | Label positive, done, zero; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4156 | __ xorps(xmm_scratch, xmm_scratch); |
| 4157 | __ ucomisd(input_reg, xmm_scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4158 | __ j(above, &positive, Label::kNear); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 4159 | __ j(not_carry, &zero, Label::kNear); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4160 | ExternalReference nan = |
| 4161 | ExternalReference::address_of_canonical_non_hole_nan(); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4162 | __ movsd(input_reg, Operand::StaticVariable(nan)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4163 | __ jmp(&done, Label::kNear); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4164 | __ bind(&zero); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4165 | ExternalReference ninf = |
| 4166 | ExternalReference::address_of_negative_infinity(); |
| 4167 | __ movsd(input_reg, Operand::StaticVariable(ninf)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4168 | __ jmp(&done, Label::kNear); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4169 | __ bind(&positive); |
| 4170 | __ fldln2(); |
| 4171 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4172 | __ movsd(Operand(esp, 0), input_reg); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4173 | __ fld_d(Operand(esp, 0)); |
| 4174 | __ fyl2x(); |
| 4175 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4176 | __ movsd(input_reg, Operand(esp, 0)); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 4177 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 4178 | __ bind(&done); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4182 | void LCodeGen::DoMathExp(LMathExp* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4183 | CpuFeatureScope scope(masm(), SSE2); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4184 | XMMRegister input = ToDoubleRegister(instr->value()); |
| 4185 | XMMRegister result = ToDoubleRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4186 | XMMRegister temp0 = double_scratch0(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4187 | Register temp1 = ToRegister(instr->temp1()); |
| 4188 | Register temp2 = ToRegister(instr->temp2()); |
| 4189 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4190 | MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4194 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 4195 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4196 | ASSERT(ToRegister(instr->function()).is(edi)); |
| 4197 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4198 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4199 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 4200 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4201 | LPointerMap* pointers = instr->pointer_map(); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4202 | SafepointGenerator generator( |
| 4203 | this, pointers, Safepoint::kLazyDeopt); |
| 4204 | ParameterCount count(instr->arity()); |
| 4205 | __ InvokeFunction(edi, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
| 4206 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4207 | CallKnownFunction(known_function, |
| 4208 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4209 | instr->arity(), |
| 4210 | instr, |
| 4211 | CALL_AS_METHOD, |
| 4212 | EDI_CONTAINS_TARGET); |
| 4213 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4217 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4218 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4219 | ASSERT(ToRegister(instr->key()).is(ecx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4220 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4221 | |
| 4222 | int arity = instr->arity(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4223 | Handle<Code> ic = |
| 4224 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arity); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4225 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | |
| 4229 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4230 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4231 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4232 | |
| 4233 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4234 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 4235 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4236 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4237 | __ mov(ecx, instr->name()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4238 | CallCode(ic, mode, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | |
| 4242 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4243 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4244 | ASSERT(ToRegister(instr->function()).is(edi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4245 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4246 | |
| 4247 | int arity = instr->arity(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4248 | CallFunctionStub stub(arity, NO_CALL_FUNCTION_FLAGS); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 4249 | if (instr->hydrogen()->IsTailCall()) { |
| 4250 | if (NeedsEagerFrame()) __ leave(); |
| 4251 | __ jmp(stub.GetCode(isolate()), RelocInfo::CODE_TARGET); |
| 4252 | } else { |
| 4253 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4254 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | |
| 4258 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4259 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4260 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4261 | |
| 4262 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4263 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
| 4264 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4265 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4266 | __ mov(ecx, instr->name()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4267 | CallCode(ic, mode, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | |
| 4271 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 4272 | ASSERT(ToRegister(instr->result()).is(eax)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4273 | CallKnownFunction(instr->hydrogen()->target(), |
| 4274 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4275 | instr->arity(), |
| 4276 | instr, |
| 4277 | CALL_AS_FUNCTION, |
| 4278 | EDI_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | |
| 4282 | void LCodeGen::DoCallNew(LCallNew* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4283 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4284 | ASSERT(ToRegister(instr->constructor()).is(edi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4285 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 4286 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4287 | // No cell in ebx for construct type feedback in optimized code |
| 4288 | Handle<Object> undefined_value(isolate()->factory()->undefined_value()); |
| 4289 | __ mov(ebx, Immediate(undefined_value)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4290 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4291 | __ Set(eax, Immediate(instr->arity())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4292 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4296 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
| 4297 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 4298 | ASSERT(ToRegister(instr->constructor()).is(edi)); |
| 4299 | ASSERT(ToRegister(instr->result()).is(eax)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4300 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4301 | __ Set(eax, Immediate(instr->arity())); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4302 | __ mov(ebx, instr->hydrogen()->property_cell()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4303 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4304 | AllocationSiteOverrideMode override_mode = |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4305 | (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4306 | ? DISABLE_ALLOCATION_SITES |
| 4307 | : DONT_OVERRIDE; |
| 4308 | ContextCheckMode context_mode = CONTEXT_CHECK_NOT_REQUIRED; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4309 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4310 | if (instr->arity() == 0) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4311 | ArrayNoArgumentConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4312 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4313 | } else if (instr->arity() == 1) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4314 | Label done; |
| 4315 | if (IsFastPackedElementsKind(kind)) { |
| 4316 | Label packed_case; |
| 4317 | // We might need a change here |
| 4318 | // look at the first argument |
| 4319 | __ mov(ecx, Operand(esp, 0)); |
| 4320 | __ test(ecx, ecx); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4321 | __ j(zero, &packed_case, Label::kNear); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4322 | |
| 4323 | ElementsKind holey_kind = GetHoleyElementsKind(kind); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4324 | ArraySingleArgumentConstructorStub stub(holey_kind, context_mode, |
| 4325 | override_mode); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4326 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4327 | __ jmp(&done, Label::kNear); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4328 | __ bind(&packed_case); |
| 4329 | } |
| 4330 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4331 | ArraySingleArgumentConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4332 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4333 | __ bind(&done); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4334 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4335 | ArrayNArgumentsConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4336 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4337 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4341 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4342 | ASSERT(ToRegister(instr->context()).is(esi)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4343 | CallRuntime(instr->function(), instr->arity(), instr, instr->save_doubles()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4347 | void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 4348 | Register function = ToRegister(instr->function()); |
| 4349 | Register code_object = ToRegister(instr->code_object()); |
| 4350 | __ lea(code_object, FieldOperand(code_object, Code::kHeaderSize)); |
| 4351 | __ mov(FieldOperand(function, JSFunction::kCodeEntryOffset), code_object); |
| 4352 | } |
| 4353 | |
| 4354 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4355 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 4356 | Register result = ToRegister(instr->result()); |
| 4357 | Register base = ToRegister(instr->base_object()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4358 | if (instr->offset()->IsConstantOperand()) { |
| 4359 | LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
| 4360 | __ lea(result, Operand(base, ToInteger32(offset))); |
| 4361 | } else { |
| 4362 | Register offset = ToRegister(instr->offset()); |
| 4363 | __ lea(result, Operand(base, offset, times_1, 0)); |
| 4364 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4368 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4369 | Representation representation = instr->representation(); |
| 4370 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4371 | HObjectAccess access = instr->hydrogen()->access(); |
| 4372 | int offset = access.offset(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4373 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4374 | if (access.IsExternalMemory()) { |
| 4375 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4376 | MemOperand operand = instr->object()->IsConstantOperand() |
| 4377 | ? MemOperand::StaticVariable( |
| 4378 | ToExternalReference(LConstantOperand::cast(instr->object()))) |
| 4379 | : MemOperand(ToRegister(instr->object()), offset); |
| 4380 | if (instr->value()->IsConstantOperand()) { |
| 4381 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 4382 | __ mov(operand, Immediate(ToInteger32(operand_value))); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4383 | } else { |
| 4384 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4385 | __ Store(value, operand, representation); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4386 | } |
| 4387 | return; |
| 4388 | } |
| 4389 | |
| 4390 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4391 | Handle<Map> transition = instr->transition(); |
| 4392 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4393 | if (FLAG_track_fields && representation.IsSmi()) { |
| 4394 | if (instr->value()->IsConstantOperand()) { |
| 4395 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4396 | if (!IsSmi(operand_value)) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4397 | DeoptimizeIf(no_condition, instr->environment()); |
| 4398 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4399 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4400 | } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) { |
| 4401 | if (instr->value()->IsConstantOperand()) { |
| 4402 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
| 4403 | if (IsInteger32(operand_value)) { |
| 4404 | DeoptimizeIf(no_condition, instr->environment()); |
| 4405 | } |
| 4406 | } else { |
| 4407 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 4408 | Register value = ToRegister(instr->value()); |
| 4409 | __ test(value, Immediate(kSmiTagMask)); |
| 4410 | DeoptimizeIf(zero, instr->environment()); |
| 4411 | } |
| 4412 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4413 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
| 4414 | ASSERT(transition.is_null()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4415 | ASSERT(access.IsInobject()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4416 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4417 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4418 | CpuFeatureScope scope(masm(), SSE2); |
| 4419 | XMMRegister value = ToDoubleRegister(instr->value()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4420 | __ movsd(FieldOperand(object, offset), value); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4421 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 4422 | X87Register value = ToX87Register(instr->value()); |
| 4423 | X87Mov(FieldOperand(object, offset), value); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4424 | } |
| 4425 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4428 | if (!transition.is_null()) { |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4429 | if (!instr->hydrogen()->NeedsWriteBarrierForMap()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4430 | __ mov(FieldOperand(object, HeapObject::kMapOffset), transition); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4431 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4432 | Register temp = ToRegister(instr->temp()); |
| 4433 | Register temp_map = ToRegister(instr->temp_map()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4434 | __ mov(temp_map, transition); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4435 | __ mov(FieldOperand(object, HeapObject::kMapOffset), temp_map); |
| 4436 | // Update the write barrier for the map field. |
| 4437 | __ RecordWriteField(object, |
| 4438 | HeapObject::kMapOffset, |
| 4439 | temp_map, |
| 4440 | temp, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4441 | GetSaveFPRegsMode(), |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4442 | OMIT_REMEMBERED_SET, |
| 4443 | OMIT_SMI_CHECK); |
| 4444 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | // Do the store. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4448 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4449 | instr->hydrogen()->value()->IsHeapObject() |
| 4450 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4451 | |
| 4452 | Register write_register = object; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4453 | if (!access.IsInobject()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4454 | write_register = ToRegister(instr->temp()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4455 | __ mov(write_register, FieldOperand(object, JSObject::kPropertiesOffset)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4456 | } |
| 4457 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4458 | MemOperand operand = FieldOperand(write_register, offset); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4459 | if (instr->value()->IsConstantOperand()) { |
| 4460 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4461 | if (operand_value->IsRegister()) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4462 | Register value = ToRegister(operand_value); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4463 | __ Store(value, operand, representation); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 4464 | } else if (representation.IsInteger32()) { |
| 4465 | Immediate immediate = ToImmediate(operand_value, representation); |
| 4466 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4467 | __ mov(operand, immediate); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4468 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4469 | Handle<Object> handle_value = ToHandle(operand_value); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4470 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4471 | __ mov(operand, handle_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4472 | } |
| 4473 | } else { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4474 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4475 | __ Store(value, operand, representation); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 4479 | Register value = ToRegister(instr->value()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4480 | Register temp = access.IsInobject() ? ToRegister(instr->temp()) : object; |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4481 | // Update the write barrier for the object for in-object properties. |
| 4482 | __ RecordWriteField(write_register, |
| 4483 | offset, |
| 4484 | value, |
| 4485 | temp, |
| 4486 | GetSaveFPRegsMode(), |
| 4487 | EMIT_REMEMBERED_SET, |
| 4488 | check_needed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | |
| 4493 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4494 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4495 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 4496 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 4497 | |
| 4498 | __ mov(ecx, instr->name()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4499 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4500 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 4501 | : isolate()->builtins()->StoreIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4502 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4506 | void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) { |
| 4507 | if (FLAG_debug_code && check->hydrogen()->skip_check()) { |
| 4508 | Label done; |
| 4509 | __ j(NegateCondition(cc), &done, Label::kNear); |
| 4510 | __ int3(); |
| 4511 | __ bind(&done); |
| 4512 | } else { |
| 4513 | DeoptimizeIf(cc, check->environment()); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4518 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4519 | if (instr->hydrogen()->skip_check() && !FLAG_debug_code) return; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4520 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4521 | if (instr->index()->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4522 | Immediate immediate = |
| 4523 | ToImmediate(LConstantOperand::cast(instr->index()), |
| 4524 | instr->hydrogen()->length()->representation()); |
| 4525 | __ cmp(ToOperand(instr->length()), immediate); |
| 4526 | Condition condition = |
| 4527 | instr->hydrogen()->allow_equality() ? below : below_equal; |
| 4528 | ApplyCheckIf(condition, instr); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4529 | } else { |
| 4530 | __ cmp(ToRegister(instr->index()), ToOperand(instr->length())); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4531 | Condition condition = |
| 4532 | instr->hydrogen()->allow_equality() ? above : above_equal; |
| 4533 | ApplyCheckIf(condition, instr); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4534 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4538 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4539 | ElementsKind elements_kind = instr->elements_kind(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4540 | LOperand* key = instr->key(); |
| 4541 | if (!key->IsConstantOperand() && |
| 4542 | ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(), |
| 4543 | elements_kind)) { |
| 4544 | __ SmiUntag(ToRegister(key)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4545 | } |
| 4546 | Operand operand(BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4547 | instr->elements(), |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4548 | key, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4549 | instr->hydrogen()->key()->representation(), |
| 4550 | elements_kind, |
| 4551 | 0, |
| 4552 | instr->additional_index())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4553 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4554 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 4555 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4556 | XMMRegister xmm_scratch = double_scratch0(); |
| 4557 | __ cvtsd2ss(xmm_scratch, ToDoubleRegister(instr->value())); |
| 4558 | __ movss(operand, xmm_scratch); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4559 | } else { |
| 4560 | __ fld(0); |
| 4561 | __ fstp_s(operand); |
| 4562 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4563 | } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4564 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 4565 | CpuFeatureScope scope(masm(), SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4566 | __ movsd(operand, ToDoubleRegister(instr->value())); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4567 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 4568 | X87Mov(operand, ToX87Register(instr->value())); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4569 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4570 | } else { |
| 4571 | Register value = ToRegister(instr->value()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4572 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4573 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4574 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 4575 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4576 | __ mov_b(operand, value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4577 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4578 | case EXTERNAL_SHORT_ELEMENTS: |
| 4579 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4580 | __ mov_w(operand, value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4581 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4582 | case EXTERNAL_INT_ELEMENTS: |
| 4583 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4584 | __ mov(operand, value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4585 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4586 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4587 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4588 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4589 | case FAST_ELEMENTS: |
| 4590 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4591 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4592 | case FAST_HOLEY_ELEMENTS: |
| 4593 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4594 | case DICTIONARY_ELEMENTS: |
| 4595 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4596 | UNREACHABLE(); |
| 4597 | break; |
| 4598 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4599 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4603 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4604 | ExternalReference canonical_nan_reference = |
| 4605 | ExternalReference::address_of_canonical_non_hole_nan(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4606 | Operand double_store_operand = BuildFastArrayOperand( |
| 4607 | instr->elements(), |
| 4608 | instr->key(), |
| 4609 | instr->hydrogen()->key()->representation(), |
| 4610 | FAST_DOUBLE_ELEMENTS, |
| 4611 | FixedDoubleArray::kHeaderSize - kHeapObjectTag, |
| 4612 | instr->additional_index()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4613 | |
| 4614 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 4615 | CpuFeatureScope scope(masm(), SSE2); |
| 4616 | XMMRegister value = ToDoubleRegister(instr->value()); |
| 4617 | |
| 4618 | if (instr->NeedsCanonicalization()) { |
| 4619 | Label have_value; |
| 4620 | |
| 4621 | __ ucomisd(value, value); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4622 | __ j(parity_odd, &have_value, Label::kNear); // NaN. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4623 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4624 | __ movsd(value, Operand::StaticVariable(canonical_nan_reference)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4625 | __ bind(&have_value); |
| 4626 | } |
| 4627 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4628 | __ movsd(double_store_operand, value); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4629 | } else { |
| 4630 | // Can't use SSE2 in the serializer |
| 4631 | if (instr->hydrogen()->IsConstantHoleStore()) { |
| 4632 | // This means we should store the (double) hole. No floating point |
| 4633 | // registers required. |
| 4634 | double nan_double = FixedDoubleArray::hole_nan_as_double(); |
| 4635 | uint64_t int_val = BitCast<uint64_t, double>(nan_double); |
| 4636 | int32_t lower = static_cast<int32_t>(int_val); |
| 4637 | int32_t upper = static_cast<int32_t>(int_val >> (kBitsPerInt)); |
| 4638 | |
| 4639 | __ mov(double_store_operand, Immediate(lower)); |
| 4640 | Operand double_store_operand2 = BuildFastArrayOperand( |
| 4641 | instr->elements(), |
| 4642 | instr->key(), |
| 4643 | instr->hydrogen()->key()->representation(), |
| 4644 | FAST_DOUBLE_ELEMENTS, |
| 4645 | FixedDoubleArray::kHeaderSize - kHeapObjectTag + kPointerSize, |
| 4646 | instr->additional_index()); |
| 4647 | __ mov(double_store_operand2, Immediate(upper)); |
| 4648 | } else { |
| 4649 | Label no_special_nan_handling; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 4650 | X87Register value = ToX87Register(instr->value()); |
| 4651 | X87Fxch(value); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4652 | |
| 4653 | if (instr->NeedsCanonicalization()) { |
| 4654 | __ fld(0); |
| 4655 | __ fld(0); |
| 4656 | __ FCmp(); |
| 4657 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4658 | __ j(parity_odd, &no_special_nan_handling, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4659 | __ sub(esp, Immediate(kDoubleSize)); |
| 4660 | __ fst_d(MemOperand(esp, 0)); |
| 4661 | __ cmp(MemOperand(esp, sizeof(kHoleNanLower32)), |
| 4662 | Immediate(kHoleNanUpper32)); |
| 4663 | __ add(esp, Immediate(kDoubleSize)); |
| 4664 | Label canonicalize; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4665 | __ j(not_equal, &canonicalize, Label::kNear); |
| 4666 | __ jmp(&no_special_nan_handling, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4667 | __ bind(&canonicalize); |
| 4668 | __ fstp(0); |
| 4669 | __ fld_d(Operand::StaticVariable(canonical_nan_reference)); |
| 4670 | } |
| 4671 | |
| 4672 | __ bind(&no_special_nan_handling); |
| 4673 | __ fst_d(double_store_operand); |
| 4674 | } |
| 4675 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | |
| 4679 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4680 | Register elements = ToRegister(instr->elements()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4681 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 4682 | |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4683 | Operand operand = BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4684 | instr->elements(), |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4685 | instr->key(), |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4686 | instr->hydrogen()->key()->representation(), |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4687 | FAST_ELEMENTS, |
| 4688 | FixedArray::kHeaderSize - kHeapObjectTag, |
| 4689 | instr->additional_index()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4690 | if (instr->value()->IsRegister()) { |
| 4691 | __ mov(operand, ToRegister(instr->value())); |
| 4692 | } else { |
| 4693 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4694 | if (IsSmi(operand_value)) { |
| 4695 | Immediate immediate = ToImmediate(operand_value, Representation::Smi()); |
| 4696 | __ mov(operand, immediate); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4697 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4698 | ASSERT(!IsInteger32(operand_value)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4699 | Handle<Object> handle_value = ToHandle(operand_value); |
| 4700 | __ mov(operand, handle_value); |
| 4701 | } |
| 4702 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4703 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4704 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4705 | ASSERT(instr->value()->IsRegister()); |
| 4706 | Register value = ToRegister(instr->value()); |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4707 | ASSERT(!instr->key()->IsConstantOperand()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4708 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4709 | instr->hydrogen()->value()->IsHeapObject() |
| 4710 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4711 | // Compute address of modified element and store it into key register. |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4712 | __ lea(key, operand); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4713 | __ RecordWrite(elements, |
| 4714 | key, |
| 4715 | value, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4716 | GetSaveFPRegsMode(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4717 | EMIT_REMEMBERED_SET, |
| 4718 | check_needed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4719 | } |
| 4720 | } |
| 4721 | |
| 4722 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4723 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4724 | // By cases...external, fast-double, fast |
| 4725 | if (instr->is_external()) { |
| 4726 | DoStoreKeyedExternalArray(instr); |
| 4727 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4728 | DoStoreKeyedFixedDoubleArray(instr); |
| 4729 | } else { |
| 4730 | DoStoreKeyedFixedArray(instr); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4731 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4735 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4736 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4737 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 4738 | ASSERT(ToRegister(instr->key()).is(ecx)); |
| 4739 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 4740 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4741 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4742 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4743 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4744 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4748 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4749 | Register object = ToRegister(instr->object()); |
| 4750 | Register temp = ToRegister(instr->temp()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4751 | Label no_memento_found; |
| 4752 | __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4753 | DeoptimizeIf(equal, instr->environment()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4754 | __ bind(&no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4758 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4759 | Register object_reg = ToRegister(instr->object()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4760 | |
| 4761 | Handle<Map> from_map = instr->original_map(); |
| 4762 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4763 | ElementsKind from_kind = instr->from_kind(); |
| 4764 | ElementsKind to_kind = instr->to_kind(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4765 | |
| 4766 | Label not_applicable; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4767 | bool is_simple_map_transition = |
| 4768 | IsSimpleMapChangeTransition(from_kind, to_kind); |
| 4769 | Label::Distance branch_distance = |
| 4770 | is_simple_map_transition ? Label::kNear : Label::kFar; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4771 | __ cmp(FieldOperand(object_reg, HeapObject::kMapOffset), from_map); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4772 | __ j(not_equal, ¬_applicable, branch_distance); |
| 4773 | if (is_simple_map_transition) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4774 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4775 | __ mov(FieldOperand(object_reg, HeapObject::kMapOffset), |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4776 | Immediate(to_map)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4777 | // Write barrier. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4778 | ASSERT_NE(instr->temp(), NULL); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4779 | __ RecordWriteForMap(object_reg, to_map, new_map_reg, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4780 | ToRegister(instr->temp()), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4781 | kDontSaveFPRegs); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4782 | } else { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 4783 | ASSERT(ToRegister(instr->context()).is(esi)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4784 | PushSafepointRegistersScope scope(this); |
| 4785 | if (!object_reg.is(eax)) { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 4786 | __ mov(eax, object_reg); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4787 | } |
| 4788 | __ mov(ebx, to_map); |
| 4789 | TransitionElementsKindStub stub(from_kind, to_kind); |
| 4790 | __ CallStub(&stub); |
| 4791 | RecordSafepointWithRegisters( |
| 4792 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4793 | } |
| 4794 | __ bind(¬_applicable); |
| 4795 | } |
| 4796 | |
| 4797 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4798 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4799 | class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4800 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4801 | DeferredStringCharCodeAt(LCodeGen* codegen, |
| 4802 | LStringCharCodeAt* instr, |
| 4803 | const X87Stack& x87_stack) |
| 4804 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4805 | virtual void Generate() V8_OVERRIDE { |
| 4806 | codegen()->DoDeferredStringCharCodeAt(instr_); |
| 4807 | } |
| 4808 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4809 | private: |
| 4810 | LStringCharCodeAt* instr_; |
| 4811 | }; |
| 4812 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4813 | DeferredStringCharCodeAt* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4814 | new(zone()) DeferredStringCharCodeAt(this, instr, x87_stack_); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4815 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4816 | StringCharLoadGenerator::Generate(masm(), |
| 4817 | factory(), |
| 4818 | ToRegister(instr->string()), |
| 4819 | ToRegister(instr->index()), |
| 4820 | ToRegister(instr->result()), |
| 4821 | deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4822 | __ bind(deferred->exit()); |
| 4823 | } |
| 4824 | |
| 4825 | |
| 4826 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4827 | Register string = ToRegister(instr->string()); |
| 4828 | Register result = ToRegister(instr->result()); |
| 4829 | |
| 4830 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4831 | // result register contain a valid pointer because it is already |
| 4832 | // contained in the register pointer map. |
| 4833 | __ Set(result, Immediate(0)); |
| 4834 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4835 | PushSafepointRegistersScope scope(this); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4836 | __ push(string); |
| 4837 | // Push the index as a smi. This is safe because of the checks in |
| 4838 | // DoStringCharCodeAt above. |
| 4839 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 4840 | if (instr->index()->IsConstantOperand()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4841 | Immediate immediate = ToImmediate(LConstantOperand::cast(instr->index()), |
| 4842 | Representation::Smi()); |
| 4843 | __ push(immediate); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4844 | } else { |
| 4845 | Register index = ToRegister(instr->index()); |
| 4846 | __ SmiTag(index); |
| 4847 | __ push(index); |
| 4848 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4849 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAt, 2, |
| 4850 | instr, instr->context()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4851 | __ AssertSmi(eax); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4852 | __ SmiUntag(eax); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4853 | __ StoreToSafepointRegisterSlot(result, eax); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4857 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4858 | class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4859 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4860 | DeferredStringCharFromCode(LCodeGen* codegen, |
| 4861 | LStringCharFromCode* instr, |
| 4862 | const X87Stack& x87_stack) |
| 4863 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4864 | virtual void Generate() V8_OVERRIDE { |
| 4865 | codegen()->DoDeferredStringCharFromCode(instr_); |
| 4866 | } |
| 4867 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4868 | private: |
| 4869 | LStringCharFromCode* instr_; |
| 4870 | }; |
| 4871 | |
| 4872 | DeferredStringCharFromCode* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4873 | new(zone()) DeferredStringCharFromCode(this, instr, x87_stack_); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4874 | |
| 4875 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4876 | Register char_code = ToRegister(instr->char_code()); |
| 4877 | Register result = ToRegister(instr->result()); |
| 4878 | ASSERT(!char_code.is(result)); |
| 4879 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4880 | __ cmp(char_code, String::kMaxOneByteCharCode); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4881 | __ j(above, deferred->entry()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4882 | __ Set(result, Immediate(factory()->single_character_string_cache())); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4883 | __ mov(result, FieldOperand(result, |
| 4884 | char_code, times_pointer_size, |
| 4885 | FixedArray::kHeaderSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4886 | __ cmp(result, factory()->undefined_value()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4887 | __ j(equal, deferred->entry()); |
| 4888 | __ bind(deferred->exit()); |
| 4889 | } |
| 4890 | |
| 4891 | |
| 4892 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4893 | Register char_code = ToRegister(instr->char_code()); |
| 4894 | Register result = ToRegister(instr->result()); |
| 4895 | |
| 4896 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4897 | // result register contain a valid pointer because it is already |
| 4898 | // contained in the register pointer map. |
| 4899 | __ Set(result, Immediate(0)); |
| 4900 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4901 | PushSafepointRegistersScope scope(this); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4902 | __ SmiTag(char_code); |
| 4903 | __ push(char_code); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4904 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4905 | __ StoreToSafepointRegisterSlot(result, eax); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4909 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4910 | ASSERT(ToRegister(instr->context()).is(esi)); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 4911 | if (FLAG_new_string_add) { |
| 4912 | ASSERT(ToRegister(instr->left()).is(edx)); |
| 4913 | ASSERT(ToRegister(instr->right()).is(eax)); |
| 4914 | NewStringAddStub stub(instr->hydrogen()->flags(), |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame^] | 4915 | instr->hydrogen()->pretenure_flag()); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 4916 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4917 | } else { |
| 4918 | EmitPushTaggedOperand(instr->left()); |
| 4919 | EmitPushTaggedOperand(instr->right()); |
| 4920 | StringAddStub stub(instr->hydrogen()->flags()); |
| 4921 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4922 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4926 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4927 | LOperand* input = instr->value(); |
| 4928 | LOperand* output = instr->result(); |
| 4929 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4930 | ASSERT(output->IsDoubleRegister()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4931 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4932 | CpuFeatureScope scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4933 | __ Cvtsi2sd(ToDoubleRegister(output), ToOperand(input)); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4934 | } else if (input->IsRegister()) { |
| 4935 | Register input_reg = ToRegister(input); |
| 4936 | __ push(input_reg); |
| 4937 | X87Mov(ToX87Register(output), Operand(esp, 0), kX87IntOperand); |
| 4938 | __ pop(input_reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4939 | } else { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4940 | X87Mov(ToX87Register(output), ToOperand(input), kX87IntOperand); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4941 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4945 | void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) { |
| 4946 | Register input = ToRegister(instr->value()); |
| 4947 | __ SmiTag(input); |
| 4948 | if (!instr->hydrogen()->value()->HasRange() || |
| 4949 | !instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 4950 | DeoptimizeIf(overflow, instr->environment()); |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4955 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4956 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4957 | LOperand* output = instr->result(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 4958 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4959 | CpuFeatureScope scope(masm(), SSE2); |
| 4960 | LOperand* temp = instr->temp(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4961 | |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 4962 | __ LoadUint32(ToDoubleRegister(output), |
| 4963 | ToRegister(input), |
| 4964 | ToDoubleRegister(temp)); |
| 4965 | } else { |
| 4966 | X87Register res = ToX87Register(output); |
| 4967 | X87PrepareToWrite(res); |
| 4968 | __ LoadUint32NoSSE2(ToRegister(input)); |
| 4969 | X87CommitWrite(res); |
| 4970 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | |
machenbach@chromium.org | ed29eb2 | 2013-10-31 13:30:00 +0000 | [diff] [blame] | 4974 | void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) { |
| 4975 | Register input = ToRegister(instr->value()); |
| 4976 | if (!instr->hydrogen()->value()->HasRange() || |
| 4977 | !instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 4978 | __ test(input, Immediate(0xc0000000)); |
| 4979 | DeoptimizeIf(not_zero, instr->environment()); |
| 4980 | } |
| 4981 | __ SmiTag(input); |
| 4982 | } |
| 4983 | |
| 4984 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4985 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4986 | class DeferredNumberTagI V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4987 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4988 | DeferredNumberTagI(LCodeGen* codegen, |
| 4989 | LNumberTagI* instr, |
| 4990 | const X87Stack& x87_stack) |
| 4991 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4992 | virtual void Generate() V8_OVERRIDE { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4993 | codegen()->DoDeferredNumberTagI(instr_, instr_->value(), SIGNED_INT32); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4994 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4995 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4996 | private: |
| 4997 | LNumberTagI* instr_; |
| 4998 | }; |
| 4999 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5000 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5001 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5002 | Register reg = ToRegister(input); |
| 5003 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5004 | DeferredNumberTagI* deferred = |
| 5005 | new(zone()) DeferredNumberTagI(this, instr, x87_stack_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5006 | __ SmiTag(reg); |
| 5007 | __ j(overflow, deferred->entry()); |
| 5008 | __ bind(deferred->exit()); |
| 5009 | } |
| 5010 | |
| 5011 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5012 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5013 | class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5014 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5015 | DeferredNumberTagU(LCodeGen* codegen, |
| 5016 | LNumberTagU* instr, |
| 5017 | const X87Stack& x87_stack) |
| 5018 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5019 | virtual void Generate() V8_OVERRIDE { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5020 | codegen()->DoDeferredNumberTagI(instr_, instr_->value(), UNSIGNED_INT32); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5021 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5022 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5023 | private: |
| 5024 | LNumberTagU* instr_; |
| 5025 | }; |
| 5026 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5027 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5028 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5029 | Register reg = ToRegister(input); |
| 5030 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5031 | DeferredNumberTagU* deferred = |
| 5032 | new(zone()) DeferredNumberTagU(this, instr, x87_stack_); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5033 | __ cmp(reg, Immediate(Smi::kMaxValue)); |
| 5034 | __ j(above, deferred->entry()); |
| 5035 | __ SmiTag(reg); |
| 5036 | __ bind(deferred->exit()); |
| 5037 | } |
| 5038 | |
| 5039 | |
| 5040 | void LCodeGen::DoDeferredNumberTagI(LInstruction* instr, |
| 5041 | LOperand* value, |
| 5042 | IntegerSignedness signedness) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5043 | Label slow; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5044 | Register reg = ToRegister(value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5045 | Register tmp = reg.is(eax) ? ecx : eax; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5046 | XMMRegister xmm_scratch = double_scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5047 | |
| 5048 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5049 | PushSafepointRegistersScope scope(this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5050 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5051 | Label done; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5052 | |
| 5053 | if (signedness == SIGNED_INT32) { |
| 5054 | // There was overflow, so bits 30 and 31 of the original integer |
| 5055 | // disagree. Try to allocate a heap number in new space and store |
| 5056 | // the value in there. If that fails, call the runtime system. |
| 5057 | __ SmiUntag(reg); |
| 5058 | __ xor_(reg, 0x80000000); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5059 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5060 | CpuFeatureScope feature_scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5061 | __ Cvtsi2sd(xmm_scratch, Operand(reg)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5062 | } else { |
| 5063 | __ push(reg); |
| 5064 | __ fild_s(Operand(esp, 0)); |
| 5065 | __ pop(reg); |
| 5066 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5067 | } else { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5068 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5069 | CpuFeatureScope feature_scope(masm(), SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5070 | __ LoadUint32(xmm_scratch, reg, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5071 | ToDoubleRegister(LNumberTagU::cast(instr)->temp())); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5072 | } else { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5073 | // There's no fild variant for unsigned values, so zero-extend to a 64-bit |
| 5074 | // int manually. |
| 5075 | __ push(Immediate(0)); |
| 5076 | __ push(reg); |
| 5077 | __ fild_d(Operand(esp, 0)); |
| 5078 | __ pop(reg); |
| 5079 | __ pop(reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5080 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5081 | } |
| 5082 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5083 | if (FLAG_inline_new) { |
| 5084 | __ AllocateHeapNumber(reg, tmp, no_reg, &slow); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5085 | __ jmp(&done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | // Slow case: Call the runtime system to do the number allocation. |
| 5089 | __ bind(&slow); |
| 5090 | |
| 5091 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 5092 | // register is stored, as this register is in the pointer map, but contains an |
| 5093 | // integer value. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5094 | __ StoreToSafepointRegisterSlot(reg, Immediate(0)); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5095 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 5096 | // the environment's HContext or HInlinedContext value. |
| 5097 | // They only call Runtime::kAllocateHeapNumber. |
| 5098 | // The corresponding HChange instructions are added in a phase that does |
| 5099 | // not have easy access to the local context. |
| 5100 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 5101 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 5102 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5103 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5104 | if (!reg.is(eax)) __ mov(reg, eax); |
| 5105 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5106 | // 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] | 5107 | // number. |
| 5108 | __ bind(&done); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5109 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5110 | CpuFeatureScope feature_scope(masm(), SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5111 | __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), xmm_scratch); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5112 | } else { |
| 5113 | __ fstp_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
| 5114 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5115 | __ StoreToSafepointRegisterSlot(reg, reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | |
| 5119 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5120 | class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5121 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5122 | DeferredNumberTagD(LCodeGen* codegen, |
| 5123 | LNumberTagD* instr, |
| 5124 | const X87Stack& x87_stack) |
| 5125 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5126 | virtual void Generate() V8_OVERRIDE { |
| 5127 | codegen()->DoDeferredNumberTagD(instr_); |
| 5128 | } |
| 5129 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5130 | private: |
| 5131 | LNumberTagD* instr_; |
| 5132 | }; |
| 5133 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5134 | Register reg = ToRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5135 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5136 | bool use_sse2 = CpuFeatures::IsSupported(SSE2); |
| 5137 | if (!use_sse2) { |
| 5138 | // Put the value to the top of stack |
| 5139 | X87Register src = ToX87Register(instr->value()); |
| 5140 | X87LoadForUsage(src); |
| 5141 | } |
| 5142 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5143 | DeferredNumberTagD* deferred = |
| 5144 | new(zone()) DeferredNumberTagD(this, instr, x87_stack_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5145 | if (FLAG_inline_new) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5146 | Register tmp = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5147 | __ AllocateHeapNumber(reg, tmp, no_reg, deferred->entry()); |
| 5148 | } else { |
| 5149 | __ jmp(deferred->entry()); |
| 5150 | } |
| 5151 | __ bind(deferred->exit()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5152 | if (use_sse2) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5153 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5154 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5155 | __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), input_reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5156 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5157 | __ fstp_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5158 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | |
| 5162 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 5163 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5164 | // result register contain a valid pointer because it is already |
| 5165 | // contained in the register pointer map. |
| 5166 | Register reg = ToRegister(instr->result()); |
| 5167 | __ Set(reg, Immediate(0)); |
| 5168 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5169 | PushSafepointRegistersScope scope(this); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5170 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 5171 | // the environment's HContext or HInlinedContext value. |
| 5172 | // They only call Runtime::kAllocateHeapNumber. |
| 5173 | // The corresponding HChange instructions are added in a phase that does |
| 5174 | // not have easy access to the local context. |
| 5175 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 5176 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5177 | RecordSafepointWithRegisters( |
| 5178 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5179 | __ StoreToSafepointRegisterSlot(reg, eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | |
| 5183 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5184 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5185 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5186 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
| 5187 | __ SmiTag(ToRegister(input)); |
| 5188 | } |
| 5189 | |
| 5190 | |
| 5191 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5192 | LOperand* input = instr->value(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5193 | Register result = ToRegister(input); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5194 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 5195 | if (instr->needs_check()) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5196 | __ test(result, Immediate(kSmiTagMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5197 | DeoptimizeIf(not_zero, instr->environment()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5198 | } else { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5199 | __ AssertSmi(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5200 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5201 | __ SmiUntag(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5205 | void LCodeGen::EmitNumberUntagDNoSSE2(Register input_reg, |
| 5206 | Register temp_reg, |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5207 | X87Register res_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5208 | bool can_convert_undefined_to_nan, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5209 | bool deoptimize_on_minus_zero, |
| 5210 | LEnvironment* env, |
| 5211 | NumberUntagDMode mode) { |
| 5212 | Label load_smi, done; |
| 5213 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5214 | X87PrepareToWrite(res_reg); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5215 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5216 | // Smi check. |
| 5217 | __ JumpIfSmi(input_reg, &load_smi, Label::kNear); |
| 5218 | |
| 5219 | // Heap number map check. |
| 5220 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5221 | factory()->heap_number_map()); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5222 | if (!can_convert_undefined_to_nan) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5223 | DeoptimizeIf(not_equal, env); |
| 5224 | } else { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5225 | Label heap_number, convert; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5226 | __ j(equal, &heap_number, Label::kNear); |
| 5227 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5228 | // Convert undefined (or hole) to NaN. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5229 | __ cmp(input_reg, factory()->undefined_value()); |
| 5230 | DeoptimizeIf(not_equal, env); |
| 5231 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5232 | __ bind(&convert); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5233 | ExternalReference nan = |
| 5234 | ExternalReference::address_of_canonical_non_hole_nan(); |
| 5235 | __ fld_d(Operand::StaticVariable(nan)); |
| 5236 | __ jmp(&done, Label::kNear); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5237 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5238 | __ bind(&heap_number); |
| 5239 | } |
| 5240 | // Heap number to x87 conversion. |
| 5241 | __ fld_d(FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 5242 | if (deoptimize_on_minus_zero) { |
| 5243 | __ fldz(); |
| 5244 | __ FCmp(); |
| 5245 | __ fld_d(FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 5246 | __ j(not_zero, &done, Label::kNear); |
| 5247 | |
| 5248 | // Use general purpose registers to check if we have -0.0 |
| 5249 | __ mov(temp_reg, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 5250 | __ test(temp_reg, Immediate(HeapNumber::kSignMask)); |
| 5251 | __ j(zero, &done, Label::kNear); |
| 5252 | |
| 5253 | // Pop FPU stack before deoptimizing. |
| 5254 | __ fstp(0); |
| 5255 | DeoptimizeIf(not_zero, env); |
| 5256 | } |
| 5257 | __ jmp(&done, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5258 | } else { |
| 5259 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
| 5260 | } |
| 5261 | |
| 5262 | __ bind(&load_smi); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5263 | // Clobbering a temp is faster than re-tagging the |
| 5264 | // input register since we avoid dependencies. |
| 5265 | __ mov(temp_reg, input_reg); |
| 5266 | __ SmiUntag(temp_reg); // Untag smi before converting to float. |
| 5267 | __ push(temp_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5268 | __ fild_s(Operand(esp, 0)); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5269 | __ add(esp, Immediate(kPointerSize)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5270 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5271 | X87CommitWrite(res_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5272 | } |
| 5273 | |
| 5274 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5275 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5276 | Register temp_reg, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5277 | XMMRegister result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5278 | bool can_convert_undefined_to_nan, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5279 | bool deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5280 | LEnvironment* env, |
| 5281 | NumberUntagDMode mode) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5282 | Label convert, load_smi, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5283 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5284 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5285 | // Smi check. |
| 5286 | __ JumpIfSmi(input_reg, &load_smi, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5287 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5288 | // Heap number map check. |
| 5289 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5290 | factory()->heap_number_map()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5291 | if (can_convert_undefined_to_nan) { |
| 5292 | __ j(not_equal, &convert, Label::kNear); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 5293 | } else { |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 5294 | DeoptimizeIf(not_equal, env); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 5295 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5296 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5297 | // Heap number to XMM conversion. |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5298 | __ movsd(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5299 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5300 | if (deoptimize_on_minus_zero) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5301 | XMMRegister xmm_scratch = double_scratch0(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5302 | __ xorps(xmm_scratch, xmm_scratch); |
| 5303 | __ ucomisd(result_reg, xmm_scratch); |
| 5304 | __ j(not_zero, &done, Label::kNear); |
| 5305 | __ movmskpd(temp_reg, result_reg); |
| 5306 | __ test_b(temp_reg, 1); |
| 5307 | DeoptimizeIf(not_zero, env); |
| 5308 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5309 | __ jmp(&done, Label::kNear); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5310 | |
| 5311 | if (can_convert_undefined_to_nan) { |
| 5312 | __ bind(&convert); |
| 5313 | |
| 5314 | // Convert undefined (and hole) to NaN. |
| 5315 | __ cmp(input_reg, factory()->undefined_value()); |
| 5316 | DeoptimizeIf(not_equal, env); |
| 5317 | |
| 5318 | ExternalReference nan = |
| 5319 | ExternalReference::address_of_canonical_non_hole_nan(); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5320 | __ movsd(result_reg, Operand::StaticVariable(nan)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5321 | __ jmp(&done, Label::kNear); |
| 5322 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5323 | } else { |
| 5324 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5325 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5326 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5327 | __ bind(&load_smi); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5328 | // Smi to XMM conversion. Clobbering a temp is faster than re-tagging the |
| 5329 | // input register since we avoid dependencies. |
| 5330 | __ mov(temp_reg, input_reg); |
| 5331 | __ SmiUntag(temp_reg); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5332 | __ Cvtsi2sd(result_reg, Operand(temp_reg)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5333 | __ bind(&done); |
| 5334 | } |
| 5335 | |
| 5336 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5337 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, Label* done) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5338 | Register input_reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5339 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5340 | if (instr->truncating()) { |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 5341 | Label no_heap_number, check_bools, check_false; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5342 | |
| 5343 | // Heap number map check. |
| 5344 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5345 | factory()->heap_number_map()); |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 5346 | __ j(not_equal, &no_heap_number, Label::kNear); |
| 5347 | __ TruncateHeapNumberToI(input_reg, input_reg); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5348 | __ jmp(done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5349 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 5350 | __ bind(&no_heap_number); |
| 5351 | // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 5352 | // for truncating conversions. |
| 5353 | __ cmp(input_reg, factory()->undefined_value()); |
| 5354 | __ j(not_equal, &check_bools, Label::kNear); |
| 5355 | __ Set(input_reg, Immediate(0)); |
| 5356 | __ jmp(done); |
| 5357 | |
| 5358 | __ bind(&check_bools); |
| 5359 | __ cmp(input_reg, factory()->true_value()); |
| 5360 | __ j(not_equal, &check_false, Label::kNear); |
| 5361 | __ Set(input_reg, Immediate(1)); |
| 5362 | __ jmp(done); |
| 5363 | |
| 5364 | __ bind(&check_false); |
| 5365 | __ cmp(input_reg, factory()->false_value()); |
| 5366 | __ RecordComment("Deferred TaggedToI: cannot truncate"); |
| 5367 | DeoptimizeIf(not_equal, instr->environment()); |
| 5368 | __ Set(input_reg, Immediate(0)); |
| 5369 | __ jmp(done); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5370 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5371 | Label bailout; |
| 5372 | XMMRegister scratch = (instr->temp() != NULL) |
| 5373 | ? ToDoubleRegister(instr->temp()) |
| 5374 | : no_xmm_reg; |
| 5375 | __ TaggedToI(input_reg, input_reg, scratch, |
| 5376 | instr->hydrogen()->GetMinusZeroMode(), &bailout); |
| 5377 | __ jmp(done); |
| 5378 | __ bind(&bailout); |
| 5379 | DeoptimizeIf(no_condition, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5380 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | |
| 5384 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5385 | class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5386 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5387 | DeferredTaggedToI(LCodeGen* codegen, |
| 5388 | LTaggedToI* instr, |
| 5389 | const X87Stack& x87_stack) |
| 5390 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5391 | virtual void Generate() V8_OVERRIDE { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5392 | codegen()->DoDeferredTaggedToI(instr_, done()); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5393 | } |
| 5394 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5395 | private: |
| 5396 | LTaggedToI* instr_; |
| 5397 | }; |
| 5398 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5399 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5400 | ASSERT(input->IsRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5401 | Register input_reg = ToRegister(input); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5402 | ASSERT(input_reg.is(ToRegister(instr->result()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5403 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5404 | if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 5405 | __ SmiUntag(input_reg); |
| 5406 | } else { |
| 5407 | DeferredTaggedToI* deferred = |
| 5408 | new(zone()) DeferredTaggedToI(this, instr, x87_stack_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5409 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5410 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 5411 | __ SmiUntag(input_reg); |
| 5412 | __ bind(deferred->exit()); |
| 5413 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5417 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5418 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5419 | ASSERT(input->IsRegister()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5420 | LOperand* temp = instr->temp(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5421 | ASSERT(temp->IsRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5422 | LOperand* result = instr->result(); |
| 5423 | ASSERT(result->IsDoubleRegister()); |
| 5424 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5425 | Register input_reg = ToRegister(input); |
| 5426 | bool deoptimize_on_minus_zero = |
| 5427 | instr->hydrogen()->deoptimize_on_minus_zero(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5428 | Register temp_reg = ToRegister(temp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5429 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5430 | HValue* value = instr->hydrogen()->value(); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5431 | NumberUntagDMode mode = value->representation().IsSmi() |
| 5432 | ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5433 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5434 | if (CpuFeatures::IsSupported(SSE2)) { |
| 5435 | CpuFeatureScope scope(masm(), SSE2); |
| 5436 | XMMRegister result_reg = ToDoubleRegister(result); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5437 | EmitNumberUntagD(input_reg, |
| 5438 | temp_reg, |
| 5439 | result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5440 | instr->hydrogen()->can_convert_undefined_to_nan(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5441 | deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5442 | instr->environment(), |
| 5443 | mode); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5444 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5445 | EmitNumberUntagDNoSSE2(input_reg, |
| 5446 | temp_reg, |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5447 | ToX87Register(instr->result()), |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5448 | instr->hydrogen()->can_convert_undefined_to_nan(), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5449 | deoptimize_on_minus_zero, |
| 5450 | instr->environment(), |
| 5451 | mode); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5452 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | |
| 5456 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5457 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5458 | ASSERT(input->IsDoubleRegister()); |
| 5459 | LOperand* result = instr->result(); |
| 5460 | ASSERT(result->IsRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5461 | Register result_reg = ToRegister(result); |
| 5462 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5463 | if (instr->truncating()) { |
| 5464 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 5465 | CpuFeatureScope scope(masm(), SSE2); |
| 5466 | XMMRegister input_reg = ToDoubleRegister(input); |
| 5467 | __ TruncateDoubleToI(result_reg, input_reg); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5468 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5469 | X87Register input_reg = ToX87Register(input); |
| 5470 | X87Fxch(input_reg); |
| 5471 | __ TruncateX87TOSToI(result_reg); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5472 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5473 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5474 | Label bailout, done; |
| 5475 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 5476 | CpuFeatureScope scope(masm(), SSE2); |
| 5477 | XMMRegister input_reg = ToDoubleRegister(input); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5478 | XMMRegister xmm_scratch = double_scratch0(); |
| 5479 | __ DoubleToI(result_reg, input_reg, xmm_scratch, |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5480 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5481 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5482 | X87Register input_reg = ToX87Register(input); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5483 | X87Fxch(input_reg); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5484 | __ X87TOSToI(result_reg, instr->hydrogen()->GetMinusZeroMode(), |
| 5485 | &bailout, Label::kNear); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5486 | } |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5487 | __ jmp(&done, Label::kNear); |
| 5488 | __ bind(&bailout); |
| 5489 | DeoptimizeIf(no_condition, instr->environment()); |
| 5490 | __ bind(&done); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | |
| 5495 | void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 5496 | LOperand* input = instr->value(); |
| 5497 | ASSERT(input->IsDoubleRegister()); |
| 5498 | LOperand* result = instr->result(); |
| 5499 | ASSERT(result->IsRegister()); |
| 5500 | Register result_reg = ToRegister(result); |
| 5501 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5502 | Label bailout, done; |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5503 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
| 5504 | CpuFeatureScope scope(masm(), SSE2); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5505 | XMMRegister input_reg = ToDoubleRegister(input); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5506 | XMMRegister xmm_scratch = double_scratch0(); |
| 5507 | __ DoubleToI(result_reg, input_reg, xmm_scratch, |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5508 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5509 | } else { |
| 5510 | X87Register input_reg = ToX87Register(input); |
| 5511 | X87Fxch(input_reg); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5512 | __ X87TOSToI(result_reg, instr->hydrogen()->GetMinusZeroMode(), |
| 5513 | &bailout, Label::kNear); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5514 | } |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5515 | __ jmp(&done, Label::kNear); |
| 5516 | __ bind(&bailout); |
| 5517 | DeoptimizeIf(no_condition, instr->environment()); |
| 5518 | __ bind(&done); |
| 5519 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5520 | __ SmiTag(result_reg); |
| 5521 | DeoptimizeIf(overflow, instr->environment()); |
| 5522 | } |
| 5523 | |
| 5524 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5525 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5526 | LOperand* input = instr->value(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5527 | __ test(ToOperand(input), Immediate(kSmiTagMask)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5528 | DeoptimizeIf(not_zero, instr->environment()); |
| 5529 | } |
| 5530 | |
| 5531 | |
| 5532 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5533 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 5534 | LOperand* input = instr->value(); |
| 5535 | __ test(ToOperand(input), Immediate(kSmiTagMask)); |
| 5536 | DeoptimizeIf(zero, instr->environment()); |
| 5537 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | |
| 5541 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5542 | Register input = ToRegister(instr->value()); |
| 5543 | Register temp = ToRegister(instr->temp()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5544 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5545 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5546 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5547 | if (instr->hydrogen()->is_interval_check()) { |
| 5548 | InstanceType first; |
| 5549 | InstanceType last; |
| 5550 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5551 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5552 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 5553 | static_cast<int8_t>(first)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5554 | |
| 5555 | // If there is only one type in the interval check for equality. |
| 5556 | if (first == last) { |
| 5557 | DeoptimizeIf(not_equal, instr->environment()); |
| 5558 | } else { |
| 5559 | DeoptimizeIf(below, instr->environment()); |
| 5560 | // Omit check for the last type. |
| 5561 | if (last != LAST_TYPE) { |
| 5562 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 5563 | static_cast<int8_t>(last)); |
| 5564 | DeoptimizeIf(above, instr->environment()); |
| 5565 | } |
| 5566 | } |
| 5567 | } else { |
| 5568 | uint8_t mask; |
| 5569 | uint8_t tag; |
| 5570 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5571 | |
| 5572 | if (IsPowerOf2(mask)) { |
| 5573 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 5574 | __ test_b(FieldOperand(temp, Map::kInstanceTypeOffset), mask); |
| 5575 | DeoptimizeIf(tag == 0 ? not_zero : zero, instr->environment()); |
| 5576 | } else { |
| 5577 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5578 | __ and_(temp, mask); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5579 | __ cmp(temp, tag); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5580 | DeoptimizeIf(not_equal, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5581 | } |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5586 | void LCodeGen::DoCheckValue(LCheckValue* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5587 | Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5588 | if (instr->hydrogen()->object_in_new_space()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5589 | Register reg = ToRegister(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5590 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5591 | __ cmp(reg, Operand::ForCell(cell)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5592 | } else { |
| 5593 | Operand operand = ToOperand(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5594 | __ cmp(operand, object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5595 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5596 | DeoptimizeIf(not_equal, instr->environment()); |
| 5597 | } |
| 5598 | |
| 5599 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5600 | void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5601 | { |
| 5602 | PushSafepointRegistersScope scope(this); |
| 5603 | __ push(object); |
| 5604 | __ xor_(esi, esi); |
| 5605 | __ CallRuntimeSaveDoubles(Runtime::kMigrateInstance); |
| 5606 | RecordSafepointWithRegisters( |
| 5607 | instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); |
| 5608 | |
| 5609 | __ test(eax, Immediate(kSmiTagMask)); |
| 5610 | } |
| 5611 | DeoptimizeIf(zero, instr->environment()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5615 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5616 | class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5617 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5618 | DeferredCheckMaps(LCodeGen* codegen, |
| 5619 | LCheckMaps* instr, |
| 5620 | Register object, |
| 5621 | const X87Stack& x87_stack) |
| 5622 | : LDeferredCode(codegen, x87_stack), instr_(instr), object_(object) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5623 | SetExit(check_maps()); |
| 5624 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5625 | virtual void Generate() V8_OVERRIDE { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5626 | codegen()->DoDeferredInstanceMigration(instr_, object_); |
| 5627 | } |
| 5628 | Label* check_maps() { return &check_maps_; } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5629 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5630 | private: |
| 5631 | LCheckMaps* instr_; |
| 5632 | Label check_maps_; |
| 5633 | Register object_; |
| 5634 | }; |
| 5635 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5636 | if (instr->hydrogen()->CanOmitMapChecks()) return; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5637 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5638 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5639 | ASSERT(input->IsRegister()); |
| 5640 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5641 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5642 | DeferredCheckMaps* deferred = NULL; |
| 5643 | if (instr->hydrogen()->has_migration_target()) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5644 | deferred = new(zone()) DeferredCheckMaps(this, instr, reg, x87_stack_); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5645 | __ bind(deferred->check_maps()); |
| 5646 | } |
| 5647 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5648 | UniqueSet<Map> map_set = instr->hydrogen()->map_set(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5649 | Label success; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5650 | for (int i = 0; i < map_set.size() - 1; i++) { |
| 5651 | Handle<Map> map = map_set.at(i).handle(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5652 | __ CompareMap(reg, map); |
| 5653 | __ j(equal, &success, Label::kNear); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5654 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5655 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5656 | Handle<Map> map = map_set.at(map_set.size() - 1).handle(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5657 | __ CompareMap(reg, map); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5658 | if (instr->hydrogen()->has_migration_target()) { |
| 5659 | __ j(not_equal, deferred->entry()); |
| 5660 | } else { |
| 5661 | DeoptimizeIf(not_equal, instr->environment()); |
| 5662 | } |
| 5663 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5664 | __ bind(&success); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5668 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5669 | CpuFeatureScope scope(masm(), SSE2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5670 | XMMRegister value_reg = ToDoubleRegister(instr->unclamped()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5671 | XMMRegister xmm_scratch = double_scratch0(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5672 | Register result_reg = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5673 | __ ClampDoubleToUint8(value_reg, xmm_scratch, result_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | |
| 5677 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5678 | ASSERT(instr->unclamped()->Equals(instr->result())); |
| 5679 | Register value_reg = ToRegister(instr->result()); |
| 5680 | __ ClampUint8(value_reg); |
| 5681 | } |
| 5682 | |
| 5683 | |
| 5684 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5685 | CpuFeatureScope scope(masm(), SSE2); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5686 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5687 | ASSERT(instr->unclamped()->Equals(instr->result())); |
| 5688 | Register input_reg = ToRegister(instr->unclamped()); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5689 | XMMRegister temp_xmm_reg = ToDoubleRegister(instr->temp_xmm()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5690 | XMMRegister xmm_scratch = double_scratch0(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5691 | Label is_smi, done, heap_number; |
| 5692 | |
| 5693 | __ JumpIfSmi(input_reg, &is_smi); |
| 5694 | |
| 5695 | // Check for heap number |
| 5696 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5697 | factory()->heap_number_map()); |
| 5698 | __ j(equal, &heap_number, Label::kNear); |
| 5699 | |
| 5700 | // Check for undefined. Undefined is converted to zero for clamping |
| 5701 | // conversions. |
| 5702 | __ cmp(input_reg, factory()->undefined_value()); |
| 5703 | DeoptimizeIf(not_equal, instr->environment()); |
| 5704 | __ mov(input_reg, 0); |
| 5705 | __ jmp(&done, Label::kNear); |
| 5706 | |
| 5707 | // Heap number |
| 5708 | __ bind(&heap_number); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 5709 | __ movsd(xmm_scratch, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5710 | __ ClampDoubleToUint8(xmm_scratch, temp_xmm_reg, input_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5711 | __ jmp(&done, Label::kNear); |
| 5712 | |
| 5713 | // smi |
| 5714 | __ bind(&is_smi); |
| 5715 | __ SmiUntag(input_reg); |
| 5716 | __ ClampUint8(input_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5717 | __ bind(&done); |
| 5718 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5719 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5720 | |
| 5721 | void LCodeGen::DoClampTToUint8NoSSE2(LClampTToUint8NoSSE2* instr) { |
| 5722 | Register input_reg = ToRegister(instr->unclamped()); |
| 5723 | Register result_reg = ToRegister(instr->result()); |
| 5724 | Register scratch = ToRegister(instr->scratch()); |
| 5725 | Register scratch2 = ToRegister(instr->scratch2()); |
| 5726 | Register scratch3 = ToRegister(instr->scratch3()); |
| 5727 | Label is_smi, done, heap_number, valid_exponent, |
| 5728 | largest_value, zero_result, maybe_nan_or_infinity; |
| 5729 | |
| 5730 | __ JumpIfSmi(input_reg, &is_smi); |
| 5731 | |
| 5732 | // Check for heap number |
| 5733 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5734 | factory()->heap_number_map()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5735 | __ j(equal, &heap_number, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5736 | |
| 5737 | // Check for undefined. Undefined is converted to zero for clamping |
| 5738 | // conversions. |
| 5739 | __ cmp(input_reg, factory()->undefined_value()); |
| 5740 | DeoptimizeIf(not_equal, instr->environment()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5741 | __ jmp(&zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5742 | |
| 5743 | // Heap number |
| 5744 | __ bind(&heap_number); |
| 5745 | |
| 5746 | // Surprisingly, all of the hand-crafted bit-manipulations below are much |
| 5747 | // faster than the x86 FPU built-in instruction, especially since "banker's |
| 5748 | // rounding" would be additionally very expensive |
| 5749 | |
| 5750 | // Get exponent word. |
| 5751 | __ mov(scratch, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 5752 | __ mov(scratch3, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
| 5753 | |
| 5754 | // Test for negative values --> clamp to zero |
| 5755 | __ test(scratch, scratch); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5756 | __ j(negative, &zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5757 | |
| 5758 | // Get exponent alone in scratch2. |
| 5759 | __ mov(scratch2, scratch); |
| 5760 | __ and_(scratch2, HeapNumber::kExponentMask); |
| 5761 | __ shr(scratch2, HeapNumber::kExponentShift); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5762 | __ j(zero, &zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5763 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias - 1)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5764 | __ j(negative, &zero_result, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5765 | |
| 5766 | const uint32_t non_int8_exponent = 7; |
| 5767 | __ cmp(scratch2, Immediate(non_int8_exponent + 1)); |
| 5768 | // If the exponent is too big, check for special values. |
| 5769 | __ j(greater, &maybe_nan_or_infinity, Label::kNear); |
| 5770 | |
| 5771 | __ bind(&valid_exponent); |
| 5772 | // Exponent word in scratch, exponent in scratch2. We know that 0 <= exponent |
| 5773 | // < 7. The shift bias is the number of bits to shift the mantissa such that |
| 5774 | // with an exponent of 7 such the that top-most one is in bit 30, allowing |
| 5775 | // detection the rounding overflow of a 255.5 to 256 (bit 31 goes from 0 to |
| 5776 | // 1). |
| 5777 | int shift_bias = (30 - HeapNumber::kExponentShift) - 7 - 1; |
| 5778 | __ lea(result_reg, MemOperand(scratch2, shift_bias)); |
| 5779 | // Here result_reg (ecx) is the shift, scratch is the exponent word. Get the |
| 5780 | // top bits of the mantissa. |
| 5781 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 5782 | // Put back the implicit 1 of the mantissa |
| 5783 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 5784 | // Shift up to round |
| 5785 | __ shl_cl(scratch); |
| 5786 | // Use "banker's rounding" to spec: If fractional part of number is 0.5, then |
| 5787 | // use the bit in the "ones" place and add it to the "halves" place, which has |
| 5788 | // the effect of rounding to even. |
| 5789 | __ mov(scratch2, scratch); |
| 5790 | const uint32_t one_half_bit_shift = 30 - sizeof(uint8_t) * 8; |
| 5791 | const uint32_t one_bit_shift = one_half_bit_shift + 1; |
| 5792 | __ and_(scratch2, Immediate((1 << one_bit_shift) - 1)); |
| 5793 | __ cmp(scratch2, Immediate(1 << one_half_bit_shift)); |
| 5794 | Label no_round; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5795 | __ j(less, &no_round, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5796 | Label round_up; |
| 5797 | __ mov(scratch2, Immediate(1 << one_half_bit_shift)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5798 | __ j(greater, &round_up, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5799 | __ test(scratch3, scratch3); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5800 | __ j(not_zero, &round_up, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5801 | __ mov(scratch2, scratch); |
| 5802 | __ and_(scratch2, Immediate(1 << one_bit_shift)); |
| 5803 | __ shr(scratch2, 1); |
| 5804 | __ bind(&round_up); |
| 5805 | __ add(scratch, scratch2); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5806 | __ j(overflow, &largest_value, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5807 | __ bind(&no_round); |
| 5808 | __ shr(scratch, 23); |
| 5809 | __ mov(result_reg, scratch); |
| 5810 | __ jmp(&done, Label::kNear); |
| 5811 | |
| 5812 | __ bind(&maybe_nan_or_infinity); |
| 5813 | // Check for NaN/Infinity, all other values map to 255 |
| 5814 | __ cmp(scratch2, Immediate(HeapNumber::kInfinityOrNanExponent + 1)); |
| 5815 | __ j(not_equal, &largest_value, Label::kNear); |
| 5816 | |
| 5817 | // Check for NaN, which differs from Infinity in that at least one mantissa |
| 5818 | // bit is set. |
| 5819 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 5820 | __ or_(scratch, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5821 | __ j(not_zero, &zero_result, Label::kNear); // M!=0 --> NaN |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5822 | // Infinity -> Fall through to map to 255. |
| 5823 | |
| 5824 | __ bind(&largest_value); |
| 5825 | __ mov(result_reg, Immediate(255)); |
| 5826 | __ jmp(&done, Label::kNear); |
| 5827 | |
| 5828 | __ bind(&zero_result); |
| 5829 | __ xor_(result_reg, result_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5830 | __ jmp(&done, Label::kNear); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5831 | |
| 5832 | // smi |
| 5833 | __ bind(&is_smi); |
| 5834 | if (!input_reg.is(result_reg)) { |
| 5835 | __ mov(result_reg, input_reg); |
| 5836 | } |
| 5837 | __ SmiUntag(result_reg); |
| 5838 | __ ClampUint8(result_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5839 | __ bind(&done); |
| 5840 | } |
| 5841 | |
| 5842 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5843 | void LCodeGen::DoAllocate(LAllocate* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5844 | class DeferredAllocate V8_FINAL : public LDeferredCode { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5845 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5846 | DeferredAllocate(LCodeGen* codegen, |
| 5847 | LAllocate* instr, |
| 5848 | const X87Stack& x87_stack) |
| 5849 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5850 | virtual void Generate() V8_OVERRIDE { |
| 5851 | codegen()->DoDeferredAllocate(instr_); |
| 5852 | } |
| 5853 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5854 | private: |
| 5855 | LAllocate* instr_; |
| 5856 | }; |
| 5857 | |
| 5858 | DeferredAllocate* deferred = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5859 | new(zone()) DeferredAllocate(this, instr, x87_stack_); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5860 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5861 | Register result = ToRegister(instr->result()); |
| 5862 | Register temp = ToRegister(instr->temp()); |
| 5863 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5864 | // Allocate memory for the object. |
| 5865 | AllocationFlags flags = TAG_OBJECT; |
| 5866 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5867 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5868 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5869 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5870 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5871 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5872 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5873 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5874 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5875 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5876 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5877 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5878 | if (instr->size()->IsConstantOperand()) { |
| 5879 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5880 | __ Allocate(size, result, temp, no_reg, deferred->entry(), flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5881 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5882 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5883 | __ Allocate(size, result, temp, no_reg, deferred->entry(), flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | __ bind(deferred->exit()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5887 | |
| 5888 | if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 5889 | if (instr->size()->IsConstantOperand()) { |
| 5890 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5891 | __ mov(temp, (size / kPointerSize) - 1); |
| 5892 | } else { |
| 5893 | temp = ToRegister(instr->size()); |
| 5894 | __ shr(temp, kPointerSizeLog2); |
| 5895 | __ dec(temp); |
| 5896 | } |
| 5897 | Label loop; |
| 5898 | __ bind(&loop); |
| 5899 | __ mov(FieldOperand(result, temp, times_pointer_size, 0), |
| 5900 | isolate()->factory()->one_pointer_filler_map()); |
| 5901 | __ dec(temp); |
| 5902 | __ j(not_zero, &loop); |
| 5903 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | |
| 5907 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5908 | Register result = ToRegister(instr->result()); |
| 5909 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5910 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5911 | // result register contain a valid pointer because it is already |
| 5912 | // contained in the register pointer map. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5913 | __ Set(result, Immediate(Smi::FromInt(0))); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5914 | |
| 5915 | PushSafepointRegistersScope scope(this); |
| 5916 | if (instr->size()->IsRegister()) { |
| 5917 | Register size = ToRegister(instr->size()); |
| 5918 | ASSERT(!size.is(result)); |
| 5919 | __ SmiTag(ToRegister(instr->size())); |
| 5920 | __ push(size); |
| 5921 | } else { |
| 5922 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5923 | __ push(Immediate(Smi::FromInt(size))); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5924 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5925 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5926 | int flags = AllocateDoubleAlignFlag::encode( |
| 5927 | instr->hydrogen()->MustAllocateDoubleAligned()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5928 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5929 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5930 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5931 | flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5932 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5933 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5934 | flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5935 | } else { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5936 | flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5937 | } |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5938 | __ push(Immediate(Smi::FromInt(flags))); |
| 5939 | |
| 5940 | CallRuntimeFromDeferred( |
| 5941 | Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5942 | __ StoreToSafepointRegisterSlot(result, eax); |
| 5943 | } |
| 5944 | |
| 5945 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5946 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5947 | ASSERT(ToRegister(instr->value()).is(eax)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5948 | __ push(eax); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5949 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5953 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5954 | ASSERT(ToRegister(instr->context()).is(esi)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5955 | Label materialized; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5956 | // Registers will be used as follows: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5957 | // ecx = literals array. |
| 5958 | // ebx = regexp literal. |
| 5959 | // eax = regexp literal clone. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5960 | // esi = context. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5961 | int literal_offset = |
| 5962 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
| 5963 | __ LoadHeapObject(ecx, instr->hydrogen()->literals()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5964 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5965 | __ cmp(ebx, factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5966 | __ j(not_equal, &materialized, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5967 | |
| 5968 | // Create regexp literal using runtime function |
| 5969 | // Result will be in eax. |
| 5970 | __ push(ecx); |
| 5971 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5972 | __ push(Immediate(instr->hydrogen()->pattern())); |
| 5973 | __ push(Immediate(instr->hydrogen()->flags())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5974 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5975 | __ mov(ebx, eax); |
| 5976 | |
| 5977 | __ bind(&materialized); |
| 5978 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5979 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5980 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5981 | __ jmp(&allocated, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5982 | |
| 5983 | __ bind(&runtime_allocate); |
| 5984 | __ push(ebx); |
| 5985 | __ push(Immediate(Smi::FromInt(size))); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5986 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5987 | __ pop(ebx); |
| 5988 | |
| 5989 | __ bind(&allocated); |
| 5990 | // Copy the content into the newly allocated memory. |
| 5991 | // (Unroll copy loop once for better throughput). |
| 5992 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 5993 | __ mov(edx, FieldOperand(ebx, i)); |
| 5994 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 5995 | __ mov(FieldOperand(eax, i), edx); |
| 5996 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 5997 | } |
| 5998 | if ((size % (2 * kPointerSize)) != 0) { |
| 5999 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 6000 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | |
| 6005 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6006 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6007 | // Use the fast case closure allocation code that allocates in new |
| 6008 | // space for nested functions that don't need literals cloning. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 6009 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6010 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
| 6011 | FastNewClosureStub stub(instr->hydrogen()->language_mode(), |
| 6012 | instr->hydrogen()->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 6013 | __ mov(ebx, Immediate(instr->hydrogen()->shared_info())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6014 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6015 | } else { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6016 | __ push(esi); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6017 | __ push(Immediate(instr->hydrogen()->shared_info())); |
| 6018 | __ push(Immediate(pretenure ? factory()->true_value() |
| 6019 | : factory()->false_value())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6020 | CallRuntime(Runtime::kNewClosure, 3, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6021 | } |
| 6022 | } |
| 6023 | |
| 6024 | |
| 6025 | void LCodeGen::DoTypeof(LTypeof* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6026 | ASSERT(ToRegister(instr->context()).is(esi)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6027 | LOperand* input = instr->value(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6028 | EmitPushTaggedOperand(input); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6029 | CallRuntime(Runtime::kTypeof, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6033 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6034 | Register input = ToRegister(instr->value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6035 | Condition final_branch_condition = EmitTypeofIs(instr, input); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6036 | if (final_branch_condition != no_condition) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6037 | EmitBranch(instr, final_branch_condition); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6038 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6042 | Condition LCodeGen::EmitTypeofIs(LTypeofIsAndBranch* instr, Register input) { |
| 6043 | Label* true_label = instr->TrueLabel(chunk_); |
| 6044 | Label* false_label = instr->FalseLabel(chunk_); |
| 6045 | Handle<String> type_name = instr->type_literal(); |
| 6046 | int left_block = instr->TrueDestination(chunk_); |
| 6047 | int right_block = instr->FalseDestination(chunk_); |
| 6048 | int next_block = GetNextEmittedBlock(); |
| 6049 | |
| 6050 | Label::Distance true_distance = left_block == next_block ? Label::kNear |
| 6051 | : Label::kFar; |
| 6052 | Label::Distance false_distance = right_block == next_block ? Label::kNear |
| 6053 | : Label::kFar; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6054 | Condition final_branch_condition = no_condition; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6055 | if (type_name->Equals(heap()->number_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6056 | __ JumpIfSmi(input, true_label, true_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6057 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6058 | factory()->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6059 | final_branch_condition = equal; |
| 6060 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6061 | } else if (type_name->Equals(heap()->string_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6062 | __ JumpIfSmi(input, false_label, false_distance); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 6063 | __ CmpObjectType(input, FIRST_NONSTRING_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6064 | __ j(above_equal, false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6065 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 6066 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 6067 | final_branch_condition = zero; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6068 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6069 | } else if (type_name->Equals(heap()->symbol_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6070 | __ JumpIfSmi(input, false_label, false_distance); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6071 | __ CmpObjectType(input, SYMBOL_TYPE, input); |
| 6072 | final_branch_condition = equal; |
| 6073 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6074 | } else if (type_name->Equals(heap()->boolean_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6075 | __ cmp(input, factory()->true_value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6076 | __ j(equal, true_label, true_distance); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6077 | __ cmp(input, factory()->false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6078 | final_branch_condition = equal; |
| 6079 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6080 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6081 | __ cmp(input, factory()->null_value()); |
| 6082 | final_branch_condition = equal; |
| 6083 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6084 | } else if (type_name->Equals(heap()->undefined_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6085 | __ cmp(input, factory()->undefined_value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6086 | __ j(equal, true_label, true_distance); |
| 6087 | __ JumpIfSmi(input, false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6088 | // Check for undetectable objects => true. |
| 6089 | __ mov(input, FieldOperand(input, HeapObject::kMapOffset)); |
| 6090 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 6091 | 1 << Map::kIsUndetectable); |
| 6092 | final_branch_condition = not_zero; |
| 6093 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6094 | } else if (type_name->Equals(heap()->function_string())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6095 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6096 | __ JumpIfSmi(input, false_label, false_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6097 | __ CmpObjectType(input, JS_FUNCTION_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6098 | __ j(equal, true_label, true_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6099 | __ CmpInstanceType(input, JS_FUNCTION_PROXY_TYPE); |
| 6100 | final_branch_condition = equal; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6101 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6102 | } else if (type_name->Equals(heap()->object_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6103 | __ JumpIfSmi(input, false_label, false_distance); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6104 | if (!FLAG_harmony_typeof) { |
| 6105 | __ cmp(input, factory()->null_value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6106 | __ j(equal, true_label, true_distance); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6107 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6108 | __ CmpObjectType(input, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6109 | __ j(below, false_label, false_distance); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6110 | __ CmpInstanceType(input, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6111 | __ j(above, false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6112 | // Check for undetectable objects => false. |
| 6113 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 6114 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 6115 | final_branch_condition = zero; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6116 | |
| 6117 | } else { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 6118 | __ jmp(false_label, false_distance); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6119 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6120 | return final_branch_condition; |
| 6121 | } |
| 6122 | |
| 6123 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6124 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 6125 | Register temp = ToRegister(instr->temp()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6126 | |
| 6127 | EmitIsConstructCall(temp); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6128 | EmitBranch(instr, equal); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | |
| 6132 | void LCodeGen::EmitIsConstructCall(Register temp) { |
| 6133 | // Get the frame pointer for the calling frame. |
| 6134 | __ mov(temp, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 6135 | |
| 6136 | // Skip the arguments adaptor frame if it exists. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6137 | Label check_frame_marker; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6138 | __ cmp(Operand(temp, StandardFrameConstants::kContextOffset), |
| 6139 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6140 | __ j(not_equal, &check_frame_marker, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 6141 | __ mov(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset)); |
| 6142 | |
| 6143 | // Check the marker in the calling frame. |
| 6144 | __ bind(&check_frame_marker); |
| 6145 | __ cmp(Operand(temp, StandardFrameConstants::kMarkerOffset), |
| 6146 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 6147 | } |
| 6148 | |
| 6149 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6150 | void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 6151 | if (!info()->IsStub()) { |
| 6152 | // Ensure that we have enough space after the previous lazy-bailout |
| 6153 | // instruction for patching the code here. |
| 6154 | int current_pc = masm()->pc_offset(); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6155 | if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
| 6156 | int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 6157 | __ Nop(padding_size); |
| 6158 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6159 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 6160 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6164 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6165 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6166 | ASSERT(instr->HasEnvironment()); |
| 6167 | LEnvironment* env = instr->environment(); |
| 6168 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 6169 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | |
| 6173 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 6174 | Deoptimizer::BailoutType type = instr->hydrogen()->type(); |
| 6175 | // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the |
| 6176 | // needed return address), even though the implementation of LAZY and EAGER is |
| 6177 | // now identical. When LAZY is eventually completely folded into EAGER, remove |
| 6178 | // the special case below. |
| 6179 | if (info()->IsStub() && type == Deoptimizer::EAGER) { |
| 6180 | type = Deoptimizer::LAZY; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 6181 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 6182 | Comment(";;; deoptimize: %s", instr->hydrogen()->reason()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 6183 | DeoptimizeIf(no_condition, instr->environment(), type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6187 | void LCodeGen::DoDummy(LDummy* instr) { |
| 6188 | // Nothing to see here, move on! |
| 6189 | } |
| 6190 | |
| 6191 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 6192 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 6193 | // Nothing to see here, move on! |
| 6194 | } |
| 6195 | |
| 6196 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6197 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6198 | PushSafepointRegistersScope scope(this); |
| 6199 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 6200 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 6201 | RecordSafepointWithLazyDeopt( |
| 6202 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 6203 | ASSERT(instr->HasEnvironment()); |
| 6204 | LEnvironment* env = instr->environment(); |
| 6205 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6206 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6207 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6208 | |
| 6209 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 6210 | class DeferredStackCheck V8_FINAL : public LDeferredCode { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6211 | public: |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 6212 | DeferredStackCheck(LCodeGen* codegen, |
| 6213 | LStackCheck* instr, |
| 6214 | const X87Stack& x87_stack) |
| 6215 | : LDeferredCode(codegen, x87_stack), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 6216 | virtual void Generate() V8_OVERRIDE { |
| 6217 | codegen()->DoDeferredStackCheck(instr_); |
| 6218 | } |
| 6219 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6220 | private: |
| 6221 | LStackCheck* instr_; |
| 6222 | }; |
| 6223 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6224 | ASSERT(instr->HasEnvironment()); |
| 6225 | LEnvironment* env = instr->environment(); |
| 6226 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 6227 | // prepare for lazy deoptimization explicitly here. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6228 | if (instr->hydrogen()->is_function_entry()) { |
| 6229 | // Perform stack overflow check. |
| 6230 | Label done; |
| 6231 | ExternalReference stack_limit = |
| 6232 | ExternalReference::address_of_stack_limit(isolate()); |
| 6233 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 6234 | __ j(above_equal, &done, Label::kNear); |
| 6235 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6236 | ASSERT(instr->context()->IsRegister()); |
| 6237 | ASSERT(ToRegister(instr->context()).is(esi)); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 6238 | CallCode(isolate()->builtins()->StackCheck(), |
| 6239 | RelocInfo::CODE_TARGET, |
| 6240 | instr); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6241 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6242 | __ bind(&done); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6243 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 6244 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6245 | } else { |
| 6246 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 6247 | // Perform stack overflow check if this goto needs it before jumping. |
| 6248 | DeferredStackCheck* deferred_stack_check = |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 6249 | new(zone()) DeferredStackCheck(this, instr, x87_stack_); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6250 | ExternalReference stack_limit = |
| 6251 | ExternalReference::address_of_stack_limit(isolate()); |
| 6252 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 6253 | __ j(below, deferred_stack_check->entry()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 6254 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6255 | __ bind(instr->done_label()); |
| 6256 | deferred_stack_check->SetExit(instr->done_label()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6257 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 6258 | // Don't record a deoptimization index for the safepoint here. |
| 6259 | // This will be done explicitly when emitting call and the safepoint in |
| 6260 | // the deferred code. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 6261 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | |
| 6265 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 6266 | // This is a pseudo-instruction that ensures that the environment here is |
| 6267 | // properly registered for deoptimization and records the assembler's PC |
| 6268 | // offset. |
| 6269 | LEnvironment* environment = instr->environment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6270 | |
| 6271 | // If the environment were already registered, we would have no way of |
| 6272 | // backpatching it with the spill slot operands. |
| 6273 | ASSERT(!environment->HasBeenRegistered()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 6274 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6275 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 6276 | GenerateOsrPrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6280 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6281 | ASSERT(ToRegister(instr->context()).is(esi)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6282 | __ cmp(eax, isolate()->factory()->undefined_value()); |
| 6283 | DeoptimizeIf(equal, instr->environment()); |
| 6284 | |
| 6285 | __ cmp(eax, isolate()->factory()->null_value()); |
| 6286 | DeoptimizeIf(equal, instr->environment()); |
| 6287 | |
| 6288 | __ test(eax, Immediate(kSmiTagMask)); |
| 6289 | DeoptimizeIf(zero, instr->environment()); |
| 6290 | |
| 6291 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 6292 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 6293 | DeoptimizeIf(below_equal, instr->environment()); |
| 6294 | |
| 6295 | Label use_cache, call_runtime; |
| 6296 | __ CheckEnumCache(&call_runtime); |
| 6297 | |
| 6298 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6299 | __ jmp(&use_cache, Label::kNear); |
| 6300 | |
| 6301 | // Get the set of properties to enumerate. |
| 6302 | __ bind(&call_runtime); |
| 6303 | __ push(eax); |
| 6304 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 6305 | |
| 6306 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6307 | isolate()->factory()->meta_map()); |
| 6308 | DeoptimizeIf(not_equal, instr->environment()); |
| 6309 | __ bind(&use_cache); |
| 6310 | } |
| 6311 | |
| 6312 | |
| 6313 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 6314 | Register map = ToRegister(instr->map()); |
| 6315 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6316 | Label load_cache, done; |
| 6317 | __ EnumLength(result, map); |
| 6318 | __ cmp(result, Immediate(Smi::FromInt(0))); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6319 | __ j(not_equal, &load_cache, Label::kNear); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6320 | __ mov(result, isolate()->factory()->empty_fixed_array()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6321 | __ jmp(&done, Label::kNear); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6322 | |
| 6323 | __ bind(&load_cache); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6324 | __ LoadInstanceDescriptors(map, result); |
| 6325 | __ mov(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 6326 | FieldOperand(result, DescriptorArray::kEnumCacheOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6327 | __ mov(result, |
| 6328 | FieldOperand(result, FixedArray::SizeFor(instr->idx()))); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 6329 | __ bind(&done); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6330 | __ test(result, result); |
| 6331 | DeoptimizeIf(equal, instr->environment()); |
| 6332 | } |
| 6333 | |
| 6334 | |
| 6335 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 6336 | Register object = ToRegister(instr->value()); |
| 6337 | __ cmp(ToRegister(instr->map()), |
| 6338 | FieldOperand(object, HeapObject::kMapOffset)); |
| 6339 | DeoptimizeIf(not_equal, instr->environment()); |
| 6340 | } |
| 6341 | |
| 6342 | |
| 6343 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 6344 | Register object = ToRegister(instr->object()); |
| 6345 | Register index = ToRegister(instr->index()); |
| 6346 | |
| 6347 | Label out_of_object, done; |
| 6348 | __ cmp(index, Immediate(0)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 6349 | __ j(less, &out_of_object, Label::kNear); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 6350 | __ mov(object, FieldOperand(object, |
| 6351 | index, |
| 6352 | times_half_pointer_size, |
| 6353 | JSObject::kHeaderSize)); |
| 6354 | __ jmp(&done, Label::kNear); |
| 6355 | |
| 6356 | __ bind(&out_of_object); |
| 6357 | __ mov(object, FieldOperand(object, JSObject::kPropertiesOffset)); |
| 6358 | __ neg(index); |
| 6359 | // Index is now equal to out of object property index plus 1. |
| 6360 | __ mov(object, FieldOperand(object, |
| 6361 | index, |
| 6362 | times_half_pointer_size, |
| 6363 | FixedArray::kHeaderSize - kPointerSize)); |
| 6364 | __ bind(&done); |
| 6365 | } |
| 6366 | |
| 6367 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6368 | #undef __ |
| 6369 | |
| 6370 | } } // namespace v8::internal |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 6371 | |
| 6372 | #endif // V8_TARGET_ARCH_IA32 |