danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +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 | |
| 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_X64 |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 31 | |
| 32 | #include "x64/lithium-codegen-x64.h" |
| 33 | #include "code-stubs.h" |
| 34 | #include "stub-cache.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 35 | #include "hydrogen-osr.h" |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 41 | // When invoking builtins, we need to record the safepoint in the middle of |
| 42 | // the invoke instruction sequence generated by the macro assembler. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 43 | class SafepointGenerator V8_FINAL : public CallWrapper { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 44 | public: |
| 45 | SafepointGenerator(LCodeGen* codegen, |
| 46 | LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 47 | Safepoint::DeoptMode mode) |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 48 | : codegen_(codegen), |
| 49 | pointers_(pointers), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 50 | deopt_mode_(mode) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 51 | virtual ~SafepointGenerator() {} |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 52 | |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 53 | virtual void BeforeCall(int call_size) const V8_OVERRIDE {} |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 54 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 55 | virtual void AfterCall() const V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 56 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | private: |
| 60 | LCodeGen* codegen_; |
| 61 | LPointerMap* pointers_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 62 | Safepoint::DeoptMode deopt_mode_; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 66 | #define __ masm()-> |
| 67 | |
| 68 | bool LCodeGen::GenerateCode() { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 69 | LPhase phase("Z_Code generation", chunk()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 70 | ASSERT(is_unused()); |
| 71 | status_ = GENERATING; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 72 | |
| 73 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 74 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 75 | // the frame (that is done in GeneratePrologue). |
| 76 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 77 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 78 | return GeneratePrologue() && |
| 79 | GenerateBody() && |
| 80 | GenerateDeferredCode() && |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 81 | GenerateJumpTable() && |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 82 | GenerateSafepointTable(); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 87 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 88 | code->set_stack_slots(GetStackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 89 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 90 | if (code->is_optimized_code()) RegisterWeakObjectsInOptimizedCode(code); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 91 | PopulateDeoptimizationData(code); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 92 | info()->CommitDependencies(code); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 96 | void LChunkBuilder::Abort(BailoutReason reason) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 97 | info()->set_bailout_reason(reason); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 98 | status_ = ABORTED; |
| 99 | } |
| 100 | |
| 101 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 102 | #ifdef _MSC_VER |
| 103 | void LCodeGen::MakeSureStackPagesMapped(int offset) { |
| 104 | const int kPageSize = 4 * KB; |
| 105 | for (offset -= kPageSize; offset > 0; offset -= kPageSize) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 106 | __ movp(Operand(rsp, offset), rax); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | #endif |
| 110 | |
| 111 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 112 | void LCodeGen::SaveCallerDoubles() { |
| 113 | ASSERT(info()->saves_caller_doubles()); |
| 114 | ASSERT(NeedsEagerFrame()); |
| 115 | Comment(";;; Save clobbered callee double registers"); |
| 116 | int count = 0; |
| 117 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 118 | BitVector::Iterator save_iterator(doubles); |
| 119 | while (!save_iterator.Done()) { |
| 120 | __ movsd(MemOperand(rsp, count * kDoubleSize), |
| 121 | XMMRegister::FromAllocationIndex(save_iterator.Current())); |
| 122 | save_iterator.Advance(); |
| 123 | count++; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |
| 128 | void LCodeGen::RestoreCallerDoubles() { |
| 129 | ASSERT(info()->saves_caller_doubles()); |
| 130 | ASSERT(NeedsEagerFrame()); |
| 131 | Comment(";;; Restore clobbered callee double registers"); |
| 132 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 133 | BitVector::Iterator save_iterator(doubles); |
| 134 | int count = 0; |
| 135 | while (!save_iterator.Done()) { |
| 136 | __ movsd(XMMRegister::FromAllocationIndex(save_iterator.Current()), |
| 137 | MemOperand(rsp, count * kDoubleSize)); |
| 138 | save_iterator.Advance(); |
| 139 | count++; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 144 | bool LCodeGen::GeneratePrologue() { |
| 145 | ASSERT(is_generating()); |
| 146 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 147 | if (info()->IsOptimizing()) { |
| 148 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 149 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 150 | #ifdef DEBUG |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 151 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 152 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 153 | __ int3(); |
| 154 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 155 | #endif |
| 156 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 157 | // Sloppy mode functions need to replace the receiver with the global proxy |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 158 | // when called as functions (without an explicit receiver object). |
| 159 | if (info_->this_has_uses() && |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 160 | info_->strict_mode() == SLOPPY && |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 161 | !info_->is_native()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 162 | Label ok; |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 163 | StackArgumentsAccessor args(rsp, scope()->num_parameters()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 164 | __ movp(rcx, args.GetReceiverOperand()); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 165 | |
| 166 | __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); |
| 167 | __ j(not_equal, &ok, Label::kNear); |
| 168 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 169 | __ movp(rcx, GlobalObjectOperand()); |
| 170 | __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset)); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 171 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 172 | __ movp(args.GetReceiverOperand(), rcx); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 173 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 174 | __ bind(&ok); |
| 175 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 176 | } |
| 177 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 178 | info()->set_prologue_offset(masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 179 | if (NeedsEagerFrame()) { |
| 180 | ASSERT(!frame_is_built_); |
| 181 | frame_is_built_ = true; |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 182 | __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 183 | info()->AddNoFrameRange(0, masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 184 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 185 | |
| 186 | // Reserve space for the stack slots needed by the code. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 187 | int slots = GetStackSlotCount(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 188 | if (slots > 0) { |
| 189 | if (FLAG_debug_code) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 190 | __ subp(rsp, Immediate(slots * kPointerSize)); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 191 | #ifdef _MSC_VER |
| 192 | MakeSureStackPagesMapped(slots * kPointerSize); |
| 193 | #endif |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 194 | __ Push(rax); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 195 | __ Set(rax, slots); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 196 | __ movq(kScratchRegister, kSlotsZapValue); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 197 | Label loop; |
| 198 | __ bind(&loop); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 199 | __ movp(MemOperand(rsp, rax, times_pointer_size, 0), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 200 | kScratchRegister); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 201 | __ decl(rax); |
| 202 | __ j(not_zero, &loop); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 203 | __ Pop(rax); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 204 | } else { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 205 | __ subp(rsp, Immediate(slots * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 206 | #ifdef _MSC_VER |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 207 | MakeSureStackPagesMapped(slots * kPointerSize); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 208 | #endif |
| 209 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 210 | |
| 211 | if (info()->saves_caller_doubles()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 212 | SaveCallerDoubles(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 213 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 214 | } |
| 215 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 216 | // Possibly allocate a local context. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 217 | int heap_slots = info_->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 218 | if (heap_slots > 0) { |
| 219 | Comment(";;; Allocate local context"); |
| 220 | // Argument to NewContext is the function, which is still in rdi. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 221 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 222 | FastNewContextStub stub(heap_slots); |
| 223 | __ CallStub(&stub); |
| 224 | } else { |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 225 | __ Push(rdi); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 226 | __ CallRuntime(Runtime::kHiddenNewFunctionContext, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 227 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 228 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 229 | // Context is returned in rax. It replaces the context passed to us. |
| 230 | // It's saved in the stack and kept live in rsi. |
| 231 | __ movp(rsi, rax); |
| 232 | __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 233 | |
| 234 | // Copy any necessary parameters into the context. |
| 235 | int num_parameters = scope()->num_parameters(); |
| 236 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 237 | Variable* var = scope()->parameter(i); |
| 238 | if (var->IsContextSlot()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 239 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 240 | (num_parameters - 1 - i) * kPointerSize; |
| 241 | // Load parameter from stack. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 242 | __ movp(rax, Operand(rbp, parameter_offset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 243 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 244 | int context_offset = Context::SlotOffset(var->index()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 245 | __ movp(Operand(rsi, context_offset), rax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 246 | // Update the write barrier. This clobbers rax and rbx. |
| 247 | __ RecordWriteContextSlot(rsi, context_offset, rax, rbx, kSaveFPRegs); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | Comment(";;; End allocate local context"); |
| 251 | } |
| 252 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 253 | // Trace the call. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 254 | if (FLAG_trace && info()->IsOptimizing()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 255 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 256 | } |
| 257 | return !is_aborted(); |
| 258 | } |
| 259 | |
| 260 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 261 | void LCodeGen::GenerateOsrPrologue() { |
| 262 | // Generate the OSR entry prologue at the first unknown OSR value, or if there |
| 263 | // are none, at the OSR entrypoint instruction. |
| 264 | if (osr_pc_offset_ >= 0) return; |
| 265 | |
| 266 | osr_pc_offset_ = masm()->pc_offset(); |
| 267 | |
| 268 | // Adjust the frame size, subsuming the unoptimized frame into the |
| 269 | // optimized frame. |
| 270 | int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
| 271 | ASSERT(slots >= 0); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 272 | __ subp(rsp, Immediate(slots * kPointerSize)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 276 | void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 277 | if (instr->IsCall()) { |
| 278 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 279 | } |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 280 | if (!instr->IsLazyBailout() && !instr->IsGap()) { |
| 281 | safepoints_.BumpLastLazySafepointIndex(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 286 | void LCodeGen::GenerateBodyInstructionPost(LInstruction* instr) { |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 287 | if (FLAG_debug_code && FLAG_enable_slow_asserts && instr->HasResult() && |
| 288 | instr->hydrogen_value()->representation().IsInteger32() && |
| 289 | instr->result()->IsRegister()) { |
| 290 | __ AssertZeroExtended(ToRegister(instr->result())); |
| 291 | } |
| 292 | |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 293 | if (instr->HasResult() && instr->MustSignExtendResult(chunk())) { |
| 294 | if (instr->result()->IsRegister()) { |
| 295 | Register result_reg = ToRegister(instr->result()); |
| 296 | __ movsxlq(result_reg, result_reg); |
| 297 | } else { |
| 298 | // Sign extend the 32bit result in the stack slots. |
| 299 | ASSERT(instr->result()->IsStackSlot()); |
| 300 | Operand src = ToOperand(instr->result()); |
| 301 | __ movsxlq(kScratchRegister, src); |
| 302 | __ movq(src, kScratchRegister); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 308 | bool LCodeGen::GenerateJumpTable() { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 309 | Label needs_frame; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 310 | if (jump_table_.length() > 0) { |
| 311 | Comment(";;; -------------------- Jump table --------------------"); |
| 312 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 313 | for (int i = 0; i < jump_table_.length(); i++) { |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 314 | __ bind(&jump_table_[i].label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 315 | Address entry = jump_table_[i].address; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 316 | Deoptimizer::BailoutType type = jump_table_[i].bailout_type; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 317 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 318 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 319 | Comment(";;; jump table entry %d.", i); |
| 320 | } else { |
| 321 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 322 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 323 | if (jump_table_[i].needs_frame) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 324 | ASSERT(!info()->saves_caller_doubles()); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 325 | __ Move(kScratchRegister, ExternalReference::ForDeoptEntry(entry)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 326 | if (needs_frame.is_bound()) { |
| 327 | __ jmp(&needs_frame); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 328 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 329 | __ bind(&needs_frame); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 330 | __ movp(rsi, MemOperand(rbp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 331 | __ pushq(rbp); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 332 | __ movp(rbp, rsp); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 333 | __ Push(rsi); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 334 | // This variant of deopt can only be used with stubs. Since we don't |
| 335 | // have a function pointer to install in the stack frame that we're |
| 336 | // building, install a special marker there instead. |
| 337 | ASSERT(info()->IsStub()); |
| 338 | __ Move(rsi, Smi::FromInt(StackFrame::STUB)); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 339 | __ Push(rsi); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 340 | __ movp(rsi, MemOperand(rsp, kPointerSize)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 341 | __ call(kScratchRegister); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 342 | } |
| 343 | } else { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 344 | if (info()->saves_caller_doubles()) { |
| 345 | ASSERT(info()->IsStub()); |
| 346 | RestoreCallerDoubles(); |
| 347 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 348 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 349 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 350 | } |
| 351 | return !is_aborted(); |
| 352 | } |
| 353 | |
| 354 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 355 | bool LCodeGen::GenerateDeferredCode() { |
| 356 | ASSERT(is_generating()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 357 | if (deferred_.length() > 0) { |
| 358 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 359 | LDeferredCode* code = deferred_[i]; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 360 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 361 | HValue* value = |
| 362 | instructions_->at(code->instruction_index())->hydrogen_value(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 363 | RecordAndWritePosition( |
| 364 | chunk()->graph()->SourcePositionToScriptPosition(value->position())); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 365 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 366 | Comment(";;; <@%d,#%d> " |
| 367 | "-------------------- Deferred %s --------------------", |
| 368 | code->instruction_index(), |
| 369 | code->instr()->hydrogen_value()->id(), |
| 370 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 371 | __ bind(code->entry()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 372 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 373 | Comment(";;; Build frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 374 | ASSERT(!frame_is_built_); |
| 375 | ASSERT(info()->IsStub()); |
| 376 | frame_is_built_ = true; |
| 377 | // Build the frame in such a way that esi isn't trashed. |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 378 | __ pushq(rbp); // Caller's frame pointer. |
| 379 | __ Push(Operand(rbp, StandardFrameConstants::kContextOffset)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 380 | __ Push(Smi::FromInt(StackFrame::STUB)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 381 | __ leap(rbp, Operand(rsp, 2 * kPointerSize)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 382 | Comment(";;; Deferred code"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 383 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 384 | code->Generate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 385 | if (NeedsDeferredFrame()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 386 | __ bind(code->done()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 387 | Comment(";;; Destroy frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 388 | ASSERT(frame_is_built_); |
| 389 | frame_is_built_ = false; |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 390 | __ movp(rsp, rbp); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 391 | __ popq(rbp); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 392 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 393 | __ jmp(code->exit()); |
| 394 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | // Deferred code is the last part of the instruction sequence. Mark |
| 398 | // the generated code as done unless we bailed out. |
| 399 | if (!is_aborted()) status_ = DONE; |
| 400 | return !is_aborted(); |
| 401 | } |
| 402 | |
| 403 | |
| 404 | bool LCodeGen::GenerateSafepointTable() { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 405 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 406 | safepoints_.Emit(masm(), GetStackSlotCount()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 407 | return !is_aborted(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | Register LCodeGen::ToRegister(int index) const { |
| 412 | return Register::FromAllocationIndex(index); |
| 413 | } |
| 414 | |
| 415 | |
| 416 | XMMRegister LCodeGen::ToDoubleRegister(int index) const { |
| 417 | return XMMRegister::FromAllocationIndex(index); |
| 418 | } |
| 419 | |
| 420 | |
| 421 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 422 | ASSERT(op->IsRegister()); |
| 423 | return ToRegister(op->index()); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | XMMRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 428 | ASSERT(op->IsDoubleRegister()); |
| 429 | return ToDoubleRegister(op->index()); |
| 430 | } |
| 431 | |
| 432 | |
| 433 | bool LCodeGen::IsInteger32Constant(LConstantOperand* op) const { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 434 | return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 438 | bool LCodeGen::IsDehoistedKeyConstant(LConstantOperand* op) const { |
| 439 | return op->IsConstantOperand() && |
| 440 | chunk_->IsDehoistedKey(chunk_->LookupConstant(op)); |
| 441 | } |
| 442 | |
| 443 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 444 | bool LCodeGen::IsSmiConstant(LConstantOperand* op) const { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 445 | return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 449 | int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 450 | HConstant* constant = chunk_->LookupConstant(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 451 | return constant->Integer32Value(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 455 | Smi* LCodeGen::ToSmi(LConstantOperand* op) const { |
| 456 | HConstant* constant = chunk_->LookupConstant(op); |
| 457 | return Smi::FromInt(constant->Integer32Value()); |
| 458 | } |
| 459 | |
| 460 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 461 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 462 | HConstant* constant = chunk_->LookupConstant(op); |
| 463 | ASSERT(constant->HasDoubleValue()); |
| 464 | return constant->DoubleValue(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 468 | ExternalReference LCodeGen::ToExternalReference(LConstantOperand* op) const { |
| 469 | HConstant* constant = chunk_->LookupConstant(op); |
| 470 | ASSERT(constant->HasExternalReferenceValue()); |
| 471 | return constant->ExternalReferenceValue(); |
| 472 | } |
| 473 | |
| 474 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 475 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 476 | HConstant* constant = chunk_->LookupConstant(op); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 477 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 478 | return constant->handle(isolate()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 482 | static int ArgumentsOffsetWithoutFrame(int index) { |
| 483 | ASSERT(index < 0); |
| 484 | return -(index + 1) * kPointerSize + kPCOnStackSize; |
| 485 | } |
| 486 | |
| 487 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 488 | Operand LCodeGen::ToOperand(LOperand* op) const { |
| 489 | // Does not handle registers. In X64 assembler, plain registers are not |
| 490 | // representable as an Operand. |
| 491 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 492 | if (NeedsEagerFrame()) { |
| 493 | return Operand(rbp, StackSlotOffset(op->index())); |
| 494 | } else { |
| 495 | // Retrieve parameter without eager stack-frame relative to the |
| 496 | // stack-pointer. |
| 497 | return Operand(rsp, ArgumentsOffsetWithoutFrame(op->index())); |
| 498 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
| 502 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 503 | Translation* translation) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 504 | if (environment == NULL) return; |
| 505 | |
| 506 | // The translation includes one command per value in the environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 507 | int translation_size = environment->translation_size(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 508 | // The output frame height does not include the parameters. |
| 509 | int height = translation_size - environment->parameter_count(); |
| 510 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 511 | WriteTranslation(environment->outer(), translation); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 512 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 513 | !info()->closure().is_identical_to(environment->closure()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 514 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 515 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 516 | : Translation::kSelfLiteralId; |
| 517 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 518 | switch (environment->frame_type()) { |
| 519 | case JS_FUNCTION: |
| 520 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 521 | break; |
| 522 | case JS_CONSTRUCT: |
| 523 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 524 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 525 | case JS_GETTER: |
| 526 | ASSERT(translation_size == 1); |
| 527 | ASSERT(height == 0); |
| 528 | translation->BeginGetterStubFrame(closure_id); |
| 529 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 530 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 531 | ASSERT(translation_size == 2); |
| 532 | ASSERT(height == 0); |
| 533 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 534 | break; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 535 | case ARGUMENTS_ADAPTOR: |
| 536 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 537 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 538 | case STUB: |
| 539 | translation->BeginCompiledStubFrame(); |
| 540 | break; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 541 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 542 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 543 | int object_index = 0; |
| 544 | int dematerialized_index = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 545 | for (int i = 0; i < translation_size; ++i) { |
| 546 | LOperand* value = environment->values()->at(i); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 547 | AddToTranslation(environment, |
| 548 | translation, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 549 | value, |
| 550 | environment->HasTaggedValueAt(i), |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 551 | environment->HasUint32ValueAt(i), |
| 552 | &object_index, |
| 553 | &dematerialized_index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
| 557 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 558 | void LCodeGen::AddToTranslation(LEnvironment* environment, |
| 559 | Translation* translation, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 560 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 561 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 562 | bool is_uint32, |
| 563 | int* object_index_pointer, |
| 564 | int* dematerialized_index_pointer) { |
| 565 | if (op == LEnvironment::materialization_marker()) { |
| 566 | int object_index = (*object_index_pointer)++; |
| 567 | if (environment->ObjectIsDuplicateAt(object_index)) { |
| 568 | int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
| 569 | translation->DuplicateObject(dupe_of); |
| 570 | return; |
| 571 | } |
| 572 | int object_length = environment->ObjectLengthAt(object_index); |
| 573 | if (environment->ObjectIsArgumentsAt(object_index)) { |
| 574 | translation->BeginArgumentsObject(object_length); |
| 575 | } else { |
| 576 | translation->BeginCapturedObject(object_length); |
| 577 | } |
| 578 | int dematerialized_index = *dematerialized_index_pointer; |
| 579 | int env_offset = environment->translation_size() + dematerialized_index; |
| 580 | *dematerialized_index_pointer += object_length; |
| 581 | for (int i = 0; i < object_length; ++i) { |
| 582 | LOperand* value = environment->values()->at(env_offset + i); |
| 583 | AddToTranslation(environment, |
| 584 | translation, |
| 585 | value, |
| 586 | environment->HasTaggedValueAt(env_offset + i), |
| 587 | environment->HasUint32ValueAt(env_offset + i), |
| 588 | object_index_pointer, |
| 589 | dematerialized_index_pointer); |
| 590 | } |
| 591 | return; |
| 592 | } |
| 593 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 594 | if (op->IsStackSlot()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 595 | if (is_tagged) { |
| 596 | translation->StoreStackSlot(op->index()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 597 | } else if (is_uint32) { |
| 598 | translation->StoreUint32StackSlot(op->index()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 599 | } else { |
| 600 | translation->StoreInt32StackSlot(op->index()); |
| 601 | } |
| 602 | } else if (op->IsDoubleStackSlot()) { |
| 603 | translation->StoreDoubleStackSlot(op->index()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 604 | } else if (op->IsRegister()) { |
| 605 | Register reg = ToRegister(op); |
| 606 | if (is_tagged) { |
| 607 | translation->StoreRegister(reg); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 608 | } else if (is_uint32) { |
| 609 | translation->StoreUint32Register(reg); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 610 | } else { |
| 611 | translation->StoreInt32Register(reg); |
| 612 | } |
| 613 | } else if (op->IsDoubleRegister()) { |
| 614 | XMMRegister reg = ToDoubleRegister(op); |
| 615 | translation->StoreDoubleRegister(reg); |
| 616 | } else if (op->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 617 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 618 | int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 619 | translation->StoreLiteral(src_index); |
| 620 | } else { |
| 621 | UNREACHABLE(); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 626 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 627 | RelocInfo::Mode mode, |
| 628 | LInstruction* instr, |
| 629 | SafepointMode safepoint_mode, |
| 630 | int argc) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 631 | ASSERT(instr != NULL); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 632 | __ call(code, mode); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 633 | RecordSafepointWithLazyDeopt(instr, safepoint_mode, argc); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 634 | |
| 635 | // Signal that we don't inline smi code before these stubs in the |
| 636 | // optimizing code generator. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 637 | if (code->kind() == Code::BINARY_OP_IC || |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 638 | code->kind() == Code::COMPARE_IC) { |
| 639 | __ nop(); |
| 640 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 644 | void LCodeGen::CallCode(Handle<Code> code, |
| 645 | RelocInfo::Mode mode, |
| 646 | LInstruction* instr) { |
| 647 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, 0); |
| 648 | } |
| 649 | |
| 650 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 651 | void LCodeGen::CallRuntime(const Runtime::Function* function, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 652 | int num_arguments, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 653 | LInstruction* instr, |
| 654 | SaveFPRegsMode save_doubles) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 655 | ASSERT(instr != NULL); |
| 656 | ASSERT(instr->HasPointerMap()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 657 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 658 | __ CallRuntime(function, num_arguments, save_doubles); |
| 659 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 660 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT, 0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 664 | void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
| 665 | if (context->IsRegister()) { |
| 666 | if (!ToRegister(context).is(rsi)) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 667 | __ movp(rsi, ToRegister(context)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 668 | } |
| 669 | } else if (context->IsStackSlot()) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 670 | __ movp(rsi, ToOperand(context)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 671 | } else if (context->IsConstantOperand()) { |
| 672 | HConstant* constant = |
| 673 | chunk_->LookupConstant(LConstantOperand::cast(context)); |
| 674 | __ Move(rsi, Handle<Object>::cast(constant->handle(isolate()))); |
| 675 | } else { |
| 676 | UNREACHABLE(); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | |
| 681 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 682 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 683 | int argc, |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 684 | LInstruction* instr, |
| 685 | LOperand* context) { |
| 686 | LoadContextFromDeferred(context); |
| 687 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 688 | __ CallRuntimeSaveDoubles(id); |
| 689 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 690 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 694 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 695 | Safepoint::DeoptMode mode) { |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 696 | environment->set_has_been_used(); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 697 | if (!environment->HasBeenRegistered()) { |
| 698 | // Physical stack frame layout: |
| 699 | // -x ............. -4 0 ..................................... y |
| 700 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 701 | |
| 702 | // Layout of the environment: |
| 703 | // 0 ..................................................... size-1 |
| 704 | // [parameters] [locals] [expression stack including arguments] |
| 705 | |
| 706 | // Layout of the translation: |
| 707 | // 0 ........................................................ size - 1 + 4 |
| 708 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 709 | // |>------------ translation_size ------------<| |
| 710 | |
| 711 | int frame_count = 0; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 712 | int jsframe_count = 0; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 713 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 714 | ++frame_count; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 715 | if (e->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 716 | ++jsframe_count; |
| 717 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 718 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 719 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 720 | WriteTranslation(environment, &translation); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 721 | int deoptimization_index = deoptimizations_.length(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 722 | int pc_offset = masm()->pc_offset(); |
| 723 | environment->Register(deoptimization_index, |
| 724 | translation.index(), |
| 725 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 726 | deoptimizations_.Add(environment, environment->zone()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 727 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 731 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 732 | LEnvironment* environment, |
| 733 | Deoptimizer::BailoutType bailout_type) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 734 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 735 | ASSERT(environment->HasBeenRegistered()); |
| 736 | int id = environment->deoptimization_index(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 737 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 738 | Address entry = |
| 739 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 740 | if (entry == NULL) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 741 | Abort(kBailoutWasNotPrepared); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 742 | return; |
| 743 | } |
| 744 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 745 | if (DeoptEveryNTimes()) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 746 | ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
| 747 | Label no_deopt; |
| 748 | __ pushfq(); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 749 | __ Push(rax); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 750 | Operand count_operand = masm()->ExternalOperand(count, kScratchRegister); |
| 751 | __ movl(rax, count_operand); |
| 752 | __ subl(rax, Immediate(1)); |
| 753 | __ j(not_zero, &no_deopt, Label::kNear); |
| 754 | if (FLAG_trap_on_deopt) __ int3(); |
| 755 | __ movl(rax, Immediate(FLAG_deopt_every_n_times)); |
| 756 | __ movl(count_operand, rax); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 757 | __ Pop(rax); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 758 | __ popfq(); |
| 759 | ASSERT(frame_is_built_); |
| 760 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
| 761 | __ bind(&no_deopt); |
| 762 | __ movl(count_operand, rax); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 763 | __ Pop(rax); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 764 | __ popfq(); |
| 765 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 766 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 767 | if (info()->ShouldTrapOnDeopt()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 768 | Label done; |
| 769 | if (cc != no_condition) { |
| 770 | __ j(NegateCondition(cc), &done, Label::kNear); |
| 771 | } |
| 772 | __ int3(); |
| 773 | __ bind(&done); |
| 774 | } |
| 775 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 776 | ASSERT(info()->IsStub() || frame_is_built_); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 777 | // Go through jump table if we need to handle condition, build frame, or |
| 778 | // restore caller doubles. |
| 779 | if (cc == no_condition && frame_is_built_ && |
| 780 | !info()->saves_caller_doubles()) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 781 | __ call(entry, RelocInfo::RUNTIME_ENTRY); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 782 | } else { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 783 | // We often have several deopts to the same entry, reuse the last |
| 784 | // jump entry if this is the case. |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 785 | if (jump_table_.is_empty() || |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 786 | jump_table_.last().address != entry || |
| 787 | jump_table_.last().needs_frame != !frame_is_built_ || |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 788 | jump_table_.last().bailout_type != bailout_type) { |
| 789 | Deoptimizer::JumpTableEntry table_entry(entry, |
| 790 | bailout_type, |
| 791 | !frame_is_built_); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 792 | jump_table_.Add(table_entry, zone()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 793 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 794 | if (cc == no_condition) { |
| 795 | __ jmp(&jump_table_.last().label); |
| 796 | } else { |
| 797 | __ j(cc, &jump_table_.last().label); |
| 798 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 799 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 803 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 804 | LEnvironment* environment) { |
| 805 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 806 | ? Deoptimizer::LAZY |
| 807 | : Deoptimizer::EAGER; |
| 808 | DeoptimizeIf(cc, environment, bailout_type); |
| 809 | } |
| 810 | |
| 811 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 812 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 813 | int length = deoptimizations_.length(); |
| 814 | if (length == 0) return; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 815 | Handle<DeoptimizationInputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 816 | factory()->NewDeoptimizationInputData(length, TENURED); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 817 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 818 | Handle<ByteArray> translations = |
| 819 | translations_.CreateByteArray(isolate()->factory()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 820 | data->SetTranslationByteArray(*translations); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 821 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 822 | data->SetOptimizationId(Smi::FromInt(info_->optimization_id())); |
| 823 | if (info_->IsOptimizing()) { |
| 824 | // Reference to shared function info does not change between phases. |
| 825 | AllowDeferredHandleDereference allow_handle_dereference; |
| 826 | data->SetSharedFunctionInfo(*info_->shared_info()); |
| 827 | } else { |
| 828 | data->SetSharedFunctionInfo(Smi::FromInt(0)); |
| 829 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 830 | |
| 831 | Handle<FixedArray> literals = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 832 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 833 | { AllowDeferredHandleDereference copy_handles; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 834 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 835 | literals->set(i, *deoptimization_literals_[i]); |
| 836 | } |
| 837 | data->SetLiteralArray(*literals); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 838 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 839 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 840 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 841 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 842 | |
| 843 | // Populate the deoptimization entries. |
| 844 | for (int i = 0; i < length; i++) { |
| 845 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 846 | data->SetAstId(i, env->ast_id()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 847 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 848 | data->SetArgumentsStackHeight(i, |
| 849 | Smi::FromInt(env->arguments_stack_height())); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 850 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 851 | } |
| 852 | code->set_deoptimization_data(*data); |
| 853 | } |
| 854 | |
| 855 | |
| 856 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 857 | int result = deoptimization_literals_.length(); |
| 858 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 859 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 860 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 861 | deoptimization_literals_.Add(literal, zone()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 862 | return result; |
| 863 | } |
| 864 | |
| 865 | |
| 866 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 867 | ASSERT(deoptimization_literals_.length() == 0); |
| 868 | |
| 869 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 870 | chunk()->inlined_closures(); |
| 871 | |
| 872 | for (int i = 0, length = inlined_closures->length(); |
| 873 | i < length; |
| 874 | i++) { |
| 875 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 876 | } |
| 877 | |
| 878 | inlined_function_count_ = deoptimization_literals_.length(); |
| 879 | } |
| 880 | |
| 881 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 882 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 883 | LInstruction* instr, SafepointMode safepoint_mode, int argc) { |
| 884 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 885 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 886 | } else { |
| 887 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS); |
| 888 | RecordSafepointWithRegisters( |
| 889 | instr->pointer_map(), argc, Safepoint::kLazyDeopt); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 894 | void LCodeGen::RecordSafepoint( |
| 895 | LPointerMap* pointers, |
| 896 | Safepoint::Kind kind, |
| 897 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 898 | Safepoint::DeoptMode deopt_mode) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 899 | ASSERT(kind == expected_safepoint_kind_); |
| 900 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 901 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 902 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 903 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 904 | kind, arguments, deopt_mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 905 | for (int i = 0; i < operands->length(); i++) { |
| 906 | LOperand* pointer = operands->at(i); |
| 907 | if (pointer->IsStackSlot()) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 908 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 909 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 910 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 911 | } |
| 912 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | |
| 916 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 917 | Safepoint::DeoptMode deopt_mode) { |
| 918 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 922 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 923 | LPointerMap empty_pointers(zone()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 924 | RecordSafepoint(&empty_pointers, deopt_mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 928 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 929 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 930 | Safepoint::DeoptMode deopt_mode) { |
| 931 | RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 935 | void LCodeGen::RecordAndWritePosition(int position) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 936 | if (position == RelocInfo::kNoPosition) return; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 937 | masm()->positions_recorder()->RecordPosition(position); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 938 | masm()->positions_recorder()->WriteRecordedPositions(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 942 | static const char* LabelType(LLabel* label) { |
| 943 | if (label->is_loop_header()) return " (loop header)"; |
| 944 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 945 | return ""; |
| 946 | } |
| 947 | |
| 948 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 949 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 950 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 951 | current_instruction_, |
| 952 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 953 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 954 | LabelType(label)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 955 | __ bind(label->label()); |
| 956 | current_block_ = label->block_id(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 957 | DoGap(label); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | |
| 961 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 962 | resolver_.Resolve(move); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | |
| 966 | void LCodeGen::DoGap(LGap* gap) { |
| 967 | for (int i = LGap::FIRST_INNER_POSITION; |
| 968 | i <= LGap::LAST_INNER_POSITION; |
| 969 | i++) { |
| 970 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 971 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 972 | if (move != NULL) DoParallelMove(move); |
| 973 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 977 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 978 | DoGap(instr); |
| 979 | } |
| 980 | |
| 981 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 982 | void LCodeGen::DoParameter(LParameter* instr) { |
| 983 | // Nothing to do. |
| 984 | } |
| 985 | |
| 986 | |
| 987 | void LCodeGen::DoCallStub(LCallStub* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 988 | ASSERT(ToRegister(instr->context()).is(rsi)); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 989 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 990 | switch (instr->hydrogen()->major_key()) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 991 | case CodeStub::RegExpExec: { |
| 992 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 993 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 994 | break; |
| 995 | } |
| 996 | case CodeStub::SubString: { |
| 997 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 998 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 999 | break; |
| 1000 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1001 | case CodeStub::StringCompare: { |
| 1002 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1003 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1004 | break; |
| 1005 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1006 | default: |
| 1007 | UNREACHABLE(); |
| 1008 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | |
| 1012 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1013 | GenerateOsrPrologue(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1017 | void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) { |
| 1018 | Register dividend = ToRegister(instr->dividend()); |
| 1019 | int32_t divisor = instr->divisor(); |
| 1020 | ASSERT(dividend.is(ToRegister(instr->result()))); |
| 1021 | |
| 1022 | // Theoretically, a variation of the branch-free code for integer division by |
| 1023 | // a power of 2 (calculating the remainder via an additional multiplication |
| 1024 | // (which gets simplified to an 'and') and subtraction) should be faster, and |
| 1025 | // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to |
| 1026 | // indicate that positive dividends are heavily favored, so the branching |
| 1027 | // version performs better. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1028 | HMod* hmod = instr->hydrogen(); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1029 | int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); |
| 1030 | Label dividend_is_not_negative, done; |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1031 | if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1032 | __ testl(dividend, dividend); |
| 1033 | __ j(not_sign, ÷nd_is_not_negative, Label::kNear); |
| 1034 | // Note that this is correct even for kMinInt operands. |
| 1035 | __ negl(dividend); |
| 1036 | __ andl(dividend, Immediate(mask)); |
| 1037 | __ negl(dividend); |
| 1038 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1039 | DeoptimizeIf(zero, instr->environment()); |
| 1040 | } |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1041 | __ jmp(&done, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1042 | } |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1043 | |
| 1044 | __ bind(÷nd_is_not_negative); |
| 1045 | __ andl(dividend, Immediate(mask)); |
| 1046 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1050 | void LCodeGen::DoModByConstI(LModByConstI* instr) { |
| 1051 | Register dividend = ToRegister(instr->dividend()); |
| 1052 | int32_t divisor = instr->divisor(); |
| 1053 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 1054 | |
| 1055 | if (divisor == 0) { |
| 1056 | DeoptimizeIf(no_condition, instr->environment()); |
| 1057 | return; |
| 1058 | } |
| 1059 | |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 1060 | __ TruncatingDiv(dividend, Abs(divisor)); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1061 | __ imull(rdx, rdx, Immediate(Abs(divisor))); |
| 1062 | __ movl(rax, dividend); |
| 1063 | __ subl(rax, rdx); |
| 1064 | |
| 1065 | // Check for negative zero. |
| 1066 | HMod* hmod = instr->hydrogen(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1067 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1068 | Label remainder_not_zero; |
| 1069 | __ j(not_zero, &remainder_not_zero, Label::kNear); |
| 1070 | __ cmpl(dividend, Immediate(0)); |
| 1071 | DeoptimizeIf(less, instr->environment()); |
| 1072 | __ bind(&remainder_not_zero); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1077 | void LCodeGen::DoModI(LModI* instr) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1078 | HMod* hmod = instr->hydrogen(); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1079 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1080 | Register left_reg = ToRegister(instr->left()); |
| 1081 | ASSERT(left_reg.is(rax)); |
| 1082 | Register right_reg = ToRegister(instr->right()); |
| 1083 | ASSERT(!right_reg.is(rax)); |
| 1084 | ASSERT(!right_reg.is(rdx)); |
| 1085 | Register result_reg = ToRegister(instr->result()); |
| 1086 | ASSERT(result_reg.is(rdx)); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1087 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1088 | Label done; |
| 1089 | // Check for x % 0, idiv would signal a divide error. We have to |
| 1090 | // deopt in this case because we can't return a NaN. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1091 | if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1092 | __ testl(right_reg, right_reg); |
| 1093 | DeoptimizeIf(zero, instr->environment()); |
| 1094 | } |
| 1095 | |
| 1096 | // Check for kMinInt % -1, idiv would signal a divide error. We |
| 1097 | // have to deopt if we care about -0, because we can't return that. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1098 | if (hmod->CheckFlag(HValue::kCanOverflow)) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1099 | Label no_overflow_possible; |
| 1100 | __ cmpl(left_reg, Immediate(kMinInt)); |
| 1101 | __ j(not_zero, &no_overflow_possible, Label::kNear); |
| 1102 | __ cmpl(right_reg, Immediate(-1)); |
| 1103 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1104 | DeoptimizeIf(equal, instr->environment()); |
| 1105 | } else { |
| 1106 | __ j(not_equal, &no_overflow_possible, Label::kNear); |
| 1107 | __ Set(result_reg, 0); |
| 1108 | __ jmp(&done, Label::kNear); |
| 1109 | } |
| 1110 | __ bind(&no_overflow_possible); |
| 1111 | } |
| 1112 | |
| 1113 | // Sign extend dividend in eax into edx:eax, since we are using only the low |
| 1114 | // 32 bits of the values. |
| 1115 | __ cdq(); |
| 1116 | |
| 1117 | // If we care about -0, test if the dividend is <0 and the result is 0. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1118 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1119 | Label positive_left; |
| 1120 | __ testl(left_reg, left_reg); |
| 1121 | __ j(not_sign, &positive_left, Label::kNear); |
| 1122 | __ idivl(right_reg); |
| 1123 | __ testl(result_reg, result_reg); |
| 1124 | DeoptimizeIf(zero, instr->environment()); |
| 1125 | __ jmp(&done, Label::kNear); |
| 1126 | __ bind(&positive_left); |
| 1127 | } |
| 1128 | __ idivl(right_reg); |
| 1129 | __ bind(&done); |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
| 1134 | Register dividend = ToRegister(instr->dividend()); |
| 1135 | int32_t divisor = instr->divisor(); |
| 1136 | ASSERT(dividend.is(ToRegister(instr->result()))); |
| 1137 | |
| 1138 | // If the divisor is positive, things are easy: There can be no deopts and we |
| 1139 | // can simply do an arithmetic right shift. |
| 1140 | if (divisor == 1) return; |
| 1141 | int32_t shift = WhichPowerOf2Abs(divisor); |
| 1142 | if (divisor > 1) { |
| 1143 | __ sarl(dividend, Immediate(shift)); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
| 1147 | // If the divisor is negative, we have to negate and handle edge cases. |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1148 | __ negl(dividend); |
| 1149 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1150 | DeoptimizeIf(zero, instr->environment()); |
| 1151 | } |
machenbach@chromium.org | 9e41f9e | 2014-04-09 00:06:04 +0000 | [diff] [blame] | 1152 | |
| 1153 | // If the negation could not overflow, simply shifting is OK. |
| 1154 | if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1155 | __ sarl(dividend, Immediate(shift)); |
| 1156 | return; |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1157 | } |
machenbach@chromium.org | 9e41f9e | 2014-04-09 00:06:04 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Note that we could emit branch-free code, but that would need one more |
| 1160 | // register. |
| 1161 | if (divisor == -1) { |
| 1162 | DeoptimizeIf(overflow, instr->environment()); |
| 1163 | return; |
| 1164 | } |
| 1165 | |
| 1166 | Label not_kmin_int, done; |
| 1167 | __ j(no_overflow, ¬_kmin_int, Label::kNear); |
| 1168 | __ movl(dividend, Immediate(kMinInt / divisor)); |
| 1169 | __ jmp(&done, Label::kNear); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1170 | __ bind(¬_kmin_int); |
| 1171 | __ sarl(dividend, Immediate(shift)); |
| 1172 | __ bind(&done); |
| 1173 | } |
| 1174 | |
| 1175 | |
| 1176 | void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
| 1177 | Register dividend = ToRegister(instr->dividend()); |
| 1178 | int32_t divisor = instr->divisor(); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1179 | ASSERT(ToRegister(instr->result()).is(rdx)); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1180 | |
| 1181 | if (divisor == 0) { |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1182 | DeoptimizeIf(no_condition, instr->environment()); |
| 1183 | return; |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1186 | // Check for (0 / -x) that will produce negative zero. |
| 1187 | HMathFloorOfDiv* hdiv = instr->hydrogen(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1188 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1189 | __ testl(dividend, dividend); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1190 | DeoptimizeIf(zero, instr->environment()); |
| 1191 | } |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1192 | |
machenbach@chromium.org | 7010a2d | 2014-03-20 15:46:12 +0000 | [diff] [blame] | 1193 | // Easy case: We need no dynamic check for the dividend and the flooring |
| 1194 | // division is the same as the truncating division. |
| 1195 | if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1196 | (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1197 | __ TruncatingDiv(dividend, Abs(divisor)); |
| 1198 | if (divisor < 0) __ negl(rdx); |
| 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | // In the general case we may need to adjust before and after the truncating |
| 1203 | // division to get a flooring division. |
| 1204 | Register temp = ToRegister(instr->temp3()); |
| 1205 | ASSERT(!temp.is(dividend) && !temp.is(rax) && !temp.is(rdx)); |
| 1206 | Label needs_adjustment, done; |
| 1207 | __ cmpl(dividend, Immediate(0)); |
| 1208 | __ j(divisor > 0 ? less : greater, &needs_adjustment, Label::kNear); |
| 1209 | __ TruncatingDiv(dividend, Abs(divisor)); |
| 1210 | if (divisor < 0) __ negl(rdx); |
| 1211 | __ jmp(&done, Label::kNear); |
| 1212 | __ bind(&needs_adjustment); |
| 1213 | __ leal(temp, Operand(dividend, divisor > 0 ? 1 : -1)); |
| 1214 | __ TruncatingDiv(temp, Abs(divisor)); |
| 1215 | if (divisor < 0) __ negl(rdx); |
| 1216 | __ decl(rdx); |
| 1217 | __ bind(&done); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1221 | // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1222 | void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1223 | HBinaryOperation* hdiv = instr->hydrogen(); |
| 1224 | Register dividend = ToRegister(instr->dividend()); |
| 1225 | Register divisor = ToRegister(instr->divisor()); |
| 1226 | Register remainder = ToRegister(instr->temp()); |
| 1227 | Register result = ToRegister(instr->result()); |
| 1228 | ASSERT(dividend.is(rax)); |
| 1229 | ASSERT(remainder.is(rdx)); |
| 1230 | ASSERT(result.is(rax)); |
| 1231 | ASSERT(!divisor.is(rax)); |
| 1232 | ASSERT(!divisor.is(rdx)); |
| 1233 | |
| 1234 | // Check for x / 0. |
| 1235 | if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1236 | __ testl(divisor, divisor); |
| 1237 | DeoptimizeIf(zero, instr->environment()); |
| 1238 | } |
| 1239 | |
| 1240 | // Check for (0 / -x) that will produce negative zero. |
| 1241 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1242 | Label dividend_not_zero; |
| 1243 | __ testl(dividend, dividend); |
| 1244 | __ j(not_zero, ÷nd_not_zero, Label::kNear); |
| 1245 | __ testl(divisor, divisor); |
| 1246 | DeoptimizeIf(sign, instr->environment()); |
| 1247 | __ bind(÷nd_not_zero); |
| 1248 | } |
| 1249 | |
| 1250 | // Check for (kMinInt / -1). |
| 1251 | if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1252 | Label dividend_not_min_int; |
| 1253 | __ cmpl(dividend, Immediate(kMinInt)); |
| 1254 | __ j(not_zero, ÷nd_not_min_int, Label::kNear); |
| 1255 | __ cmpl(divisor, Immediate(-1)); |
| 1256 | DeoptimizeIf(zero, instr->environment()); |
| 1257 | __ bind(÷nd_not_min_int); |
| 1258 | } |
| 1259 | |
| 1260 | // Sign extend to rdx (= remainder). |
| 1261 | __ cdq(); |
| 1262 | __ idivl(divisor); |
| 1263 | |
| 1264 | Label done; |
| 1265 | __ testl(remainder, remainder); |
| 1266 | __ j(zero, &done, Label::kNear); |
| 1267 | __ xorl(remainder, divisor); |
| 1268 | __ sarl(remainder, Immediate(31)); |
| 1269 | __ addl(result, remainder); |
| 1270 | __ bind(&done); |
| 1271 | } |
| 1272 | |
| 1273 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1274 | void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
| 1275 | Register dividend = ToRegister(instr->dividend()); |
| 1276 | int32_t divisor = instr->divisor(); |
| 1277 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1278 | ASSERT(divisor == kMinInt || IsPowerOf2(Abs(divisor))); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1279 | ASSERT(!result.is(dividend)); |
| 1280 | |
| 1281 | // Check for (0 / -x) that will produce negative zero. |
| 1282 | HDiv* hdiv = instr->hydrogen(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1283 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1284 | __ testl(dividend, dividend); |
| 1285 | DeoptimizeIf(zero, instr->environment()); |
| 1286 | } |
| 1287 | // Check for (kMinInt / -1). |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1288 | if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1289 | __ cmpl(dividend, Immediate(kMinInt)); |
| 1290 | DeoptimizeIf(zero, instr->environment()); |
| 1291 | } |
| 1292 | // Deoptimize if remainder will not be 0. |
| 1293 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
| 1294 | divisor != 1 && divisor != -1) { |
| 1295 | int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); |
| 1296 | __ testl(dividend, Immediate(mask)); |
| 1297 | DeoptimizeIf(not_zero, instr->environment()); |
| 1298 | } |
| 1299 | __ Move(result, dividend); |
| 1300 | int32_t shift = WhichPowerOf2Abs(divisor); |
| 1301 | if (shift > 0) { |
| 1302 | // The arithmetic shift is always OK, the 'if' is an optimization only. |
| 1303 | if (shift > 1) __ sarl(result, Immediate(31)); |
| 1304 | __ shrl(result, Immediate(32 - shift)); |
| 1305 | __ addl(result, dividend); |
| 1306 | __ sarl(result, Immediate(shift)); |
| 1307 | } |
| 1308 | if (divisor < 0) __ negl(result); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1312 | void LCodeGen::DoDivByConstI(LDivByConstI* instr) { |
| 1313 | Register dividend = ToRegister(instr->dividend()); |
| 1314 | int32_t divisor = instr->divisor(); |
| 1315 | ASSERT(ToRegister(instr->result()).is(rdx)); |
| 1316 | |
| 1317 | if (divisor == 0) { |
| 1318 | DeoptimizeIf(no_condition, instr->environment()); |
| 1319 | return; |
| 1320 | } |
| 1321 | |
| 1322 | // Check for (0 / -x) that will produce negative zero. |
| 1323 | HDiv* hdiv = instr->hydrogen(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1324 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1325 | __ testl(dividend, dividend); |
| 1326 | DeoptimizeIf(zero, instr->environment()); |
| 1327 | } |
| 1328 | |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 1329 | __ TruncatingDiv(dividend, Abs(divisor)); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1330 | if (divisor < 0) __ negl(rdx); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1331 | |
| 1332 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1333 | __ movl(rax, rdx); |
| 1334 | __ imull(rax, rax, Immediate(divisor)); |
| 1335 | __ subl(rax, dividend); |
| 1336 | DeoptimizeIf(not_equal, instr->environment()); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1341 | // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1342 | void LCodeGen::DoDivI(LDivI* instr) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1343 | HBinaryOperation* hdiv = instr->hydrogen(); |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1344 | Register dividend = ToRegister(instr->dividend()); |
| 1345 | Register divisor = ToRegister(instr->divisor()); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1346 | Register remainder = ToRegister(instr->temp()); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1347 | ASSERT(dividend.is(rax)); |
| 1348 | ASSERT(remainder.is(rdx)); |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1349 | ASSERT(ToRegister(instr->result()).is(rax)); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1350 | ASSERT(!divisor.is(rax)); |
| 1351 | ASSERT(!divisor.is(rdx)); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1352 | |
| 1353 | // Check for x / 0. |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1354 | if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1355 | __ testl(divisor, divisor); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1356 | DeoptimizeIf(zero, instr->environment()); |
| 1357 | } |
| 1358 | |
| 1359 | // Check for (0 / -x) that will produce negative zero. |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1360 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1361 | Label dividend_not_zero; |
| 1362 | __ testl(dividend, dividend); |
| 1363 | __ j(not_zero, ÷nd_not_zero, Label::kNear); |
| 1364 | __ testl(divisor, divisor); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1365 | DeoptimizeIf(sign, instr->environment()); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1366 | __ bind(÷nd_not_zero); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1369 | // Check for (kMinInt / -1). |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1370 | if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1371 | Label dividend_not_min_int; |
| 1372 | __ cmpl(dividend, Immediate(kMinInt)); |
| 1373 | __ j(not_zero, ÷nd_not_min_int, Label::kNear); |
| 1374 | __ cmpl(divisor, Immediate(-1)); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1375 | DeoptimizeIf(zero, instr->environment()); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1376 | __ bind(÷nd_not_min_int); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1379 | // Sign extend to rdx (= remainder). |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1380 | __ cdq(); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1381 | __ idivl(divisor); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1382 | |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1383 | if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1384 | // Deoptimize if remainder is not 0. |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1385 | __ testl(remainder, remainder); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1386 | DeoptimizeIf(not_zero, instr->environment()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1387 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1388 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1389 | |
| 1390 | |
| 1391 | void LCodeGen::DoMulI(LMulI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1392 | Register left = ToRegister(instr->left()); |
| 1393 | LOperand* right = instr->right(); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1394 | |
| 1395 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1396 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1397 | __ movp(kScratchRegister, left); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1398 | } else { |
| 1399 | __ movl(kScratchRegister, left); |
| 1400 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1403 | bool can_overflow = |
| 1404 | instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1405 | if (right->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1406 | int32_t right_value = ToInteger32(LConstantOperand::cast(right)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1407 | if (right_value == -1) { |
| 1408 | __ negl(left); |
| 1409 | } else if (right_value == 0) { |
| 1410 | __ xorl(left, left); |
| 1411 | } else if (right_value == 2) { |
| 1412 | __ addl(left, left); |
| 1413 | } else if (!can_overflow) { |
| 1414 | // If the multiplication is known to not overflow, we |
| 1415 | // can use operations that don't set the overflow flag |
| 1416 | // correctly. |
| 1417 | switch (right_value) { |
| 1418 | case 1: |
| 1419 | // Do nothing. |
| 1420 | break; |
| 1421 | case 3: |
| 1422 | __ leal(left, Operand(left, left, times_2, 0)); |
| 1423 | break; |
| 1424 | case 4: |
| 1425 | __ shll(left, Immediate(2)); |
| 1426 | break; |
| 1427 | case 5: |
| 1428 | __ leal(left, Operand(left, left, times_4, 0)); |
| 1429 | break; |
| 1430 | case 8: |
| 1431 | __ shll(left, Immediate(3)); |
| 1432 | break; |
| 1433 | case 9: |
| 1434 | __ leal(left, Operand(left, left, times_8, 0)); |
| 1435 | break; |
| 1436 | case 16: |
| 1437 | __ shll(left, Immediate(4)); |
| 1438 | break; |
| 1439 | default: |
| 1440 | __ imull(left, left, Immediate(right_value)); |
| 1441 | break; |
| 1442 | } |
| 1443 | } else { |
| 1444 | __ imull(left, left, Immediate(right_value)); |
| 1445 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1446 | } else if (right->IsStackSlot()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1447 | if (instr->hydrogen_value()->representation().IsSmi()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1448 | __ SmiToInteger64(left, left); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1449 | __ imulp(left, ToOperand(right)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1450 | } else { |
| 1451 | __ imull(left, ToOperand(right)); |
| 1452 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1453 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1454 | if (instr->hydrogen_value()->representation().IsSmi()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1455 | __ SmiToInteger64(left, left); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1456 | __ imulp(left, ToRegister(right)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1457 | } else { |
| 1458 | __ imull(left, ToRegister(right)); |
| 1459 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1462 | if (can_overflow) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1463 | DeoptimizeIf(overflow, instr->environment()); |
| 1464 | } |
| 1465 | |
| 1466 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1467 | // Bail out if the result is supposed to be negative zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1468 | Label done; |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1469 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 1470 | __ testp(left, left); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1471 | } else { |
| 1472 | __ testl(left, left); |
| 1473 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1474 | __ j(not_zero, &done, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1475 | if (right->IsConstantOperand()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1476 | // Constant can't be represented as Smi due to immediate size limit. |
| 1477 | ASSERT(!instr->hydrogen_value()->representation().IsSmi()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1478 | if (ToInteger32(LConstantOperand::cast(right)) < 0) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1479 | DeoptimizeIf(no_condition, instr->environment()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1480 | } else if (ToInteger32(LConstantOperand::cast(right)) == 0) { |
| 1481 | __ cmpl(kScratchRegister, Immediate(0)); |
| 1482 | DeoptimizeIf(less, instr->environment()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1483 | } |
| 1484 | } else if (right->IsStackSlot()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1485 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1486 | __ orp(kScratchRegister, ToOperand(right)); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1487 | } else { |
| 1488 | __ orl(kScratchRegister, ToOperand(right)); |
| 1489 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1490 | DeoptimizeIf(sign, instr->environment()); |
| 1491 | } else { |
| 1492 | // Test the non-zero operand for negative sign. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1493 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1494 | __ orp(kScratchRegister, ToRegister(right)); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1495 | } else { |
| 1496 | __ orl(kScratchRegister, ToRegister(right)); |
| 1497 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1498 | DeoptimizeIf(sign, instr->environment()); |
| 1499 | } |
| 1500 | __ bind(&done); |
| 1501 | } |
| 1502 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1503 | |
| 1504 | |
| 1505 | void LCodeGen::DoBitI(LBitI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1506 | LOperand* left = instr->left(); |
| 1507 | LOperand* right = instr->right(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1508 | ASSERT(left->Equals(instr->result())); |
| 1509 | ASSERT(left->IsRegister()); |
| 1510 | |
| 1511 | if (right->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1512 | int32_t right_operand = ToInteger32(LConstantOperand::cast(right)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1513 | switch (instr->op()) { |
| 1514 | case Token::BIT_AND: |
| 1515 | __ andl(ToRegister(left), Immediate(right_operand)); |
| 1516 | break; |
| 1517 | case Token::BIT_OR: |
| 1518 | __ orl(ToRegister(left), Immediate(right_operand)); |
| 1519 | break; |
| 1520 | case Token::BIT_XOR: |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1521 | if (right_operand == int32_t(~0)) { |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1522 | __ notl(ToRegister(left)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1523 | } else { |
| 1524 | __ xorl(ToRegister(left), Immediate(right_operand)); |
| 1525 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | default: |
| 1528 | UNREACHABLE(); |
| 1529 | break; |
| 1530 | } |
| 1531 | } else if (right->IsStackSlot()) { |
| 1532 | switch (instr->op()) { |
| 1533 | case Token::BIT_AND: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1534 | if (instr->IsInteger32()) { |
| 1535 | __ andl(ToRegister(left), ToOperand(right)); |
| 1536 | } else { |
| 1537 | __ andp(ToRegister(left), ToOperand(right)); |
| 1538 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | case Token::BIT_OR: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1541 | if (instr->IsInteger32()) { |
| 1542 | __ orl(ToRegister(left), ToOperand(right)); |
| 1543 | } else { |
| 1544 | __ orp(ToRegister(left), ToOperand(right)); |
| 1545 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1546 | break; |
| 1547 | case Token::BIT_XOR: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1548 | if (instr->IsInteger32()) { |
| 1549 | __ xorl(ToRegister(left), ToOperand(right)); |
| 1550 | } else { |
| 1551 | __ xorp(ToRegister(left), ToOperand(right)); |
| 1552 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1553 | break; |
| 1554 | default: |
| 1555 | UNREACHABLE(); |
| 1556 | break; |
| 1557 | } |
| 1558 | } else { |
| 1559 | ASSERT(right->IsRegister()); |
| 1560 | switch (instr->op()) { |
| 1561 | case Token::BIT_AND: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1562 | if (instr->IsInteger32()) { |
| 1563 | __ andl(ToRegister(left), ToRegister(right)); |
| 1564 | } else { |
| 1565 | __ andp(ToRegister(left), ToRegister(right)); |
| 1566 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1567 | break; |
| 1568 | case Token::BIT_OR: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1569 | if (instr->IsInteger32()) { |
| 1570 | __ orl(ToRegister(left), ToRegister(right)); |
| 1571 | } else { |
| 1572 | __ orp(ToRegister(left), ToRegister(right)); |
| 1573 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1574 | break; |
| 1575 | case Token::BIT_XOR: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1576 | if (instr->IsInteger32()) { |
| 1577 | __ xorl(ToRegister(left), ToRegister(right)); |
| 1578 | } else { |
| 1579 | __ xorp(ToRegister(left), ToRegister(right)); |
| 1580 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | default: |
| 1583 | UNREACHABLE(); |
| 1584 | break; |
| 1585 | } |
| 1586 | } |
| 1587 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1588 | |
| 1589 | |
| 1590 | void LCodeGen::DoShiftI(LShiftI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1591 | LOperand* left = instr->left(); |
| 1592 | LOperand* right = instr->right(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1593 | ASSERT(left->Equals(instr->result())); |
| 1594 | ASSERT(left->IsRegister()); |
| 1595 | if (right->IsRegister()) { |
| 1596 | ASSERT(ToRegister(right).is(rcx)); |
| 1597 | |
| 1598 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1599 | case Token::ROR: |
| 1600 | __ rorl_cl(ToRegister(left)); |
| 1601 | break; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1602 | case Token::SAR: |
| 1603 | __ sarl_cl(ToRegister(left)); |
| 1604 | break; |
| 1605 | case Token::SHR: |
| 1606 | __ shrl_cl(ToRegister(left)); |
| 1607 | if (instr->can_deopt()) { |
| 1608 | __ testl(ToRegister(left), ToRegister(left)); |
| 1609 | DeoptimizeIf(negative, instr->environment()); |
| 1610 | } |
| 1611 | break; |
| 1612 | case Token::SHL: |
| 1613 | __ shll_cl(ToRegister(left)); |
| 1614 | break; |
| 1615 | default: |
| 1616 | UNREACHABLE(); |
| 1617 | break; |
| 1618 | } |
| 1619 | } else { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1620 | int32_t value = ToInteger32(LConstantOperand::cast(right)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1621 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1622 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1623 | case Token::ROR: |
| 1624 | if (shift_count != 0) { |
| 1625 | __ rorl(ToRegister(left), Immediate(shift_count)); |
| 1626 | } |
| 1627 | break; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1628 | case Token::SAR: |
| 1629 | if (shift_count != 0) { |
| 1630 | __ sarl(ToRegister(left), Immediate(shift_count)); |
| 1631 | } |
| 1632 | break; |
| 1633 | case Token::SHR: |
| 1634 | if (shift_count == 0 && instr->can_deopt()) { |
| 1635 | __ testl(ToRegister(left), ToRegister(left)); |
| 1636 | DeoptimizeIf(negative, instr->environment()); |
| 1637 | } else { |
| 1638 | __ shrl(ToRegister(left), Immediate(shift_count)); |
| 1639 | } |
| 1640 | break; |
| 1641 | case Token::SHL: |
| 1642 | if (shift_count != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1643 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 1644 | __ shlp(ToRegister(left), Immediate(shift_count)); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1645 | } else { |
| 1646 | __ shll(ToRegister(left), Immediate(shift_count)); |
| 1647 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1648 | } |
| 1649 | break; |
| 1650 | default: |
| 1651 | UNREACHABLE(); |
| 1652 | break; |
| 1653 | } |
| 1654 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | void LCodeGen::DoSubI(LSubI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1659 | LOperand* left = instr->left(); |
| 1660 | LOperand* right = instr->right(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1661 | ASSERT(left->Equals(instr->result())); |
| 1662 | |
| 1663 | if (right->IsConstantOperand()) { |
| 1664 | __ subl(ToRegister(left), |
| 1665 | Immediate(ToInteger32(LConstantOperand::cast(right)))); |
| 1666 | } else if (right->IsRegister()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1667 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1668 | __ subp(ToRegister(left), ToRegister(right)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1669 | } else { |
| 1670 | __ subl(ToRegister(left), ToRegister(right)); |
| 1671 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1672 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1673 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1674 | __ subp(ToRegister(left), ToOperand(right)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1675 | } else { |
| 1676 | __ subl(ToRegister(left), ToOperand(right)); |
| 1677 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1681 | DeoptimizeIf(overflow, instr->environment()); |
| 1682 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | |
| 1686 | void LCodeGen::DoConstantI(LConstantI* instr) { |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 1687 | Register dst = ToRegister(instr->result()); |
| 1688 | if (instr->value() == 0) { |
| 1689 | __ xorl(dst, dst); |
| 1690 | } else { |
| 1691 | __ movl(dst, Immediate(instr->value())); |
| 1692 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1696 | void LCodeGen::DoConstantS(LConstantS* instr) { |
| 1697 | __ Move(ToRegister(instr->result()), instr->value()); |
| 1698 | } |
| 1699 | |
| 1700 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1701 | void LCodeGen::DoConstantD(LConstantD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1702 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1703 | XMMRegister res = ToDoubleRegister(instr->result()); |
| 1704 | double v = instr->value(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1705 | uint64_t int_val = BitCast<uint64_t, double>(v); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1706 | // Use xor to produce +0.0 in a fast and compact way, but avoid to |
| 1707 | // do so if the constant is -0.0. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1708 | if (int_val == 0) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1709 | __ xorps(res, res); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1710 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1711 | Register tmp = ToRegister(instr->temp()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1712 | __ Set(tmp, int_val); |
| 1713 | __ movq(res, tmp); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1714 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1718 | void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1719 | __ LoadAddress(ToRegister(instr->result()), instr->value()); |
| 1720 | } |
| 1721 | |
| 1722 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1723 | void LCodeGen::DoConstantT(LConstantT* instr) { |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1724 | Handle<Object> value = instr->value(isolate()); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 1725 | __ Move(ToRegister(instr->result()), value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1729 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1730 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1731 | Register map = ToRegister(instr->value()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1732 | __ EnumLength(result, map); |
| 1733 | } |
| 1734 | |
| 1735 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1736 | void LCodeGen::DoDateField(LDateField* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1737 | Register object = ToRegister(instr->date()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1738 | Register result = ToRegister(instr->result()); |
| 1739 | Smi* index = instr->index(); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1740 | Label runtime, done, not_date_object; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1741 | ASSERT(object.is(result)); |
| 1742 | ASSERT(object.is(rax)); |
| 1743 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1744 | Condition cc = masm()->CheckSmi(object); |
| 1745 | DeoptimizeIf(cc, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1746 | __ CmpObjectType(object, JS_DATE_TYPE, kScratchRegister); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1747 | DeoptimizeIf(not_equal, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1748 | |
| 1749 | if (index->value() == 0) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1750 | __ movp(result, FieldOperand(object, JSDate::kValueOffset)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1751 | } else { |
| 1752 | if (index->value() < JSDate::kFirstUncachedField) { |
| 1753 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1754 | Operand stamp_operand = __ ExternalOperand(stamp); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1755 | __ movp(kScratchRegister, stamp_operand); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 1756 | __ cmpp(kScratchRegister, FieldOperand(object, |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1757 | JSDate::kCacheStampOffset)); |
| 1758 | __ j(not_equal, &runtime, Label::kNear); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1759 | __ movp(result, FieldOperand(object, JSDate::kValueOffset + |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1760 | kPointerSize * index->value())); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1761 | __ jmp(&done, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1762 | } |
| 1763 | __ bind(&runtime); |
| 1764 | __ PrepareCallCFunction(2); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1765 | __ movp(arg_reg_1, object); |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 1766 | __ Move(arg_reg_2, index, Assembler::RelocInfoNone()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1767 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1768 | __ bind(&done); |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1773 | Operand LCodeGen::BuildSeqStringOperand(Register string, |
| 1774 | LOperand* index, |
| 1775 | String::Encoding encoding) { |
| 1776 | if (index->IsConstantOperand()) { |
| 1777 | int offset = ToInteger32(LConstantOperand::cast(index)); |
| 1778 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 1779 | offset *= kUC16Size; |
| 1780 | } |
| 1781 | STATIC_ASSERT(kCharSize == 1); |
| 1782 | return FieldOperand(string, SeqString::kHeaderSize + offset); |
| 1783 | } |
| 1784 | return FieldOperand( |
| 1785 | string, ToRegister(index), |
| 1786 | encoding == String::ONE_BYTE_ENCODING ? times_1 : times_2, |
| 1787 | SeqString::kHeaderSize); |
| 1788 | } |
| 1789 | |
| 1790 | |
| 1791 | void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 1792 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1793 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1794 | Register string = ToRegister(instr->string()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1795 | |
| 1796 | if (FLAG_debug_code) { |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 1797 | __ Push(string); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1798 | __ movp(string, FieldOperand(string, HeapObject::kMapOffset)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1799 | __ movzxbp(string, FieldOperand(string, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1800 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1801 | __ andb(string, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1802 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1803 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 1804 | __ cmpp(string, Immediate(encoding == String::ONE_BYTE_ENCODING |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1805 | ? one_byte_seq_type : two_byte_seq_type)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1806 | __ Check(equal, kUnexpectedStringType); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 1807 | __ Pop(string); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1810 | Operand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1811 | if (encoding == String::ONE_BYTE_ENCODING) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1812 | __ movzxbl(result, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1813 | } else { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1814 | __ movzxwl(result, operand); |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | |
| 1819 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1820 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1821 | Register string = ToRegister(instr->string()); |
| 1822 | |
| 1823 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1824 | Register value = ToRegister(instr->value()); |
| 1825 | Register index = ToRegister(instr->index()); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1826 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1827 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1828 | int encoding_mask = |
| 1829 | instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
| 1830 | ? one_byte_seq_type : two_byte_seq_type; |
| 1831 | __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | Operand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 1835 | if (instr->value()->IsConstantOperand()) { |
| 1836 | int value = ToInteger32(LConstantOperand::cast(instr->value())); |
| 1837 | ASSERT_LE(0, value); |
| 1838 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1839 | ASSERT_LE(value, String::kMaxOneByteCharCode); |
| 1840 | __ movb(operand, Immediate(value)); |
| 1841 | } else { |
| 1842 | ASSERT_LE(value, String::kMaxUtf16CodeUnit); |
| 1843 | __ movw(operand, Immediate(value)); |
| 1844 | } |
| 1845 | } else { |
| 1846 | Register value = ToRegister(instr->value()); |
| 1847 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1848 | __ movb(operand, value); |
| 1849 | } else { |
| 1850 | __ movw(operand, value); |
| 1851 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1852 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1856 | void LCodeGen::DoAddI(LAddI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1857 | LOperand* left = instr->left(); |
| 1858 | LOperand* right = instr->right(); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1859 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1860 | Representation target_rep = instr->hydrogen()->representation(); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1861 | bool is_p = target_rep.IsSmi() || target_rep.IsExternal(); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1862 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1863 | if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) { |
| 1864 | if (right->IsConstantOperand()) { |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1865 | ASSERT(!target_rep.IsSmi()); // No support for smi-immediates. |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1866 | int32_t offset = ToInteger32(LConstantOperand::cast(right)); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1867 | if (is_p) { |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1868 | __ leap(ToRegister(instr->result()), |
| 1869 | MemOperand(ToRegister(left), offset)); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1870 | } else { |
| 1871 | __ leal(ToRegister(instr->result()), |
| 1872 | MemOperand(ToRegister(left), offset)); |
| 1873 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1874 | } else { |
| 1875 | Operand address(ToRegister(left), ToRegister(right), times_1, 0); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1876 | if (is_p) { |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1877 | __ leap(ToRegister(instr->result()), address); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1878 | } else { |
| 1879 | __ leal(ToRegister(instr->result()), address); |
| 1880 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1881 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1882 | } else { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1883 | if (right->IsConstantOperand()) { |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1884 | ASSERT(!target_rep.IsSmi()); // No support for smi-immediates. |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1885 | if (is_p) { |
| 1886 | __ addp(ToRegister(left), |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1887 | Immediate(ToInteger32(LConstantOperand::cast(right)))); |
| 1888 | } else { |
| 1889 | __ addl(ToRegister(left), |
| 1890 | Immediate(ToInteger32(LConstantOperand::cast(right)))); |
| 1891 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1892 | } else if (right->IsRegister()) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1893 | if (is_p) { |
| 1894 | __ addp(ToRegister(left), ToRegister(right)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1895 | } else { |
| 1896 | __ addl(ToRegister(left), ToRegister(right)); |
| 1897 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1898 | } else { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1899 | if (is_p) { |
| 1900 | __ addp(ToRegister(left), ToOperand(right)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1901 | } else { |
| 1902 | __ addl(ToRegister(left), ToOperand(right)); |
| 1903 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1904 | } |
| 1905 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1906 | DeoptimizeIf(overflow, instr->environment()); |
| 1907 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1908 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1912 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1913 | LOperand* left = instr->left(); |
| 1914 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1915 | ASSERT(left->Equals(instr->result())); |
| 1916 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1917 | if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1918 | Label return_left; |
| 1919 | Condition condition = (operation == HMathMinMax::kMathMin) |
| 1920 | ? less_equal |
| 1921 | : greater_equal; |
| 1922 | Register left_reg = ToRegister(left); |
| 1923 | if (right->IsConstantOperand()) { |
| 1924 | Immediate right_imm = |
| 1925 | Immediate(ToInteger32(LConstantOperand::cast(right))); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1926 | ASSERT(!instr->hydrogen_value()->representation().IsSmi()); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 1927 | __ cmpl(left_reg, right_imm); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1928 | __ j(condition, &return_left, Label::kNear); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1929 | __ movp(left_reg, right_imm); |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 1930 | } else if (right->IsRegister()) { |
| 1931 | Register right_reg = ToRegister(right); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1932 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 1933 | __ cmpp(left_reg, right_reg); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1934 | } else { |
| 1935 | __ cmpl(left_reg, right_reg); |
| 1936 | } |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 1937 | __ j(condition, &return_left, Label::kNear); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1938 | __ movp(left_reg, right_reg); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1939 | } else { |
| 1940 | Operand right_op = ToOperand(right); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1941 | if (instr->hydrogen_value()->representation().IsSmi()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 1942 | __ cmpp(left_reg, right_op); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1943 | } else { |
| 1944 | __ cmpl(left_reg, right_op); |
| 1945 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1946 | __ j(condition, &return_left, Label::kNear); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 1947 | __ movp(left_reg, right_op); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1948 | } |
| 1949 | __ bind(&return_left); |
| 1950 | } else { |
| 1951 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
| 1952 | Label check_nan_left, check_zero, return_left, return_right; |
| 1953 | Condition condition = (operation == HMathMinMax::kMathMin) ? below : above; |
| 1954 | XMMRegister left_reg = ToDoubleRegister(left); |
| 1955 | XMMRegister right_reg = ToDoubleRegister(right); |
| 1956 | __ ucomisd(left_reg, right_reg); |
| 1957 | __ j(parity_even, &check_nan_left, Label::kNear); // At least one NaN. |
| 1958 | __ j(equal, &check_zero, Label::kNear); // left == right. |
| 1959 | __ j(condition, &return_left, Label::kNear); |
| 1960 | __ jmp(&return_right, Label::kNear); |
| 1961 | |
| 1962 | __ bind(&check_zero); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1963 | XMMRegister xmm_scratch = double_scratch0(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1964 | __ xorps(xmm_scratch, xmm_scratch); |
| 1965 | __ ucomisd(left_reg, xmm_scratch); |
| 1966 | __ j(not_equal, &return_left, Label::kNear); // left == right != 0. |
| 1967 | // At this point, both left and right are either 0 or -0. |
| 1968 | if (operation == HMathMinMax::kMathMin) { |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1969 | __ orps(left_reg, right_reg); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1970 | } else { |
| 1971 | // Since we operate on +0 and/or -0, addsd and andsd have the same effect. |
| 1972 | __ addsd(left_reg, right_reg); |
| 1973 | } |
| 1974 | __ jmp(&return_left, Label::kNear); |
| 1975 | |
| 1976 | __ bind(&check_nan_left); |
| 1977 | __ ucomisd(left_reg, left_reg); // NaN check. |
| 1978 | __ j(parity_even, &return_left, Label::kNear); |
| 1979 | __ bind(&return_right); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1980 | __ movaps(left_reg, right_reg); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1981 | |
| 1982 | __ bind(&return_left); |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1987 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1988 | XMMRegister left = ToDoubleRegister(instr->left()); |
| 1989 | XMMRegister right = ToDoubleRegister(instr->right()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1990 | XMMRegister result = ToDoubleRegister(instr->result()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1991 | // All operations except MOD are computed in-place. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1992 | ASSERT(instr->op() == Token::MOD || left.is(result)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1993 | switch (instr->op()) { |
| 1994 | case Token::ADD: |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1995 | __ addsd(left, right); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1996 | break; |
| 1997 | case Token::SUB: |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1998 | __ subsd(left, right); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1999 | break; |
| 2000 | case Token::MUL: |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2001 | __ mulsd(left, right); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2002 | break; |
| 2003 | case Token::DIV: |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2004 | __ divsd(left, right); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2005 | // Don't delete this mov. It may improve performance on some CPUs, |
| 2006 | // when there is a mulsd depending on the result |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 2007 | __ movaps(left, left); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2008 | break; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2009 | case Token::MOD: { |
| 2010 | XMMRegister xmm_scratch = double_scratch0(); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2011 | __ PrepareCallCFunction(2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2012 | __ movaps(xmm_scratch, left); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2013 | ASSERT(right.is(xmm1)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2014 | __ CallCFunction( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 2015 | ExternalReference::mod_two_doubles_operation(isolate()), 2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2016 | __ movaps(result, xmm_scratch); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2017 | break; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2018 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2019 | default: |
| 2020 | UNREACHABLE(); |
| 2021 | break; |
| 2022 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | |
| 2026 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2027 | ASSERT(ToRegister(instr->context()).is(rsi)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2028 | ASSERT(ToRegister(instr->left()).is(rdx)); |
| 2029 | ASSERT(ToRegister(instr->right()).is(rax)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2030 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 2031 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2032 | BinaryOpICStub stub(instr->op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2033 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2037 | template<class InstrType> |
| 2038 | void LCodeGen::EmitBranch(InstrType instr, Condition cc) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2039 | int left_block = instr->TrueDestination(chunk_); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2040 | int right_block = instr->FalseDestination(chunk_); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2041 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2042 | int next_block = GetNextEmittedBlock(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2043 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2044 | if (right_block == left_block || cc == no_condition) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2045 | EmitGoto(left_block); |
| 2046 | } else if (left_block == next_block) { |
| 2047 | __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 2048 | } else if (right_block == next_block) { |
| 2049 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2050 | } else { |
| 2051 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2052 | if (cc != always) { |
| 2053 | __ jmp(chunk_->GetAssemblyLabel(right_block)); |
| 2054 | } |
| 2055 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2059 | template<class InstrType> |
| 2060 | void LCodeGen::EmitFalseBranch(InstrType instr, Condition cc) { |
| 2061 | int false_block = instr->FalseDestination(chunk_); |
| 2062 | __ j(cc, chunk_->GetAssemblyLabel(false_block)); |
| 2063 | } |
| 2064 | |
| 2065 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2066 | void LCodeGen::DoDebugBreak(LDebugBreak* instr) { |
| 2067 | __ int3(); |
| 2068 | } |
| 2069 | |
| 2070 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2071 | void LCodeGen::DoBranch(LBranch* instr) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2072 | Representation r = instr->hydrogen()->value()->representation(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2073 | if (r.IsInteger32()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2074 | ASSERT(!info()->IsStub()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2075 | Register reg = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2076 | __ testl(reg, reg); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2077 | EmitBranch(instr, not_zero); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2078 | } else if (r.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2079 | ASSERT(!info()->IsStub()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2080 | Register reg = ToRegister(instr->value()); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2081 | __ testp(reg, reg); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2082 | EmitBranch(instr, not_zero); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2083 | } else if (r.IsDouble()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2084 | ASSERT(!info()->IsStub()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2085 | XMMRegister reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2086 | XMMRegister xmm_scratch = double_scratch0(); |
| 2087 | __ xorps(xmm_scratch, xmm_scratch); |
| 2088 | __ ucomisd(reg, xmm_scratch); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2089 | EmitBranch(instr, not_equal); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2090 | } else { |
| 2091 | ASSERT(r.IsTagged()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2092 | Register reg = ToRegister(instr->value()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2093 | HType type = instr->hydrogen()->value()->type(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2094 | if (type.IsBoolean()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2095 | ASSERT(!info()->IsStub()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2096 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2097 | EmitBranch(instr, equal); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2098 | } else if (type.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2099 | ASSERT(!info()->IsStub()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2100 | __ SmiCompare(reg, Smi::FromInt(0)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2101 | EmitBranch(instr, not_equal); |
| 2102 | } else if (type.IsJSArray()) { |
| 2103 | ASSERT(!info()->IsStub()); |
| 2104 | EmitBranch(instr, no_condition); |
| 2105 | } else if (type.IsHeapNumber()) { |
| 2106 | ASSERT(!info()->IsStub()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2107 | XMMRegister xmm_scratch = double_scratch0(); |
| 2108 | __ xorps(xmm_scratch, xmm_scratch); |
| 2109 | __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2110 | EmitBranch(instr, not_equal); |
| 2111 | } else if (type.IsString()) { |
| 2112 | ASSERT(!info()->IsStub()); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2113 | __ cmpp(FieldOperand(reg, String::kLengthOffset), Immediate(0)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2114 | EmitBranch(instr, not_equal); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2115 | } else { |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2116 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 2117 | // Avoid deopts in the case where we've never executed this path before. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2118 | if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2119 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2120 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2121 | // undefined -> false. |
| 2122 | __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2123 | __ j(equal, instr->FalseLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2124 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2125 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2126 | // true -> true. |
| 2127 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2128 | __ j(equal, instr->TrueLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2129 | // false -> false. |
| 2130 | __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2131 | __ j(equal, instr->FalseLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2132 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2133 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2134 | // 'null' -> false. |
| 2135 | __ CompareRoot(reg, Heap::kNullValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2136 | __ j(equal, instr->FalseLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 2140 | // Smis: 0 -> false, all other -> true. |
| 2141 | __ Cmp(reg, Smi::FromInt(0)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2142 | __ j(equal, instr->FalseLabel(chunk_)); |
| 2143 | __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2144 | } else if (expected.NeedsMap()) { |
| 2145 | // If we need a map later and have a Smi -> deopt. |
| 2146 | __ testb(reg, Immediate(kSmiTagMask)); |
| 2147 | DeoptimizeIf(zero, instr->environment()); |
| 2148 | } |
| 2149 | |
| 2150 | const Register map = kScratchRegister; |
| 2151 | if (expected.NeedsMap()) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2152 | __ movp(map, FieldOperand(reg, HeapObject::kMapOffset)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2153 | |
| 2154 | if (expected.CanBeUndetectable()) { |
| 2155 | // Undetectable -> false. |
| 2156 | __ testb(FieldOperand(map, Map::kBitFieldOffset), |
| 2157 | Immediate(1 << Map::kIsUndetectable)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2158 | __ j(not_zero, instr->FalseLabel(chunk_)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2159 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2163 | // spec object -> true. |
| 2164 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2165 | __ j(above_equal, instr->TrueLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 2169 | // String value -> false iff empty. |
| 2170 | Label not_string; |
| 2171 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 2172 | __ j(above_equal, ¬_string, Label::kNear); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2173 | __ cmpp(FieldOperand(reg, String::kLengthOffset), Immediate(0)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2174 | __ j(not_zero, instr->TrueLabel(chunk_)); |
| 2175 | __ jmp(instr->FalseLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2176 | __ bind(¬_string); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
danno@chromium.org | c16e828 | 2013-08-12 16:17:40 +0000 | [diff] [blame] | 2179 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2180 | // Symbol value -> true. |
| 2181 | __ CmpInstanceType(map, SYMBOL_TYPE); |
| 2182 | __ j(equal, instr->TrueLabel(chunk_)); |
| 2183 | } |
| 2184 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2185 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2186 | // heap number -> false iff +0, -0, or NaN. |
| 2187 | Label not_heap_number; |
| 2188 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 2189 | __ j(not_equal, ¬_heap_number, Label::kNear); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2190 | XMMRegister xmm_scratch = double_scratch0(); |
| 2191 | __ xorps(xmm_scratch, xmm_scratch); |
| 2192 | __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2193 | __ j(zero, instr->FalseLabel(chunk_)); |
| 2194 | __ jmp(instr->TrueLabel(chunk_)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2195 | __ bind(¬_heap_number); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2198 | if (!expected.IsGeneric()) { |
| 2199 | // We've seen something for the first time -> deopt. |
| 2200 | // This can only happen if we are not generic already. |
| 2201 | DeoptimizeIf(no_condition, instr->environment()); |
| 2202 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2203 | } |
| 2204 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2208 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2209 | if (!IsNextEmittedBlock(block)) { |
| 2210 | __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2211 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2215 | void LCodeGen::DoGoto(LGoto* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2216 | EmitGoto(instr->block_id()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2220 | inline Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2221 | Condition cond = no_condition; |
| 2222 | switch (op) { |
| 2223 | case Token::EQ: |
| 2224 | case Token::EQ_STRICT: |
| 2225 | cond = equal; |
| 2226 | break; |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2227 | case Token::NE: |
| 2228 | case Token::NE_STRICT: |
| 2229 | cond = not_equal; |
| 2230 | break; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2231 | case Token::LT: |
| 2232 | cond = is_unsigned ? below : less; |
| 2233 | break; |
| 2234 | case Token::GT: |
| 2235 | cond = is_unsigned ? above : greater; |
| 2236 | break; |
| 2237 | case Token::LTE: |
| 2238 | cond = is_unsigned ? below_equal : less_equal; |
| 2239 | break; |
| 2240 | case Token::GTE: |
| 2241 | cond = is_unsigned ? above_equal : greater_equal; |
| 2242 | break; |
| 2243 | case Token::IN: |
| 2244 | case Token::INSTANCEOF: |
| 2245 | default: |
| 2246 | UNREACHABLE(); |
| 2247 | } |
| 2248 | return cond; |
| 2249 | } |
| 2250 | |
| 2251 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2252 | void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2253 | LOperand* left = instr->left(); |
| 2254 | LOperand* right = instr->right(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2255 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2256 | |
| 2257 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2258 | // We can statically evaluate the comparison. |
| 2259 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2260 | double right_val = ToDouble(LConstantOperand::cast(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2261 | int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
| 2262 | instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2263 | EmitGoto(next_block); |
| 2264 | } else { |
| 2265 | if (instr->is_double()) { |
| 2266 | // Don't base result on EFLAGS when a NaN is involved. Instead |
| 2267 | // jump to the false block. |
| 2268 | __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2269 | __ j(parity_even, instr->FalseLabel(chunk_)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2270 | } else { |
| 2271 | int32_t value; |
| 2272 | if (right->IsConstantOperand()) { |
| 2273 | value = ToInteger32(LConstantOperand::cast(right)); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2274 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2275 | __ Cmp(ToRegister(left), Smi::FromInt(value)); |
| 2276 | } else { |
| 2277 | __ cmpl(ToRegister(left), Immediate(value)); |
| 2278 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2279 | } else if (left->IsConstantOperand()) { |
| 2280 | value = ToInteger32(LConstantOperand::cast(left)); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2281 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2282 | if (right->IsRegister()) { |
| 2283 | __ Cmp(ToRegister(right), Smi::FromInt(value)); |
| 2284 | } else { |
| 2285 | __ Cmp(ToOperand(right), Smi::FromInt(value)); |
| 2286 | } |
| 2287 | } else if (right->IsRegister()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2288 | __ cmpl(ToRegister(right), Immediate(value)); |
| 2289 | } else { |
| 2290 | __ cmpl(ToOperand(right), Immediate(value)); |
| 2291 | } |
| 2292 | // We transposed the operands. Reverse the condition. |
| 2293 | cc = ReverseCondition(cc); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2294 | } else if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2295 | if (right->IsRegister()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2296 | __ cmpp(ToRegister(left), ToRegister(right)); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2297 | } else { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2298 | __ cmpp(ToRegister(left), ToOperand(right)); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2299 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2300 | } else { |
| 2301 | if (right->IsRegister()) { |
| 2302 | __ cmpl(ToRegister(left), ToRegister(right)); |
| 2303 | } else { |
| 2304 | __ cmpl(ToRegister(left), ToOperand(right)); |
| 2305 | } |
| 2306 | } |
| 2307 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2308 | EmitBranch(instr, cc); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2309 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 2313 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2314 | Register left = ToRegister(instr->left()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2315 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2316 | if (instr->right()->IsConstantOperand()) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2317 | Handle<Object> right = ToHandle(LConstantOperand::cast(instr->right())); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 2318 | __ Cmp(left, right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2319 | } else { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2320 | Register right = ToRegister(instr->right()); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2321 | __ cmpp(left, right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2322 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2323 | EmitBranch(instr, equal); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2327 | void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2328 | if (instr->hydrogen()->representation().IsTagged()) { |
| 2329 | Register input_reg = ToRegister(instr->object()); |
| 2330 | __ Cmp(input_reg, factory()->the_hole_value()); |
| 2331 | EmitBranch(instr, equal); |
| 2332 | return; |
| 2333 | } |
| 2334 | |
| 2335 | XMMRegister input_reg = ToDoubleRegister(instr->object()); |
| 2336 | __ ucomisd(input_reg, input_reg); |
| 2337 | EmitFalseBranch(instr, parity_odd); |
| 2338 | |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 2339 | __ subp(rsp, Immediate(kDoubleSize)); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2340 | __ movsd(MemOperand(rsp, 0), input_reg); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 2341 | __ addp(rsp, Immediate(kDoubleSize)); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2342 | |
| 2343 | int offset = sizeof(kHoleNanUpper32); |
| 2344 | __ cmpl(MemOperand(rsp, -offset), Immediate(kHoleNanUpper32)); |
| 2345 | EmitBranch(instr, equal); |
| 2346 | } |
| 2347 | |
| 2348 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2349 | void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
| 2350 | Representation rep = instr->hydrogen()->value()->representation(); |
| 2351 | ASSERT(!rep.IsInteger32()); |
| 2352 | |
| 2353 | if (rep.IsDouble()) { |
| 2354 | XMMRegister value = ToDoubleRegister(instr->value()); |
| 2355 | XMMRegister xmm_scratch = double_scratch0(); |
| 2356 | __ xorps(xmm_scratch, xmm_scratch); |
| 2357 | __ ucomisd(xmm_scratch, value); |
| 2358 | EmitFalseBranch(instr, not_equal); |
| 2359 | __ movmskpd(kScratchRegister, value); |
| 2360 | __ testl(kScratchRegister, Immediate(1)); |
| 2361 | EmitBranch(instr, not_zero); |
| 2362 | } else { |
| 2363 | Register value = ToRegister(instr->value()); |
| 2364 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 2365 | __ CheckMap(value, map, instr->FalseLabel(chunk()), DO_SMI_CHECK); |
| 2366 | __ cmpl(FieldOperand(value, HeapNumber::kExponentOffset), |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 2367 | Immediate(0x1)); |
| 2368 | EmitFalseBranch(instr, no_overflow); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2369 | __ cmpl(FieldOperand(value, HeapNumber::kMantissaOffset), |
| 2370 | Immediate(0x00000000)); |
| 2371 | EmitBranch(instr, equal); |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2376 | Condition LCodeGen::EmitIsObject(Register input, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2377 | Label* is_not_object, |
| 2378 | Label* is_object) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2379 | ASSERT(!input.is(kScratchRegister)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2380 | |
| 2381 | __ JumpIfSmi(input, is_not_object); |
| 2382 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2383 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2384 | __ j(equal, is_object); |
| 2385 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2386 | __ movp(kScratchRegister, FieldOperand(input, HeapObject::kMapOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2387 | // Undetectable objects behave like undefined. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2388 | __ testb(FieldOperand(kScratchRegister, Map::kBitFieldOffset), |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2389 | Immediate(1 << Map::kIsUndetectable)); |
| 2390 | __ j(not_zero, is_not_object); |
| 2391 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2392 | __ movzxbl(kScratchRegister, |
| 2393 | FieldOperand(kScratchRegister, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2394 | __ cmpb(kScratchRegister, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2395 | __ j(below, is_not_object); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2396 | __ cmpb(kScratchRegister, Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2397 | return below_equal; |
| 2398 | } |
| 2399 | |
| 2400 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2401 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2402 | Register reg = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2403 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2404 | Condition true_cond = EmitIsObject( |
| 2405 | reg, instr->FalseLabel(chunk_), instr->TrueLabel(chunk_)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2406 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2407 | EmitBranch(instr, true_cond); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2411 | Condition LCodeGen::EmitIsString(Register input, |
| 2412 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2413 | Label* is_not_string, |
| 2414 | SmiCheck check_needed = INLINE_SMI_CHECK) { |
| 2415 | if (check_needed == INLINE_SMI_CHECK) { |
| 2416 | __ JumpIfSmi(input, is_not_string); |
| 2417 | } |
| 2418 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2419 | Condition cond = masm_->IsObjectStringType(input, temp1, temp1); |
| 2420 | |
| 2421 | return cond; |
| 2422 | } |
| 2423 | |
| 2424 | |
| 2425 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2426 | Register reg = ToRegister(instr->value()); |
| 2427 | Register temp = ToRegister(instr->temp()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2428 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2429 | SmiCheck check_needed = |
| 2430 | instr->hydrogen()->value()->IsHeapObject() |
| 2431 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2432 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2433 | Condition true_cond = EmitIsString( |
| 2434 | reg, temp, instr->FalseLabel(chunk_), check_needed); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2435 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2436 | EmitBranch(instr, true_cond); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2440 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2441 | Condition is_smi; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2442 | if (instr->value()->IsRegister()) { |
| 2443 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2444 | is_smi = masm()->CheckSmi(input); |
| 2445 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2446 | Operand input = ToOperand(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2447 | is_smi = masm()->CheckSmi(input); |
| 2448 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2449 | EmitBranch(instr, is_smi); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2453 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2454 | Register input = ToRegister(instr->value()); |
| 2455 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2456 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2457 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2458 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2459 | } |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2460 | __ movp(temp, FieldOperand(input, HeapObject::kMapOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2461 | __ testb(FieldOperand(temp, Map::kBitFieldOffset), |
| 2462 | Immediate(1 << Map::kIsUndetectable)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2463 | EmitBranch(instr, not_zero); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2467 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2468 | ASSERT(ToRegister(instr->context()).is(rsi)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2469 | Token::Value op = instr->op(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2470 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2471 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2472 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2473 | |
| 2474 | Condition condition = TokenToCondition(op, false); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2475 | __ testp(rax, rax); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2476 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2477 | EmitBranch(instr, condition); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2481 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2482 | InstanceType from = instr->from(); |
| 2483 | InstanceType to = instr->to(); |
| 2484 | if (from == FIRST_TYPE) return to; |
| 2485 | ASSERT(from == to || to == LAST_TYPE); |
| 2486 | return from; |
| 2487 | } |
| 2488 | |
| 2489 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2490 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2491 | InstanceType from = instr->from(); |
| 2492 | InstanceType to = instr->to(); |
| 2493 | if (from == to) return equal; |
| 2494 | if (to == LAST_TYPE) return above_equal; |
| 2495 | if (from == FIRST_TYPE) return below_equal; |
| 2496 | UNREACHABLE(); |
| 2497 | return equal; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2501 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2502 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2503 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2504 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2505 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2506 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2507 | |
| 2508 | __ CmpObjectType(input, TestType(instr->hydrogen()), kScratchRegister); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2509 | EmitBranch(instr, BranchCondition(instr->hydrogen())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2513 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2514 | Register input = ToRegister(instr->value()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2515 | Register result = ToRegister(instr->result()); |
| 2516 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2517 | __ AssertString(input); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2518 | |
| 2519 | __ movl(result, FieldOperand(input, String::kHashFieldOffset)); |
| 2520 | ASSERT(String::kHashShift >= kSmiTagSize); |
| 2521 | __ IndexFromHash(result, result); |
| 2522 | } |
| 2523 | |
| 2524 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2525 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2526 | LHasCachedArrayIndexAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2527 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2528 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2529 | __ testl(FieldOperand(input, String::kHashFieldOffset), |
| 2530 | Immediate(String::kContainsCachedArrayIndexMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2531 | EmitBranch(instr, equal); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2535 | // Branches to a label or falls through with the answer in the z flag. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2536 | // Trashes the temp register. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2537 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2538 | Label* is_false, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2539 | Handle<String> class_name, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2540 | Register input, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2541 | Register temp, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2542 | Register temp2) { |
| 2543 | ASSERT(!input.is(temp)); |
| 2544 | ASSERT(!input.is(temp2)); |
| 2545 | ASSERT(!temp.is(temp2)); |
| 2546 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2547 | __ JumpIfSmi(input, is_false); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2548 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2549 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2550 | // Assuming the following assertions, we can use the same compares to test |
| 2551 | // for both being a function type and being in the object type range. |
| 2552 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2553 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2554 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2555 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2556 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2557 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2558 | __ CmpObjectType(input, FIRST_SPEC_OBJECT_TYPE, temp); |
| 2559 | __ j(below, is_false); |
| 2560 | __ j(equal, is_true); |
| 2561 | __ CmpInstanceType(temp, LAST_SPEC_OBJECT_TYPE); |
| 2562 | __ j(equal, is_true); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2563 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2564 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2565 | // actual type and do a signed compare with the width of the type range. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2566 | __ movp(temp, FieldOperand(input, HeapObject::kMapOffset)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2567 | __ movzxbl(temp2, FieldOperand(temp, Map::kInstanceTypeOffset)); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 2568 | __ subp(temp2, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2569 | __ cmpp(temp2, Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2570 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2571 | __ j(above, is_false); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2574 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2575 | // Check if the constructor in the map is a function. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2576 | __ movp(temp, FieldOperand(temp, Map::kConstructorOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2577 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2578 | // Objects with a non-function constructor have class 'Object'. |
| 2579 | __ CmpObjectType(temp, JS_FUNCTION_TYPE, kScratchRegister); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2580 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2581 | __ j(not_equal, is_true); |
| 2582 | } else { |
| 2583 | __ j(not_equal, is_false); |
| 2584 | } |
| 2585 | |
| 2586 | // temp now contains the constructor function. Grab the |
| 2587 | // instance class name from there. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2588 | __ movp(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2589 | __ movp(temp, FieldOperand(temp, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2590 | SharedFunctionInfo::kInstanceClassNameOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2591 | // The class name we are testing against is internalized since it's a literal. |
| 2592 | // The name in the constructor is internalized because of the way the context |
| 2593 | // is booted. This routine isn't expected to work for random API-created |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2594 | // 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] | 2595 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2596 | // identity comparison. |
| 2597 | ASSERT(class_name->IsInternalizedString()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2598 | __ Cmp(temp, class_name); |
| 2599 | // End with the answer in the z flag. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2603 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2604 | Register input = ToRegister(instr->value()); |
| 2605 | Register temp = ToRegister(instr->temp()); |
| 2606 | Register temp2 = ToRegister(instr->temp2()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2607 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2608 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2609 | EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2610 | class_name, input, temp, temp2); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2611 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2612 | EmitBranch(instr, equal); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | |
| 2616 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2617 | Register reg = ToRegister(instr->value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2618 | |
| 2619 | __ Cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2620 | EmitBranch(instr, equal); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2625 | ASSERT(ToRegister(instr->context()).is(rsi)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2626 | InstanceofStub stub(InstanceofStub::kNoFlags); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 2627 | __ Push(ToRegister(instr->left())); |
| 2628 | __ Push(ToRegister(instr->right())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2629 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2630 | Label true_value, done; |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2631 | __ testp(rax, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2632 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2633 | __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2634 | __ jmp(&done, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2635 | __ bind(&true_value); |
| 2636 | __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
| 2637 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2641 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2642 | class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2643 | public: |
| 2644 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2645 | LInstanceOfKnownGlobal* instr) |
| 2646 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2647 | virtual void Generate() V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2648 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2649 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2650 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2651 | Label* map_check() { return &map_check_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2652 | private: |
| 2653 | LInstanceOfKnownGlobal* instr_; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2654 | Label map_check_; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2655 | }; |
| 2656 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2657 | ASSERT(ToRegister(instr->context()).is(rsi)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2658 | DeferredInstanceOfKnownGlobal* deferred; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2659 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2660 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2661 | Label done, false_result; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2662 | Register object = ToRegister(instr->value()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2663 | |
| 2664 | // A Smi is not an instance of anything. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2665 | __ JumpIfSmi(object, &false_result, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2666 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2667 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2668 | // hole value will be patched to the last map/result pair generated by the |
| 2669 | // instanceof stub. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2670 | Label cache_miss; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2671 | // Use a temp register to avoid memory operands with variable lengths. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2672 | Register map = ToRegister(instr->temp()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2673 | __ movp(map, FieldOperand(object, HeapObject::kMapOffset)); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2674 | __ bind(deferred->map_check()); // Label for calculating code patching. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2675 | Handle<Cell> cache_cell = factory()->NewCell(factory()->the_hole_value()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2676 | __ Move(kScratchRegister, cache_cell, RelocInfo::CELL); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2677 | __ cmpp(map, Operand(kScratchRegister, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2678 | __ j(not_equal, &cache_miss, Label::kNear); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2679 | // Patched to load either true or false. |
| 2680 | __ LoadRoot(ToRegister(instr->result()), Heap::kTheHoleValueRootIndex); |
| 2681 | #ifdef DEBUG |
| 2682 | // Check that the code size between patch label and patch sites is invariant. |
| 2683 | Label end_of_patched_code; |
| 2684 | __ bind(&end_of_patched_code); |
| 2685 | ASSERT(true); |
| 2686 | #endif |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2687 | __ jmp(&done, Label::kNear); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2688 | |
| 2689 | // The inlined call site cache did not match. Check for null and string |
| 2690 | // before calling the deferred code. |
| 2691 | __ bind(&cache_miss); // Null is not an instance of anything. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2692 | __ CompareRoot(object, Heap::kNullValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2693 | __ j(equal, &false_result, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2694 | |
| 2695 | // String values are not instances of anything. |
| 2696 | __ JumpIfNotString(object, kScratchRegister, deferred->entry()); |
| 2697 | |
| 2698 | __ bind(&false_result); |
| 2699 | __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
| 2700 | |
| 2701 | __ bind(deferred->exit()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2702 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2706 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2707 | Label* map_check) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2708 | { |
| 2709 | PushSafepointRegistersScope scope(this); |
| 2710 | InstanceofStub::Flags flags = static_cast<InstanceofStub::Flags>( |
| 2711 | InstanceofStub::kNoFlags | InstanceofStub::kCallSiteInlineCheck); |
| 2712 | InstanceofStub stub(flags); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2713 | |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 2714 | __ Push(ToRegister(instr->value())); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 2715 | __ Push(instr->function()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2716 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2717 | static const int kAdditionalDelta = 10; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2718 | int delta = |
| 2719 | masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2720 | ASSERT(delta >= 0); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 2721 | __ PushImm32(delta); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2722 | |
| 2723 | // We are pushing three values on the stack but recording a |
| 2724 | // safepoint with two arguments because stub is going to |
| 2725 | // remove the third argument from the stack before jumping |
| 2726 | // to instanceof builtin on the slow path. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2727 | CallCodeGeneric(stub.GetCode(isolate()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2728 | RelocInfo::CODE_TARGET, |
| 2729 | instr, |
| 2730 | RECORD_SAFEPOINT_WITH_REGISTERS, |
| 2731 | 2); |
| 2732 | ASSERT(delta == masm_->SizeOfCodeGeneratedSince(map_check)); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2733 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2734 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2735 | // Move result to a register that survives the end of the |
| 2736 | // PushSafepointRegisterScope. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2737 | __ movp(kScratchRegister, rax); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2738 | } |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2739 | __ testp(kScratchRegister, kScratchRegister); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2740 | Label load_false; |
| 2741 | Label done; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2742 | __ j(not_zero, &load_false, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2743 | __ LoadRoot(rax, Heap::kTrueValueRootIndex); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2744 | __ jmp(&done, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2745 | __ bind(&load_false); |
| 2746 | __ LoadRoot(rax, Heap::kFalseValueRootIndex); |
| 2747 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | |
| 2751 | void LCodeGen::DoCmpT(LCmpT* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2752 | ASSERT(ToRegister(instr->context()).is(rsi)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2753 | Token::Value op = instr->op(); |
| 2754 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2755 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2756 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2757 | |
| 2758 | Condition condition = TokenToCondition(op, false); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2759 | Label true_value, done; |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 2760 | __ testp(rax, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2761 | __ j(condition, &true_value, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2762 | __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2763 | __ jmp(&done, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2764 | __ bind(&true_value); |
| 2765 | __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
| 2766 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2770 | void LCodeGen::DoReturn(LReturn* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2771 | if (FLAG_trace && info()->IsOptimizing()) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2772 | // Preserve the return value on the stack and rely on the runtime call |
| 2773 | // to return the value in the same register. We're leaving the code |
| 2774 | // managed by the register allocator and tearing down the frame, it's |
| 2775 | // safe to write to the context register. |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 2776 | __ Push(rax); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2777 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2778 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2779 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2780 | if (info()->saves_caller_doubles()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2781 | RestoreCallerDoubles(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2782 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2783 | int no_frame_start = -1; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2784 | if (NeedsEagerFrame()) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2785 | __ movp(rsp, rbp); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 2786 | __ popq(rbp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2787 | no_frame_start = masm_->pc_offset(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2788 | } |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2789 | if (instr->has_constant_parameter_count()) { |
| 2790 | __ Ret((ToInteger32(instr->constant_parameter_count()) + 1) * kPointerSize, |
| 2791 | rcx); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2792 | } else { |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2793 | Register reg = ToRegister(instr->parameter_count()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2794 | // The argument count parameter is a smi |
| 2795 | __ SmiToInteger32(reg, reg); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2796 | Register return_addr_reg = reg.is(rcx) ? rbx : rcx; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2797 | __ PopReturnAddressTo(return_addr_reg); |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 2798 | __ shlp(reg, Immediate(kPointerSizeLog2)); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 2799 | __ addp(rsp, reg); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2800 | __ jmp(return_addr_reg); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2801 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2802 | if (no_frame_start != -1) { |
| 2803 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 2804 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2808 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2809 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2810 | __ LoadGlobalCell(result, instr->hydrogen()->cell().handle()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2811 | if (instr->hydrogen()->RequiresHoleCheck()) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2812 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 2813 | DeoptimizeIf(equal, instr->environment()); |
| 2814 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2818 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2819 | ASSERT(ToRegister(instr->context()).is(rsi)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2820 | ASSERT(ToRegister(instr->global_object()).is(rax)); |
| 2821 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 2822 | |
| 2823 | __ Move(rcx, instr->name()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2824 | ContextualMode mode = instr->for_typeof() ? NOT_CONTEXTUAL : CONTEXTUAL; |
| 2825 | Handle<Code> ic = LoadIC::initialize_stub(isolate(), mode); |
| 2826 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2830 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2831 | Register value = ToRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2832 | Handle<Cell> cell_handle = instr->hydrogen()->cell().handle(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2833 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2834 | // If the cell we are storing to contains the hole it could have |
| 2835 | // been deleted from the property dictionary. In that case, we need |
| 2836 | // to update the property details in the property dictionary to mark |
| 2837 | // it as no longer deleted. We deoptimize in that case. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2838 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2839 | // We have a temp because CompareRoot might clobber kScratchRegister. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2840 | Register cell = ToRegister(instr->temp()); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2841 | ASSERT(!value.is(cell)); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2842 | __ Move(cell, cell_handle, RelocInfo::CELL); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2843 | __ CompareRoot(Operand(cell, 0), Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2844 | DeoptimizeIf(equal, instr->environment()); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2845 | // Store the value. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2846 | __ movp(Operand(cell, 0), value); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2847 | } else { |
| 2848 | // Store the value. |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2849 | __ Move(kScratchRegister, cell_handle, RelocInfo::CELL); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2850 | __ movp(Operand(kScratchRegister, 0), value); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2851 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2852 | // Cells are always rescanned, so no write barrier here. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | |
| 2856 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2857 | Register context = ToRegister(instr->context()); |
| 2858 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2859 | __ movp(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2860 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2861 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2862 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2863 | DeoptimizeIf(equal, instr->environment()); |
| 2864 | } else { |
| 2865 | Label is_not_hole; |
| 2866 | __ j(not_equal, &is_not_hole, Label::kNear); |
| 2867 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2868 | __ bind(&is_not_hole); |
| 2869 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2870 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | |
| 2874 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 2875 | Register context = ToRegister(instr->context()); |
| 2876 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2877 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2878 | Operand target = ContextOperand(context, instr->slot_index()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2879 | |
| 2880 | Label skip_assignment; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2881 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2882 | __ CompareRoot(target, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2883 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2884 | DeoptimizeIf(equal, instr->environment()); |
| 2885 | } else { |
| 2886 | __ j(not_equal, &skip_assignment); |
| 2887 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2888 | } |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2889 | __ movp(target, value); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2890 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2891 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2892 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2893 | instr->hydrogen()->value()->IsHeapObject() |
| 2894 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2895 | int offset = Context::SlotOffset(instr->slot_index()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2896 | Register scratch = ToRegister(instr->temp()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2897 | __ RecordWriteContextSlot(context, |
| 2898 | offset, |
| 2899 | value, |
| 2900 | scratch, |
| 2901 | kSaveFPRegs, |
| 2902 | EMIT_REMEMBERED_SET, |
| 2903 | check_needed); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2904 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2905 | |
| 2906 | __ bind(&skip_assignment); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | |
| 2910 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2911 | HObjectAccess access = instr->hydrogen()->access(); |
| 2912 | int offset = access.offset(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2913 | |
| 2914 | if (access.IsExternalMemory()) { |
| 2915 | Register result = ToRegister(instr->result()); |
| 2916 | if (instr->object()->IsConstantOperand()) { |
| 2917 | ASSERT(result.is(rax)); |
| 2918 | __ load_rax(ToExternalReference(LConstantOperand::cast(instr->object()))); |
| 2919 | } else { |
| 2920 | Register object = ToRegister(instr->object()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2921 | __ Load(result, MemOperand(object, offset), access.representation()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2922 | } |
| 2923 | return; |
| 2924 | } |
| 2925 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2926 | Register object = ToRegister(instr->object()); |
machenbach@chromium.org | 09cae8d | 2014-01-30 01:05:27 +0000 | [diff] [blame] | 2927 | if (instr->hydrogen()->representation().IsDouble()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2928 | XMMRegister result = ToDoubleRegister(instr->result()); |
| 2929 | __ movsd(result, FieldOperand(object, offset)); |
| 2930 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2933 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2934 | if (!access.IsInobject()) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2935 | __ movp(result, FieldOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2936 | object = result; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2937 | } |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 2938 | |
| 2939 | Representation representation = access.representation(); |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 2940 | if (representation.IsSmi() && SmiValuesAre32Bits() && |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 2941 | instr->hydrogen()->representation().IsInteger32()) { |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 2942 | if (FLAG_debug_code) { |
| 2943 | Register scratch = kScratchRegister; |
| 2944 | __ Load(scratch, FieldOperand(object, offset), representation); |
| 2945 | __ AssertSmi(scratch); |
| 2946 | } |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2947 | |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 2948 | // Read int value directly from upper half of the smi. |
| 2949 | STATIC_ASSERT(kSmiTag == 0); |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 2950 | ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 2951 | offset += kPointerSize / 2; |
| 2952 | representation = Representation::Integer32(); |
| 2953 | } |
| 2954 | __ Load(result, FieldOperand(object, offset), representation); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | |
| 2958 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2959 | ASSERT(ToRegister(instr->context()).is(rsi)); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2960 | ASSERT(ToRegister(instr->object()).is(rax)); |
| 2961 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 2962 | |
| 2963 | __ Move(rcx, instr->name()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2964 | Handle<Code> ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2965 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | |
| 2969 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2970 | Register function = ToRegister(instr->function()); |
| 2971 | Register result = ToRegister(instr->result()); |
| 2972 | |
| 2973 | // Check that the function really is a function. |
| 2974 | __ CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 2975 | DeoptimizeIf(not_equal, instr->environment()); |
| 2976 | |
| 2977 | // Check whether the function has an instance prototype. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2978 | Label non_instance; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2979 | __ testb(FieldOperand(result, Map::kBitFieldOffset), |
| 2980 | Immediate(1 << Map::kHasNonInstancePrototype)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2981 | __ j(not_zero, &non_instance, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2982 | |
| 2983 | // Get the prototype or initial map from the function. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2984 | __ movp(result, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2985 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2986 | |
| 2987 | // Check that the function has a prototype or an initial map. |
| 2988 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 2989 | DeoptimizeIf(equal, instr->environment()); |
| 2990 | |
| 2991 | // 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] | 2992 | Label done; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2993 | __ CmpObjectType(result, MAP_TYPE, kScratchRegister); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2994 | __ j(not_equal, &done, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2995 | |
| 2996 | // Get the prototype from the initial map. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2997 | __ movp(result, FieldOperand(result, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2998 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2999 | |
| 3000 | // Non-instance prototype: Fetch prototype from constructor field |
| 3001 | // in the function's map. |
| 3002 | __ bind(&non_instance); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3003 | __ movp(result, FieldOperand(result, Map::kConstructorOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3004 | |
| 3005 | // All done. |
| 3006 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3010 | void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 3011 | Register result = ToRegister(instr->result()); |
| 3012 | __ LoadRoot(result, instr->index()); |
| 3013 | } |
| 3014 | |
| 3015 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3016 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3017 | Register arguments = ToRegister(instr->arguments()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3018 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3019 | |
| 3020 | if (instr->length()->IsConstantOperand() && |
| 3021 | instr->index()->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3022 | int32_t const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3023 | int32_t const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
machenbach@chromium.org | 9b95fd7 | 2014-03-26 01:04:35 +0000 | [diff] [blame] | 3024 | if (const_index >= 0 && const_index < const_length) { |
| 3025 | StackArgumentsAccessor args(arguments, const_length, |
| 3026 | ARGUMENTS_DONT_CONTAIN_RECEIVER); |
| 3027 | __ movp(result, args.GetArgumentOperand(const_index)); |
| 3028 | } else if (FLAG_debug_code) { |
| 3029 | __ int3(); |
| 3030 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3031 | } else { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3032 | Register length = ToRegister(instr->length()); |
| 3033 | // There are two words between the frame pointer and the last argument. |
| 3034 | // Subtracting from length accounts for one of them add one more. |
| 3035 | if (instr->index()->IsRegister()) { |
| 3036 | __ subl(length, ToRegister(instr->index())); |
| 3037 | } else { |
| 3038 | __ subl(length, ToOperand(instr->index())); |
| 3039 | } |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3040 | StackArgumentsAccessor args(arguments, length, |
| 3041 | ARGUMENTS_DONT_CONTAIN_RECEIVER); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3042 | __ movp(result, args.GetArgumentOperand(0)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3043 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 3047 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 3048 | ElementsKind elements_kind = instr->elements_kind(); |
| 3049 | LOperand* key = instr->key(); |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3050 | int base_offset = instr->is_fixed_typed_array() |
| 3051 | ? FixedTypedArrayBase::kDataOffset - kHeapObjectTag |
| 3052 | : 0; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3053 | Operand operand(BuildFastArrayOperand( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3054 | instr->elements(), |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3055 | key, |
| 3056 | elements_kind, |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3057 | base_offset, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3058 | instr->additional_index())); |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 3059 | |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3060 | if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3061 | elements_kind == FLOAT32_ELEMENTS) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3062 | XMMRegister result(ToDoubleRegister(instr->result())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3063 | __ movss(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3064 | __ cvtss2sd(result, result); |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3065 | } else if (elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3066 | elements_kind == FLOAT64_ELEMENTS) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3067 | __ movsd(ToDoubleRegister(instr->result()), operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3068 | } else { |
| 3069 | Register result(ToRegister(instr->result())); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3070 | switch (elements_kind) { |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3071 | case EXTERNAL_INT8_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3072 | case INT8_ELEMENTS: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 3073 | __ movsxbl(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3074 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3075 | case EXTERNAL_UINT8_ELEMENTS: |
| 3076 | case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3077 | case UINT8_ELEMENTS: |
| 3078 | case UINT8_CLAMPED_ELEMENTS: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 3079 | __ movzxbl(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3080 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3081 | case EXTERNAL_INT16_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3082 | case INT16_ELEMENTS: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 3083 | __ movsxwl(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3084 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3085 | case EXTERNAL_UINT16_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3086 | case UINT16_ELEMENTS: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 3087 | __ movzxwl(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3088 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3089 | case EXTERNAL_INT32_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3090 | case INT32_ELEMENTS: |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 3091 | __ movl(result, operand); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3092 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3093 | case EXTERNAL_UINT32_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3094 | case UINT32_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3095 | __ movl(result, operand); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3096 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3097 | __ testl(result, result); |
| 3098 | DeoptimizeIf(negative, instr->environment()); |
| 3099 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3100 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3101 | case EXTERNAL_FLOAT32_ELEMENTS: |
| 3102 | case EXTERNAL_FLOAT64_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3103 | case FLOAT32_ELEMENTS: |
| 3104 | case FLOAT64_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3105 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3106 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3107 | case FAST_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3108 | case FAST_HOLEY_ELEMENTS: |
| 3109 | case FAST_HOLEY_SMI_ELEMENTS: |
| 3110 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3111 | case DICTIONARY_ELEMENTS: |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 3112 | case SLOPPY_ARGUMENTS_ELEMENTS: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3113 | UNREACHABLE(); |
| 3114 | break; |
| 3115 | } |
| 3116 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3120 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 3121 | XMMRegister result(ToDoubleRegister(instr->result())); |
| 3122 | LOperand* key = instr->key(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3123 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3124 | int offset = FixedDoubleArray::kHeaderSize - kHeapObjectTag + |
| 3125 | sizeof(kHoleNanLower32); |
| 3126 | Operand hole_check_operand = BuildFastArrayOperand( |
| 3127 | instr->elements(), |
| 3128 | key, |
| 3129 | FAST_DOUBLE_ELEMENTS, |
| 3130 | offset, |
| 3131 | instr->additional_index()); |
| 3132 | __ cmpl(hole_check_operand, Immediate(kHoleNanUpper32)); |
| 3133 | DeoptimizeIf(equal, instr->environment()); |
| 3134 | } |
| 3135 | |
| 3136 | Operand double_load_operand = BuildFastArrayOperand( |
| 3137 | instr->elements(), |
| 3138 | key, |
| 3139 | FAST_DOUBLE_ELEMENTS, |
| 3140 | FixedDoubleArray::kHeaderSize - kHeapObjectTag, |
| 3141 | instr->additional_index()); |
| 3142 | __ movsd(result, double_load_operand); |
| 3143 | } |
| 3144 | |
| 3145 | |
| 3146 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3147 | HLoadKeyed* hinstr = instr->hydrogen(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3148 | Register result = ToRegister(instr->result()); |
| 3149 | LOperand* key = instr->key(); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3150 | bool requires_hole_check = hinstr->RequiresHoleCheck(); |
| 3151 | int offset = FixedArray::kHeaderSize - kHeapObjectTag; |
| 3152 | Representation representation = hinstr->representation(); |
| 3153 | |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 3154 | if (representation.IsInteger32() && SmiValuesAre32Bits() && |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3155 | hinstr->elements_kind() == FAST_SMI_ELEMENTS) { |
| 3156 | ASSERT(!requires_hole_check); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 3157 | if (FLAG_debug_code) { |
| 3158 | Register scratch = kScratchRegister; |
| 3159 | __ Load(scratch, |
| 3160 | BuildFastArrayOperand(instr->elements(), |
| 3161 | key, |
| 3162 | FAST_ELEMENTS, |
| 3163 | offset, |
| 3164 | instr->additional_index()), |
| 3165 | Representation::Smi()); |
| 3166 | __ AssertSmi(scratch); |
| 3167 | } |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3168 | // Read int value directly from upper half of the smi. |
| 3169 | STATIC_ASSERT(kSmiTag == 0); |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 3170 | ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3171 | offset += kPointerSize / 2; |
| 3172 | } |
| 3173 | |
| 3174 | __ Load(result, |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3175 | BuildFastArrayOperand(instr->elements(), |
| 3176 | key, |
| 3177 | FAST_ELEMENTS, |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3178 | offset, |
| 3179 | instr->additional_index()), |
| 3180 | representation); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3181 | |
| 3182 | // Check for the hole value. |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 3183 | if (requires_hole_check) { |
| 3184 | if (IsFastSmiElementsKind(hinstr->elements_kind())) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3185 | Condition smi = __ CheckSmi(result); |
| 3186 | DeoptimizeIf(NegateCondition(smi), instr->environment()); |
| 3187 | } else { |
| 3188 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 3189 | DeoptimizeIf(equal, instr->environment()); |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | |
| 3195 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3196 | if (instr->is_typed_elements()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3197 | DoLoadKeyedExternalArray(instr); |
| 3198 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3199 | DoLoadKeyedFixedDoubleArray(instr); |
| 3200 | } else { |
| 3201 | DoLoadKeyedFixedArray(instr); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | |
| 3206 | Operand LCodeGen::BuildFastArrayOperand( |
| 3207 | LOperand* elements_pointer, |
| 3208 | LOperand* key, |
| 3209 | ElementsKind elements_kind, |
| 3210 | uint32_t offset, |
| 3211 | uint32_t additional_index) { |
| 3212 | Register elements_pointer_reg = ToRegister(elements_pointer); |
| 3213 | int shift_size = ElementsKindToShiftSize(elements_kind); |
| 3214 | if (key->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3215 | int32_t constant_value = ToInteger32(LConstantOperand::cast(key)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3216 | if (constant_value & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3217 | Abort(kArrayIndexConstantValueTooBig); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3218 | } |
| 3219 | return Operand(elements_pointer_reg, |
| 3220 | ((constant_value + additional_index) << shift_size) |
| 3221 | + offset); |
| 3222 | } else { |
| 3223 | ScaleFactor scale_factor = static_cast<ScaleFactor>(shift_size); |
| 3224 | return Operand(elements_pointer_reg, |
| 3225 | ToRegister(key), |
| 3226 | scale_factor, |
| 3227 | offset + (additional_index << shift_size)); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3232 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3233 | ASSERT(ToRegister(instr->context()).is(rsi)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3234 | ASSERT(ToRegister(instr->object()).is(rdx)); |
| 3235 | ASSERT(ToRegister(instr->key()).is(rax)); |
| 3236 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3237 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3238 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | |
| 3242 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3243 | Register result = ToRegister(instr->result()); |
| 3244 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3245 | if (instr->hydrogen()->from_inlined()) { |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3246 | __ leap(result, Operand(rsp, -kFPOnStackSize + -kPCOnStackSize)); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3247 | } else { |
| 3248 | // Check for arguments adapter frame. |
| 3249 | Label done, adapted; |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3250 | __ movp(result, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3251 | __ Cmp(Operand(result, StandardFrameConstants::kContextOffset), |
| 3252 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 3253 | __ j(equal, &adapted, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3254 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3255 | // No arguments adaptor frame. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3256 | __ movp(result, rbp); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3257 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3258 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3259 | // Arguments adaptor frame present. |
| 3260 | __ bind(&adapted); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3261 | __ movp(result, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3262 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3263 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3264 | // frame below the adaptor frame if adapted. |
| 3265 | __ bind(&done); |
| 3266 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | |
| 3270 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3271 | Register result = ToRegister(instr->result()); |
| 3272 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3273 | Label done; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3274 | |
| 3275 | // If no arguments adaptor frame the number of arguments is fixed. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3276 | if (instr->elements()->IsRegister()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 3277 | __ cmpp(rbp, ToRegister(instr->elements())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3278 | } else { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 3279 | __ cmpp(rbp, ToOperand(instr->elements())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3280 | } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 3281 | __ movl(result, Immediate(scope()->num_parameters())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3282 | __ j(equal, &done, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3283 | |
| 3284 | // Arguments adaptor frame present. Get argument length from there. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3285 | __ movp(result, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 3286 | __ SmiToInteger32(result, |
| 3287 | Operand(result, |
| 3288 | ArgumentsAdaptorFrameConstants::kLengthOffset)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3289 | |
| 3290 | // Argument length is in result register. |
| 3291 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3295 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3296 | Register receiver = ToRegister(instr->receiver()); |
| 3297 | Register function = ToRegister(instr->function()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3298 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3299 | // If the receiver is null or undefined, we have to pass the global |
| 3300 | // object as a receiver to normal functions. Values have to be |
| 3301 | // passed unchanged to builtins and strict-mode functions. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3302 | Label global_object, receiver_ok; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3303 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3304 | |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3305 | if (!instr->hydrogen()->known_function()) { |
| 3306 | // Do not transform the receiver to object for strict mode |
| 3307 | // functions. |
| 3308 | __ movp(kScratchRegister, |
| 3309 | FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3310 | __ testb(FieldOperand(kScratchRegister, |
| 3311 | SharedFunctionInfo::kStrictModeByteOffset), |
| 3312 | Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
| 3313 | __ j(not_equal, &receiver_ok, dist); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3314 | |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3315 | // Do not transform the receiver to object for builtins. |
| 3316 | __ testb(FieldOperand(kScratchRegister, |
| 3317 | SharedFunctionInfo::kNativeByteOffset), |
| 3318 | Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
| 3319 | __ j(not_equal, &receiver_ok, dist); |
| 3320 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3321 | |
| 3322 | // Normal function. Replace undefined or null with global receiver. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3323 | __ CompareRoot(receiver, Heap::kNullValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3324 | __ j(equal, &global_object, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3325 | __ CompareRoot(receiver, Heap::kUndefinedValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3326 | __ j(equal, &global_object, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3327 | |
| 3328 | // The receiver should be a JS object. |
| 3329 | Condition is_smi = __ CheckSmi(receiver); |
| 3330 | DeoptimizeIf(is_smi, instr->environment()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3331 | __ CmpObjectType(receiver, FIRST_SPEC_OBJECT_TYPE, kScratchRegister); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3332 | DeoptimizeIf(below, instr->environment()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3333 | |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3334 | __ jmp(&receiver_ok, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3335 | __ bind(&global_object); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3336 | __ movp(receiver, FieldOperand(function, JSFunction::kContextOffset)); |
| 3337 | __ movp(receiver, |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3338 | Operand(receiver, |
| 3339 | Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3340 | __ movp(receiver, |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3341 | FieldOperand(receiver, GlobalObject::kGlobalReceiverOffset)); |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3342 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3343 | __ bind(&receiver_ok); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | |
| 3347 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3348 | Register receiver = ToRegister(instr->receiver()); |
| 3349 | Register function = ToRegister(instr->function()); |
| 3350 | Register length = ToRegister(instr->length()); |
| 3351 | Register elements = ToRegister(instr->elements()); |
| 3352 | ASSERT(receiver.is(rax)); // Used for parameter count. |
| 3353 | ASSERT(function.is(rdi)); // Required by InvokeFunction. |
| 3354 | ASSERT(ToRegister(instr->result()).is(rax)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3355 | |
| 3356 | // Copy the arguments to this function possibly from the |
| 3357 | // adaptor frame below it. |
| 3358 | const uint32_t kArgumentsLimit = 1 * KB; |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 3359 | __ cmpp(length, Immediate(kArgumentsLimit)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3360 | DeoptimizeIf(above, instr->environment()); |
| 3361 | |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 3362 | __ Push(receiver); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3363 | __ movp(receiver, length); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3364 | |
| 3365 | // Loop through the arguments pushing them onto the execution |
| 3366 | // stack. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3367 | Label invoke, loop; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3368 | // length is a small non-negative integer, due to the test above. |
| 3369 | __ testl(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3370 | __ j(zero, &invoke, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3371 | __ bind(&loop); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3372 | StackArgumentsAccessor args(elements, length, |
| 3373 | ARGUMENTS_DONT_CONTAIN_RECEIVER); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 3374 | __ Push(args.GetArgumentOperand(0)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3375 | __ decl(length); |
| 3376 | __ j(not_zero, &loop); |
| 3377 | |
| 3378 | // Invoke the function. |
| 3379 | __ bind(&invoke); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3380 | ASSERT(instr->HasPointerMap()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3381 | LPointerMap* pointers = instr->pointer_map(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3382 | SafepointGenerator safepoint_generator( |
| 3383 | this, pointers, Safepoint::kLazyDeopt); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3384 | ParameterCount actual(rax); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3385 | __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | |
| 3389 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3390 | LOperand* argument = instr->value(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3391 | EmitPushTaggedOperand(argument); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3395 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3396 | __ Drop(instr->count()); |
| 3397 | } |
| 3398 | |
| 3399 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3400 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3401 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3402 | __ movp(result, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3406 | void LCodeGen::DoContext(LContext* instr) { |
| 3407 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3408 | if (info()->IsOptimizing()) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3409 | __ movp(result, Operand(rbp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3410 | } else { |
| 3411 | // If there is no frame, the context must be in rsi. |
| 3412 | ASSERT(result.is(rsi)); |
| 3413 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3417 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3418 | ASSERT(ToRegister(instr->context()).is(rsi)); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 3419 | __ Push(rsi); // The context is the first argument. |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 3420 | __ Push(instr->hydrogen()->pairs()); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3421 | __ Push(Smi::FromInt(instr->hydrogen()->flags())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3422 | CallRuntime(Runtime::kHiddenDeclareGlobals, 3, instr); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3423 | } |
| 3424 | |
| 3425 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3426 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3427 | int formal_parameter_count, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3428 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3429 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3430 | RDIState rdi_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3431 | bool dont_adapt_arguments = |
| 3432 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3433 | bool can_invoke_directly = |
| 3434 | dont_adapt_arguments || formal_parameter_count == arity; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3435 | |
| 3436 | LPointerMap* pointers = instr->pointer_map(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3437 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3438 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3439 | if (rdi_state == RDI_UNINITIALIZED) { |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 3440 | __ Move(rdi, function); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3441 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3442 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3443 | // Change context. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3444 | __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3445 | |
| 3446 | // Set rax to arguments count if adaption is not needed. Assumes that rax |
| 3447 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3448 | if (dont_adapt_arguments) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3449 | __ Set(rax, arity); |
| 3450 | } |
| 3451 | |
| 3452 | // Invoke function. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3453 | if (function.is_identical_to(info()->closure())) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3454 | __ CallSelf(); |
| 3455 | } else { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 3456 | __ Call(FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | // Set up deoptimization. |
| 3460 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT, 0); |
| 3461 | } else { |
| 3462 | // We need to adapt arguments. |
| 3463 | SafepointGenerator generator( |
| 3464 | this, pointers, Safepoint::kLazyDeopt); |
| 3465 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3466 | ParameterCount expected(formal_parameter_count); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3467 | __ InvokeFunction(function, expected, count, CALL_FUNCTION, generator); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3468 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3472 | void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3473 | ASSERT(ToRegister(instr->result()).is(rax)); |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3474 | |
| 3475 | LPointerMap* pointers = instr->pointer_map(); |
| 3476 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3477 | |
| 3478 | if (instr->target()->IsConstantOperand()) { |
| 3479 | LConstantOperand* target = LConstantOperand::cast(instr->target()); |
| 3480 | Handle<Code> code = Handle<Code>::cast(ToHandle(target)); |
| 3481 | generator.BeforeCall(__ CallSize(code)); |
| 3482 | __ call(code, RelocInfo::CODE_TARGET); |
| 3483 | } else { |
| 3484 | ASSERT(instr->target()->IsRegister()); |
| 3485 | Register target = ToRegister(instr->target()); |
| 3486 | generator.BeforeCall(__ CallSize(target)); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 3487 | __ addp(target, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3488 | __ call(target); |
| 3489 | } |
| 3490 | generator.AfterCall(); |
| 3491 | } |
| 3492 | |
| 3493 | |
| 3494 | void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { |
| 3495 | ASSERT(ToRegister(instr->function()).is(rdi)); |
| 3496 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 3497 | |
| 3498 | if (instr->hydrogen()->pass_argument_count()) { |
| 3499 | __ Set(rax, instr->arity()); |
| 3500 | } |
| 3501 | |
| 3502 | // Change context. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3503 | __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3504 | |
| 3505 | LPointerMap* pointers = instr->pointer_map(); |
| 3506 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3507 | |
| 3508 | bool is_self_call = false; |
| 3509 | if (instr->hydrogen()->function()->IsConstant()) { |
| 3510 | Handle<JSFunction> jsfun = Handle<JSFunction>::null(); |
| 3511 | HConstant* fun_const = HConstant::cast(instr->hydrogen()->function()); |
| 3512 | jsfun = Handle<JSFunction>::cast(fun_const->handle(isolate())); |
| 3513 | is_self_call = jsfun.is_identical_to(info()->closure()); |
| 3514 | } |
| 3515 | |
| 3516 | if (is_self_call) { |
| 3517 | __ CallSelf(); |
| 3518 | } else { |
| 3519 | Operand target = FieldOperand(rdi, JSFunction::kCodeEntryOffset); |
| 3520 | generator.BeforeCall(__ CallSize(target)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 3521 | __ Call(target); |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3522 | } |
| 3523 | generator.AfterCall(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3527 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3528 | Register input_reg = ToRegister(instr->value()); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3529 | __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 3530 | Heap::kHeapNumberMapRootIndex); |
| 3531 | DeoptimizeIf(not_equal, instr->environment()); |
| 3532 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3533 | Label slow, allocated, done; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3534 | Register tmp = input_reg.is(rax) ? rcx : rax; |
| 3535 | Register tmp2 = tmp.is(rcx) ? rdx : input_reg.is(rcx) ? rdx : rcx; |
| 3536 | |
| 3537 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3538 | PushSafepointRegistersScope scope(this); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3539 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3540 | __ movl(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 3541 | // Check the sign of the argument. If the argument is positive, just |
| 3542 | // return it. We do not need to patch the stack since |input| and |
| 3543 | // |result| are the same register and |input| will be restored |
| 3544 | // unchanged by popping safepoint registers. |
| 3545 | __ testl(tmp, Immediate(HeapNumber::kSignMask)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3546 | __ j(zero, &done); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3547 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3548 | __ AllocateHeapNumber(tmp, tmp2, &slow); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3549 | __ jmp(&allocated, Label::kNear); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3550 | |
| 3551 | // Slow case: Call the runtime system to do the number allocation. |
| 3552 | __ bind(&slow); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3553 | CallRuntimeFromDeferred( |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3554 | Runtime::kHiddenAllocateHeapNumber, 0, instr, instr->context()); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3555 | // Set the pointer to the new heap number in tmp. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3556 | if (!tmp.is(rax)) __ movp(tmp, rax); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3557 | // Restore input_reg after call to runtime. |
| 3558 | __ LoadFromSafepointRegisterSlot(input_reg, input_reg); |
| 3559 | |
| 3560 | __ bind(&allocated); |
machenbach@chromium.org | bb8234d | 2014-02-10 09:01:23 +0000 | [diff] [blame] | 3561 | __ movq(tmp2, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 3562 | __ shlq(tmp2, Immediate(1)); |
| 3563 | __ shrq(tmp2, Immediate(1)); |
machenbach@chromium.org | bb8234d | 2014-02-10 09:01:23 +0000 | [diff] [blame] | 3564 | __ movq(FieldOperand(tmp, HeapNumber::kValueOffset), tmp2); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3565 | __ StoreToSafepointRegisterSlot(input_reg, tmp); |
| 3566 | |
| 3567 | __ bind(&done); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3571 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3572 | Register input_reg = ToRegister(instr->value()); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3573 | __ testl(input_reg, input_reg); |
| 3574 | Label is_positive; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3575 | __ j(not_sign, &is_positive, Label::kNear); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3576 | __ negl(input_reg); // Sets flags. |
| 3577 | DeoptimizeIf(negative, instr->environment()); |
| 3578 | __ bind(&is_positive); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3582 | void LCodeGen::EmitSmiMathAbs(LMathAbs* instr) { |
| 3583 | Register input_reg = ToRegister(instr->value()); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 3584 | __ testp(input_reg, input_reg); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3585 | Label is_positive; |
| 3586 | __ j(not_sign, &is_positive, Label::kNear); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 3587 | __ negp(input_reg); // Sets flags. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3588 | DeoptimizeIf(negative, instr->environment()); |
| 3589 | __ bind(&is_positive); |
| 3590 | } |
| 3591 | |
| 3592 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3593 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3594 | // Class for deferred case. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3595 | class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3596 | public: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3597 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3598 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3599 | virtual void Generate() V8_OVERRIDE { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3600 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3601 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3602 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3603 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3604 | LMathAbs* instr_; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3605 | }; |
| 3606 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3607 | ASSERT(instr->value()->Equals(instr->result())); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3608 | Representation r = instr->hydrogen()->value()->representation(); |
| 3609 | |
| 3610 | if (r.IsDouble()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3611 | XMMRegister scratch = double_scratch0(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3612 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3613 | __ xorps(scratch, scratch); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3614 | __ subsd(scratch, input_reg); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 3615 | __ andps(input_reg, scratch); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3616 | } else if (r.IsInteger32()) { |
| 3617 | EmitIntegerMathAbs(instr); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3618 | } else if (r.IsSmi()) { |
| 3619 | EmitSmiMathAbs(instr); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3620 | } else { // Tagged case. |
| 3621 | DeferredMathAbsTaggedHeapNumber* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3622 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3623 | Register input_reg = ToRegister(instr->value()); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3624 | // Smi check. |
| 3625 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3626 | EmitSmiMathAbs(instr); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3627 | __ bind(deferred->exit()); |
| 3628 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3632 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3633 | XMMRegister xmm_scratch = double_scratch0(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3634 | Register output_reg = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3635 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3636 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3637 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3638 | CpuFeatureScope scope(masm(), SSE4_1); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3639 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3640 | // Deoptimize if minus zero. |
| 3641 | __ movq(output_reg, input_reg); |
| 3642 | __ subq(output_reg, Immediate(1)); |
| 3643 | DeoptimizeIf(overflow, instr->environment()); |
| 3644 | } |
| 3645 | __ roundsd(xmm_scratch, input_reg, Assembler::kRoundDown); |
| 3646 | __ cvttsd2si(output_reg, xmm_scratch); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3647 | __ cmpl(output_reg, Immediate(0x1)); |
| 3648 | DeoptimizeIf(overflow, instr->environment()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3649 | } else { |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3650 | Label negative_sign, done; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3651 | // Deoptimize on unordered. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3652 | __ xorps(xmm_scratch, xmm_scratch); // Zero the register. |
| 3653 | __ ucomisd(input_reg, xmm_scratch); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3654 | DeoptimizeIf(parity_even, instr->environment()); |
| 3655 | __ j(below, &negative_sign, Label::kNear); |
| 3656 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3657 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3658 | // Check for negative zero. |
| 3659 | Label positive_sign; |
| 3660 | __ j(above, &positive_sign, Label::kNear); |
| 3661 | __ movmskpd(output_reg, input_reg); |
| 3662 | __ testq(output_reg, Immediate(1)); |
| 3663 | DeoptimizeIf(not_zero, instr->environment()); |
| 3664 | __ Set(output_reg, 0); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3665 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3666 | __ bind(&positive_sign); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | // Use truncating instruction (OK because input is positive). |
| 3670 | __ cvttsd2si(output_reg, input_reg); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3671 | // Overflow is signalled with minint. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3672 | __ cmpl(output_reg, Immediate(0x1)); |
| 3673 | DeoptimizeIf(overflow, instr->environment()); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3674 | __ jmp(&done, Label::kNear); |
| 3675 | |
| 3676 | // Non-zero negative reaches here. |
| 3677 | __ bind(&negative_sign); |
| 3678 | // Truncate, then compare and compensate. |
| 3679 | __ cvttsd2si(output_reg, input_reg); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3680 | __ Cvtlsi2sd(xmm_scratch, output_reg); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3681 | __ ucomisd(input_reg, xmm_scratch); |
| 3682 | __ j(equal, &done, Label::kNear); |
| 3683 | __ subl(output_reg, Immediate(1)); |
| 3684 | DeoptimizeIf(overflow, instr->environment()); |
| 3685 | |
| 3686 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3687 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3691 | void LCodeGen::DoMathRound(LMathRound* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3692 | const XMMRegister xmm_scratch = double_scratch0(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3693 | Register output_reg = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3694 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 3695 | XMMRegister input_temp = ToDoubleRegister(instr->temp()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3696 | static int64_t one_half = V8_INT64_C(0x3FE0000000000000); // 0.5 |
| 3697 | static int64_t minus_one_half = V8_INT64_C(0xBFE0000000000000); // -0.5 |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3698 | |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 3699 | Label done, round_to_zero, below_one_half; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3700 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 3701 | __ movq(kScratchRegister, one_half); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3702 | __ movq(xmm_scratch, kScratchRegister); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3703 | __ ucomisd(xmm_scratch, input_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3704 | __ j(above, &below_one_half, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3705 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3706 | // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x). |
| 3707 | __ addsd(xmm_scratch, input_reg); |
| 3708 | __ cvttsd2si(output_reg, xmm_scratch); |
| 3709 | // Overflow is signalled with minint. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3710 | __ cmpl(output_reg, Immediate(0x1)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3711 | __ RecordComment("D2I conversion overflow"); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3712 | DeoptimizeIf(overflow, instr->environment()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3713 | __ jmp(&done, dist); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3714 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3715 | __ bind(&below_one_half); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 3716 | __ movq(kScratchRegister, minus_one_half); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3717 | __ movq(xmm_scratch, kScratchRegister); |
| 3718 | __ ucomisd(xmm_scratch, input_reg); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3719 | __ j(below_equal, &round_to_zero, Label::kNear); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3720 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3721 | // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then |
| 3722 | // compare and compensate. |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 3723 | __ movq(input_temp, input_reg); // Do not alter input_reg. |
| 3724 | __ subsd(input_temp, xmm_scratch); |
| 3725 | __ cvttsd2si(output_reg, input_temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3726 | // Catch minint due to overflow, and to prevent overflow when compensating. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3727 | __ cmpl(output_reg, Immediate(0x1)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3728 | __ RecordComment("D2I conversion overflow"); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3729 | DeoptimizeIf(overflow, instr->environment()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3730 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3731 | __ Cvtlsi2sd(xmm_scratch, output_reg); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 3732 | __ ucomisd(xmm_scratch, input_temp); |
| 3733 | __ j(equal, &done, dist); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3734 | __ subl(output_reg, Immediate(1)); |
| 3735 | // No overflow because we already ruled out minint. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3736 | __ jmp(&done, dist); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3737 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3738 | __ bind(&round_to_zero); |
| 3739 | // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if |
| 3740 | // we can ignore the difference between a result of -0 and +0. |
| 3741 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3742 | __ movq(output_reg, input_reg); |
| 3743 | __ testq(output_reg, output_reg); |
| 3744 | __ RecordComment("Minus zero"); |
| 3745 | DeoptimizeIf(negative, instr->environment()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3746 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3747 | __ Set(output_reg, 0); |
| 3748 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3752 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3753 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3754 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
| 3755 | __ sqrtsd(input_reg, input_reg); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3759 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3760 | XMMRegister xmm_scratch = double_scratch0(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3761 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3762 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3763 | |
| 3764 | // Note that according to ECMA-262 15.8.2.13: |
| 3765 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3766 | // Math.sqrt(-Infinity) == NaN |
| 3767 | Label done, sqrt; |
| 3768 | // Check base for -Infinity. According to IEEE-754, double-precision |
| 3769 | // -Infinity has the highest 12 bits set and the lowest 52 bits cleared. |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 3770 | __ movq(kScratchRegister, V8_INT64_C(0xFFF0000000000000)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3771 | __ movq(xmm_scratch, kScratchRegister); |
| 3772 | __ ucomisd(xmm_scratch, input_reg); |
| 3773 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3774 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3775 | __ j(not_equal, &sqrt, Label::kNear); |
| 3776 | __ j(carry, &sqrt, Label::kNear); |
| 3777 | // If input is -Infinity, return Infinity. |
| 3778 | __ xorps(input_reg, input_reg); |
| 3779 | __ subsd(input_reg, xmm_scratch); |
| 3780 | __ jmp(&done, Label::kNear); |
| 3781 | |
| 3782 | // Square root. |
| 3783 | __ bind(&sqrt); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3784 | __ xorps(xmm_scratch, xmm_scratch); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3785 | __ addsd(input_reg, xmm_scratch); // Convert -0 to +0. |
| 3786 | __ sqrtsd(input_reg, input_reg); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3787 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | |
| 3791 | void LCodeGen::DoPower(LPower* instr) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3792 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3793 | // Having marked this as a call, we can use any registers. |
| 3794 | // Just make sure that the input/output registers are the expected ones. |
| 3795 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3796 | Register exponent = rdx; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3797 | ASSERT(!instr->right()->IsRegister() || |
| 3798 | ToRegister(instr->right()).is(exponent)); |
| 3799 | ASSERT(!instr->right()->IsDoubleRegister() || |
| 3800 | ToDoubleRegister(instr->right()).is(xmm1)); |
| 3801 | ASSERT(ToDoubleRegister(instr->left()).is(xmm2)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3802 | ASSERT(ToDoubleRegister(instr->result()).is(xmm3)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3803 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3804 | if (exponent_type.IsSmi()) { |
| 3805 | MathPowStub stub(MathPowStub::TAGGED); |
| 3806 | __ CallStub(&stub); |
| 3807 | } else if (exponent_type.IsTagged()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3808 | Label no_deopt; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3809 | __ JumpIfSmi(exponent, &no_deopt, Label::kNear); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3810 | __ CmpObjectType(exponent, HEAP_NUMBER_TYPE, rcx); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3811 | DeoptimizeIf(not_equal, instr->environment()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3812 | __ bind(&no_deopt); |
| 3813 | MathPowStub stub(MathPowStub::TAGGED); |
| 3814 | __ CallStub(&stub); |
| 3815 | } else if (exponent_type.IsInteger32()) { |
| 3816 | MathPowStub stub(MathPowStub::INTEGER); |
| 3817 | __ CallStub(&stub); |
| 3818 | } else { |
| 3819 | ASSERT(exponent_type.IsDouble()); |
| 3820 | MathPowStub stub(MathPowStub::DOUBLE); |
| 3821 | __ CallStub(&stub); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3822 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3826 | void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3827 | XMMRegister input = ToDoubleRegister(instr->value()); |
| 3828 | XMMRegister result = ToDoubleRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3829 | XMMRegister temp0 = double_scratch0(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3830 | Register temp1 = ToRegister(instr->temp1()); |
| 3831 | Register temp2 = ToRegister(instr->temp2()); |
| 3832 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3833 | MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3837 | void LCodeGen::DoMathLog(LMathLog* instr) { |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3838 | ASSERT(instr->value()->Equals(instr->result())); |
| 3839 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
| 3840 | XMMRegister xmm_scratch = double_scratch0(); |
| 3841 | Label positive, done, zero; |
| 3842 | __ xorps(xmm_scratch, xmm_scratch); |
| 3843 | __ ucomisd(input_reg, xmm_scratch); |
| 3844 | __ j(above, &positive, Label::kNear); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3845 | __ j(not_carry, &zero, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3846 | ExternalReference nan = |
| 3847 | ExternalReference::address_of_canonical_non_hole_nan(); |
| 3848 | Operand nan_operand = masm()->ExternalOperand(nan); |
| 3849 | __ movsd(input_reg, nan_operand); |
| 3850 | __ jmp(&done, Label::kNear); |
| 3851 | __ bind(&zero); |
| 3852 | ExternalReference ninf = |
| 3853 | ExternalReference::address_of_negative_infinity(); |
| 3854 | Operand ninf_operand = masm()->ExternalOperand(ninf); |
| 3855 | __ movsd(input_reg, ninf_operand); |
| 3856 | __ jmp(&done, Label::kNear); |
| 3857 | __ bind(&positive); |
| 3858 | __ fldln2(); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 3859 | __ subp(rsp, Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3860 | __ movsd(Operand(rsp, 0), input_reg); |
| 3861 | __ fld_d(Operand(rsp, 0)); |
| 3862 | __ fyl2x(); |
| 3863 | __ fstp_d(Operand(rsp, 0)); |
| 3864 | __ movsd(input_reg, Operand(rsp, 0)); |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 3865 | __ addp(rsp, Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3866 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 3870 | void LCodeGen::DoMathClz32(LMathClz32* instr) { |
| 3871 | Register input = ToRegister(instr->value()); |
| 3872 | Register result = ToRegister(instr->result()); |
| 3873 | Label not_zero_input; |
| 3874 | __ bsrl(result, input); |
| 3875 | |
| 3876 | __ j(not_zero, ¬_zero_input); |
| 3877 | __ Set(result, 63); // 63^31 == 32 |
| 3878 | |
| 3879 | __ bind(¬_zero_input); |
| 3880 | __ xorl(result, Immediate(31)); // for x in [0..31], 31^x == 31-x. |
| 3881 | } |
| 3882 | |
| 3883 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3884 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3885 | ASSERT(ToRegister(instr->context()).is(rsi)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3886 | ASSERT(ToRegister(instr->function()).is(rdi)); |
| 3887 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3888 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3889 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 3890 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3891 | LPointerMap* pointers = instr->pointer_map(); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3892 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3893 | ParameterCount count(instr->arity()); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3894 | __ InvokeFunction(rdi, count, CALL_FUNCTION, generator); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3895 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3896 | CallKnownFunction(known_function, |
| 3897 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3898 | instr->arity(), |
| 3899 | instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3900 | RDI_CONTAINS_TARGET); |
| 3901 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3905 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3906 | ASSERT(ToRegister(instr->context()).is(rsi)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3907 | ASSERT(ToRegister(instr->function()).is(rdi)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3908 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 3909 | |
| 3910 | int arity = instr->arity(); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 3911 | CallFunctionStub stub(arity, instr->hydrogen()->function_flags()); |
| 3912 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3916 | void LCodeGen::DoCallNew(LCallNew* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3917 | ASSERT(ToRegister(instr->context()).is(rsi)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3918 | ASSERT(ToRegister(instr->constructor()).is(rdi)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3919 | ASSERT(ToRegister(instr->result()).is(rax)); |
| 3920 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3921 | __ Set(rax, instr->arity()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3922 | // No cell in ebx for construct type feedback in optimized code |
machenbach@chromium.org | 5697144 | 2014-03-19 13:13:40 +0000 | [diff] [blame] | 3923 | __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3924 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3925 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3929 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3930 | ASSERT(ToRegister(instr->context()).is(rsi)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3931 | ASSERT(ToRegister(instr->constructor()).is(rdi)); |
| 3932 | ASSERT(ToRegister(instr->result()).is(rax)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3933 | |
| 3934 | __ Set(rax, instr->arity()); |
machenbach@chromium.org | 5697144 | 2014-03-19 13:13:40 +0000 | [diff] [blame] | 3935 | __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3936 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3937 | AllocationSiteOverrideMode override_mode = |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3938 | (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3939 | ? DISABLE_ALLOCATION_SITES |
| 3940 | : DONT_OVERRIDE; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3941 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3942 | if (instr->arity() == 0) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 3943 | ArrayNoArgumentConstructorStub stub(kind, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3944 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 3945 | } else if (instr->arity() == 1) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3946 | Label done; |
| 3947 | if (IsFastPackedElementsKind(kind)) { |
| 3948 | Label packed_case; |
| 3949 | // We might need a change here |
| 3950 | // look at the first argument |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3951 | __ movp(rcx, Operand(rsp, 0)); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 3952 | __ testp(rcx, rcx); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3953 | __ j(zero, &packed_case, Label::kNear); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3954 | |
| 3955 | ElementsKind holey_kind = GetHoleyElementsKind(kind); |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 3956 | ArraySingleArgumentConstructorStub stub(holey_kind, override_mode); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3957 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3958 | __ jmp(&done, Label::kNear); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3959 | __ bind(&packed_case); |
| 3960 | } |
| 3961 | |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 3962 | ArraySingleArgumentConstructorStub stub(kind, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3963 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3964 | __ bind(&done); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3965 | } else { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 3966 | ArrayNArgumentsConstructorStub stub(kind, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3967 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 3968 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3972 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3973 | ASSERT(ToRegister(instr->context()).is(rsi)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3974 | CallRuntime(instr->function(), instr->arity(), instr, instr->save_doubles()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3978 | void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 3979 | Register function = ToRegister(instr->function()); |
| 3980 | Register code_object = ToRegister(instr->code_object()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3981 | __ leap(code_object, FieldOperand(code_object, Code::kHeaderSize)); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 3982 | __ movp(FieldOperand(function, JSFunction::kCodeEntryOffset), code_object); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3986 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 3987 | Register result = ToRegister(instr->result()); |
| 3988 | Register base = ToRegister(instr->base_object()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3989 | if (instr->offset()->IsConstantOperand()) { |
| 3990 | LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3991 | __ leap(result, Operand(base, ToInteger32(offset))); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3992 | } else { |
| 3993 | Register offset = ToRegister(instr->offset()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3994 | __ leap(result, Operand(base, offset, times_1, 0)); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3995 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3999 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4000 | HStoreNamedField* hinstr = instr->hydrogen(); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4001 | Representation representation = instr->representation(); |
| 4002 | |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4003 | HObjectAccess access = hinstr->access(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4004 | int offset = access.offset(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4005 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4006 | if (access.IsExternalMemory()) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4007 | ASSERT(!hinstr->NeedsWriteBarrier()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4008 | Register value = ToRegister(instr->value()); |
| 4009 | if (instr->object()->IsConstantOperand()) { |
| 4010 | ASSERT(value.is(rax)); |
| 4011 | LConstantOperand* object = LConstantOperand::cast(instr->object()); |
| 4012 | __ store_rax(ToExternalReference(object)); |
| 4013 | } else { |
| 4014 | Register object = ToRegister(instr->object()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4015 | __ Store(MemOperand(object, offset), value, representation); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4016 | } |
| 4017 | return; |
| 4018 | } |
| 4019 | |
| 4020 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4021 | Handle<Map> transition = instr->transition(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4022 | SmiCheck check_needed = hinstr->value()->IsHeapObject() |
| 4023 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4024 | |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 4025 | ASSERT(!(representation.IsSmi() && |
| 4026 | instr->value()->IsConstantOperand() && |
| 4027 | !IsInteger32Constant(LConstantOperand::cast(instr->value())))); |
| 4028 | if (representation.IsHeapObject()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4029 | if (instr->value()->IsConstantOperand()) { |
| 4030 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 4031 | if (chunk_->LookupConstant(operand_value)->HasSmiValue()) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4032 | DeoptimizeIf(no_condition, instr->environment()); |
| 4033 | } |
| 4034 | } else { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4035 | if (!hinstr->value()->type().IsHeapObject()) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4036 | Register value = ToRegister(instr->value()); |
| 4037 | Condition cc = masm()->CheckSmi(value); |
| 4038 | DeoptimizeIf(cc, instr->environment()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4039 | |
| 4040 | // We know that value is a smi now, so we can omit the check below. |
| 4041 | check_needed = OMIT_SMI_CHECK; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4042 | } |
| 4043 | } |
machenbach@chromium.org | 09cae8d | 2014-01-30 01:05:27 +0000 | [diff] [blame] | 4044 | } else if (representation.IsDouble()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4045 | ASSERT(transition.is_null()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4046 | ASSERT(access.IsInobject()); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4047 | ASSERT(!hinstr->NeedsWriteBarrier()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4048 | XMMRegister value = ToDoubleRegister(instr->value()); |
| 4049 | __ movsd(FieldOperand(object, offset), value); |
| 4050 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4053 | if (!transition.is_null()) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4054 | if (!hinstr->NeedsWriteBarrierForMap()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4055 | __ Move(FieldOperand(object, HeapObject::kMapOffset), transition); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4056 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4057 | Register temp = ToRegister(instr->temp()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4058 | __ Move(kScratchRegister, transition); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4059 | __ movp(FieldOperand(object, HeapObject::kMapOffset), kScratchRegister); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4060 | // Update the write barrier for the map field. |
| 4061 | __ RecordWriteField(object, |
| 4062 | HeapObject::kMapOffset, |
| 4063 | kScratchRegister, |
| 4064 | temp, |
| 4065 | kSaveFPRegs, |
| 4066 | OMIT_REMEMBERED_SET, |
| 4067 | OMIT_SMI_CHECK); |
| 4068 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | // Do the store. |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4072 | Register write_register = object; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4073 | if (!access.IsInobject()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4074 | write_register = ToRegister(instr->temp()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4075 | __ movp(write_register, FieldOperand(object, JSObject::kPropertiesOffset)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4076 | } |
| 4077 | |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 4078 | if (representation.IsSmi() && SmiValuesAre32Bits() && |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4079 | hinstr->value()->representation().IsInteger32()) { |
| 4080 | ASSERT(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 4081 | if (FLAG_debug_code) { |
| 4082 | Register scratch = kScratchRegister; |
| 4083 | __ Load(scratch, FieldOperand(write_register, offset), representation); |
| 4084 | __ AssertSmi(scratch); |
| 4085 | } |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4086 | // Store int value directly to upper half of the smi. |
| 4087 | STATIC_ASSERT(kSmiTag == 0); |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 4088 | ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4089 | offset += kPointerSize / 2; |
| 4090 | representation = Representation::Integer32(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4091 | } |
| 4092 | |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4093 | Operand operand = FieldOperand(write_register, offset); |
| 4094 | |
| 4095 | if (instr->value()->IsRegister()) { |
| 4096 | Register value = ToRegister(instr->value()); |
| 4097 | __ Store(operand, value, representation); |
| 4098 | } else { |
| 4099 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
| 4100 | if (IsInteger32Constant(operand_value)) { |
| 4101 | ASSERT(!hinstr->NeedsWriteBarrier()); |
| 4102 | int32_t value = ToInteger32(operand_value); |
| 4103 | if (representation.IsSmi()) { |
| 4104 | __ Move(operand, Smi::FromInt(value)); |
| 4105 | |
| 4106 | } else { |
| 4107 | __ movl(operand, Immediate(value)); |
| 4108 | } |
| 4109 | |
| 4110 | } else { |
| 4111 | Handle<Object> handle_value = ToHandle(operand_value); |
| 4112 | ASSERT(!hinstr->NeedsWriteBarrier()); |
| 4113 | __ Move(operand, handle_value); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | if (hinstr->NeedsWriteBarrier()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4118 | Register value = ToRegister(instr->value()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4119 | Register temp = access.IsInobject() ? ToRegister(instr->temp()) : object; |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4120 | // Update the write barrier for the object for in-object properties. |
| 4121 | __ RecordWriteField(write_register, |
| 4122 | offset, |
| 4123 | value, |
| 4124 | temp, |
| 4125 | kSaveFPRegs, |
| 4126 | EMIT_REMEMBERED_SET, |
| 4127 | check_needed); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4128 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | |
| 4132 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4133 | ASSERT(ToRegister(instr->context()).is(rsi)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4134 | ASSERT(ToRegister(instr->object()).is(rdx)); |
| 4135 | ASSERT(ToRegister(instr->value()).is(rax)); |
| 4136 | |
| 4137 | __ Move(rcx, instr->hydrogen()->name()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4138 | Handle<Code> ic = StoreIC::initialize_stub(isolate(), instr->strict_mode()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4139 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4140 | } |
| 4141 | |
| 4142 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4143 | void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) { |
| 4144 | if (FLAG_debug_code && check->hydrogen()->skip_check()) { |
| 4145 | Label done; |
| 4146 | __ j(NegateCondition(cc), &done, Label::kNear); |
| 4147 | __ int3(); |
| 4148 | __ bind(&done); |
| 4149 | } else { |
| 4150 | DeoptimizeIf(cc, check->environment()); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4155 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4156 | HBoundsCheck* hinstr = instr->hydrogen(); |
| 4157 | if (hinstr->skip_check()) return; |
| 4158 | |
| 4159 | Representation representation = hinstr->length()->representation(); |
| 4160 | ASSERT(representation.Equals(hinstr->index()->representation())); |
| 4161 | ASSERT(representation.IsSmiOrInteger32()); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4162 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4163 | if (instr->length()->IsRegister()) { |
| 4164 | Register reg = ToRegister(instr->length()); |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4165 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4166 | if (instr->index()->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4167 | int32_t constant_index = |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 4168 | ToInteger32(LConstantOperand::cast(instr->index())); |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4169 | if (representation.IsSmi()) { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 4170 | __ Cmp(reg, Smi::FromInt(constant_index)); |
| 4171 | } else { |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4172 | __ cmpl(reg, Immediate(constant_index)); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 4173 | } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4174 | } else { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4175 | Register reg2 = ToRegister(instr->index()); |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4176 | if (representation.IsSmi()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 4177 | __ cmpp(reg, reg2); |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4178 | } else { |
| 4179 | __ cmpl(reg, reg2); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4180 | } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4181 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4182 | } else { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4183 | Operand length = ToOperand(instr->length()); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4184 | if (instr->index()->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4185 | int32_t constant_index = |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4186 | ToInteger32(LConstantOperand::cast(instr->index())); |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4187 | if (representation.IsSmi()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4188 | __ Cmp(length, Smi::FromInt(constant_index)); |
| 4189 | } else { |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4190 | __ cmpl(length, Immediate(constant_index)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4191 | } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4192 | } else { |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4193 | if (representation.IsSmi()) { |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 4194 | __ cmpp(length, ToRegister(instr->index())); |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4195 | } else { |
| 4196 | __ cmpl(length, ToRegister(instr->index())); |
| 4197 | } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 4198 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4199 | } |
jkummerow@chromium.org | 50bb868 | 2014-03-06 17:59:13 +0000 | [diff] [blame] | 4200 | Condition condition = hinstr->allow_equality() ? below : below_equal; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4201 | ApplyCheckIf(condition, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4205 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4206 | ElementsKind elements_kind = instr->elements_kind(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4207 | LOperand* key = instr->key(); |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4208 | int base_offset = instr->is_fixed_typed_array() |
| 4209 | ? FixedTypedArrayBase::kDataOffset - kHeapObjectTag |
| 4210 | : 0; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4211 | Operand operand(BuildFastArrayOperand( |
| 4212 | instr->elements(), |
| 4213 | key, |
| 4214 | elements_kind, |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4215 | base_offset, |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4216 | instr->additional_index())); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4217 | |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4218 | if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4219 | elements_kind == FLOAT32_ELEMENTS) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4220 | XMMRegister value(ToDoubleRegister(instr->value())); |
| 4221 | __ cvtsd2ss(value, value); |
| 4222 | __ movss(operand, value); |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4223 | } else if (elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4224 | elements_kind == FLOAT64_ELEMENTS) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4225 | __ movsd(operand, ToDoubleRegister(instr->value())); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4226 | } else { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4227 | Register value(ToRegister(instr->value())); |
| 4228 | switch (elements_kind) { |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4229 | case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
| 4230 | case EXTERNAL_INT8_ELEMENTS: |
| 4231 | case EXTERNAL_UINT8_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4232 | case INT8_ELEMENTS: |
| 4233 | case UINT8_ELEMENTS: |
| 4234 | case UINT8_CLAMPED_ELEMENTS: |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4235 | __ movb(operand, value); |
| 4236 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4237 | case EXTERNAL_INT16_ELEMENTS: |
| 4238 | case EXTERNAL_UINT16_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4239 | case INT16_ELEMENTS: |
| 4240 | case UINT16_ELEMENTS: |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4241 | __ movw(operand, value); |
| 4242 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4243 | case EXTERNAL_INT32_ELEMENTS: |
| 4244 | case EXTERNAL_UINT32_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4245 | case INT32_ELEMENTS: |
| 4246 | case UINT32_ELEMENTS: |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4247 | __ movl(operand, value); |
| 4248 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4249 | case EXTERNAL_FLOAT32_ELEMENTS: |
| 4250 | case EXTERNAL_FLOAT64_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4251 | case FLOAT32_ELEMENTS: |
| 4252 | case FLOAT64_ELEMENTS: |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4253 | case FAST_ELEMENTS: |
| 4254 | case FAST_SMI_ELEMENTS: |
| 4255 | case FAST_DOUBLE_ELEMENTS: |
| 4256 | case FAST_HOLEY_ELEMENTS: |
| 4257 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4258 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4259 | case DICTIONARY_ELEMENTS: |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4260 | case SLOPPY_ARGUMENTS_ELEMENTS: |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4261 | UNREACHABLE(); |
| 4262 | break; |
| 4263 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4264 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4268 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4269 | XMMRegister value = ToDoubleRegister(instr->value()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4270 | LOperand* key = instr->key(); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4271 | if (instr->NeedsCanonicalization()) { |
| 4272 | Label have_value; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4273 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4274 | __ ucomisd(value, value); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4275 | __ j(parity_odd, &have_value, Label::kNear); // NaN. |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4276 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4277 | __ Set(kScratchRegister, BitCast<uint64_t>( |
| 4278 | FixedDoubleArray::canonical_not_the_hole_nan_as_double())); |
| 4279 | __ movq(value, kScratchRegister); |
| 4280 | |
| 4281 | __ bind(&have_value); |
| 4282 | } |
| 4283 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4284 | Operand double_store_operand = BuildFastArrayOperand( |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4285 | instr->elements(), |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4286 | key, |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4287 | FAST_DOUBLE_ELEMENTS, |
| 4288 | FixedDoubleArray::kHeaderSize - kHeapObjectTag, |
| 4289 | instr->additional_index()); |
| 4290 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4291 | __ movsd(double_store_operand, value); |
| 4292 | } |
| 4293 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4294 | |
| 4295 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4296 | HStoreKeyed* hinstr = instr->hydrogen(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4297 | LOperand* key = instr->key(); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4298 | int offset = FixedArray::kHeaderSize - kHeapObjectTag; |
| 4299 | Representation representation = hinstr->value()->representation(); |
| 4300 | |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 4301 | if (representation.IsInteger32() && SmiValuesAre32Bits()) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4302 | ASSERT(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 4303 | ASSERT(hinstr->elements_kind() == FAST_SMI_ELEMENTS); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 4304 | if (FLAG_debug_code) { |
| 4305 | Register scratch = kScratchRegister; |
| 4306 | __ Load(scratch, |
| 4307 | BuildFastArrayOperand(instr->elements(), |
| 4308 | key, |
| 4309 | FAST_ELEMENTS, |
| 4310 | offset, |
| 4311 | instr->additional_index()), |
| 4312 | Representation::Smi()); |
| 4313 | __ AssertSmi(scratch); |
| 4314 | } |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4315 | // Store int value directly to upper half of the smi. |
| 4316 | STATIC_ASSERT(kSmiTag == 0); |
machenbach@chromium.org | 04a34e6 | 2014-04-10 09:03:11 +0000 | [diff] [blame] | 4317 | ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4318 | offset += kPointerSize / 2; |
| 4319 | } |
| 4320 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4321 | Operand operand = |
| 4322 | BuildFastArrayOperand(instr->elements(), |
| 4323 | key, |
| 4324 | FAST_ELEMENTS, |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4325 | offset, |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4326 | instr->additional_index()); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4327 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4328 | if (instr->value()->IsRegister()) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4329 | __ Store(operand, ToRegister(instr->value()), representation); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4330 | } else { |
| 4331 | LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
| 4332 | if (IsInteger32Constant(operand_value)) { |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4333 | int32_t value = ToInteger32(operand_value); |
| 4334 | if (representation.IsSmi()) { |
| 4335 | __ Move(operand, Smi::FromInt(value)); |
| 4336 | |
| 4337 | } else { |
| 4338 | __ movl(operand, Immediate(value)); |
| 4339 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4340 | } else { |
| 4341 | Handle<Object> handle_value = ToHandle(operand_value); |
| 4342 | __ Move(operand, handle_value); |
| 4343 | } |
| 4344 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4345 | |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4346 | if (hinstr->NeedsWriteBarrier()) { |
| 4347 | Register elements = ToRegister(instr->elements()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 4348 | ASSERT(instr->value()->IsRegister()); |
| 4349 | Register value = ToRegister(instr->value()); |
hpayer@chromium.org | 71ea97f | 2013-12-19 16:03:26 +0000 | [diff] [blame] | 4350 | ASSERT(!key->IsConstantOperand()); |
| 4351 | SmiCheck check_needed = hinstr->value()->IsHeapObject() |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4352 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4353 | // Compute address of modified element and store it into key register. |
| 4354 | Register key_reg(ToRegister(key)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4355 | __ leap(key_reg, operand); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4356 | __ RecordWrite(elements, |
| 4357 | key_reg, |
| 4358 | value, |
| 4359 | kSaveFPRegs, |
| 4360 | EMIT_REMEMBERED_SET, |
| 4361 | check_needed); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4362 | } |
| 4363 | } |
| 4364 | |
| 4365 | |
| 4366 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4367 | if (instr->is_typed_elements()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4368 | DoStoreKeyedExternalArray(instr); |
| 4369 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4370 | DoStoreKeyedFixedDoubleArray(instr); |
| 4371 | } else { |
| 4372 | DoStoreKeyedFixedArray(instr); |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4377 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4378 | ASSERT(ToRegister(instr->context()).is(rsi)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4379 | ASSERT(ToRegister(instr->object()).is(rdx)); |
| 4380 | ASSERT(ToRegister(instr->key()).is(rcx)); |
| 4381 | ASSERT(ToRegister(instr->value()).is(rax)); |
| 4382 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4383 | Handle<Code> ic = instr->strict_mode() == STRICT |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4384 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4385 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4386 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4387 | } |
| 4388 | |
| 4389 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4390 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4391 | Register object_reg = ToRegister(instr->object()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4392 | |
| 4393 | Handle<Map> from_map = instr->original_map(); |
| 4394 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4395 | ElementsKind from_kind = instr->from_kind(); |
| 4396 | ElementsKind to_kind = instr->to_kind(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4397 | |
| 4398 | Label not_applicable; |
| 4399 | __ Cmp(FieldOperand(object_reg, HeapObject::kMapOffset), from_map); |
| 4400 | __ j(not_equal, ¬_applicable); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4401 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4402 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 4403 | __ Move(new_map_reg, to_map, RelocInfo::EMBEDDED_OBJECT); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4404 | __ movp(FieldOperand(object_reg, HeapObject::kMapOffset), new_map_reg); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4405 | // Write barrier. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4406 | ASSERT_NE(instr->temp(), NULL); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4407 | __ RecordWriteField(object_reg, HeapObject::kMapOffset, new_map_reg, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4408 | ToRegister(instr->temp()), kDontSaveFPRegs); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4409 | } else { |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 4410 | ASSERT(object_reg.is(rax)); |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 4411 | ASSERT(ToRegister(instr->context()).is(rsi)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4412 | PushSafepointRegistersScope scope(this); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4413 | __ Move(rbx, to_map); |
machenbach@chromium.org | 9801e3c | 2014-03-19 01:04:51 +0000 | [diff] [blame] | 4414 | bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; |
| 4415 | TransitionElementsKindStub stub(from_kind, to_kind, is_js_array); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4416 | __ CallStub(&stub); |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 4417 | RecordSafepointWithLazyDeopt(instr, RECORD_SAFEPOINT_WITH_REGISTERS, 0); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4418 | } |
| 4419 | __ bind(¬_applicable); |
| 4420 | } |
| 4421 | |
| 4422 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4423 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4424 | Register object = ToRegister(instr->object()); |
| 4425 | Register temp = ToRegister(instr->temp()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4426 | Label no_memento_found; |
| 4427 | __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4428 | DeoptimizeIf(equal, instr->environment()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4429 | __ bind(&no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4433 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4434 | ASSERT(ToRegister(instr->context()).is(rsi)); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 4435 | ASSERT(ToRegister(instr->left()).is(rdx)); |
| 4436 | ASSERT(ToRegister(instr->right()).is(rax)); |
| 4437 | StringAddStub stub(instr->hydrogen()->flags(), |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 4438 | instr->hydrogen()->pretenure_flag()); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 4439 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4443 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4444 | class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4445 | public: |
| 4446 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 4447 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4448 | virtual void Generate() V8_OVERRIDE { |
| 4449 | codegen()->DoDeferredStringCharCodeAt(instr_); |
| 4450 | } |
| 4451 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4452 | private: |
| 4453 | LStringCharCodeAt* instr_; |
| 4454 | }; |
| 4455 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4456 | DeferredStringCharCodeAt* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4457 | new(zone()) DeferredStringCharCodeAt(this, instr); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4458 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4459 | StringCharLoadGenerator::Generate(masm(), |
| 4460 | ToRegister(instr->string()), |
| 4461 | ToRegister(instr->index()), |
| 4462 | ToRegister(instr->result()), |
| 4463 | deferred->entry()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4464 | __ bind(deferred->exit()); |
| 4465 | } |
| 4466 | |
| 4467 | |
| 4468 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4469 | Register string = ToRegister(instr->string()); |
| 4470 | Register result = ToRegister(instr->result()); |
| 4471 | |
| 4472 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4473 | // result register contain a valid pointer because it is already |
| 4474 | // contained in the register pointer map. |
| 4475 | __ Set(result, 0); |
| 4476 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4477 | PushSafepointRegistersScope scope(this); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 4478 | __ Push(string); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4479 | // Push the index as a smi. This is safe because of the checks in |
| 4480 | // DoStringCharCodeAt above. |
| 4481 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 4482 | if (instr->index()->IsConstantOperand()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4483 | int32_t const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4484 | __ Push(Smi::FromInt(const_index)); |
| 4485 | } else { |
| 4486 | Register index = ToRegister(instr->index()); |
| 4487 | __ Integer32ToSmi(index, index); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 4488 | __ Push(index); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4489 | } |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4490 | CallRuntimeFromDeferred( |
machenbach@chromium.org | 9b95fd7 | 2014-03-26 01:04:35 +0000 | [diff] [blame] | 4491 | Runtime::kHiddenStringCharCodeAt, 2, instr, instr->context()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4492 | __ AssertSmi(rax); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4493 | __ SmiToInteger32(rax, rax); |
| 4494 | __ StoreToSafepointRegisterSlot(result, rax); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4498 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4499 | class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4500 | public: |
| 4501 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4502 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4503 | virtual void Generate() V8_OVERRIDE { |
| 4504 | codegen()->DoDeferredStringCharFromCode(instr_); |
| 4505 | } |
| 4506 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4507 | private: |
| 4508 | LStringCharFromCode* instr_; |
| 4509 | }; |
| 4510 | |
| 4511 | DeferredStringCharFromCode* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4512 | new(zone()) DeferredStringCharFromCode(this, instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4513 | |
| 4514 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4515 | Register char_code = ToRegister(instr->char_code()); |
| 4516 | Register result = ToRegister(instr->result()); |
| 4517 | ASSERT(!char_code.is(result)); |
| 4518 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4519 | __ cmpl(char_code, Immediate(String::kMaxOneByteCharCode)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4520 | __ j(above, deferred->entry()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4521 | __ movsxlq(char_code, char_code); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4522 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4523 | __ movp(result, FieldOperand(result, |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4524 | char_code, times_pointer_size, |
| 4525 | FixedArray::kHeaderSize)); |
| 4526 | __ CompareRoot(result, Heap::kUndefinedValueRootIndex); |
| 4527 | __ j(equal, deferred->entry()); |
| 4528 | __ bind(deferred->exit()); |
| 4529 | } |
| 4530 | |
| 4531 | |
| 4532 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4533 | Register char_code = ToRegister(instr->char_code()); |
| 4534 | Register result = ToRegister(instr->result()); |
| 4535 | |
| 4536 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4537 | // result register contain a valid pointer because it is already |
| 4538 | // contained in the register pointer map. |
| 4539 | __ Set(result, 0); |
| 4540 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4541 | PushSafepointRegistersScope scope(this); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4542 | __ Integer32ToSmi(char_code, char_code); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 4543 | __ Push(char_code); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4544 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4545 | __ StoreToSafepointRegisterSlot(result, rax); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4549 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4550 | LOperand* input = instr->value(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4551 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4552 | LOperand* output = instr->result(); |
| 4553 | ASSERT(output->IsDoubleRegister()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4554 | if (input->IsRegister()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4555 | __ Cvtlsi2sd(ToDoubleRegister(output), ToRegister(input)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4556 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4557 | __ Cvtlsi2sd(ToDoubleRegister(output), ToOperand(input)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4558 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4562 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4563 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4564 | LOperand* output = instr->result(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4565 | LOperand* temp = instr->temp(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4566 | |
| 4567 | __ LoadUint32(ToDoubleRegister(output), |
| 4568 | ToRegister(input), |
| 4569 | ToDoubleRegister(temp)); |
| 4570 | } |
| 4571 | |
| 4572 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4573 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4574 | LOperand* input = instr->value(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4575 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 4576 | Register reg = ToRegister(input); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4577 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4578 | __ Integer32ToSmi(reg, reg); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4582 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4583 | class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4584 | public: |
| 4585 | DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4586 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4587 | virtual void Generate() V8_OVERRIDE { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4588 | codegen()->DoDeferredNumberTagU(instr_); |
| 4589 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4590 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4591 | private: |
| 4592 | LNumberTagU* instr_; |
| 4593 | }; |
| 4594 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4595 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4596 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 4597 | Register reg = ToRegister(input); |
| 4598 | |
| 4599 | DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
| 4600 | __ cmpl(reg, Immediate(Smi::kMaxValue)); |
| 4601 | __ j(above, deferred->entry()); |
| 4602 | __ Integer32ToSmi(reg, reg); |
| 4603 | __ bind(deferred->exit()); |
| 4604 | } |
| 4605 | |
| 4606 | |
| 4607 | void LCodeGen::DoDeferredNumberTagU(LNumberTagU* instr) { |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4608 | Label done, slow; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4609 | Register reg = ToRegister(instr->value()); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4610 | Register tmp = ToRegister(instr->temp1()); |
| 4611 | XMMRegister temp_xmm = ToDoubleRegister(instr->temp2()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4612 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4613 | // Load value into temp_xmm which will be preserved across potential call to |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4614 | // runtime (MacroAssembler::EnterExitFrameEpilogue preserves only allocatable |
| 4615 | // XMM registers on x64). |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4616 | XMMRegister xmm_scratch = double_scratch0(); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4617 | __ LoadUint32(temp_xmm, reg, xmm_scratch); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4618 | |
| 4619 | if (FLAG_inline_new) { |
| 4620 | __ AllocateHeapNumber(reg, tmp, &slow); |
| 4621 | __ jmp(&done, Label::kNear); |
| 4622 | } |
| 4623 | |
| 4624 | // Slow case: Call the runtime system to do the number allocation. |
| 4625 | __ bind(&slow); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4626 | { |
| 4627 | // Put a valid pointer value in the stack slot where the result |
| 4628 | // register is stored, as this register is in the pointer map, but contains |
| 4629 | // an integer value. |
| 4630 | __ Set(reg, 0); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4631 | |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4632 | // Preserve the value of all registers. |
| 4633 | PushSafepointRegistersScope scope(this); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4634 | |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4635 | // NumberTagU uses the context from the frame, rather than |
| 4636 | // the environment's HContext or HInlinedContext value. |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4637 | // They only call Runtime::kHiddenAllocateHeapNumber. |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4638 | // The corresponding HChange instructions are added in a phase that does |
| 4639 | // not have easy access to the local context. |
| 4640 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4641 | __ CallRuntimeSaveDoubles(Runtime::kHiddenAllocateHeapNumber); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4642 | RecordSafepointWithRegisters( |
| 4643 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
| 4644 | __ StoreToSafepointRegisterSlot(reg, rax); |
| 4645 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4646 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4647 | // Done. Put the value in temp_xmm into the value of the allocated heap |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4648 | // number. |
| 4649 | __ bind(&done); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4650 | __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), temp_xmm); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4654 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4655 | class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4656 | public: |
| 4657 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4658 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4659 | virtual void Generate() V8_OVERRIDE { |
| 4660 | codegen()->DoDeferredNumberTagD(instr_); |
| 4661 | } |
| 4662 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4663 | private: |
| 4664 | LNumberTagD* instr_; |
| 4665 | }; |
| 4666 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4667 | XMMRegister input_reg = ToDoubleRegister(instr->value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4668 | Register reg = ToRegister(instr->result()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4669 | Register tmp = ToRegister(instr->temp()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4670 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4671 | DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4672 | if (FLAG_inline_new) { |
| 4673 | __ AllocateHeapNumber(reg, tmp, deferred->entry()); |
| 4674 | } else { |
| 4675 | __ jmp(deferred->entry()); |
| 4676 | } |
| 4677 | __ bind(deferred->exit()); |
| 4678 | __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), input_reg); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | |
| 4682 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4683 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4684 | // result register contain a valid pointer because it is already |
| 4685 | // contained in the register pointer map. |
| 4686 | Register reg = ToRegister(instr->result()); |
| 4687 | __ Move(reg, Smi::FromInt(0)); |
| 4688 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4689 | { |
| 4690 | PushSafepointRegistersScope scope(this); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4691 | // NumberTagD uses the context from the frame, rather than |
| 4692 | // the environment's HContext or HInlinedContext value. |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4693 | // They only call Runtime::kHiddenAllocateHeapNumber. |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4694 | // The corresponding HChange instructions are added in a phase that does |
| 4695 | // not have easy access to the local context. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4696 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4697 | __ CallRuntimeSaveDoubles(Runtime::kHiddenAllocateHeapNumber); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4698 | RecordSafepointWithRegisters( |
| 4699 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4700 | __ movp(kScratchRegister, rax); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4701 | } |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4702 | __ movp(reg, kScratchRegister); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | |
| 4706 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 4707 | HChange* hchange = instr->hydrogen(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4708 | Register input = ToRegister(instr->value()); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 4709 | Register output = ToRegister(instr->result()); |
| 4710 | if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4711 | hchange->value()->CheckFlag(HValue::kUint32)) { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 4712 | __ testl(input, input); |
| 4713 | DeoptimizeIf(sign, instr->environment()); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 4714 | } |
| 4715 | __ Integer32ToSmi(output, input); |
| 4716 | if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4717 | !hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4718 | DeoptimizeIf(overflow, instr->environment()); |
| 4719 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | |
| 4723 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4724 | ASSERT(instr->value()->Equals(instr->result())); |
| 4725 | Register input = ToRegister(instr->value()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4726 | if (instr->needs_check()) { |
| 4727 | Condition is_smi = __ CheckSmi(input); |
| 4728 | DeoptimizeIf(NegateCondition(is_smi), instr->environment()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4729 | } else { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4730 | __ AssertSmi(input); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4731 | } |
| 4732 | __ SmiToInteger32(input, input); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | |
| 4736 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 4737 | XMMRegister result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4738 | bool can_convert_undefined_to_nan, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4739 | bool deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4740 | LEnvironment* env, |
| 4741 | NumberUntagDMode mode) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4742 | Label convert, load_smi, done; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4743 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4744 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4745 | // Smi check. |
| 4746 | __ JumpIfSmi(input_reg, &load_smi, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4747 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4748 | // Heap number map check. |
| 4749 | __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 4750 | Heap::kHeapNumberMapRootIndex); |
hpayer@chromium.org | 4f626d1 | 2013-09-18 07:47:45 +0000 | [diff] [blame] | 4751 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4752 | // On x64 it is safe to load at heap number offset before evaluating the map |
| 4753 | // check, since all heap objects are at least two words long. |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 4754 | __ movsd(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4755 | |
| 4756 | if (can_convert_undefined_to_nan) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4757 | __ j(not_equal, &convert, Label::kNear); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4758 | } else { |
| 4759 | DeoptimizeIf(not_equal, env); |
| 4760 | } |
| 4761 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4762 | if (deoptimize_on_minus_zero) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4763 | XMMRegister xmm_scratch = double_scratch0(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4764 | __ xorps(xmm_scratch, xmm_scratch); |
| 4765 | __ ucomisd(xmm_scratch, result_reg); |
| 4766 | __ j(not_equal, &done, Label::kNear); |
| 4767 | __ movmskpd(kScratchRegister, result_reg); |
| 4768 | __ testq(kScratchRegister, Immediate(1)); |
| 4769 | DeoptimizeIf(not_zero, env); |
| 4770 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4771 | __ jmp(&done, Label::kNear); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4772 | |
| 4773 | if (can_convert_undefined_to_nan) { |
| 4774 | __ bind(&convert); |
| 4775 | |
| 4776 | // Convert undefined (and hole) to NaN. Compute NaN as 0/0. |
| 4777 | __ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex); |
| 4778 | DeoptimizeIf(not_equal, env); |
| 4779 | |
| 4780 | __ xorps(result_reg, result_reg); |
| 4781 | __ divsd(result_reg, result_reg); |
| 4782 | __ jmp(&done, Label::kNear); |
| 4783 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4784 | } else { |
| 4785 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4786 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4787 | |
| 4788 | // Smi to XMM conversion |
| 4789 | __ bind(&load_smi); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4790 | __ SmiToInteger32(kScratchRegister, input_reg); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4791 | __ Cvtlsi2sd(result_reg, kScratchRegister); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4792 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4796 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, Label* done) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4797 | Register input_reg = ToRegister(instr->value()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4798 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4799 | if (instr->truncating()) { |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4800 | Label no_heap_number, check_bools, check_false; |
| 4801 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4802 | // Heap number map check. |
| 4803 | __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 4804 | Heap::kHeapNumberMapRootIndex); |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4805 | __ j(not_equal, &no_heap_number, Label::kNear); |
| 4806 | __ TruncateHeapNumberToI(input_reg, input_reg); |
| 4807 | __ jmp(done); |
| 4808 | |
| 4809 | __ bind(&no_heap_number); |
| 4810 | // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 4811 | // for truncating conversions. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4812 | __ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex); |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4813 | __ j(not_equal, &check_bools, Label::kNear); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 4814 | __ Set(input_reg, 0); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4815 | __ jmp(done); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4816 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4817 | __ bind(&check_bools); |
| 4818 | __ CompareRoot(input_reg, Heap::kTrueValueRootIndex); |
| 4819 | __ j(not_equal, &check_false, Label::kNear); |
| 4820 | __ Set(input_reg, 1); |
| 4821 | __ jmp(done); |
| 4822 | |
| 4823 | __ bind(&check_false); |
| 4824 | __ CompareRoot(input_reg, Heap::kFalseValueRootIndex); |
| 4825 | __ RecordComment("Deferred TaggedToI: cannot truncate"); |
| 4826 | DeoptimizeIf(not_equal, instr->environment()); |
| 4827 | __ Set(input_reg, 0); |
| 4828 | __ jmp(done); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4829 | } else { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4830 | Label bailout; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4831 | XMMRegister xmm_temp = ToDoubleRegister(instr->temp()); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4832 | __ TaggedToI(input_reg, input_reg, xmm_temp, |
| 4833 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
| 4834 | |
| 4835 | __ jmp(done); |
| 4836 | __ bind(&bailout); |
| 4837 | DeoptimizeIf(no_condition, instr->environment()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4838 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | |
| 4842 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4843 | class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4844 | public: |
| 4845 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 4846 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4847 | virtual void Generate() V8_OVERRIDE { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4848 | codegen()->DoDeferredTaggedToI(instr_, done()); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4849 | } |
| 4850 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4851 | private: |
| 4852 | LTaggedToI* instr_; |
| 4853 | }; |
| 4854 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4855 | LOperand* input = instr->value(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4856 | ASSERT(input->IsRegister()); |
| 4857 | ASSERT(input->Equals(instr->result())); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 4858 | Register input_reg = ToRegister(input); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4859 | |
| 4860 | if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 4861 | __ SmiToInteger32(input_reg, input_reg); |
| 4862 | } else { |
| 4863 | DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
| 4864 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 4865 | __ SmiToInteger32(input_reg, input_reg); |
| 4866 | __ bind(deferred->exit()); |
| 4867 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | |
| 4871 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4872 | LOperand* input = instr->value(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4873 | ASSERT(input->IsRegister()); |
| 4874 | LOperand* result = instr->result(); |
| 4875 | ASSERT(result->IsDoubleRegister()); |
| 4876 | |
| 4877 | Register input_reg = ToRegister(input); |
| 4878 | XMMRegister result_reg = ToDoubleRegister(result); |
| 4879 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4880 | HValue* value = instr->hydrogen()->value(); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4881 | NumberUntagDMode mode = value->representation().IsSmi() |
| 4882 | ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4883 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4884 | EmitNumberUntagD(input_reg, result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4885 | instr->hydrogen()->can_convert_undefined_to_nan(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4886 | instr->hydrogen()->deoptimize_on_minus_zero(), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4887 | instr->environment(), |
| 4888 | mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | |
| 4892 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4893 | LOperand* input = instr->value(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4894 | ASSERT(input->IsDoubleRegister()); |
| 4895 | LOperand* result = instr->result(); |
| 4896 | ASSERT(result->IsRegister()); |
| 4897 | |
| 4898 | XMMRegister input_reg = ToDoubleRegister(input); |
| 4899 | Register result_reg = ToRegister(result); |
| 4900 | |
| 4901 | if (instr->truncating()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4902 | __ TruncateDoubleToI(result_reg, input_reg); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4903 | } else { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4904 | Label bailout, done; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4905 | XMMRegister xmm_scratch = double_scratch0(); |
| 4906 | __ DoubleToI(result_reg, input_reg, xmm_scratch, |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4907 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
| 4908 | |
| 4909 | __ jmp(&done, Label::kNear); |
| 4910 | __ bind(&bailout); |
| 4911 | DeoptimizeIf(no_condition, instr->environment()); |
| 4912 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4913 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4917 | void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 4918 | LOperand* input = instr->value(); |
| 4919 | ASSERT(input->IsDoubleRegister()); |
| 4920 | LOperand* result = instr->result(); |
| 4921 | ASSERT(result->IsRegister()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4922 | |
| 4923 | XMMRegister input_reg = ToDoubleRegister(input); |
| 4924 | Register result_reg = ToRegister(result); |
| 4925 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4926 | Label bailout, done; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4927 | XMMRegister xmm_scratch = double_scratch0(); |
| 4928 | __ DoubleToI(result_reg, input_reg, xmm_scratch, |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4929 | instr->hydrogen()->GetMinusZeroMode(), &bailout, Label::kNear); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4930 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4931 | __ jmp(&done, Label::kNear); |
| 4932 | __ bind(&bailout); |
| 4933 | DeoptimizeIf(no_condition, instr->environment()); |
| 4934 | __ bind(&done); |
| 4935 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4936 | __ Integer32ToSmi(result_reg, result_reg); |
| 4937 | DeoptimizeIf(overflow, instr->environment()); |
| 4938 | } |
| 4939 | |
| 4940 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4941 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4942 | LOperand* input = instr->value(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4943 | Condition cc = masm()->CheckSmi(ToRegister(input)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4944 | DeoptimizeIf(NegateCondition(cc), instr->environment()); |
| 4945 | } |
| 4946 | |
| 4947 | |
| 4948 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4949 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 4950 | LOperand* input = instr->value(); |
| 4951 | Condition cc = masm()->CheckSmi(ToRegister(input)); |
| 4952 | DeoptimizeIf(cc, instr->environment()); |
| 4953 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | |
| 4957 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4958 | Register input = ToRegister(instr->value()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4959 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 4960 | __ movp(kScratchRegister, FieldOperand(input, HeapObject::kMapOffset)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4961 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4962 | if (instr->hydrogen()->is_interval_check()) { |
| 4963 | InstanceType first; |
| 4964 | InstanceType last; |
| 4965 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 4966 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4967 | __ cmpb(FieldOperand(kScratchRegister, Map::kInstanceTypeOffset), |
| 4968 | Immediate(static_cast<int8_t>(first))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4969 | |
| 4970 | // If there is only one type in the interval check for equality. |
| 4971 | if (first == last) { |
| 4972 | DeoptimizeIf(not_equal, instr->environment()); |
| 4973 | } else { |
| 4974 | DeoptimizeIf(below, instr->environment()); |
| 4975 | // Omit check for the last type. |
| 4976 | if (last != LAST_TYPE) { |
| 4977 | __ cmpb(FieldOperand(kScratchRegister, Map::kInstanceTypeOffset), |
| 4978 | Immediate(static_cast<int8_t>(last))); |
| 4979 | DeoptimizeIf(above, instr->environment()); |
| 4980 | } |
| 4981 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4982 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4983 | uint8_t mask; |
| 4984 | uint8_t tag; |
| 4985 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 4986 | |
| 4987 | if (IsPowerOf2(mask)) { |
| 4988 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 4989 | __ testb(FieldOperand(kScratchRegister, Map::kInstanceTypeOffset), |
| 4990 | Immediate(mask)); |
| 4991 | DeoptimizeIf(tag == 0 ? not_zero : zero, instr->environment()); |
| 4992 | } else { |
| 4993 | __ movzxbl(kScratchRegister, |
| 4994 | FieldOperand(kScratchRegister, Map::kInstanceTypeOffset)); |
| 4995 | __ andb(kScratchRegister, Immediate(mask)); |
| 4996 | __ cmpb(kScratchRegister, Immediate(tag)); |
| 4997 | DeoptimizeIf(not_equal, instr->environment()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4998 | } |
| 4999 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5003 | void LCodeGen::DoCheckValue(LCheckValue* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5004 | Register reg = ToRegister(instr->value()); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 5005 | __ Cmp(reg, instr->hydrogen()->object().handle()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5006 | DeoptimizeIf(not_equal, instr->environment()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5010 | void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5011 | { |
| 5012 | PushSafepointRegistersScope scope(this); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5013 | __ Push(object); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5014 | __ Set(rsi, 0); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 5015 | __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5016 | RecordSafepointWithRegisters( |
| 5017 | instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); |
| 5018 | |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 5019 | __ testp(rax, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5020 | } |
| 5021 | DeoptimizeIf(zero, instr->environment()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5025 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5026 | class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5027 | public: |
| 5028 | DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) |
| 5029 | : LDeferredCode(codegen), instr_(instr), object_(object) { |
| 5030 | SetExit(check_maps()); |
| 5031 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5032 | virtual void Generate() V8_OVERRIDE { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5033 | codegen()->DoDeferredInstanceMigration(instr_, object_); |
| 5034 | } |
| 5035 | Label* check_maps() { return &check_maps_; } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5036 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5037 | private: |
| 5038 | LCheckMaps* instr_; |
| 5039 | Label check_maps_; |
| 5040 | Register object_; |
| 5041 | }; |
| 5042 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5043 | if (instr->hydrogen()->CanOmitMapChecks()) return; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5044 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5045 | LOperand* input = instr->value(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5046 | ASSERT(input->IsRegister()); |
| 5047 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5048 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5049 | DeferredCheckMaps* deferred = NULL; |
| 5050 | if (instr->hydrogen()->has_migration_target()) { |
| 5051 | deferred = new(zone()) DeferredCheckMaps(this, instr, reg); |
| 5052 | __ bind(deferred->check_maps()); |
| 5053 | } |
| 5054 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5055 | UniqueSet<Map> map_set = instr->hydrogen()->map_set(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5056 | Label success; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5057 | for (int i = 0; i < map_set.size() - 1; i++) { |
| 5058 | Handle<Map> map = map_set.at(i).handle(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5059 | __ CompareMap(reg, map); |
| 5060 | __ j(equal, &success, Label::kNear); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5061 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5062 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5063 | Handle<Map> map = map_set.at(map_set.size() - 1).handle(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5064 | __ CompareMap(reg, map); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5065 | if (instr->hydrogen()->has_migration_target()) { |
| 5066 | __ j(not_equal, deferred->entry()); |
| 5067 | } else { |
| 5068 | DeoptimizeIf(not_equal, instr->environment()); |
| 5069 | } |
| 5070 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5071 | __ bind(&success); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5075 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
| 5076 | XMMRegister value_reg = ToDoubleRegister(instr->unclamped()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5077 | XMMRegister xmm_scratch = double_scratch0(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5078 | Register result_reg = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5079 | __ ClampDoubleToUint8(value_reg, xmm_scratch, result_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | |
| 5083 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5084 | ASSERT(instr->unclamped()->Equals(instr->result())); |
| 5085 | Register value_reg = ToRegister(instr->result()); |
| 5086 | __ ClampUint8(value_reg); |
| 5087 | } |
| 5088 | |
| 5089 | |
| 5090 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 5091 | ASSERT(instr->unclamped()->Equals(instr->result())); |
| 5092 | Register input_reg = ToRegister(instr->unclamped()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5093 | XMMRegister temp_xmm_reg = ToDoubleRegister(instr->temp_xmm()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5094 | XMMRegister xmm_scratch = double_scratch0(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5095 | Label is_smi, done, heap_number; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5096 | Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear; |
| 5097 | __ JumpIfSmi(input_reg, &is_smi, dist); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5098 | |
| 5099 | // Check for heap number |
| 5100 | __ Cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 5101 | factory()->heap_number_map()); |
| 5102 | __ j(equal, &heap_number, Label::kNear); |
| 5103 | |
| 5104 | // Check for undefined. Undefined is converted to zero for clamping |
| 5105 | // conversions. |
| 5106 | __ Cmp(input_reg, factory()->undefined_value()); |
| 5107 | DeoptimizeIf(not_equal, instr->environment()); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 5108 | __ xorl(input_reg, input_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5109 | __ jmp(&done, Label::kNear); |
| 5110 | |
| 5111 | // Heap number |
| 5112 | __ bind(&heap_number); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5113 | __ movsd(xmm_scratch, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 5114 | __ ClampDoubleToUint8(xmm_scratch, temp_xmm_reg, input_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5115 | __ jmp(&done, Label::kNear); |
| 5116 | |
| 5117 | // smi |
| 5118 | __ bind(&is_smi); |
| 5119 | __ SmiToInteger32(input_reg, input_reg); |
| 5120 | __ ClampUint8(input_reg); |
| 5121 | |
| 5122 | __ bind(&done); |
| 5123 | } |
| 5124 | |
| 5125 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 5126 | void LCodeGen::DoDoubleBits(LDoubleBits* instr) { |
| 5127 | XMMRegister value_reg = ToDoubleRegister(instr->value()); |
| 5128 | Register result_reg = ToRegister(instr->result()); |
| 5129 | if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { |
| 5130 | __ movq(result_reg, value_reg); |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 5131 | __ shrq(result_reg, Immediate(32)); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 5132 | } else { |
| 5133 | __ movd(result_reg, value_reg); |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | |
| 5138 | void LCodeGen::DoConstructDouble(LConstructDouble* instr) { |
| 5139 | Register hi_reg = ToRegister(instr->hi()); |
| 5140 | Register lo_reg = ToRegister(instr->lo()); |
| 5141 | XMMRegister result_reg = ToDoubleRegister(instr->result()); |
| 5142 | XMMRegister xmm_scratch = double_scratch0(); |
| 5143 | __ movd(result_reg, hi_reg); |
| 5144 | __ psllq(result_reg, 32); |
| 5145 | __ movd(xmm_scratch, lo_reg); |
| 5146 | __ orps(result_reg, xmm_scratch); |
| 5147 | } |
| 5148 | |
| 5149 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5150 | void LCodeGen::DoAllocate(LAllocate* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5151 | class DeferredAllocate V8_FINAL : public LDeferredCode { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5152 | public: |
| 5153 | DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5154 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5155 | virtual void Generate() V8_OVERRIDE { |
| 5156 | codegen()->DoDeferredAllocate(instr_); |
| 5157 | } |
| 5158 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5159 | private: |
| 5160 | LAllocate* instr_; |
| 5161 | }; |
| 5162 | |
| 5163 | DeferredAllocate* deferred = |
| 5164 | new(zone()) DeferredAllocate(this, instr); |
| 5165 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5166 | Register result = ToRegister(instr->result()); |
| 5167 | Register temp = ToRegister(instr->temp()); |
| 5168 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5169 | // Allocate memory for the object. |
| 5170 | AllocationFlags flags = TAG_OBJECT; |
| 5171 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5172 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5173 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5174 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5175 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5176 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5177 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5178 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5179 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5180 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5181 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5182 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5183 | if (instr->size()->IsConstantOperand()) { |
| 5184 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
dslomov@chromium.org | 6b6df38 | 2014-03-14 16:14:53 +0000 | [diff] [blame] | 5185 | if (size <= Page::kMaxRegularHeapObjectSize) { |
| 5186 | __ Allocate(size, result, temp, no_reg, deferred->entry(), flags); |
| 5187 | } else { |
| 5188 | __ jmp(deferred->entry()); |
| 5189 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5190 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5191 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5192 | __ Allocate(size, result, temp, no_reg, deferred->entry(), flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | __ bind(deferred->exit()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5196 | |
| 5197 | if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 5198 | if (instr->size()->IsConstantOperand()) { |
| 5199 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5200 | __ movl(temp, Immediate((size / kPointerSize) - 1)); |
| 5201 | } else { |
| 5202 | temp = ToRegister(instr->size()); |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 5203 | __ sarp(temp, Immediate(kPointerSizeLog2)); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5204 | __ decl(temp); |
| 5205 | } |
| 5206 | Label loop; |
| 5207 | __ bind(&loop); |
| 5208 | __ Move(FieldOperand(result, temp, times_pointer_size, 0), |
| 5209 | isolate()->factory()->one_pointer_filler_map()); |
| 5210 | __ decl(temp); |
| 5211 | __ j(not_zero, &loop); |
| 5212 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | |
| 5216 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5217 | Register result = ToRegister(instr->result()); |
| 5218 | |
| 5219 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5220 | // result register contain a valid pointer because it is already |
| 5221 | // contained in the register pointer map. |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5222 | __ Move(result, Smi::FromInt(0)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5223 | |
| 5224 | PushSafepointRegistersScope scope(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5225 | if (instr->size()->IsRegister()) { |
| 5226 | Register size = ToRegister(instr->size()); |
| 5227 | ASSERT(!size.is(result)); |
| 5228 | __ Integer32ToSmi(size, size); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5229 | __ Push(size); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5230 | } else { |
| 5231 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5232 | __ Push(Smi::FromInt(size)); |
| 5233 | } |
| 5234 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5235 | int flags = 0; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5236 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5237 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5238 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5239 | flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5240 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5241 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5242 | flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5243 | } else { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5244 | flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5245 | } |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5246 | __ Push(Smi::FromInt(flags)); |
| 5247 | |
| 5248 | CallRuntimeFromDeferred( |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5249 | Runtime::kHiddenAllocateInTargetSpace, 2, instr, instr->context()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5250 | __ StoreToSafepointRegisterSlot(result, rax); |
| 5251 | } |
| 5252 | |
| 5253 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5254 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5255 | ASSERT(ToRegister(instr->value()).is(rax)); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5256 | __ Push(rax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5257 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 5258 | } |
| 5259 | |
| 5260 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5261 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5262 | ASSERT(ToRegister(instr->context()).is(rsi)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5263 | Label materialized; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5264 | // Registers will be used as follows: |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5265 | // rcx = literals array. |
| 5266 | // rbx = regexp literal. |
| 5267 | // rax = regexp literal clone. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5268 | int literal_offset = |
| 5269 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 5270 | __ Move(rcx, instr->hydrogen()->literals()); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5271 | __ movp(rbx, FieldOperand(rcx, literal_offset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5272 | __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5273 | __ j(not_equal, &materialized, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5274 | |
| 5275 | // Create regexp literal using runtime function |
| 5276 | // Result will be in rax. |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5277 | __ Push(rcx); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5278 | __ Push(Smi::FromInt(instr->hydrogen()->literal_index())); |
| 5279 | __ Push(instr->hydrogen()->pattern()); |
| 5280 | __ Push(instr->hydrogen()->flags()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5281 | CallRuntime(Runtime::kHiddenMaterializeRegExpLiteral, 4, instr); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5282 | __ movp(rbx, rax); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5283 | |
| 5284 | __ bind(&materialized); |
| 5285 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5286 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5287 | __ Allocate(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5288 | __ jmp(&allocated, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5289 | |
| 5290 | __ bind(&runtime_allocate); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5291 | __ Push(rbx); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5292 | __ Push(Smi::FromInt(size)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5293 | CallRuntime(Runtime::kHiddenAllocateInNewSpace, 1, instr); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5294 | __ Pop(rbx); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5295 | |
| 5296 | __ bind(&allocated); |
| 5297 | // Copy the content into the newly allocated memory. |
| 5298 | // (Unroll copy loop once for better throughput). |
| 5299 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5300 | __ movp(rdx, FieldOperand(rbx, i)); |
| 5301 | __ movp(rcx, FieldOperand(rbx, i + kPointerSize)); |
| 5302 | __ movp(FieldOperand(rax, i), rdx); |
| 5303 | __ movp(FieldOperand(rax, i + kPointerSize), rcx); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5304 | } |
| 5305 | if ((size % (2 * kPointerSize)) != 0) { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5306 | __ movp(rdx, FieldOperand(rbx, size - kPointerSize)); |
| 5307 | __ movp(FieldOperand(rax, size - kPointerSize), rdx); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5308 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | |
| 5312 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5313 | ASSERT(ToRegister(instr->context()).is(rsi)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5314 | // Use the fast case closure allocation code that allocates in new |
| 5315 | // space for nested functions that don't need literals cloning. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5316 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5317 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 5318 | FastNewClosureStub stub(instr->hydrogen()->strict_mode(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5319 | instr->hydrogen()->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 5320 | __ Move(rbx, instr->hydrogen()->shared_info()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5321 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5322 | } else { |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5323 | __ Push(rsi); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5324 | __ Push(instr->hydrogen()->shared_info()); |
| 5325 | __ PushRoot(pretenure ? Heap::kTrueValueRootIndex : |
| 5326 | Heap::kFalseValueRootIndex); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5327 | CallRuntime(Runtime::kHiddenNewClosure, 3, instr); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5328 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | |
| 5332 | void LCodeGen::DoTypeof(LTypeof* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5333 | ASSERT(ToRegister(instr->context()).is(rsi)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5334 | LOperand* input = instr->value(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5335 | EmitPushTaggedOperand(input); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5336 | CallRuntime(Runtime::kTypeof, 1, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5340 | void LCodeGen::EmitPushTaggedOperand(LOperand* operand) { |
| 5341 | ASSERT(!operand->IsDoubleRegister()); |
| 5342 | if (operand->IsConstantOperand()) { |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 5343 | __ Push(ToHandle(LConstantOperand::cast(operand))); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5344 | } else if (operand->IsRegister()) { |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5345 | __ Push(ToRegister(operand)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5346 | } else { |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5347 | __ Push(ToOperand(operand)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5348 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5352 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5353 | Register input = ToRegister(instr->value()); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5354 | Condition final_branch_condition = EmitTypeofIs(instr, input); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5355 | if (final_branch_condition != no_condition) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5356 | EmitBranch(instr, final_branch_condition); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5357 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5361 | Condition LCodeGen::EmitTypeofIs(LTypeofIsAndBranch* instr, Register input) { |
| 5362 | Label* true_label = instr->TrueLabel(chunk_); |
| 5363 | Label* false_label = instr->FalseLabel(chunk_); |
| 5364 | Handle<String> type_name = instr->type_literal(); |
| 5365 | int left_block = instr->TrueDestination(chunk_); |
| 5366 | int right_block = instr->FalseDestination(chunk_); |
| 5367 | int next_block = GetNextEmittedBlock(); |
| 5368 | |
| 5369 | Label::Distance true_distance = left_block == next_block ? Label::kNear |
| 5370 | : Label::kFar; |
| 5371 | Label::Distance false_distance = right_block == next_block ? Label::kNear |
| 5372 | : Label::kFar; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5373 | Condition final_branch_condition = no_condition; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5374 | Factory* factory = isolate()->factory(); |
| 5375 | if (String::Equals(type_name, factory->number_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5376 | __ JumpIfSmi(input, true_label, true_distance); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5377 | __ CompareRoot(FieldOperand(input, HeapObject::kMapOffset), |
| 5378 | Heap::kHeapNumberMapRootIndex); |
| 5379 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5380 | final_branch_condition = equal; |
| 5381 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5382 | } else if (String::Equals(type_name, factory->string_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5383 | __ JumpIfSmi(input, false_label, false_distance); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5384 | __ CmpObjectType(input, FIRST_NONSTRING_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5385 | __ j(above_equal, false_label, false_distance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5386 | __ testb(FieldOperand(input, Map::kBitFieldOffset), |
| 5387 | Immediate(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5388 | final_branch_condition = zero; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5389 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5390 | } else if (String::Equals(type_name, factory->symbol_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5391 | __ JumpIfSmi(input, false_label, false_distance); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5392 | __ CmpObjectType(input, SYMBOL_TYPE, input); |
| 5393 | final_branch_condition = equal; |
| 5394 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5395 | } else if (String::Equals(type_name, factory->boolean_string())) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5396 | __ CompareRoot(input, Heap::kTrueValueRootIndex); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5397 | __ j(equal, true_label, true_distance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5398 | __ CompareRoot(input, Heap::kFalseValueRootIndex); |
| 5399 | final_branch_condition = equal; |
| 5400 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5401 | } else if (FLAG_harmony_typeof && |
| 5402 | String::Equals(type_name, factory->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5403 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5404 | final_branch_condition = equal; |
| 5405 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5406 | } else if (String::Equals(type_name, factory->undefined_string())) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5407 | __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5408 | __ j(equal, true_label, true_distance); |
| 5409 | __ JumpIfSmi(input, false_label, false_distance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5410 | // Check for undetectable objects => true. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5411 | __ movp(input, FieldOperand(input, HeapObject::kMapOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5412 | __ testb(FieldOperand(input, Map::kBitFieldOffset), |
| 5413 | Immediate(1 << Map::kIsUndetectable)); |
| 5414 | final_branch_condition = not_zero; |
| 5415 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5416 | } else if (String::Equals(type_name, factory->function_string())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5417 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5418 | __ JumpIfSmi(input, false_label, false_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5419 | __ CmpObjectType(input, JS_FUNCTION_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5420 | __ j(equal, true_label, true_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5421 | __ CmpInstanceType(input, JS_FUNCTION_PROXY_TYPE); |
| 5422 | final_branch_condition = equal; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5423 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame^] | 5424 | } else if (String::Equals(type_name, factory->object_string())) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5425 | __ JumpIfSmi(input, false_label, false_distance); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5426 | if (!FLAG_harmony_typeof) { |
| 5427 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5428 | __ j(equal, true_label, true_distance); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5429 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5430 | __ CmpObjectType(input, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, input); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5431 | __ j(below, false_label, false_distance); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5432 | __ CmpInstanceType(input, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5433 | __ j(above, false_label, false_distance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5434 | // Check for undetectable objects => false. |
| 5435 | __ testb(FieldOperand(input, Map::kBitFieldOffset), |
| 5436 | Immediate(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5437 | final_branch_condition = zero; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5438 | |
| 5439 | } else { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 5440 | __ jmp(false_label, false_distance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | return final_branch_condition; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5447 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5448 | Register temp = ToRegister(instr->temp()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5449 | |
| 5450 | EmitIsConstructCall(temp); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5451 | EmitBranch(instr, equal); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | |
| 5455 | void LCodeGen::EmitIsConstructCall(Register temp) { |
| 5456 | // Get the frame pointer for the calling frame. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5457 | __ movp(temp, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5458 | |
| 5459 | // Skip the arguments adaptor frame if it exists. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5460 | Label check_frame_marker; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5461 | __ Cmp(Operand(temp, StandardFrameConstants::kContextOffset), |
| 5462 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5463 | __ j(not_equal, &check_frame_marker, Label::kNear); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5464 | __ movp(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5465 | |
| 5466 | // Check the marker in the calling frame. |
| 5467 | __ bind(&check_frame_marker); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5468 | __ Cmp(Operand(temp, StandardFrameConstants::kMarkerOffset), |
| 5469 | Smi::FromInt(StackFrame::CONSTRUCT)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5473 | void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 5474 | if (!info()->IsStub()) { |
| 5475 | // Ensure that we have enough space after the previous lazy-bailout |
| 5476 | // instruction for patching the code here. |
| 5477 | int current_pc = masm()->pc_offset(); |
| 5478 | if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
| 5479 | int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 5480 | __ Nop(padding_size); |
| 5481 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5482 | } |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 5483 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5487 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 5488 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5489 | ASSERT(instr->HasEnvironment()); |
| 5490 | LEnvironment* env = instr->environment(); |
| 5491 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5492 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | |
| 5496 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5497 | Deoptimizer::BailoutType type = instr->hydrogen()->type(); |
| 5498 | // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the |
| 5499 | // needed return address), even though the implementation of LAZY and EAGER is |
| 5500 | // now identical. When LAZY is eventually completely folded into EAGER, remove |
| 5501 | // the special case below. |
| 5502 | if (info()->IsStub() && type == Deoptimizer::EAGER) { |
| 5503 | type = Deoptimizer::LAZY; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 5504 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5505 | |
| 5506 | Comment(";;; deoptimize: %s", instr->hydrogen()->reason()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5507 | DeoptimizeIf(no_condition, instr->environment(), type); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5508 | } |
| 5509 | |
| 5510 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5511 | void LCodeGen::DoDummy(LDummy* instr) { |
| 5512 | // Nothing to see here, move on! |
| 5513 | } |
| 5514 | |
| 5515 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5516 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 5517 | // Nothing to see here, move on! |
| 5518 | } |
| 5519 | |
| 5520 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5521 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5522 | PushSafepointRegistersScope scope(this); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5523 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5524 | __ CallRuntimeSaveDoubles(Runtime::kHiddenStackGuard); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5525 | RecordSafepointWithLazyDeopt(instr, RECORD_SAFEPOINT_WITH_REGISTERS, 0); |
| 5526 | ASSERT(instr->HasEnvironment()); |
| 5527 | LEnvironment* env = instr->environment(); |
| 5528 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5529 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5530 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5531 | |
| 5532 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5533 | class DeferredStackCheck V8_FINAL : public LDeferredCode { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5534 | public: |
| 5535 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 5536 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5537 | virtual void Generate() V8_OVERRIDE { |
| 5538 | codegen()->DoDeferredStackCheck(instr_); |
| 5539 | } |
| 5540 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5541 | private: |
| 5542 | LStackCheck* instr_; |
| 5543 | }; |
| 5544 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5545 | ASSERT(instr->HasEnvironment()); |
| 5546 | LEnvironment* env = instr->environment(); |
| 5547 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 5548 | // prepare for lazy deoptimization explicitly here. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5549 | if (instr->hydrogen()->is_function_entry()) { |
| 5550 | // Perform stack overflow check. |
| 5551 | Label done; |
| 5552 | __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 5553 | __ j(above_equal, &done, Label::kNear); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5554 | |
| 5555 | ASSERT(instr->context()->IsRegister()); |
| 5556 | ASSERT(ToRegister(instr->context()).is(rsi)); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 5557 | CallCode(isolate()->builtins()->StackCheck(), |
| 5558 | RelocInfo::CODE_TARGET, |
| 5559 | instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5560 | __ bind(&done); |
| 5561 | } else { |
| 5562 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 5563 | // Perform stack overflow check if this goto needs it before jumping. |
| 5564 | DeferredStackCheck* deferred_stack_check = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5565 | new(zone()) DeferredStackCheck(this, instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5566 | __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 5567 | __ j(below, deferred_stack_check->entry()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5568 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5569 | __ bind(instr->done_label()); |
| 5570 | deferred_stack_check->SetExit(instr->done_label()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5571 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5572 | // Don't record a deoptimization index for the safepoint here. |
| 5573 | // This will be done explicitly when emitting call and the safepoint in |
| 5574 | // the deferred code. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5575 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | |
| 5579 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5580 | // This is a pseudo-instruction that ensures that the environment here is |
| 5581 | // properly registered for deoptimization and records the assembler's PC |
| 5582 | // offset. |
| 5583 | LEnvironment* environment = instr->environment(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5584 | |
| 5585 | // If the environment were already registered, we would have no way of |
| 5586 | // backpatching it with the spill slot operands. |
| 5587 | ASSERT(!environment->HasBeenRegistered()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5588 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5589 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 5590 | GenerateOsrPrologue(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5591 | } |
| 5592 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5593 | |
| 5594 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5595 | ASSERT(ToRegister(instr->context()).is(rsi)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5596 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 5597 | DeoptimizeIf(equal, instr->environment()); |
| 5598 | |
| 5599 | Register null_value = rdi; |
| 5600 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 5601 | __ cmpp(rax, null_value); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5602 | DeoptimizeIf(equal, instr->environment()); |
| 5603 | |
| 5604 | Condition cc = masm()->CheckSmi(rax); |
| 5605 | DeoptimizeIf(cc, instr->environment()); |
| 5606 | |
| 5607 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5608 | __ CmpObjectType(rax, LAST_JS_PROXY_TYPE, rcx); |
| 5609 | DeoptimizeIf(below_equal, instr->environment()); |
| 5610 | |
| 5611 | Label use_cache, call_runtime; |
| 5612 | __ CheckEnumCache(null_value, &call_runtime); |
| 5613 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5614 | __ movp(rax, FieldOperand(rax, HeapObject::kMapOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5615 | __ jmp(&use_cache, Label::kNear); |
| 5616 | |
| 5617 | // Get the set of properties to enumerate. |
| 5618 | __ bind(&call_runtime); |
machenbach@chromium.org | 763da4c | 2014-03-19 10:48:37 +0000 | [diff] [blame] | 5619 | __ Push(rax); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5620 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5621 | |
| 5622 | __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 5623 | Heap::kMetaMapRootIndex); |
| 5624 | DeoptimizeIf(not_equal, instr->environment()); |
| 5625 | __ bind(&use_cache); |
| 5626 | } |
| 5627 | |
| 5628 | |
| 5629 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5630 | Register map = ToRegister(instr->map()); |
| 5631 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5632 | Label load_cache, done; |
| 5633 | __ EnumLength(result, map); |
| 5634 | __ Cmp(result, Smi::FromInt(0)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5635 | __ j(not_equal, &load_cache, Label::kNear); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5636 | __ LoadRoot(result, Heap::kEmptyFixedArrayRootIndex); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5637 | __ jmp(&done, Label::kNear); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5638 | __ bind(&load_cache); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5639 | __ LoadInstanceDescriptors(map, result); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5640 | __ movp(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 5641 | FieldOperand(result, DescriptorArray::kEnumCacheOffset)); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5642 | __ movp(result, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5643 | FieldOperand(result, FixedArray::SizeFor(instr->idx()))); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5644 | __ bind(&done); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5645 | Condition cc = masm()->CheckSmi(result); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 5646 | DeoptimizeIf(cc, instr->environment()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | |
| 5650 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5651 | Register object = ToRegister(instr->value()); |
machenbach@chromium.org | 7a1bfbe | 2014-03-26 12:42:48 +0000 | [diff] [blame] | 5652 | __ cmpp(ToRegister(instr->map()), |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5653 | FieldOperand(object, HeapObject::kMapOffset)); |
| 5654 | DeoptimizeIf(not_equal, instr->environment()); |
| 5655 | } |
| 5656 | |
| 5657 | |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 5658 | void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, |
| 5659 | Register object, |
| 5660 | Register index) { |
| 5661 | PushSafepointRegistersScope scope(this); |
| 5662 | __ Push(object); |
| 5663 | __ Push(index); |
| 5664 | __ xorp(rsi, rsi); |
| 5665 | __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); |
| 5666 | RecordSafepointWithRegisters( |
| 5667 | instr->pointer_map(), 2, Safepoint::kNoLazyDeopt); |
| 5668 | __ StoreToSafepointRegisterSlot(object, rax); |
| 5669 | } |
| 5670 | |
| 5671 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5672 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 5673 | class DeferredLoadMutableDouble V8_FINAL : public LDeferredCode { |
| 5674 | public: |
| 5675 | DeferredLoadMutableDouble(LCodeGen* codegen, |
| 5676 | LLoadFieldByIndex* instr, |
| 5677 | Register object, |
| 5678 | Register index) |
| 5679 | : LDeferredCode(codegen), |
| 5680 | instr_(instr), |
| 5681 | object_(object), |
| 5682 | index_(index) { |
| 5683 | } |
| 5684 | virtual void Generate() V8_OVERRIDE { |
| 5685 | codegen()->DoDeferredLoadMutableDouble(instr_, object_, index_); |
| 5686 | } |
| 5687 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 5688 | private: |
| 5689 | LLoadFieldByIndex* instr_; |
| 5690 | Register object_; |
| 5691 | Register index_; |
| 5692 | }; |
| 5693 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5694 | Register object = ToRegister(instr->object()); |
| 5695 | Register index = ToRegister(instr->index()); |
| 5696 | |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 5697 | DeferredLoadMutableDouble* deferred; |
| 5698 | deferred = new(zone()) DeferredLoadMutableDouble(this, instr, object, index); |
| 5699 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5700 | Label out_of_object, done; |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 5701 | __ Move(kScratchRegister, Smi::FromInt(1)); |
| 5702 | __ testp(index, kScratchRegister); |
| 5703 | __ j(not_zero, deferred->entry()); |
| 5704 | |
| 5705 | __ sarp(index, Immediate(1)); |
| 5706 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5707 | __ SmiToInteger32(index, index); |
| 5708 | __ cmpl(index, Immediate(0)); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5709 | __ j(less, &out_of_object, Label::kNear); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5710 | __ movp(object, FieldOperand(object, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5711 | index, |
| 5712 | times_pointer_size, |
| 5713 | JSObject::kHeaderSize)); |
| 5714 | __ jmp(&done, Label::kNear); |
| 5715 | |
| 5716 | __ bind(&out_of_object); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5717 | __ movp(object, FieldOperand(object, JSObject::kPropertiesOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5718 | __ negl(index); |
| 5719 | // Index is now equal to out of object property index plus 1. |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 5720 | __ movp(object, FieldOperand(object, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5721 | index, |
| 5722 | times_pointer_size, |
| 5723 | FixedArray::kHeaderSize - kPointerSize)); |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 5724 | __ bind(deferred->exit()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5725 | __ bind(&done); |
| 5726 | } |
| 5727 | |
| 5728 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5729 | #undef __ |
| 5730 | |
| 5731 | } } // namespace v8::internal |
| 5732 | |
| 5733 | #endif // V8_TARGET_ARCH_X64 |