Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <assert.h> // For assert |
| 6 | #include <limits.h> // For LONG_MIN, LONG_MAX. |
| 7 | |
| 8 | #include "src/v8.h" |
| 9 | |
| 10 | #if V8_TARGET_ARCH_PPC |
| 11 | |
| 12 | #include "src/base/bits.h" |
| 13 | #include "src/base/division-by-constant.h" |
| 14 | #include "src/bootstrapper.h" |
| 15 | #include "src/codegen.h" |
| 16 | #include "src/cpu-profiler.h" |
| 17 | #include "src/debug.h" |
| 18 | #include "src/isolate-inl.h" |
| 19 | #include "src/runtime/runtime.h" |
| 20 | |
| 21 | namespace v8 { |
| 22 | namespace internal { |
| 23 | |
| 24 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 25 | : Assembler(arg_isolate, buffer, size), |
| 26 | generating_stub_(false), |
| 27 | has_frame_(false) { |
| 28 | if (isolate() != NULL) { |
| 29 | code_object_ = |
| 30 | Handle<Object>(isolate()->heap()->undefined_value(), isolate()); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | |
| 35 | void MacroAssembler::Jump(Register target) { |
| 36 | mtctr(target); |
| 37 | bctr(); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | void MacroAssembler::JumpToJSEntry(Register target) { |
| 42 | Move(ip, target); |
| 43 | Jump(ip); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 48 | Condition cond, CRegister cr) { |
| 49 | Label skip; |
| 50 | |
| 51 | if (cond != al) b(NegateCondition(cond), &skip, cr); |
| 52 | |
| 53 | DCHECK(rmode == RelocInfo::CODE_TARGET || rmode == RelocInfo::RUNTIME_ENTRY); |
| 54 | |
| 55 | mov(ip, Operand(target, rmode)); |
| 56 | mtctr(ip); |
| 57 | bctr(); |
| 58 | |
| 59 | bind(&skip); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | void MacroAssembler::Jump(Address target, RelocInfo::Mode rmode, Condition cond, |
| 64 | CRegister cr) { |
| 65 | DCHECK(!RelocInfo::IsCodeTarget(rmode)); |
| 66 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond, cr); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 71 | Condition cond) { |
| 72 | DCHECK(RelocInfo::IsCodeTarget(rmode)); |
| 73 | // 'code' is always generated ppc code, never THUMB code |
| 74 | AllowDeferredHandleDereference embedding_raw_address; |
| 75 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | int MacroAssembler::CallSize(Register target) { return 2 * kInstrSize; } |
| 80 | |
| 81 | |
| 82 | void MacroAssembler::Call(Register target) { |
| 83 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 84 | Label start; |
| 85 | bind(&start); |
| 86 | |
| 87 | // Statement positions are expected to be recorded when the target |
| 88 | // address is loaded. |
| 89 | positions_recorder()->WriteRecordedPositions(); |
| 90 | |
| 91 | // branch via link register and set LK bit for return point |
| 92 | mtctr(target); |
| 93 | bctrl(); |
| 94 | |
| 95 | DCHECK_EQ(CallSize(target), SizeOfCodeGeneratedSince(&start)); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | void MacroAssembler::CallJSEntry(Register target) { |
| 100 | DCHECK(target.is(ip)); |
| 101 | Call(target); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | int MacroAssembler::CallSize(Address target, RelocInfo::Mode rmode, |
| 106 | Condition cond) { |
| 107 | Operand mov_operand = Operand(reinterpret_cast<intptr_t>(target), rmode); |
| 108 | return (2 + instructions_required_for_mov(mov_operand)) * kInstrSize; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | int MacroAssembler::CallSizeNotPredictableCodeSize(Address target, |
| 113 | RelocInfo::Mode rmode, |
| 114 | Condition cond) { |
| 115 | return (2 + kMovInstructionsNoConstantPool) * kInstrSize; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | void MacroAssembler::Call(Address target, RelocInfo::Mode rmode, |
| 120 | Condition cond) { |
| 121 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 122 | DCHECK(cond == al); |
| 123 | |
| 124 | #ifdef DEBUG |
| 125 | // Check the expected size before generating code to ensure we assume the same |
| 126 | // constant pool availability (e.g., whether constant pool is full or not). |
| 127 | int expected_size = CallSize(target, rmode, cond); |
| 128 | Label start; |
| 129 | bind(&start); |
| 130 | #endif |
| 131 | |
| 132 | // Statement positions are expected to be recorded when the target |
| 133 | // address is loaded. |
| 134 | positions_recorder()->WriteRecordedPositions(); |
| 135 | |
| 136 | // This can likely be optimized to make use of bc() with 24bit relative |
| 137 | // |
| 138 | // RecordRelocInfo(x.rmode_, x.imm_); |
| 139 | // bc( BA, .... offset, LKset); |
| 140 | // |
| 141 | |
| 142 | mov(ip, Operand(reinterpret_cast<intptr_t>(target), rmode)); |
| 143 | mtctr(ip); |
| 144 | bctrl(); |
| 145 | |
| 146 | DCHECK_EQ(expected_size, SizeOfCodeGeneratedSince(&start)); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | int MacroAssembler::CallSize(Handle<Code> code, RelocInfo::Mode rmode, |
| 151 | TypeFeedbackId ast_id, Condition cond) { |
| 152 | AllowDeferredHandleDereference using_raw_address; |
| 153 | return CallSize(reinterpret_cast<Address>(code.location()), rmode, cond); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, |
| 158 | TypeFeedbackId ast_id, Condition cond) { |
| 159 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 160 | DCHECK(RelocInfo::IsCodeTarget(rmode)); |
| 161 | |
| 162 | #ifdef DEBUG |
| 163 | // Check the expected size before generating code to ensure we assume the same |
| 164 | // constant pool availability (e.g., whether constant pool is full or not). |
| 165 | int expected_size = CallSize(code, rmode, ast_id, cond); |
| 166 | Label start; |
| 167 | bind(&start); |
| 168 | #endif |
| 169 | |
| 170 | if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) { |
| 171 | SetRecordedAstId(ast_id); |
| 172 | rmode = RelocInfo::CODE_TARGET_WITH_ID; |
| 173 | } |
| 174 | AllowDeferredHandleDereference using_raw_address; |
| 175 | Call(reinterpret_cast<Address>(code.location()), rmode, cond); |
| 176 | DCHECK_EQ(expected_size, SizeOfCodeGeneratedSince(&start)); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | void MacroAssembler::Ret(Condition cond) { |
| 181 | DCHECK(cond == al); |
| 182 | blr(); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | void MacroAssembler::Drop(int count, Condition cond) { |
| 187 | DCHECK(cond == al); |
| 188 | if (count > 0) { |
| 189 | Add(sp, sp, count * kPointerSize, r0); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | |
| 194 | void MacroAssembler::Ret(int drop, Condition cond) { |
| 195 | Drop(drop, cond); |
| 196 | Ret(cond); |
| 197 | } |
| 198 | |
| 199 | |
| 200 | void MacroAssembler::Call(Label* target) { b(target, SetLK); } |
| 201 | |
| 202 | |
| 203 | void MacroAssembler::Push(Handle<Object> handle) { |
| 204 | mov(r0, Operand(handle)); |
| 205 | push(r0); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 210 | AllowDeferredHandleDereference smi_check; |
| 211 | if (value->IsSmi()) { |
| 212 | LoadSmiLiteral(dst, reinterpret_cast<Smi*>(*value)); |
| 213 | } else { |
| 214 | DCHECK(value->IsHeapObject()); |
| 215 | if (isolate()->heap()->InNewSpace(*value)) { |
| 216 | Handle<Cell> cell = isolate()->factory()->NewCell(value); |
| 217 | mov(dst, Operand(cell)); |
| 218 | LoadP(dst, FieldMemOperand(dst, Cell::kValueOffset)); |
| 219 | } else { |
| 220 | mov(dst, Operand(value)); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | |
| 226 | void MacroAssembler::Move(Register dst, Register src, Condition cond) { |
| 227 | DCHECK(cond == al); |
| 228 | if (!dst.is(src)) { |
| 229 | mr(dst, src); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
| 234 | void MacroAssembler::Move(DoubleRegister dst, DoubleRegister src) { |
| 235 | if (!dst.is(src)) { |
| 236 | fmr(dst, src); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | |
| 241 | void MacroAssembler::MultiPush(RegList regs) { |
| 242 | int16_t num_to_push = NumberOfBitsSet(regs); |
| 243 | int16_t stack_offset = num_to_push * kPointerSize; |
| 244 | |
| 245 | subi(sp, sp, Operand(stack_offset)); |
| 246 | for (int16_t i = kNumRegisters - 1; i >= 0; i--) { |
| 247 | if ((regs & (1 << i)) != 0) { |
| 248 | stack_offset -= kPointerSize; |
| 249 | StoreP(ToRegister(i), MemOperand(sp, stack_offset)); |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | |
| 255 | void MacroAssembler::MultiPop(RegList regs) { |
| 256 | int16_t stack_offset = 0; |
| 257 | |
| 258 | for (int16_t i = 0; i < kNumRegisters; i++) { |
| 259 | if ((regs & (1 << i)) != 0) { |
| 260 | LoadP(ToRegister(i), MemOperand(sp, stack_offset)); |
| 261 | stack_offset += kPointerSize; |
| 262 | } |
| 263 | } |
| 264 | addi(sp, sp, Operand(stack_offset)); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index, |
| 269 | Condition cond) { |
| 270 | DCHECK(cond == al); |
| 271 | LoadP(destination, MemOperand(kRootRegister, index << kPointerSizeLog2), r0); |
| 272 | } |
| 273 | |
| 274 | |
| 275 | void MacroAssembler::StoreRoot(Register source, Heap::RootListIndex index, |
| 276 | Condition cond) { |
| 277 | DCHECK(cond == al); |
| 278 | StoreP(source, MemOperand(kRootRegister, index << kPointerSizeLog2), r0); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | void MacroAssembler::InNewSpace(Register object, Register scratch, |
| 283 | Condition cond, Label* branch) { |
| 284 | // N.B. scratch may be same register as object |
| 285 | DCHECK(cond == eq || cond == ne); |
| 286 | mov(r0, Operand(ExternalReference::new_space_mask(isolate()))); |
| 287 | and_(scratch, object, r0); |
| 288 | mov(r0, Operand(ExternalReference::new_space_start(isolate()))); |
| 289 | cmp(scratch, r0); |
| 290 | b(cond, branch); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | void MacroAssembler::RecordWriteField( |
| 295 | Register object, int offset, Register value, Register dst, |
| 296 | LinkRegisterStatus lr_status, SaveFPRegsMode save_fp, |
| 297 | RememberedSetAction remembered_set_action, SmiCheck smi_check, |
| 298 | PointersToHereCheck pointers_to_here_check_for_value) { |
| 299 | // First, check if a write barrier is even needed. The tests below |
| 300 | // catch stores of Smis. |
| 301 | Label done; |
| 302 | |
| 303 | // Skip barrier if writing a smi. |
| 304 | if (smi_check == INLINE_SMI_CHECK) { |
| 305 | JumpIfSmi(value, &done); |
| 306 | } |
| 307 | |
| 308 | // Although the object register is tagged, the offset is relative to the start |
| 309 | // of the object, so so offset must be a multiple of kPointerSize. |
| 310 | DCHECK(IsAligned(offset, kPointerSize)); |
| 311 | |
| 312 | Add(dst, object, offset - kHeapObjectTag, r0); |
| 313 | if (emit_debug_code()) { |
| 314 | Label ok; |
| 315 | andi(r0, dst, Operand((1 << kPointerSizeLog2) - 1)); |
| 316 | beq(&ok, cr0); |
| 317 | stop("Unaligned cell in write barrier"); |
| 318 | bind(&ok); |
| 319 | } |
| 320 | |
| 321 | RecordWrite(object, dst, value, lr_status, save_fp, remembered_set_action, |
| 322 | OMIT_SMI_CHECK, pointers_to_here_check_for_value); |
| 323 | |
| 324 | bind(&done); |
| 325 | |
| 326 | // Clobber clobbered input registers when running with the debug-code flag |
| 327 | // turned on to provoke errors. |
| 328 | if (emit_debug_code()) { |
| 329 | mov(value, Operand(bit_cast<intptr_t>(kZapValue + 4))); |
| 330 | mov(dst, Operand(bit_cast<intptr_t>(kZapValue + 8))); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | |
| 335 | // Will clobber 4 registers: object, map, dst, ip. The |
| 336 | // register 'object' contains a heap object pointer. |
| 337 | void MacroAssembler::RecordWriteForMap(Register object, Register map, |
| 338 | Register dst, |
| 339 | LinkRegisterStatus lr_status, |
| 340 | SaveFPRegsMode fp_mode) { |
| 341 | if (emit_debug_code()) { |
| 342 | LoadP(dst, FieldMemOperand(map, HeapObject::kMapOffset)); |
| 343 | Cmpi(dst, Operand(isolate()->factory()->meta_map()), r0); |
| 344 | Check(eq, kWrongAddressOrValuePassedToRecordWrite); |
| 345 | } |
| 346 | |
| 347 | if (!FLAG_incremental_marking) { |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | if (emit_debug_code()) { |
| 352 | LoadP(ip, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 353 | cmp(ip, map); |
| 354 | Check(eq, kWrongAddressOrValuePassedToRecordWrite); |
| 355 | } |
| 356 | |
| 357 | Label done; |
| 358 | |
| 359 | // A single check of the map's pages interesting flag suffices, since it is |
| 360 | // only set during incremental collection, and then it's also guaranteed that |
| 361 | // the from object's page's interesting flag is also set. This optimization |
| 362 | // relies on the fact that maps can never be in new space. |
| 363 | CheckPageFlag(map, |
| 364 | map, // Used as scratch. |
| 365 | MemoryChunk::kPointersToHereAreInterestingMask, eq, &done); |
| 366 | |
| 367 | addi(dst, object, Operand(HeapObject::kMapOffset - kHeapObjectTag)); |
| 368 | if (emit_debug_code()) { |
| 369 | Label ok; |
| 370 | andi(r0, dst, Operand((1 << kPointerSizeLog2) - 1)); |
| 371 | beq(&ok, cr0); |
| 372 | stop("Unaligned cell in write barrier"); |
| 373 | bind(&ok); |
| 374 | } |
| 375 | |
| 376 | // Record the actual write. |
| 377 | if (lr_status == kLRHasNotBeenSaved) { |
| 378 | mflr(r0); |
| 379 | push(r0); |
| 380 | } |
| 381 | RecordWriteStub stub(isolate(), object, map, dst, OMIT_REMEMBERED_SET, |
| 382 | fp_mode); |
| 383 | CallStub(&stub); |
| 384 | if (lr_status == kLRHasNotBeenSaved) { |
| 385 | pop(r0); |
| 386 | mtlr(r0); |
| 387 | } |
| 388 | |
| 389 | bind(&done); |
| 390 | |
| 391 | // Count number of write barriers in generated code. |
| 392 | isolate()->counters()->write_barriers_static()->Increment(); |
| 393 | IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, ip, dst); |
| 394 | |
| 395 | // Clobber clobbered registers when running with the debug-code flag |
| 396 | // turned on to provoke errors. |
| 397 | if (emit_debug_code()) { |
| 398 | mov(dst, Operand(bit_cast<intptr_t>(kZapValue + 12))); |
| 399 | mov(map, Operand(bit_cast<intptr_t>(kZapValue + 16))); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | |
| 404 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 405 | // register 'object' contains a heap object pointer. The heap object |
| 406 | // tag is shifted away. |
| 407 | void MacroAssembler::RecordWrite( |
| 408 | Register object, Register address, Register value, |
| 409 | LinkRegisterStatus lr_status, SaveFPRegsMode fp_mode, |
| 410 | RememberedSetAction remembered_set_action, SmiCheck smi_check, |
| 411 | PointersToHereCheck pointers_to_here_check_for_value) { |
| 412 | DCHECK(!object.is(value)); |
| 413 | if (emit_debug_code()) { |
| 414 | LoadP(r0, MemOperand(address)); |
| 415 | cmp(r0, value); |
| 416 | Check(eq, kWrongAddressOrValuePassedToRecordWrite); |
| 417 | } |
| 418 | |
| 419 | if (remembered_set_action == OMIT_REMEMBERED_SET && |
| 420 | !FLAG_incremental_marking) { |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | // First, check if a write barrier is even needed. The tests below |
| 425 | // catch stores of smis and stores into the young generation. |
| 426 | Label done; |
| 427 | |
| 428 | if (smi_check == INLINE_SMI_CHECK) { |
| 429 | JumpIfSmi(value, &done); |
| 430 | } |
| 431 | |
| 432 | if (pointers_to_here_check_for_value != kPointersToHereAreAlwaysInteresting) { |
| 433 | CheckPageFlag(value, |
| 434 | value, // Used as scratch. |
| 435 | MemoryChunk::kPointersToHereAreInterestingMask, eq, &done); |
| 436 | } |
| 437 | CheckPageFlag(object, |
| 438 | value, // Used as scratch. |
| 439 | MemoryChunk::kPointersFromHereAreInterestingMask, eq, &done); |
| 440 | |
| 441 | // Record the actual write. |
| 442 | if (lr_status == kLRHasNotBeenSaved) { |
| 443 | mflr(r0); |
| 444 | push(r0); |
| 445 | } |
| 446 | RecordWriteStub stub(isolate(), object, value, address, remembered_set_action, |
| 447 | fp_mode); |
| 448 | CallStub(&stub); |
| 449 | if (lr_status == kLRHasNotBeenSaved) { |
| 450 | pop(r0); |
| 451 | mtlr(r0); |
| 452 | } |
| 453 | |
| 454 | bind(&done); |
| 455 | |
| 456 | // Count number of write barriers in generated code. |
| 457 | isolate()->counters()->write_barriers_static()->Increment(); |
| 458 | IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, ip, |
| 459 | value); |
| 460 | |
| 461 | // Clobber clobbered registers when running with the debug-code flag |
| 462 | // turned on to provoke errors. |
| 463 | if (emit_debug_code()) { |
| 464 | mov(address, Operand(bit_cast<intptr_t>(kZapValue + 12))); |
| 465 | mov(value, Operand(bit_cast<intptr_t>(kZapValue + 16))); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | |
| 470 | void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. |
| 471 | Register address, Register scratch, |
| 472 | SaveFPRegsMode fp_mode, |
| 473 | RememberedSetFinalAction and_then) { |
| 474 | Label done; |
| 475 | if (emit_debug_code()) { |
| 476 | Label ok; |
| 477 | JumpIfNotInNewSpace(object, scratch, &ok); |
| 478 | stop("Remembered set pointer is in new space"); |
| 479 | bind(&ok); |
| 480 | } |
| 481 | // Load store buffer top. |
| 482 | ExternalReference store_buffer = |
| 483 | ExternalReference::store_buffer_top(isolate()); |
| 484 | mov(ip, Operand(store_buffer)); |
| 485 | LoadP(scratch, MemOperand(ip)); |
| 486 | // Store pointer to buffer and increment buffer top. |
| 487 | StoreP(address, MemOperand(scratch)); |
| 488 | addi(scratch, scratch, Operand(kPointerSize)); |
| 489 | // Write back new top of buffer. |
| 490 | StoreP(scratch, MemOperand(ip)); |
| 491 | // Call stub on end of buffer. |
| 492 | // Check for end of buffer. |
| 493 | mov(r0, Operand(StoreBuffer::kStoreBufferOverflowBit)); |
| 494 | and_(r0, scratch, r0, SetRC); |
| 495 | |
| 496 | if (and_then == kFallThroughAtEnd) { |
| 497 | beq(&done, cr0); |
| 498 | } else { |
| 499 | DCHECK(and_then == kReturnAtEnd); |
| 500 | beq(&done, cr0); |
| 501 | } |
| 502 | mflr(r0); |
| 503 | push(r0); |
| 504 | StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode); |
| 505 | CallStub(&store_buffer_overflow); |
| 506 | pop(r0); |
| 507 | mtlr(r0); |
| 508 | bind(&done); |
| 509 | if (and_then == kReturnAtEnd) { |
| 510 | Ret(); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | |
| 515 | void MacroAssembler::PushFixedFrame(Register marker_reg) { |
| 516 | mflr(r0); |
| 517 | #if V8_OOL_CONSTANT_POOL |
| 518 | if (marker_reg.is_valid()) { |
| 519 | Push(r0, fp, kConstantPoolRegister, cp, marker_reg); |
| 520 | } else { |
| 521 | Push(r0, fp, kConstantPoolRegister, cp); |
| 522 | } |
| 523 | #else |
| 524 | if (marker_reg.is_valid()) { |
| 525 | Push(r0, fp, cp, marker_reg); |
| 526 | } else { |
| 527 | Push(r0, fp, cp); |
| 528 | } |
| 529 | #endif |
| 530 | } |
| 531 | |
| 532 | |
| 533 | void MacroAssembler::PopFixedFrame(Register marker_reg) { |
| 534 | #if V8_OOL_CONSTANT_POOL |
| 535 | if (marker_reg.is_valid()) { |
| 536 | Pop(r0, fp, kConstantPoolRegister, cp, marker_reg); |
| 537 | } else { |
| 538 | Pop(r0, fp, kConstantPoolRegister, cp); |
| 539 | } |
| 540 | #else |
| 541 | if (marker_reg.is_valid()) { |
| 542 | Pop(r0, fp, cp, marker_reg); |
| 543 | } else { |
| 544 | Pop(r0, fp, cp); |
| 545 | } |
| 546 | #endif |
| 547 | mtlr(r0); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | // Push and pop all registers that can hold pointers. |
| 552 | void MacroAssembler::PushSafepointRegisters() { |
| 553 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 554 | // stack, so adjust the stack for unsaved registers. |
| 555 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 556 | DCHECK(num_unsaved >= 0); |
| 557 | if (num_unsaved > 0) { |
| 558 | subi(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 559 | } |
| 560 | MultiPush(kSafepointSavedRegisters); |
| 561 | } |
| 562 | |
| 563 | |
| 564 | void MacroAssembler::PopSafepointRegisters() { |
| 565 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 566 | MultiPop(kSafepointSavedRegisters); |
| 567 | if (num_unsaved > 0) { |
| 568 | addi(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | |
| 573 | void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) { |
| 574 | StoreP(src, SafepointRegisterSlot(dst)); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 579 | LoadP(dst, SafepointRegisterSlot(src)); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 584 | // The registers are pushed starting with the highest encoding, |
| 585 | // which means that lowest encodings are closest to the stack pointer. |
| 586 | RegList regs = kSafepointSavedRegisters; |
| 587 | int index = 0; |
| 588 | |
| 589 | DCHECK(reg_code >= 0 && reg_code < kNumRegisters); |
| 590 | |
| 591 | for (int16_t i = 0; i < reg_code; i++) { |
| 592 | if ((regs & (1 << i)) != 0) { |
| 593 | index++; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | return index; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 602 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 603 | } |
| 604 | |
| 605 | |
| 606 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
| 607 | // General purpose registers are pushed last on the stack. |
| 608 | int doubles_size = DoubleRegister::NumAllocatableRegisters() * kDoubleSize; |
| 609 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 610 | return MemOperand(sp, doubles_size + register_offset); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | void MacroAssembler::CanonicalizeNaN(const DoubleRegister dst, |
| 615 | const DoubleRegister src) { |
| 616 | Label done; |
| 617 | |
| 618 | // Test for NaN |
| 619 | fcmpu(src, src); |
| 620 | |
| 621 | if (dst.is(src)) { |
| 622 | bordered(&done); |
| 623 | } else { |
| 624 | Label is_nan; |
| 625 | bunordered(&is_nan); |
| 626 | fmr(dst, src); |
| 627 | b(&done); |
| 628 | bind(&is_nan); |
| 629 | } |
| 630 | |
| 631 | // Replace with canonical NaN. |
| 632 | double nan_value = FixedDoubleArray::canonical_not_the_hole_nan_as_double(); |
| 633 | LoadDoubleLiteral(dst, nan_value, r0); |
| 634 | |
| 635 | bind(&done); |
| 636 | } |
| 637 | |
| 638 | |
| 639 | void MacroAssembler::ConvertIntToDouble(Register src, |
| 640 | DoubleRegister double_dst) { |
| 641 | MovIntToDouble(double_dst, src, r0); |
| 642 | fcfid(double_dst, double_dst); |
| 643 | } |
| 644 | |
| 645 | |
| 646 | void MacroAssembler::ConvertUnsignedIntToDouble(Register src, |
| 647 | DoubleRegister double_dst) { |
| 648 | MovUnsignedIntToDouble(double_dst, src, r0); |
| 649 | fcfid(double_dst, double_dst); |
| 650 | } |
| 651 | |
| 652 | |
| 653 | void MacroAssembler::ConvertIntToFloat(const DoubleRegister dst, |
| 654 | const Register src, |
| 655 | const Register int_scratch) { |
| 656 | MovIntToDouble(dst, src, int_scratch); |
| 657 | fcfid(dst, dst); |
| 658 | frsp(dst, dst); |
| 659 | } |
| 660 | |
| 661 | |
| 662 | void MacroAssembler::ConvertDoubleToInt64(const DoubleRegister double_input, |
| 663 | #if !V8_TARGET_ARCH_PPC64 |
| 664 | const Register dst_hi, |
| 665 | #endif |
| 666 | const Register dst, |
| 667 | const DoubleRegister double_dst, |
| 668 | FPRoundingMode rounding_mode) { |
| 669 | if (rounding_mode == kRoundToZero) { |
| 670 | fctidz(double_dst, double_input); |
| 671 | } else { |
| 672 | SetRoundingMode(rounding_mode); |
| 673 | fctid(double_dst, double_input); |
| 674 | ResetRoundingMode(); |
| 675 | } |
| 676 | |
| 677 | MovDoubleToInt64( |
| 678 | #if !V8_TARGET_ARCH_PPC64 |
| 679 | dst_hi, |
| 680 | #endif |
| 681 | dst, double_dst); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | #if V8_OOL_CONSTANT_POOL |
| 686 | void MacroAssembler::LoadConstantPoolPointerRegister( |
| 687 | CodeObjectAccessMethod access_method, int ip_code_entry_delta) { |
| 688 | Register base; |
| 689 | int constant_pool_offset = Code::kConstantPoolOffset - Code::kHeaderSize; |
| 690 | if (access_method == CAN_USE_IP) { |
| 691 | base = ip; |
| 692 | constant_pool_offset += ip_code_entry_delta; |
| 693 | } else { |
| 694 | DCHECK(access_method == CONSTRUCT_INTERNAL_REFERENCE); |
| 695 | base = kConstantPoolRegister; |
| 696 | ConstantPoolUnavailableScope constant_pool_unavailable(this); |
| 697 | |
| 698 | // CheckBuffer() is called too frequently. This will pre-grow |
| 699 | // the buffer if needed to avoid spliting the relocation and instructions |
| 700 | EnsureSpaceFor(kMovInstructionsNoConstantPool * kInstrSize); |
| 701 | |
| 702 | uintptr_t code_start = reinterpret_cast<uintptr_t>(pc_) - pc_offset(); |
| 703 | mov(base, Operand(code_start, RelocInfo::INTERNAL_REFERENCE)); |
| 704 | } |
| 705 | LoadP(kConstantPoolRegister, MemOperand(base, constant_pool_offset)); |
| 706 | } |
| 707 | #endif |
| 708 | |
| 709 | |
| 710 | void MacroAssembler::StubPrologue(int prologue_offset) { |
| 711 | LoadSmiLiteral(r11, Smi::FromInt(StackFrame::STUB)); |
| 712 | PushFixedFrame(r11); |
| 713 | // Adjust FP to point to saved FP. |
| 714 | addi(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 715 | #if V8_OOL_CONSTANT_POOL |
| 716 | // ip contains prologue address |
| 717 | LoadConstantPoolPointerRegister(CAN_USE_IP, -prologue_offset); |
| 718 | set_ool_constant_pool_available(true); |
| 719 | #endif |
| 720 | } |
| 721 | |
| 722 | |
| 723 | void MacroAssembler::Prologue(bool code_pre_aging, int prologue_offset) { |
| 724 | { |
| 725 | PredictableCodeSizeScope predictible_code_size_scope( |
| 726 | this, kNoCodeAgeSequenceLength); |
| 727 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(this); |
| 728 | // The following instructions must remain together and unmodified |
| 729 | // for code aging to work properly. |
| 730 | if (code_pre_aging) { |
| 731 | // Pre-age the code. |
| 732 | // This matches the code found in PatchPlatformCodeAge() |
| 733 | Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); |
| 734 | intptr_t target = reinterpret_cast<intptr_t>(stub->instruction_start()); |
| 735 | // Don't use Call -- we need to preserve ip and lr |
| 736 | nop(); // marker to detect sequence (see IsOld) |
| 737 | mov(r3, Operand(target)); |
| 738 | Jump(r3); |
| 739 | for (int i = 0; i < kCodeAgingSequenceNops; i++) { |
| 740 | nop(); |
| 741 | } |
| 742 | } else { |
| 743 | // This matches the code found in GetNoCodeAgeSequence() |
| 744 | PushFixedFrame(r4); |
| 745 | // Adjust fp to point to saved fp. |
| 746 | addi(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 747 | for (int i = 0; i < kNoCodeAgeSequenceNops; i++) { |
| 748 | nop(); |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | #if V8_OOL_CONSTANT_POOL |
| 753 | // ip contains prologue address |
| 754 | LoadConstantPoolPointerRegister(CAN_USE_IP, -prologue_offset); |
| 755 | set_ool_constant_pool_available(true); |
| 756 | #endif |
| 757 | } |
| 758 | |
| 759 | |
| 760 | void MacroAssembler::EnterFrame(StackFrame::Type type, |
| 761 | bool load_constant_pool_pointer_reg) { |
| 762 | if (FLAG_enable_ool_constant_pool && load_constant_pool_pointer_reg) { |
| 763 | PushFixedFrame(); |
| 764 | #if V8_OOL_CONSTANT_POOL |
| 765 | // This path should not rely on ip containing code entry. |
| 766 | LoadConstantPoolPointerRegister(CONSTRUCT_INTERNAL_REFERENCE); |
| 767 | #endif |
| 768 | LoadSmiLiteral(ip, Smi::FromInt(type)); |
| 769 | push(ip); |
| 770 | } else { |
| 771 | LoadSmiLiteral(ip, Smi::FromInt(type)); |
| 772 | PushFixedFrame(ip); |
| 773 | } |
| 774 | // Adjust FP to point to saved FP. |
| 775 | addi(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 776 | |
| 777 | mov(r0, Operand(CodeObject())); |
| 778 | push(r0); |
| 779 | } |
| 780 | |
| 781 | |
| 782 | int MacroAssembler::LeaveFrame(StackFrame::Type type, int stack_adjustment) { |
| 783 | #if V8_OOL_CONSTANT_POOL |
| 784 | ConstantPoolUnavailableScope constant_pool_unavailable(this); |
| 785 | #endif |
| 786 | // r3: preserved |
| 787 | // r4: preserved |
| 788 | // r5: preserved |
| 789 | |
| 790 | // Drop the execution stack down to the frame pointer and restore |
| 791 | // the caller frame pointer, return address and constant pool pointer. |
| 792 | int frame_ends; |
| 793 | LoadP(r0, MemOperand(fp, StandardFrameConstants::kCallerPCOffset)); |
| 794 | LoadP(ip, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 795 | #if V8_OOL_CONSTANT_POOL |
| 796 | const int exitOffset = ExitFrameConstants::kConstantPoolOffset; |
| 797 | const int standardOffset = StandardFrameConstants::kConstantPoolOffset; |
| 798 | const int offset = ((type == StackFrame::EXIT) ? exitOffset : standardOffset); |
| 799 | LoadP(kConstantPoolRegister, MemOperand(fp, offset)); |
| 800 | #endif |
| 801 | mtlr(r0); |
| 802 | frame_ends = pc_offset(); |
| 803 | Add(sp, fp, StandardFrameConstants::kCallerSPOffset + stack_adjustment, r0); |
| 804 | mr(fp, ip); |
| 805 | return frame_ends; |
| 806 | } |
| 807 | |
| 808 | |
| 809 | // ExitFrame layout (probably wrongish.. needs updating) |
| 810 | // |
| 811 | // SP -> previousSP |
| 812 | // LK reserved |
| 813 | // code |
| 814 | // sp_on_exit (for debug?) |
| 815 | // oldSP->prev SP |
| 816 | // LK |
| 817 | // <parameters on stack> |
| 818 | |
| 819 | // Prior to calling EnterExitFrame, we've got a bunch of parameters |
| 820 | // on the stack that we need to wrap a real frame around.. so first |
| 821 | // we reserve a slot for LK and push the previous SP which is captured |
| 822 | // in the fp register (r31) |
| 823 | // Then - we buy a new frame |
| 824 | |
| 825 | void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
| 826 | // Set up the frame structure on the stack. |
| 827 | DCHECK_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
| 828 | DCHECK_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
| 829 | DCHECK_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
| 830 | DCHECK(stack_space > 0); |
| 831 | |
| 832 | // This is an opportunity to build a frame to wrap |
| 833 | // all of the pushes that have happened inside of V8 |
| 834 | // since we were called from C code |
| 835 | |
| 836 | // replicate ARM frame - TODO make this more closely follow PPC ABI |
| 837 | mflr(r0); |
| 838 | Push(r0, fp); |
| 839 | mr(fp, sp); |
| 840 | // Reserve room for saved entry sp and code object. |
| 841 | subi(sp, sp, Operand(ExitFrameConstants::kFrameSize)); |
| 842 | |
| 843 | if (emit_debug_code()) { |
| 844 | li(r8, Operand::Zero()); |
| 845 | StoreP(r8, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 846 | } |
| 847 | #if V8_OOL_CONSTANT_POOL |
| 848 | StoreP(kConstantPoolRegister, |
| 849 | MemOperand(fp, ExitFrameConstants::kConstantPoolOffset)); |
| 850 | #endif |
| 851 | mov(r8, Operand(CodeObject())); |
| 852 | StoreP(r8, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
| 853 | |
| 854 | // Save the frame pointer and the context in top. |
| 855 | mov(r8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate()))); |
| 856 | StoreP(fp, MemOperand(r8)); |
| 857 | mov(r8, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
| 858 | StoreP(cp, MemOperand(r8)); |
| 859 | |
| 860 | // Optionally save all volatile double registers. |
| 861 | if (save_doubles) { |
| 862 | SaveFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters); |
| 863 | // Note that d0 will be accessible at |
| 864 | // fp - ExitFrameConstants::kFrameSize - |
| 865 | // kNumVolatileRegisters * kDoubleSize, |
| 866 | // since the sp slot and code slot were pushed after the fp. |
| 867 | } |
| 868 | |
| 869 | addi(sp, sp, Operand(-stack_space * kPointerSize)); |
| 870 | |
| 871 | // Allocate and align the frame preparing for calling the runtime |
| 872 | // function. |
| 873 | const int frame_alignment = ActivationFrameAlignment(); |
| 874 | if (frame_alignment > kPointerSize) { |
| 875 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
| 876 | ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment))); |
| 877 | } |
| 878 | li(r0, Operand::Zero()); |
| 879 | StorePU(r0, MemOperand(sp, -kNumRequiredStackFrameSlots * kPointerSize)); |
| 880 | |
| 881 | // Set the exit frame sp value to point just before the return address |
| 882 | // location. |
| 883 | addi(r8, sp, Operand((kStackFrameExtraParamSlot + 1) * kPointerSize)); |
| 884 | StoreP(r8, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | void MacroAssembler::InitializeNewString(Register string, Register length, |
| 889 | Heap::RootListIndex map_index, |
| 890 | Register scratch1, Register scratch2) { |
| 891 | SmiTag(scratch1, length); |
| 892 | LoadRoot(scratch2, map_index); |
| 893 | StoreP(scratch1, FieldMemOperand(string, String::kLengthOffset), r0); |
| 894 | li(scratch1, Operand(String::kEmptyHashField)); |
| 895 | StoreP(scratch2, FieldMemOperand(string, HeapObject::kMapOffset), r0); |
| 896 | StoreP(scratch1, FieldMemOperand(string, String::kHashFieldSlot), r0); |
| 897 | } |
| 898 | |
| 899 | |
| 900 | int MacroAssembler::ActivationFrameAlignment() { |
| 901 | #if !defined(USE_SIMULATOR) |
| 902 | // Running on the real platform. Use the alignment as mandated by the local |
| 903 | // environment. |
| 904 | // Note: This will break if we ever start generating snapshots on one PPC |
| 905 | // platform for another PPC platform with a different alignment. |
| 906 | return base::OS::ActivationFrameAlignment(); |
| 907 | #else // Simulated |
| 908 | // If we are using the simulator then we should always align to the expected |
| 909 | // alignment. As the simulator is used to generate snapshots we do not know |
| 910 | // if the target platform will need alignment, so this is controlled from a |
| 911 | // flag. |
| 912 | return FLAG_sim_stack_alignment; |
| 913 | #endif |
| 914 | } |
| 915 | |
| 916 | |
| 917 | void MacroAssembler::LeaveExitFrame(bool save_doubles, Register argument_count, |
| 918 | bool restore_context) { |
| 919 | #if V8_OOL_CONSTANT_POOL |
| 920 | ConstantPoolUnavailableScope constant_pool_unavailable(this); |
| 921 | #endif |
| 922 | // Optionally restore all double registers. |
| 923 | if (save_doubles) { |
| 924 | // Calculate the stack location of the saved doubles and restore them. |
| 925 | const int kNumRegs = DoubleRegister::kNumVolatileRegisters; |
| 926 | const int offset = |
| 927 | (ExitFrameConstants::kFrameSize + kNumRegs * kDoubleSize); |
| 928 | addi(r6, fp, Operand(-offset)); |
| 929 | RestoreFPRegs(r6, 0, kNumRegs); |
| 930 | } |
| 931 | |
| 932 | // Clear top frame. |
| 933 | li(r6, Operand::Zero()); |
| 934 | mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate()))); |
| 935 | StoreP(r6, MemOperand(ip)); |
| 936 | |
| 937 | // Restore current context from top and clear it in debug mode. |
| 938 | if (restore_context) { |
| 939 | mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
| 940 | LoadP(cp, MemOperand(ip)); |
| 941 | } |
| 942 | #ifdef DEBUG |
| 943 | mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
| 944 | StoreP(r6, MemOperand(ip)); |
| 945 | #endif |
| 946 | |
| 947 | // Tear down the exit frame, pop the arguments, and return. |
| 948 | LeaveFrame(StackFrame::EXIT); |
| 949 | |
| 950 | if (argument_count.is_valid()) { |
| 951 | ShiftLeftImm(argument_count, argument_count, Operand(kPointerSizeLog2)); |
| 952 | add(sp, sp, argument_count); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | |
| 957 | void MacroAssembler::MovFromFloatResult(const DoubleRegister dst) { |
| 958 | Move(dst, d1); |
| 959 | } |
| 960 | |
| 961 | |
| 962 | void MacroAssembler::MovFromFloatParameter(const DoubleRegister dst) { |
| 963 | Move(dst, d1); |
| 964 | } |
| 965 | |
| 966 | |
| 967 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 968 | const ParameterCount& actual, |
| 969 | Handle<Code> code_constant, |
| 970 | Register code_reg, Label* done, |
| 971 | bool* definitely_mismatches, |
| 972 | InvokeFlag flag, |
| 973 | const CallWrapper& call_wrapper) { |
| 974 | bool definitely_matches = false; |
| 975 | *definitely_mismatches = false; |
| 976 | Label regular_invoke; |
| 977 | |
| 978 | // Check whether the expected and actual arguments count match. If not, |
| 979 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 980 | // r3: actual arguments count |
| 981 | // r4: function (passed through to callee) |
| 982 | // r5: expected arguments count |
| 983 | |
| 984 | // The code below is made a lot easier because the calling code already sets |
| 985 | // up actual and expected registers according to the contract if values are |
| 986 | // passed in registers. |
| 987 | |
| 988 | // ARM has some sanity checks as per below, considering add them for PPC |
| 989 | // DCHECK(actual.is_immediate() || actual.reg().is(r3)); |
| 990 | // DCHECK(expected.is_immediate() || expected.reg().is(r5)); |
| 991 | // DCHECK((!code_constant.is_null() && code_reg.is(no_reg)) |
| 992 | // || code_reg.is(r6)); |
| 993 | |
| 994 | if (expected.is_immediate()) { |
| 995 | DCHECK(actual.is_immediate()); |
| 996 | if (expected.immediate() == actual.immediate()) { |
| 997 | definitely_matches = true; |
| 998 | } else { |
| 999 | mov(r3, Operand(actual.immediate())); |
| 1000 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 1001 | if (expected.immediate() == sentinel) { |
| 1002 | // Don't worry about adapting arguments for builtins that |
| 1003 | // don't want that done. Skip adaption code by making it look |
| 1004 | // like we have a match between expected and actual number of |
| 1005 | // arguments. |
| 1006 | definitely_matches = true; |
| 1007 | } else { |
| 1008 | *definitely_mismatches = true; |
| 1009 | mov(r5, Operand(expected.immediate())); |
| 1010 | } |
| 1011 | } |
| 1012 | } else { |
| 1013 | if (actual.is_immediate()) { |
| 1014 | cmpi(expected.reg(), Operand(actual.immediate())); |
| 1015 | beq(®ular_invoke); |
| 1016 | mov(r3, Operand(actual.immediate())); |
| 1017 | } else { |
| 1018 | cmp(expected.reg(), actual.reg()); |
| 1019 | beq(®ular_invoke); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | if (!definitely_matches) { |
| 1024 | if (!code_constant.is_null()) { |
| 1025 | mov(r6, Operand(code_constant)); |
| 1026 | addi(r6, r6, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1027 | } |
| 1028 | |
| 1029 | Handle<Code> adaptor = isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 1030 | if (flag == CALL_FUNCTION) { |
| 1031 | call_wrapper.BeforeCall(CallSize(adaptor)); |
| 1032 | Call(adaptor); |
| 1033 | call_wrapper.AfterCall(); |
| 1034 | if (!*definitely_mismatches) { |
| 1035 | b(done); |
| 1036 | } |
| 1037 | } else { |
| 1038 | Jump(adaptor, RelocInfo::CODE_TARGET); |
| 1039 | } |
| 1040 | bind(®ular_invoke); |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | void MacroAssembler::InvokeCode(Register code, const ParameterCount& expected, |
| 1046 | const ParameterCount& actual, InvokeFlag flag, |
| 1047 | const CallWrapper& call_wrapper) { |
| 1048 | // You can't call a function without a valid frame. |
| 1049 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
| 1050 | |
| 1051 | Label done; |
| 1052 | bool definitely_mismatches = false; |
| 1053 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, |
| 1054 | &definitely_mismatches, flag, call_wrapper); |
| 1055 | if (!definitely_mismatches) { |
| 1056 | if (flag == CALL_FUNCTION) { |
| 1057 | call_wrapper.BeforeCall(CallSize(code)); |
| 1058 | CallJSEntry(code); |
| 1059 | call_wrapper.AfterCall(); |
| 1060 | } else { |
| 1061 | DCHECK(flag == JUMP_FUNCTION); |
| 1062 | JumpToJSEntry(code); |
| 1063 | } |
| 1064 | |
| 1065 | // Continue here if InvokePrologue does handle the invocation due to |
| 1066 | // mismatched parameter counts. |
| 1067 | bind(&done); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | void MacroAssembler::InvokeFunction(Register fun, const ParameterCount& actual, |
| 1073 | InvokeFlag flag, |
| 1074 | const CallWrapper& call_wrapper) { |
| 1075 | // You can't call a function without a valid frame. |
| 1076 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
| 1077 | |
| 1078 | // Contract with called JS functions requires that function is passed in r4. |
| 1079 | DCHECK(fun.is(r4)); |
| 1080 | |
| 1081 | Register expected_reg = r5; |
| 1082 | Register code_reg = ip; |
| 1083 | |
| 1084 | LoadP(code_reg, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset)); |
| 1085 | LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset)); |
| 1086 | LoadWordArith(expected_reg, |
| 1087 | FieldMemOperand( |
| 1088 | code_reg, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 1089 | #if !defined(V8_TARGET_ARCH_PPC64) |
| 1090 | SmiUntag(expected_reg); |
| 1091 | #endif |
| 1092 | LoadP(code_reg, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
| 1093 | |
| 1094 | ParameterCount expected(expected_reg); |
| 1095 | InvokeCode(code_reg, expected, actual, flag, call_wrapper); |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | void MacroAssembler::InvokeFunction(Register function, |
| 1100 | const ParameterCount& expected, |
| 1101 | const ParameterCount& actual, |
| 1102 | InvokeFlag flag, |
| 1103 | const CallWrapper& call_wrapper) { |
| 1104 | // You can't call a function without a valid frame. |
| 1105 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
| 1106 | |
| 1107 | // Contract with called JS functions requires that function is passed in r4. |
| 1108 | DCHECK(function.is(r4)); |
| 1109 | |
| 1110 | // Get the function and setup the context. |
| 1111 | LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset)); |
| 1112 | |
| 1113 | // We call indirectly through the code field in the function to |
| 1114 | // allow recompilation to take effect without changing any of the |
| 1115 | // call sites. |
| 1116 | LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
| 1117 | InvokeCode(ip, expected, actual, flag, call_wrapper); |
| 1118 | } |
| 1119 | |
| 1120 | |
| 1121 | void MacroAssembler::InvokeFunction(Handle<JSFunction> function, |
| 1122 | const ParameterCount& expected, |
| 1123 | const ParameterCount& actual, |
| 1124 | InvokeFlag flag, |
| 1125 | const CallWrapper& call_wrapper) { |
| 1126 | Move(r4, function); |
| 1127 | InvokeFunction(r4, expected, actual, flag, call_wrapper); |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, Register map, |
| 1132 | Register scratch, Label* fail) { |
| 1133 | LoadP(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 1134 | IsInstanceJSObjectType(map, scratch, fail); |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | void MacroAssembler::IsInstanceJSObjectType(Register map, Register scratch, |
| 1139 | Label* fail) { |
| 1140 | lbz(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1141 | cmpi(scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 1142 | blt(fail); |
| 1143 | cmpi(scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 1144 | bgt(fail); |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | void MacroAssembler::IsObjectJSStringType(Register object, Register scratch, |
| 1149 | Label* fail) { |
| 1150 | DCHECK(kNotStringTag != 0); |
| 1151 | |
| 1152 | LoadP(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1153 | lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1154 | andi(r0, scratch, Operand(kIsNotStringMask)); |
| 1155 | bne(fail, cr0); |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | void MacroAssembler::IsObjectNameType(Register object, Register scratch, |
| 1160 | Label* fail) { |
| 1161 | LoadP(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1162 | lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1163 | cmpi(scratch, Operand(LAST_NAME_TYPE)); |
| 1164 | bgt(fail); |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | void MacroAssembler::DebugBreak() { |
| 1169 | li(r3, Operand::Zero()); |
| 1170 | mov(r4, Operand(ExternalReference(Runtime::kDebugBreak, isolate()))); |
| 1171 | CEntryStub ces(isolate(), 1); |
| 1172 | DCHECK(AllowThisStubCall(&ces)); |
| 1173 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | void MacroAssembler::PushTryHandler(StackHandler::Kind kind, |
| 1178 | int handler_index) { |
| 1179 | // Adjust this code if not the case. |
| 1180 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1181 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
| 1182 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1183 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1184 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1185 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 1186 | |
| 1187 | // For the JSEntry handler, we must preserve r1-r7, r0,r8-r15 are available. |
| 1188 | // We want the stack to look like |
| 1189 | // sp -> NextOffset |
| 1190 | // CodeObject |
| 1191 | // state |
| 1192 | // context |
| 1193 | // frame pointer |
| 1194 | |
| 1195 | // Link the current handler as the next handler. |
| 1196 | mov(r8, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 1197 | LoadP(r0, MemOperand(r8)); |
| 1198 | StorePU(r0, MemOperand(sp, -StackHandlerConstants::kSize)); |
| 1199 | // Set this new handler as the current one. |
| 1200 | StoreP(sp, MemOperand(r8)); |
| 1201 | |
| 1202 | if (kind == StackHandler::JS_ENTRY) { |
| 1203 | li(r8, Operand::Zero()); // NULL frame pointer. |
| 1204 | StoreP(r8, MemOperand(sp, StackHandlerConstants::kFPOffset)); |
| 1205 | LoadSmiLiteral(r8, Smi::FromInt(0)); // Indicates no context. |
| 1206 | StoreP(r8, MemOperand(sp, StackHandlerConstants::kContextOffset)); |
| 1207 | } else { |
| 1208 | // still not sure if fp is right |
| 1209 | StoreP(fp, MemOperand(sp, StackHandlerConstants::kFPOffset)); |
| 1210 | StoreP(cp, MemOperand(sp, StackHandlerConstants::kContextOffset)); |
| 1211 | } |
| 1212 | unsigned state = StackHandler::IndexField::encode(handler_index) | |
| 1213 | StackHandler::KindField::encode(kind); |
| 1214 | LoadIntLiteral(r8, state); |
| 1215 | StoreP(r8, MemOperand(sp, StackHandlerConstants::kStateOffset)); |
| 1216 | mov(r8, Operand(CodeObject())); |
| 1217 | StoreP(r8, MemOperand(sp, StackHandlerConstants::kCodeOffset)); |
| 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | void MacroAssembler::PopTryHandler() { |
| 1222 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1223 | pop(r4); |
| 1224 | mov(ip, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 1225 | addi(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 1226 | StoreP(r4, MemOperand(ip)); |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | // PPC - make use of ip as a temporary register |
| 1231 | void MacroAssembler::JumpToHandlerEntry() { |
| 1232 | // Compute the handler entry address and jump to it. The handler table is |
| 1233 | // a fixed array of (smi-tagged) code offsets. |
| 1234 | // r3 = exception, r4 = code object, r5 = state. |
| 1235 | #if V8_OOL_CONSTANT_POOL |
| 1236 | ConstantPoolUnavailableScope constant_pool_unavailable(this); |
| 1237 | LoadP(kConstantPoolRegister, FieldMemOperand(r4, Code::kConstantPoolOffset)); |
| 1238 | #endif |
| 1239 | LoadP(r6, FieldMemOperand(r4, Code::kHandlerTableOffset)); // Handler table. |
| 1240 | addi(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 1241 | srwi(r5, r5, Operand(StackHandler::kKindWidth)); // Handler index. |
| 1242 | slwi(ip, r5, Operand(kPointerSizeLog2)); |
| 1243 | add(ip, r6, ip); |
| 1244 | LoadP(r5, MemOperand(ip)); // Smi-tagged offset. |
| 1245 | addi(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start. |
| 1246 | SmiUntag(ip, r5); |
| 1247 | add(r0, r4, ip); |
| 1248 | mtctr(r0); |
| 1249 | bctr(); |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | void MacroAssembler::Throw(Register value) { |
| 1254 | // Adjust this code if not the case. |
| 1255 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1256 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1257 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1258 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1259 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1260 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 1261 | Label skip; |
| 1262 | |
| 1263 | // The exception is expected in r3. |
| 1264 | if (!value.is(r3)) { |
| 1265 | mr(r3, value); |
| 1266 | } |
| 1267 | // Drop the stack pointer to the top of the top handler. |
| 1268 | mov(r6, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 1269 | LoadP(sp, MemOperand(r6)); |
| 1270 | // Restore the next handler. |
| 1271 | pop(r5); |
| 1272 | StoreP(r5, MemOperand(r6)); |
| 1273 | |
| 1274 | // Get the code object (r4) and state (r5). Restore the context and frame |
| 1275 | // pointer. |
| 1276 | pop(r4); |
| 1277 | pop(r5); |
| 1278 | pop(cp); |
| 1279 | pop(fp); |
| 1280 | |
| 1281 | // If the handler is a JS frame, restore the context to the frame. |
| 1282 | // (kind == ENTRY) == (fp == 0) == (cp == 0), so we could test either fp |
| 1283 | // or cp. |
| 1284 | cmpi(cp, Operand::Zero()); |
| 1285 | beq(&skip); |
| 1286 | StoreP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1287 | bind(&skip); |
| 1288 | |
| 1289 | JumpToHandlerEntry(); |
| 1290 | } |
| 1291 | |
| 1292 | |
| 1293 | void MacroAssembler::ThrowUncatchable(Register value) { |
| 1294 | // Adjust this code if not the case. |
| 1295 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1296 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
| 1297 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1298 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1299 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1300 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 1301 | |
| 1302 | // The exception is expected in r3. |
| 1303 | if (!value.is(r3)) { |
| 1304 | mr(r3, value); |
| 1305 | } |
| 1306 | // Drop the stack pointer to the top of the top stack handler. |
| 1307 | mov(r6, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 1308 | LoadP(sp, MemOperand(r6)); |
| 1309 | |
| 1310 | // Unwind the handlers until the ENTRY handler is found. |
| 1311 | Label fetch_next, check_kind; |
| 1312 | b(&check_kind); |
| 1313 | bind(&fetch_next); |
| 1314 | LoadP(sp, MemOperand(sp, StackHandlerConstants::kNextOffset)); |
| 1315 | |
| 1316 | bind(&check_kind); |
| 1317 | STATIC_ASSERT(StackHandler::JS_ENTRY == 0); |
| 1318 | LoadP(r5, MemOperand(sp, StackHandlerConstants::kStateOffset)); |
| 1319 | andi(r0, r5, Operand(StackHandler::KindField::kMask)); |
| 1320 | bne(&fetch_next, cr0); |
| 1321 | |
| 1322 | // Set the top handler address to next handler past the top ENTRY handler. |
| 1323 | pop(r5); |
| 1324 | StoreP(r5, MemOperand(r6)); |
| 1325 | // Get the code object (r4) and state (r5). Clear the context and frame |
| 1326 | // pointer (0 was saved in the handler). |
| 1327 | pop(r4); |
| 1328 | pop(r5); |
| 1329 | pop(cp); |
| 1330 | pop(fp); |
| 1331 | |
| 1332 | JumpToHandlerEntry(); |
| 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 1337 | Register scratch, Label* miss) { |
| 1338 | Label same_contexts; |
| 1339 | |
| 1340 | DCHECK(!holder_reg.is(scratch)); |
| 1341 | DCHECK(!holder_reg.is(ip)); |
| 1342 | DCHECK(!scratch.is(ip)); |
| 1343 | |
| 1344 | // Load current lexical context from the stack frame. |
| 1345 | LoadP(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1346 | // In debug mode, make sure the lexical context is set. |
| 1347 | #ifdef DEBUG |
| 1348 | cmpi(scratch, Operand::Zero()); |
| 1349 | Check(ne, kWeShouldNotHaveAnEmptyLexicalContext); |
| 1350 | #endif |
| 1351 | |
| 1352 | // Load the native context of the current context. |
| 1353 | int offset = |
| 1354 | Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; |
| 1355 | LoadP(scratch, FieldMemOperand(scratch, offset)); |
| 1356 | LoadP(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset)); |
| 1357 | |
| 1358 | // Check the context is a native context. |
| 1359 | if (emit_debug_code()) { |
| 1360 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1361 | // that ip is clobbered as part of cmp with an object Operand. |
| 1362 | push(holder_reg); // Temporarily save holder on the stack. |
| 1363 | // Read the first word and compare to the native_context_map. |
| 1364 | LoadP(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 1365 | LoadRoot(ip, Heap::kNativeContextMapRootIndex); |
| 1366 | cmp(holder_reg, ip); |
| 1367 | Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext); |
| 1368 | pop(holder_reg); // Restore holder. |
| 1369 | } |
| 1370 | |
| 1371 | // Check if both contexts are the same. |
| 1372 | LoadP(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
| 1373 | cmp(scratch, ip); |
| 1374 | beq(&same_contexts); |
| 1375 | |
| 1376 | // Check the context is a native context. |
| 1377 | if (emit_debug_code()) { |
| 1378 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1379 | // that ip is clobbered as part of cmp with an object Operand. |
| 1380 | push(holder_reg); // Temporarily save holder on the stack. |
| 1381 | mr(holder_reg, ip); // Move ip to its holding place. |
| 1382 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1383 | cmp(holder_reg, ip); |
| 1384 | Check(ne, kJSGlobalProxyContextShouldNotBeNull); |
| 1385 | |
| 1386 | LoadP(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
| 1387 | LoadRoot(ip, Heap::kNativeContextMapRootIndex); |
| 1388 | cmp(holder_reg, ip); |
| 1389 | Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext); |
| 1390 | // Restore ip is not needed. ip is reloaded below. |
| 1391 | pop(holder_reg); // Restore holder. |
| 1392 | // Restore ip to holder's context. |
| 1393 | LoadP(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
| 1394 | } |
| 1395 | |
| 1396 | // Check that the security token in the calling global object is |
| 1397 | // compatible with the security token in the receiving global |
| 1398 | // object. |
| 1399 | int token_offset = |
| 1400 | Context::kHeaderSize + Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 1401 | |
| 1402 | LoadP(scratch, FieldMemOperand(scratch, token_offset)); |
| 1403 | LoadP(ip, FieldMemOperand(ip, token_offset)); |
| 1404 | cmp(scratch, ip); |
| 1405 | bne(miss); |
| 1406 | |
| 1407 | bind(&same_contexts); |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | // Compute the hash code from the untagged key. This must be kept in sync with |
| 1412 | // ComputeIntegerHash in utils.h and KeyedLoadGenericStub in |
| 1413 | // code-stub-hydrogen.cc |
| 1414 | void MacroAssembler::GetNumberHash(Register t0, Register scratch) { |
| 1415 | // First of all we assign the hash seed to scratch. |
| 1416 | LoadRoot(scratch, Heap::kHashSeedRootIndex); |
| 1417 | SmiUntag(scratch); |
| 1418 | |
| 1419 | // Xor original key with a seed. |
| 1420 | xor_(t0, t0, scratch); |
| 1421 | |
| 1422 | // Compute the hash code from the untagged key. This must be kept in sync |
| 1423 | // with ComputeIntegerHash in utils.h. |
| 1424 | // |
| 1425 | // hash = ~hash + (hash << 15); |
| 1426 | notx(scratch, t0); |
| 1427 | slwi(t0, t0, Operand(15)); |
| 1428 | add(t0, scratch, t0); |
| 1429 | // hash = hash ^ (hash >> 12); |
| 1430 | srwi(scratch, t0, Operand(12)); |
| 1431 | xor_(t0, t0, scratch); |
| 1432 | // hash = hash + (hash << 2); |
| 1433 | slwi(scratch, t0, Operand(2)); |
| 1434 | add(t0, t0, scratch); |
| 1435 | // hash = hash ^ (hash >> 4); |
| 1436 | srwi(scratch, t0, Operand(4)); |
| 1437 | xor_(t0, t0, scratch); |
| 1438 | // hash = hash * 2057; |
| 1439 | mr(r0, t0); |
| 1440 | slwi(scratch, t0, Operand(3)); |
| 1441 | add(t0, t0, scratch); |
| 1442 | slwi(scratch, r0, Operand(11)); |
| 1443 | add(t0, t0, scratch); |
| 1444 | // hash = hash ^ (hash >> 16); |
| 1445 | srwi(scratch, t0, Operand(16)); |
| 1446 | xor_(t0, t0, scratch); |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, Register elements, |
| 1451 | Register key, Register result, |
| 1452 | Register t0, Register t1, |
| 1453 | Register t2) { |
| 1454 | // Register use: |
| 1455 | // |
| 1456 | // elements - holds the slow-case elements of the receiver on entry. |
| 1457 | // Unchanged unless 'result' is the same register. |
| 1458 | // |
| 1459 | // key - holds the smi key on entry. |
| 1460 | // Unchanged unless 'result' is the same register. |
| 1461 | // |
| 1462 | // result - holds the result on exit if the load succeeded. |
| 1463 | // Allowed to be the same as 'key' or 'result'. |
| 1464 | // Unchanged on bailout so 'key' or 'result' can be used |
| 1465 | // in further computation. |
| 1466 | // |
| 1467 | // Scratch registers: |
| 1468 | // |
| 1469 | // t0 - holds the untagged key on entry and holds the hash once computed. |
| 1470 | // |
| 1471 | // t1 - used to hold the capacity mask of the dictionary |
| 1472 | // |
| 1473 | // t2 - used for the index into the dictionary. |
| 1474 | Label done; |
| 1475 | |
| 1476 | GetNumberHash(t0, t1); |
| 1477 | |
| 1478 | // Compute the capacity mask. |
| 1479 | LoadP(t1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset)); |
| 1480 | SmiUntag(t1); |
| 1481 | subi(t1, t1, Operand(1)); |
| 1482 | |
| 1483 | // Generate an unrolled loop that performs a few probes before giving up. |
| 1484 | for (int i = 0; i < kNumberDictionaryProbes; i++) { |
| 1485 | // Use t2 for index calculations and keep the hash intact in t0. |
| 1486 | mr(t2, t0); |
| 1487 | // Compute the masked index: (hash + i + i * i) & mask. |
| 1488 | if (i > 0) { |
| 1489 | addi(t2, t2, Operand(SeededNumberDictionary::GetProbeOffset(i))); |
| 1490 | } |
| 1491 | and_(t2, t2, t1); |
| 1492 | |
| 1493 | // Scale the index by multiplying by the element size. |
| 1494 | DCHECK(SeededNumberDictionary::kEntrySize == 3); |
| 1495 | slwi(ip, t2, Operand(1)); |
| 1496 | add(t2, t2, ip); // t2 = t2 * 3 |
| 1497 | |
| 1498 | // Check if the key is identical to the name. |
| 1499 | slwi(t2, t2, Operand(kPointerSizeLog2)); |
| 1500 | add(t2, elements, t2); |
| 1501 | LoadP(ip, |
| 1502 | FieldMemOperand(t2, SeededNumberDictionary::kElementsStartOffset)); |
| 1503 | cmp(key, ip); |
| 1504 | if (i != kNumberDictionaryProbes - 1) { |
| 1505 | beq(&done); |
| 1506 | } else { |
| 1507 | bne(miss); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | bind(&done); |
| 1512 | // Check that the value is a field property. |
| 1513 | // t2: elements + (index * kPointerSize) |
| 1514 | const int kDetailsOffset = |
| 1515 | SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
| 1516 | LoadP(t1, FieldMemOperand(t2, kDetailsOffset)); |
| 1517 | LoadSmiLiteral(ip, Smi::FromInt(PropertyDetails::TypeField::kMask)); |
| 1518 | DCHECK_EQ(FIELD, 0); |
| 1519 | and_(r0, t1, ip, SetRC); |
| 1520 | bne(miss, cr0); |
| 1521 | |
| 1522 | // Get the value at the masked, scaled index and return. |
| 1523 | const int kValueOffset = |
| 1524 | SeededNumberDictionary::kElementsStartOffset + kPointerSize; |
| 1525 | LoadP(result, FieldMemOperand(t2, kValueOffset)); |
| 1526 | } |
| 1527 | |
| 1528 | |
| 1529 | void MacroAssembler::Allocate(int object_size, Register result, |
| 1530 | Register scratch1, Register scratch2, |
| 1531 | Label* gc_required, AllocationFlags flags) { |
| 1532 | DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); |
| 1533 | if (!FLAG_inline_new) { |
| 1534 | if (emit_debug_code()) { |
| 1535 | // Trash the registers to simulate an allocation failure. |
| 1536 | li(result, Operand(0x7091)); |
| 1537 | li(scratch1, Operand(0x7191)); |
| 1538 | li(scratch2, Operand(0x7291)); |
| 1539 | } |
| 1540 | b(gc_required); |
| 1541 | return; |
| 1542 | } |
| 1543 | |
| 1544 | DCHECK(!result.is(scratch1)); |
| 1545 | DCHECK(!result.is(scratch2)); |
| 1546 | DCHECK(!scratch1.is(scratch2)); |
| 1547 | DCHECK(!scratch1.is(ip)); |
| 1548 | DCHECK(!scratch2.is(ip)); |
| 1549 | |
| 1550 | // Make object size into bytes. |
| 1551 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1552 | object_size *= kPointerSize; |
| 1553 | } |
| 1554 | DCHECK_EQ(0, static_cast<int>(object_size & kObjectAlignmentMask)); |
| 1555 | |
| 1556 | // Check relative positions of allocation top and limit addresses. |
| 1557 | ExternalReference allocation_top = |
| 1558 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
| 1559 | ExternalReference allocation_limit = |
| 1560 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
| 1561 | |
| 1562 | intptr_t top = reinterpret_cast<intptr_t>(allocation_top.address()); |
| 1563 | intptr_t limit = reinterpret_cast<intptr_t>(allocation_limit.address()); |
| 1564 | DCHECK((limit - top) == kPointerSize); |
| 1565 | |
| 1566 | // Set up allocation top address register. |
| 1567 | Register topaddr = scratch1; |
| 1568 | mov(topaddr, Operand(allocation_top)); |
| 1569 | |
| 1570 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1571 | // does not need ip for implicit literal generation. |
| 1572 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 1573 | // Load allocation top into result and allocation limit into ip. |
| 1574 | LoadP(result, MemOperand(topaddr)); |
| 1575 | LoadP(ip, MemOperand(topaddr, kPointerSize)); |
| 1576 | } else { |
| 1577 | if (emit_debug_code()) { |
| 1578 | // Assert that result actually contains top on entry. ip is used |
| 1579 | // immediately below so this use of ip does not cause difference with |
| 1580 | // respect to register content between debug and release mode. |
| 1581 | LoadP(ip, MemOperand(topaddr)); |
| 1582 | cmp(result, ip); |
| 1583 | Check(eq, kUnexpectedAllocationTop); |
| 1584 | } |
| 1585 | // Load allocation limit into ip. Result already contains allocation top. |
| 1586 | LoadP(ip, MemOperand(topaddr, limit - top), r0); |
| 1587 | } |
| 1588 | |
| 1589 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1590 | // Align the next allocation. Storing the filler map without checking top is |
| 1591 | // safe in new-space because the limit of the heap is aligned there. |
| 1592 | DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
| 1593 | #if V8_TARGET_ARCH_PPC64 |
| 1594 | STATIC_ASSERT(kPointerAlignment == kDoubleAlignment); |
| 1595 | #else |
| 1596 | STATIC_ASSERT(kPointerAlignment * 2 == kDoubleAlignment); |
| 1597 | andi(scratch2, result, Operand(kDoubleAlignmentMask)); |
| 1598 | Label aligned; |
| 1599 | beq(&aligned, cr0); |
| 1600 | if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) { |
| 1601 | cmpl(result, ip); |
| 1602 | bge(gc_required); |
| 1603 | } |
| 1604 | mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 1605 | stw(scratch2, MemOperand(result)); |
| 1606 | addi(result, result, Operand(kDoubleSize / 2)); |
| 1607 | bind(&aligned); |
| 1608 | #endif |
| 1609 | } |
| 1610 | |
| 1611 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1612 | // to calculate the new top. |
| 1613 | sub(r0, ip, result); |
| 1614 | if (is_int16(object_size)) { |
| 1615 | cmpi(r0, Operand(object_size)); |
| 1616 | blt(gc_required); |
| 1617 | addi(scratch2, result, Operand(object_size)); |
| 1618 | } else { |
| 1619 | Cmpi(r0, Operand(object_size), scratch2); |
| 1620 | blt(gc_required); |
| 1621 | add(scratch2, result, scratch2); |
| 1622 | } |
| 1623 | StoreP(scratch2, MemOperand(topaddr)); |
| 1624 | |
| 1625 | // Tag object if requested. |
| 1626 | if ((flags & TAG_OBJECT) != 0) { |
| 1627 | addi(result, result, Operand(kHeapObjectTag)); |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | |
| 1632 | void MacroAssembler::Allocate(Register object_size, Register result, |
| 1633 | Register scratch1, Register scratch2, |
| 1634 | Label* gc_required, AllocationFlags flags) { |
| 1635 | if (!FLAG_inline_new) { |
| 1636 | if (emit_debug_code()) { |
| 1637 | // Trash the registers to simulate an allocation failure. |
| 1638 | li(result, Operand(0x7091)); |
| 1639 | li(scratch1, Operand(0x7191)); |
| 1640 | li(scratch2, Operand(0x7291)); |
| 1641 | } |
| 1642 | b(gc_required); |
| 1643 | return; |
| 1644 | } |
| 1645 | |
| 1646 | // Assert that the register arguments are different and that none of |
| 1647 | // them are ip. ip is used explicitly in the code generated below. |
| 1648 | DCHECK(!result.is(scratch1)); |
| 1649 | DCHECK(!result.is(scratch2)); |
| 1650 | DCHECK(!scratch1.is(scratch2)); |
| 1651 | DCHECK(!object_size.is(ip)); |
| 1652 | DCHECK(!result.is(ip)); |
| 1653 | DCHECK(!scratch1.is(ip)); |
| 1654 | DCHECK(!scratch2.is(ip)); |
| 1655 | |
| 1656 | // Check relative positions of allocation top and limit addresses. |
| 1657 | ExternalReference allocation_top = |
| 1658 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
| 1659 | ExternalReference allocation_limit = |
| 1660 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
| 1661 | intptr_t top = reinterpret_cast<intptr_t>(allocation_top.address()); |
| 1662 | intptr_t limit = reinterpret_cast<intptr_t>(allocation_limit.address()); |
| 1663 | DCHECK((limit - top) == kPointerSize); |
| 1664 | |
| 1665 | // Set up allocation top address. |
| 1666 | Register topaddr = scratch1; |
| 1667 | mov(topaddr, Operand(allocation_top)); |
| 1668 | |
| 1669 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1670 | // does not need ip for implicit literal generation. |
| 1671 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 1672 | // Load allocation top into result and allocation limit into ip. |
| 1673 | LoadP(result, MemOperand(topaddr)); |
| 1674 | LoadP(ip, MemOperand(topaddr, kPointerSize)); |
| 1675 | } else { |
| 1676 | if (emit_debug_code()) { |
| 1677 | // Assert that result actually contains top on entry. ip is used |
| 1678 | // immediately below so this use of ip does not cause difference with |
| 1679 | // respect to register content between debug and release mode. |
| 1680 | LoadP(ip, MemOperand(topaddr)); |
| 1681 | cmp(result, ip); |
| 1682 | Check(eq, kUnexpectedAllocationTop); |
| 1683 | } |
| 1684 | // Load allocation limit into ip. Result already contains allocation top. |
| 1685 | LoadP(ip, MemOperand(topaddr, limit - top)); |
| 1686 | } |
| 1687 | |
| 1688 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1689 | // Align the next allocation. Storing the filler map without checking top is |
| 1690 | // safe in new-space because the limit of the heap is aligned there. |
| 1691 | DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
| 1692 | #if V8_TARGET_ARCH_PPC64 |
| 1693 | STATIC_ASSERT(kPointerAlignment == kDoubleAlignment); |
| 1694 | #else |
| 1695 | STATIC_ASSERT(kPointerAlignment * 2 == kDoubleAlignment); |
| 1696 | andi(scratch2, result, Operand(kDoubleAlignmentMask)); |
| 1697 | Label aligned; |
| 1698 | beq(&aligned, cr0); |
| 1699 | if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) { |
| 1700 | cmpl(result, ip); |
| 1701 | bge(gc_required); |
| 1702 | } |
| 1703 | mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 1704 | stw(scratch2, MemOperand(result)); |
| 1705 | addi(result, result, Operand(kDoubleSize / 2)); |
| 1706 | bind(&aligned); |
| 1707 | #endif |
| 1708 | } |
| 1709 | |
| 1710 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1711 | // to calculate the new top. Object size may be in words so a shift is |
| 1712 | // required to get the number of bytes. |
| 1713 | sub(r0, ip, result); |
| 1714 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1715 | ShiftLeftImm(scratch2, object_size, Operand(kPointerSizeLog2)); |
| 1716 | cmp(r0, scratch2); |
| 1717 | blt(gc_required); |
| 1718 | add(scratch2, result, scratch2); |
| 1719 | } else { |
| 1720 | cmp(r0, object_size); |
| 1721 | blt(gc_required); |
| 1722 | add(scratch2, result, object_size); |
| 1723 | } |
| 1724 | |
| 1725 | // Update allocation top. result temporarily holds the new top. |
| 1726 | if (emit_debug_code()) { |
| 1727 | andi(r0, scratch2, Operand(kObjectAlignmentMask)); |
| 1728 | Check(eq, kUnalignedAllocationInNewSpace, cr0); |
| 1729 | } |
| 1730 | StoreP(scratch2, MemOperand(topaddr)); |
| 1731 | |
| 1732 | // Tag object if requested. |
| 1733 | if ((flags & TAG_OBJECT) != 0) { |
| 1734 | addi(result, result, Operand(kHeapObjectTag)); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | |
| 1739 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1740 | Register scratch) { |
| 1741 | ExternalReference new_space_allocation_top = |
| 1742 | ExternalReference::new_space_allocation_top_address(isolate()); |
| 1743 | |
| 1744 | // Make sure the object has no tag before resetting top. |
| 1745 | mov(r0, Operand(~kHeapObjectTagMask)); |
| 1746 | and_(object, object, r0); |
| 1747 | // was.. and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1748 | #ifdef DEBUG |
| 1749 | // Check that the object un-allocated is below the current top. |
| 1750 | mov(scratch, Operand(new_space_allocation_top)); |
| 1751 | LoadP(scratch, MemOperand(scratch)); |
| 1752 | cmp(object, scratch); |
| 1753 | Check(lt, kUndoAllocationOfNonAllocatedMemory); |
| 1754 | #endif |
| 1755 | // Write the address of the object to un-allocate as the current top. |
| 1756 | mov(scratch, Operand(new_space_allocation_top)); |
| 1757 | StoreP(object, MemOperand(scratch)); |
| 1758 | } |
| 1759 | |
| 1760 | |
| 1761 | void MacroAssembler::AllocateTwoByteString(Register result, Register length, |
| 1762 | Register scratch1, Register scratch2, |
| 1763 | Register scratch3, |
| 1764 | Label* gc_required) { |
| 1765 | // Calculate the number of bytes needed for the characters in the string while |
| 1766 | // observing object alignment. |
| 1767 | DCHECK((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1768 | slwi(scratch1, length, Operand(1)); // Length in bytes, not chars. |
| 1769 | addi(scratch1, scratch1, |
| 1770 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
| 1771 | mov(r0, Operand(~kObjectAlignmentMask)); |
| 1772 | and_(scratch1, scratch1, r0); |
| 1773 | |
| 1774 | // Allocate two-byte string in new space. |
| 1775 | Allocate(scratch1, result, scratch2, scratch3, gc_required, TAG_OBJECT); |
| 1776 | |
| 1777 | // Set the map, length and hash field. |
| 1778 | InitializeNewString(result, length, Heap::kStringMapRootIndex, scratch1, |
| 1779 | scratch2); |
| 1780 | } |
| 1781 | |
| 1782 | |
| 1783 | void MacroAssembler::AllocateOneByteString(Register result, Register length, |
| 1784 | Register scratch1, Register scratch2, |
| 1785 | Register scratch3, |
| 1786 | Label* gc_required) { |
| 1787 | // Calculate the number of bytes needed for the characters in the string while |
| 1788 | // observing object alignment. |
| 1789 | DCHECK((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1790 | DCHECK(kCharSize == 1); |
| 1791 | addi(scratch1, length, |
| 1792 | Operand(kObjectAlignmentMask + SeqOneByteString::kHeaderSize)); |
| 1793 | li(r0, Operand(~kObjectAlignmentMask)); |
| 1794 | and_(scratch1, scratch1, r0); |
| 1795 | |
| 1796 | // Allocate one-byte string in new space. |
| 1797 | Allocate(scratch1, result, scratch2, scratch3, gc_required, TAG_OBJECT); |
| 1798 | |
| 1799 | // Set the map, length and hash field. |
| 1800 | InitializeNewString(result, length, Heap::kOneByteStringMapRootIndex, |
| 1801 | scratch1, scratch2); |
| 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | void MacroAssembler::AllocateTwoByteConsString(Register result, Register length, |
| 1806 | Register scratch1, |
| 1807 | Register scratch2, |
| 1808 | Label* gc_required) { |
| 1809 | Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| 1810 | TAG_OBJECT); |
| 1811 | |
| 1812 | InitializeNewString(result, length, Heap::kConsStringMapRootIndex, scratch1, |
| 1813 | scratch2); |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | void MacroAssembler::AllocateOneByteConsString(Register result, Register length, |
| 1818 | Register scratch1, |
| 1819 | Register scratch2, |
| 1820 | Label* gc_required) { |
| 1821 | Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| 1822 | TAG_OBJECT); |
| 1823 | |
| 1824 | InitializeNewString(result, length, Heap::kConsOneByteStringMapRootIndex, |
| 1825 | scratch1, scratch2); |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
| 1830 | Register length, |
| 1831 | Register scratch1, |
| 1832 | Register scratch2, |
| 1833 | Label* gc_required) { |
| 1834 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 1835 | TAG_OBJECT); |
| 1836 | |
| 1837 | InitializeNewString(result, length, Heap::kSlicedStringMapRootIndex, scratch1, |
| 1838 | scratch2); |
| 1839 | } |
| 1840 | |
| 1841 | |
| 1842 | void MacroAssembler::AllocateOneByteSlicedString(Register result, |
| 1843 | Register length, |
| 1844 | Register scratch1, |
| 1845 | Register scratch2, |
| 1846 | Label* gc_required) { |
| 1847 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 1848 | TAG_OBJECT); |
| 1849 | |
| 1850 | InitializeNewString(result, length, Heap::kSlicedOneByteStringMapRootIndex, |
| 1851 | scratch1, scratch2); |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | void MacroAssembler::CompareObjectType(Register object, Register map, |
| 1856 | Register type_reg, InstanceType type) { |
| 1857 | const Register temp = type_reg.is(no_reg) ? r0 : type_reg; |
| 1858 | |
| 1859 | LoadP(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1860 | CompareInstanceType(map, temp, type); |
| 1861 | } |
| 1862 | |
| 1863 | |
| 1864 | void MacroAssembler::CheckObjectTypeRange(Register object, Register map, |
| 1865 | InstanceType min_type, |
| 1866 | InstanceType max_type, |
| 1867 | Label* false_label) { |
| 1868 | STATIC_ASSERT(Map::kInstanceTypeOffset < 4096); |
| 1869 | STATIC_ASSERT(LAST_TYPE < 256); |
| 1870 | LoadP(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1871 | lbz(ip, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1872 | subi(ip, ip, Operand(min_type)); |
| 1873 | cmpli(ip, Operand(max_type - min_type)); |
| 1874 | bgt(false_label); |
| 1875 | } |
| 1876 | |
| 1877 | |
| 1878 | void MacroAssembler::CompareInstanceType(Register map, Register type_reg, |
| 1879 | InstanceType type) { |
| 1880 | STATIC_ASSERT(Map::kInstanceTypeOffset < 4096); |
| 1881 | STATIC_ASSERT(LAST_TYPE < 256); |
| 1882 | lbz(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1883 | cmpi(type_reg, Operand(type)); |
| 1884 | } |
| 1885 | |
| 1886 | |
| 1887 | void MacroAssembler::CompareRoot(Register obj, Heap::RootListIndex index) { |
| 1888 | DCHECK(!obj.is(r0)); |
| 1889 | LoadRoot(r0, index); |
| 1890 | cmp(obj, r0); |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | void MacroAssembler::CheckFastElements(Register map, Register scratch, |
| 1895 | Label* fail) { |
| 1896 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 1897 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 1898 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 1899 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 1900 | lbz(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
| 1901 | STATIC_ASSERT(Map::kMaximumBitField2FastHoleyElementValue < 0x8000); |
| 1902 | cmpli(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue)); |
| 1903 | bgt(fail); |
| 1904 | } |
| 1905 | |
| 1906 | |
| 1907 | void MacroAssembler::CheckFastObjectElements(Register map, Register scratch, |
| 1908 | Label* fail) { |
| 1909 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 1910 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 1911 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 1912 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 1913 | lbz(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
| 1914 | cmpli(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue)); |
| 1915 | ble(fail); |
| 1916 | cmpli(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue)); |
| 1917 | bgt(fail); |
| 1918 | } |
| 1919 | |
| 1920 | |
| 1921 | void MacroAssembler::CheckFastSmiElements(Register map, Register scratch, |
| 1922 | Label* fail) { |
| 1923 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 1924 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 1925 | lbz(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
| 1926 | cmpli(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue)); |
| 1927 | bgt(fail); |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | void MacroAssembler::StoreNumberToDoubleElements( |
| 1932 | Register value_reg, Register key_reg, Register elements_reg, |
| 1933 | Register scratch1, DoubleRegister double_scratch, Label* fail, |
| 1934 | int elements_offset) { |
| 1935 | Label smi_value, store; |
| 1936 | |
| 1937 | // Handle smi values specially. |
| 1938 | JumpIfSmi(value_reg, &smi_value); |
| 1939 | |
| 1940 | // Ensure that the object is a heap number |
| 1941 | CheckMap(value_reg, scratch1, isolate()->factory()->heap_number_map(), fail, |
| 1942 | DONT_DO_SMI_CHECK); |
| 1943 | |
| 1944 | lfd(double_scratch, FieldMemOperand(value_reg, HeapNumber::kValueOffset)); |
| 1945 | // Force a canonical NaN. |
| 1946 | CanonicalizeNaN(double_scratch); |
| 1947 | b(&store); |
| 1948 | |
| 1949 | bind(&smi_value); |
| 1950 | SmiToDouble(double_scratch, value_reg); |
| 1951 | |
| 1952 | bind(&store); |
| 1953 | SmiToDoubleArrayOffset(scratch1, key_reg); |
| 1954 | add(scratch1, elements_reg, scratch1); |
| 1955 | stfd(double_scratch, FieldMemOperand(scratch1, FixedDoubleArray::kHeaderSize - |
| 1956 | elements_offset)); |
| 1957 | } |
| 1958 | |
| 1959 | |
| 1960 | void MacroAssembler::AddAndCheckForOverflow(Register dst, Register left, |
| 1961 | Register right, |
| 1962 | Register overflow_dst, |
| 1963 | Register scratch) { |
| 1964 | DCHECK(!dst.is(overflow_dst)); |
| 1965 | DCHECK(!dst.is(scratch)); |
| 1966 | DCHECK(!overflow_dst.is(scratch)); |
| 1967 | DCHECK(!overflow_dst.is(left)); |
| 1968 | DCHECK(!overflow_dst.is(right)); |
| 1969 | |
| 1970 | // C = A+B; C overflows if A/B have same sign and C has diff sign than A |
| 1971 | if (dst.is(left)) { |
| 1972 | mr(scratch, left); // Preserve left. |
| 1973 | add(dst, left, right); // Left is overwritten. |
| 1974 | xor_(scratch, dst, scratch); // Original left. |
| 1975 | xor_(overflow_dst, dst, right); |
| 1976 | } else if (dst.is(right)) { |
| 1977 | mr(scratch, right); // Preserve right. |
| 1978 | add(dst, left, right); // Right is overwritten. |
| 1979 | xor_(scratch, dst, scratch); // Original right. |
| 1980 | xor_(overflow_dst, dst, left); |
| 1981 | } else { |
| 1982 | add(dst, left, right); |
| 1983 | xor_(overflow_dst, dst, left); |
| 1984 | xor_(scratch, dst, right); |
| 1985 | } |
| 1986 | and_(overflow_dst, scratch, overflow_dst, SetRC); |
| 1987 | } |
| 1988 | |
| 1989 | |
| 1990 | void MacroAssembler::AddAndCheckForOverflow(Register dst, Register left, |
| 1991 | intptr_t right, |
| 1992 | Register overflow_dst, |
| 1993 | Register scratch) { |
| 1994 | Register original_left = left; |
| 1995 | DCHECK(!dst.is(overflow_dst)); |
| 1996 | DCHECK(!dst.is(scratch)); |
| 1997 | DCHECK(!overflow_dst.is(scratch)); |
| 1998 | DCHECK(!overflow_dst.is(left)); |
| 1999 | |
| 2000 | // C = A+B; C overflows if A/B have same sign and C has diff sign than A |
| 2001 | if (dst.is(left)) { |
| 2002 | // Preserve left. |
| 2003 | original_left = overflow_dst; |
| 2004 | mr(original_left, left); |
| 2005 | } |
| 2006 | Add(dst, left, right, scratch); |
| 2007 | xor_(overflow_dst, dst, original_left); |
| 2008 | if (right >= 0) { |
| 2009 | and_(overflow_dst, overflow_dst, dst, SetRC); |
| 2010 | } else { |
| 2011 | andc(overflow_dst, overflow_dst, dst, SetRC); |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | |
| 2016 | void MacroAssembler::SubAndCheckForOverflow(Register dst, Register left, |
| 2017 | Register right, |
| 2018 | Register overflow_dst, |
| 2019 | Register scratch) { |
| 2020 | DCHECK(!dst.is(overflow_dst)); |
| 2021 | DCHECK(!dst.is(scratch)); |
| 2022 | DCHECK(!overflow_dst.is(scratch)); |
| 2023 | DCHECK(!overflow_dst.is(left)); |
| 2024 | DCHECK(!overflow_dst.is(right)); |
| 2025 | |
| 2026 | // C = A-B; C overflows if A/B have diff signs and C has diff sign than A |
| 2027 | if (dst.is(left)) { |
| 2028 | mr(scratch, left); // Preserve left. |
| 2029 | sub(dst, left, right); // Left is overwritten. |
| 2030 | xor_(overflow_dst, dst, scratch); |
| 2031 | xor_(scratch, scratch, right); |
| 2032 | and_(overflow_dst, overflow_dst, scratch, SetRC); |
| 2033 | } else if (dst.is(right)) { |
| 2034 | mr(scratch, right); // Preserve right. |
| 2035 | sub(dst, left, right); // Right is overwritten. |
| 2036 | xor_(overflow_dst, dst, left); |
| 2037 | xor_(scratch, left, scratch); |
| 2038 | and_(overflow_dst, overflow_dst, scratch, SetRC); |
| 2039 | } else { |
| 2040 | sub(dst, left, right); |
| 2041 | xor_(overflow_dst, dst, left); |
| 2042 | xor_(scratch, left, right); |
| 2043 | and_(overflow_dst, scratch, overflow_dst, SetRC); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | |
| 2048 | void MacroAssembler::CompareMap(Register obj, Register scratch, Handle<Map> map, |
| 2049 | Label* early_success) { |
| 2050 | LoadP(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 2051 | CompareMap(scratch, map, early_success); |
| 2052 | } |
| 2053 | |
| 2054 | |
| 2055 | void MacroAssembler::CompareMap(Register obj_map, Handle<Map> map, |
| 2056 | Label* early_success) { |
| 2057 | mov(r0, Operand(map)); |
| 2058 | cmp(obj_map, r0); |
| 2059 | } |
| 2060 | |
| 2061 | |
| 2062 | void MacroAssembler::CheckMap(Register obj, Register scratch, Handle<Map> map, |
| 2063 | Label* fail, SmiCheckType smi_check_type) { |
| 2064 | if (smi_check_type == DO_SMI_CHECK) { |
| 2065 | JumpIfSmi(obj, fail); |
| 2066 | } |
| 2067 | |
| 2068 | Label success; |
| 2069 | CompareMap(obj, scratch, map, &success); |
| 2070 | bne(fail); |
| 2071 | bind(&success); |
| 2072 | } |
| 2073 | |
| 2074 | |
| 2075 | void MacroAssembler::CheckMap(Register obj, Register scratch, |
| 2076 | Heap::RootListIndex index, Label* fail, |
| 2077 | SmiCheckType smi_check_type) { |
| 2078 | if (smi_check_type == DO_SMI_CHECK) { |
| 2079 | JumpIfSmi(obj, fail); |
| 2080 | } |
| 2081 | LoadP(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 2082 | LoadRoot(r0, index); |
| 2083 | cmp(scratch, r0); |
| 2084 | bne(fail); |
| 2085 | } |
| 2086 | |
| 2087 | |
| 2088 | void MacroAssembler::DispatchMap(Register obj, Register scratch, |
| 2089 | Handle<Map> map, Handle<Code> success, |
| 2090 | SmiCheckType smi_check_type) { |
| 2091 | Label fail; |
| 2092 | if (smi_check_type == DO_SMI_CHECK) { |
| 2093 | JumpIfSmi(obj, &fail); |
| 2094 | } |
| 2095 | LoadP(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 2096 | mov(r0, Operand(map)); |
| 2097 | cmp(scratch, r0); |
| 2098 | bne(&fail); |
| 2099 | Jump(success, RelocInfo::CODE_TARGET, al); |
| 2100 | bind(&fail); |
| 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | void MacroAssembler::TryGetFunctionPrototype(Register function, Register result, |
| 2105 | Register scratch, Label* miss, |
| 2106 | bool miss_on_bound_function) { |
| 2107 | Label non_instance; |
| 2108 | if (miss_on_bound_function) { |
| 2109 | // Check that the receiver isn't a smi. |
| 2110 | JumpIfSmi(function, miss); |
| 2111 | |
| 2112 | // Check that the function really is a function. Load map into result reg. |
| 2113 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 2114 | bne(miss); |
| 2115 | |
| 2116 | LoadP(scratch, |
| 2117 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 2118 | lwz(scratch, |
| 2119 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 2120 | TestBit(scratch, |
| 2121 | #if V8_TARGET_ARCH_PPC64 |
| 2122 | SharedFunctionInfo::kBoundFunction, |
| 2123 | #else |
| 2124 | SharedFunctionInfo::kBoundFunction + kSmiTagSize, |
| 2125 | #endif |
| 2126 | r0); |
| 2127 | bne(miss, cr0); |
| 2128 | |
| 2129 | // Make sure that the function has an instance prototype. |
| 2130 | lbz(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 2131 | andi(r0, scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 2132 | bne(&non_instance, cr0); |
| 2133 | } |
| 2134 | |
| 2135 | // Get the prototype or initial map from the function. |
| 2136 | LoadP(result, |
| 2137 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2138 | |
| 2139 | // If the prototype or initial map is the hole, don't return it and |
| 2140 | // simply miss the cache instead. This will allow us to allocate a |
| 2141 | // prototype object on-demand in the runtime system. |
| 2142 | LoadRoot(r0, Heap::kTheHoleValueRootIndex); |
| 2143 | cmp(result, r0); |
| 2144 | beq(miss); |
| 2145 | |
| 2146 | // If the function does not have an initial map, we're done. |
| 2147 | Label done; |
| 2148 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 2149 | bne(&done); |
| 2150 | |
| 2151 | // Get the prototype from the initial map. |
| 2152 | LoadP(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 2153 | |
| 2154 | if (miss_on_bound_function) { |
| 2155 | b(&done); |
| 2156 | |
| 2157 | // Non-instance prototype: Fetch prototype from constructor field |
| 2158 | // in initial map. |
| 2159 | bind(&non_instance); |
| 2160 | LoadP(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 2161 | } |
| 2162 | |
| 2163 | // All done. |
| 2164 | bind(&done); |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | void MacroAssembler::CallStub(CodeStub* stub, TypeFeedbackId ast_id, |
| 2169 | Condition cond) { |
| 2170 | DCHECK(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs. |
| 2171 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id, cond); |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
| 2176 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 2177 | } |
| 2178 | |
| 2179 | |
| 2180 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 2181 | return ref0.address() - ref1.address(); |
| 2182 | } |
| 2183 | |
| 2184 | |
| 2185 | void MacroAssembler::CallApiFunctionAndReturn( |
| 2186 | Register function_address, ExternalReference thunk_ref, int stack_space, |
| 2187 | MemOperand return_value_operand, MemOperand* context_restore_operand) { |
| 2188 | ExternalReference next_address = |
| 2189 | ExternalReference::handle_scope_next_address(isolate()); |
| 2190 | const int kNextOffset = 0; |
| 2191 | const int kLimitOffset = AddressOffset( |
| 2192 | ExternalReference::handle_scope_limit_address(isolate()), next_address); |
| 2193 | const int kLevelOffset = AddressOffset( |
| 2194 | ExternalReference::handle_scope_level_address(isolate()), next_address); |
| 2195 | |
| 2196 | DCHECK(function_address.is(r4) || function_address.is(r5)); |
| 2197 | Register scratch = r6; |
| 2198 | |
| 2199 | Label profiler_disabled; |
| 2200 | Label end_profiler_check; |
| 2201 | mov(scratch, Operand(ExternalReference::is_profiling_address(isolate()))); |
| 2202 | lbz(scratch, MemOperand(scratch, 0)); |
| 2203 | cmpi(scratch, Operand::Zero()); |
| 2204 | beq(&profiler_disabled); |
| 2205 | |
| 2206 | // Additional parameter is the address of the actual callback. |
| 2207 | mov(scratch, Operand(thunk_ref)); |
| 2208 | jmp(&end_profiler_check); |
| 2209 | |
| 2210 | bind(&profiler_disabled); |
| 2211 | mr(scratch, function_address); |
| 2212 | bind(&end_profiler_check); |
| 2213 | |
| 2214 | // Allocate HandleScope in callee-save registers. |
| 2215 | // r17 - next_address |
| 2216 | // r14 - next_address->kNextOffset |
| 2217 | // r15 - next_address->kLimitOffset |
| 2218 | // r16 - next_address->kLevelOffset |
| 2219 | mov(r17, Operand(next_address)); |
| 2220 | LoadP(r14, MemOperand(r17, kNextOffset)); |
| 2221 | LoadP(r15, MemOperand(r17, kLimitOffset)); |
| 2222 | lwz(r16, MemOperand(r17, kLevelOffset)); |
| 2223 | addi(r16, r16, Operand(1)); |
| 2224 | stw(r16, MemOperand(r17, kLevelOffset)); |
| 2225 | |
| 2226 | if (FLAG_log_timer_events) { |
| 2227 | FrameScope frame(this, StackFrame::MANUAL); |
| 2228 | PushSafepointRegisters(); |
| 2229 | PrepareCallCFunction(1, r3); |
| 2230 | mov(r3, Operand(ExternalReference::isolate_address(isolate()))); |
| 2231 | CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1); |
| 2232 | PopSafepointRegisters(); |
| 2233 | } |
| 2234 | |
| 2235 | // Native call returns to the DirectCEntry stub which redirects to the |
| 2236 | // return address pushed on stack (could have moved after GC). |
| 2237 | // DirectCEntry stub itself is generated early and never moves. |
| 2238 | DirectCEntryStub stub(isolate()); |
| 2239 | stub.GenerateCall(this, scratch); |
| 2240 | |
| 2241 | if (FLAG_log_timer_events) { |
| 2242 | FrameScope frame(this, StackFrame::MANUAL); |
| 2243 | PushSafepointRegisters(); |
| 2244 | PrepareCallCFunction(1, r3); |
| 2245 | mov(r3, Operand(ExternalReference::isolate_address(isolate()))); |
| 2246 | CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1); |
| 2247 | PopSafepointRegisters(); |
| 2248 | } |
| 2249 | |
| 2250 | Label promote_scheduled_exception; |
| 2251 | Label exception_handled; |
| 2252 | Label delete_allocated_handles; |
| 2253 | Label leave_exit_frame; |
| 2254 | Label return_value_loaded; |
| 2255 | |
| 2256 | // load value from ReturnValue |
| 2257 | LoadP(r3, return_value_operand); |
| 2258 | bind(&return_value_loaded); |
| 2259 | // No more valid handles (the result handle was the last one). Restore |
| 2260 | // previous handle scope. |
| 2261 | StoreP(r14, MemOperand(r17, kNextOffset)); |
| 2262 | if (emit_debug_code()) { |
| 2263 | lwz(r4, MemOperand(r17, kLevelOffset)); |
| 2264 | cmp(r4, r16); |
| 2265 | Check(eq, kUnexpectedLevelAfterReturnFromApiCall); |
| 2266 | } |
| 2267 | subi(r16, r16, Operand(1)); |
| 2268 | stw(r16, MemOperand(r17, kLevelOffset)); |
| 2269 | LoadP(r0, MemOperand(r17, kLimitOffset)); |
| 2270 | cmp(r15, r0); |
| 2271 | bne(&delete_allocated_handles); |
| 2272 | |
| 2273 | // Check if the function scheduled an exception. |
| 2274 | bind(&leave_exit_frame); |
| 2275 | LoadRoot(r14, Heap::kTheHoleValueRootIndex); |
| 2276 | mov(r15, Operand(ExternalReference::scheduled_exception_address(isolate()))); |
| 2277 | LoadP(r15, MemOperand(r15)); |
| 2278 | cmp(r14, r15); |
| 2279 | bne(&promote_scheduled_exception); |
| 2280 | bind(&exception_handled); |
| 2281 | |
| 2282 | bool restore_context = context_restore_operand != NULL; |
| 2283 | if (restore_context) { |
| 2284 | LoadP(cp, *context_restore_operand); |
| 2285 | } |
| 2286 | // LeaveExitFrame expects unwind space to be in a register. |
| 2287 | mov(r14, Operand(stack_space)); |
| 2288 | LeaveExitFrame(false, r14, !restore_context); |
| 2289 | blr(); |
| 2290 | |
| 2291 | bind(&promote_scheduled_exception); |
| 2292 | { |
| 2293 | FrameScope frame(this, StackFrame::INTERNAL); |
| 2294 | CallExternalReference( |
| 2295 | ExternalReference(Runtime::kPromoteScheduledException, isolate()), 0); |
| 2296 | } |
| 2297 | jmp(&exception_handled); |
| 2298 | |
| 2299 | // HandleScope limit has changed. Delete allocated extensions. |
| 2300 | bind(&delete_allocated_handles); |
| 2301 | StoreP(r15, MemOperand(r17, kLimitOffset)); |
| 2302 | mr(r14, r3); |
| 2303 | PrepareCallCFunction(1, r15); |
| 2304 | mov(r3, Operand(ExternalReference::isolate_address(isolate()))); |
| 2305 | CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate()), |
| 2306 | 1); |
| 2307 | mr(r3, r14); |
| 2308 | b(&leave_exit_frame); |
| 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | bool MacroAssembler::AllowThisStubCall(CodeStub* stub) { |
| 2313 | return has_frame_ || !stub->SometimesSetsUpAFrame(); |
| 2314 | } |
| 2315 | |
| 2316 | |
| 2317 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 2318 | // If the hash field contains an array index pick it out. The assert checks |
| 2319 | // that the constants for the maximum number of digits for an array index |
| 2320 | // cached in the hash field and the number of bits reserved for it does not |
| 2321 | // conflict. |
| 2322 | DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 2323 | (1 << String::kArrayIndexValueBits)); |
| 2324 | DecodeFieldToSmi<String::ArrayIndexValueBits>(index, hash); |
| 2325 | } |
| 2326 | |
| 2327 | |
| 2328 | void MacroAssembler::SmiToDouble(DoubleRegister value, Register smi) { |
| 2329 | SmiUntag(ip, smi); |
| 2330 | ConvertIntToDouble(ip, value); |
| 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | void MacroAssembler::TestDoubleIsInt32(DoubleRegister double_input, |
| 2335 | Register scratch1, Register scratch2, |
| 2336 | DoubleRegister double_scratch) { |
| 2337 | TryDoubleToInt32Exact(scratch1, double_input, scratch2, double_scratch); |
| 2338 | } |
| 2339 | |
| 2340 | |
| 2341 | void MacroAssembler::TryDoubleToInt32Exact(Register result, |
| 2342 | DoubleRegister double_input, |
| 2343 | Register scratch, |
| 2344 | DoubleRegister double_scratch) { |
| 2345 | Label done; |
| 2346 | DCHECK(!double_input.is(double_scratch)); |
| 2347 | |
| 2348 | ConvertDoubleToInt64(double_input, |
| 2349 | #if !V8_TARGET_ARCH_PPC64 |
| 2350 | scratch, |
| 2351 | #endif |
| 2352 | result, double_scratch); |
| 2353 | |
| 2354 | #if V8_TARGET_ARCH_PPC64 |
| 2355 | TestIfInt32(result, scratch, r0); |
| 2356 | #else |
| 2357 | TestIfInt32(scratch, result, r0); |
| 2358 | #endif |
| 2359 | bne(&done); |
| 2360 | |
| 2361 | // convert back and compare |
| 2362 | fcfid(double_scratch, double_scratch); |
| 2363 | fcmpu(double_scratch, double_input); |
| 2364 | bind(&done); |
| 2365 | } |
| 2366 | |
| 2367 | |
| 2368 | void MacroAssembler::TryInt32Floor(Register result, DoubleRegister double_input, |
| 2369 | Register input_high, Register scratch, |
| 2370 | DoubleRegister double_scratch, Label* done, |
| 2371 | Label* exact) { |
| 2372 | DCHECK(!result.is(input_high)); |
| 2373 | DCHECK(!double_input.is(double_scratch)); |
| 2374 | Label exception; |
| 2375 | |
| 2376 | MovDoubleHighToInt(input_high, double_input); |
| 2377 | |
| 2378 | // Test for NaN/Inf |
| 2379 | ExtractBitMask(result, input_high, HeapNumber::kExponentMask); |
| 2380 | cmpli(result, Operand(0x7ff)); |
| 2381 | beq(&exception); |
| 2382 | |
| 2383 | // Convert (rounding to -Inf) |
| 2384 | ConvertDoubleToInt64(double_input, |
| 2385 | #if !V8_TARGET_ARCH_PPC64 |
| 2386 | scratch, |
| 2387 | #endif |
| 2388 | result, double_scratch, kRoundToMinusInf); |
| 2389 | |
| 2390 | // Test for overflow |
| 2391 | #if V8_TARGET_ARCH_PPC64 |
| 2392 | TestIfInt32(result, scratch, r0); |
| 2393 | #else |
| 2394 | TestIfInt32(scratch, result, r0); |
| 2395 | #endif |
| 2396 | bne(&exception); |
| 2397 | |
| 2398 | // Test for exactness |
| 2399 | fcfid(double_scratch, double_scratch); |
| 2400 | fcmpu(double_scratch, double_input); |
| 2401 | beq(exact); |
| 2402 | b(done); |
| 2403 | |
| 2404 | bind(&exception); |
| 2405 | } |
| 2406 | |
| 2407 | |
| 2408 | void MacroAssembler::TryInlineTruncateDoubleToI(Register result, |
| 2409 | DoubleRegister double_input, |
| 2410 | Label* done) { |
| 2411 | DoubleRegister double_scratch = kScratchDoubleReg; |
| 2412 | Register scratch = ip; |
| 2413 | |
| 2414 | ConvertDoubleToInt64(double_input, |
| 2415 | #if !V8_TARGET_ARCH_PPC64 |
| 2416 | scratch, |
| 2417 | #endif |
| 2418 | result, double_scratch); |
| 2419 | |
| 2420 | // Test for overflow |
| 2421 | #if V8_TARGET_ARCH_PPC64 |
| 2422 | TestIfInt32(result, scratch, r0); |
| 2423 | #else |
| 2424 | TestIfInt32(scratch, result, r0); |
| 2425 | #endif |
| 2426 | beq(done); |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | void MacroAssembler::TruncateDoubleToI(Register result, |
| 2431 | DoubleRegister double_input) { |
| 2432 | Label done; |
| 2433 | |
| 2434 | TryInlineTruncateDoubleToI(result, double_input, &done); |
| 2435 | |
| 2436 | // If we fell through then inline version didn't succeed - call stub instead. |
| 2437 | mflr(r0); |
| 2438 | push(r0); |
| 2439 | // Put input on stack. |
| 2440 | stfdu(double_input, MemOperand(sp, -kDoubleSize)); |
| 2441 | |
| 2442 | DoubleToIStub stub(isolate(), sp, result, 0, true, true); |
| 2443 | CallStub(&stub); |
| 2444 | |
| 2445 | addi(sp, sp, Operand(kDoubleSize)); |
| 2446 | pop(r0); |
| 2447 | mtlr(r0); |
| 2448 | |
| 2449 | bind(&done); |
| 2450 | } |
| 2451 | |
| 2452 | |
| 2453 | void MacroAssembler::TruncateHeapNumberToI(Register result, Register object) { |
| 2454 | Label done; |
| 2455 | DoubleRegister double_scratch = kScratchDoubleReg; |
| 2456 | DCHECK(!result.is(object)); |
| 2457 | |
| 2458 | lfd(double_scratch, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 2459 | TryInlineTruncateDoubleToI(result, double_scratch, &done); |
| 2460 | |
| 2461 | // If we fell through then inline version didn't succeed - call stub instead. |
| 2462 | mflr(r0); |
| 2463 | push(r0); |
| 2464 | DoubleToIStub stub(isolate(), object, result, |
| 2465 | HeapNumber::kValueOffset - kHeapObjectTag, true, true); |
| 2466 | CallStub(&stub); |
| 2467 | pop(r0); |
| 2468 | mtlr(r0); |
| 2469 | |
| 2470 | bind(&done); |
| 2471 | } |
| 2472 | |
| 2473 | |
| 2474 | void MacroAssembler::TruncateNumberToI(Register object, Register result, |
| 2475 | Register heap_number_map, |
| 2476 | Register scratch1, Label* not_number) { |
| 2477 | Label done; |
| 2478 | DCHECK(!result.is(object)); |
| 2479 | |
| 2480 | UntagAndJumpIfSmi(result, object, &done); |
| 2481 | JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number); |
| 2482 | TruncateHeapNumberToI(result, object); |
| 2483 | |
| 2484 | bind(&done); |
| 2485 | } |
| 2486 | |
| 2487 | |
| 2488 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, Register src, |
| 2489 | int num_least_bits) { |
| 2490 | #if V8_TARGET_ARCH_PPC64 |
| 2491 | rldicl(dst, src, kBitsPerPointer - kSmiShift, |
| 2492 | kBitsPerPointer - num_least_bits); |
| 2493 | #else |
| 2494 | rlwinm(dst, src, kBitsPerPointer - kSmiShift, |
| 2495 | kBitsPerPointer - num_least_bits, 31); |
| 2496 | #endif |
| 2497 | } |
| 2498 | |
| 2499 | |
| 2500 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, Register src, |
| 2501 | int num_least_bits) { |
| 2502 | rlwinm(dst, src, 0, 32 - num_least_bits, 31); |
| 2503 | } |
| 2504 | |
| 2505 | |
| 2506 | void MacroAssembler::CallRuntime(const Runtime::Function* f, int num_arguments, |
| 2507 | SaveFPRegsMode save_doubles) { |
| 2508 | // All parameters are on the stack. r3 has the return value after call. |
| 2509 | |
| 2510 | // If the expected number of arguments of the runtime function is |
| 2511 | // constant, we check that the actual number of arguments match the |
| 2512 | // expectation. |
| 2513 | CHECK(f->nargs < 0 || f->nargs == num_arguments); |
| 2514 | |
| 2515 | // TODO(1236192): Most runtime routines don't need the number of |
| 2516 | // arguments passed in because it is constant. At some point we |
| 2517 | // should remove this need and make the runtime routine entry code |
| 2518 | // smarter. |
| 2519 | mov(r3, Operand(num_arguments)); |
| 2520 | mov(r4, Operand(ExternalReference(f, isolate()))); |
| 2521 | CEntryStub stub(isolate(), |
| 2522 | #if V8_TARGET_ARCH_PPC64 |
| 2523 | f->result_size, |
| 2524 | #else |
| 2525 | 1, |
| 2526 | #endif |
| 2527 | save_doubles); |
| 2528 | CallStub(&stub); |
| 2529 | } |
| 2530 | |
| 2531 | |
| 2532 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 2533 | int num_arguments) { |
| 2534 | mov(r3, Operand(num_arguments)); |
| 2535 | mov(r4, Operand(ext)); |
| 2536 | |
| 2537 | CEntryStub stub(isolate(), 1); |
| 2538 | CallStub(&stub); |
| 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 2543 | int num_arguments, |
| 2544 | int result_size) { |
| 2545 | // TODO(1236192): Most runtime routines don't need the number of |
| 2546 | // arguments passed in because it is constant. At some point we |
| 2547 | // should remove this need and make the runtime routine entry code |
| 2548 | // smarter. |
| 2549 | mov(r3, Operand(num_arguments)); |
| 2550 | JumpToExternalReference(ext); |
| 2551 | } |
| 2552 | |
| 2553 | |
| 2554 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, int num_arguments, |
| 2555 | int result_size) { |
| 2556 | TailCallExternalReference(ExternalReference(fid, isolate()), num_arguments, |
| 2557 | result_size); |
| 2558 | } |
| 2559 | |
| 2560 | |
| 2561 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
| 2562 | mov(r4, Operand(builtin)); |
| 2563 | CEntryStub stub(isolate(), 1); |
| 2564 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2565 | } |
| 2566 | |
| 2567 | |
| 2568 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag, |
| 2569 | const CallWrapper& call_wrapper) { |
| 2570 | // You can't call a builtin without a valid frame. |
| 2571 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
| 2572 | |
| 2573 | GetBuiltinEntry(ip, id); |
| 2574 | if (flag == CALL_FUNCTION) { |
| 2575 | call_wrapper.BeforeCall(CallSize(ip)); |
| 2576 | CallJSEntry(ip); |
| 2577 | call_wrapper.AfterCall(); |
| 2578 | } else { |
| 2579 | DCHECK(flag == JUMP_FUNCTION); |
| 2580 | JumpToJSEntry(ip); |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | |
| 2585 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2586 | Builtins::JavaScript id) { |
| 2587 | // Load the builtins object into target register. |
| 2588 | LoadP(target, |
| 2589 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2590 | LoadP(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
| 2591 | // Load the JavaScript builtin function from the builtins object. |
| 2592 | LoadP(target, |
| 2593 | FieldMemOperand(target, JSBuiltinsObject::OffsetOfFunctionWithId(id)), |
| 2594 | r0); |
| 2595 | } |
| 2596 | |
| 2597 | |
| 2598 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 2599 | DCHECK(!target.is(r4)); |
| 2600 | GetBuiltinFunction(r4, id); |
| 2601 | // Load the code entry point from the builtins object. |
| 2602 | LoadP(target, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
| 2603 | } |
| 2604 | |
| 2605 | |
| 2606 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 2607 | Register scratch1, Register scratch2) { |
| 2608 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2609 | mov(scratch1, Operand(value)); |
| 2610 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2611 | stw(scratch1, MemOperand(scratch2)); |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | |
| 2616 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 2617 | Register scratch1, Register scratch2) { |
| 2618 | DCHECK(value > 0); |
| 2619 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2620 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2621 | lwz(scratch1, MemOperand(scratch2)); |
| 2622 | addi(scratch1, scratch1, Operand(value)); |
| 2623 | stw(scratch1, MemOperand(scratch2)); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | |
| 2628 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 2629 | Register scratch1, Register scratch2) { |
| 2630 | DCHECK(value > 0); |
| 2631 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2632 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2633 | lwz(scratch1, MemOperand(scratch2)); |
| 2634 | subi(scratch1, scratch1, Operand(value)); |
| 2635 | stw(scratch1, MemOperand(scratch2)); |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | |
| 2640 | void MacroAssembler::Assert(Condition cond, BailoutReason reason, |
| 2641 | CRegister cr) { |
| 2642 | if (emit_debug_code()) Check(cond, reason, cr); |
| 2643 | } |
| 2644 | |
| 2645 | |
| 2646 | void MacroAssembler::AssertFastElements(Register elements) { |
| 2647 | if (emit_debug_code()) { |
| 2648 | DCHECK(!elements.is(r0)); |
| 2649 | Label ok; |
| 2650 | push(elements); |
| 2651 | LoadP(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 2652 | LoadRoot(r0, Heap::kFixedArrayMapRootIndex); |
| 2653 | cmp(elements, r0); |
| 2654 | beq(&ok); |
| 2655 | LoadRoot(r0, Heap::kFixedDoubleArrayMapRootIndex); |
| 2656 | cmp(elements, r0); |
| 2657 | beq(&ok); |
| 2658 | LoadRoot(r0, Heap::kFixedCOWArrayMapRootIndex); |
| 2659 | cmp(elements, r0); |
| 2660 | beq(&ok); |
| 2661 | Abort(kJSObjectWithFastElementsMapHasSlowElements); |
| 2662 | bind(&ok); |
| 2663 | pop(elements); |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | |
| 2668 | void MacroAssembler::Check(Condition cond, BailoutReason reason, CRegister cr) { |
| 2669 | Label L; |
| 2670 | b(cond, &L, cr); |
| 2671 | Abort(reason); |
| 2672 | // will not return here |
| 2673 | bind(&L); |
| 2674 | } |
| 2675 | |
| 2676 | |
| 2677 | void MacroAssembler::Abort(BailoutReason reason) { |
| 2678 | Label abort_start; |
| 2679 | bind(&abort_start); |
| 2680 | #ifdef DEBUG |
| 2681 | const char* msg = GetBailoutReason(reason); |
| 2682 | if (msg != NULL) { |
| 2683 | RecordComment("Abort message: "); |
| 2684 | RecordComment(msg); |
| 2685 | } |
| 2686 | |
| 2687 | if (FLAG_trap_on_abort) { |
| 2688 | stop(msg); |
| 2689 | return; |
| 2690 | } |
| 2691 | #endif |
| 2692 | |
| 2693 | LoadSmiLiteral(r0, Smi::FromInt(reason)); |
| 2694 | push(r0); |
| 2695 | // Disable stub call restrictions to always allow calls to abort. |
| 2696 | if (!has_frame_) { |
| 2697 | // We don't actually want to generate a pile of code for this, so just |
| 2698 | // claim there is a stack frame, without generating one. |
| 2699 | FrameScope scope(this, StackFrame::NONE); |
| 2700 | CallRuntime(Runtime::kAbort, 1); |
| 2701 | } else { |
| 2702 | CallRuntime(Runtime::kAbort, 1); |
| 2703 | } |
| 2704 | // will not return here |
| 2705 | } |
| 2706 | |
| 2707 | |
| 2708 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2709 | if (context_chain_length > 0) { |
| 2710 | // Move up the chain of contexts to the context containing the slot. |
| 2711 | LoadP(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
| 2712 | for (int i = 1; i < context_chain_length; i++) { |
| 2713 | LoadP(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
| 2714 | } |
| 2715 | } else { |
| 2716 | // Slot is in the current function context. Move it into the |
| 2717 | // destination register in case we store into it (the write barrier |
| 2718 | // cannot be allowed to destroy the context in esi). |
| 2719 | mr(dst, cp); |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | |
| 2724 | void MacroAssembler::LoadTransitionedArrayMapConditional( |
| 2725 | ElementsKind expected_kind, ElementsKind transitioned_kind, |
| 2726 | Register map_in_out, Register scratch, Label* no_map_match) { |
| 2727 | // Load the global or builtins object from the current context. |
| 2728 | LoadP(scratch, |
| 2729 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2730 | LoadP(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset)); |
| 2731 | |
| 2732 | // Check that the function's map is the same as the expected cached map. |
| 2733 | LoadP(scratch, |
| 2734 | MemOperand(scratch, Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX))); |
| 2735 | size_t offset = expected_kind * kPointerSize + FixedArrayBase::kHeaderSize; |
| 2736 | LoadP(scratch, FieldMemOperand(scratch, offset)); |
| 2737 | cmp(map_in_out, scratch); |
| 2738 | bne(no_map_match); |
| 2739 | |
| 2740 | // Use the transitioned cached map. |
| 2741 | offset = transitioned_kind * kPointerSize + FixedArrayBase::kHeaderSize; |
| 2742 | LoadP(map_in_out, FieldMemOperand(scratch, offset)); |
| 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2747 | // Load the global or builtins object from the current context. |
| 2748 | LoadP(function, |
| 2749 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2750 | // Load the native context from the global or builtins object. |
| 2751 | LoadP(function, |
| 2752 | FieldMemOperand(function, GlobalObject::kNativeContextOffset)); |
| 2753 | // Load the function from the native context. |
| 2754 | LoadP(function, MemOperand(function, Context::SlotOffset(index)), r0); |
| 2755 | } |
| 2756 | |
| 2757 | |
| 2758 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2759 | Register map, |
| 2760 | Register scratch) { |
| 2761 | // Load the initial map. The global functions all have initial maps. |
| 2762 | LoadP(map, |
| 2763 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2764 | if (emit_debug_code()) { |
| 2765 | Label ok, fail; |
| 2766 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK); |
| 2767 | b(&ok); |
| 2768 | bind(&fail); |
| 2769 | Abort(kGlobalFunctionsMustHaveInitialMap); |
| 2770 | bind(&ok); |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | |
| 2775 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 2776 | Register reg, Register scratch, Label* not_power_of_two_or_zero) { |
| 2777 | subi(scratch, reg, Operand(1)); |
| 2778 | cmpi(scratch, Operand::Zero()); |
| 2779 | blt(not_power_of_two_or_zero); |
| 2780 | and_(r0, scratch, reg, SetRC); |
| 2781 | bne(not_power_of_two_or_zero, cr0); |
| 2782 | } |
| 2783 | |
| 2784 | |
| 2785 | void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg, |
| 2786 | Register scratch, |
| 2787 | Label* zero_and_neg, |
| 2788 | Label* not_power_of_two) { |
| 2789 | subi(scratch, reg, Operand(1)); |
| 2790 | cmpi(scratch, Operand::Zero()); |
| 2791 | blt(zero_and_neg); |
| 2792 | and_(r0, scratch, reg, SetRC); |
| 2793 | bne(not_power_of_two, cr0); |
| 2794 | } |
| 2795 | |
| 2796 | #if !V8_TARGET_ARCH_PPC64 |
| 2797 | void MacroAssembler::SmiTagCheckOverflow(Register reg, Register overflow) { |
| 2798 | DCHECK(!reg.is(overflow)); |
| 2799 | mr(overflow, reg); // Save original value. |
| 2800 | SmiTag(reg); |
| 2801 | xor_(overflow, overflow, reg, SetRC); // Overflow if (value ^ 2 * value) < 0. |
| 2802 | } |
| 2803 | |
| 2804 | |
| 2805 | void MacroAssembler::SmiTagCheckOverflow(Register dst, Register src, |
| 2806 | Register overflow) { |
| 2807 | if (dst.is(src)) { |
| 2808 | // Fall back to slower case. |
| 2809 | SmiTagCheckOverflow(dst, overflow); |
| 2810 | } else { |
| 2811 | DCHECK(!dst.is(src)); |
| 2812 | DCHECK(!dst.is(overflow)); |
| 2813 | DCHECK(!src.is(overflow)); |
| 2814 | SmiTag(dst, src); |
| 2815 | xor_(overflow, dst, src, SetRC); // Overflow if (value ^ 2 * value) < 0. |
| 2816 | } |
| 2817 | } |
| 2818 | #endif |
| 2819 | |
| 2820 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, Register reg2, |
| 2821 | Label* on_not_both_smi) { |
| 2822 | STATIC_ASSERT(kSmiTag == 0); |
| 2823 | DCHECK_EQ(1, static_cast<int>(kSmiTagMask)); |
| 2824 | orx(r0, reg1, reg2, LeaveRC); |
| 2825 | JumpIfNotSmi(r0, on_not_both_smi); |
| 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | void MacroAssembler::UntagAndJumpIfSmi(Register dst, Register src, |
| 2830 | Label* smi_case) { |
| 2831 | STATIC_ASSERT(kSmiTag == 0); |
| 2832 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2833 | TestBit(src, 0, r0); |
| 2834 | SmiUntag(dst, src); |
| 2835 | beq(smi_case, cr0); |
| 2836 | } |
| 2837 | |
| 2838 | |
| 2839 | void MacroAssembler::UntagAndJumpIfNotSmi(Register dst, Register src, |
| 2840 | Label* non_smi_case) { |
| 2841 | STATIC_ASSERT(kSmiTag == 0); |
| 2842 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2843 | TestBit(src, 0, r0); |
| 2844 | SmiUntag(dst, src); |
| 2845 | bne(non_smi_case, cr0); |
| 2846 | } |
| 2847 | |
| 2848 | |
| 2849 | void MacroAssembler::JumpIfEitherSmi(Register reg1, Register reg2, |
| 2850 | Label* on_either_smi) { |
| 2851 | STATIC_ASSERT(kSmiTag == 0); |
| 2852 | JumpIfSmi(reg1, on_either_smi); |
| 2853 | JumpIfSmi(reg2, on_either_smi); |
| 2854 | } |
| 2855 | |
| 2856 | |
| 2857 | void MacroAssembler::AssertNotSmi(Register object) { |
| 2858 | if (emit_debug_code()) { |
| 2859 | STATIC_ASSERT(kSmiTag == 0); |
| 2860 | TestIfSmi(object, r0); |
| 2861 | Check(ne, kOperandIsASmi, cr0); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | void MacroAssembler::AssertSmi(Register object) { |
| 2867 | if (emit_debug_code()) { |
| 2868 | STATIC_ASSERT(kSmiTag == 0); |
| 2869 | TestIfSmi(object, r0); |
| 2870 | Check(eq, kOperandIsNotSmi, cr0); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | |
| 2875 | void MacroAssembler::AssertString(Register object) { |
| 2876 | if (emit_debug_code()) { |
| 2877 | STATIC_ASSERT(kSmiTag == 0); |
| 2878 | TestIfSmi(object, r0); |
| 2879 | Check(ne, kOperandIsASmiAndNotAString, cr0); |
| 2880 | push(object); |
| 2881 | LoadP(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2882 | CompareInstanceType(object, object, FIRST_NONSTRING_TYPE); |
| 2883 | pop(object); |
| 2884 | Check(lt, kOperandIsNotAString); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | |
| 2889 | void MacroAssembler::AssertName(Register object) { |
| 2890 | if (emit_debug_code()) { |
| 2891 | STATIC_ASSERT(kSmiTag == 0); |
| 2892 | TestIfSmi(object, r0); |
| 2893 | Check(ne, kOperandIsASmiAndNotAName, cr0); |
| 2894 | push(object); |
| 2895 | LoadP(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2896 | CompareInstanceType(object, object, LAST_NAME_TYPE); |
| 2897 | pop(object); |
| 2898 | Check(le, kOperandIsNotAName); |
| 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | |
| 2903 | void MacroAssembler::AssertUndefinedOrAllocationSite(Register object, |
| 2904 | Register scratch) { |
| 2905 | if (emit_debug_code()) { |
| 2906 | Label done_checking; |
| 2907 | AssertNotSmi(object); |
| 2908 | CompareRoot(object, Heap::kUndefinedValueRootIndex); |
| 2909 | beq(&done_checking); |
| 2910 | LoadP(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2911 | CompareRoot(scratch, Heap::kAllocationSiteMapRootIndex); |
| 2912 | Assert(eq, kExpectedUndefinedOrCell); |
| 2913 | bind(&done_checking); |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | void MacroAssembler::AssertIsRoot(Register reg, Heap::RootListIndex index) { |
| 2919 | if (emit_debug_code()) { |
| 2920 | CompareRoot(reg, index); |
| 2921 | Check(eq, kHeapNumberMapRegisterClobbered); |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | |
| 2926 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 2927 | Register heap_number_map, |
| 2928 | Register scratch, |
| 2929 | Label* on_not_heap_number) { |
| 2930 | LoadP(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2931 | AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2932 | cmp(scratch, heap_number_map); |
| 2933 | bne(on_not_heap_number); |
| 2934 | } |
| 2935 | |
| 2936 | |
| 2937 | void MacroAssembler::LookupNumberStringCache(Register object, Register result, |
| 2938 | Register scratch1, |
| 2939 | Register scratch2, |
| 2940 | Register scratch3, |
| 2941 | Label* not_found) { |
| 2942 | // Use of registers. Register result is used as a temporary. |
| 2943 | Register number_string_cache = result; |
| 2944 | Register mask = scratch3; |
| 2945 | |
| 2946 | // Load the number string cache. |
| 2947 | LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 2948 | |
| 2949 | // Make the hash mask from the length of the number string cache. It |
| 2950 | // contains two elements (number and string) for each cache entry. |
| 2951 | LoadP(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 2952 | // Divide length by two (length is a smi). |
| 2953 | ShiftRightArithImm(mask, mask, kSmiTagSize + kSmiShiftSize + 1); |
| 2954 | subi(mask, mask, Operand(1)); // Make mask. |
| 2955 | |
| 2956 | // Calculate the entry in the number string cache. The hash value in the |
| 2957 | // number string cache for smis is just the smi value, and the hash for |
| 2958 | // doubles is the xor of the upper and lower words. See |
| 2959 | // Heap::GetNumberStringCache. |
| 2960 | Label is_smi; |
| 2961 | Label load_result_from_cache; |
| 2962 | JumpIfSmi(object, &is_smi); |
| 2963 | CheckMap(object, scratch1, Heap::kHeapNumberMapRootIndex, not_found, |
| 2964 | DONT_DO_SMI_CHECK); |
| 2965 | |
| 2966 | STATIC_ASSERT(8 == kDoubleSize); |
| 2967 | lwz(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 2968 | lwz(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 2969 | xor_(scratch1, scratch1, scratch2); |
| 2970 | and_(scratch1, scratch1, mask); |
| 2971 | |
| 2972 | // Calculate address of entry in string cache: each entry consists |
| 2973 | // of two pointer sized fields. |
| 2974 | ShiftLeftImm(scratch1, scratch1, Operand(kPointerSizeLog2 + 1)); |
| 2975 | add(scratch1, number_string_cache, scratch1); |
| 2976 | |
| 2977 | Register probe = mask; |
| 2978 | LoadP(probe, FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
| 2979 | JumpIfSmi(probe, not_found); |
| 2980 | lfd(d0, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 2981 | lfd(d1, FieldMemOperand(probe, HeapNumber::kValueOffset)); |
| 2982 | fcmpu(d0, d1); |
| 2983 | bne(not_found); // The cache did not contain this value. |
| 2984 | b(&load_result_from_cache); |
| 2985 | |
| 2986 | bind(&is_smi); |
| 2987 | Register scratch = scratch1; |
| 2988 | SmiUntag(scratch, object); |
| 2989 | and_(scratch, mask, scratch); |
| 2990 | // Calculate address of entry in string cache: each entry consists |
| 2991 | // of two pointer sized fields. |
| 2992 | ShiftLeftImm(scratch, scratch, Operand(kPointerSizeLog2 + 1)); |
| 2993 | add(scratch, number_string_cache, scratch); |
| 2994 | |
| 2995 | // Check if the entry is the smi we are looking for. |
| 2996 | LoadP(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 2997 | cmp(object, probe); |
| 2998 | bne(not_found); |
| 2999 | |
| 3000 | // Get the result from the cache. |
| 3001 | bind(&load_result_from_cache); |
| 3002 | LoadP(result, |
| 3003 | FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize)); |
| 3004 | IncrementCounter(isolate()->counters()->number_to_string_native(), 1, |
| 3005 | scratch1, scratch2); |
| 3006 | } |
| 3007 | |
| 3008 | |
| 3009 | void MacroAssembler::JumpIfNonSmisNotBothSequentialOneByteStrings( |
| 3010 | Register first, Register second, Register scratch1, Register scratch2, |
| 3011 | Label* failure) { |
| 3012 | // Test that both first and second are sequential one-byte strings. |
| 3013 | // Assume that they are non-smis. |
| 3014 | LoadP(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 3015 | LoadP(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 3016 | lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 3017 | lbz(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
| 3018 | |
| 3019 | JumpIfBothInstanceTypesAreNotSequentialOneByte(scratch1, scratch2, scratch1, |
| 3020 | scratch2, failure); |
| 3021 | } |
| 3022 | |
| 3023 | void MacroAssembler::JumpIfNotBothSequentialOneByteStrings(Register first, |
| 3024 | Register second, |
| 3025 | Register scratch1, |
| 3026 | Register scratch2, |
| 3027 | Label* failure) { |
| 3028 | // Check that neither is a smi. |
| 3029 | and_(scratch1, first, second); |
| 3030 | JumpIfSmi(scratch1, failure); |
| 3031 | JumpIfNonSmisNotBothSequentialOneByteStrings(first, second, scratch1, |
| 3032 | scratch2, failure); |
| 3033 | } |
| 3034 | |
| 3035 | |
| 3036 | void MacroAssembler::JumpIfNotUniqueNameInstanceType(Register reg, |
| 3037 | Label* not_unique_name) { |
| 3038 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3039 | Label succeed; |
| 3040 | andi(r0, reg, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3041 | beq(&succeed, cr0); |
| 3042 | cmpi(reg, Operand(SYMBOL_TYPE)); |
| 3043 | bne(not_unique_name); |
| 3044 | |
| 3045 | bind(&succeed); |
| 3046 | } |
| 3047 | |
| 3048 | |
| 3049 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 3050 | // is full and a scavenge is needed. |
| 3051 | void MacroAssembler::AllocateHeapNumber(Register result, Register scratch1, |
| 3052 | Register scratch2, |
| 3053 | Register heap_number_map, |
| 3054 | Label* gc_required, |
| 3055 | TaggingMode tagging_mode, |
| 3056 | MutableMode mode) { |
| 3057 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 3058 | // object. |
| 3059 | Allocate(HeapNumber::kSize, result, scratch1, scratch2, gc_required, |
| 3060 | tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS); |
| 3061 | |
| 3062 | Heap::RootListIndex map_index = mode == MUTABLE |
| 3063 | ? Heap::kMutableHeapNumberMapRootIndex |
| 3064 | : Heap::kHeapNumberMapRootIndex; |
| 3065 | AssertIsRoot(heap_number_map, map_index); |
| 3066 | |
| 3067 | // Store heap number map in the allocated object. |
| 3068 | if (tagging_mode == TAG_RESULT) { |
| 3069 | StoreP(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset), |
| 3070 | r0); |
| 3071 | } else { |
| 3072 | StoreP(heap_number_map, MemOperand(result, HeapObject::kMapOffset)); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | |
| 3077 | void MacroAssembler::AllocateHeapNumberWithValue( |
| 3078 | Register result, DoubleRegister value, Register scratch1, Register scratch2, |
| 3079 | Register heap_number_map, Label* gc_required) { |
| 3080 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 3081 | stfd(value, FieldMemOperand(result, HeapNumber::kValueOffset)); |
| 3082 | } |
| 3083 | |
| 3084 | |
| 3085 | // Copies a fixed number of fields of heap objects from src to dst. |
| 3086 | void MacroAssembler::CopyFields(Register dst, Register src, RegList temps, |
| 3087 | int field_count) { |
| 3088 | // At least one bit set in the first 15 registers. |
| 3089 | DCHECK((temps & ((1 << 15) - 1)) != 0); |
| 3090 | DCHECK((temps & dst.bit()) == 0); |
| 3091 | DCHECK((temps & src.bit()) == 0); |
| 3092 | // Primitive implementation using only one temporary register. |
| 3093 | |
| 3094 | Register tmp = no_reg; |
| 3095 | // Find a temp register in temps list. |
| 3096 | for (int i = 0; i < 15; i++) { |
| 3097 | if ((temps & (1 << i)) != 0) { |
| 3098 | tmp.set_code(i); |
| 3099 | break; |
| 3100 | } |
| 3101 | } |
| 3102 | DCHECK(!tmp.is(no_reg)); |
| 3103 | |
| 3104 | for (int i = 0; i < field_count; i++) { |
| 3105 | LoadP(tmp, FieldMemOperand(src, i * kPointerSize), r0); |
| 3106 | StoreP(tmp, FieldMemOperand(dst, i * kPointerSize), r0); |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | |
| 3111 | void MacroAssembler::CopyBytes(Register src, Register dst, Register length, |
| 3112 | Register scratch) { |
| 3113 | Label align_loop, aligned, word_loop, byte_loop, byte_loop_1, done; |
| 3114 | |
| 3115 | DCHECK(!scratch.is(r0)); |
| 3116 | |
| 3117 | cmpi(length, Operand::Zero()); |
| 3118 | beq(&done); |
| 3119 | |
| 3120 | // Check src alignment and length to see whether word_loop is possible |
| 3121 | andi(scratch, src, Operand(kPointerSize - 1)); |
| 3122 | beq(&aligned, cr0); |
| 3123 | subfic(scratch, scratch, Operand(kPointerSize * 2)); |
| 3124 | cmp(length, scratch); |
| 3125 | blt(&byte_loop); |
| 3126 | |
| 3127 | // Align src before copying in word size chunks. |
| 3128 | subi(scratch, scratch, Operand(kPointerSize)); |
| 3129 | mtctr(scratch); |
| 3130 | bind(&align_loop); |
| 3131 | lbz(scratch, MemOperand(src)); |
| 3132 | addi(src, src, Operand(1)); |
| 3133 | subi(length, length, Operand(1)); |
| 3134 | stb(scratch, MemOperand(dst)); |
| 3135 | addi(dst, dst, Operand(1)); |
| 3136 | bdnz(&align_loop); |
| 3137 | |
| 3138 | bind(&aligned); |
| 3139 | |
| 3140 | // Copy bytes in word size chunks. |
| 3141 | if (emit_debug_code()) { |
| 3142 | andi(r0, src, Operand(kPointerSize - 1)); |
| 3143 | Assert(eq, kExpectingAlignmentForCopyBytes, cr0); |
| 3144 | } |
| 3145 | |
| 3146 | ShiftRightImm(scratch, length, Operand(kPointerSizeLog2)); |
| 3147 | cmpi(scratch, Operand::Zero()); |
| 3148 | beq(&byte_loop); |
| 3149 | |
| 3150 | mtctr(scratch); |
| 3151 | bind(&word_loop); |
| 3152 | LoadP(scratch, MemOperand(src)); |
| 3153 | addi(src, src, Operand(kPointerSize)); |
| 3154 | subi(length, length, Operand(kPointerSize)); |
| 3155 | if (CpuFeatures::IsSupported(UNALIGNED_ACCESSES)) { |
| 3156 | // currently false for PPC - but possible future opt |
| 3157 | StoreP(scratch, MemOperand(dst)); |
| 3158 | addi(dst, dst, Operand(kPointerSize)); |
| 3159 | } else { |
| 3160 | #if V8_TARGET_LITTLE_ENDIAN |
| 3161 | stb(scratch, MemOperand(dst, 0)); |
| 3162 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3163 | stb(scratch, MemOperand(dst, 1)); |
| 3164 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3165 | stb(scratch, MemOperand(dst, 2)); |
| 3166 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3167 | stb(scratch, MemOperand(dst, 3)); |
| 3168 | #if V8_TARGET_ARCH_PPC64 |
| 3169 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3170 | stb(scratch, MemOperand(dst, 4)); |
| 3171 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3172 | stb(scratch, MemOperand(dst, 5)); |
| 3173 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3174 | stb(scratch, MemOperand(dst, 6)); |
| 3175 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3176 | stb(scratch, MemOperand(dst, 7)); |
| 3177 | #endif |
| 3178 | #else |
| 3179 | #if V8_TARGET_ARCH_PPC64 |
| 3180 | stb(scratch, MemOperand(dst, 7)); |
| 3181 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3182 | stb(scratch, MemOperand(dst, 6)); |
| 3183 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3184 | stb(scratch, MemOperand(dst, 5)); |
| 3185 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3186 | stb(scratch, MemOperand(dst, 4)); |
| 3187 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3188 | #endif |
| 3189 | stb(scratch, MemOperand(dst, 3)); |
| 3190 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3191 | stb(scratch, MemOperand(dst, 2)); |
| 3192 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3193 | stb(scratch, MemOperand(dst, 1)); |
| 3194 | ShiftRightImm(scratch, scratch, Operand(8)); |
| 3195 | stb(scratch, MemOperand(dst, 0)); |
| 3196 | #endif |
| 3197 | addi(dst, dst, Operand(kPointerSize)); |
| 3198 | } |
| 3199 | bdnz(&word_loop); |
| 3200 | |
| 3201 | // Copy the last bytes if any left. |
| 3202 | cmpi(length, Operand::Zero()); |
| 3203 | beq(&done); |
| 3204 | |
| 3205 | bind(&byte_loop); |
| 3206 | mtctr(length); |
| 3207 | bind(&byte_loop_1); |
| 3208 | lbz(scratch, MemOperand(src)); |
| 3209 | addi(src, src, Operand(1)); |
| 3210 | stb(scratch, MemOperand(dst)); |
| 3211 | addi(dst, dst, Operand(1)); |
| 3212 | bdnz(&byte_loop_1); |
| 3213 | |
| 3214 | bind(&done); |
| 3215 | } |
| 3216 | |
| 3217 | |
| 3218 | void MacroAssembler::InitializeNFieldsWithFiller(Register start_offset, |
| 3219 | Register count, |
| 3220 | Register filler) { |
| 3221 | Label loop; |
| 3222 | mtctr(count); |
| 3223 | bind(&loop); |
| 3224 | StoreP(filler, MemOperand(start_offset)); |
| 3225 | addi(start_offset, start_offset, Operand(kPointerSize)); |
| 3226 | bdnz(&loop); |
| 3227 | } |
| 3228 | |
| 3229 | void MacroAssembler::InitializeFieldsWithFiller(Register start_offset, |
| 3230 | Register end_offset, |
| 3231 | Register filler) { |
| 3232 | Label done; |
| 3233 | sub(r0, end_offset, start_offset, LeaveOE, SetRC); |
| 3234 | beq(&done, cr0); |
| 3235 | ShiftRightImm(r0, r0, Operand(kPointerSizeLog2)); |
| 3236 | InitializeNFieldsWithFiller(start_offset, r0, filler); |
| 3237 | bind(&done); |
| 3238 | } |
| 3239 | |
| 3240 | |
| 3241 | void MacroAssembler::SaveFPRegs(Register location, int first, int count) { |
| 3242 | DCHECK(count > 0); |
| 3243 | int cur = first; |
| 3244 | subi(location, location, Operand(count * kDoubleSize)); |
| 3245 | for (int i = 0; i < count; i++) { |
| 3246 | DoubleRegister reg = DoubleRegister::from_code(cur++); |
| 3247 | stfd(reg, MemOperand(location, i * kDoubleSize)); |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | |
| 3252 | void MacroAssembler::RestoreFPRegs(Register location, int first, int count) { |
| 3253 | DCHECK(count > 0); |
| 3254 | int cur = first + count - 1; |
| 3255 | for (int i = count - 1; i >= 0; i--) { |
| 3256 | DoubleRegister reg = DoubleRegister::from_code(cur--); |
| 3257 | lfd(reg, MemOperand(location, i * kDoubleSize)); |
| 3258 | } |
| 3259 | addi(location, location, Operand(count * kDoubleSize)); |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialOneByte( |
| 3264 | Register first, Register second, Register scratch1, Register scratch2, |
| 3265 | Label* failure) { |
| 3266 | const int kFlatOneByteStringMask = |
| 3267 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 3268 | const int kFlatOneByteStringTag = |
| 3269 | kStringTag | kOneByteStringTag | kSeqStringTag; |
| 3270 | andi(scratch1, first, Operand(kFlatOneByteStringMask)); |
| 3271 | andi(scratch2, second, Operand(kFlatOneByteStringMask)); |
| 3272 | cmpi(scratch1, Operand(kFlatOneByteStringTag)); |
| 3273 | bne(failure); |
| 3274 | cmpi(scratch2, Operand(kFlatOneByteStringTag)); |
| 3275 | bne(failure); |
| 3276 | } |
| 3277 | |
| 3278 | |
| 3279 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialOneByte(Register type, |
| 3280 | Register scratch, |
| 3281 | Label* failure) { |
| 3282 | const int kFlatOneByteStringMask = |
| 3283 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 3284 | const int kFlatOneByteStringTag = |
| 3285 | kStringTag | kOneByteStringTag | kSeqStringTag; |
| 3286 | andi(scratch, type, Operand(kFlatOneByteStringMask)); |
| 3287 | cmpi(scratch, Operand(kFlatOneByteStringTag)); |
| 3288 | bne(failure); |
| 3289 | } |
| 3290 | |
| 3291 | static const int kRegisterPassedArguments = 8; |
| 3292 | |
| 3293 | |
| 3294 | int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments, |
| 3295 | int num_double_arguments) { |
| 3296 | int stack_passed_words = 0; |
| 3297 | if (num_double_arguments > DoubleRegister::kNumRegisters) { |
| 3298 | stack_passed_words += |
| 3299 | 2 * (num_double_arguments - DoubleRegister::kNumRegisters); |
| 3300 | } |
| 3301 | // Up to 8 simple arguments are passed in registers r3..r10. |
| 3302 | if (num_reg_arguments > kRegisterPassedArguments) { |
| 3303 | stack_passed_words += num_reg_arguments - kRegisterPassedArguments; |
| 3304 | } |
| 3305 | return stack_passed_words; |
| 3306 | } |
| 3307 | |
| 3308 | |
| 3309 | void MacroAssembler::EmitSeqStringSetCharCheck(Register string, Register index, |
| 3310 | Register value, |
| 3311 | uint32_t encoding_mask) { |
| 3312 | Label is_object; |
| 3313 | TestIfSmi(string, r0); |
| 3314 | Check(ne, kNonObject, cr0); |
| 3315 | |
| 3316 | LoadP(ip, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3317 | lbz(ip, FieldMemOperand(ip, Map::kInstanceTypeOffset)); |
| 3318 | |
| 3319 | andi(ip, ip, Operand(kStringRepresentationMask | kStringEncodingMask)); |
| 3320 | cmpi(ip, Operand(encoding_mask)); |
| 3321 | Check(eq, kUnexpectedStringType); |
| 3322 | |
| 3323 | // The index is assumed to be untagged coming in, tag it to compare with the |
| 3324 | // string length without using a temp register, it is restored at the end of |
| 3325 | // this function. |
| 3326 | #if !V8_TARGET_ARCH_PPC64 |
| 3327 | Label index_tag_ok, index_tag_bad; |
| 3328 | JumpIfNotSmiCandidate(index, r0, &index_tag_bad); |
| 3329 | #endif |
| 3330 | SmiTag(index, index); |
| 3331 | #if !V8_TARGET_ARCH_PPC64 |
| 3332 | b(&index_tag_ok); |
| 3333 | bind(&index_tag_bad); |
| 3334 | Abort(kIndexIsTooLarge); |
| 3335 | bind(&index_tag_ok); |
| 3336 | #endif |
| 3337 | |
| 3338 | LoadP(ip, FieldMemOperand(string, String::kLengthOffset)); |
| 3339 | cmp(index, ip); |
| 3340 | Check(lt, kIndexIsTooLarge); |
| 3341 | |
| 3342 | DCHECK(Smi::FromInt(0) == 0); |
| 3343 | cmpi(index, Operand::Zero()); |
| 3344 | Check(ge, kIndexIsNegative); |
| 3345 | |
| 3346 | SmiUntag(index, index); |
| 3347 | } |
| 3348 | |
| 3349 | |
| 3350 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 3351 | int num_double_arguments, |
| 3352 | Register scratch) { |
| 3353 | int frame_alignment = ActivationFrameAlignment(); |
| 3354 | int stack_passed_arguments = |
| 3355 | CalculateStackPassedWords(num_reg_arguments, num_double_arguments); |
| 3356 | int stack_space = kNumRequiredStackFrameSlots; |
| 3357 | |
| 3358 | if (frame_alignment > kPointerSize) { |
| 3359 | // Make stack end at alignment and make room for stack arguments |
| 3360 | // -- preserving original value of sp. |
| 3361 | mr(scratch, sp); |
| 3362 | addi(sp, sp, Operand(-(stack_passed_arguments + 1) * kPointerSize)); |
| 3363 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
| 3364 | ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment))); |
| 3365 | StoreP(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 3366 | } else { |
| 3367 | // Make room for stack arguments |
| 3368 | stack_space += stack_passed_arguments; |
| 3369 | } |
| 3370 | |
| 3371 | // Allocate frame with required slots to make ABI work. |
| 3372 | li(r0, Operand::Zero()); |
| 3373 | StorePU(r0, MemOperand(sp, -stack_space * kPointerSize)); |
| 3374 | } |
| 3375 | |
| 3376 | |
| 3377 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 3378 | Register scratch) { |
| 3379 | PrepareCallCFunction(num_reg_arguments, 0, scratch); |
| 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | void MacroAssembler::MovToFloatParameter(DoubleRegister src) { Move(d1, src); } |
| 3384 | |
| 3385 | |
| 3386 | void MacroAssembler::MovToFloatResult(DoubleRegister src) { Move(d1, src); } |
| 3387 | |
| 3388 | |
| 3389 | void MacroAssembler::MovToFloatParameters(DoubleRegister src1, |
| 3390 | DoubleRegister src2) { |
| 3391 | if (src2.is(d1)) { |
| 3392 | DCHECK(!src1.is(d2)); |
| 3393 | Move(d2, src2); |
| 3394 | Move(d1, src1); |
| 3395 | } else { |
| 3396 | Move(d1, src1); |
| 3397 | Move(d2, src2); |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | |
| 3402 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3403 | int num_reg_arguments, |
| 3404 | int num_double_arguments) { |
| 3405 | mov(ip, Operand(function)); |
| 3406 | CallCFunctionHelper(ip, num_reg_arguments, num_double_arguments); |
| 3407 | } |
| 3408 | |
| 3409 | |
| 3410 | void MacroAssembler::CallCFunction(Register function, int num_reg_arguments, |
| 3411 | int num_double_arguments) { |
| 3412 | CallCFunctionHelper(function, num_reg_arguments, num_double_arguments); |
| 3413 | } |
| 3414 | |
| 3415 | |
| 3416 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3417 | int num_arguments) { |
| 3418 | CallCFunction(function, num_arguments, 0); |
| 3419 | } |
| 3420 | |
| 3421 | |
| 3422 | void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
| 3423 | CallCFunction(function, num_arguments, 0); |
| 3424 | } |
| 3425 | |
| 3426 | |
| 3427 | void MacroAssembler::CallCFunctionHelper(Register function, |
| 3428 | int num_reg_arguments, |
| 3429 | int num_double_arguments) { |
| 3430 | DCHECK(has_frame()); |
| 3431 | // Just call directly. The function called cannot cause a GC, or |
| 3432 | // allow preemption, so the return address in the link register |
| 3433 | // stays correct. |
| 3434 | #if ABI_USES_FUNCTION_DESCRIPTORS && !defined(USE_SIMULATOR) |
| 3435 | // AIX uses a function descriptor. When calling C code be aware |
| 3436 | // of this descriptor and pick up values from it |
| 3437 | LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(function, kPointerSize)); |
| 3438 | LoadP(ip, MemOperand(function, 0)); |
| 3439 | Register dest = ip; |
| 3440 | #elif ABI_TOC_ADDRESSABILITY_VIA_IP |
| 3441 | Move(ip, function); |
| 3442 | Register dest = ip; |
| 3443 | #else |
| 3444 | Register dest = function; |
| 3445 | #endif |
| 3446 | |
| 3447 | Call(dest); |
| 3448 | |
| 3449 | // Remove frame bought in PrepareCallCFunction |
| 3450 | int stack_passed_arguments = |
| 3451 | CalculateStackPassedWords(num_reg_arguments, num_double_arguments); |
| 3452 | int stack_space = kNumRequiredStackFrameSlots + stack_passed_arguments; |
| 3453 | if (ActivationFrameAlignment() > kPointerSize) { |
| 3454 | LoadP(sp, MemOperand(sp, stack_space * kPointerSize)); |
| 3455 | } else { |
| 3456 | addi(sp, sp, Operand(stack_space * kPointerSize)); |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | |
| 3461 | void MacroAssembler::FlushICache(Register address, size_t size, |
| 3462 | Register scratch) { |
| 3463 | if (CpuFeatures::IsSupported(INSTR_AND_DATA_CACHE_COHERENCY)) { |
| 3464 | sync(); |
| 3465 | icbi(r0, address); |
| 3466 | isync(); |
| 3467 | return; |
| 3468 | } |
| 3469 | |
| 3470 | Label done; |
| 3471 | |
| 3472 | dcbf(r0, address); |
| 3473 | sync(); |
| 3474 | icbi(r0, address); |
| 3475 | isync(); |
| 3476 | |
| 3477 | // This code handles ranges which cross a single cacheline boundary. |
| 3478 | // scratch is last cacheline which intersects range. |
| 3479 | const int kCacheLineSizeLog2 = WhichPowerOf2(CpuFeatures::cache_line_size()); |
| 3480 | |
| 3481 | DCHECK(size > 0 && size <= (size_t)(1 << kCacheLineSizeLog2)); |
| 3482 | addi(scratch, address, Operand(size - 1)); |
| 3483 | ClearRightImm(scratch, scratch, Operand(kCacheLineSizeLog2)); |
| 3484 | cmpl(scratch, address); |
| 3485 | ble(&done); |
| 3486 | |
| 3487 | dcbf(r0, scratch); |
| 3488 | sync(); |
| 3489 | icbi(r0, scratch); |
| 3490 | isync(); |
| 3491 | |
| 3492 | bind(&done); |
| 3493 | } |
| 3494 | |
| 3495 | |
| 3496 | void MacroAssembler::SetRelocatedValue(Register location, Register scratch, |
| 3497 | Register new_value) { |
| 3498 | lwz(scratch, MemOperand(location)); |
| 3499 | |
| 3500 | #if V8_OOL_CONSTANT_POOL |
| 3501 | if (emit_debug_code()) { |
| 3502 | // Check that the instruction sequence is a load from the constant pool |
| 3503 | #if V8_TARGET_ARCH_PPC64 |
| 3504 | And(scratch, scratch, Operand(kOpcodeMask | (0x1f * B16))); |
| 3505 | Cmpi(scratch, Operand(ADDI), r0); |
| 3506 | Check(eq, kTheInstructionShouldBeALi); |
| 3507 | lwz(scratch, MemOperand(location, kInstrSize)); |
| 3508 | #endif |
| 3509 | ExtractBitMask(scratch, scratch, 0x1f * B16); |
| 3510 | cmpi(scratch, Operand(kConstantPoolRegister.code())); |
| 3511 | Check(eq, kTheInstructionToPatchShouldBeALoadFromConstantPool); |
| 3512 | // Scratch was clobbered. Restore it. |
| 3513 | lwz(scratch, MemOperand(location)); |
| 3514 | } |
| 3515 | // Get the address of the constant and patch it. |
| 3516 | andi(scratch, scratch, Operand(kImm16Mask)); |
| 3517 | StorePX(new_value, MemOperand(kConstantPoolRegister, scratch)); |
| 3518 | #else |
| 3519 | // This code assumes a FIXED_SEQUENCE for lis/ori |
| 3520 | |
| 3521 | // At this point scratch is a lis instruction. |
| 3522 | if (emit_debug_code()) { |
| 3523 | And(scratch, scratch, Operand(kOpcodeMask | (0x1f * B16))); |
| 3524 | Cmpi(scratch, Operand(ADDIS), r0); |
| 3525 | Check(eq, kTheInstructionToPatchShouldBeALis); |
| 3526 | lwz(scratch, MemOperand(location)); |
| 3527 | } |
| 3528 | |
| 3529 | // insert new high word into lis instruction |
| 3530 | #if V8_TARGET_ARCH_PPC64 |
| 3531 | srdi(ip, new_value, Operand(32)); |
| 3532 | rlwimi(scratch, ip, 16, 16, 31); |
| 3533 | #else |
| 3534 | rlwimi(scratch, new_value, 16, 16, 31); |
| 3535 | #endif |
| 3536 | |
| 3537 | stw(scratch, MemOperand(location)); |
| 3538 | |
| 3539 | lwz(scratch, MemOperand(location, kInstrSize)); |
| 3540 | // scratch is now ori. |
| 3541 | if (emit_debug_code()) { |
| 3542 | And(scratch, scratch, Operand(kOpcodeMask)); |
| 3543 | Cmpi(scratch, Operand(ORI), r0); |
| 3544 | Check(eq, kTheInstructionShouldBeAnOri); |
| 3545 | lwz(scratch, MemOperand(location, kInstrSize)); |
| 3546 | } |
| 3547 | |
| 3548 | // insert new low word into ori instruction |
| 3549 | #if V8_TARGET_ARCH_PPC64 |
| 3550 | rlwimi(scratch, ip, 0, 16, 31); |
| 3551 | #else |
| 3552 | rlwimi(scratch, new_value, 0, 16, 31); |
| 3553 | #endif |
| 3554 | stw(scratch, MemOperand(location, kInstrSize)); |
| 3555 | |
| 3556 | #if V8_TARGET_ARCH_PPC64 |
| 3557 | if (emit_debug_code()) { |
| 3558 | lwz(scratch, MemOperand(location, 2 * kInstrSize)); |
| 3559 | // scratch is now sldi. |
| 3560 | And(scratch, scratch, Operand(kOpcodeMask | kExt5OpcodeMask)); |
| 3561 | Cmpi(scratch, Operand(EXT5 | RLDICR), r0); |
| 3562 | Check(eq, kTheInstructionShouldBeASldi); |
| 3563 | } |
| 3564 | |
| 3565 | lwz(scratch, MemOperand(location, 3 * kInstrSize)); |
| 3566 | // scratch is now ori. |
| 3567 | if (emit_debug_code()) { |
| 3568 | And(scratch, scratch, Operand(kOpcodeMask)); |
| 3569 | Cmpi(scratch, Operand(ORIS), r0); |
| 3570 | Check(eq, kTheInstructionShouldBeAnOris); |
| 3571 | lwz(scratch, MemOperand(location, 3 * kInstrSize)); |
| 3572 | } |
| 3573 | |
| 3574 | rlwimi(scratch, new_value, 16, 16, 31); |
| 3575 | stw(scratch, MemOperand(location, 3 * kInstrSize)); |
| 3576 | |
| 3577 | lwz(scratch, MemOperand(location, 4 * kInstrSize)); |
| 3578 | // scratch is now ori. |
| 3579 | if (emit_debug_code()) { |
| 3580 | And(scratch, scratch, Operand(kOpcodeMask)); |
| 3581 | Cmpi(scratch, Operand(ORI), r0); |
| 3582 | Check(eq, kTheInstructionShouldBeAnOri); |
| 3583 | lwz(scratch, MemOperand(location, 4 * kInstrSize)); |
| 3584 | } |
| 3585 | rlwimi(scratch, new_value, 0, 16, 31); |
| 3586 | stw(scratch, MemOperand(location, 4 * kInstrSize)); |
| 3587 | #endif |
| 3588 | |
| 3589 | // Update the I-cache so the new lis and addic can be executed. |
| 3590 | #if V8_TARGET_ARCH_PPC64 |
| 3591 | FlushICache(location, 5 * kInstrSize, scratch); |
| 3592 | #else |
| 3593 | FlushICache(location, 2 * kInstrSize, scratch); |
| 3594 | #endif |
| 3595 | #endif |
| 3596 | } |
| 3597 | |
| 3598 | |
| 3599 | void MacroAssembler::GetRelocatedValue(Register location, Register result, |
| 3600 | Register scratch) { |
| 3601 | lwz(result, MemOperand(location)); |
| 3602 | |
| 3603 | #if V8_OOL_CONSTANT_POOL |
| 3604 | if (emit_debug_code()) { |
| 3605 | // Check that the instruction sequence is a load from the constant pool |
| 3606 | #if V8_TARGET_ARCH_PPC64 |
| 3607 | And(result, result, Operand(kOpcodeMask | (0x1f * B16))); |
| 3608 | Cmpi(result, Operand(ADDI), r0); |
| 3609 | Check(eq, kTheInstructionShouldBeALi); |
| 3610 | lwz(result, MemOperand(location, kInstrSize)); |
| 3611 | #endif |
| 3612 | ExtractBitMask(result, result, 0x1f * B16); |
| 3613 | cmpi(result, Operand(kConstantPoolRegister.code())); |
| 3614 | Check(eq, kTheInstructionToPatchShouldBeALoadFromConstantPool); |
| 3615 | lwz(result, MemOperand(location)); |
| 3616 | } |
| 3617 | // Get the address of the constant and retrieve it. |
| 3618 | andi(result, result, Operand(kImm16Mask)); |
| 3619 | LoadPX(result, MemOperand(kConstantPoolRegister, result)); |
| 3620 | #else |
| 3621 | // This code assumes a FIXED_SEQUENCE for lis/ori |
| 3622 | if (emit_debug_code()) { |
| 3623 | And(result, result, Operand(kOpcodeMask | (0x1f * B16))); |
| 3624 | Cmpi(result, Operand(ADDIS), r0); |
| 3625 | Check(eq, kTheInstructionShouldBeALis); |
| 3626 | lwz(result, MemOperand(location)); |
| 3627 | } |
| 3628 | |
| 3629 | // result now holds a lis instruction. Extract the immediate. |
| 3630 | slwi(result, result, Operand(16)); |
| 3631 | |
| 3632 | lwz(scratch, MemOperand(location, kInstrSize)); |
| 3633 | if (emit_debug_code()) { |
| 3634 | And(scratch, scratch, Operand(kOpcodeMask)); |
| 3635 | Cmpi(scratch, Operand(ORI), r0); |
| 3636 | Check(eq, kTheInstructionShouldBeAnOri); |
| 3637 | lwz(scratch, MemOperand(location, kInstrSize)); |
| 3638 | } |
| 3639 | // Copy the low 16bits from ori instruction into result |
| 3640 | rlwimi(result, scratch, 0, 16, 31); |
| 3641 | |
| 3642 | #if V8_TARGET_ARCH_PPC64 |
| 3643 | if (emit_debug_code()) { |
| 3644 | lwz(scratch, MemOperand(location, 2 * kInstrSize)); |
| 3645 | // scratch is now sldi. |
| 3646 | And(scratch, scratch, Operand(kOpcodeMask | kExt5OpcodeMask)); |
| 3647 | Cmpi(scratch, Operand(EXT5 | RLDICR), r0); |
| 3648 | Check(eq, kTheInstructionShouldBeASldi); |
| 3649 | } |
| 3650 | |
| 3651 | lwz(scratch, MemOperand(location, 3 * kInstrSize)); |
| 3652 | // scratch is now ori. |
| 3653 | if (emit_debug_code()) { |
| 3654 | And(scratch, scratch, Operand(kOpcodeMask)); |
| 3655 | Cmpi(scratch, Operand(ORIS), r0); |
| 3656 | Check(eq, kTheInstructionShouldBeAnOris); |
| 3657 | lwz(scratch, MemOperand(location, 3 * kInstrSize)); |
| 3658 | } |
| 3659 | sldi(result, result, Operand(16)); |
| 3660 | rldimi(result, scratch, 0, 48); |
| 3661 | |
| 3662 | lwz(scratch, MemOperand(location, 4 * kInstrSize)); |
| 3663 | // scratch is now ori. |
| 3664 | if (emit_debug_code()) { |
| 3665 | And(scratch, scratch, Operand(kOpcodeMask)); |
| 3666 | Cmpi(scratch, Operand(ORI), r0); |
| 3667 | Check(eq, kTheInstructionShouldBeAnOri); |
| 3668 | lwz(scratch, MemOperand(location, 4 * kInstrSize)); |
| 3669 | } |
| 3670 | sldi(result, result, Operand(16)); |
| 3671 | rldimi(result, scratch, 0, 48); |
| 3672 | #endif |
| 3673 | #endif |
| 3674 | } |
| 3675 | |
| 3676 | |
| 3677 | void MacroAssembler::CheckPageFlag( |
| 3678 | Register object, |
| 3679 | Register scratch, // scratch may be same register as object |
| 3680 | int mask, Condition cc, Label* condition_met) { |
| 3681 | DCHECK(cc == ne || cc == eq); |
| 3682 | ClearRightImm(scratch, object, Operand(kPageSizeBits)); |
| 3683 | LoadP(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset)); |
| 3684 | |
| 3685 | And(r0, scratch, Operand(mask), SetRC); |
| 3686 | |
| 3687 | if (cc == ne) { |
| 3688 | bne(condition_met, cr0); |
| 3689 | } |
| 3690 | if (cc == eq) { |
| 3691 | beq(condition_met, cr0); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | |
| 3696 | void MacroAssembler::CheckMapDeprecated(Handle<Map> map, Register scratch, |
| 3697 | Label* if_deprecated) { |
| 3698 | if (map->CanBeDeprecated()) { |
| 3699 | mov(scratch, Operand(map)); |
| 3700 | lwz(scratch, FieldMemOperand(scratch, Map::kBitField3Offset)); |
| 3701 | ExtractBitMask(scratch, scratch, Map::Deprecated::kMask, SetRC); |
| 3702 | bne(if_deprecated, cr0); |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | |
| 3707 | void MacroAssembler::JumpIfBlack(Register object, Register scratch0, |
| 3708 | Register scratch1, Label* on_black) { |
| 3709 | HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern. |
| 3710 | DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 3711 | } |
| 3712 | |
| 3713 | |
| 3714 | void MacroAssembler::HasColor(Register object, Register bitmap_scratch, |
| 3715 | Register mask_scratch, Label* has_color, |
| 3716 | int first_bit, int second_bit) { |
| 3717 | DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, no_reg)); |
| 3718 | |
| 3719 | GetMarkBits(object, bitmap_scratch, mask_scratch); |
| 3720 | |
| 3721 | Label other_color, word_boundary; |
| 3722 | lwz(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3723 | // Test the first bit |
| 3724 | and_(r0, ip, mask_scratch, SetRC); |
| 3725 | b(first_bit == 1 ? eq : ne, &other_color, cr0); |
| 3726 | // Shift left 1 |
| 3727 | // May need to load the next cell |
| 3728 | slwi(mask_scratch, mask_scratch, Operand(1), SetRC); |
| 3729 | beq(&word_boundary, cr0); |
| 3730 | // Test the second bit |
| 3731 | and_(r0, ip, mask_scratch, SetRC); |
| 3732 | b(second_bit == 1 ? ne : eq, has_color, cr0); |
| 3733 | b(&other_color); |
| 3734 | |
| 3735 | bind(&word_boundary); |
| 3736 | lwz(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize + kIntSize)); |
| 3737 | andi(r0, ip, Operand(1)); |
| 3738 | b(second_bit == 1 ? ne : eq, has_color, cr0); |
| 3739 | bind(&other_color); |
| 3740 | } |
| 3741 | |
| 3742 | |
| 3743 | // Detect some, but not all, common pointer-free objects. This is used by the |
| 3744 | // incremental write barrier which doesn't care about oddballs (they are always |
| 3745 | // marked black immediately so this code is not hit). |
| 3746 | void MacroAssembler::JumpIfDataObject(Register value, Register scratch, |
| 3747 | Label* not_data_object) { |
| 3748 | Label is_data_object; |
| 3749 | LoadP(scratch, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 3750 | CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 3751 | beq(&is_data_object); |
| 3752 | DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 3753 | DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 3754 | // If it's a string and it's not a cons string then it's an object containing |
| 3755 | // no GC pointers. |
| 3756 | lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 3757 | STATIC_ASSERT((kIsIndirectStringMask | kIsNotStringMask) == 0x81); |
| 3758 | andi(scratch, scratch, Operand(kIsIndirectStringMask | kIsNotStringMask)); |
| 3759 | bne(not_data_object, cr0); |
| 3760 | bind(&is_data_object); |
| 3761 | } |
| 3762 | |
| 3763 | |
| 3764 | void MacroAssembler::GetMarkBits(Register addr_reg, Register bitmap_reg, |
| 3765 | Register mask_reg) { |
| 3766 | DCHECK(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg)); |
| 3767 | DCHECK((~Page::kPageAlignmentMask & 0xffff) == 0); |
| 3768 | lis(r0, Operand((~Page::kPageAlignmentMask >> 16))); |
| 3769 | and_(bitmap_reg, addr_reg, r0); |
| 3770 | const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2; |
| 3771 | ExtractBitRange(mask_reg, addr_reg, kLowBits - 1, kPointerSizeLog2); |
| 3772 | ExtractBitRange(ip, addr_reg, kPageSizeBits - 1, kLowBits); |
| 3773 | ShiftLeftImm(ip, ip, Operand(Bitmap::kBytesPerCellLog2)); |
| 3774 | add(bitmap_reg, bitmap_reg, ip); |
| 3775 | li(ip, Operand(1)); |
| 3776 | slw(mask_reg, ip, mask_reg); |
| 3777 | } |
| 3778 | |
| 3779 | |
| 3780 | void MacroAssembler::EnsureNotWhite(Register value, Register bitmap_scratch, |
| 3781 | Register mask_scratch, |
| 3782 | Register load_scratch, |
| 3783 | Label* value_is_white_and_not_data) { |
| 3784 | DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, ip)); |
| 3785 | GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 3786 | |
| 3787 | // If the value is black or grey we don't need to do anything. |
| 3788 | DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 3789 | DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 3790 | DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 3791 | DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 3792 | |
| 3793 | Label done; |
| 3794 | |
| 3795 | // Since both black and grey have a 1 in the first position and white does |
| 3796 | // not have a 1 there we only need to check one bit. |
| 3797 | lwz(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3798 | and_(r0, mask_scratch, load_scratch, SetRC); |
| 3799 | bne(&done, cr0); |
| 3800 | |
| 3801 | if (emit_debug_code()) { |
| 3802 | // Check for impossible bit pattern. |
| 3803 | Label ok; |
| 3804 | // LSL may overflow, making the check conservative. |
| 3805 | slwi(r0, mask_scratch, Operand(1)); |
| 3806 | and_(r0, load_scratch, r0, SetRC); |
| 3807 | beq(&ok, cr0); |
| 3808 | stop("Impossible marking bit pattern"); |
| 3809 | bind(&ok); |
| 3810 | } |
| 3811 | |
| 3812 | // Value is white. We check whether it is data that doesn't need scanning. |
| 3813 | // Currently only checks for HeapNumber and non-cons strings. |
| 3814 | Register map = load_scratch; // Holds map while checking type. |
| 3815 | Register length = load_scratch; // Holds length of object after testing type. |
| 3816 | Label is_data_object, maybe_string_object, is_string_object, is_encoded; |
| 3817 | #if V8_TARGET_ARCH_PPC64 |
| 3818 | Label length_computed; |
| 3819 | #endif |
| 3820 | |
| 3821 | |
| 3822 | // Check for heap-number |
| 3823 | LoadP(map, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 3824 | CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 3825 | bne(&maybe_string_object); |
| 3826 | li(length, Operand(HeapNumber::kSize)); |
| 3827 | b(&is_data_object); |
| 3828 | bind(&maybe_string_object); |
| 3829 | |
| 3830 | // Check for strings. |
| 3831 | DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 3832 | DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 3833 | // If it's a string and it's not a cons string then it's an object containing |
| 3834 | // no GC pointers. |
| 3835 | Register instance_type = load_scratch; |
| 3836 | lbz(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 3837 | andi(r0, instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask)); |
| 3838 | bne(value_is_white_and_not_data, cr0); |
| 3839 | // It's a non-indirect (non-cons and non-slice) string. |
| 3840 | // If it's external, the length is just ExternalString::kSize. |
| 3841 | // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). |
| 3842 | // External strings are the only ones with the kExternalStringTag bit |
| 3843 | // set. |
| 3844 | DCHECK_EQ(0, kSeqStringTag & kExternalStringTag); |
| 3845 | DCHECK_EQ(0, kConsStringTag & kExternalStringTag); |
| 3846 | andi(r0, instance_type, Operand(kExternalStringTag)); |
| 3847 | beq(&is_string_object, cr0); |
| 3848 | li(length, Operand(ExternalString::kSize)); |
| 3849 | b(&is_data_object); |
| 3850 | bind(&is_string_object); |
| 3851 | |
| 3852 | // Sequential string, either Latin1 or UC16. |
| 3853 | // For Latin1 (char-size of 1) we untag the smi to get the length. |
| 3854 | // For UC16 (char-size of 2): |
| 3855 | // - (32-bit) we just leave the smi tag in place, thereby getting |
| 3856 | // the length multiplied by 2. |
| 3857 | // - (64-bit) we compute the offset in the 2-byte array |
| 3858 | DCHECK(kOneByteStringTag == 4 && kStringEncodingMask == 4); |
| 3859 | LoadP(ip, FieldMemOperand(value, String::kLengthOffset)); |
| 3860 | andi(r0, instance_type, Operand(kStringEncodingMask)); |
| 3861 | beq(&is_encoded, cr0); |
| 3862 | SmiUntag(ip); |
| 3863 | #if V8_TARGET_ARCH_PPC64 |
| 3864 | b(&length_computed); |
| 3865 | #endif |
| 3866 | bind(&is_encoded); |
| 3867 | #if V8_TARGET_ARCH_PPC64 |
| 3868 | SmiToShortArrayOffset(ip, ip); |
| 3869 | bind(&length_computed); |
| 3870 | #else |
| 3871 | DCHECK(kSmiShift == 1); |
| 3872 | #endif |
| 3873 | addi(length, ip, Operand(SeqString::kHeaderSize + kObjectAlignmentMask)); |
| 3874 | li(r0, Operand(~kObjectAlignmentMask)); |
| 3875 | and_(length, length, r0); |
| 3876 | |
| 3877 | bind(&is_data_object); |
| 3878 | // Value is a data object, and it is white. Mark it black. Since we know |
| 3879 | // that the object is white we can make it black by flipping one bit. |
| 3880 | lwz(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3881 | orx(ip, ip, mask_scratch); |
| 3882 | stw(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3883 | |
| 3884 | mov(ip, Operand(~Page::kPageAlignmentMask)); |
| 3885 | and_(bitmap_scratch, bitmap_scratch, ip); |
| 3886 | lwz(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 3887 | add(ip, ip, length); |
| 3888 | stw(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 3889 | |
| 3890 | bind(&done); |
| 3891 | } |
| 3892 | |
| 3893 | |
| 3894 | // Saturate a value into 8-bit unsigned integer |
| 3895 | // if input_value < 0, output_value is 0 |
| 3896 | // if input_value > 255, output_value is 255 |
| 3897 | // otherwise output_value is the input_value |
| 3898 | void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) { |
| 3899 | Label done, negative_label, overflow_label; |
| 3900 | int satval = (1 << 8) - 1; |
| 3901 | |
| 3902 | cmpi(input_reg, Operand::Zero()); |
| 3903 | blt(&negative_label); |
| 3904 | |
| 3905 | cmpi(input_reg, Operand(satval)); |
| 3906 | bgt(&overflow_label); |
| 3907 | if (!output_reg.is(input_reg)) { |
| 3908 | mr(output_reg, input_reg); |
| 3909 | } |
| 3910 | b(&done); |
| 3911 | |
| 3912 | bind(&negative_label); |
| 3913 | li(output_reg, Operand::Zero()); // set to 0 if negative |
| 3914 | b(&done); |
| 3915 | |
| 3916 | |
| 3917 | bind(&overflow_label); // set to satval if > satval |
| 3918 | li(output_reg, Operand(satval)); |
| 3919 | |
| 3920 | bind(&done); |
| 3921 | } |
| 3922 | |
| 3923 | |
| 3924 | void MacroAssembler::SetRoundingMode(FPRoundingMode RN) { mtfsfi(7, RN); } |
| 3925 | |
| 3926 | |
| 3927 | void MacroAssembler::ResetRoundingMode() { |
| 3928 | mtfsfi(7, kRoundToNearest); // reset (default is kRoundToNearest) |
| 3929 | } |
| 3930 | |
| 3931 | |
| 3932 | void MacroAssembler::ClampDoubleToUint8(Register result_reg, |
| 3933 | DoubleRegister input_reg, |
| 3934 | DoubleRegister double_scratch) { |
| 3935 | Label above_zero; |
| 3936 | Label done; |
| 3937 | Label in_bounds; |
| 3938 | |
| 3939 | LoadDoubleLiteral(double_scratch, 0.0, result_reg); |
| 3940 | fcmpu(input_reg, double_scratch); |
| 3941 | bgt(&above_zero); |
| 3942 | |
| 3943 | // Double value is less than zero, NaN or Inf, return 0. |
| 3944 | LoadIntLiteral(result_reg, 0); |
| 3945 | b(&done); |
| 3946 | |
| 3947 | // Double value is >= 255, return 255. |
| 3948 | bind(&above_zero); |
| 3949 | LoadDoubleLiteral(double_scratch, 255.0, result_reg); |
| 3950 | fcmpu(input_reg, double_scratch); |
| 3951 | ble(&in_bounds); |
| 3952 | LoadIntLiteral(result_reg, 255); |
| 3953 | b(&done); |
| 3954 | |
| 3955 | // In 0-255 range, round and truncate. |
| 3956 | bind(&in_bounds); |
| 3957 | |
| 3958 | // round to nearest (default rounding mode) |
| 3959 | fctiw(double_scratch, input_reg); |
| 3960 | MovDoubleLowToInt(result_reg, double_scratch); |
| 3961 | bind(&done); |
| 3962 | } |
| 3963 | |
| 3964 | |
| 3965 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
| 3966 | Register descriptors) { |
| 3967 | LoadP(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset)); |
| 3968 | } |
| 3969 | |
| 3970 | |
| 3971 | void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) { |
| 3972 | lwz(dst, FieldMemOperand(map, Map::kBitField3Offset)); |
| 3973 | DecodeField<Map::NumberOfOwnDescriptorsBits>(dst); |
| 3974 | } |
| 3975 | |
| 3976 | |
| 3977 | void MacroAssembler::EnumLength(Register dst, Register map) { |
| 3978 | STATIC_ASSERT(Map::EnumLengthBits::kShift == 0); |
| 3979 | lwz(dst, FieldMemOperand(map, Map::kBitField3Offset)); |
| 3980 | ExtractBitMask(dst, dst, Map::EnumLengthBits::kMask); |
| 3981 | SmiTag(dst); |
| 3982 | } |
| 3983 | |
| 3984 | |
| 3985 | void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { |
| 3986 | Register empty_fixed_array_value = r9; |
| 3987 | LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); |
| 3988 | Label next, start; |
| 3989 | mr(r5, r3); |
| 3990 | |
| 3991 | // Check if the enum length field is properly initialized, indicating that |
| 3992 | // there is an enum cache. |
| 3993 | LoadP(r4, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 3994 | |
| 3995 | EnumLength(r6, r4); |
| 3996 | CmpSmiLiteral(r6, Smi::FromInt(kInvalidEnumCacheSentinel), r0); |
| 3997 | beq(call_runtime); |
| 3998 | |
| 3999 | b(&start); |
| 4000 | |
| 4001 | bind(&next); |
| 4002 | LoadP(r4, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 4003 | |
| 4004 | // For all objects but the receiver, check that the cache is empty. |
| 4005 | EnumLength(r6, r4); |
| 4006 | CmpSmiLiteral(r6, Smi::FromInt(0), r0); |
| 4007 | bne(call_runtime); |
| 4008 | |
| 4009 | bind(&start); |
| 4010 | |
| 4011 | // Check that there are no elements. Register r5 contains the current JS |
| 4012 | // object we've reached through the prototype chain. |
| 4013 | Label no_elements; |
| 4014 | LoadP(r5, FieldMemOperand(r5, JSObject::kElementsOffset)); |
| 4015 | cmp(r5, empty_fixed_array_value); |
| 4016 | beq(&no_elements); |
| 4017 | |
| 4018 | // Second chance, the object may be using the empty slow element dictionary. |
| 4019 | CompareRoot(r5, Heap::kEmptySlowElementDictionaryRootIndex); |
| 4020 | bne(call_runtime); |
| 4021 | |
| 4022 | bind(&no_elements); |
| 4023 | LoadP(r5, FieldMemOperand(r4, Map::kPrototypeOffset)); |
| 4024 | cmp(r5, null_value); |
| 4025 | bne(&next); |
| 4026 | } |
| 4027 | |
| 4028 | |
| 4029 | //////////////////////////////////////////////////////////////////////////////// |
| 4030 | // |
| 4031 | // New MacroAssembler Interfaces added for PPC |
| 4032 | // |
| 4033 | //////////////////////////////////////////////////////////////////////////////// |
| 4034 | void MacroAssembler::LoadIntLiteral(Register dst, int value) { |
| 4035 | mov(dst, Operand(value)); |
| 4036 | } |
| 4037 | |
| 4038 | |
| 4039 | void MacroAssembler::LoadSmiLiteral(Register dst, Smi* smi) { |
| 4040 | mov(dst, Operand(smi)); |
| 4041 | } |
| 4042 | |
| 4043 | |
| 4044 | void MacroAssembler::LoadDoubleLiteral(DoubleRegister result, double value, |
| 4045 | Register scratch) { |
| 4046 | #if V8_OOL_CONSTANT_POOL |
| 4047 | // TODO(mbrandy): enable extended constant pool usage for doubles. |
| 4048 | // See ARM commit e27ab337 for a reference. |
| 4049 | if (is_ool_constant_pool_available() && !is_constant_pool_full()) { |
| 4050 | RelocInfo rinfo(pc_, value); |
| 4051 | ConstantPoolAddEntry(rinfo); |
| 4052 | #if V8_TARGET_ARCH_PPC64 |
| 4053 | // We use 2 instruction sequence here for consistency with mov. |
| 4054 | li(scratch, Operand::Zero()); |
| 4055 | lfdx(result, MemOperand(kConstantPoolRegister, scratch)); |
| 4056 | #else |
| 4057 | lfd(result, MemOperand(kConstantPoolRegister, 0)); |
| 4058 | #endif |
| 4059 | return; |
| 4060 | } |
| 4061 | #endif |
| 4062 | |
| 4063 | // avoid gcc strict aliasing error using union cast |
| 4064 | union { |
| 4065 | double dval; |
| 4066 | #if V8_TARGET_ARCH_PPC64 |
| 4067 | intptr_t ival; |
| 4068 | #else |
| 4069 | intptr_t ival[2]; |
| 4070 | #endif |
| 4071 | } litVal; |
| 4072 | |
| 4073 | litVal.dval = value; |
| 4074 | |
| 4075 | #if V8_TARGET_ARCH_PPC64 |
| 4076 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4077 | mov(scratch, Operand(litVal.ival)); |
| 4078 | mtfprd(result, scratch); |
| 4079 | return; |
| 4080 | } |
| 4081 | #endif |
| 4082 | |
| 4083 | addi(sp, sp, Operand(-kDoubleSize)); |
| 4084 | #if V8_TARGET_ARCH_PPC64 |
| 4085 | mov(scratch, Operand(litVal.ival)); |
| 4086 | std(scratch, MemOperand(sp)); |
| 4087 | #else |
| 4088 | LoadIntLiteral(scratch, litVal.ival[0]); |
| 4089 | stw(scratch, MemOperand(sp, 0)); |
| 4090 | LoadIntLiteral(scratch, litVal.ival[1]); |
| 4091 | stw(scratch, MemOperand(sp, 4)); |
| 4092 | #endif |
| 4093 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4094 | lfd(result, MemOperand(sp, 0)); |
| 4095 | addi(sp, sp, Operand(kDoubleSize)); |
| 4096 | } |
| 4097 | |
| 4098 | |
| 4099 | void MacroAssembler::MovIntToDouble(DoubleRegister dst, Register src, |
| 4100 | Register scratch) { |
| 4101 | // sign-extend src to 64-bit |
| 4102 | #if V8_TARGET_ARCH_PPC64 |
| 4103 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4104 | mtfprwa(dst, src); |
| 4105 | return; |
| 4106 | } |
| 4107 | #endif |
| 4108 | |
| 4109 | DCHECK(!src.is(scratch)); |
| 4110 | subi(sp, sp, Operand(kDoubleSize)); |
| 4111 | #if V8_TARGET_ARCH_PPC64 |
| 4112 | extsw(scratch, src); |
| 4113 | std(scratch, MemOperand(sp, 0)); |
| 4114 | #else |
| 4115 | srawi(scratch, src, 31); |
| 4116 | stw(scratch, MemOperand(sp, Register::kExponentOffset)); |
| 4117 | stw(src, MemOperand(sp, Register::kMantissaOffset)); |
| 4118 | #endif |
| 4119 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4120 | lfd(dst, MemOperand(sp, 0)); |
| 4121 | addi(sp, sp, Operand(kDoubleSize)); |
| 4122 | } |
| 4123 | |
| 4124 | |
| 4125 | void MacroAssembler::MovUnsignedIntToDouble(DoubleRegister dst, Register src, |
| 4126 | Register scratch) { |
| 4127 | // zero-extend src to 64-bit |
| 4128 | #if V8_TARGET_ARCH_PPC64 |
| 4129 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4130 | mtfprwz(dst, src); |
| 4131 | return; |
| 4132 | } |
| 4133 | #endif |
| 4134 | |
| 4135 | DCHECK(!src.is(scratch)); |
| 4136 | subi(sp, sp, Operand(kDoubleSize)); |
| 4137 | #if V8_TARGET_ARCH_PPC64 |
| 4138 | clrldi(scratch, src, Operand(32)); |
| 4139 | std(scratch, MemOperand(sp, 0)); |
| 4140 | #else |
| 4141 | li(scratch, Operand::Zero()); |
| 4142 | stw(scratch, MemOperand(sp, Register::kExponentOffset)); |
| 4143 | stw(src, MemOperand(sp, Register::kMantissaOffset)); |
| 4144 | #endif |
| 4145 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4146 | lfd(dst, MemOperand(sp, 0)); |
| 4147 | addi(sp, sp, Operand(kDoubleSize)); |
| 4148 | } |
| 4149 | |
| 4150 | |
| 4151 | void MacroAssembler::MovInt64ToDouble(DoubleRegister dst, |
| 4152 | #if !V8_TARGET_ARCH_PPC64 |
| 4153 | Register src_hi, |
| 4154 | #endif |
| 4155 | Register src) { |
| 4156 | #if V8_TARGET_ARCH_PPC64 |
| 4157 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4158 | mtfprd(dst, src); |
| 4159 | return; |
| 4160 | } |
| 4161 | #endif |
| 4162 | |
| 4163 | subi(sp, sp, Operand(kDoubleSize)); |
| 4164 | #if V8_TARGET_ARCH_PPC64 |
| 4165 | std(src, MemOperand(sp, 0)); |
| 4166 | #else |
| 4167 | stw(src_hi, MemOperand(sp, Register::kExponentOffset)); |
| 4168 | stw(src, MemOperand(sp, Register::kMantissaOffset)); |
| 4169 | #endif |
| 4170 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4171 | lfd(dst, MemOperand(sp, 0)); |
| 4172 | addi(sp, sp, Operand(kDoubleSize)); |
| 4173 | } |
| 4174 | |
| 4175 | |
| 4176 | #if V8_TARGET_ARCH_PPC64 |
| 4177 | void MacroAssembler::MovInt64ComponentsToDouble(DoubleRegister dst, |
| 4178 | Register src_hi, |
| 4179 | Register src_lo, |
| 4180 | Register scratch) { |
| 4181 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4182 | sldi(scratch, src_hi, Operand(32)); |
| 4183 | rldimi(scratch, src_lo, 0, 32); |
| 4184 | mtfprd(dst, scratch); |
| 4185 | return; |
| 4186 | } |
| 4187 | |
| 4188 | subi(sp, sp, Operand(kDoubleSize)); |
| 4189 | stw(src_hi, MemOperand(sp, Register::kExponentOffset)); |
| 4190 | stw(src_lo, MemOperand(sp, Register::kMantissaOffset)); |
| 4191 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4192 | lfd(dst, MemOperand(sp)); |
| 4193 | addi(sp, sp, Operand(kDoubleSize)); |
| 4194 | } |
| 4195 | #endif |
| 4196 | |
| 4197 | |
| 4198 | void MacroAssembler::MovDoubleLowToInt(Register dst, DoubleRegister src) { |
| 4199 | #if V8_TARGET_ARCH_PPC64 |
| 4200 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4201 | mffprwz(dst, src); |
| 4202 | return; |
| 4203 | } |
| 4204 | #endif |
| 4205 | |
| 4206 | subi(sp, sp, Operand(kDoubleSize)); |
| 4207 | stfd(src, MemOperand(sp)); |
| 4208 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4209 | lwz(dst, MemOperand(sp, Register::kMantissaOffset)); |
| 4210 | addi(sp, sp, Operand(kDoubleSize)); |
| 4211 | } |
| 4212 | |
| 4213 | |
| 4214 | void MacroAssembler::MovDoubleHighToInt(Register dst, DoubleRegister src) { |
| 4215 | #if V8_TARGET_ARCH_PPC64 |
| 4216 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4217 | mffprd(dst, src); |
| 4218 | srdi(dst, dst, Operand(32)); |
| 4219 | return; |
| 4220 | } |
| 4221 | #endif |
| 4222 | |
| 4223 | subi(sp, sp, Operand(kDoubleSize)); |
| 4224 | stfd(src, MemOperand(sp)); |
| 4225 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4226 | lwz(dst, MemOperand(sp, Register::kExponentOffset)); |
| 4227 | addi(sp, sp, Operand(kDoubleSize)); |
| 4228 | } |
| 4229 | |
| 4230 | |
| 4231 | void MacroAssembler::MovDoubleToInt64( |
| 4232 | #if !V8_TARGET_ARCH_PPC64 |
| 4233 | Register dst_hi, |
| 4234 | #endif |
| 4235 | Register dst, DoubleRegister src) { |
| 4236 | #if V8_TARGET_ARCH_PPC64 |
| 4237 | if (CpuFeatures::IsSupported(FPR_GPR_MOV)) { |
| 4238 | mffprd(dst, src); |
| 4239 | return; |
| 4240 | } |
| 4241 | #endif |
| 4242 | |
| 4243 | subi(sp, sp, Operand(kDoubleSize)); |
| 4244 | stfd(src, MemOperand(sp)); |
| 4245 | nop(GROUP_ENDING_NOP); // LHS/RAW optimization |
| 4246 | #if V8_TARGET_ARCH_PPC64 |
| 4247 | ld(dst, MemOperand(sp, 0)); |
| 4248 | #else |
| 4249 | lwz(dst_hi, MemOperand(sp, Register::kExponentOffset)); |
| 4250 | lwz(dst, MemOperand(sp, Register::kMantissaOffset)); |
| 4251 | #endif |
| 4252 | addi(sp, sp, Operand(kDoubleSize)); |
| 4253 | } |
| 4254 | |
| 4255 | |
| 4256 | void MacroAssembler::Add(Register dst, Register src, intptr_t value, |
| 4257 | Register scratch) { |
| 4258 | if (is_int16(value)) { |
| 4259 | addi(dst, src, Operand(value)); |
| 4260 | } else { |
| 4261 | mov(scratch, Operand(value)); |
| 4262 | add(dst, src, scratch); |
| 4263 | } |
| 4264 | } |
| 4265 | |
| 4266 | |
| 4267 | void MacroAssembler::Cmpi(Register src1, const Operand& src2, Register scratch, |
| 4268 | CRegister cr) { |
| 4269 | intptr_t value = src2.immediate(); |
| 4270 | if (is_int16(value)) { |
| 4271 | cmpi(src1, src2, cr); |
| 4272 | } else { |
| 4273 | mov(scratch, src2); |
| 4274 | cmp(src1, scratch, cr); |
| 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | |
| 4279 | void MacroAssembler::Cmpli(Register src1, const Operand& src2, Register scratch, |
| 4280 | CRegister cr) { |
| 4281 | intptr_t value = src2.immediate(); |
| 4282 | if (is_uint16(value)) { |
| 4283 | cmpli(src1, src2, cr); |
| 4284 | } else { |
| 4285 | mov(scratch, src2); |
| 4286 | cmpl(src1, scratch, cr); |
| 4287 | } |
| 4288 | } |
| 4289 | |
| 4290 | |
| 4291 | void MacroAssembler::Cmpwi(Register src1, const Operand& src2, Register scratch, |
| 4292 | CRegister cr) { |
| 4293 | intptr_t value = src2.immediate(); |
| 4294 | if (is_int16(value)) { |
| 4295 | cmpwi(src1, src2, cr); |
| 4296 | } else { |
| 4297 | mov(scratch, src2); |
| 4298 | cmpw(src1, scratch, cr); |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | |
| 4303 | void MacroAssembler::Cmplwi(Register src1, const Operand& src2, |
| 4304 | Register scratch, CRegister cr) { |
| 4305 | intptr_t value = src2.immediate(); |
| 4306 | if (is_uint16(value)) { |
| 4307 | cmplwi(src1, src2, cr); |
| 4308 | } else { |
| 4309 | mov(scratch, src2); |
| 4310 | cmplw(src1, scratch, cr); |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | |
| 4315 | void MacroAssembler::And(Register ra, Register rs, const Operand& rb, |
| 4316 | RCBit rc) { |
| 4317 | if (rb.is_reg()) { |
| 4318 | and_(ra, rs, rb.rm(), rc); |
| 4319 | } else { |
| 4320 | if (is_uint16(rb.imm_) && RelocInfo::IsNone(rb.rmode_) && rc == SetRC) { |
| 4321 | andi(ra, rs, rb); |
| 4322 | } else { |
| 4323 | // mov handles the relocation. |
| 4324 | DCHECK(!rs.is(r0)); |
| 4325 | mov(r0, rb); |
| 4326 | and_(ra, rs, r0, rc); |
| 4327 | } |
| 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | |
| 4332 | void MacroAssembler::Or(Register ra, Register rs, const Operand& rb, RCBit rc) { |
| 4333 | if (rb.is_reg()) { |
| 4334 | orx(ra, rs, rb.rm(), rc); |
| 4335 | } else { |
| 4336 | if (is_uint16(rb.imm_) && RelocInfo::IsNone(rb.rmode_) && rc == LeaveRC) { |
| 4337 | ori(ra, rs, rb); |
| 4338 | } else { |
| 4339 | // mov handles the relocation. |
| 4340 | DCHECK(!rs.is(r0)); |
| 4341 | mov(r0, rb); |
| 4342 | orx(ra, rs, r0, rc); |
| 4343 | } |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | |
| 4348 | void MacroAssembler::Xor(Register ra, Register rs, const Operand& rb, |
| 4349 | RCBit rc) { |
| 4350 | if (rb.is_reg()) { |
| 4351 | xor_(ra, rs, rb.rm(), rc); |
| 4352 | } else { |
| 4353 | if (is_uint16(rb.imm_) && RelocInfo::IsNone(rb.rmode_) && rc == LeaveRC) { |
| 4354 | xori(ra, rs, rb); |
| 4355 | } else { |
| 4356 | // mov handles the relocation. |
| 4357 | DCHECK(!rs.is(r0)); |
| 4358 | mov(r0, rb); |
| 4359 | xor_(ra, rs, r0, rc); |
| 4360 | } |
| 4361 | } |
| 4362 | } |
| 4363 | |
| 4364 | |
| 4365 | void MacroAssembler::CmpSmiLiteral(Register src1, Smi* smi, Register scratch, |
| 4366 | CRegister cr) { |
| 4367 | #if V8_TARGET_ARCH_PPC64 |
| 4368 | LoadSmiLiteral(scratch, smi); |
| 4369 | cmp(src1, scratch, cr); |
| 4370 | #else |
| 4371 | Cmpi(src1, Operand(smi), scratch, cr); |
| 4372 | #endif |
| 4373 | } |
| 4374 | |
| 4375 | |
| 4376 | void MacroAssembler::CmplSmiLiteral(Register src1, Smi* smi, Register scratch, |
| 4377 | CRegister cr) { |
| 4378 | #if V8_TARGET_ARCH_PPC64 |
| 4379 | LoadSmiLiteral(scratch, smi); |
| 4380 | cmpl(src1, scratch, cr); |
| 4381 | #else |
| 4382 | Cmpli(src1, Operand(smi), scratch, cr); |
| 4383 | #endif |
| 4384 | } |
| 4385 | |
| 4386 | |
| 4387 | void MacroAssembler::AddSmiLiteral(Register dst, Register src, Smi* smi, |
| 4388 | Register scratch) { |
| 4389 | #if V8_TARGET_ARCH_PPC64 |
| 4390 | LoadSmiLiteral(scratch, smi); |
| 4391 | add(dst, src, scratch); |
| 4392 | #else |
| 4393 | Add(dst, src, reinterpret_cast<intptr_t>(smi), scratch); |
| 4394 | #endif |
| 4395 | } |
| 4396 | |
| 4397 | |
| 4398 | void MacroAssembler::SubSmiLiteral(Register dst, Register src, Smi* smi, |
| 4399 | Register scratch) { |
| 4400 | #if V8_TARGET_ARCH_PPC64 |
| 4401 | LoadSmiLiteral(scratch, smi); |
| 4402 | sub(dst, src, scratch); |
| 4403 | #else |
| 4404 | Add(dst, src, -(reinterpret_cast<intptr_t>(smi)), scratch); |
| 4405 | #endif |
| 4406 | } |
| 4407 | |
| 4408 | |
| 4409 | void MacroAssembler::AndSmiLiteral(Register dst, Register src, Smi* smi, |
| 4410 | Register scratch, RCBit rc) { |
| 4411 | #if V8_TARGET_ARCH_PPC64 |
| 4412 | LoadSmiLiteral(scratch, smi); |
| 4413 | and_(dst, src, scratch, rc); |
| 4414 | #else |
| 4415 | And(dst, src, Operand(smi), rc); |
| 4416 | #endif |
| 4417 | } |
| 4418 | |
| 4419 | |
| 4420 | // Load a "pointer" sized value from the memory location |
| 4421 | void MacroAssembler::LoadP(Register dst, const MemOperand& mem, |
| 4422 | Register scratch) { |
| 4423 | int offset = mem.offset(); |
| 4424 | |
| 4425 | if (!scratch.is(no_reg) && !is_int16(offset)) { |
| 4426 | /* cannot use d-form */ |
| 4427 | LoadIntLiteral(scratch, offset); |
| 4428 | #if V8_TARGET_ARCH_PPC64 |
| 4429 | ldx(dst, MemOperand(mem.ra(), scratch)); |
| 4430 | #else |
| 4431 | lwzx(dst, MemOperand(mem.ra(), scratch)); |
| 4432 | #endif |
| 4433 | } else { |
| 4434 | #if V8_TARGET_ARCH_PPC64 |
| 4435 | int misaligned = (offset & 3); |
| 4436 | if (misaligned) { |
| 4437 | // adjust base to conform to offset alignment requirements |
| 4438 | // Todo: enhance to use scratch if dst is unsuitable |
| 4439 | DCHECK(!dst.is(r0)); |
| 4440 | addi(dst, mem.ra(), Operand((offset & 3) - 4)); |
| 4441 | ld(dst, MemOperand(dst, (offset & ~3) + 4)); |
| 4442 | } else { |
| 4443 | ld(dst, mem); |
| 4444 | } |
| 4445 | #else |
| 4446 | lwz(dst, mem); |
| 4447 | #endif |
| 4448 | } |
| 4449 | } |
| 4450 | |
| 4451 | |
| 4452 | // Store a "pointer" sized value to the memory location |
| 4453 | void MacroAssembler::StoreP(Register src, const MemOperand& mem, |
| 4454 | Register scratch) { |
| 4455 | int offset = mem.offset(); |
| 4456 | |
| 4457 | if (!scratch.is(no_reg) && !is_int16(offset)) { |
| 4458 | /* cannot use d-form */ |
| 4459 | LoadIntLiteral(scratch, offset); |
| 4460 | #if V8_TARGET_ARCH_PPC64 |
| 4461 | stdx(src, MemOperand(mem.ra(), scratch)); |
| 4462 | #else |
| 4463 | stwx(src, MemOperand(mem.ra(), scratch)); |
| 4464 | #endif |
| 4465 | } else { |
| 4466 | #if V8_TARGET_ARCH_PPC64 |
| 4467 | int misaligned = (offset & 3); |
| 4468 | if (misaligned) { |
| 4469 | // adjust base to conform to offset alignment requirements |
| 4470 | // a suitable scratch is required here |
| 4471 | DCHECK(!scratch.is(no_reg)); |
| 4472 | if (scratch.is(r0)) { |
| 4473 | LoadIntLiteral(scratch, offset); |
| 4474 | stdx(src, MemOperand(mem.ra(), scratch)); |
| 4475 | } else { |
| 4476 | addi(scratch, mem.ra(), Operand((offset & 3) - 4)); |
| 4477 | std(src, MemOperand(scratch, (offset & ~3) + 4)); |
| 4478 | } |
| 4479 | } else { |
| 4480 | std(src, mem); |
| 4481 | } |
| 4482 | #else |
| 4483 | stw(src, mem); |
| 4484 | #endif |
| 4485 | } |
| 4486 | } |
| 4487 | |
| 4488 | void MacroAssembler::LoadWordArith(Register dst, const MemOperand& mem, |
| 4489 | Register scratch) { |
| 4490 | int offset = mem.offset(); |
| 4491 | |
| 4492 | if (!scratch.is(no_reg) && !is_int16(offset)) { |
| 4493 | /* cannot use d-form */ |
| 4494 | LoadIntLiteral(scratch, offset); |
| 4495 | #if V8_TARGET_ARCH_PPC64 |
| 4496 | // lwax(dst, MemOperand(mem.ra(), scratch)); |
| 4497 | DCHECK(0); // lwax not yet implemented |
| 4498 | #else |
| 4499 | lwzx(dst, MemOperand(mem.ra(), scratch)); |
| 4500 | #endif |
| 4501 | } else { |
| 4502 | #if V8_TARGET_ARCH_PPC64 |
| 4503 | int misaligned = (offset & 3); |
| 4504 | if (misaligned) { |
| 4505 | // adjust base to conform to offset alignment requirements |
| 4506 | // Todo: enhance to use scratch if dst is unsuitable |
| 4507 | DCHECK(!dst.is(r0)); |
| 4508 | addi(dst, mem.ra(), Operand((offset & 3) - 4)); |
| 4509 | lwa(dst, MemOperand(dst, (offset & ~3) + 4)); |
| 4510 | } else { |
| 4511 | lwa(dst, mem); |
| 4512 | } |
| 4513 | #else |
| 4514 | lwz(dst, mem); |
| 4515 | #endif |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | |
| 4520 | // Variable length depending on whether offset fits into immediate field |
| 4521 | // MemOperand currently only supports d-form |
| 4522 | void MacroAssembler::LoadWord(Register dst, const MemOperand& mem, |
| 4523 | Register scratch) { |
| 4524 | Register base = mem.ra(); |
| 4525 | int offset = mem.offset(); |
| 4526 | |
| 4527 | if (!is_int16(offset)) { |
| 4528 | LoadIntLiteral(scratch, offset); |
| 4529 | lwzx(dst, MemOperand(base, scratch)); |
| 4530 | } else { |
| 4531 | lwz(dst, mem); |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | |
| 4536 | // Variable length depending on whether offset fits into immediate field |
| 4537 | // MemOperand current only supports d-form |
| 4538 | void MacroAssembler::StoreWord(Register src, const MemOperand& mem, |
| 4539 | Register scratch) { |
| 4540 | Register base = mem.ra(); |
| 4541 | int offset = mem.offset(); |
| 4542 | |
| 4543 | if (!is_int16(offset)) { |
| 4544 | LoadIntLiteral(scratch, offset); |
| 4545 | stwx(src, MemOperand(base, scratch)); |
| 4546 | } else { |
| 4547 | stw(src, mem); |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | |
| 4552 | // Variable length depending on whether offset fits into immediate field |
| 4553 | // MemOperand currently only supports d-form |
| 4554 | void MacroAssembler::LoadHalfWord(Register dst, const MemOperand& mem, |
| 4555 | Register scratch) { |
| 4556 | Register base = mem.ra(); |
| 4557 | int offset = mem.offset(); |
| 4558 | |
| 4559 | if (!is_int16(offset)) { |
| 4560 | LoadIntLiteral(scratch, offset); |
| 4561 | lhzx(dst, MemOperand(base, scratch)); |
| 4562 | } else { |
| 4563 | lhz(dst, mem); |
| 4564 | } |
| 4565 | } |
| 4566 | |
| 4567 | |
| 4568 | // Variable length depending on whether offset fits into immediate field |
| 4569 | // MemOperand current only supports d-form |
| 4570 | void MacroAssembler::StoreHalfWord(Register src, const MemOperand& mem, |
| 4571 | Register scratch) { |
| 4572 | Register base = mem.ra(); |
| 4573 | int offset = mem.offset(); |
| 4574 | |
| 4575 | if (!is_int16(offset)) { |
| 4576 | LoadIntLiteral(scratch, offset); |
| 4577 | sthx(src, MemOperand(base, scratch)); |
| 4578 | } else { |
| 4579 | sth(src, mem); |
| 4580 | } |
| 4581 | } |
| 4582 | |
| 4583 | |
| 4584 | // Variable length depending on whether offset fits into immediate field |
| 4585 | // MemOperand currently only supports d-form |
| 4586 | void MacroAssembler::LoadByte(Register dst, const MemOperand& mem, |
| 4587 | Register scratch) { |
| 4588 | Register base = mem.ra(); |
| 4589 | int offset = mem.offset(); |
| 4590 | |
| 4591 | if (!is_int16(offset)) { |
| 4592 | LoadIntLiteral(scratch, offset); |
| 4593 | lbzx(dst, MemOperand(base, scratch)); |
| 4594 | } else { |
| 4595 | lbz(dst, mem); |
| 4596 | } |
| 4597 | } |
| 4598 | |
| 4599 | |
| 4600 | // Variable length depending on whether offset fits into immediate field |
| 4601 | // MemOperand current only supports d-form |
| 4602 | void MacroAssembler::StoreByte(Register src, const MemOperand& mem, |
| 4603 | Register scratch) { |
| 4604 | Register base = mem.ra(); |
| 4605 | int offset = mem.offset(); |
| 4606 | |
| 4607 | if (!is_int16(offset)) { |
| 4608 | LoadIntLiteral(scratch, offset); |
| 4609 | stbx(src, MemOperand(base, scratch)); |
| 4610 | } else { |
| 4611 | stb(src, mem); |
| 4612 | } |
| 4613 | } |
| 4614 | |
| 4615 | |
| 4616 | void MacroAssembler::LoadRepresentation(Register dst, const MemOperand& mem, |
| 4617 | Representation r, Register scratch) { |
| 4618 | DCHECK(!r.IsDouble()); |
| 4619 | if (r.IsInteger8()) { |
| 4620 | LoadByte(dst, mem, scratch); |
| 4621 | extsb(dst, dst); |
| 4622 | } else if (r.IsUInteger8()) { |
| 4623 | LoadByte(dst, mem, scratch); |
| 4624 | } else if (r.IsInteger16()) { |
| 4625 | LoadHalfWord(dst, mem, scratch); |
| 4626 | extsh(dst, dst); |
| 4627 | } else if (r.IsUInteger16()) { |
| 4628 | LoadHalfWord(dst, mem, scratch); |
| 4629 | #if V8_TARGET_ARCH_PPC64 |
| 4630 | } else if (r.IsInteger32()) { |
| 4631 | LoadWord(dst, mem, scratch); |
| 4632 | #endif |
| 4633 | } else { |
| 4634 | LoadP(dst, mem, scratch); |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | |
| 4639 | void MacroAssembler::StoreRepresentation(Register src, const MemOperand& mem, |
| 4640 | Representation r, Register scratch) { |
| 4641 | DCHECK(!r.IsDouble()); |
| 4642 | if (r.IsInteger8() || r.IsUInteger8()) { |
| 4643 | StoreByte(src, mem, scratch); |
| 4644 | } else if (r.IsInteger16() || r.IsUInteger16()) { |
| 4645 | StoreHalfWord(src, mem, scratch); |
| 4646 | #if V8_TARGET_ARCH_PPC64 |
| 4647 | } else if (r.IsInteger32()) { |
| 4648 | StoreWord(src, mem, scratch); |
| 4649 | #endif |
| 4650 | } else { |
| 4651 | if (r.IsHeapObject()) { |
| 4652 | AssertNotSmi(src); |
| 4653 | } else if (r.IsSmi()) { |
| 4654 | AssertSmi(src); |
| 4655 | } |
| 4656 | StoreP(src, mem, scratch); |
| 4657 | } |
| 4658 | } |
| 4659 | |
| 4660 | |
| 4661 | void MacroAssembler::TestJSArrayForAllocationMemento(Register receiver_reg, |
| 4662 | Register scratch_reg, |
| 4663 | Label* no_memento_found) { |
| 4664 | ExternalReference new_space_start = |
| 4665 | ExternalReference::new_space_start(isolate()); |
| 4666 | ExternalReference new_space_allocation_top = |
| 4667 | ExternalReference::new_space_allocation_top_address(isolate()); |
| 4668 | addi(scratch_reg, receiver_reg, |
| 4669 | Operand(JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag)); |
| 4670 | Cmpi(scratch_reg, Operand(new_space_start), r0); |
| 4671 | blt(no_memento_found); |
| 4672 | mov(ip, Operand(new_space_allocation_top)); |
| 4673 | LoadP(ip, MemOperand(ip)); |
| 4674 | cmp(scratch_reg, ip); |
| 4675 | bgt(no_memento_found); |
| 4676 | LoadP(scratch_reg, MemOperand(scratch_reg, -AllocationMemento::kSize)); |
| 4677 | Cmpi(scratch_reg, Operand(isolate()->factory()->allocation_memento_map()), |
| 4678 | r0); |
| 4679 | } |
| 4680 | |
| 4681 | |
| 4682 | Register GetRegisterThatIsNotOneOf(Register reg1, Register reg2, Register reg3, |
| 4683 | Register reg4, Register reg5, |
| 4684 | Register reg6) { |
| 4685 | RegList regs = 0; |
| 4686 | if (reg1.is_valid()) regs |= reg1.bit(); |
| 4687 | if (reg2.is_valid()) regs |= reg2.bit(); |
| 4688 | if (reg3.is_valid()) regs |= reg3.bit(); |
| 4689 | if (reg4.is_valid()) regs |= reg4.bit(); |
| 4690 | if (reg5.is_valid()) regs |= reg5.bit(); |
| 4691 | if (reg6.is_valid()) regs |= reg6.bit(); |
| 4692 | |
| 4693 | for (int i = 0; i < Register::NumAllocatableRegisters(); i++) { |
| 4694 | Register candidate = Register::FromAllocationIndex(i); |
| 4695 | if (regs & candidate.bit()) continue; |
| 4696 | return candidate; |
| 4697 | } |
| 4698 | UNREACHABLE(); |
| 4699 | return no_reg; |
| 4700 | } |
| 4701 | |
| 4702 | |
| 4703 | void MacroAssembler::JumpIfDictionaryInPrototypeChain(Register object, |
| 4704 | Register scratch0, |
| 4705 | Register scratch1, |
| 4706 | Label* found) { |
| 4707 | DCHECK(!scratch1.is(scratch0)); |
| 4708 | Factory* factory = isolate()->factory(); |
| 4709 | Register current = scratch0; |
| 4710 | Label loop_again; |
| 4711 | |
| 4712 | // scratch contained elements pointer. |
| 4713 | mr(current, object); |
| 4714 | |
| 4715 | // Loop based on the map going up the prototype chain. |
| 4716 | bind(&loop_again); |
| 4717 | LoadP(current, FieldMemOperand(current, HeapObject::kMapOffset)); |
| 4718 | lbz(scratch1, FieldMemOperand(current, Map::kBitField2Offset)); |
| 4719 | DecodeField<Map::ElementsKindBits>(scratch1); |
| 4720 | cmpi(scratch1, Operand(DICTIONARY_ELEMENTS)); |
| 4721 | beq(found); |
| 4722 | LoadP(current, FieldMemOperand(current, Map::kPrototypeOffset)); |
| 4723 | Cmpi(current, Operand(factory->null_value()), r0); |
| 4724 | bne(&loop_again); |
| 4725 | } |
| 4726 | |
| 4727 | |
| 4728 | #ifdef DEBUG |
| 4729 | bool AreAliased(Register reg1, Register reg2, Register reg3, Register reg4, |
| 4730 | Register reg5, Register reg6, Register reg7, Register reg8) { |
| 4731 | int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() + reg3.is_valid() + |
| 4732 | reg4.is_valid() + reg5.is_valid() + reg6.is_valid() + |
| 4733 | reg7.is_valid() + reg8.is_valid(); |
| 4734 | |
| 4735 | RegList regs = 0; |
| 4736 | if (reg1.is_valid()) regs |= reg1.bit(); |
| 4737 | if (reg2.is_valid()) regs |= reg2.bit(); |
| 4738 | if (reg3.is_valid()) regs |= reg3.bit(); |
| 4739 | if (reg4.is_valid()) regs |= reg4.bit(); |
| 4740 | if (reg5.is_valid()) regs |= reg5.bit(); |
| 4741 | if (reg6.is_valid()) regs |= reg6.bit(); |
| 4742 | if (reg7.is_valid()) regs |= reg7.bit(); |
| 4743 | if (reg8.is_valid()) regs |= reg8.bit(); |
| 4744 | int n_of_non_aliasing_regs = NumRegs(regs); |
| 4745 | |
| 4746 | return n_of_valid_regs != n_of_non_aliasing_regs; |
| 4747 | } |
| 4748 | #endif |
| 4749 | |
| 4750 | |
| 4751 | CodePatcher::CodePatcher(byte* address, int instructions, |
| 4752 | FlushICache flush_cache) |
| 4753 | : address_(address), |
| 4754 | size_(instructions * Assembler::kInstrSize), |
| 4755 | masm_(NULL, address, size_ + Assembler::kGap), |
| 4756 | flush_cache_(flush_cache) { |
| 4757 | // Create a new macro assembler pointing to the address of the code to patch. |
| 4758 | // The size is adjusted with kGap on order for the assembler to generate size |
| 4759 | // bytes of instructions without failing with buffer size constraints. |
| 4760 | DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 4761 | } |
| 4762 | |
| 4763 | |
| 4764 | CodePatcher::~CodePatcher() { |
| 4765 | // Indicate that code has changed. |
| 4766 | if (flush_cache_ == FLUSH) { |
| 4767 | CpuFeatures::FlushICache(address_, size_); |
| 4768 | } |
| 4769 | |
| 4770 | // Check that the code was patched as expected. |
| 4771 | DCHECK(masm_.pc_ == address_ + size_); |
| 4772 | DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 4773 | } |
| 4774 | |
| 4775 | |
| 4776 | void CodePatcher::Emit(Instr instr) { masm()->emit(instr); } |
| 4777 | |
| 4778 | |
| 4779 | void CodePatcher::EmitCondition(Condition cond) { |
| 4780 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 4781 | switch (cond) { |
| 4782 | case eq: |
| 4783 | instr = (instr & ~kCondMask) | BT; |
| 4784 | break; |
| 4785 | case ne: |
| 4786 | instr = (instr & ~kCondMask) | BF; |
| 4787 | break; |
| 4788 | default: |
| 4789 | UNIMPLEMENTED(); |
| 4790 | } |
| 4791 | masm_.emit(instr); |
| 4792 | } |
| 4793 | |
| 4794 | |
| 4795 | void MacroAssembler::TruncatingDiv(Register result, Register dividend, |
| 4796 | int32_t divisor) { |
| 4797 | DCHECK(!dividend.is(result)); |
| 4798 | DCHECK(!dividend.is(r0)); |
| 4799 | DCHECK(!result.is(r0)); |
| 4800 | base::MagicNumbersForDivision<uint32_t> mag = |
| 4801 | base::SignedDivisionByConstant(static_cast<uint32_t>(divisor)); |
| 4802 | mov(r0, Operand(mag.multiplier)); |
| 4803 | mulhw(result, dividend, r0); |
| 4804 | bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0; |
| 4805 | if (divisor > 0 && neg) { |
| 4806 | add(result, result, dividend); |
| 4807 | } |
| 4808 | if (divisor < 0 && !neg && mag.multiplier > 0) { |
| 4809 | sub(result, result, dividend); |
| 4810 | } |
| 4811 | if (mag.shift > 0) srawi(result, result, mag.shift); |
| 4812 | ExtractBit(r0, dividend, 31); |
| 4813 | add(result, result, r0); |
| 4814 | } |
| 4815 | |
| 4816 | } // namespace internal |
| 4817 | } // namespace v8 |
| 4818 | |
| 4819 | #endif // V8_TARGET_ARCH_PPC |