sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
| 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "ia32/lithium-codegen-ia32.h" |
| 33 | #include "code-stubs.h" |
| 34 | #include "stub-cache.h" |
| 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
| 39 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 40 | // When invoking builtins, we need to record the safepoint in the middle of |
| 41 | // the invoke instruction sequence generated by the macro assembler. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 42 | class SafepointGenerator : public PostCallGenerator { |
| 43 | public: |
| 44 | SafepointGenerator(LCodeGen* codegen, |
| 45 | LPointerMap* pointers, |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 46 | int deoptimization_index, |
| 47 | bool ensure_reloc_space = false) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 48 | : codegen_(codegen), |
| 49 | pointers_(pointers), |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 50 | deoptimization_index_(deoptimization_index), |
| 51 | ensure_reloc_space_(ensure_reloc_space) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 52 | virtual ~SafepointGenerator() { } |
| 53 | |
| 54 | virtual void Generate() { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 55 | // Ensure that we have enough space in the reloc info to patch |
| 56 | // this with calls when doing deoptimization. |
| 57 | if (ensure_reloc_space_) { |
| 58 | codegen_->masm()->RecordComment(RelocInfo::kFillerCommentString, true); |
| 59 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 60 | codegen_->RecordSafepoint(pointers_, deoptimization_index_); |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | LCodeGen* codegen_; |
| 65 | LPointerMap* pointers_; |
| 66 | int deoptimization_index_; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 67 | bool ensure_reloc_space_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | |
| 71 | #define __ masm()-> |
| 72 | |
| 73 | bool LCodeGen::GenerateCode() { |
| 74 | HPhase phase("Code generation", chunk()); |
| 75 | ASSERT(is_unused()); |
| 76 | status_ = GENERATING; |
| 77 | CpuFeatures::Scope scope(SSE2); |
| 78 | return GeneratePrologue() && |
| 79 | GenerateBody() && |
| 80 | GenerateDeferredCode() && |
| 81 | GenerateSafepointTable(); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 86 | ASSERT(is_done()); |
| 87 | code->set_stack_slots(StackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 88 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 89 | PopulateDeoptimizationData(code); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void LCodeGen::Abort(const char* format, ...) { |
| 94 | if (FLAG_trace_bailout) { |
| 95 | SmartPointer<char> debug_name = graph()->debug_name()->ToCString(); |
| 96 | PrintF("Aborting LCodeGen in @\"%s\": ", *debug_name); |
| 97 | va_list arguments; |
| 98 | va_start(arguments, format); |
| 99 | OS::VPrint(format, arguments); |
| 100 | va_end(arguments); |
| 101 | PrintF("\n"); |
| 102 | } |
| 103 | status_ = ABORTED; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | void LCodeGen::Comment(const char* format, ...) { |
| 108 | if (!FLAG_code_comments) return; |
| 109 | char buffer[4 * KB]; |
| 110 | StringBuilder builder(buffer, ARRAY_SIZE(buffer)); |
| 111 | va_list arguments; |
| 112 | va_start(arguments, format); |
| 113 | builder.AddFormattedList(format, arguments); |
| 114 | va_end(arguments); |
| 115 | |
| 116 | // Copy the string before recording it in the assembler to avoid |
| 117 | // issues when the stack allocated buffer goes out of scope. |
| 118 | size_t length = builder.position(); |
| 119 | Vector<char> copy = Vector<char>::New(length + 1); |
| 120 | memcpy(copy.start(), builder.Finalize(), copy.length()); |
| 121 | masm()->RecordComment(copy.start()); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | bool LCodeGen::GeneratePrologue() { |
| 126 | ASSERT(is_generating()); |
| 127 | |
| 128 | #ifdef DEBUG |
| 129 | if (strlen(FLAG_stop_at) > 0 && |
| 130 | info_->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 131 | __ int3(); |
| 132 | } |
| 133 | #endif |
| 134 | |
| 135 | __ push(ebp); // Caller's frame pointer. |
| 136 | __ mov(ebp, esp); |
| 137 | __ push(esi); // Callee's context. |
| 138 | __ push(edi); // Callee's JS function. |
| 139 | |
| 140 | // Reserve space for the stack slots needed by the code. |
| 141 | int slots = StackSlotCount(); |
| 142 | if (slots > 0) { |
| 143 | if (FLAG_debug_code) { |
| 144 | __ mov(Operand(eax), Immediate(slots)); |
| 145 | Label loop; |
| 146 | __ bind(&loop); |
| 147 | __ push(Immediate(kSlotsZapValue)); |
| 148 | __ dec(eax); |
| 149 | __ j(not_zero, &loop); |
| 150 | } else { |
| 151 | __ sub(Operand(esp), Immediate(slots * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 152 | #ifdef _MSC_VER |
| 153 | // On windows, you may not access the stack more than one page below |
| 154 | // the most recently mapped page. To make the allocated area randomly |
| 155 | // accessible, we write to each page in turn (the value is irrelevant). |
| 156 | const int kPageSize = 4 * KB; |
| 157 | for (int offset = slots * kPointerSize - kPageSize; |
| 158 | offset > 0; |
| 159 | offset -= kPageSize) { |
| 160 | __ mov(Operand(esp, offset), eax); |
| 161 | } |
| 162 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | // Trace the call. |
| 167 | if (FLAG_trace) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 168 | // We have not executed any compiled code yet, so esi still holds the |
| 169 | // incoming context. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 170 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 171 | } |
| 172 | return !is_aborted(); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | bool LCodeGen::GenerateBody() { |
| 177 | ASSERT(is_generating()); |
| 178 | bool emit_instructions = true; |
| 179 | for (current_instruction_ = 0; |
| 180 | !is_aborted() && current_instruction_ < instructions_->length(); |
| 181 | current_instruction_++) { |
| 182 | LInstruction* instr = instructions_->at(current_instruction_); |
| 183 | if (instr->IsLabel()) { |
| 184 | LLabel* label = LLabel::cast(instr); |
| 185 | emit_instructions = !label->HasReplacement(); |
| 186 | } |
| 187 | |
| 188 | if (emit_instructions) { |
| 189 | Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); |
| 190 | instr->CompileToNative(this); |
| 191 | } |
| 192 | } |
| 193 | return !is_aborted(); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | LInstruction* LCodeGen::GetNextInstruction() { |
| 198 | if (current_instruction_ < instructions_->length() - 1) { |
| 199 | return instructions_->at(current_instruction_ + 1); |
| 200 | } else { |
| 201 | return NULL; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | |
| 206 | bool LCodeGen::GenerateDeferredCode() { |
| 207 | ASSERT(is_generating()); |
| 208 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 209 | LDeferredCode* code = deferred_[i]; |
| 210 | __ bind(code->entry()); |
| 211 | code->Generate(); |
| 212 | __ jmp(code->exit()); |
| 213 | } |
| 214 | |
| 215 | // Deferred code is the last part of the instruction sequence. Mark |
| 216 | // the generated code as done unless we bailed out. |
| 217 | if (!is_aborted()) status_ = DONE; |
| 218 | return !is_aborted(); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | bool LCodeGen::GenerateSafepointTable() { |
| 223 | ASSERT(is_done()); |
| 224 | safepoints_.Emit(masm(), StackSlotCount()); |
| 225 | return !is_aborted(); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | Register LCodeGen::ToRegister(int index) const { |
| 230 | return Register::FromAllocationIndex(index); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | XMMRegister LCodeGen::ToDoubleRegister(int index) const { |
| 235 | return XMMRegister::FromAllocationIndex(index); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 240 | ASSERT(op->IsRegister()); |
| 241 | return ToRegister(op->index()); |
| 242 | } |
| 243 | |
| 244 | |
| 245 | XMMRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 246 | ASSERT(op->IsDoubleRegister()); |
| 247 | return ToDoubleRegister(op->index()); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | int LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 252 | Handle<Object> value = chunk_->LookupLiteral(op); |
| 253 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); |
| 254 | ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == |
| 255 | value->Number()); |
| 256 | return static_cast<int32_t>(value->Number()); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | Immediate LCodeGen::ToImmediate(LOperand* op) { |
| 261 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 262 | Handle<Object> literal = chunk_->LookupLiteral(const_op); |
| 263 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 264 | if (r.IsInteger32()) { |
| 265 | ASSERT(literal->IsNumber()); |
| 266 | return Immediate(static_cast<int32_t>(literal->Number())); |
| 267 | } else if (r.IsDouble()) { |
| 268 | Abort("unsupported double immediate"); |
| 269 | } |
| 270 | ASSERT(r.IsTagged()); |
| 271 | return Immediate(literal); |
| 272 | } |
| 273 | |
| 274 | |
| 275 | Operand LCodeGen::ToOperand(LOperand* op) const { |
| 276 | if (op->IsRegister()) return Operand(ToRegister(op)); |
| 277 | if (op->IsDoubleRegister()) return Operand(ToDoubleRegister(op)); |
| 278 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
| 279 | int index = op->index(); |
| 280 | if (index >= 0) { |
| 281 | // Local or spill slot. Skip the frame pointer, function, and |
| 282 | // context in the fixed part of the frame. |
| 283 | return Operand(ebp, -(index + 3) * kPointerSize); |
| 284 | } else { |
| 285 | // Incoming parameter. Skip the return address. |
| 286 | return Operand(ebp, -(index - 1) * kPointerSize); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 291 | Operand LCodeGen::HighOperand(LOperand* op) { |
| 292 | ASSERT(op->IsDoubleStackSlot()); |
| 293 | int index = op->index(); |
| 294 | int offset = (index >= 0) ? index + 3 : index - 1; |
| 295 | return Operand(ebp, -offset * kPointerSize); |
| 296 | } |
| 297 | |
| 298 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 299 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
| 300 | Translation* translation) { |
| 301 | if (environment == NULL) return; |
| 302 | |
| 303 | // The translation includes one command per value in the environment. |
| 304 | int translation_size = environment->values()->length(); |
| 305 | // The output frame height does not include the parameters. |
| 306 | int height = translation_size - environment->parameter_count(); |
| 307 | |
| 308 | WriteTranslation(environment->outer(), translation); |
| 309 | int closure_id = DefineDeoptimizationLiteral(environment->closure()); |
| 310 | translation->BeginFrame(environment->ast_id(), closure_id, height); |
| 311 | for (int i = 0; i < translation_size; ++i) { |
| 312 | LOperand* value = environment->values()->at(i); |
| 313 | // spilled_registers_ and spilled_double_registers_ are either |
| 314 | // both NULL or both set. |
| 315 | if (environment->spilled_registers() != NULL && value != NULL) { |
| 316 | if (value->IsRegister() && |
| 317 | environment->spilled_registers()[value->index()] != NULL) { |
| 318 | translation->MarkDuplicate(); |
| 319 | AddToTranslation(translation, |
| 320 | environment->spilled_registers()[value->index()], |
| 321 | environment->HasTaggedValueAt(i)); |
| 322 | } else if ( |
| 323 | value->IsDoubleRegister() && |
| 324 | environment->spilled_double_registers()[value->index()] != NULL) { |
| 325 | translation->MarkDuplicate(); |
| 326 | AddToTranslation( |
| 327 | translation, |
| 328 | environment->spilled_double_registers()[value->index()], |
| 329 | false); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | AddToTranslation(translation, value, environment->HasTaggedValueAt(i)); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 338 | void LCodeGen::AddToTranslation(Translation* translation, |
| 339 | LOperand* op, |
| 340 | bool is_tagged) { |
| 341 | if (op == NULL) { |
| 342 | // TODO(twuerthinger): Introduce marker operands to indicate that this value |
| 343 | // is not present and must be reconstructed from the deoptimizer. Currently |
| 344 | // this is only used for the arguments object. |
| 345 | translation->StoreArgumentsObject(); |
| 346 | } else if (op->IsStackSlot()) { |
| 347 | if (is_tagged) { |
| 348 | translation->StoreStackSlot(op->index()); |
| 349 | } else { |
| 350 | translation->StoreInt32StackSlot(op->index()); |
| 351 | } |
| 352 | } else if (op->IsDoubleStackSlot()) { |
| 353 | translation->StoreDoubleStackSlot(op->index()); |
| 354 | } else if (op->IsArgument()) { |
| 355 | ASSERT(is_tagged); |
| 356 | int src_index = StackSlotCount() + op->index(); |
| 357 | translation->StoreStackSlot(src_index); |
| 358 | } else if (op->IsRegister()) { |
| 359 | Register reg = ToRegister(op); |
| 360 | if (is_tagged) { |
| 361 | translation->StoreRegister(reg); |
| 362 | } else { |
| 363 | translation->StoreInt32Register(reg); |
| 364 | } |
| 365 | } else if (op->IsDoubleRegister()) { |
| 366 | XMMRegister reg = ToDoubleRegister(op); |
| 367 | translation->StoreDoubleRegister(reg); |
| 368 | } else if (op->IsConstantOperand()) { |
| 369 | Handle<Object> literal = chunk()->LookupLiteral(LConstantOperand::cast(op)); |
| 370 | int src_index = DefineDeoptimizationLiteral(literal); |
| 371 | translation->StoreLiteral(src_index); |
| 372 | } else { |
| 373 | UNREACHABLE(); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | |
| 378 | void LCodeGen::CallCode(Handle<Code> code, |
| 379 | RelocInfo::Mode mode, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 380 | LInstruction* instr, |
| 381 | bool adjusted) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 382 | ASSERT(instr != NULL); |
| 383 | LPointerMap* pointers = instr->pointer_map(); |
| 384 | RecordPosition(pointers->position()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 385 | if (!adjusted) { |
| 386 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 387 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 388 | __ call(code, mode); |
| 389 | RegisterLazyDeoptimization(instr); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 390 | |
| 391 | // Signal that we don't inline smi code before these stubs in the |
| 392 | // optimizing code generator. |
| 393 | if (code->kind() == Code::TYPE_RECORDING_BINARY_OP_IC || |
| 394 | code->kind() == Code::COMPARE_IC) { |
| 395 | __ nop(); |
| 396 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 400 | void LCodeGen::CallRuntime(Runtime::Function* fun, |
| 401 | int argc, |
| 402 | LInstruction* instr, |
| 403 | bool adjusted) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 404 | ASSERT(instr != NULL); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 405 | ASSERT(instr->HasPointerMap()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 406 | LPointerMap* pointers = instr->pointer_map(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 407 | RecordPosition(pointers->position()); |
| 408 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 409 | if (!adjusted) { |
| 410 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 411 | } |
| 412 | __ CallRuntime(fun, argc); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 413 | RegisterLazyDeoptimization(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
| 417 | void LCodeGen::RegisterLazyDeoptimization(LInstruction* instr) { |
| 418 | // Create the environment to bailout to. If the call has side effects |
| 419 | // execution has to continue after the call otherwise execution can continue |
| 420 | // from a previous bailout point repeating the call. |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 421 | LEnvironment* deoptimization_environment; |
| 422 | if (instr->HasDeoptimizationEnvironment()) { |
| 423 | deoptimization_environment = instr->deoptimization_environment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 424 | } else { |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 425 | deoptimization_environment = instr->environment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 426 | } |
| 427 | |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 428 | RegisterEnvironmentForDeoptimization(deoptimization_environment); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 429 | RecordSafepoint(instr->pointer_map(), |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 430 | deoptimization_environment->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | |
| 434 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment) { |
| 435 | if (!environment->HasBeenRegistered()) { |
| 436 | // Physical stack frame layout: |
| 437 | // -x ............. -4 0 ..................................... y |
| 438 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 439 | |
| 440 | // Layout of the environment: |
| 441 | // 0 ..................................................... size-1 |
| 442 | // [parameters] [locals] [expression stack including arguments] |
| 443 | |
| 444 | // Layout of the translation: |
| 445 | // 0 ........................................................ size - 1 + 4 |
| 446 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 447 | // |>------------ translation_size ------------<| |
| 448 | |
| 449 | int frame_count = 0; |
| 450 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 451 | ++frame_count; |
| 452 | } |
| 453 | Translation translation(&translations_, frame_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 454 | WriteTranslation(environment, &translation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 455 | int deoptimization_index = deoptimizations_.length(); |
| 456 | environment->Register(deoptimization_index, translation.index()); |
| 457 | deoptimizations_.Add(environment); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | |
| 462 | void LCodeGen::DeoptimizeIf(Condition cc, LEnvironment* environment) { |
| 463 | RegisterEnvironmentForDeoptimization(environment); |
| 464 | ASSERT(environment->HasBeenRegistered()); |
| 465 | int id = environment->deoptimization_index(); |
| 466 | Address entry = Deoptimizer::GetDeoptimizationEntry(id, Deoptimizer::EAGER); |
| 467 | ASSERT(entry != NULL); |
| 468 | if (entry == NULL) { |
| 469 | Abort("bailout was not prepared"); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | if (FLAG_deopt_every_n_times != 0) { |
| 474 | Handle<SharedFunctionInfo> shared(info_->shared_info()); |
| 475 | Label no_deopt; |
| 476 | __ pushfd(); |
| 477 | __ push(eax); |
| 478 | __ push(ebx); |
| 479 | __ mov(ebx, shared); |
| 480 | __ mov(eax, FieldOperand(ebx, SharedFunctionInfo::kDeoptCounterOffset)); |
| 481 | __ sub(Operand(eax), Immediate(Smi::FromInt(1))); |
| 482 | __ j(not_zero, &no_deopt); |
| 483 | if (FLAG_trap_on_deopt) __ int3(); |
| 484 | __ mov(eax, Immediate(Smi::FromInt(FLAG_deopt_every_n_times))); |
| 485 | __ mov(FieldOperand(ebx, SharedFunctionInfo::kDeoptCounterOffset), eax); |
| 486 | __ pop(ebx); |
| 487 | __ pop(eax); |
| 488 | __ popfd(); |
| 489 | __ jmp(entry, RelocInfo::RUNTIME_ENTRY); |
| 490 | |
| 491 | __ bind(&no_deopt); |
| 492 | __ mov(FieldOperand(ebx, SharedFunctionInfo::kDeoptCounterOffset), eax); |
| 493 | __ pop(ebx); |
| 494 | __ pop(eax); |
| 495 | __ popfd(); |
| 496 | } |
| 497 | |
| 498 | if (cc == no_condition) { |
| 499 | if (FLAG_trap_on_deopt) __ int3(); |
| 500 | __ jmp(entry, RelocInfo::RUNTIME_ENTRY); |
| 501 | } else { |
| 502 | if (FLAG_trap_on_deopt) { |
| 503 | NearLabel done; |
| 504 | __ j(NegateCondition(cc), &done); |
| 505 | __ int3(); |
| 506 | __ jmp(entry, RelocInfo::RUNTIME_ENTRY); |
| 507 | __ bind(&done); |
| 508 | } else { |
| 509 | __ j(cc, entry, RelocInfo::RUNTIME_ENTRY, not_taken); |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | |
| 515 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 516 | int length = deoptimizations_.length(); |
| 517 | if (length == 0) return; |
| 518 | ASSERT(FLAG_deopt); |
| 519 | Handle<DeoptimizationInputData> data = |
| 520 | Factory::NewDeoptimizationInputData(length, TENURED); |
| 521 | |
| 522 | data->SetTranslationByteArray(*translations_.CreateByteArray()); |
| 523 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 524 | |
| 525 | Handle<FixedArray> literals = |
| 526 | Factory::NewFixedArray(deoptimization_literals_.length(), TENURED); |
| 527 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 528 | literals->set(i, *deoptimization_literals_[i]); |
| 529 | } |
| 530 | data->SetLiteralArray(*literals); |
| 531 | |
| 532 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id())); |
| 533 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 534 | |
| 535 | // Populate the deoptimization entries. |
| 536 | for (int i = 0; i < length; i++) { |
| 537 | LEnvironment* env = deoptimizations_[i]; |
| 538 | data->SetAstId(i, Smi::FromInt(env->ast_id())); |
| 539 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 540 | data->SetArgumentsStackHeight(i, |
| 541 | Smi::FromInt(env->arguments_stack_height())); |
| 542 | } |
| 543 | code->set_deoptimization_data(*data); |
| 544 | } |
| 545 | |
| 546 | |
| 547 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 548 | int result = deoptimization_literals_.length(); |
| 549 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 550 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 551 | } |
| 552 | deoptimization_literals_.Add(literal); |
| 553 | return result; |
| 554 | } |
| 555 | |
| 556 | |
| 557 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 558 | ASSERT(deoptimization_literals_.length() == 0); |
| 559 | |
| 560 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 561 | chunk()->inlined_closures(); |
| 562 | |
| 563 | for (int i = 0, length = inlined_closures->length(); |
| 564 | i < length; |
| 565 | i++) { |
| 566 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 567 | } |
| 568 | |
| 569 | inlined_function_count_ = deoptimization_literals_.length(); |
| 570 | } |
| 571 | |
| 572 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 573 | void LCodeGen::RecordSafepoint( |
| 574 | LPointerMap* pointers, |
| 575 | Safepoint::Kind kind, |
| 576 | int arguments, |
| 577 | int deoptimization_index) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 578 | const ZoneList<LOperand*>* operands = pointers->operands(); |
| 579 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 580 | kind, arguments, deoptimization_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 581 | for (int i = 0; i < operands->length(); i++) { |
| 582 | LOperand* pointer = operands->at(i); |
| 583 | if (pointer->IsStackSlot()) { |
| 584 | safepoint.DefinePointerSlot(pointer->index()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 585 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
| 586 | safepoint.DefinePointerRegister(ToRegister(pointer)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 587 | } |
| 588 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
| 592 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
| 593 | int deoptimization_index) { |
| 594 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
| 598 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 599 | int arguments, |
| 600 | int deoptimization_index) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 601 | RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, |
| 602 | deoptimization_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
| 606 | void LCodeGen::RecordPosition(int position) { |
| 607 | if (!FLAG_debug_info || position == RelocInfo::kNoPosition) return; |
| 608 | masm()->positions_recorder()->RecordPosition(position); |
| 609 | } |
| 610 | |
| 611 | |
| 612 | void LCodeGen::DoLabel(LLabel* label) { |
| 613 | if (label->is_loop_header()) { |
| 614 | Comment(";;; B%d - LOOP entry", label->block_id()); |
| 615 | } else { |
| 616 | Comment(";;; B%d", label->block_id()); |
| 617 | } |
| 618 | __ bind(label->label()); |
| 619 | current_block_ = label->block_id(); |
| 620 | LCodeGen::DoGap(label); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 625 | resolver_.Resolve(move); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
| 629 | void LCodeGen::DoGap(LGap* gap) { |
| 630 | for (int i = LGap::FIRST_INNER_POSITION; |
| 631 | i <= LGap::LAST_INNER_POSITION; |
| 632 | i++) { |
| 633 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 634 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 635 | if (move != NULL) DoParallelMove(move); |
| 636 | } |
| 637 | |
| 638 | LInstruction* next = GetNextInstruction(); |
| 639 | if (next != NULL && next->IsLazyBailout()) { |
| 640 | int pc = masm()->pc_offset(); |
| 641 | safepoints_.SetPcAfterGap(pc); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | |
| 646 | void LCodeGen::DoParameter(LParameter* instr) { |
| 647 | // Nothing to do. |
| 648 | } |
| 649 | |
| 650 | |
| 651 | void LCodeGen::DoCallStub(LCallStub* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 652 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 653 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 654 | switch (instr->hydrogen()->major_key()) { |
| 655 | case CodeStub::RegExpConstructResult: { |
| 656 | RegExpConstructResultStub stub; |
| 657 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 658 | break; |
| 659 | } |
| 660 | case CodeStub::RegExpExec: { |
| 661 | RegExpExecStub stub; |
| 662 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 663 | break; |
| 664 | } |
| 665 | case CodeStub::SubString: { |
| 666 | SubStringStub stub; |
| 667 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 668 | break; |
| 669 | } |
| 670 | case CodeStub::StringCharAt: { |
| 671 | StringCharAtStub stub; |
| 672 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 673 | break; |
| 674 | } |
| 675 | case CodeStub::MathPow: { |
| 676 | MathPowStub stub; |
| 677 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 678 | break; |
| 679 | } |
| 680 | case CodeStub::NumberToString: { |
| 681 | NumberToStringStub stub; |
| 682 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 683 | break; |
| 684 | } |
| 685 | case CodeStub::StringAdd: { |
| 686 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 687 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 688 | break; |
| 689 | } |
| 690 | case CodeStub::StringCompare: { |
| 691 | StringCompareStub stub; |
| 692 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 693 | break; |
| 694 | } |
| 695 | case CodeStub::TranscendentalCache: { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 696 | TranscendentalCacheStub stub(instr->transcendental_type(), |
| 697 | TranscendentalCacheStub::TAGGED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 698 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 699 | break; |
| 700 | } |
| 701 | default: |
| 702 | UNREACHABLE(); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | |
| 707 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 708 | // Nothing to do. |
| 709 | } |
| 710 | |
| 711 | |
| 712 | void LCodeGen::DoModI(LModI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 713 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 714 | ASSERT(ToRegister(instr->result()).is(edx)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 715 | ASSERT(ToRegister(instr->InputAt(0)).is(eax)); |
| 716 | ASSERT(!ToRegister(instr->InputAt(1)).is(eax)); |
| 717 | ASSERT(!ToRegister(instr->InputAt(1)).is(edx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 718 | |
| 719 | Register right_reg = ToRegister(right); |
| 720 | |
| 721 | // Check for x % 0. |
| 722 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 723 | __ test(right_reg, ToOperand(right)); |
| 724 | DeoptimizeIf(zero, instr->environment()); |
| 725 | } |
| 726 | |
| 727 | // Sign extend to edx. |
| 728 | __ cdq(); |
| 729 | |
| 730 | // Check for (0 % -x) that will produce negative zero. |
| 731 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 732 | NearLabel positive_left; |
| 733 | NearLabel done; |
| 734 | __ test(eax, Operand(eax)); |
| 735 | __ j(not_sign, &positive_left); |
| 736 | __ idiv(right_reg); |
| 737 | |
| 738 | // Test the remainder for 0, because then the result would be -0. |
| 739 | __ test(edx, Operand(edx)); |
| 740 | __ j(not_zero, &done); |
| 741 | |
| 742 | DeoptimizeIf(no_condition, instr->environment()); |
| 743 | __ bind(&positive_left); |
| 744 | __ idiv(right_reg); |
| 745 | __ bind(&done); |
| 746 | } else { |
| 747 | __ idiv(right_reg); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
| 752 | void LCodeGen::DoDivI(LDivI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 753 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 754 | ASSERT(ToRegister(instr->result()).is(eax)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 755 | ASSERT(ToRegister(instr->InputAt(0)).is(eax)); |
| 756 | ASSERT(!ToRegister(instr->InputAt(1)).is(eax)); |
| 757 | ASSERT(!ToRegister(instr->InputAt(1)).is(edx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 758 | |
| 759 | Register left_reg = eax; |
| 760 | |
| 761 | // Check for x / 0. |
| 762 | Register right_reg = ToRegister(right); |
| 763 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 764 | __ test(right_reg, ToOperand(right)); |
| 765 | DeoptimizeIf(zero, instr->environment()); |
| 766 | } |
| 767 | |
| 768 | // Check for (0 / -x) that will produce negative zero. |
| 769 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 770 | NearLabel left_not_zero; |
| 771 | __ test(left_reg, Operand(left_reg)); |
| 772 | __ j(not_zero, &left_not_zero); |
| 773 | __ test(right_reg, ToOperand(right)); |
| 774 | DeoptimizeIf(sign, instr->environment()); |
| 775 | __ bind(&left_not_zero); |
| 776 | } |
| 777 | |
| 778 | // Check for (-kMinInt / -1). |
| 779 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 780 | NearLabel left_not_min_int; |
| 781 | __ cmp(left_reg, kMinInt); |
| 782 | __ j(not_zero, &left_not_min_int); |
| 783 | __ cmp(right_reg, -1); |
| 784 | DeoptimizeIf(zero, instr->environment()); |
| 785 | __ bind(&left_not_min_int); |
| 786 | } |
| 787 | |
| 788 | // Sign extend to edx. |
| 789 | __ cdq(); |
| 790 | __ idiv(right_reg); |
| 791 | |
| 792 | // Deoptimize if remainder is not 0. |
| 793 | __ test(edx, Operand(edx)); |
| 794 | DeoptimizeIf(not_zero, instr->environment()); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | void LCodeGen::DoMulI(LMulI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 799 | Register left = ToRegister(instr->InputAt(0)); |
| 800 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 801 | |
| 802 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 803 | __ mov(ToRegister(instr->TempAt(0)), left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | if (right->IsConstantOperand()) { |
| 807 | __ imul(left, left, ToInteger32(LConstantOperand::cast(right))); |
| 808 | } else { |
| 809 | __ imul(left, ToOperand(right)); |
| 810 | } |
| 811 | |
| 812 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 813 | DeoptimizeIf(overflow, instr->environment()); |
| 814 | } |
| 815 | |
| 816 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 817 | // Bail out if the result is supposed to be negative zero. |
| 818 | NearLabel done; |
| 819 | __ test(left, Operand(left)); |
| 820 | __ j(not_zero, &done); |
| 821 | if (right->IsConstantOperand()) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 822 | if (ToInteger32(LConstantOperand::cast(right)) <= 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 823 | DeoptimizeIf(no_condition, instr->environment()); |
| 824 | } |
| 825 | } else { |
| 826 | // Test the non-zero operand for negative sign. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 827 | __ or_(ToRegister(instr->TempAt(0)), ToOperand(right)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 828 | DeoptimizeIf(sign, instr->environment()); |
| 829 | } |
| 830 | __ bind(&done); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | |
| 835 | void LCodeGen::DoBitI(LBitI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 836 | LOperand* left = instr->InputAt(0); |
| 837 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 838 | ASSERT(left->Equals(instr->result())); |
| 839 | ASSERT(left->IsRegister()); |
| 840 | |
| 841 | if (right->IsConstantOperand()) { |
| 842 | int right_operand = ToInteger32(LConstantOperand::cast(right)); |
| 843 | switch (instr->op()) { |
| 844 | case Token::BIT_AND: |
| 845 | __ and_(ToRegister(left), right_operand); |
| 846 | break; |
| 847 | case Token::BIT_OR: |
| 848 | __ or_(ToRegister(left), right_operand); |
| 849 | break; |
| 850 | case Token::BIT_XOR: |
| 851 | __ xor_(ToRegister(left), right_operand); |
| 852 | break; |
| 853 | default: |
| 854 | UNREACHABLE(); |
| 855 | break; |
| 856 | } |
| 857 | } else { |
| 858 | switch (instr->op()) { |
| 859 | case Token::BIT_AND: |
| 860 | __ and_(ToRegister(left), ToOperand(right)); |
| 861 | break; |
| 862 | case Token::BIT_OR: |
| 863 | __ or_(ToRegister(left), ToOperand(right)); |
| 864 | break; |
| 865 | case Token::BIT_XOR: |
| 866 | __ xor_(ToRegister(left), ToOperand(right)); |
| 867 | break; |
| 868 | default: |
| 869 | UNREACHABLE(); |
| 870 | break; |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | |
| 876 | void LCodeGen::DoShiftI(LShiftI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 877 | LOperand* left = instr->InputAt(0); |
| 878 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 879 | ASSERT(left->Equals(instr->result())); |
| 880 | ASSERT(left->IsRegister()); |
| 881 | if (right->IsRegister()) { |
| 882 | ASSERT(ToRegister(right).is(ecx)); |
| 883 | |
| 884 | switch (instr->op()) { |
| 885 | case Token::SAR: |
| 886 | __ sar_cl(ToRegister(left)); |
| 887 | break; |
| 888 | case Token::SHR: |
| 889 | __ shr_cl(ToRegister(left)); |
| 890 | if (instr->can_deopt()) { |
| 891 | __ test(ToRegister(left), Immediate(0x80000000)); |
| 892 | DeoptimizeIf(not_zero, instr->environment()); |
| 893 | } |
| 894 | break; |
| 895 | case Token::SHL: |
| 896 | __ shl_cl(ToRegister(left)); |
| 897 | break; |
| 898 | default: |
| 899 | UNREACHABLE(); |
| 900 | break; |
| 901 | } |
| 902 | } else { |
| 903 | int value = ToInteger32(LConstantOperand::cast(right)); |
| 904 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 905 | switch (instr->op()) { |
| 906 | case Token::SAR: |
| 907 | if (shift_count != 0) { |
| 908 | __ sar(ToRegister(left), shift_count); |
| 909 | } |
| 910 | break; |
| 911 | case Token::SHR: |
| 912 | if (shift_count == 0 && instr->can_deopt()) { |
| 913 | __ test(ToRegister(left), Immediate(0x80000000)); |
| 914 | DeoptimizeIf(not_zero, instr->environment()); |
| 915 | } else { |
| 916 | __ shr(ToRegister(left), shift_count); |
| 917 | } |
| 918 | break; |
| 919 | case Token::SHL: |
| 920 | if (shift_count != 0) { |
| 921 | __ shl(ToRegister(left), shift_count); |
| 922 | } |
| 923 | break; |
| 924 | default: |
| 925 | UNREACHABLE(); |
| 926 | break; |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | |
| 932 | void LCodeGen::DoSubI(LSubI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 933 | LOperand* left = instr->InputAt(0); |
| 934 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 935 | ASSERT(left->Equals(instr->result())); |
| 936 | |
| 937 | if (right->IsConstantOperand()) { |
| 938 | __ sub(ToOperand(left), ToImmediate(right)); |
| 939 | } else { |
| 940 | __ sub(ToRegister(left), ToOperand(right)); |
| 941 | } |
| 942 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 943 | DeoptimizeIf(overflow, instr->environment()); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | |
| 948 | void LCodeGen::DoConstantI(LConstantI* instr) { |
| 949 | ASSERT(instr->result()->IsRegister()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 950 | __ Set(ToRegister(instr->result()), Immediate(instr->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | |
| 954 | void LCodeGen::DoConstantD(LConstantD* instr) { |
| 955 | ASSERT(instr->result()->IsDoubleRegister()); |
| 956 | XMMRegister res = ToDoubleRegister(instr->result()); |
| 957 | double v = instr->value(); |
| 958 | // Use xor to produce +0.0 in a fast and compact way, but avoid to |
| 959 | // do so if the constant is -0.0. |
| 960 | if (BitCast<uint64_t, double>(v) == 0) { |
| 961 | __ xorpd(res, res); |
| 962 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 963 | Register temp = ToRegister(instr->TempAt(0)); |
| 964 | uint64_t int_val = BitCast<uint64_t, double>(v); |
| 965 | int32_t lower = static_cast<int32_t>(int_val); |
| 966 | int32_t upper = static_cast<int32_t>(int_val >> (kBitsPerInt)); |
| 967 | if (CpuFeatures::IsSupported(SSE4_1)) { |
| 968 | CpuFeatures::Scope scope(SSE4_1); |
| 969 | if (lower != 0) { |
| 970 | __ Set(temp, Immediate(lower)); |
| 971 | __ movd(res, Operand(temp)); |
| 972 | __ Set(temp, Immediate(upper)); |
| 973 | __ pinsrd(res, Operand(temp), 1); |
| 974 | } else { |
| 975 | __ xorpd(res, res); |
| 976 | __ Set(temp, Immediate(upper)); |
| 977 | __ pinsrd(res, Operand(temp), 1); |
| 978 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 979 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 980 | __ Set(temp, Immediate(upper)); |
| 981 | __ movd(res, Operand(temp)); |
| 982 | __ psllq(res, 32); |
| 983 | if (lower != 0) { |
| 984 | __ Set(temp, Immediate(lower)); |
| 985 | __ movd(xmm0, Operand(temp)); |
| 986 | __ por(res, xmm0); |
| 987 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | |
| 993 | void LCodeGen::DoConstantT(LConstantT* instr) { |
| 994 | ASSERT(instr->result()->IsRegister()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 995 | __ Set(ToRegister(instr->result()), Immediate(instr->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 999 | void LCodeGen::DoJSArrayLength(LJSArrayLength* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1000 | Register result = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1001 | Register array = ToRegister(instr->InputAt(0)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1002 | __ mov(result, FieldOperand(array, JSArray::kLengthOffset)); |
| 1003 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1004 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1005 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1006 | void LCodeGen::DoFixedArrayLength(LFixedArrayLength* instr) { |
| 1007 | Register result = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1008 | Register array = ToRegister(instr->InputAt(0)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1009 | __ mov(result, FieldOperand(array, FixedArray::kLengthOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1013 | void LCodeGen::DoPixelArrayLength(LPixelArrayLength* instr) { |
| 1014 | Register result = ToRegister(instr->result()); |
| 1015 | Register array = ToRegister(instr->InputAt(0)); |
| 1016 | __ mov(result, FieldOperand(array, PixelArray::kLengthOffset)); |
| 1017 | } |
| 1018 | |
| 1019 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1020 | void LCodeGen::DoValueOf(LValueOf* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1021 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1022 | Register result = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1023 | Register map = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1024 | ASSERT(input.is(result)); |
| 1025 | NearLabel done; |
| 1026 | // If the object is a smi return the object. |
| 1027 | __ test(input, Immediate(kSmiTagMask)); |
| 1028 | __ j(zero, &done); |
| 1029 | |
| 1030 | // If the object is not a value type, return the object. |
| 1031 | __ CmpObjectType(input, JS_VALUE_TYPE, map); |
| 1032 | __ j(not_equal, &done); |
| 1033 | __ mov(result, FieldOperand(input, JSValue::kValueOffset)); |
| 1034 | |
| 1035 | __ bind(&done); |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | void LCodeGen::DoBitNotI(LBitNotI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1040 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | ASSERT(input->Equals(instr->result())); |
| 1042 | __ not_(ToRegister(input)); |
| 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | void LCodeGen::DoThrow(LThrow* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1047 | __ push(ToOperand(instr->InputAt(0))); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1048 | CallRuntime(Runtime::kThrow, 1, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1049 | |
| 1050 | if (FLAG_debug_code) { |
| 1051 | Comment("Unreachable code."); |
| 1052 | __ int3(); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | void LCodeGen::DoAddI(LAddI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1058 | LOperand* left = instr->InputAt(0); |
| 1059 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1060 | ASSERT(left->Equals(instr->result())); |
| 1061 | |
| 1062 | if (right->IsConstantOperand()) { |
| 1063 | __ add(ToOperand(left), ToImmediate(right)); |
| 1064 | } else { |
| 1065 | __ add(ToRegister(left), ToOperand(right)); |
| 1066 | } |
| 1067 | |
| 1068 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1069 | DeoptimizeIf(overflow, instr->environment()); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1075 | LOperand* left = instr->InputAt(0); |
| 1076 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1077 | // Modulo uses a fixed result register. |
| 1078 | ASSERT(instr->op() == Token::MOD || left->Equals(instr->result())); |
| 1079 | switch (instr->op()) { |
| 1080 | case Token::ADD: |
| 1081 | __ addsd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1082 | break; |
| 1083 | case Token::SUB: |
| 1084 | __ subsd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1085 | break; |
| 1086 | case Token::MUL: |
| 1087 | __ mulsd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1088 | break; |
| 1089 | case Token::DIV: |
| 1090 | __ divsd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1091 | break; |
| 1092 | case Token::MOD: { |
| 1093 | // Pass two doubles as arguments on the stack. |
| 1094 | __ PrepareCallCFunction(4, eax); |
| 1095 | __ movdbl(Operand(esp, 0 * kDoubleSize), ToDoubleRegister(left)); |
| 1096 | __ movdbl(Operand(esp, 1 * kDoubleSize), ToDoubleRegister(right)); |
| 1097 | __ CallCFunction(ExternalReference::double_fp_operation(Token::MOD), 4); |
| 1098 | |
| 1099 | // Return value is in st(0) on ia32. |
| 1100 | // Store it into the (fixed) result register. |
| 1101 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
| 1102 | __ fstp_d(Operand(esp, 0)); |
| 1103 | __ movdbl(ToDoubleRegister(instr->result()), Operand(esp, 0)); |
| 1104 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 1105 | break; |
| 1106 | } |
| 1107 | default: |
| 1108 | UNREACHABLE(); |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1115 | ASSERT(ToRegister(instr->InputAt(0)).is(edx)); |
| 1116 | ASSERT(ToRegister(instr->InputAt(1)).is(eax)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1117 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 1118 | |
| 1119 | TypeRecordingBinaryOpStub stub(instr->op(), NO_OVERWRITE); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1120 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | int LCodeGen::GetNextEmittedBlock(int block) { |
| 1125 | for (int i = block + 1; i < graph()->blocks()->length(); ++i) { |
| 1126 | LLabel* label = chunk_->GetLabel(i); |
| 1127 | if (!label->HasReplacement()) return i; |
| 1128 | } |
| 1129 | return -1; |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | void LCodeGen::EmitBranch(int left_block, int right_block, Condition cc) { |
| 1134 | int next_block = GetNextEmittedBlock(current_block_); |
| 1135 | right_block = chunk_->LookupDestination(right_block); |
| 1136 | left_block = chunk_->LookupDestination(left_block); |
| 1137 | |
| 1138 | if (right_block == left_block) { |
| 1139 | EmitGoto(left_block); |
| 1140 | } else if (left_block == next_block) { |
| 1141 | __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 1142 | } else if (right_block == next_block) { |
| 1143 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 1144 | } else { |
| 1145 | __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
| 1146 | __ jmp(chunk_->GetAssemblyLabel(right_block)); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | |
| 1151 | void LCodeGen::DoBranch(LBranch* instr) { |
| 1152 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1153 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1154 | |
| 1155 | Representation r = instr->hydrogen()->representation(); |
| 1156 | if (r.IsInteger32()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1157 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1158 | __ test(reg, Operand(reg)); |
| 1159 | EmitBranch(true_block, false_block, not_zero); |
| 1160 | } else if (r.IsDouble()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1161 | XMMRegister reg = ToDoubleRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1162 | __ xorpd(xmm0, xmm0); |
| 1163 | __ ucomisd(reg, xmm0); |
| 1164 | EmitBranch(true_block, false_block, not_equal); |
| 1165 | } else { |
| 1166 | ASSERT(r.IsTagged()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1167 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1168 | if (instr->hydrogen()->type().IsBoolean()) { |
| 1169 | __ cmp(reg, Factory::true_value()); |
| 1170 | EmitBranch(true_block, false_block, equal); |
| 1171 | } else { |
| 1172 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1173 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1174 | |
| 1175 | __ cmp(reg, Factory::undefined_value()); |
| 1176 | __ j(equal, false_label); |
| 1177 | __ cmp(reg, Factory::true_value()); |
| 1178 | __ j(equal, true_label); |
| 1179 | __ cmp(reg, Factory::false_value()); |
| 1180 | __ j(equal, false_label); |
| 1181 | __ test(reg, Operand(reg)); |
| 1182 | __ j(equal, false_label); |
| 1183 | __ test(reg, Immediate(kSmiTagMask)); |
| 1184 | __ j(zero, true_label); |
| 1185 | |
| 1186 | // Test for double values. Zero is false. |
| 1187 | NearLabel call_stub; |
| 1188 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 1189 | Factory::heap_number_map()); |
| 1190 | __ j(not_equal, &call_stub); |
| 1191 | __ fldz(); |
| 1192 | __ fld_d(FieldOperand(reg, HeapNumber::kValueOffset)); |
| 1193 | __ FCmp(); |
| 1194 | __ j(zero, false_label); |
| 1195 | __ jmp(true_label); |
| 1196 | |
| 1197 | // The conversion stub doesn't cause garbage collections so it's |
| 1198 | // safe to not record a safepoint after the call. |
| 1199 | __ bind(&call_stub); |
| 1200 | ToBooleanStub stub; |
| 1201 | __ pushad(); |
| 1202 | __ push(reg); |
| 1203 | __ CallStub(&stub); |
| 1204 | __ test(eax, Operand(eax)); |
| 1205 | __ popad(); |
| 1206 | EmitBranch(true_block, false_block, not_zero); |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | void LCodeGen::EmitGoto(int block, LDeferredCode* deferred_stack_check) { |
| 1213 | block = chunk_->LookupDestination(block); |
| 1214 | int next_block = GetNextEmittedBlock(current_block_); |
| 1215 | if (block != next_block) { |
| 1216 | // Perform stack overflow check if this goto needs it before jumping. |
| 1217 | if (deferred_stack_check != NULL) { |
| 1218 | ExternalReference stack_limit = |
| 1219 | ExternalReference::address_of_stack_limit(); |
| 1220 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 1221 | __ j(above_equal, chunk_->GetAssemblyLabel(block)); |
| 1222 | __ jmp(deferred_stack_check->entry()); |
| 1223 | deferred_stack_check->SetExit(chunk_->GetAssemblyLabel(block)); |
| 1224 | } else { |
| 1225 | __ jmp(chunk_->GetAssemblyLabel(block)); |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | void LCodeGen::DoDeferredStackCheck(LGoto* instr) { |
| 1232 | __ pushad(); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1233 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1234 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 1235 | RecordSafepointWithRegisters( |
| 1236 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 1237 | __ popad(); |
| 1238 | } |
| 1239 | |
| 1240 | void LCodeGen::DoGoto(LGoto* instr) { |
| 1241 | class DeferredStackCheck: public LDeferredCode { |
| 1242 | public: |
| 1243 | DeferredStackCheck(LCodeGen* codegen, LGoto* instr) |
| 1244 | : LDeferredCode(codegen), instr_(instr) { } |
| 1245 | virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } |
| 1246 | private: |
| 1247 | LGoto* instr_; |
| 1248 | }; |
| 1249 | |
| 1250 | DeferredStackCheck* deferred = NULL; |
| 1251 | if (instr->include_stack_check()) { |
| 1252 | deferred = new DeferredStackCheck(this, instr); |
| 1253 | } |
| 1254 | EmitGoto(instr->block_id(), deferred); |
| 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
| 1259 | Condition cond = no_condition; |
| 1260 | switch (op) { |
| 1261 | case Token::EQ: |
| 1262 | case Token::EQ_STRICT: |
| 1263 | cond = equal; |
| 1264 | break; |
| 1265 | case Token::LT: |
| 1266 | cond = is_unsigned ? below : less; |
| 1267 | break; |
| 1268 | case Token::GT: |
| 1269 | cond = is_unsigned ? above : greater; |
| 1270 | break; |
| 1271 | case Token::LTE: |
| 1272 | cond = is_unsigned ? below_equal : less_equal; |
| 1273 | break; |
| 1274 | case Token::GTE: |
| 1275 | cond = is_unsigned ? above_equal : greater_equal; |
| 1276 | break; |
| 1277 | case Token::IN: |
| 1278 | case Token::INSTANCEOF: |
| 1279 | default: |
| 1280 | UNREACHABLE(); |
| 1281 | } |
| 1282 | return cond; |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | void LCodeGen::EmitCmpI(LOperand* left, LOperand* right) { |
| 1287 | if (right->IsConstantOperand()) { |
| 1288 | __ cmp(ToOperand(left), ToImmediate(right)); |
| 1289 | } else { |
| 1290 | __ cmp(ToRegister(left), ToOperand(right)); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | void LCodeGen::DoCmpID(LCmpID* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1296 | LOperand* left = instr->InputAt(0); |
| 1297 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1298 | LOperand* result = instr->result(); |
| 1299 | |
| 1300 | NearLabel unordered; |
| 1301 | if (instr->is_double()) { |
| 1302 | // Don't base result on EFLAGS when a NaN is involved. Instead |
| 1303 | // jump to the unordered case, which produces a false value. |
| 1304 | __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1305 | __ j(parity_even, &unordered, not_taken); |
| 1306 | } else { |
| 1307 | EmitCmpI(left, right); |
| 1308 | } |
| 1309 | |
| 1310 | NearLabel done; |
| 1311 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1312 | __ mov(ToRegister(result), Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1313 | __ j(cc, &done); |
| 1314 | |
| 1315 | __ bind(&unordered); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1316 | __ mov(ToRegister(result), Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1317 | __ bind(&done); |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1322 | LOperand* left = instr->InputAt(0); |
| 1323 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1324 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1325 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1326 | |
| 1327 | if (instr->is_double()) { |
| 1328 | // Don't base result on EFLAGS when a NaN is involved. Instead |
| 1329 | // jump to the false block. |
| 1330 | __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1331 | __ j(parity_even, chunk_->GetAssemblyLabel(false_block)); |
| 1332 | } else { |
| 1333 | EmitCmpI(left, right); |
| 1334 | } |
| 1335 | |
| 1336 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
| 1337 | EmitBranch(true_block, false_block, cc); |
| 1338 | } |
| 1339 | |
| 1340 | |
| 1341 | void LCodeGen::DoCmpJSObjectEq(LCmpJSObjectEq* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1342 | Register left = ToRegister(instr->InputAt(0)); |
| 1343 | Register right = ToRegister(instr->InputAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1344 | Register result = ToRegister(instr->result()); |
| 1345 | |
| 1346 | __ cmp(left, Operand(right)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1347 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1348 | NearLabel done; |
| 1349 | __ j(equal, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1350 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1351 | __ bind(&done); |
| 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | void LCodeGen::DoCmpJSObjectEqAndBranch(LCmpJSObjectEqAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1356 | Register left = ToRegister(instr->InputAt(0)); |
| 1357 | Register right = ToRegister(instr->InputAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1358 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1359 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1360 | |
| 1361 | __ cmp(left, Operand(right)); |
| 1362 | EmitBranch(true_block, false_block, equal); |
| 1363 | } |
| 1364 | |
| 1365 | |
| 1366 | void LCodeGen::DoIsNull(LIsNull* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1367 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1368 | Register result = ToRegister(instr->result()); |
| 1369 | |
| 1370 | // TODO(fsc): If the expression is known to be a smi, then it's |
| 1371 | // definitely not null. Materialize false. |
| 1372 | |
| 1373 | __ cmp(reg, Factory::null_value()); |
| 1374 | if (instr->is_strict()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1375 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1376 | NearLabel done; |
| 1377 | __ j(equal, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1378 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1379 | __ bind(&done); |
| 1380 | } else { |
| 1381 | NearLabel true_value, false_value, done; |
| 1382 | __ j(equal, &true_value); |
| 1383 | __ cmp(reg, Factory::undefined_value()); |
| 1384 | __ j(equal, &true_value); |
| 1385 | __ test(reg, Immediate(kSmiTagMask)); |
| 1386 | __ j(zero, &false_value); |
| 1387 | // Check for undetectable objects by looking in the bit field in |
| 1388 | // the map. The object has already been smi checked. |
| 1389 | Register scratch = result; |
| 1390 | __ mov(scratch, FieldOperand(reg, HeapObject::kMapOffset)); |
| 1391 | __ movzx_b(scratch, FieldOperand(scratch, Map::kBitFieldOffset)); |
| 1392 | __ test(scratch, Immediate(1 << Map::kIsUndetectable)); |
| 1393 | __ j(not_zero, &true_value); |
| 1394 | __ bind(&false_value); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1395 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1396 | __ jmp(&done); |
| 1397 | __ bind(&true_value); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1398 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1399 | __ bind(&done); |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | void LCodeGen::DoIsNullAndBranch(LIsNullAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1405 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1406 | |
| 1407 | // TODO(fsc): If the expression is known to be a smi, then it's |
| 1408 | // definitely not null. Jump to the false block. |
| 1409 | |
| 1410 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1411 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1412 | |
| 1413 | __ cmp(reg, Factory::null_value()); |
| 1414 | if (instr->is_strict()) { |
| 1415 | EmitBranch(true_block, false_block, equal); |
| 1416 | } else { |
| 1417 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1418 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1419 | __ j(equal, true_label); |
| 1420 | __ cmp(reg, Factory::undefined_value()); |
| 1421 | __ j(equal, true_label); |
| 1422 | __ test(reg, Immediate(kSmiTagMask)); |
| 1423 | __ j(zero, false_label); |
| 1424 | // Check for undetectable objects by looking in the bit field in |
| 1425 | // the map. The object has already been smi checked. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1426 | Register scratch = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1427 | __ mov(scratch, FieldOperand(reg, HeapObject::kMapOffset)); |
| 1428 | __ movzx_b(scratch, FieldOperand(scratch, Map::kBitFieldOffset)); |
| 1429 | __ test(scratch, Immediate(1 << Map::kIsUndetectable)); |
| 1430 | EmitBranch(true_block, false_block, not_zero); |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1435 | Condition LCodeGen::EmitIsObject(Register input, |
| 1436 | Register temp1, |
| 1437 | Register temp2, |
| 1438 | Label* is_not_object, |
| 1439 | Label* is_object) { |
| 1440 | ASSERT(!input.is(temp1)); |
| 1441 | ASSERT(!input.is(temp2)); |
| 1442 | ASSERT(!temp1.is(temp2)); |
| 1443 | |
| 1444 | __ test(input, Immediate(kSmiTagMask)); |
| 1445 | __ j(equal, is_not_object); |
| 1446 | |
| 1447 | __ cmp(input, Factory::null_value()); |
| 1448 | __ j(equal, is_object); |
| 1449 | |
| 1450 | __ mov(temp1, FieldOperand(input, HeapObject::kMapOffset)); |
| 1451 | // Undetectable objects behave like undefined. |
| 1452 | __ movzx_b(temp2, FieldOperand(temp1, Map::kBitFieldOffset)); |
| 1453 | __ test(temp2, Immediate(1 << Map::kIsUndetectable)); |
| 1454 | __ j(not_zero, is_not_object); |
| 1455 | |
| 1456 | __ movzx_b(temp2, FieldOperand(temp1, Map::kInstanceTypeOffset)); |
| 1457 | __ cmp(temp2, FIRST_JS_OBJECT_TYPE); |
| 1458 | __ j(below, is_not_object); |
| 1459 | __ cmp(temp2, LAST_JS_OBJECT_TYPE); |
| 1460 | return below_equal; |
| 1461 | } |
| 1462 | |
| 1463 | |
| 1464 | void LCodeGen::DoIsObject(LIsObject* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1465 | Register reg = ToRegister(instr->InputAt(0)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1466 | Register result = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1467 | Register temp = ToRegister(instr->TempAt(0)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1468 | Label is_false, is_true, done; |
| 1469 | |
| 1470 | Condition true_cond = EmitIsObject(reg, result, temp, &is_false, &is_true); |
| 1471 | __ j(true_cond, &is_true); |
| 1472 | |
| 1473 | __ bind(&is_false); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1474 | __ mov(result, Factory::false_value()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1475 | __ jmp(&done); |
| 1476 | |
| 1477 | __ bind(&is_true); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1478 | __ mov(result, Factory::true_value()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1479 | |
| 1480 | __ bind(&done); |
| 1481 | } |
| 1482 | |
| 1483 | |
| 1484 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1485 | Register reg = ToRegister(instr->InputAt(0)); |
| 1486 | Register temp = ToRegister(instr->TempAt(0)); |
| 1487 | Register temp2 = ToRegister(instr->TempAt(1)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1488 | |
| 1489 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1490 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1491 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1492 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1493 | |
| 1494 | Condition true_cond = EmitIsObject(reg, temp, temp2, false_label, true_label); |
| 1495 | |
| 1496 | EmitBranch(true_block, false_block, true_cond); |
| 1497 | } |
| 1498 | |
| 1499 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1500 | void LCodeGen::DoIsSmi(LIsSmi* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1501 | Operand input = ToOperand(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1502 | Register result = ToRegister(instr->result()); |
| 1503 | |
| 1504 | ASSERT(instr->hydrogen()->value()->representation().IsTagged()); |
| 1505 | __ test(input, Immediate(kSmiTagMask)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1506 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1507 | NearLabel done; |
| 1508 | __ j(zero, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1509 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1510 | __ bind(&done); |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1515 | Operand input = ToOperand(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1516 | |
| 1517 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1518 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1519 | |
| 1520 | __ test(input, Immediate(kSmiTagMask)); |
| 1521 | EmitBranch(true_block, false_block, zero); |
| 1522 | } |
| 1523 | |
| 1524 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1525 | static InstanceType TestType(HHasInstanceType* instr) { |
| 1526 | InstanceType from = instr->from(); |
| 1527 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1528 | if (from == FIRST_TYPE) return to; |
| 1529 | ASSERT(from == to || to == LAST_TYPE); |
| 1530 | return from; |
| 1531 | } |
| 1532 | |
| 1533 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1534 | static Condition BranchCondition(HHasInstanceType* instr) { |
| 1535 | InstanceType from = instr->from(); |
| 1536 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1537 | if (from == to) return equal; |
| 1538 | if (to == LAST_TYPE) return above_equal; |
| 1539 | if (from == FIRST_TYPE) return below_equal; |
| 1540 | UNREACHABLE(); |
| 1541 | return equal; |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | void LCodeGen::DoHasInstanceType(LHasInstanceType* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1546 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1547 | Register result = ToRegister(instr->result()); |
| 1548 | |
| 1549 | ASSERT(instr->hydrogen()->value()->representation().IsTagged()); |
| 1550 | __ test(input, Immediate(kSmiTagMask)); |
| 1551 | NearLabel done, is_false; |
| 1552 | __ j(zero, &is_false); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1553 | __ CmpObjectType(input, TestType(instr->hydrogen()), result); |
| 1554 | __ j(NegateCondition(BranchCondition(instr->hydrogen())), &is_false); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1555 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1556 | __ jmp(&done); |
| 1557 | __ bind(&is_false); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1558 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1559 | __ bind(&done); |
| 1560 | } |
| 1561 | |
| 1562 | |
| 1563 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1564 | Register input = ToRegister(instr->InputAt(0)); |
| 1565 | Register temp = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1566 | |
| 1567 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1568 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1569 | |
| 1570 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1571 | |
| 1572 | __ test(input, Immediate(kSmiTagMask)); |
| 1573 | __ j(zero, false_label); |
| 1574 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1575 | __ CmpObjectType(input, TestType(instr->hydrogen()), temp); |
| 1576 | EmitBranch(true_block, false_block, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | |
| 1580 | void LCodeGen::DoHasCachedArrayIndex(LHasCachedArrayIndex* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1581 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1582 | Register result = ToRegister(instr->result()); |
| 1583 | |
| 1584 | ASSERT(instr->hydrogen()->value()->representation().IsTagged()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1585 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1586 | __ test(FieldOperand(input, String::kHashFieldOffset), |
| 1587 | Immediate(String::kContainsCachedArrayIndexMask)); |
| 1588 | NearLabel done; |
| 1589 | __ j(not_zero, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1590 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1591 | __ bind(&done); |
| 1592 | } |
| 1593 | |
| 1594 | |
| 1595 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 1596 | LHasCachedArrayIndexAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1597 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1598 | |
| 1599 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1600 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1601 | |
| 1602 | __ test(FieldOperand(input, String::kHashFieldOffset), |
| 1603 | Immediate(String::kContainsCachedArrayIndexMask)); |
| 1604 | EmitBranch(true_block, false_block, not_equal); |
| 1605 | } |
| 1606 | |
| 1607 | |
| 1608 | // Branches to a label or falls through with the answer in the z flag. Trashes |
| 1609 | // the temp registers, but not the input. Only input and temp2 may alias. |
| 1610 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 1611 | Label* is_false, |
| 1612 | Handle<String>class_name, |
| 1613 | Register input, |
| 1614 | Register temp, |
| 1615 | Register temp2) { |
| 1616 | ASSERT(!input.is(temp)); |
| 1617 | ASSERT(!temp.is(temp2)); // But input and temp2 may be the same register. |
| 1618 | __ test(input, Immediate(kSmiTagMask)); |
| 1619 | __ j(zero, is_false); |
| 1620 | __ CmpObjectType(input, FIRST_JS_OBJECT_TYPE, temp); |
| 1621 | __ j(below, is_false); |
| 1622 | |
| 1623 | // Map is now in temp. |
| 1624 | // Functions have class 'Function'. |
| 1625 | __ CmpInstanceType(temp, JS_FUNCTION_TYPE); |
| 1626 | if (class_name->IsEqualTo(CStrVector("Function"))) { |
| 1627 | __ j(equal, is_true); |
| 1628 | } else { |
| 1629 | __ j(equal, is_false); |
| 1630 | } |
| 1631 | |
| 1632 | // Check if the constructor in the map is a function. |
| 1633 | __ mov(temp, FieldOperand(temp, Map::kConstructorOffset)); |
| 1634 | |
| 1635 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 1636 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 1637 | // LAST_JS_OBJECT_TYPE. |
| 1638 | ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 1639 | ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
| 1640 | |
| 1641 | // Objects with a non-function constructor have class 'Object'. |
| 1642 | __ CmpObjectType(temp, JS_FUNCTION_TYPE, temp2); |
| 1643 | if (class_name->IsEqualTo(CStrVector("Object"))) { |
| 1644 | __ j(not_equal, is_true); |
| 1645 | } else { |
| 1646 | __ j(not_equal, is_false); |
| 1647 | } |
| 1648 | |
| 1649 | // temp now contains the constructor function. Grab the |
| 1650 | // instance class name from there. |
| 1651 | __ mov(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 1652 | __ mov(temp, FieldOperand(temp, |
| 1653 | SharedFunctionInfo::kInstanceClassNameOffset)); |
| 1654 | // The class name we are testing against is a symbol because it's a literal. |
| 1655 | // The name in the constructor is a symbol because of the way the context is |
| 1656 | // booted. This routine isn't expected to work for random API-created |
| 1657 | // classes and it doesn't have to because you can't access it with natives |
| 1658 | // syntax. Since both sides are symbols it is sufficient to use an identity |
| 1659 | // comparison. |
| 1660 | __ cmp(temp, class_name); |
| 1661 | // End with the answer in the z flag. |
| 1662 | } |
| 1663 | |
| 1664 | |
| 1665 | void LCodeGen::DoClassOfTest(LClassOfTest* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1666 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1667 | Register result = ToRegister(instr->result()); |
| 1668 | ASSERT(input.is(result)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1669 | Register temp = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1670 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 1671 | NearLabel done; |
| 1672 | Label is_true, is_false; |
| 1673 | |
| 1674 | EmitClassOfTest(&is_true, &is_false, class_name, input, temp, input); |
| 1675 | |
| 1676 | __ j(not_equal, &is_false); |
| 1677 | |
| 1678 | __ bind(&is_true); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1679 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1680 | __ jmp(&done); |
| 1681 | |
| 1682 | __ bind(&is_false); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1683 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1684 | __ bind(&done); |
| 1685 | } |
| 1686 | |
| 1687 | |
| 1688 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1689 | Register input = ToRegister(instr->InputAt(0)); |
| 1690 | Register temp = ToRegister(instr->TempAt(0)); |
| 1691 | Register temp2 = ToRegister(instr->TempAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1692 | if (input.is(temp)) { |
| 1693 | // Swap. |
| 1694 | Register swapper = temp; |
| 1695 | temp = temp2; |
| 1696 | temp2 = swapper; |
| 1697 | } |
| 1698 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 1699 | |
| 1700 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1701 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1702 | |
| 1703 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1704 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1705 | |
| 1706 | EmitClassOfTest(true_label, false_label, class_name, input, temp, temp2); |
| 1707 | |
| 1708 | EmitBranch(true_block, false_block, equal); |
| 1709 | } |
| 1710 | |
| 1711 | |
| 1712 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1713 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1714 | int true_block = instr->true_block_id(); |
| 1715 | int false_block = instr->false_block_id(); |
| 1716 | |
| 1717 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map()); |
| 1718 | EmitBranch(true_block, false_block, equal); |
| 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1723 | // Object and function are in fixed registers defined by the stub. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1724 | ASSERT(ToRegister(instr->context()).is(esi)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1725 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1726 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 1727 | |
| 1728 | NearLabel true_value, done; |
| 1729 | __ test(eax, Operand(eax)); |
| 1730 | __ j(zero, &true_value); |
| 1731 | __ mov(ToRegister(instr->result()), Factory::false_value()); |
| 1732 | __ jmp(&done); |
| 1733 | __ bind(&true_value); |
| 1734 | __ mov(ToRegister(instr->result()), Factory::true_value()); |
| 1735 | __ bind(&done); |
| 1736 | } |
| 1737 | |
| 1738 | |
| 1739 | void LCodeGen::DoInstanceOfAndBranch(LInstanceOfAndBranch* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1740 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1741 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1742 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1743 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1744 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1745 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 1746 | __ test(eax, Operand(eax)); |
| 1747 | EmitBranch(true_block, false_block, zero); |
| 1748 | } |
| 1749 | |
| 1750 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1751 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
| 1752 | class DeferredInstanceOfKnownGlobal: public LDeferredCode { |
| 1753 | public: |
| 1754 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 1755 | LInstanceOfKnownGlobal* instr) |
| 1756 | : LDeferredCode(codegen), instr_(instr) { } |
| 1757 | virtual void Generate() { |
| 1758 | codegen()->DoDeferredLInstanceOfKnownGlobal(instr_, &map_check_); |
| 1759 | } |
| 1760 | |
| 1761 | Label* map_check() { return &map_check_; } |
| 1762 | |
| 1763 | private: |
| 1764 | LInstanceOfKnownGlobal* instr_; |
| 1765 | Label map_check_; |
| 1766 | }; |
| 1767 | |
| 1768 | DeferredInstanceOfKnownGlobal* deferred; |
| 1769 | deferred = new DeferredInstanceOfKnownGlobal(this, instr); |
| 1770 | |
| 1771 | Label done, false_result; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1772 | Register object = ToRegister(instr->InputAt(0)); |
| 1773 | Register temp = ToRegister(instr->TempAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1774 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 1775 | // A Smi is not an instance of anything. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1776 | __ test(object, Immediate(kSmiTagMask)); |
| 1777 | __ j(zero, &false_result, not_taken); |
| 1778 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 1779 | // This is the inlined call site instanceof cache. The two occurences of the |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1780 | // hole value will be patched to the last map/result pair generated by the |
| 1781 | // instanceof stub. |
| 1782 | NearLabel cache_miss; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1783 | Register map = ToRegister(instr->TempAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1784 | __ mov(map, FieldOperand(object, HeapObject::kMapOffset)); |
| 1785 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 1786 | __ cmp(map, Factory::the_hole_value()); // Patched to cached map. |
| 1787 | __ j(not_equal, &cache_miss, not_taken); |
| 1788 | __ mov(eax, Factory::the_hole_value()); // Patched to either true or false. |
| 1789 | __ jmp(&done); |
| 1790 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 1791 | // The inlined call site cache did not match. Check for null and string |
| 1792 | // before calling the deferred code. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1793 | __ bind(&cache_miss); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 1794 | // Null is not an instance of anything. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1795 | __ cmp(object, Factory::null_value()); |
| 1796 | __ j(equal, &false_result); |
| 1797 | |
| 1798 | // String values are not instances of anything. |
| 1799 | Condition is_string = masm_->IsObjectStringType(object, temp, temp); |
| 1800 | __ j(is_string, &false_result); |
| 1801 | |
| 1802 | // Go to the deferred code. |
| 1803 | __ jmp(deferred->entry()); |
| 1804 | |
| 1805 | __ bind(&false_result); |
| 1806 | __ mov(ToRegister(instr->result()), Factory::false_value()); |
| 1807 | |
| 1808 | // Here result has either true or false. Deferred code also produces true or |
| 1809 | // false object. |
| 1810 | __ bind(deferred->exit()); |
| 1811 | __ bind(&done); |
| 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | void LCodeGen::DoDeferredLInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 1816 | Label* map_check) { |
| 1817 | __ PushSafepointRegisters(); |
| 1818 | |
| 1819 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 1820 | flags = static_cast<InstanceofStub::Flags>( |
| 1821 | flags | InstanceofStub::kArgsInRegisters); |
| 1822 | flags = static_cast<InstanceofStub::Flags>( |
| 1823 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 1824 | flags = static_cast<InstanceofStub::Flags>( |
| 1825 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 1826 | InstanceofStub stub(flags); |
| 1827 | |
| 1828 | // Get the temp register reserved by the instruction. This needs to be edi as |
| 1829 | // its slot of the pushing of safepoint registers is used to communicate the |
| 1830 | // offset to the location of the map check. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1831 | Register temp = ToRegister(instr->TempAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1832 | ASSERT(temp.is(edi)); |
| 1833 | __ mov(InstanceofStub::right(), Immediate(instr->function())); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1834 | static const int kAdditionalDelta = 16; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1835 | int delta = masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta; |
| 1836 | Label before_push_delta; |
| 1837 | __ bind(&before_push_delta); |
| 1838 | __ mov(temp, Immediate(delta)); |
| 1839 | __ mov(Operand(esp, EspIndexForPushAll(temp) * kPointerSize), temp); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1840 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1841 | __ call(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 1842 | ASSERT_EQ(kAdditionalDelta, |
| 1843 | masm_->SizeOfCodeGeneratedSince(&before_push_delta)); |
| 1844 | RecordSafepointWithRegisters( |
| 1845 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 1846 | // Put the result value into the eax slot and restore all registers. |
| 1847 | __ mov(Operand(esp, EspIndexForPushAll(eax) * kPointerSize), eax); |
| 1848 | |
| 1849 | __ PopSafepointRegisters(); |
| 1850 | } |
| 1851 | |
| 1852 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1853 | static Condition ComputeCompareCondition(Token::Value op) { |
| 1854 | switch (op) { |
| 1855 | case Token::EQ_STRICT: |
| 1856 | case Token::EQ: |
| 1857 | return equal; |
| 1858 | case Token::LT: |
| 1859 | return less; |
| 1860 | case Token::GT: |
| 1861 | return greater; |
| 1862 | case Token::LTE: |
| 1863 | return less_equal; |
| 1864 | case Token::GTE: |
| 1865 | return greater_equal; |
| 1866 | default: |
| 1867 | UNREACHABLE(); |
| 1868 | return no_condition; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | |
| 1873 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 1874 | Token::Value op = instr->op(); |
| 1875 | |
| 1876 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1877 | CallCode(ic, RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1878 | |
| 1879 | Condition condition = ComputeCompareCondition(op); |
| 1880 | if (op == Token::GT || op == Token::LTE) { |
| 1881 | condition = ReverseCondition(condition); |
| 1882 | } |
| 1883 | NearLabel true_value, done; |
| 1884 | __ test(eax, Operand(eax)); |
| 1885 | __ j(condition, &true_value); |
| 1886 | __ mov(ToRegister(instr->result()), Factory::false_value()); |
| 1887 | __ jmp(&done); |
| 1888 | __ bind(&true_value); |
| 1889 | __ mov(ToRegister(instr->result()), Factory::true_value()); |
| 1890 | __ bind(&done); |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | void LCodeGen::DoCmpTAndBranch(LCmpTAndBranch* instr) { |
| 1895 | Token::Value op = instr->op(); |
| 1896 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1897 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1898 | |
| 1899 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1900 | CallCode(ic, RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1901 | |
| 1902 | // The compare stub expects compare condition and the input operands |
| 1903 | // reversed for GT and LTE. |
| 1904 | Condition condition = ComputeCompareCondition(op); |
| 1905 | if (op == Token::GT || op == Token::LTE) { |
| 1906 | condition = ReverseCondition(condition); |
| 1907 | } |
| 1908 | __ test(eax, Operand(eax)); |
| 1909 | EmitBranch(true_block, false_block, condition); |
| 1910 | } |
| 1911 | |
| 1912 | |
| 1913 | void LCodeGen::DoReturn(LReturn* instr) { |
| 1914 | if (FLAG_trace) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1915 | // Preserve the return value on the stack and rely on the runtime call |
| 1916 | // to return the value in the same register. We're leaving the code |
| 1917 | // managed by the register allocator and tearing down the frame, it's |
| 1918 | // safe to write to the context register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1919 | __ push(eax); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1920 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1921 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 1922 | } |
| 1923 | __ mov(esp, ebp); |
| 1924 | __ pop(ebp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1925 | __ Ret((ParameterCount() + 1) * kPointerSize, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | |
| 1929 | void LCodeGen::DoLoadGlobal(LLoadGlobal* instr) { |
| 1930 | Register result = ToRegister(instr->result()); |
| 1931 | __ mov(result, Operand::Cell(instr->hydrogen()->cell())); |
| 1932 | if (instr->hydrogen()->check_hole_value()) { |
| 1933 | __ cmp(result, Factory::the_hole_value()); |
| 1934 | DeoptimizeIf(equal, instr->environment()); |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | |
| 1939 | void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1940 | Register value = ToRegister(instr->InputAt(0)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1941 | Operand cell_operand = Operand::Cell(instr->hydrogen()->cell()); |
| 1942 | |
| 1943 | // If the cell we are storing to contains the hole it could have |
| 1944 | // been deleted from the property dictionary. In that case, we need |
| 1945 | // to update the property details in the property dictionary to mark |
| 1946 | // it as no longer deleted. We deoptimize in that case. |
| 1947 | if (instr->hydrogen()->check_hole_value()) { |
| 1948 | __ cmp(cell_operand, Factory::the_hole_value()); |
| 1949 | DeoptimizeIf(equal, instr->environment()); |
| 1950 | } |
| 1951 | |
| 1952 | // Store the value. |
| 1953 | __ mov(cell_operand, value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1957 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1958 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1959 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1960 | __ mov(result, ContextOperand(context, instr->slot_index())); |
| 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 1965 | Register context = ToRegister(instr->context()); |
| 1966 | Register value = ToRegister(instr->value()); |
| 1967 | __ mov(ContextOperand(context, instr->slot_index()), value); |
| 1968 | if (instr->needs_write_barrier()) { |
| 1969 | Register temp = ToRegister(instr->TempAt(0)); |
| 1970 | int offset = Context::SlotOffset(instr->slot_index()); |
| 1971 | __ RecordWrite(context, offset, value, temp); |
| 1972 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1976 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1977 | Register object = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1978 | Register result = ToRegister(instr->result()); |
| 1979 | if (instr->hydrogen()->is_in_object()) { |
| 1980 | __ mov(result, FieldOperand(object, instr->hydrogen()->offset())); |
| 1981 | } else { |
| 1982 | __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset)); |
| 1983 | __ mov(result, FieldOperand(result, instr->hydrogen()->offset())); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | |
| 1988 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1989 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1990 | ASSERT(ToRegister(instr->object()).is(eax)); |
| 1991 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 1992 | |
| 1993 | __ mov(ecx, instr->name()); |
| 1994 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 1995 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 1996 | } |
| 1997 | |
| 1998 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1999 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 2000 | Register function = ToRegister(instr->function()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2001 | Register temp = ToRegister(instr->TempAt(0)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2002 | Register result = ToRegister(instr->result()); |
| 2003 | |
| 2004 | // Check that the function really is a function. |
| 2005 | __ CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 2006 | DeoptimizeIf(not_equal, instr->environment()); |
| 2007 | |
| 2008 | // Check whether the function has an instance prototype. |
| 2009 | NearLabel non_instance; |
| 2010 | __ test_b(FieldOperand(result, Map::kBitFieldOffset), |
| 2011 | 1 << Map::kHasNonInstancePrototype); |
| 2012 | __ j(not_zero, &non_instance); |
| 2013 | |
| 2014 | // Get the prototype or initial map from the function. |
| 2015 | __ mov(result, |
| 2016 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2017 | |
| 2018 | // Check that the function has a prototype or an initial map. |
| 2019 | __ cmp(Operand(result), Immediate(Factory::the_hole_value())); |
| 2020 | DeoptimizeIf(equal, instr->environment()); |
| 2021 | |
| 2022 | // If the function does not have an initial map, we're done. |
| 2023 | NearLabel done; |
| 2024 | __ CmpObjectType(result, MAP_TYPE, temp); |
| 2025 | __ j(not_equal, &done); |
| 2026 | |
| 2027 | // Get the prototype from the initial map. |
| 2028 | __ mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
| 2029 | __ jmp(&done); |
| 2030 | |
| 2031 | // Non-instance prototype: Fetch prototype from constructor field |
| 2032 | // in the function's map. |
| 2033 | __ bind(&non_instance); |
| 2034 | __ mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 2035 | |
| 2036 | // All done. |
| 2037 | __ bind(&done); |
| 2038 | } |
| 2039 | |
| 2040 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2041 | void LCodeGen::DoLoadElements(LLoadElements* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2042 | Register result = ToRegister(instr->result()); |
| 2043 | Register input = ToRegister(instr->InputAt(0)); |
| 2044 | __ mov(result, FieldOperand(input, JSObject::kElementsOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2045 | if (FLAG_debug_code) { |
| 2046 | NearLabel done; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2047 | __ cmp(FieldOperand(result, HeapObject::kMapOffset), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2048 | Immediate(Factory::fixed_array_map())); |
| 2049 | __ j(equal, &done); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2050 | __ cmp(FieldOperand(result, HeapObject::kMapOffset), |
| 2051 | Immediate(Factory::pixel_array_map())); |
| 2052 | __ j(equal, &done); |
| 2053 | __ cmp(FieldOperand(result, HeapObject::kMapOffset), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2054 | Immediate(Factory::fixed_cow_array_map())); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2055 | __ Check(equal, "Check for fast elements or pixel array failed."); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2056 | __ bind(&done); |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2061 | void LCodeGen::DoLoadPixelArrayExternalPointer( |
| 2062 | LLoadPixelArrayExternalPointer* instr) { |
| 2063 | Register result = ToRegister(instr->result()); |
| 2064 | Register input = ToRegister(instr->InputAt(0)); |
| 2065 | __ mov(result, FieldOperand(input, PixelArray::kExternalPointerOffset)); |
| 2066 | } |
| 2067 | |
| 2068 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2069 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 2070 | Register arguments = ToRegister(instr->arguments()); |
| 2071 | Register length = ToRegister(instr->length()); |
| 2072 | Operand index = ToOperand(instr->index()); |
| 2073 | Register result = ToRegister(instr->result()); |
| 2074 | |
| 2075 | __ sub(length, index); |
| 2076 | DeoptimizeIf(below_equal, instr->environment()); |
| 2077 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2078 | // There are two words between the frame pointer and the last argument. |
| 2079 | // Subtracting from length accounts for one of them add one more. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2080 | __ mov(result, Operand(arguments, length, times_4, kPointerSize)); |
| 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) { |
| 2085 | Register elements = ToRegister(instr->elements()); |
| 2086 | Register key = ToRegister(instr->key()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2087 | Register result = ToRegister(instr->result()); |
| 2088 | ASSERT(result.is(elements)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2089 | |
| 2090 | // Load the result. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2091 | __ mov(result, FieldOperand(elements, |
| 2092 | key, |
| 2093 | times_pointer_size, |
| 2094 | FixedArray::kHeaderSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2095 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2096 | // Check for the hole value. |
| 2097 | __ cmp(result, Factory::the_hole_value()); |
| 2098 | DeoptimizeIf(equal, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2102 | void LCodeGen::DoLoadPixelArrayElement(LLoadPixelArrayElement* instr) { |
| 2103 | Register external_elements = ToRegister(instr->external_pointer()); |
| 2104 | Register key = ToRegister(instr->key()); |
| 2105 | Register result = ToRegister(instr->result()); |
| 2106 | ASSERT(result.is(external_elements)); |
| 2107 | |
| 2108 | // Load the result. |
| 2109 | __ movzx_b(result, Operand(external_elements, key, times_1, 0)); |
| 2110 | } |
| 2111 | |
| 2112 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2113 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2114 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2115 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 2116 | ASSERT(ToRegister(instr->key()).is(eax)); |
| 2117 | |
| 2118 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 2119 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2120 | } |
| 2121 | |
| 2122 | |
| 2123 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 2124 | Register result = ToRegister(instr->result()); |
| 2125 | |
| 2126 | // Check for arguments adapter frame. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2127 | NearLabel done, adapted; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2128 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2129 | __ mov(result, Operand(result, StandardFrameConstants::kContextOffset)); |
| 2130 | __ cmp(Operand(result), |
| 2131 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2132 | __ j(equal, &adapted); |
| 2133 | |
| 2134 | // No arguments adaptor frame. |
| 2135 | __ mov(result, Operand(ebp)); |
| 2136 | __ jmp(&done); |
| 2137 | |
| 2138 | // Arguments adaptor frame present. |
| 2139 | __ bind(&adapted); |
| 2140 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2141 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2142 | // Result is the frame pointer for the frame if not adapted and for the real |
| 2143 | // frame below the adaptor frame if adapted. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2144 | __ bind(&done); |
| 2145 | } |
| 2146 | |
| 2147 | |
| 2148 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2149 | Operand elem = ToOperand(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2150 | Register result = ToRegister(instr->result()); |
| 2151 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2152 | NearLabel done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2154 | // If no arguments adaptor frame the number of arguments is fixed. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2155 | __ cmp(ebp, elem); |
| 2156 | __ mov(result, Immediate(scope()->num_parameters())); |
| 2157 | __ j(equal, &done); |
| 2158 | |
| 2159 | // Arguments adaptor frame present. Get argument length from there. |
| 2160 | __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2161 | __ mov(result, Operand(result, |
| 2162 | ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2163 | __ SmiUntag(result); |
| 2164 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2165 | // Argument length is in result register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2166 | __ bind(&done); |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 2171 | Register receiver = ToRegister(instr->receiver()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2172 | Register function = ToRegister(instr->function()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2173 | Register length = ToRegister(instr->length()); |
| 2174 | Register elements = ToRegister(instr->elements()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2175 | Register scratch = ToRegister(instr->TempAt(0)); |
| 2176 | ASSERT(receiver.is(eax)); // Used for parameter count. |
| 2177 | ASSERT(function.is(edi)); // Required by InvokeFunction. |
| 2178 | ASSERT(ToRegister(instr->result()).is(eax)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2179 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2180 | // If the receiver is null or undefined, we have to pass the global object |
| 2181 | // as a receiver. |
| 2182 | NearLabel global_object, receiver_ok; |
| 2183 | __ cmp(receiver, Factory::null_value()); |
| 2184 | __ j(equal, &global_object); |
| 2185 | __ cmp(receiver, Factory::undefined_value()); |
| 2186 | __ j(equal, &global_object); |
| 2187 | |
| 2188 | // The receiver should be a JS object. |
| 2189 | __ test(receiver, Immediate(kSmiTagMask)); |
| 2190 | DeoptimizeIf(equal, instr->environment()); |
| 2191 | __ CmpObjectType(receiver, FIRST_JS_OBJECT_TYPE, scratch); |
| 2192 | DeoptimizeIf(below, instr->environment()); |
| 2193 | __ jmp(&receiver_ok); |
| 2194 | |
| 2195 | __ bind(&global_object); |
| 2196 | // TODO(kmillikin): We have a hydrogen value for the global object. See |
| 2197 | // if it's better to use it than to explicitly fetch it from the context |
| 2198 | // here. |
| 2199 | __ mov(receiver, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2200 | __ mov(receiver, ContextOperand(receiver, Context::GLOBAL_INDEX)); |
| 2201 | __ bind(&receiver_ok); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2202 | |
| 2203 | // Copy the arguments to this function possibly from the |
| 2204 | // adaptor frame below it. |
| 2205 | const uint32_t kArgumentsLimit = 1 * KB; |
| 2206 | __ cmp(length, kArgumentsLimit); |
| 2207 | DeoptimizeIf(above, instr->environment()); |
| 2208 | |
| 2209 | __ push(receiver); |
| 2210 | __ mov(receiver, length); |
| 2211 | |
| 2212 | // Loop through the arguments pushing them onto the execution |
| 2213 | // stack. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2214 | NearLabel invoke, loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2215 | // length is a small non-negative integer, due to the test above. |
| 2216 | __ test(length, Operand(length)); |
| 2217 | __ j(zero, &invoke); |
| 2218 | __ bind(&loop); |
| 2219 | __ push(Operand(elements, length, times_pointer_size, 1 * kPointerSize)); |
| 2220 | __ dec(length); |
| 2221 | __ j(not_zero, &loop); |
| 2222 | |
| 2223 | // Invoke the function. |
| 2224 | __ bind(&invoke); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2225 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 2226 | LPointerMap* pointers = instr->pointer_map(); |
| 2227 | LEnvironment* env = instr->deoptimization_environment(); |
| 2228 | RecordPosition(pointers->position()); |
| 2229 | RegisterEnvironmentForDeoptimization(env); |
| 2230 | SafepointGenerator safepoint_generator(this, |
| 2231 | pointers, |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 2232 | env->deoptimization_index(), |
| 2233 | true); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2234 | v8::internal::ParameterCount actual(eax); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2235 | __ InvokeFunction(function, actual, CALL_FUNCTION, &safepoint_generator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2240 | LOperand* argument = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2241 | if (argument->IsConstantOperand()) { |
| 2242 | __ push(ToImmediate(argument)); |
| 2243 | } else { |
| 2244 | __ push(ToOperand(argument)); |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2249 | void LCodeGen::DoContext(LContext* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2250 | Register result = ToRegister(instr->result()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2251 | __ mov(result, Operand(ebp, StandardFrameConstants::kContextOffset)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | |
| 2255 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 2256 | Register context = ToRegister(instr->context()); |
| 2257 | Register result = ToRegister(instr->result()); |
| 2258 | __ mov(result, Operand(context, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2259 | __ mov(result, FieldOperand(result, JSFunction::kContextOffset)); |
| 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
| 2264 | Register context = ToRegister(instr->context()); |
| 2265 | Register result = ToRegister(instr->result()); |
| 2266 | __ mov(result, Operand(context, Context::SlotOffset(Context::GLOBAL_INDEX))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2271 | Register global = ToRegister(instr->global()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2272 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2273 | __ mov(result, FieldOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | |
| 2277 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
| 2278 | int arity, |
| 2279 | LInstruction* instr) { |
| 2280 | // Change context if needed. |
| 2281 | bool change_context = |
| 2282 | (graph()->info()->closure()->context() != function->context()) || |
| 2283 | scope()->contains_with() || |
| 2284 | (scope()->num_heap_slots() > 0); |
| 2285 | if (change_context) { |
| 2286 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2287 | } else { |
| 2288 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | // Set eax to arguments count if adaption is not needed. Assumes that eax |
| 2292 | // is available to write to at this point. |
| 2293 | if (!function->NeedsArgumentsAdaption()) { |
| 2294 | __ mov(eax, arity); |
| 2295 | } |
| 2296 | |
| 2297 | LPointerMap* pointers = instr->pointer_map(); |
| 2298 | RecordPosition(pointers->position()); |
| 2299 | |
| 2300 | // Invoke function. |
| 2301 | if (*function == *graph()->info()->closure()) { |
| 2302 | __ CallSelf(); |
| 2303 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 2304 | // This is an indirect call and will not be recorded in the reloc info. |
| 2305 | // Add a comment to the reloc info in case we need to patch this during |
| 2306 | // deoptimization. |
| 2307 | __ RecordComment(RelocInfo::kFillerCommentString, true); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2308 | __ call(FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2309 | } |
| 2310 | |
| 2311 | // Setup deoptimization. |
| 2312 | RegisterLazyDeoptimization(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | |
| 2316 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
| 2317 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2318 | __ mov(edi, instr->function()); |
| 2319 | CallKnownFunction(instr->function(), instr->arity(), instr); |
| 2320 | } |
| 2321 | |
| 2322 | |
| 2323 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2324 | Register input_reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2325 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 2326 | Factory::heap_number_map()); |
| 2327 | DeoptimizeIf(not_equal, instr->environment()); |
| 2328 | |
| 2329 | Label done; |
| 2330 | Register tmp = input_reg.is(eax) ? ecx : eax; |
| 2331 | Register tmp2 = tmp.is(ecx) ? edx : input_reg.is(ecx) ? edx : ecx; |
| 2332 | |
| 2333 | // Preserve the value of all registers. |
| 2334 | __ PushSafepointRegisters(); |
| 2335 | |
| 2336 | Label negative; |
| 2337 | __ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2338 | // Check the sign of the argument. If the argument is positive, just |
| 2339 | // return it. We do not need to patch the stack since |input| and |
| 2340 | // |result| are the same register and |input| will be restored |
| 2341 | // unchanged by popping safepoint registers. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2342 | __ test(tmp, Immediate(HeapNumber::kSignMask)); |
| 2343 | __ j(not_zero, &negative); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | __ jmp(&done); |
| 2345 | |
| 2346 | __ bind(&negative); |
| 2347 | |
| 2348 | Label allocated, slow; |
| 2349 | __ AllocateHeapNumber(tmp, tmp2, no_reg, &slow); |
| 2350 | __ jmp(&allocated); |
| 2351 | |
| 2352 | // Slow case: Call the runtime system to do the number allocation. |
| 2353 | __ bind(&slow); |
| 2354 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2355 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2356 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 2357 | RecordSafepointWithRegisters( |
| 2358 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 2359 | // Set the pointer to the new heap number in tmp. |
| 2360 | if (!tmp.is(eax)) __ mov(tmp, eax); |
| 2361 | |
| 2362 | // Restore input_reg after call to runtime. |
| 2363 | __ mov(input_reg, Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize)); |
| 2364 | |
| 2365 | __ bind(&allocated); |
| 2366 | __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 2367 | __ and_(tmp2, ~HeapNumber::kSignMask); |
| 2368 | __ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2); |
| 2369 | __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
| 2370 | __ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2371 | __ mov(Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize), tmp); |
| 2372 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2373 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2374 | __ PopSafepointRegisters(); |
| 2375 | } |
| 2376 | |
| 2377 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2378 | void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { |
| 2379 | Register input_reg = ToRegister(instr->InputAt(0)); |
| 2380 | __ test(input_reg, Operand(input_reg)); |
| 2381 | Label is_positive; |
| 2382 | __ j(not_sign, &is_positive); |
| 2383 | __ neg(input_reg); |
| 2384 | __ test(input_reg, Operand(input_reg)); |
| 2385 | DeoptimizeIf(negative, instr->environment()); |
| 2386 | __ bind(&is_positive); |
| 2387 | } |
| 2388 | |
| 2389 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2390 | void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { |
| 2391 | // Class for deferred case. |
| 2392 | class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
| 2393 | public: |
| 2394 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, |
| 2395 | LUnaryMathOperation* instr) |
| 2396 | : LDeferredCode(codegen), instr_(instr) { } |
| 2397 | virtual void Generate() { |
| 2398 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 2399 | } |
| 2400 | private: |
| 2401 | LUnaryMathOperation* instr_; |
| 2402 | }; |
| 2403 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2404 | ASSERT(instr->InputAt(0)->Equals(instr->result())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2405 | Representation r = instr->hydrogen()->value()->representation(); |
| 2406 | |
| 2407 | if (r.IsDouble()) { |
| 2408 | XMMRegister scratch = xmm0; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2409 | XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2410 | __ pxor(scratch, scratch); |
| 2411 | __ subsd(scratch, input_reg); |
| 2412 | __ pand(input_reg, scratch); |
| 2413 | } else if (r.IsInteger32()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2414 | EmitIntegerMathAbs(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2415 | } else { // Tagged case. |
| 2416 | DeferredMathAbsTaggedHeapNumber* deferred = |
| 2417 | new DeferredMathAbsTaggedHeapNumber(this, instr); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2418 | Register input_reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2419 | // Smi check. |
| 2420 | __ test(input_reg, Immediate(kSmiTagMask)); |
| 2421 | __ j(not_zero, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2422 | EmitIntegerMathAbs(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2423 | __ bind(deferred->exit()); |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | |
| 2428 | void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { |
| 2429 | XMMRegister xmm_scratch = xmm0; |
| 2430 | Register output_reg = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2431 | XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2432 | __ xorpd(xmm_scratch, xmm_scratch); // Zero the register. |
| 2433 | __ ucomisd(input_reg, xmm_scratch); |
| 2434 | |
| 2435 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 2436 | DeoptimizeIf(below_equal, instr->environment()); |
| 2437 | } else { |
| 2438 | DeoptimizeIf(below, instr->environment()); |
| 2439 | } |
| 2440 | |
| 2441 | // Use truncating instruction (OK because input is positive). |
| 2442 | __ cvttsd2si(output_reg, Operand(input_reg)); |
| 2443 | |
| 2444 | // Overflow is signalled with minint. |
| 2445 | __ cmp(output_reg, 0x80000000u); |
| 2446 | DeoptimizeIf(equal, instr->environment()); |
| 2447 | } |
| 2448 | |
| 2449 | |
| 2450 | void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { |
| 2451 | XMMRegister xmm_scratch = xmm0; |
| 2452 | Register output_reg = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2453 | XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2454 | |
| 2455 | // xmm_scratch = 0.5 |
| 2456 | ExternalReference one_half = ExternalReference::address_of_one_half(); |
| 2457 | __ movdbl(xmm_scratch, Operand::StaticVariable(one_half)); |
| 2458 | |
| 2459 | // input = input + 0.5 |
| 2460 | __ addsd(input_reg, xmm_scratch); |
| 2461 | |
| 2462 | // We need to return -0 for the input range [-0.5, 0[, otherwise |
| 2463 | // compute Math.floor(value + 0.5). |
| 2464 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 2465 | __ ucomisd(input_reg, xmm_scratch); |
| 2466 | DeoptimizeIf(below_equal, instr->environment()); |
| 2467 | } else { |
| 2468 | // If we don't need to bailout on -0, we check only bailout |
| 2469 | // on negative inputs. |
| 2470 | __ xorpd(xmm_scratch, xmm_scratch); // Zero the register. |
| 2471 | __ ucomisd(input_reg, xmm_scratch); |
| 2472 | DeoptimizeIf(below, instr->environment()); |
| 2473 | } |
| 2474 | |
| 2475 | // Compute Math.floor(value + 0.5). |
| 2476 | // Use truncating instruction (OK because input is positive). |
| 2477 | __ cvttsd2si(output_reg, Operand(input_reg)); |
| 2478 | |
| 2479 | // Overflow is signalled with minint. |
| 2480 | __ cmp(output_reg, 0x80000000u); |
| 2481 | DeoptimizeIf(equal, instr->environment()); |
| 2482 | } |
| 2483 | |
| 2484 | |
| 2485 | void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2486 | XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2487 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
| 2488 | __ sqrtsd(input_reg, input_reg); |
| 2489 | } |
| 2490 | |
| 2491 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2492 | void LCodeGen::DoMathPowHalf(LUnaryMathOperation* instr) { |
| 2493 | XMMRegister xmm_scratch = xmm0; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2494 | XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2495 | ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); |
| 2496 | ExternalReference negative_infinity = |
| 2497 | ExternalReference::address_of_negative_infinity(); |
| 2498 | __ movdbl(xmm_scratch, Operand::StaticVariable(negative_infinity)); |
| 2499 | __ ucomisd(xmm_scratch, input_reg); |
| 2500 | DeoptimizeIf(equal, instr->environment()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2501 | __ xorpd(xmm_scratch, xmm_scratch); |
| 2502 | __ addsd(input_reg, xmm_scratch); // Convert -0 to +0. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2503 | __ sqrtsd(input_reg, input_reg); |
| 2504 | } |
| 2505 | |
| 2506 | |
| 2507 | void LCodeGen::DoPower(LPower* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2508 | LOperand* left = instr->InputAt(0); |
| 2509 | LOperand* right = instr->InputAt(1); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2510 | DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
| 2511 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
| 2512 | if (exponent_type.IsDouble()) { |
| 2513 | // It is safe to use ebx directly since the instruction is marked |
| 2514 | // as a call. |
| 2515 | __ PrepareCallCFunction(4, ebx); |
| 2516 | __ movdbl(Operand(esp, 0 * kDoubleSize), ToDoubleRegister(left)); |
| 2517 | __ movdbl(Operand(esp, 1 * kDoubleSize), ToDoubleRegister(right)); |
| 2518 | __ CallCFunction(ExternalReference::power_double_double_function(), 4); |
| 2519 | } else if (exponent_type.IsInteger32()) { |
| 2520 | // It is safe to use ebx directly since the instruction is marked |
| 2521 | // as a call. |
| 2522 | ASSERT(!ToRegister(right).is(ebx)); |
| 2523 | __ PrepareCallCFunction(4, ebx); |
| 2524 | __ movdbl(Operand(esp, 0 * kDoubleSize), ToDoubleRegister(left)); |
| 2525 | __ mov(Operand(esp, 1 * kDoubleSize), ToRegister(right)); |
| 2526 | __ CallCFunction(ExternalReference::power_double_int_function(), 4); |
| 2527 | } else { |
| 2528 | ASSERT(exponent_type.IsTagged()); |
| 2529 | CpuFeatures::Scope scope(SSE2); |
| 2530 | Register right_reg = ToRegister(right); |
| 2531 | |
| 2532 | Label non_smi, call; |
| 2533 | __ test(right_reg, Immediate(kSmiTagMask)); |
| 2534 | __ j(not_zero, &non_smi); |
| 2535 | __ SmiUntag(right_reg); |
| 2536 | __ cvtsi2sd(result_reg, Operand(right_reg)); |
| 2537 | __ jmp(&call); |
| 2538 | |
| 2539 | __ bind(&non_smi); |
| 2540 | // It is safe to use ebx directly since the instruction is marked |
| 2541 | // as a call. |
| 2542 | ASSERT(!right_reg.is(ebx)); |
| 2543 | __ CmpObjectType(right_reg, HEAP_NUMBER_TYPE , ebx); |
| 2544 | DeoptimizeIf(not_equal, instr->environment()); |
| 2545 | __ movdbl(result_reg, FieldOperand(right_reg, HeapNumber::kValueOffset)); |
| 2546 | |
| 2547 | __ bind(&call); |
| 2548 | __ PrepareCallCFunction(4, ebx); |
| 2549 | __ movdbl(Operand(esp, 0 * kDoubleSize), ToDoubleRegister(left)); |
| 2550 | __ movdbl(Operand(esp, 1 * kDoubleSize), result_reg); |
| 2551 | __ CallCFunction(ExternalReference::power_double_double_function(), 4); |
| 2552 | } |
| 2553 | |
| 2554 | // Return value is in st(0) on ia32. |
| 2555 | // Store it into the (fixed) result register. |
| 2556 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
| 2557 | __ fstp_d(Operand(esp, 0)); |
| 2558 | __ movdbl(result_reg, Operand(esp, 0)); |
| 2559 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 2560 | } |
| 2561 | |
| 2562 | |
| 2563 | void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { |
| 2564 | ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2565 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 2566 | TranscendentalCacheStub::UNTAGGED); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2567 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | |
| 2571 | void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { |
| 2572 | ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
| 2573 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 2574 | TranscendentalCacheStub::UNTAGGED); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2575 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | |
| 2579 | void LCodeGen::DoMathSin(LUnaryMathOperation* instr) { |
| 2580 | ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
| 2581 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 2582 | TranscendentalCacheStub::UNTAGGED); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2583 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2587 | void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) { |
| 2588 | switch (instr->op()) { |
| 2589 | case kMathAbs: |
| 2590 | DoMathAbs(instr); |
| 2591 | break; |
| 2592 | case kMathFloor: |
| 2593 | DoMathFloor(instr); |
| 2594 | break; |
| 2595 | case kMathRound: |
| 2596 | DoMathRound(instr); |
| 2597 | break; |
| 2598 | case kMathSqrt: |
| 2599 | DoMathSqrt(instr); |
| 2600 | break; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2601 | case kMathPowHalf: |
| 2602 | DoMathPowHalf(instr); |
| 2603 | break; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2604 | case kMathCos: |
| 2605 | DoMathCos(instr); |
| 2606 | break; |
| 2607 | case kMathSin: |
| 2608 | DoMathSin(instr); |
| 2609 | break; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2610 | case kMathLog: |
| 2611 | DoMathLog(instr); |
| 2612 | break; |
| 2613 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2614 | default: |
| 2615 | UNREACHABLE(); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | |
| 2620 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2621 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 2622 | ASSERT(ToRegister(instr->key()).is(ecx)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2623 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2624 | |
| 2625 | int arity = instr->arity(); |
| 2626 | Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arity, NOT_IN_LOOP); |
| 2627 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | |
| 2631 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2632 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2633 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2634 | |
| 2635 | int arity = instr->arity(); |
| 2636 | Handle<Code> ic = StubCache::ComputeCallInitialize(arity, NOT_IN_LOOP); |
| 2637 | __ mov(ecx, instr->name()); |
| 2638 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | |
| 2642 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2643 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2644 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2645 | |
| 2646 | int arity = instr->arity(); |
| 2647 | CallFunctionStub stub(arity, NOT_IN_LOOP, RECEIVER_MIGHT_BE_VALUE); |
| 2648 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2649 | __ Drop(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | |
| 2653 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2654 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2655 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2656 | |
| 2657 | int arity = instr->arity(); |
| 2658 | Handle<Code> ic = StubCache::ComputeCallInitialize(arity, NOT_IN_LOOP); |
| 2659 | __ mov(ecx, instr->name()); |
| 2660 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | |
| 2664 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 2665 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2666 | __ mov(edi, instr->target()); |
| 2667 | CallKnownFunction(instr->target(), instr->arity(), instr); |
| 2668 | } |
| 2669 | |
| 2670 | |
| 2671 | void LCodeGen::DoCallNew(LCallNew* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2672 | ASSERT(ToRegister(instr->context()).is(esi)); |
| 2673 | ASSERT(ToRegister(instr->constructor()).is(edi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2674 | ASSERT(ToRegister(instr->result()).is(eax)); |
| 2675 | |
| 2676 | Handle<Code> builtin(Builtins::builtin(Builtins::JSConstructCall)); |
| 2677 | __ Set(eax, Immediate(instr->arity())); |
| 2678 | CallCode(builtin, RelocInfo::CONSTRUCT_CALL, instr); |
| 2679 | } |
| 2680 | |
| 2681 | |
| 2682 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2683 | CallRuntime(instr->function(), instr->arity(), instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
| 2688 | Register object = ToRegister(instr->object()); |
| 2689 | Register value = ToRegister(instr->value()); |
| 2690 | int offset = instr->offset(); |
| 2691 | |
| 2692 | if (!instr->transition().is_null()) { |
| 2693 | __ mov(FieldOperand(object, HeapObject::kMapOffset), instr->transition()); |
| 2694 | } |
| 2695 | |
| 2696 | // Do the store. |
| 2697 | if (instr->is_in_object()) { |
| 2698 | __ mov(FieldOperand(object, offset), value); |
| 2699 | if (instr->needs_write_barrier()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2700 | Register temp = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2701 | // Update the write barrier for the object for in-object properties. |
| 2702 | __ RecordWrite(object, offset, value, temp); |
| 2703 | } |
| 2704 | } else { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2705 | Register temp = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2706 | __ mov(temp, FieldOperand(object, JSObject::kPropertiesOffset)); |
| 2707 | __ mov(FieldOperand(temp, offset), value); |
| 2708 | if (instr->needs_write_barrier()) { |
| 2709 | // Update the write barrier for the properties array. |
| 2710 | // object is used as a scratch register. |
| 2711 | __ RecordWrite(temp, offset, value, object); |
| 2712 | } |
| 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | |
| 2717 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2718 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2719 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 2720 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 2721 | |
| 2722 | __ mov(ecx, instr->name()); |
| 2723 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 2724 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2725 | } |
| 2726 | |
| 2727 | |
| 2728 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
| 2729 | __ cmp(ToRegister(instr->index()), ToOperand(instr->length())); |
| 2730 | DeoptimizeIf(above_equal, instr->environment()); |
| 2731 | } |
| 2732 | |
| 2733 | |
| 2734 | void LCodeGen::DoStoreKeyedFastElement(LStoreKeyedFastElement* instr) { |
| 2735 | Register value = ToRegister(instr->value()); |
| 2736 | Register elements = ToRegister(instr->object()); |
| 2737 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 2738 | |
| 2739 | // Do the store. |
| 2740 | if (instr->key()->IsConstantOperand()) { |
| 2741 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 2742 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 2743 | int offset = |
| 2744 | ToInteger32(const_operand) * kPointerSize + FixedArray::kHeaderSize; |
| 2745 | __ mov(FieldOperand(elements, offset), value); |
| 2746 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2747 | __ mov(FieldOperand(elements, |
| 2748 | key, |
| 2749 | times_pointer_size, |
| 2750 | FixedArray::kHeaderSize), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2751 | value); |
| 2752 | } |
| 2753 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2754 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 2755 | // Compute address of modified element and store it into key register. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2756 | __ lea(key, |
| 2757 | FieldOperand(elements, |
| 2758 | key, |
| 2759 | times_pointer_size, |
| 2760 | FixedArray::kHeaderSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2761 | __ RecordWrite(elements, key, value); |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | |
| 2766 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2767 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2768 | ASSERT(ToRegister(instr->object()).is(edx)); |
| 2769 | ASSERT(ToRegister(instr->key()).is(ecx)); |
| 2770 | ASSERT(ToRegister(instr->value()).is(eax)); |
| 2771 | |
| 2772 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 2773 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2774 | } |
| 2775 | |
| 2776 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2777 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 2778 | class DeferredStringCharCodeAt: public LDeferredCode { |
| 2779 | public: |
| 2780 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 2781 | : LDeferredCode(codegen), instr_(instr) { } |
| 2782 | virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 2783 | private: |
| 2784 | LStringCharCodeAt* instr_; |
| 2785 | }; |
| 2786 | |
| 2787 | Register string = ToRegister(instr->string()); |
| 2788 | Register index = no_reg; |
| 2789 | int const_index = -1; |
| 2790 | if (instr->index()->IsConstantOperand()) { |
| 2791 | const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2792 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 2793 | if (!Smi::IsValid(const_index)) { |
| 2794 | // Guaranteed to be out of bounds because of the assert above. |
| 2795 | // So the bounds check that must dominate this instruction must |
| 2796 | // have deoptimized already. |
| 2797 | if (FLAG_debug_code) { |
| 2798 | __ Abort("StringCharCodeAt: out of bounds index."); |
| 2799 | } |
| 2800 | // No code needs to be generated. |
| 2801 | return; |
| 2802 | } |
| 2803 | } else { |
| 2804 | index = ToRegister(instr->index()); |
| 2805 | } |
| 2806 | Register result = ToRegister(instr->result()); |
| 2807 | |
| 2808 | DeferredStringCharCodeAt* deferred = |
| 2809 | new DeferredStringCharCodeAt(this, instr); |
| 2810 | |
| 2811 | NearLabel flat_string, ascii_string, done; |
| 2812 | |
| 2813 | // Fetch the instance type of the receiver into result register. |
| 2814 | __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
| 2815 | __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
| 2816 | |
| 2817 | // We need special handling for non-flat strings. |
| 2818 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2819 | __ test(result, Immediate(kStringRepresentationMask)); |
| 2820 | __ j(zero, &flat_string); |
| 2821 | |
| 2822 | // Handle non-flat strings. |
| 2823 | __ test(result, Immediate(kIsConsStringMask)); |
| 2824 | __ j(zero, deferred->entry()); |
| 2825 | |
| 2826 | // ConsString. |
| 2827 | // Check whether the right hand side is the empty string (i.e. if |
| 2828 | // this is really a flat string in a cons string). If that is not |
| 2829 | // the case we would rather go to the runtime system now to flatten |
| 2830 | // the string. |
| 2831 | __ cmp(FieldOperand(string, ConsString::kSecondOffset), |
| 2832 | Immediate(Factory::empty_string())); |
| 2833 | __ j(not_equal, deferred->entry()); |
| 2834 | // Get the first of the two strings and load its instance type. |
| 2835 | __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); |
| 2836 | __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
| 2837 | __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
| 2838 | // If the first cons component is also non-flat, then go to runtime. |
| 2839 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2840 | __ test(result, Immediate(kStringRepresentationMask)); |
| 2841 | __ j(not_zero, deferred->entry()); |
| 2842 | |
| 2843 | // Check for 1-byte or 2-byte string. |
| 2844 | __ bind(&flat_string); |
| 2845 | STATIC_ASSERT(kAsciiStringTag != 0); |
| 2846 | __ test(result, Immediate(kStringEncodingMask)); |
| 2847 | __ j(not_zero, &ascii_string); |
| 2848 | |
| 2849 | // 2-byte string. |
| 2850 | // Load the 2-byte character code into the result register. |
| 2851 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 2852 | if (instr->index()->IsConstantOperand()) { |
| 2853 | __ movzx_w(result, |
| 2854 | FieldOperand(string, |
| 2855 | SeqTwoByteString::kHeaderSize + 2 * const_index)); |
| 2856 | } else { |
| 2857 | __ movzx_w(result, FieldOperand(string, |
| 2858 | index, |
| 2859 | times_2, |
| 2860 | SeqTwoByteString::kHeaderSize)); |
| 2861 | } |
| 2862 | __ jmp(&done); |
| 2863 | |
| 2864 | // ASCII string. |
| 2865 | // Load the byte into the result register. |
| 2866 | __ bind(&ascii_string); |
| 2867 | if (instr->index()->IsConstantOperand()) { |
| 2868 | __ movzx_b(result, FieldOperand(string, |
| 2869 | SeqAsciiString::kHeaderSize + const_index)); |
| 2870 | } else { |
| 2871 | __ movzx_b(result, FieldOperand(string, |
| 2872 | index, |
| 2873 | times_1, |
| 2874 | SeqAsciiString::kHeaderSize)); |
| 2875 | } |
| 2876 | __ bind(&done); |
| 2877 | __ bind(deferred->exit()); |
| 2878 | } |
| 2879 | |
| 2880 | |
| 2881 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 2882 | Register string = ToRegister(instr->string()); |
| 2883 | Register result = ToRegister(instr->result()); |
| 2884 | |
| 2885 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 2886 | // result register contain a valid pointer because it is already |
| 2887 | // contained in the register pointer map. |
| 2888 | __ Set(result, Immediate(0)); |
| 2889 | |
| 2890 | __ PushSafepointRegisters(); |
| 2891 | __ push(string); |
| 2892 | // Push the index as a smi. This is safe because of the checks in |
| 2893 | // DoStringCharCodeAt above. |
| 2894 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 2895 | if (instr->index()->IsConstantOperand()) { |
| 2896 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2897 | __ push(Immediate(Smi::FromInt(const_index))); |
| 2898 | } else { |
| 2899 | Register index = ToRegister(instr->index()); |
| 2900 | __ SmiTag(index); |
| 2901 | __ push(index); |
| 2902 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2903 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2904 | __ CallRuntimeSaveDoubles(Runtime::kStringCharCodeAt); |
| 2905 | RecordSafepointWithRegisters( |
| 2906 | instr->pointer_map(), 2, Safepoint::kNoDeoptimizationIndex); |
| 2907 | if (FLAG_debug_code) { |
| 2908 | __ AbortIfNotSmi(eax); |
| 2909 | } |
| 2910 | __ SmiUntag(eax); |
| 2911 | __ mov(Operand(esp, EspIndexForPushAll(result) * kPointerSize), eax); |
| 2912 | __ PopSafepointRegisters(); |
| 2913 | } |
| 2914 | |
| 2915 | |
| 2916 | void LCodeGen::DoStringLength(LStringLength* instr) { |
| 2917 | Register string = ToRegister(instr->string()); |
| 2918 | Register result = ToRegister(instr->result()); |
| 2919 | __ mov(result, FieldOperand(string, String::kLengthOffset)); |
| 2920 | } |
| 2921 | |
| 2922 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2923 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2924 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2925 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 2926 | LOperand* output = instr->result(); |
| 2927 | ASSERT(output->IsDoubleRegister()); |
| 2928 | __ cvtsi2sd(ToDoubleRegister(output), ToOperand(input)); |
| 2929 | } |
| 2930 | |
| 2931 | |
| 2932 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 2933 | class DeferredNumberTagI: public LDeferredCode { |
| 2934 | public: |
| 2935 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 2936 | : LDeferredCode(codegen), instr_(instr) { } |
| 2937 | virtual void Generate() { codegen()->DoDeferredNumberTagI(instr_); } |
| 2938 | private: |
| 2939 | LNumberTagI* instr_; |
| 2940 | }; |
| 2941 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2942 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2943 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 2944 | Register reg = ToRegister(input); |
| 2945 | |
| 2946 | DeferredNumberTagI* deferred = new DeferredNumberTagI(this, instr); |
| 2947 | __ SmiTag(reg); |
| 2948 | __ j(overflow, deferred->entry()); |
| 2949 | __ bind(deferred->exit()); |
| 2950 | } |
| 2951 | |
| 2952 | |
| 2953 | void LCodeGen::DoDeferredNumberTagI(LNumberTagI* instr) { |
| 2954 | Label slow; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2955 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2956 | Register tmp = reg.is(eax) ? ecx : eax; |
| 2957 | |
| 2958 | // Preserve the value of all registers. |
| 2959 | __ PushSafepointRegisters(); |
| 2960 | |
| 2961 | // There was overflow, so bits 30 and 31 of the original integer |
| 2962 | // disagree. Try to allocate a heap number in new space and store |
| 2963 | // the value in there. If that fails, call the runtime system. |
| 2964 | NearLabel done; |
| 2965 | __ SmiUntag(reg); |
| 2966 | __ xor_(reg, 0x80000000); |
| 2967 | __ cvtsi2sd(xmm0, Operand(reg)); |
| 2968 | if (FLAG_inline_new) { |
| 2969 | __ AllocateHeapNumber(reg, tmp, no_reg, &slow); |
| 2970 | __ jmp(&done); |
| 2971 | } |
| 2972 | |
| 2973 | // Slow case: Call the runtime system to do the number allocation. |
| 2974 | __ bind(&slow); |
| 2975 | |
| 2976 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 2977 | // register is stored, as this register is in the pointer map, but contains an |
| 2978 | // integer value. |
| 2979 | __ mov(Operand(esp, EspIndexForPushAll(reg) * kPointerSize), Immediate(0)); |
| 2980 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2981 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2982 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 2983 | RecordSafepointWithRegisters( |
| 2984 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 2985 | if (!reg.is(eax)) __ mov(reg, eax); |
| 2986 | |
| 2987 | // Done. Put the value in xmm0 into the value of the allocated heap |
| 2988 | // number. |
| 2989 | __ bind(&done); |
| 2990 | __ movdbl(FieldOperand(reg, HeapNumber::kValueOffset), xmm0); |
| 2991 | __ mov(Operand(esp, EspIndexForPushAll(reg) * kPointerSize), reg); |
| 2992 | __ PopSafepointRegisters(); |
| 2993 | } |
| 2994 | |
| 2995 | |
| 2996 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 2997 | class DeferredNumberTagD: public LDeferredCode { |
| 2998 | public: |
| 2999 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 3000 | : LDeferredCode(codegen), instr_(instr) { } |
| 3001 | virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); } |
| 3002 | private: |
| 3003 | LNumberTagD* instr_; |
| 3004 | }; |
| 3005 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3006 | XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3007 | Register reg = ToRegister(instr->result()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3008 | Register tmp = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3009 | |
| 3010 | DeferredNumberTagD* deferred = new DeferredNumberTagD(this, instr); |
| 3011 | if (FLAG_inline_new) { |
| 3012 | __ AllocateHeapNumber(reg, tmp, no_reg, deferred->entry()); |
| 3013 | } else { |
| 3014 | __ jmp(deferred->entry()); |
| 3015 | } |
| 3016 | __ bind(deferred->exit()); |
| 3017 | __ movdbl(FieldOperand(reg, HeapNumber::kValueOffset), input_reg); |
| 3018 | } |
| 3019 | |
| 3020 | |
| 3021 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 3022 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 3023 | // result register contain a valid pointer because it is already |
| 3024 | // contained in the register pointer map. |
| 3025 | Register reg = ToRegister(instr->result()); |
| 3026 | __ Set(reg, Immediate(0)); |
| 3027 | |
| 3028 | __ PushSafepointRegisters(); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3029 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3030 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 3031 | RecordSafepointWithRegisters( |
| 3032 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 3033 | __ mov(Operand(esp, EspIndexForPushAll(reg) * kPointerSize), eax); |
| 3034 | __ PopSafepointRegisters(); |
| 3035 | } |
| 3036 | |
| 3037 | |
| 3038 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3039 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3040 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 3041 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
| 3042 | __ SmiTag(ToRegister(input)); |
| 3043 | } |
| 3044 | |
| 3045 | |
| 3046 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3047 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3048 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 3049 | if (instr->needs_check()) { |
| 3050 | __ test(ToRegister(input), Immediate(kSmiTagMask)); |
| 3051 | DeoptimizeIf(not_zero, instr->environment()); |
| 3052 | } |
| 3053 | __ SmiUntag(ToRegister(input)); |
| 3054 | } |
| 3055 | |
| 3056 | |
| 3057 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 3058 | XMMRegister result_reg, |
| 3059 | LEnvironment* env) { |
| 3060 | NearLabel load_smi, heap_number, done; |
| 3061 | |
| 3062 | // Smi check. |
| 3063 | __ test(input_reg, Immediate(kSmiTagMask)); |
| 3064 | __ j(zero, &load_smi, not_taken); |
| 3065 | |
| 3066 | // Heap number map check. |
| 3067 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 3068 | Factory::heap_number_map()); |
| 3069 | __ j(equal, &heap_number); |
| 3070 | |
| 3071 | __ cmp(input_reg, Factory::undefined_value()); |
| 3072 | DeoptimizeIf(not_equal, env); |
| 3073 | |
| 3074 | // Convert undefined to NaN. |
| 3075 | __ push(input_reg); |
| 3076 | __ mov(input_reg, Factory::nan_value()); |
| 3077 | __ movdbl(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 3078 | __ pop(input_reg); |
| 3079 | __ jmp(&done); |
| 3080 | |
| 3081 | // Heap number to XMM conversion. |
| 3082 | __ bind(&heap_number); |
| 3083 | __ movdbl(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 3084 | __ jmp(&done); |
| 3085 | |
| 3086 | // Smi to XMM conversion |
| 3087 | __ bind(&load_smi); |
| 3088 | __ SmiUntag(input_reg); // Untag smi before converting to float. |
| 3089 | __ cvtsi2sd(result_reg, Operand(input_reg)); |
| 3090 | __ SmiTag(input_reg); // Retag smi. |
| 3091 | __ bind(&done); |
| 3092 | } |
| 3093 | |
| 3094 | |
| 3095 | class DeferredTaggedToI: public LDeferredCode { |
| 3096 | public: |
| 3097 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 3098 | : LDeferredCode(codegen), instr_(instr) { } |
| 3099 | virtual void Generate() { codegen()->DoDeferredTaggedToI(instr_); } |
| 3100 | private: |
| 3101 | LTaggedToI* instr_; |
| 3102 | }; |
| 3103 | |
| 3104 | |
| 3105 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
| 3106 | NearLabel done, heap_number; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3107 | Register input_reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3108 | |
| 3109 | // Heap number map check. |
| 3110 | __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), |
| 3111 | Factory::heap_number_map()); |
| 3112 | |
| 3113 | if (instr->truncating()) { |
| 3114 | __ j(equal, &heap_number); |
| 3115 | // Check for undefined. Undefined is converted to zero for truncating |
| 3116 | // conversions. |
| 3117 | __ cmp(input_reg, Factory::undefined_value()); |
| 3118 | DeoptimizeIf(not_equal, instr->environment()); |
| 3119 | __ mov(input_reg, 0); |
| 3120 | __ jmp(&done); |
| 3121 | |
| 3122 | __ bind(&heap_number); |
| 3123 | if (CpuFeatures::IsSupported(SSE3)) { |
| 3124 | CpuFeatures::Scope scope(SSE3); |
| 3125 | NearLabel convert; |
| 3126 | // Use more powerful conversion when sse3 is available. |
| 3127 | // Load x87 register with heap number. |
| 3128 | __ fld_d(FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 3129 | // Get exponent alone and check for too-big exponent. |
| 3130 | __ mov(input_reg, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 3131 | __ and_(input_reg, HeapNumber::kExponentMask); |
| 3132 | const uint32_t kTooBigExponent = |
| 3133 | (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; |
| 3134 | __ cmp(Operand(input_reg), Immediate(kTooBigExponent)); |
| 3135 | __ j(less, &convert); |
| 3136 | // Pop FPU stack before deoptimizing. |
| 3137 | __ ffree(0); |
| 3138 | __ fincstp(); |
| 3139 | DeoptimizeIf(no_condition, instr->environment()); |
| 3140 | |
| 3141 | // Reserve space for 64 bit answer. |
| 3142 | __ bind(&convert); |
| 3143 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
| 3144 | // Do conversion, which cannot fail because we checked the exponent. |
| 3145 | __ fisttp_d(Operand(esp, 0)); |
| 3146 | __ mov(input_reg, Operand(esp, 0)); // Low word of answer is the result. |
| 3147 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 3148 | } else { |
| 3149 | NearLabel deopt; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3150 | XMMRegister xmm_temp = ToDoubleRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3151 | __ movdbl(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 3152 | __ cvttsd2si(input_reg, Operand(xmm0)); |
| 3153 | __ cmp(input_reg, 0x80000000u); |
| 3154 | __ j(not_equal, &done); |
| 3155 | // Check if the input was 0x8000000 (kMinInt). |
| 3156 | // If no, then we got an overflow and we deoptimize. |
| 3157 | ExternalReference min_int = ExternalReference::address_of_min_int(); |
| 3158 | __ movdbl(xmm_temp, Operand::StaticVariable(min_int)); |
| 3159 | __ ucomisd(xmm_temp, xmm0); |
| 3160 | DeoptimizeIf(not_equal, instr->environment()); |
| 3161 | DeoptimizeIf(parity_even, instr->environment()); // NaN. |
| 3162 | } |
| 3163 | } else { |
| 3164 | // Deoptimize if we don't have a heap number. |
| 3165 | DeoptimizeIf(not_equal, instr->environment()); |
| 3166 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3167 | XMMRegister xmm_temp = ToDoubleRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3168 | __ movdbl(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 3169 | __ cvttsd2si(input_reg, Operand(xmm0)); |
| 3170 | __ cvtsi2sd(xmm_temp, Operand(input_reg)); |
| 3171 | __ ucomisd(xmm0, xmm_temp); |
| 3172 | DeoptimizeIf(not_equal, instr->environment()); |
| 3173 | DeoptimizeIf(parity_even, instr->environment()); // NaN. |
| 3174 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3175 | __ test(input_reg, Operand(input_reg)); |
| 3176 | __ j(not_zero, &done); |
| 3177 | __ movmskpd(input_reg, xmm0); |
| 3178 | __ and_(input_reg, 1); |
| 3179 | DeoptimizeIf(not_zero, instr->environment()); |
| 3180 | } |
| 3181 | } |
| 3182 | __ bind(&done); |
| 3183 | } |
| 3184 | |
| 3185 | |
| 3186 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3187 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3188 | ASSERT(input->IsRegister()); |
| 3189 | ASSERT(input->Equals(instr->result())); |
| 3190 | |
| 3191 | Register input_reg = ToRegister(input); |
| 3192 | |
| 3193 | DeferredTaggedToI* deferred = new DeferredTaggedToI(this, instr); |
| 3194 | |
| 3195 | // Smi check. |
| 3196 | __ test(input_reg, Immediate(kSmiTagMask)); |
| 3197 | __ j(not_zero, deferred->entry()); |
| 3198 | |
| 3199 | // Smi to int32 conversion |
| 3200 | __ SmiUntag(input_reg); // Untag smi. |
| 3201 | |
| 3202 | __ bind(deferred->exit()); |
| 3203 | } |
| 3204 | |
| 3205 | |
| 3206 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3207 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3208 | ASSERT(input->IsRegister()); |
| 3209 | LOperand* result = instr->result(); |
| 3210 | ASSERT(result->IsDoubleRegister()); |
| 3211 | |
| 3212 | Register input_reg = ToRegister(input); |
| 3213 | XMMRegister result_reg = ToDoubleRegister(result); |
| 3214 | |
| 3215 | EmitNumberUntagD(input_reg, result_reg, instr->environment()); |
| 3216 | } |
| 3217 | |
| 3218 | |
| 3219 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3220 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3221 | ASSERT(input->IsDoubleRegister()); |
| 3222 | LOperand* result = instr->result(); |
| 3223 | ASSERT(result->IsRegister()); |
| 3224 | |
| 3225 | XMMRegister input_reg = ToDoubleRegister(input); |
| 3226 | Register result_reg = ToRegister(result); |
| 3227 | |
| 3228 | if (instr->truncating()) { |
| 3229 | // Performs a truncating conversion of a floating point number as used by |
| 3230 | // the JS bitwise operations. |
| 3231 | __ cvttsd2si(result_reg, Operand(input_reg)); |
| 3232 | __ cmp(result_reg, 0x80000000u); |
| 3233 | if (CpuFeatures::IsSupported(SSE3)) { |
| 3234 | // This will deoptimize if the exponent of the input in out of range. |
| 3235 | CpuFeatures::Scope scope(SSE3); |
| 3236 | NearLabel convert, done; |
| 3237 | __ j(not_equal, &done); |
| 3238 | __ sub(Operand(esp), Immediate(kDoubleSize)); |
| 3239 | __ movdbl(Operand(esp, 0), input_reg); |
| 3240 | // Get exponent alone and check for too-big exponent. |
| 3241 | __ mov(result_reg, Operand(esp, sizeof(int32_t))); |
| 3242 | __ and_(result_reg, HeapNumber::kExponentMask); |
| 3243 | const uint32_t kTooBigExponent = |
| 3244 | (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; |
| 3245 | __ cmp(Operand(result_reg), Immediate(kTooBigExponent)); |
| 3246 | __ j(less, &convert); |
| 3247 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 3248 | DeoptimizeIf(no_condition, instr->environment()); |
| 3249 | __ bind(&convert); |
| 3250 | // Do conversion, which cannot fail because we checked the exponent. |
| 3251 | __ fld_d(Operand(esp, 0)); |
| 3252 | __ fisttp_d(Operand(esp, 0)); |
| 3253 | __ mov(result_reg, Operand(esp, 0)); // Low word of answer is the result. |
| 3254 | __ add(Operand(esp), Immediate(kDoubleSize)); |
| 3255 | __ bind(&done); |
| 3256 | } else { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3257 | NearLabel done; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3258 | Register temp_reg = ToRegister(instr->TempAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3259 | XMMRegister xmm_scratch = xmm0; |
| 3260 | |
| 3261 | // If cvttsd2si succeeded, we're done. Otherwise, we attempt |
| 3262 | // manual conversion. |
| 3263 | __ j(not_equal, &done); |
| 3264 | |
| 3265 | // Get high 32 bits of the input in result_reg and temp_reg. |
| 3266 | __ pshufd(xmm_scratch, input_reg, 1); |
| 3267 | __ movd(Operand(temp_reg), xmm_scratch); |
| 3268 | __ mov(result_reg, temp_reg); |
| 3269 | |
| 3270 | // Prepare negation mask in temp_reg. |
| 3271 | __ sar(temp_reg, kBitsPerInt - 1); |
| 3272 | |
| 3273 | // Extract the exponent from result_reg and subtract adjusted |
| 3274 | // bias from it. The adjustment is selected in a way such that |
| 3275 | // when the difference is zero, the answer is in the low 32 bits |
| 3276 | // of the input, otherwise a shift has to be performed. |
| 3277 | __ shr(result_reg, HeapNumber::kExponentShift); |
| 3278 | __ and_(result_reg, |
| 3279 | HeapNumber::kExponentMask >> HeapNumber::kExponentShift); |
| 3280 | __ sub(Operand(result_reg), |
| 3281 | Immediate(HeapNumber::kExponentBias + |
| 3282 | HeapNumber::kExponentBits + |
| 3283 | HeapNumber::kMantissaBits)); |
| 3284 | // Don't handle big (> kMantissaBits + kExponentBits == 63) or |
| 3285 | // special exponents. |
| 3286 | DeoptimizeIf(greater, instr->environment()); |
| 3287 | |
| 3288 | // Zero out the sign and the exponent in the input (by shifting |
| 3289 | // it to the left) and restore the implicit mantissa bit, |
| 3290 | // i.e. convert the input to unsigned int64 shifted left by |
| 3291 | // kExponentBits. |
| 3292 | ExternalReference minus_zero = ExternalReference::address_of_minus_zero(); |
| 3293 | // Minus zero has the most significant bit set and the other |
| 3294 | // bits cleared. |
| 3295 | __ movdbl(xmm_scratch, Operand::StaticVariable(minus_zero)); |
| 3296 | __ psllq(input_reg, HeapNumber::kExponentBits); |
| 3297 | __ por(input_reg, xmm_scratch); |
| 3298 | |
| 3299 | // Get the amount to shift the input right in xmm_scratch. |
| 3300 | __ neg(result_reg); |
| 3301 | __ movd(xmm_scratch, Operand(result_reg)); |
| 3302 | |
| 3303 | // Shift the input right and extract low 32 bits. |
| 3304 | __ psrlq(input_reg, xmm_scratch); |
| 3305 | __ movd(Operand(result_reg), input_reg); |
| 3306 | |
| 3307 | // Use the prepared mask in temp_reg to negate the result if necessary. |
| 3308 | __ xor_(result_reg, Operand(temp_reg)); |
| 3309 | __ sub(result_reg, Operand(temp_reg)); |
| 3310 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3311 | } |
| 3312 | } else { |
| 3313 | NearLabel done; |
| 3314 | __ cvttsd2si(result_reg, Operand(input_reg)); |
| 3315 | __ cvtsi2sd(xmm0, Operand(result_reg)); |
| 3316 | __ ucomisd(xmm0, input_reg); |
| 3317 | DeoptimizeIf(not_equal, instr->environment()); |
| 3318 | DeoptimizeIf(parity_even, instr->environment()); // NaN. |
| 3319 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3320 | // The integer converted back is equal to the original. We |
| 3321 | // only have to test if we got -0 as an input. |
| 3322 | __ test(result_reg, Operand(result_reg)); |
| 3323 | __ j(not_zero, &done); |
| 3324 | __ movmskpd(result_reg, input_reg); |
| 3325 | // Bit 0 contains the sign of the double in input_reg. |
| 3326 | // If input was positive, we are ok and return 0, otherwise |
| 3327 | // deoptimize. |
| 3328 | __ and_(result_reg, 1); |
| 3329 | DeoptimizeIf(not_zero, instr->environment()); |
| 3330 | } |
| 3331 | __ bind(&done); |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | |
| 3336 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3337 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3338 | ASSERT(input->IsRegister()); |
| 3339 | __ test(ToRegister(input), Immediate(kSmiTagMask)); |
| 3340 | DeoptimizeIf(instr->condition(), instr->environment()); |
| 3341 | } |
| 3342 | |
| 3343 | |
| 3344 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3345 | Register input = ToRegister(instr->InputAt(0)); |
| 3346 | Register temp = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3347 | InstanceType first = instr->hydrogen()->first(); |
| 3348 | InstanceType last = instr->hydrogen()->last(); |
| 3349 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3350 | __ mov(temp, FieldOperand(input, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3351 | |
| 3352 | // If there is only one type in the interval check for equality. |
| 3353 | if (first == last) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3354 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 3355 | static_cast<int8_t>(first)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3356 | DeoptimizeIf(not_equal, instr->environment()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3357 | } else if (first == FIRST_STRING_TYPE && last == LAST_STRING_TYPE) { |
| 3358 | // String has a dedicated bit in instance type. |
| 3359 | __ test_b(FieldOperand(temp, Map::kInstanceTypeOffset), kIsNotStringMask); |
| 3360 | DeoptimizeIf(not_zero, instr->environment()); |
| 3361 | } else { |
| 3362 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 3363 | static_cast<int8_t>(first)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3364 | DeoptimizeIf(below, instr->environment()); |
| 3365 | // Omit check for the last type. |
| 3366 | if (last != LAST_TYPE) { |
| 3367 | __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset), |
| 3368 | static_cast<int8_t>(last)); |
| 3369 | DeoptimizeIf(above, instr->environment()); |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | |
| 3375 | void LCodeGen::DoCheckFunction(LCheckFunction* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3376 | ASSERT(instr->InputAt(0)->IsRegister()); |
| 3377 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3378 | __ cmp(reg, instr->hydrogen()->target()); |
| 3379 | DeoptimizeIf(not_equal, instr->environment()); |
| 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | void LCodeGen::DoCheckMap(LCheckMap* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3384 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3385 | ASSERT(input->IsRegister()); |
| 3386 | Register reg = ToRegister(input); |
| 3387 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 3388 | instr->hydrogen()->map()); |
| 3389 | DeoptimizeIf(not_equal, instr->environment()); |
| 3390 | } |
| 3391 | |
| 3392 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3393 | void LCodeGen::LoadHeapObject(Register result, Handle<HeapObject> object) { |
| 3394 | if (Heap::InNewSpace(*object)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3395 | Handle<JSGlobalPropertyCell> cell = |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3396 | Factory::NewJSGlobalPropertyCell(object); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3397 | __ mov(result, Operand::Cell(cell)); |
| 3398 | } else { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3399 | __ mov(result, object); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | |
| 3404 | void LCodeGen::DoCheckPrototypeMaps(LCheckPrototypeMaps* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3405 | Register reg = ToRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3406 | |
| 3407 | Handle<JSObject> holder = instr->holder(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3408 | Handle<JSObject> current_prototype = instr->prototype(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3409 | |
| 3410 | // Load prototype object. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3411 | LoadHeapObject(reg, current_prototype); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3412 | |
| 3413 | // Check prototype maps up to the holder. |
| 3414 | while (!current_prototype.is_identical_to(holder)) { |
| 3415 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 3416 | Handle<Map>(current_prototype->map())); |
| 3417 | DeoptimizeIf(not_equal, instr->environment()); |
| 3418 | current_prototype = |
| 3419 | Handle<JSObject>(JSObject::cast(current_prototype->GetPrototype())); |
| 3420 | // Load next prototype object. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3421 | LoadHeapObject(reg, current_prototype); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | // Check the holder map. |
| 3425 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 3426 | Handle<Map>(current_prototype->map())); |
| 3427 | DeoptimizeIf(not_equal, instr->environment()); |
| 3428 | } |
| 3429 | |
| 3430 | |
| 3431 | void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
| 3432 | // Setup the parameters to the stub/runtime call. |
| 3433 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3434 | __ push(FieldOperand(eax, JSFunction::kLiteralsOffset)); |
| 3435 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 3436 | __ push(Immediate(instr->hydrogen()->constant_elements())); |
| 3437 | |
| 3438 | // Pick the right runtime function or stub to call. |
| 3439 | int length = instr->hydrogen()->length(); |
| 3440 | if (instr->hydrogen()->IsCopyOnWrite()) { |
| 3441 | ASSERT(instr->hydrogen()->depth() == 1); |
| 3442 | FastCloneShallowArrayStub::Mode mode = |
| 3443 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
| 3444 | FastCloneShallowArrayStub stub(mode, length); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3445 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3446 | } else if (instr->hydrogen()->depth() > 1) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3447 | CallRuntime(Runtime::kCreateArrayLiteral, 3, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3448 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3449 | CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3450 | } else { |
| 3451 | FastCloneShallowArrayStub::Mode mode = |
| 3452 | FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 3453 | FastCloneShallowArrayStub stub(mode, length); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3454 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | |
| 3458 | |
| 3459 | void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3460 | ASSERT(ToRegister(instr->context()).is(esi)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3461 | // Setup the parameters to the stub/runtime call. |
| 3462 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3463 | __ push(FieldOperand(eax, JSFunction::kLiteralsOffset)); |
| 3464 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 3465 | __ push(Immediate(instr->hydrogen()->constant_properties())); |
| 3466 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->fast_elements() ? 1 : 0))); |
| 3467 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3468 | // Pick the right runtime function to call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3469 | if (instr->hydrogen()->depth() > 1) { |
| 3470 | CallRuntime(Runtime::kCreateObjectLiteral, 4, instr); |
| 3471 | } else { |
| 3472 | CallRuntime(Runtime::kCreateObjectLiteralShallow, 4, instr); |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | |
| 3477 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
| 3478 | NearLabel materialized; |
| 3479 | // Registers will be used as follows: |
| 3480 | // edi = JS function. |
| 3481 | // ecx = literals array. |
| 3482 | // ebx = regexp literal. |
| 3483 | // eax = regexp literal clone. |
| 3484 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3485 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 3486 | int literal_offset = FixedArray::kHeaderSize + |
| 3487 | instr->hydrogen()->literal_index() * kPointerSize; |
| 3488 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
| 3489 | __ cmp(ebx, Factory::undefined_value()); |
| 3490 | __ j(not_equal, &materialized); |
| 3491 | |
| 3492 | // Create regexp literal using runtime function |
| 3493 | // Result will be in eax. |
| 3494 | __ push(ecx); |
| 3495 | __ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 3496 | __ push(Immediate(instr->hydrogen()->pattern())); |
| 3497 | __ push(Immediate(instr->hydrogen()->flags())); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3498 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3499 | __ mov(ebx, eax); |
| 3500 | |
| 3501 | __ bind(&materialized); |
| 3502 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 3503 | Label allocated, runtime_allocate; |
| 3504 | __ AllocateInNewSpace(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
| 3505 | __ jmp(&allocated); |
| 3506 | |
| 3507 | __ bind(&runtime_allocate); |
| 3508 | __ push(ebx); |
| 3509 | __ push(Immediate(Smi::FromInt(size))); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3510 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3511 | __ pop(ebx); |
| 3512 | |
| 3513 | __ bind(&allocated); |
| 3514 | // Copy the content into the newly allocated memory. |
| 3515 | // (Unroll copy loop once for better throughput). |
| 3516 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 3517 | __ mov(edx, FieldOperand(ebx, i)); |
| 3518 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 3519 | __ mov(FieldOperand(eax, i), edx); |
| 3520 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 3521 | } |
| 3522 | if ((size % (2 * kPointerSize)) != 0) { |
| 3523 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 3524 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | |
| 3529 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
| 3530 | // Use the fast case closure allocation code that allocates in new |
| 3531 | // space for nested functions that don't need literals cloning. |
| 3532 | Handle<SharedFunctionInfo> shared_info = instr->shared_info(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3533 | bool pretenure = instr->hydrogen()->pretenure(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3534 | if (shared_info->num_literals() == 0 && !pretenure) { |
| 3535 | FastNewClosureStub stub; |
| 3536 | __ push(Immediate(shared_info)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3537 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3538 | } else { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3539 | __ push(Operand(ebp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3540 | __ push(Immediate(shared_info)); |
| 3541 | __ push(Immediate(pretenure |
| 3542 | ? Factory::true_value() |
| 3543 | : Factory::false_value())); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3544 | CallRuntime(Runtime::kNewClosure, 3, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | |
| 3549 | void LCodeGen::DoTypeof(LTypeof* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3550 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3551 | if (input->IsConstantOperand()) { |
| 3552 | __ push(ToImmediate(input)); |
| 3553 | } else { |
| 3554 | __ push(ToOperand(input)); |
| 3555 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3556 | CallRuntime(Runtime::kTypeof, 1, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | |
| 3560 | void LCodeGen::DoTypeofIs(LTypeofIs* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3561 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3562 | Register result = ToRegister(instr->result()); |
| 3563 | Label true_label; |
| 3564 | Label false_label; |
| 3565 | NearLabel done; |
| 3566 | |
| 3567 | Condition final_branch_condition = EmitTypeofIs(&true_label, |
| 3568 | &false_label, |
| 3569 | input, |
| 3570 | instr->type_literal()); |
| 3571 | __ j(final_branch_condition, &true_label); |
| 3572 | __ bind(&false_label); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3573 | __ mov(result, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3574 | __ jmp(&done); |
| 3575 | |
| 3576 | __ bind(&true_label); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3577 | __ mov(result, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3578 | |
| 3579 | __ bind(&done); |
| 3580 | } |
| 3581 | |
| 3582 | |
| 3583 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3584 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3585 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 3586 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 3587 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 3588 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 3589 | |
| 3590 | Condition final_branch_condition = EmitTypeofIs(true_label, |
| 3591 | false_label, |
| 3592 | input, |
| 3593 | instr->type_literal()); |
| 3594 | |
| 3595 | EmitBranch(true_block, false_block, final_branch_condition); |
| 3596 | } |
| 3597 | |
| 3598 | |
| 3599 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 3600 | Label* false_label, |
| 3601 | Register input, |
| 3602 | Handle<String> type_name) { |
| 3603 | Condition final_branch_condition = no_condition; |
| 3604 | if (type_name->Equals(Heap::number_symbol())) { |
| 3605 | __ test(input, Immediate(kSmiTagMask)); |
| 3606 | __ j(zero, true_label); |
| 3607 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 3608 | Factory::heap_number_map()); |
| 3609 | final_branch_condition = equal; |
| 3610 | |
| 3611 | } else if (type_name->Equals(Heap::string_symbol())) { |
| 3612 | __ test(input, Immediate(kSmiTagMask)); |
| 3613 | __ j(zero, false_label); |
| 3614 | __ mov(input, FieldOperand(input, HeapObject::kMapOffset)); |
| 3615 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 3616 | 1 << Map::kIsUndetectable); |
| 3617 | __ j(not_zero, false_label); |
| 3618 | __ CmpInstanceType(input, FIRST_NONSTRING_TYPE); |
| 3619 | final_branch_condition = below; |
| 3620 | |
| 3621 | } else if (type_name->Equals(Heap::boolean_symbol())) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3622 | __ cmp(input, Factory::true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3623 | __ j(equal, true_label); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3624 | __ cmp(input, Factory::false_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3625 | final_branch_condition = equal; |
| 3626 | |
| 3627 | } else if (type_name->Equals(Heap::undefined_symbol())) { |
| 3628 | __ cmp(input, Factory::undefined_value()); |
| 3629 | __ j(equal, true_label); |
| 3630 | __ test(input, Immediate(kSmiTagMask)); |
| 3631 | __ j(zero, false_label); |
| 3632 | // Check for undetectable objects => true. |
| 3633 | __ mov(input, FieldOperand(input, HeapObject::kMapOffset)); |
| 3634 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 3635 | 1 << Map::kIsUndetectable); |
| 3636 | final_branch_condition = not_zero; |
| 3637 | |
| 3638 | } else if (type_name->Equals(Heap::function_symbol())) { |
| 3639 | __ test(input, Immediate(kSmiTagMask)); |
| 3640 | __ j(zero, false_label); |
| 3641 | __ CmpObjectType(input, JS_FUNCTION_TYPE, input); |
| 3642 | __ j(equal, true_label); |
| 3643 | // Regular expressions => 'function' (they are callable). |
| 3644 | __ CmpInstanceType(input, JS_REGEXP_TYPE); |
| 3645 | final_branch_condition = equal; |
| 3646 | |
| 3647 | } else if (type_name->Equals(Heap::object_symbol())) { |
| 3648 | __ test(input, Immediate(kSmiTagMask)); |
| 3649 | __ j(zero, false_label); |
| 3650 | __ cmp(input, Factory::null_value()); |
| 3651 | __ j(equal, true_label); |
| 3652 | // Regular expressions => 'function', not 'object'. |
| 3653 | __ CmpObjectType(input, JS_REGEXP_TYPE, input); |
| 3654 | __ j(equal, false_label); |
| 3655 | // Check for undetectable objects => false. |
| 3656 | __ test_b(FieldOperand(input, Map::kBitFieldOffset), |
| 3657 | 1 << Map::kIsUndetectable); |
| 3658 | __ j(not_zero, false_label); |
| 3659 | // Check for JS objects => true. |
| 3660 | __ CmpInstanceType(input, FIRST_JS_OBJECT_TYPE); |
| 3661 | __ j(below, false_label); |
| 3662 | __ CmpInstanceType(input, LAST_JS_OBJECT_TYPE); |
| 3663 | final_branch_condition = below_equal; |
| 3664 | |
| 3665 | } else { |
| 3666 | final_branch_condition = not_equal; |
| 3667 | __ jmp(false_label); |
| 3668 | // A dead branch instruction will be generated after this point. |
| 3669 | } |
| 3670 | |
| 3671 | return final_branch_condition; |
| 3672 | } |
| 3673 | |
| 3674 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3675 | void LCodeGen::DoIsConstructCall(LIsConstructCall* instr) { |
| 3676 | Register result = ToRegister(instr->result()); |
| 3677 | NearLabel true_label; |
| 3678 | NearLabel false_label; |
| 3679 | NearLabel done; |
| 3680 | |
| 3681 | EmitIsConstructCall(result); |
| 3682 | __ j(equal, &true_label); |
| 3683 | |
| 3684 | __ mov(result, Factory::false_value()); |
| 3685 | __ jmp(&done); |
| 3686 | |
| 3687 | __ bind(&true_label); |
| 3688 | __ mov(result, Factory::true_value()); |
| 3689 | |
| 3690 | __ bind(&done); |
| 3691 | } |
| 3692 | |
| 3693 | |
| 3694 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
| 3695 | Register temp = ToRegister(instr->TempAt(0)); |
| 3696 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 3697 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 3698 | |
| 3699 | EmitIsConstructCall(temp); |
| 3700 | EmitBranch(true_block, false_block, equal); |
| 3701 | } |
| 3702 | |
| 3703 | |
| 3704 | void LCodeGen::EmitIsConstructCall(Register temp) { |
| 3705 | // Get the frame pointer for the calling frame. |
| 3706 | __ mov(temp, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3707 | |
| 3708 | // Skip the arguments adaptor frame if it exists. |
| 3709 | NearLabel check_frame_marker; |
| 3710 | __ cmp(Operand(temp, StandardFrameConstants::kContextOffset), |
| 3711 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3712 | __ j(not_equal, &check_frame_marker); |
| 3713 | __ mov(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset)); |
| 3714 | |
| 3715 | // Check the marker in the calling frame. |
| 3716 | __ bind(&check_frame_marker); |
| 3717 | __ cmp(Operand(temp, StandardFrameConstants::kMarkerOffset), |
| 3718 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 3719 | } |
| 3720 | |
| 3721 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3722 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
| 3723 | // No code for lazy bailout instruction. Used to capture environment after a |
| 3724 | // call for populating the safepoint data with deoptimization data. |
| 3725 | } |
| 3726 | |
| 3727 | |
| 3728 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
| 3729 | DeoptimizeIf(no_condition, instr->environment()); |
| 3730 | } |
| 3731 | |
| 3732 | |
| 3733 | void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { |
| 3734 | LOperand* obj = instr->object(); |
| 3735 | LOperand* key = instr->key(); |
| 3736 | __ push(ToOperand(obj)); |
| 3737 | if (key->IsConstantOperand()) { |
| 3738 | __ push(ToImmediate(key)); |
| 3739 | } else { |
| 3740 | __ push(ToOperand(key)); |
| 3741 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3742 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 3743 | LPointerMap* pointers = instr->pointer_map(); |
| 3744 | LEnvironment* env = instr->deoptimization_environment(); |
| 3745 | RecordPosition(pointers->position()); |
| 3746 | RegisterEnvironmentForDeoptimization(env); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 3747 | // Create safepoint generator that will also ensure enough space in the |
| 3748 | // reloc info for patching in deoptimization (since this is invoking a |
| 3749 | // builtin) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3750 | SafepointGenerator safepoint_generator(this, |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3751 | pointers, |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 3752 | env->deoptimization_index(), |
| 3753 | true); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3754 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame^] | 3755 | __ push(Immediate(Smi::FromInt(strict_mode_flag()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3756 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, &safepoint_generator); |
| 3757 | } |
| 3758 | |
| 3759 | |
| 3760 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
| 3761 | // Perform stack overflow check. |
| 3762 | NearLabel done; |
| 3763 | ExternalReference stack_limit = ExternalReference::address_of_stack_limit(); |
| 3764 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 3765 | __ j(above_equal, &done); |
| 3766 | |
| 3767 | StackCheckStub stub; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3768 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3769 | __ bind(&done); |
| 3770 | } |
| 3771 | |
| 3772 | |
| 3773 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 3774 | // This is a pseudo-instruction that ensures that the environment here is |
| 3775 | // properly registered for deoptimization and records the assembler's PC |
| 3776 | // offset. |
| 3777 | LEnvironment* environment = instr->environment(); |
| 3778 | environment->SetSpilledRegisters(instr->SpilledRegisterArray(), |
| 3779 | instr->SpilledDoubleRegisterArray()); |
| 3780 | |
| 3781 | // If the environment were already registered, we would have no way of |
| 3782 | // backpatching it with the spill slot operands. |
| 3783 | ASSERT(!environment->HasBeenRegistered()); |
| 3784 | RegisterEnvironmentForDeoptimization(environment); |
| 3785 | ASSERT(osr_pc_offset_ == -1); |
| 3786 | osr_pc_offset_ = masm()->pc_offset(); |
| 3787 | } |
| 3788 | |
| 3789 | |
| 3790 | #undef __ |
| 3791 | |
| 3792 | } } // namespace v8::internal |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3793 | |
| 3794 | #endif // V8_TARGET_ARCH_IA32 |