Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/arm/assembler-arm.cc

Issue 574009: Fixed random style violations. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm/assembler-arm.h ('k') | src/arm/assembler-thumb2.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. 1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved. 2 // All Rights Reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions 5 // modification, are permitted provided that the following conditions
6 // are met: 6 // are met:
7 // 7 //
8 // - Redistributions of source code must retain the above copyright notice, 8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer. 9 // this list of conditions and the following disclaimer.
10 // 10 //
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 ASSERT(is_uint5(shift_imm)); 257 ASSERT(is_uint5(shift_imm));
258 rn_ = rn; 258 rn_ = rn;
259 rm_ = rm; 259 rm_ = rm;
260 shift_op_ = shift_op; 260 shift_op_ = shift_op;
261 shift_imm_ = shift_imm & 31; 261 shift_imm_ = shift_imm & 31;
262 am_ = am; 262 am_ = am;
263 } 263 }
264 264
265 265
266 // ----------------------------------------------------------------------------- 266 // -----------------------------------------------------------------------------
267 // Implementation of Assembler 267 // Implementation of Assembler.
268 268
269 // Instruction encoding bits 269 // Instruction encoding bits.
270 enum { 270 enum {
271 H = 1 << 5, // halfword (or byte) 271 H = 1 << 5, // halfword (or byte)
272 S6 = 1 << 6, // signed (or unsigned) 272 S6 = 1 << 6, // signed (or unsigned)
273 L = 1 << 20, // load (or store) 273 L = 1 << 20, // load (or store)
274 S = 1 << 20, // set condition code (or leave unchanged) 274 S = 1 << 20, // set condition code (or leave unchanged)
275 W = 1 << 21, // writeback base register (or leave unchanged) 275 W = 1 << 21, // writeback base register (or leave unchanged)
276 A = 1 << 21, // accumulate in multiply instruction (or not) 276 A = 1 << 21, // accumulate in multiply instruction (or not)
277 B = 1 << 22, // unsigned byte (or word) 277 B = 1 << 22, // unsigned byte (or word)
278 N = 1 << 22, // long (or short) 278 N = 1 << 22, // long (or short)
279 U = 1 << 23, // positive (or negative) offset/index 279 U = 1 << 23, // positive (or negative) offset/index
(...skipping 12 matching lines...) Expand all
292 B19 = 1 << 19, 292 B19 = 1 << 19,
293 B20 = 1 << 20, 293 B20 = 1 << 20,
294 B21 = 1 << 21, 294 B21 = 1 << 21,
295 B22 = 1 << 22, 295 B22 = 1 << 22,
296 B23 = 1 << 23, 296 B23 = 1 << 23,
297 B24 = 1 << 24, 297 B24 = 1 << 24,
298 B25 = 1 << 25, 298 B25 = 1 << 25,
299 B26 = 1 << 26, 299 B26 = 1 << 26,
300 B27 = 1 << 27, 300 B27 = 1 << 27,
301 301
302 // Instruction bit masks 302 // Instruction bit masks.
303 RdMask = 15 << 12, // in str instruction 303 RdMask = 15 << 12, // in str instruction
304 CondMask = 15 << 28, 304 CondMask = 15 << 28,
305 CoprocessorMask = 15 << 8, 305 CoprocessorMask = 15 << 8,
306 OpCodeMask = 15 << 21, // in data-processing instructions 306 OpCodeMask = 15 << 21, // in data-processing instructions
307 Imm24Mask = (1 << 24) - 1, 307 Imm24Mask = (1 << 24) - 1,
308 Off12Mask = (1 << 12) - 1, 308 Off12Mask = (1 << 12) - 1,
309 // Reserved condition 309 // Reserved condition.
310 nv = 15 << 28 310 nv = 15 << 28
311 }; 311 };
312 312
313 313
314 // add(sp, sp, 4) instruction (aka Pop()) 314 // add(sp, sp, 4) instruction (aka Pop())
315 static const Instr kPopInstruction = 315 static const Instr kPopInstruction =
316 al | 4 * B21 | 4 | LeaveCC | I | sp.code() * B16 | sp.code() * B12; 316 al | 4 * B21 | 4 | LeaveCC | I | sp.code() * B16 | sp.code() * B12;
317 // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r)) 317 // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r))
318 // register r is not encoded. 318 // register r is not encoded.
319 static const Instr kPushRegPattern = 319 static const Instr kPushRegPattern =
320 al | B26 | 4 | NegPreIndex | sp.code() * B16; 320 al | B26 | 4 | NegPreIndex | sp.code() * B16;
321 // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r)) 321 // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r))
322 // register r is not encoded. 322 // register r is not encoded.
323 static const Instr kPopRegPattern = 323 static const Instr kPopRegPattern =
324 al | B26 | L | 4 | PostIndex | sp.code() * B16; 324 al | B26 | L | 4 | PostIndex | sp.code() * B16;
325 // mov lr, pc 325 // mov lr, pc
326 const Instr kMovLrPc = al | 13*B21 | pc.code() | lr.code() * B12; 326 const Instr kMovLrPc = al | 13*B21 | pc.code() | lr.code() * B12;
327 // ldr pc, [pc, #XXX] 327 // ldr pc, [pc, #XXX]
328 const Instr kLdrPCPattern = al | B26 | L | pc.code() * B16; 328 const Instr kLdrPCPattern = al | B26 | L | pc.code() * B16;
329 329
330 // spare_buffer_ 330 // Spare buffer.
331 static const int kMinimalBufferSize = 4*KB; 331 static const int kMinimalBufferSize = 4*KB;
332 static byte* spare_buffer_ = NULL; 332 static byte* spare_buffer_ = NULL;
333 333
334 Assembler::Assembler(void* buffer, int buffer_size) { 334 Assembler::Assembler(void* buffer, int buffer_size) {
335 if (buffer == NULL) { 335 if (buffer == NULL) {
336 // do our own buffer management 336 // Do our own buffer management.
337 if (buffer_size <= kMinimalBufferSize) { 337 if (buffer_size <= kMinimalBufferSize) {
338 buffer_size = kMinimalBufferSize; 338 buffer_size = kMinimalBufferSize;
339 339
340 if (spare_buffer_ != NULL) { 340 if (spare_buffer_ != NULL) {
341 buffer = spare_buffer_; 341 buffer = spare_buffer_;
342 spare_buffer_ = NULL; 342 spare_buffer_ = NULL;
343 } 343 }
344 } 344 }
345 if (buffer == NULL) { 345 if (buffer == NULL) {
346 buffer_ = NewArray<byte>(buffer_size); 346 buffer_ = NewArray<byte>(buffer_size);
347 } else { 347 } else {
348 buffer_ = static_cast<byte*>(buffer); 348 buffer_ = static_cast<byte*>(buffer);
349 } 349 }
350 buffer_size_ = buffer_size; 350 buffer_size_ = buffer_size;
351 own_buffer_ = true; 351 own_buffer_ = true;
352 352
353 } else { 353 } else {
354 // use externally provided buffer instead 354 // Use externally provided buffer instead.
355 ASSERT(buffer_size > 0); 355 ASSERT(buffer_size > 0);
356 buffer_ = static_cast<byte*>(buffer); 356 buffer_ = static_cast<byte*>(buffer);
357 buffer_size_ = buffer_size; 357 buffer_size_ = buffer_size;
358 own_buffer_ = false; 358 own_buffer_ = false;
359 } 359 }
360 360
361 // setup buffer pointers 361 // Setup buffer pointers.
362 ASSERT(buffer_ != NULL); 362 ASSERT(buffer_ != NULL);
363 pc_ = buffer_; 363 pc_ = buffer_;
364 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); 364 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_);
365 num_prinfo_ = 0; 365 num_prinfo_ = 0;
366 next_buffer_check_ = 0; 366 next_buffer_check_ = 0;
367 no_const_pool_before_ = 0; 367 no_const_pool_before_ = 0;
368 last_const_pool_end_ = 0; 368 last_const_pool_end_ = 0;
369 last_bound_pos_ = 0; 369 last_bound_pos_ = 0;
370 current_statement_position_ = RelocInfo::kNoPosition; 370 current_statement_position_ = RelocInfo::kNoPosition;
371 current_position_ = RelocInfo::kNoPosition; 371 current_position_ = RelocInfo::kNoPosition;
372 written_statement_position_ = current_statement_position_; 372 written_statement_position_ = current_statement_position_;
373 written_position_ = current_position_; 373 written_position_ = current_position_;
374 } 374 }
375 375
376 376
377 Assembler::~Assembler() { 377 Assembler::~Assembler() {
378 if (own_buffer_) { 378 if (own_buffer_) {
379 if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) { 379 if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) {
380 spare_buffer_ = buffer_; 380 spare_buffer_ = buffer_;
381 } else { 381 } else {
382 DeleteArray(buffer_); 382 DeleteArray(buffer_);
383 } 383 }
384 } 384 }
385 } 385 }
386 386
387 387
388 void Assembler::GetCode(CodeDesc* desc) { 388 void Assembler::GetCode(CodeDesc* desc) {
389 // emit constant pool if necessary 389 // Emit constant pool if necessary.
390 CheckConstPool(true, false); 390 CheckConstPool(true, false);
391 ASSERT(num_prinfo_ == 0); 391 ASSERT(num_prinfo_ == 0);
392 392
393 // setup desc 393 // Setup code descriptor.
394 desc->buffer = buffer_; 394 desc->buffer = buffer_;
395 desc->buffer_size = buffer_size_; 395 desc->buffer_size = buffer_size_;
396 desc->instr_size = pc_offset(); 396 desc->instr_size = pc_offset();
397 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); 397 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
398 } 398 }
399 399
400 400
401 void Assembler::Align(int m) { 401 void Assembler::Align(int m) {
402 ASSERT(m >= 4 && IsPowerOf2(m)); 402 ASSERT(m >= 4 && IsPowerOf2(m));
403 while ((pc_offset() & (m - 1)) != 0) { 403 while ((pc_offset() & (m - 1)) != 0) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // Keep track of the last bound label so we don't eliminate any instructions 532 // Keep track of the last bound label so we don't eliminate any instructions
533 // before a bound label. 533 // before a bound label.
534 if (pos > last_bound_pos_) 534 if (pos > last_bound_pos_)
535 last_bound_pos_ = pos; 535 last_bound_pos_ = pos;
536 } 536 }
537 537
538 538
539 void Assembler::link_to(Label* L, Label* appendix) { 539 void Assembler::link_to(Label* L, Label* appendix) {
540 if (appendix->is_linked()) { 540 if (appendix->is_linked()) {
541 if (L->is_linked()) { 541 if (L->is_linked()) {
542 // append appendix to L's list 542 // Append appendix to L's list.
543 int fixup_pos; 543 int fixup_pos;
544 int link = L->pos(); 544 int link = L->pos();
545 do { 545 do {
546 fixup_pos = link; 546 fixup_pos = link;
547 link = target_at(fixup_pos); 547 link = target_at(fixup_pos);
548 } while (link > 0); 548 } while (link > 0);
549 ASSERT(link == kEndOfChain); 549 ASSERT(link == kEndOfChain);
550 target_at_put(fixup_pos, appendix->pos()); 550 target_at_put(fixup_pos, appendix->pos());
551 } else { 551 } else {
552 // L is empty, simply use appendix 552 // L is empty, simply use appendix.
553 *L = *appendix; 553 *L = *appendix;
554 } 554 }
555 } 555 }
556 appendix->Unuse(); // appendix should not be used anymore 556 appendix->Unuse(); // appendix should not be used anymore
557 } 557 }
558 558
559 559
560 void Assembler::bind(Label* L) { 560 void Assembler::bind(Label* L) {
561 ASSERT(!L->is_bound()); // label can only be bound once 561 ASSERT(!L->is_bound()); // label can only be bound once
562 bind_to(L, pc_offset()); 562 bind_to(L, pc_offset());
563 } 563 }
564 564
565 565
566 void Assembler::next(Label* L) { 566 void Assembler::next(Label* L) {
567 ASSERT(L->is_linked()); 567 ASSERT(L->is_linked());
568 int link = target_at(L->pos()); 568 int link = target_at(L->pos());
569 if (link > 0) { 569 if (link > 0) {
570 L->link_to(link); 570 L->link_to(link);
571 } else { 571 } else {
572 ASSERT(link == kEndOfChain); 572 ASSERT(link == kEndOfChain);
573 L->Unuse(); 573 L->Unuse();
574 } 574 }
575 } 575 }
576 576
577 577
578 // Low-level code emission routines depending on the addressing mode 578 // Low-level code emission routines depending on the addressing mode.
579 static bool fits_shifter(uint32_t imm32, 579 static bool fits_shifter(uint32_t imm32,
580 uint32_t* rotate_imm, 580 uint32_t* rotate_imm,
581 uint32_t* immed_8, 581 uint32_t* immed_8,
582 Instr* instr) { 582 Instr* instr) {
583 // imm32 must be unsigned 583 // imm32 must be unsigned.
584 for (int rot = 0; rot < 16; rot++) { 584 for (int rot = 0; rot < 16; rot++) {
585 uint32_t imm8 = (imm32 << 2*rot) | (imm32 >> (32 - 2*rot)); 585 uint32_t imm8 = (imm32 << 2*rot) | (imm32 >> (32 - 2*rot));
586 if ((imm8 <= 0xff)) { 586 if ((imm8 <= 0xff)) {
587 *rotate_imm = rot; 587 *rotate_imm = rot;
588 *immed_8 = imm8; 588 *immed_8 = imm8;
589 return true; 589 return true;
590 } 590 }
591 } 591 }
592 // if the opcode is mov or mvn and if ~imm32 fits, change the opcode 592 // If the opcode is mov or mvn and if ~imm32 fits, change the opcode.
593 if (instr != NULL && (*instr & 0xd*B21) == 0xd*B21) { 593 if (instr != NULL && (*instr & 0xd*B21) == 0xd*B21) {
594 if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) { 594 if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) {
595 *instr ^= 0x2*B21; 595 *instr ^= 0x2*B21;
596 return true; 596 return true;
597 } 597 }
598 } 598 }
599 return false; 599 return false;
600 } 600 }
601 601
602 602
(...skipping 16 matching lines...) Expand all
619 } 619 }
620 620
621 621
622 void Assembler::addrmod1(Instr instr, 622 void Assembler::addrmod1(Instr instr,
623 Register rn, 623 Register rn,
624 Register rd, 624 Register rd,
625 const Operand& x) { 625 const Operand& x) {
626 CheckBuffer(); 626 CheckBuffer();
627 ASSERT((instr & ~(CondMask | OpCodeMask | S)) == 0); 627 ASSERT((instr & ~(CondMask | OpCodeMask | S)) == 0);
628 if (!x.rm_.is_valid()) { 628 if (!x.rm_.is_valid()) {
629 // immediate 629 // Immediate.
630 uint32_t rotate_imm; 630 uint32_t rotate_imm;
631 uint32_t immed_8; 631 uint32_t immed_8;
632 if (MustUseIp(x.rmode_) || 632 if (MustUseIp(x.rmode_) ||
633 !fits_shifter(x.imm32_, &rotate_imm, &immed_8, &instr)) { 633 !fits_shifter(x.imm32_, &rotate_imm, &immed_8, &instr)) {
634 // The immediate operand cannot be encoded as a shifter operand, so load 634 // The immediate operand cannot be encoded as a shifter operand, so load
635 // it first to register ip and change the original instruction to use ip. 635 // it first to register ip and change the original instruction to use ip.
636 // However, if the original instruction is a 'mov rd, x' (not setting the 636 // However, if the original instruction is a 'mov rd, x' (not setting the
637 // condition code), then replace it with a 'ldr rd, [pc]' 637 // condition code), then replace it with a 'ldr rd, [pc]'.
638 RecordRelocInfo(x.rmode_, x.imm32_); 638 RecordRelocInfo(x.rmode_, x.imm32_);
639 CHECK(!rn.is(ip)); // rn should never be ip, or will be trashed 639 CHECK(!rn.is(ip)); // rn should never be ip, or will be trashed
640 Condition cond = static_cast<Condition>(instr & CondMask); 640 Condition cond = static_cast<Condition>(instr & CondMask);
641 if ((instr & ~CondMask) == 13*B21) { // mov, S not set 641 if ((instr & ~CondMask) == 13*B21) { // mov, S not set
642 ldr(rd, MemOperand(pc, 0), cond); 642 ldr(rd, MemOperand(pc, 0), cond);
643 } else { 643 } else {
644 ldr(ip, MemOperand(pc, 0), cond); 644 ldr(ip, MemOperand(pc, 0), cond);
645 addrmod1(instr, rn, rd, Operand(ip)); 645 addrmod1(instr, rn, rd, Operand(ip));
646 } 646 }
647 return; 647 return;
648 } 648 }
649 instr |= I | rotate_imm*B8 | immed_8; 649 instr |= I | rotate_imm*B8 | immed_8;
650 } else if (!x.rs_.is_valid()) { 650 } else if (!x.rs_.is_valid()) {
651 // immediate shift 651 // Immediate shift.
652 instr |= x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); 652 instr |= x.shift_imm_*B7 | x.shift_op_ | x.rm_.code();
653 } else { 653 } else {
654 // register shift 654 // Register shift.
655 ASSERT(!rn.is(pc) && !rd.is(pc) && !x.rm_.is(pc) && !x.rs_.is(pc)); 655 ASSERT(!rn.is(pc) && !rd.is(pc) && !x.rm_.is(pc) && !x.rs_.is(pc));
656 instr |= x.rs_.code()*B8 | x.shift_op_ | B4 | x.rm_.code(); 656 instr |= x.rs_.code()*B8 | x.shift_op_ | B4 | x.rm_.code();
657 } 657 }
658 emit(instr | rn.code()*B16 | rd.code()*B12); 658 emit(instr | rn.code()*B16 | rd.code()*B12);
659 if (rn.is(pc) || x.rm_.is(pc)) 659 if (rn.is(pc) || x.rm_.is(pc))
660 // block constant pool emission for one instruction after reading pc 660 // Block constant pool emission for one instruction after reading pc.
661 BlockConstPoolBefore(pc_offset() + kInstrSize); 661 BlockConstPoolBefore(pc_offset() + kInstrSize);
662 } 662 }
663 663
664 664
665 void Assembler::addrmod2(Instr instr, Register rd, const MemOperand& x) { 665 void Assembler::addrmod2(Instr instr, Register rd, const MemOperand& x) {
666 ASSERT((instr & ~(CondMask | B | L)) == B26); 666 ASSERT((instr & ~(CondMask | B | L)) == B26);
667 int am = x.am_; 667 int am = x.am_;
668 if (!x.rm_.is_valid()) { 668 if (!x.rm_.is_valid()) {
669 // immediate offset 669 // Immediate offset.
670 int offset_12 = x.offset_; 670 int offset_12 = x.offset_;
671 if (offset_12 < 0) { 671 if (offset_12 < 0) {
672 offset_12 = -offset_12; 672 offset_12 = -offset_12;
673 am ^= U; 673 am ^= U;
674 } 674 }
675 if (!is_uint12(offset_12)) { 675 if (!is_uint12(offset_12)) {
676 // immediate offset cannot be encoded, load it first to register ip 676 // Immediate offset cannot be encoded, load it first to register ip
677 // rn (and rd in a load) should never be ip, or will be trashed 677 // rn (and rd in a load) should never be ip, or will be trashed.
678 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); 678 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip)));
679 mov(ip, Operand(x.offset_), LeaveCC, 679 mov(ip, Operand(x.offset_), LeaveCC,
680 static_cast<Condition>(instr & CondMask)); 680 static_cast<Condition>(instr & CondMask));
681 addrmod2(instr, rd, MemOperand(x.rn_, ip, x.am_)); 681 addrmod2(instr, rd, MemOperand(x.rn_, ip, x.am_));
682 return; 682 return;
683 } 683 }
684 ASSERT(offset_12 >= 0); // no masking needed 684 ASSERT(offset_12 >= 0); // no masking needed
685 instr |= offset_12; 685 instr |= offset_12;
686 } else { 686 } else {
687 // register offset (shift_imm_ and shift_op_ are 0) or scaled 687 // Register offset (shift_imm_ and shift_op_ are 0) or scaled
688 // register offset the constructors make sure than both shift_imm_ 688 // register offset the constructors make sure than both shift_imm_
689 // and shift_op_ are initialized 689 // and shift_op_ are initialized.
690 ASSERT(!x.rm_.is(pc)); 690 ASSERT(!x.rm_.is(pc));
691 instr |= B25 | x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); 691 instr |= B25 | x.shift_imm_*B7 | x.shift_op_ | x.rm_.code();
692 } 692 }
693 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback 693 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback
694 emit(instr | am | x.rn_.code()*B16 | rd.code()*B12); 694 emit(instr | am | x.rn_.code()*B16 | rd.code()*B12);
695 } 695 }
696 696
697 697
698 void Assembler::addrmod3(Instr instr, Register rd, const MemOperand& x) { 698 void Assembler::addrmod3(Instr instr, Register rd, const MemOperand& x) {
699 ASSERT((instr & ~(CondMask | L | S6 | H)) == (B4 | B7)); 699 ASSERT((instr & ~(CondMask | L | S6 | H)) == (B4 | B7));
700 ASSERT(x.rn_.is_valid()); 700 ASSERT(x.rn_.is_valid());
701 int am = x.am_; 701 int am = x.am_;
702 if (!x.rm_.is_valid()) { 702 if (!x.rm_.is_valid()) {
703 // immediate offset 703 // Immediate offset.
704 int offset_8 = x.offset_; 704 int offset_8 = x.offset_;
705 if (offset_8 < 0) { 705 if (offset_8 < 0) {
706 offset_8 = -offset_8; 706 offset_8 = -offset_8;
707 am ^= U; 707 am ^= U;
708 } 708 }
709 if (!is_uint8(offset_8)) { 709 if (!is_uint8(offset_8)) {
710 // immediate offset cannot be encoded, load it first to register ip 710 // Immediate offset cannot be encoded, load it first to register ip
711 // rn (and rd in a load) should never be ip, or will be trashed 711 // rn (and rd in a load) should never be ip, or will be trashed.
712 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); 712 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip)));
713 mov(ip, Operand(x.offset_), LeaveCC, 713 mov(ip, Operand(x.offset_), LeaveCC,
714 static_cast<Condition>(instr & CondMask)); 714 static_cast<Condition>(instr & CondMask));
715 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); 715 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_));
716 return; 716 return;
717 } 717 }
718 ASSERT(offset_8 >= 0); // no masking needed 718 ASSERT(offset_8 >= 0); // no masking needed
719 instr |= B | (offset_8 >> 4)*B8 | (offset_8 & 0xf); 719 instr |= B | (offset_8 >> 4)*B8 | (offset_8 & 0xf);
720 } else if (x.shift_imm_ != 0) { 720 } else if (x.shift_imm_ != 0) {
721 // scaled register offset not supported, load index first 721 // Scaled register offset not supported, load index first
722 // rn (and rd in a load) should never be ip, or will be trashed 722 // rn (and rd in a load) should never be ip, or will be trashed.
723 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); 723 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip)));
724 mov(ip, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC, 724 mov(ip, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC,
725 static_cast<Condition>(instr & CondMask)); 725 static_cast<Condition>(instr & CondMask));
726 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); 726 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_));
727 return; 727 return;
728 } else { 728 } else {
729 // register offset 729 // Register offset.
730 ASSERT((am & (P|W)) == P || !x.rm_.is(pc)); // no pc index with writeback 730 ASSERT((am & (P|W)) == P || !x.rm_.is(pc)); // no pc index with writeback
731 instr |= x.rm_.code(); 731 instr |= x.rm_.code();
732 } 732 }
733 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback 733 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback
734 emit(instr | am | x.rn_.code()*B16 | rd.code()*B12); 734 emit(instr | am | x.rn_.code()*B16 | rd.code()*B12);
735 } 735 }
736 736
737 737
738 void Assembler::addrmod4(Instr instr, Register rn, RegList rl) { 738 void Assembler::addrmod4(Instr instr, Register rn, RegList rl) {
739 ASSERT((instr & ~(CondMask | P | U | W | L)) == B27); 739 ASSERT((instr & ~(CondMask | P | U | W | L)) == B27);
740 ASSERT(rl != 0); 740 ASSERT(rl != 0);
741 ASSERT(!rn.is(pc)); 741 ASSERT(!rn.is(pc));
742 emit(instr | rn.code()*B16 | rl); 742 emit(instr | rn.code()*B16 | rl);
743 } 743 }
744 744
745 745
746 void Assembler::addrmod5(Instr instr, CRegister crd, const MemOperand& x) { 746 void Assembler::addrmod5(Instr instr, CRegister crd, const MemOperand& x) {
747 // unindexed addressing is not encoded by this function 747 // Unindexed addressing is not encoded by this function.
748 ASSERT_EQ((B27 | B26), 748 ASSERT_EQ((B27 | B26),
749 (instr & ~(CondMask | CoprocessorMask | P | U | N | W | L))); 749 (instr & ~(CondMask | CoprocessorMask | P | U | N | W | L)));
750 ASSERT(x.rn_.is_valid() && !x.rm_.is_valid()); 750 ASSERT(x.rn_.is_valid() && !x.rm_.is_valid());
751 int am = x.am_; 751 int am = x.am_;
752 int offset_8 = x.offset_; 752 int offset_8 = x.offset_;
753 ASSERT((offset_8 & 3) == 0); // offset must be an aligned word offset 753 ASSERT((offset_8 & 3) == 0); // offset must be an aligned word offset
754 offset_8 >>= 2; 754 offset_8 >>= 2;
755 if (offset_8 < 0) { 755 if (offset_8 < 0) {
756 offset_8 = -offset_8; 756 offset_8 = -offset_8;
757 am ^= U; 757 am ^= U;
758 } 758 }
759 ASSERT(is_uint8(offset_8)); // unsigned word offset must fit in a byte 759 ASSERT(is_uint8(offset_8)); // unsigned word offset must fit in a byte
760 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback 760 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback
761 761
762 // post-indexed addressing requires W == 1; different than in addrmod2/3 762 // Post-indexed addressing requires W == 1; different than in addrmod2/3.
763 if ((am & P) == 0) 763 if ((am & P) == 0)
764 am |= W; 764 am |= W;
765 765
766 ASSERT(offset_8 >= 0); // no masking needed 766 ASSERT(offset_8 >= 0); // no masking needed
767 emit(instr | am | x.rn_.code()*B16 | crd.code()*B12 | offset_8); 767 emit(instr | am | x.rn_.code()*B16 | crd.code()*B12 | offset_8);
768 } 768 }
769 769
770 770
771 int Assembler::branch_offset(Label* L, bool jump_elimination_allowed) { 771 int Assembler::branch_offset(Label* L, bool jump_elimination_allowed) {
772 int target_pos; 772 int target_pos;
773 if (L->is_bound()) { 773 if (L->is_bound()) {
774 target_pos = L->pos(); 774 target_pos = L->pos();
775 } else { 775 } else {
776 if (L->is_linked()) { 776 if (L->is_linked()) {
777 target_pos = L->pos(); // L's link 777 target_pos = L->pos(); // L's link
778 } else { 778 } else {
779 target_pos = kEndOfChain; 779 target_pos = kEndOfChain;
780 } 780 }
781 L->link_to(pc_offset()); 781 L->link_to(pc_offset());
782 } 782 }
783 783
784 // Block the emission of the constant pool, since the branch instruction must 784 // Block the emission of the constant pool, since the branch instruction must
785 // be emitted at the pc offset recorded by the label 785 // be emitted at the pc offset recorded by the label.
786 BlockConstPoolBefore(pc_offset() + kInstrSize); 786 BlockConstPoolBefore(pc_offset() + kInstrSize);
787 return target_pos - (pc_offset() + kPcLoadDelta); 787 return target_pos - (pc_offset() + kPcLoadDelta);
788 } 788 }
789 789
790 790
791 void Assembler::label_at_put(Label* L, int at_offset) { 791 void Assembler::label_at_put(Label* L, int at_offset) {
792 int target_pos; 792 int target_pos;
793 if (L->is_bound()) { 793 if (L->is_bound()) {
794 target_pos = L->pos(); 794 target_pos = L->pos();
795 } else { 795 } else {
796 if (L->is_linked()) { 796 if (L->is_linked()) {
797 target_pos = L->pos(); // L's link 797 target_pos = L->pos(); // L's link
798 } else { 798 } else {
799 target_pos = kEndOfChain; 799 target_pos = kEndOfChain;
800 } 800 }
801 L->link_to(at_offset); 801 L->link_to(at_offset);
802 instr_at_put(at_offset, target_pos + (Code::kHeaderSize - kHeapObjectTag)); 802 instr_at_put(at_offset, target_pos + (Code::kHeaderSize - kHeapObjectTag));
803 } 803 }
804 } 804 }
805 805
806 806
807 // Branch instructions 807 // Branch instructions.
808 void Assembler::b(int branch_offset, Condition cond) { 808 void Assembler::b(int branch_offset, Condition cond) {
809 ASSERT((branch_offset & 3) == 0); 809 ASSERT((branch_offset & 3) == 0);
810 int imm24 = branch_offset >> 2; 810 int imm24 = branch_offset >> 2;
811 ASSERT(is_int24(imm24)); 811 ASSERT(is_int24(imm24));
812 emit(cond | B27 | B25 | (imm24 & Imm24Mask)); 812 emit(cond | B27 | B25 | (imm24 & Imm24Mask));
813 813
814 if (cond == al) 814 if (cond == al)
815 // dead code is a good location to emit the constant pool 815 // Dead code is a good location to emit the constant pool.
816 CheckConstPool(false, false); 816 CheckConstPool(false, false);
817 } 817 }
818 818
819 819
820 void Assembler::bl(int branch_offset, Condition cond) { 820 void Assembler::bl(int branch_offset, Condition cond) {
821 ASSERT((branch_offset & 3) == 0); 821 ASSERT((branch_offset & 3) == 0);
822 int imm24 = branch_offset >> 2; 822 int imm24 = branch_offset >> 2;
823 ASSERT(is_int24(imm24)); 823 ASSERT(is_int24(imm24));
824 emit(cond | B27 | B25 | B24 | (imm24 & Imm24Mask)); 824 emit(cond | B27 | B25 | B24 | (imm24 & Imm24Mask));
825 } 825 }
(...skipping 16 matching lines...) Expand all
842 } 842 }
843 843
844 844
845 void Assembler::bx(Register target, Condition cond) { // v5 and above, plus v4t 845 void Assembler::bx(Register target, Condition cond) { // v5 and above, plus v4t
846 WriteRecordedPositions(); 846 WriteRecordedPositions();
847 ASSERT(!target.is(pc)); // use of pc is actually allowed, but discouraged 847 ASSERT(!target.is(pc)); // use of pc is actually allowed, but discouraged
848 emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | B4 | target.code()); 848 emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | B4 | target.code());
849 } 849 }
850 850
851 851
852 // Data-processing instructions 852 // Data-processing instructions.
853 void Assembler::and_(Register dst, Register src1, const Operand& src2, 853 void Assembler::and_(Register dst, Register src1, const Operand& src2,
854 SBit s, Condition cond) { 854 SBit s, Condition cond) {
855 addrmod1(cond | 0*B21 | s, src1, dst, src2); 855 addrmod1(cond | 0*B21 | s, src1, dst, src2);
856 } 856 }
857 857
858 858
859 void Assembler::eor(Register dst, Register src1, const Operand& src2, 859 void Assembler::eor(Register dst, Register src1, const Operand& src2,
860 SBit s, Condition cond) { 860 SBit s, Condition cond) {
861 addrmod1(cond | 1*B21 | s, src1, dst, src2); 861 addrmod1(cond | 1*B21 | s, src1, dst, src2);
862 } 862 }
(...skipping 16 matching lines...) Expand all
879 addrmod1(cond | 4*B21 | s, src1, dst, src2); 879 addrmod1(cond | 4*B21 | s, src1, dst, src2);
880 880
881 // Eliminate pattern: push(r), pop() 881 // Eliminate pattern: push(r), pop()
882 // str(src, MemOperand(sp, 4, NegPreIndex), al); 882 // str(src, MemOperand(sp, 4, NegPreIndex), al);
883 // add(sp, sp, Operand(kPointerSize)); 883 // add(sp, sp, Operand(kPointerSize));
884 // Both instructions can be eliminated. 884 // Both instructions can be eliminated.
885 int pattern_size = 2 * kInstrSize; 885 int pattern_size = 2 * kInstrSize;
886 if (FLAG_push_pop_elimination && 886 if (FLAG_push_pop_elimination &&
887 last_bound_pos_ <= (pc_offset() - pattern_size) && 887 last_bound_pos_ <= (pc_offset() - pattern_size) &&
888 reloc_info_writer.last_pc() <= (pc_ - pattern_size) && 888 reloc_info_writer.last_pc() <= (pc_ - pattern_size) &&
889 // pattern 889 // Pattern.
890 instr_at(pc_ - 1 * kInstrSize) == kPopInstruction && 890 instr_at(pc_ - 1 * kInstrSize) == kPopInstruction &&
891 (instr_at(pc_ - 2 * kInstrSize) & ~RdMask) == kPushRegPattern) { 891 (instr_at(pc_ - 2 * kInstrSize) & ~RdMask) == kPushRegPattern) {
892 pc_ -= 2 * kInstrSize; 892 pc_ -= 2 * kInstrSize;
893 if (FLAG_print_push_pop_elimination) { 893 if (FLAG_print_push_pop_elimination) {
894 PrintF("%x push(reg)/pop() eliminated\n", pc_offset()); 894 PrintF("%x push(reg)/pop() eliminated\n", pc_offset());
895 } 895 }
896 } 896 }
897 } 897 }
898 898
899 899
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 SBit s, Condition cond) { 953 SBit s, Condition cond) {
954 addrmod1(cond | 14*B21 | s, src1, dst, src2); 954 addrmod1(cond | 14*B21 | s, src1, dst, src2);
955 } 955 }
956 956
957 957
958 void Assembler::mvn(Register dst, const Operand& src, SBit s, Condition cond) { 958 void Assembler::mvn(Register dst, const Operand& src, SBit s, Condition cond) {
959 addrmod1(cond | 15*B21 | s, r0, dst, src); 959 addrmod1(cond | 15*B21 | s, r0, dst, src);
960 } 960 }
961 961
962 962
963 // Multiply instructions 963 // Multiply instructions.
964 void Assembler::mla(Register dst, Register src1, Register src2, Register srcA, 964 void Assembler::mla(Register dst, Register src1, Register src2, Register srcA,
965 SBit s, Condition cond) { 965 SBit s, Condition cond) {
966 ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc) && !srcA.is(pc)); 966 ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc) && !srcA.is(pc));
967 emit(cond | A | s | dst.code()*B16 | srcA.code()*B12 | 967 emit(cond | A | s | dst.code()*B16 | srcA.code()*B12 |
968 src2.code()*B8 | B7 | B4 | src1.code()); 968 src2.code()*B8 | B7 | B4 | src1.code());
969 } 969 }
970 970
971 971
972 void Assembler::mul(Register dst, Register src1, Register src2, 972 void Assembler::mul(Register dst, Register src1, Register src2,
973 SBit s, Condition cond) { 973 SBit s, Condition cond) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 Register src2, 1022 Register src2,
1023 SBit s, 1023 SBit s,
1024 Condition cond) { 1024 Condition cond) {
1025 ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc)); 1025 ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc));
1026 ASSERT(!dstL.is(dstH)); 1026 ASSERT(!dstL.is(dstH));
1027 emit(cond | B23 | s | dstH.code()*B16 | dstL.code()*B12 | 1027 emit(cond | B23 | s | dstH.code()*B16 | dstL.code()*B12 |
1028 src2.code()*B8 | B7 | B4 | src1.code()); 1028 src2.code()*B8 | B7 | B4 | src1.code());
1029 } 1029 }
1030 1030
1031 1031
1032 // Miscellaneous arithmetic instructions 1032 // Miscellaneous arithmetic instructions.
1033 void Assembler::clz(Register dst, Register src, Condition cond) { 1033 void Assembler::clz(Register dst, Register src, Condition cond) {
1034 // v5 and above. 1034 // v5 and above.
1035 ASSERT(!dst.is(pc) && !src.is(pc)); 1035 ASSERT(!dst.is(pc) && !src.is(pc));
1036 emit(cond | B24 | B22 | B21 | 15*B16 | dst.code()*B12 | 1036 emit(cond | B24 | B22 | B21 | 15*B16 | dst.code()*B12 |
1037 15*B8 | B4 | src.code()); 1037 15*B8 | B4 | src.code());
1038 } 1038 }
1039 1039
1040 1040
1041 // Status register access instructions 1041 // Status register access instructions.
1042 void Assembler::mrs(Register dst, SRegister s, Condition cond) { 1042 void Assembler::mrs(Register dst, SRegister s, Condition cond) {
1043 ASSERT(!dst.is(pc)); 1043 ASSERT(!dst.is(pc));
1044 emit(cond | B24 | s | 15*B16 | dst.code()*B12); 1044 emit(cond | B24 | s | 15*B16 | dst.code()*B12);
1045 } 1045 }
1046 1046
1047 1047
1048 void Assembler::msr(SRegisterFieldMask fields, const Operand& src, 1048 void Assembler::msr(SRegisterFieldMask fields, const Operand& src,
1049 Condition cond) { 1049 Condition cond) {
1050 ASSERT(fields >= B16 && fields < B20); // at least one field set 1050 ASSERT(fields >= B16 && fields < B20); // at least one field set
1051 Instr instr; 1051 Instr instr;
1052 if (!src.rm_.is_valid()) { 1052 if (!src.rm_.is_valid()) {
1053 // immediate 1053 // Immediate.
1054 uint32_t rotate_imm; 1054 uint32_t rotate_imm;
1055 uint32_t immed_8; 1055 uint32_t immed_8;
1056 if (MustUseIp(src.rmode_) || 1056 if (MustUseIp(src.rmode_) ||
1057 !fits_shifter(src.imm32_, &rotate_imm, &immed_8, NULL)) { 1057 !fits_shifter(src.imm32_, &rotate_imm, &immed_8, NULL)) {
1058 // immediate operand cannot be encoded, load it first to register ip 1058 // Immediate operand cannot be encoded, load it first to register ip.
1059 RecordRelocInfo(src.rmode_, src.imm32_); 1059 RecordRelocInfo(src.rmode_, src.imm32_);
1060 ldr(ip, MemOperand(pc, 0), cond); 1060 ldr(ip, MemOperand(pc, 0), cond);
1061 msr(fields, Operand(ip), cond); 1061 msr(fields, Operand(ip), cond);
1062 return; 1062 return;
1063 } 1063 }
1064 instr = I | rotate_imm*B8 | immed_8; 1064 instr = I | rotate_imm*B8 | immed_8;
1065 } else { 1065 } else {
1066 ASSERT(!src.rs_.is_valid() && src.shift_imm_ == 0); // only rm allowed 1066 ASSERT(!src.rs_.is_valid() && src.shift_imm_ == 0); // only rm allowed
1067 instr = src.rm_.code(); 1067 instr = src.rm_.code();
1068 } 1068 }
1069 emit(cond | instr | B24 | B21 | fields | 15*B12); 1069 emit(cond | instr | B24 | B21 | fields | 15*B12);
1070 } 1070 }
1071 1071
1072 1072
1073 // Load/Store instructions 1073 // Load/Store instructions.
1074 void Assembler::ldr(Register dst, const MemOperand& src, Condition cond) { 1074 void Assembler::ldr(Register dst, const MemOperand& src, Condition cond) {
1075 if (dst.is(pc)) { 1075 if (dst.is(pc)) {
1076 WriteRecordedPositions(); 1076 WriteRecordedPositions();
1077 } 1077 }
1078 addrmod2(cond | B26 | L, dst, src); 1078 addrmod2(cond | B26 | L, dst, src);
1079 1079
1080 // Eliminate pattern: push(r), pop(r) 1080 // Eliminate pattern: push(r), pop(r)
1081 // str(r, MemOperand(sp, 4, NegPreIndex), al) 1081 // str(r, MemOperand(sp, 4, NegPreIndex), al)
1082 // ldr(r, MemOperand(sp, 4, PostIndex), al) 1082 // ldr(r, MemOperand(sp, 4, PostIndex), al)
1083 // Both instructions can be eliminated. 1083 // Both instructions can be eliminated.
1084 int pattern_size = 2 * kInstrSize; 1084 int pattern_size = 2 * kInstrSize;
1085 if (FLAG_push_pop_elimination && 1085 if (FLAG_push_pop_elimination &&
1086 last_bound_pos_ <= (pc_offset() - pattern_size) && 1086 last_bound_pos_ <= (pc_offset() - pattern_size) &&
1087 reloc_info_writer.last_pc() <= (pc_ - pattern_size) && 1087 reloc_info_writer.last_pc() <= (pc_ - pattern_size) &&
1088 // pattern 1088 // Pattern.
1089 instr_at(pc_ - 1 * kInstrSize) == (kPopRegPattern | dst.code() * B12) && 1089 instr_at(pc_ - 1 * kInstrSize) == (kPopRegPattern | dst.code() * B12) &&
1090 instr_at(pc_ - 2 * kInstrSize) == (kPushRegPattern | dst.code() * B12)) { 1090 instr_at(pc_ - 2 * kInstrSize) == (kPushRegPattern | dst.code() * B12)) {
1091 pc_ -= 2 * kInstrSize; 1091 pc_ -= 2 * kInstrSize;
1092 if (FLAG_print_push_pop_elimination) { 1092 if (FLAG_print_push_pop_elimination) {
1093 PrintF("%x push/pop (same reg) eliminated\n", pc_offset()); 1093 PrintF("%x push/pop (same reg) eliminated\n", pc_offset());
1094 } 1094 }
1095 } 1095 }
1096 } 1096 }
1097 1097
1098 1098
1099 void Assembler::str(Register src, const MemOperand& dst, Condition cond) { 1099 void Assembler::str(Register src, const MemOperand& dst, Condition cond) {
1100 addrmod2(cond | B26, src, dst); 1100 addrmod2(cond | B26, src, dst);
1101 1101
1102 // Eliminate pattern: pop(), push(r) 1102 // Eliminate pattern: pop(), push(r)
1103 // add sp, sp, #4 LeaveCC, al; str r, [sp, #-4], al 1103 // add sp, sp, #4 LeaveCC, al; str r, [sp, #-4], al
1104 // -> str r, [sp, 0], al 1104 // -> str r, [sp, 0], al
1105 int pattern_size = 2 * kInstrSize; 1105 int pattern_size = 2 * kInstrSize;
1106 if (FLAG_push_pop_elimination && 1106 if (FLAG_push_pop_elimination &&
1107 last_bound_pos_ <= (pc_offset() - pattern_size) && 1107 last_bound_pos_ <= (pc_offset() - pattern_size) &&
1108 reloc_info_writer.last_pc() <= (pc_ - pattern_size) && 1108 reloc_info_writer.last_pc() <= (pc_ - pattern_size) &&
1109 // Pattern.
1109 instr_at(pc_ - 1 * kInstrSize) == (kPushRegPattern | src.code() * B12) && 1110 instr_at(pc_ - 1 * kInstrSize) == (kPushRegPattern | src.code() * B12) &&
1110 instr_at(pc_ - 2 * kInstrSize) == kPopInstruction) { 1111 instr_at(pc_ - 2 * kInstrSize) == kPopInstruction) {
1111 pc_ -= 2 * kInstrSize; 1112 pc_ -= 2 * kInstrSize;
1112 emit(al | B26 | 0 | Offset | sp.code() * B16 | src.code() * B12); 1113 emit(al | B26 | 0 | Offset | sp.code() * B16 | src.code() * B12);
1113 if (FLAG_print_push_pop_elimination) { 1114 if (FLAG_print_push_pop_elimination) {
1114 PrintF("%x pop()/push(reg) eliminated\n", pc_offset()); 1115 PrintF("%x pop()/push(reg) eliminated\n", pc_offset());
1115 } 1116 }
1116 } 1117 }
1117 } 1118 }
1118 1119
(...skipping 21 matching lines...) Expand all
1140 void Assembler::ldrsb(Register dst, const MemOperand& src, Condition cond) { 1141 void Assembler::ldrsb(Register dst, const MemOperand& src, Condition cond) {
1141 addrmod3(cond | L | B7 | S6 | B4, dst, src); 1142 addrmod3(cond | L | B7 | S6 | B4, dst, src);
1142 } 1143 }
1143 1144
1144 1145
1145 void Assembler::ldrsh(Register dst, const MemOperand& src, Condition cond) { 1146 void Assembler::ldrsh(Register dst, const MemOperand& src, Condition cond) {
1146 addrmod3(cond | L | B7 | S6 | H | B4, dst, src); 1147 addrmod3(cond | L | B7 | S6 | H | B4, dst, src);
1147 } 1148 }
1148 1149
1149 1150
1150 // Load/Store multiple instructions 1151 // Load/Store multiple instructions.
1151 void Assembler::ldm(BlockAddrMode am, 1152 void Assembler::ldm(BlockAddrMode am,
1152 Register base, 1153 Register base,
1153 RegList dst, 1154 RegList dst,
1154 Condition cond) { 1155 Condition cond) {
1155 // ABI stack constraint: ldmxx base, {..sp..} base != sp is not restartable 1156 // ABI stack constraint: ldmxx base, {..sp..} base != sp is not restartable.
1156 ASSERT(base.is(sp) || (dst & sp.bit()) == 0); 1157 ASSERT(base.is(sp) || (dst & sp.bit()) == 0);
1157 1158
1158 addrmod4(cond | B27 | am | L, base, dst); 1159 addrmod4(cond | B27 | am | L, base, dst);
1159 1160
1160 // emit the constant pool after a function return implemented by ldm ..{..pc} 1161 // Emit the constant pool after a function return implemented by ldm ..{..pc}.
1161 if (cond == al && (dst & pc.bit()) != 0) { 1162 if (cond == al && (dst & pc.bit()) != 0) {
1162 // There is a slight chance that the ldm instruction was actually a call, 1163 // There is a slight chance that the ldm instruction was actually a call,
1163 // in which case it would be wrong to return into the constant pool; we 1164 // in which case it would be wrong to return into the constant pool; we
1164 // recognize this case by checking if the emission of the pool was blocked 1165 // recognize this case by checking if the emission of the pool was blocked
1165 // at the pc of the ldm instruction by a mov lr, pc instruction; if this is 1166 // at the pc of the ldm instruction by a mov lr, pc instruction; if this is
1166 // the case, we emit a jump over the pool. 1167 // the case, we emit a jump over the pool.
1167 CheckConstPool(true, no_const_pool_before_ == pc_offset() - kInstrSize); 1168 CheckConstPool(true, no_const_pool_before_ == pc_offset() - kInstrSize);
1168 } 1169 }
1169 } 1170 }
1170 1171
1171 1172
1172 void Assembler::stm(BlockAddrMode am, 1173 void Assembler::stm(BlockAddrMode am,
1173 Register base, 1174 Register base,
1174 RegList src, 1175 RegList src,
1175 Condition cond) { 1176 Condition cond) {
1176 addrmod4(cond | B27 | am, base, src); 1177 addrmod4(cond | B27 | am, base, src);
1177 } 1178 }
1178 1179
1179 1180
1180 // Semaphore instructions 1181 // Semaphore instructions.
1181 void Assembler::swp(Register dst, Register src, Register base, Condition cond) { 1182 void Assembler::swp(Register dst, Register src, Register base, Condition cond) {
1182 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc)); 1183 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc));
1183 ASSERT(!dst.is(base) && !src.is(base)); 1184 ASSERT(!dst.is(base) && !src.is(base));
1184 emit(cond | P | base.code()*B16 | dst.code()*B12 | 1185 emit(cond | P | base.code()*B16 | dst.code()*B12 |
1185 B7 | B4 | src.code()); 1186 B7 | B4 | src.code());
1186 } 1187 }
1187 1188
1188 1189
1189 void Assembler::swpb(Register dst, 1190 void Assembler::swpb(Register dst,
1190 Register src, 1191 Register src,
1191 Register base, 1192 Register base,
1192 Condition cond) { 1193 Condition cond) {
1193 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc)); 1194 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc));
1194 ASSERT(!dst.is(base) && !src.is(base)); 1195 ASSERT(!dst.is(base) && !src.is(base));
1195 emit(cond | P | B | base.code()*B16 | dst.code()*B12 | 1196 emit(cond | P | B | base.code()*B16 | dst.code()*B12 |
1196 B7 | B4 | src.code()); 1197 B7 | B4 | src.code());
1197 } 1198 }
1198 1199
1199 1200
1200 // Exception-generating instructions and debugging support 1201 // Exception-generating instructions and debugging support.
1201 void Assembler::stop(const char* msg) { 1202 void Assembler::stop(const char* msg) {
1202 #if !defined(__arm__) 1203 #if !defined(__arm__)
1203 // The simulator handles these special instructions and stops execution. 1204 // The simulator handles these special instructions and stops execution.
1204 emit(15 << 28 | ((intptr_t) msg)); 1205 emit(15 << 28 | ((intptr_t) msg));
1205 #else 1206 #else
1206 // Just issue a simple break instruction for now. Alternatively we could use 1207 // Just issue a simple break instruction for now. Alternatively we could use
1207 // the swi(0x9f0001) instruction on Linux. 1208 // the swi(0x9f0001) instruction on Linux.
1208 bkpt(0); 1209 bkpt(0);
1209 #endif 1210 #endif
1210 } 1211 }
1211 1212
1212 1213
1213 void Assembler::bkpt(uint32_t imm16) { // v5 and above 1214 void Assembler::bkpt(uint32_t imm16) { // v5 and above
1214 ASSERT(is_uint16(imm16)); 1215 ASSERT(is_uint16(imm16));
1215 emit(al | B24 | B21 | (imm16 >> 4)*B8 | 7*B4 | (imm16 & 0xf)); 1216 emit(al | B24 | B21 | (imm16 >> 4)*B8 | 7*B4 | (imm16 & 0xf));
1216 } 1217 }
1217 1218
1218 1219
1219 void Assembler::swi(uint32_t imm24, Condition cond) { 1220 void Assembler::swi(uint32_t imm24, Condition cond) {
1220 ASSERT(is_uint24(imm24)); 1221 ASSERT(is_uint24(imm24));
1221 emit(cond | 15*B24 | imm24); 1222 emit(cond | 15*B24 | imm24);
1222 } 1223 }
1223 1224
1224 1225
1225 // Coprocessor instructions 1226 // Coprocessor instructions.
1226 void Assembler::cdp(Coprocessor coproc, 1227 void Assembler::cdp(Coprocessor coproc,
1227 int opcode_1, 1228 int opcode_1,
1228 CRegister crd, 1229 CRegister crd,
1229 CRegister crn, 1230 CRegister crn,
1230 CRegister crm, 1231 CRegister crm,
1231 int opcode_2, 1232 int opcode_2,
1232 Condition cond) { 1233 Condition cond) {
1233 ASSERT(is_uint4(opcode_1) && is_uint3(opcode_2)); 1234 ASSERT(is_uint4(opcode_1) && is_uint3(opcode_2));
1234 emit(cond | B27 | B26 | B25 | (opcode_1 & 15)*B20 | crn.code()*B16 | 1235 emit(cond | B27 | B26 | B25 | (opcode_1 & 15)*B20 | crn.code()*B16 |
1235 crd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | crm.code()); 1236 crd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | crm.code());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 addrmod5(cond | B27 | B26 | l | L | coproc*B8, crd, src); 1301 addrmod5(cond | B27 | B26 | l | L | coproc*B8, crd, src);
1301 } 1302 }
1302 1303
1303 1304
1304 void Assembler::ldc(Coprocessor coproc, 1305 void Assembler::ldc(Coprocessor coproc,
1305 CRegister crd, 1306 CRegister crd,
1306 Register rn, 1307 Register rn,
1307 int option, 1308 int option,
1308 LFlag l, 1309 LFlag l,
1309 Condition cond) { 1310 Condition cond) {
1310 // unindexed addressing 1311 // Unindexed addressing.
1311 ASSERT(is_uint8(option)); 1312 ASSERT(is_uint8(option));
1312 emit(cond | B27 | B26 | U | l | L | rn.code()*B16 | crd.code()*B12 | 1313 emit(cond | B27 | B26 | U | l | L | rn.code()*B16 | crd.code()*B12 |
1313 coproc*B8 | (option & 255)); 1314 coproc*B8 | (option & 255));
1314 } 1315 }
1315 1316
1316 1317
1317 void Assembler::ldc2(Coprocessor coproc, 1318 void Assembler::ldc2(Coprocessor coproc,
1318 CRegister crd, 1319 CRegister crd,
1319 const MemOperand& src, 1320 const MemOperand& src,
1320 LFlag l) { // v5 and above 1321 LFlag l) { // v5 and above
(...skipping 18 matching lines...) Expand all
1339 addrmod5(cond | B27 | B26 | l | coproc*B8, crd, dst); 1340 addrmod5(cond | B27 | B26 | l | coproc*B8, crd, dst);
1340 } 1341 }
1341 1342
1342 1343
1343 void Assembler::stc(Coprocessor coproc, 1344 void Assembler::stc(Coprocessor coproc,
1344 CRegister crd, 1345 CRegister crd,
1345 Register rn, 1346 Register rn,
1346 int option, 1347 int option,
1347 LFlag l, 1348 LFlag l,
1348 Condition cond) { 1349 Condition cond) {
1349 // unindexed addressing 1350 // Unindexed addressing.
1350 ASSERT(is_uint8(option)); 1351 ASSERT(is_uint8(option));
1351 emit(cond | B27 | B26 | U | l | rn.code()*B16 | crd.code()*B12 | 1352 emit(cond | B27 | B26 | U | l | rn.code()*B16 | crd.code()*B12 |
1352 coproc*B8 | (option & 255)); 1353 coproc*B8 | (option & 255));
1353 } 1354 }
1354 1355
1355 1356
1356 void Assembler::stc2(Coprocessor 1357 void Assembler::stc2(Coprocessor
1357 coproc, CRegister crd, 1358 coproc, CRegister crd,
1358 const MemOperand& dst, 1359 const MemOperand& dst,
1359 LFlag l) { // v5 and above 1360 LFlag l) { // v5 and above
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 emit(cond | 0xE*B24 | B20 | (src.code() >> 1)*B16 | 1458 emit(cond | 0xE*B24 | B20 | (src.code() >> 1)*B16 |
1458 dst.code()*B12 | 0xA*B8 | (0x1 & src.code())*B7 | B4); 1459 dst.code()*B12 | 0xA*B8 | (0x1 & src.code())*B7 | B4);
1459 } 1460 }
1460 1461
1461 1462
1462 void Assembler::vcvt(const DwVfpRegister dst, 1463 void Assembler::vcvt(const DwVfpRegister dst,
1463 const SwVfpRegister src, 1464 const SwVfpRegister src,
1464 const Condition cond) { 1465 const Condition cond) {
1465 // Dd = Sm (integer in Sm converted to IEEE 64-bit doubles in Dd). 1466 // Dd = Sm (integer in Sm converted to IEEE 64-bit doubles in Dd).
1466 // Instruction details available in ARM DDI 0406A, A8-576. 1467 // Instruction details available in ARM DDI 0406A, A8-576.
1467 // cond(31-28) | 11101(27-23)| D=?(22) | 11(21-20) | 1(19) |opc2=000(18-16) | 1468 // cond(31-28) | 11101(27-23)| D=?(22) | 11(21-20) | 1(19) | opc2=000(18-16) |
1468 // Vd(15-12) | 101(11-9) | sz(8)=1 | op(7)=1 | 1(6) | M=?(5) | 0(4) | Vm(3-0) 1469 // Vd(15-12) | 101(11-9) | sz(8)=1 | op(7)=1 | 1(6) | M=?(5) | 0(4) | Vm(3-0)
1469 ASSERT(CpuFeatures::IsEnabled(VFP3)); 1470 ASSERT(CpuFeatures::IsEnabled(VFP3));
1470 emit(cond | 0xE*B24 | B23 | 0x3*B20 | B19 | 1471 emit(cond | 0xE*B24 | B23 | 0x3*B20 | B19 |
1471 dst.code()*B12 | 0x5*B9 | B8 | B7 | B6 | 1472 dst.code()*B12 | 0x5*B9 | B8 | B7 | B6 |
1472 (0x1 & src.code())*B5 | (src.code() >> 1)); 1473 (0x1 & src.code())*B5 | (src.code() >> 1));
1473 } 1474 }
1474 1475
1475 1476
1476 void Assembler::vcvt(const SwVfpRegister dst, 1477 void Assembler::vcvt(const SwVfpRegister dst,
1477 const DwVfpRegister src, 1478 const DwVfpRegister src,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 void Assembler::vmrs(Register dst, Condition cond) { 1565 void Assembler::vmrs(Register dst, Condition cond) {
1565 // Instruction details available in ARM DDI 0406A, A8-652. 1566 // Instruction details available in ARM DDI 0406A, A8-652.
1566 // cond(31-28) | 1110 (27-24) | 1111(23-20)| 0001 (19-16) | 1567 // cond(31-28) | 1110 (27-24) | 1111(23-20)| 0001 (19-16) |
1567 // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0) 1568 // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0)
1568 ASSERT(CpuFeatures::IsEnabled(VFP3)); 1569 ASSERT(CpuFeatures::IsEnabled(VFP3));
1569 emit(cond | 0xE*B24 | 0xF*B20 | B16 | 1570 emit(cond | 0xE*B24 | 0xF*B20 | B16 |
1570 dst.code()*B12 | 0xA*B8 | B4); 1571 dst.code()*B12 | 0xA*B8 | B4);
1571 } 1572 }
1572 1573
1573 1574
1574 // Pseudo instructions 1575 // Pseudo instructions.
1575 void Assembler::lea(Register dst, 1576 void Assembler::lea(Register dst,
1576 const MemOperand& x, 1577 const MemOperand& x,
1577 SBit s, 1578 SBit s,
1578 Condition cond) { 1579 Condition cond) {
1579 int am = x.am_; 1580 int am = x.am_;
1580 if (!x.rm_.is_valid()) { 1581 if (!x.rm_.is_valid()) {
1581 // immediate offset 1582 // Immediate offset.
1582 if ((am & P) == 0) // post indexing 1583 if ((am & P) == 0) // post indexing
1583 mov(dst, Operand(x.rn_), s, cond); 1584 mov(dst, Operand(x.rn_), s, cond);
1584 else if ((am & U) == 0) // negative indexing 1585 else if ((am & U) == 0) // negative indexing
1585 sub(dst, x.rn_, Operand(x.offset_), s, cond); 1586 sub(dst, x.rn_, Operand(x.offset_), s, cond);
1586 else 1587 else
1587 add(dst, x.rn_, Operand(x.offset_), s, cond); 1588 add(dst, x.rn_, Operand(x.offset_), s, cond);
1588 } else { 1589 } else {
1589 // Register offset (shift_imm_ and shift_op_ are 0) or scaled 1590 // Register offset (shift_imm_ and shift_op_ are 0) or scaled
1590 // register offset the constructors make sure than both shift_imm_ 1591 // register offset the constructors make sure than both shift_imm_
1591 // and shift_op_ are initialized. 1592 // and shift_op_ are initialized.
(...skipping 13 matching lines...) Expand all
1605 uint32_t dummy2; 1606 uint32_t dummy2;
1606 return fits_shifter(imm32, &dummy1, &dummy2, NULL); 1607 return fits_shifter(imm32, &dummy1, &dummy2, NULL);
1607 } 1608 }
1608 1609
1609 1610
1610 void Assembler::BlockConstPoolFor(int instructions) { 1611 void Assembler::BlockConstPoolFor(int instructions) {
1611 BlockConstPoolBefore(pc_offset() + instructions * kInstrSize); 1612 BlockConstPoolBefore(pc_offset() + instructions * kInstrSize);
1612 } 1613 }
1613 1614
1614 1615
1615 // Debugging 1616 // Debugging.
1616 void Assembler::RecordJSReturn() { 1617 void Assembler::RecordJSReturn() {
1617 WriteRecordedPositions(); 1618 WriteRecordedPositions();
1618 CheckBuffer(); 1619 CheckBuffer();
1619 RecordRelocInfo(RelocInfo::JS_RETURN); 1620 RecordRelocInfo(RelocInfo::JS_RETURN);
1620 } 1621 }
1621 1622
1622 1623
1623 void Assembler::RecordComment(const char* msg) { 1624 void Assembler::RecordComment(const char* msg) {
1624 if (FLAG_debug_code) { 1625 if (FLAG_debug_code) {
1625 CheckBuffer(); 1626 CheckBuffer();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 CheckBuffer(); 1659 CheckBuffer();
1659 RecordRelocInfo(RelocInfo::POSITION, current_position_); 1660 RecordRelocInfo(RelocInfo::POSITION, current_position_);
1660 written_position_ = current_position_; 1661 written_position_ = current_position_;
1661 } 1662 }
1662 } 1663 }
1663 1664
1664 1665
1665 void Assembler::GrowBuffer() { 1666 void Assembler::GrowBuffer() {
1666 if (!own_buffer_) FATAL("external code buffer is too small"); 1667 if (!own_buffer_) FATAL("external code buffer is too small");
1667 1668
1668 // compute new buffer size 1669 // Compute new buffer size.
1669 CodeDesc desc; // the new buffer 1670 CodeDesc desc; // the new buffer
1670 if (buffer_size_ < 4*KB) { 1671 if (buffer_size_ < 4*KB) {
1671 desc.buffer_size = 4*KB; 1672 desc.buffer_size = 4*KB;
1672 } else if (buffer_size_ < 1*MB) { 1673 } else if (buffer_size_ < 1*MB) {
1673 desc.buffer_size = 2*buffer_size_; 1674 desc.buffer_size = 2*buffer_size_;
1674 } else { 1675 } else {
1675 desc.buffer_size = buffer_size_ + 1*MB; 1676 desc.buffer_size = buffer_size_ + 1*MB;
1676 } 1677 }
1677 CHECK_GT(desc.buffer_size, 0); // no overflow 1678 CHECK_GT(desc.buffer_size, 0); // no overflow
1678 1679
1679 // setup new buffer 1680 // Setup new buffer.
1680 desc.buffer = NewArray<byte>(desc.buffer_size); 1681 desc.buffer = NewArray<byte>(desc.buffer_size);
1681 1682
1682 desc.instr_size = pc_offset(); 1683 desc.instr_size = pc_offset();
1683 desc.reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); 1684 desc.reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
1684 1685
1685 // copy the data 1686 // Copy the data.
1686 int pc_delta = desc.buffer - buffer_; 1687 int pc_delta = desc.buffer - buffer_;
1687 int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_); 1688 int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_);
1688 memmove(desc.buffer, buffer_, desc.instr_size); 1689 memmove(desc.buffer, buffer_, desc.instr_size);
1689 memmove(reloc_info_writer.pos() + rc_delta, 1690 memmove(reloc_info_writer.pos() + rc_delta,
1690 reloc_info_writer.pos(), desc.reloc_size); 1691 reloc_info_writer.pos(), desc.reloc_size);
1691 1692
1692 // switch buffers 1693 // Switch buffers.
1693 DeleteArray(buffer_); 1694 DeleteArray(buffer_);
1694 buffer_ = desc.buffer; 1695 buffer_ = desc.buffer;
1695 buffer_size_ = desc.buffer_size; 1696 buffer_size_ = desc.buffer_size;
1696 pc_ += pc_delta; 1697 pc_ += pc_delta;
1697 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, 1698 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
1698 reloc_info_writer.last_pc() + pc_delta); 1699 reloc_info_writer.last_pc() + pc_delta);
1699 1700
1700 // none of our relocation types are pc relative pointing outside the code 1701 // None of our relocation types are pc relative pointing outside the code
1701 // buffer nor pc absolute pointing inside the code buffer, so there is no need 1702 // buffer nor pc absolute pointing inside the code buffer, so there is no need
1702 // to relocate any emitted relocation entries 1703 // to relocate any emitted relocation entries.
1703 1704
1704 // relocate pending relocation entries 1705 // Relocate pending relocation entries.
1705 for (int i = 0; i < num_prinfo_; i++) { 1706 for (int i = 0; i < num_prinfo_; i++) {
1706 RelocInfo& rinfo = prinfo_[i]; 1707 RelocInfo& rinfo = prinfo_[i];
1707 ASSERT(rinfo.rmode() != RelocInfo::COMMENT && 1708 ASSERT(rinfo.rmode() != RelocInfo::COMMENT &&
1708 rinfo.rmode() != RelocInfo::POSITION); 1709 rinfo.rmode() != RelocInfo::POSITION);
1709 if (rinfo.rmode() != RelocInfo::JS_RETURN) { 1710 if (rinfo.rmode() != RelocInfo::JS_RETURN) {
1710 rinfo.set_pc(rinfo.pc() + pc_delta); 1711 rinfo.set_pc(rinfo.pc() + pc_delta);
1711 } 1712 }
1712 } 1713 }
1713 } 1714 }
1714 1715
1715 1716
1716 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { 1717 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
1717 RelocInfo rinfo(pc_, rmode, data); // we do not try to reuse pool constants 1718 RelocInfo rinfo(pc_, rmode, data); // we do not try to reuse pool constants
1718 if (rmode >= RelocInfo::JS_RETURN && rmode <= RelocInfo::STATEMENT_POSITION) { 1719 if (rmode >= RelocInfo::JS_RETURN && rmode <= RelocInfo::STATEMENT_POSITION) {
1719 // Adjust code for new modes 1720 // Adjust code for new modes.
1720 ASSERT(RelocInfo::IsJSReturn(rmode) 1721 ASSERT(RelocInfo::IsJSReturn(rmode)
1721 || RelocInfo::IsComment(rmode) 1722 || RelocInfo::IsComment(rmode)
1722 || RelocInfo::IsPosition(rmode)); 1723 || RelocInfo::IsPosition(rmode));
1723 // these modes do not need an entry in the constant pool 1724 // These modes do not need an entry in the constant pool.
1724 } else { 1725 } else {
1725 ASSERT(num_prinfo_ < kMaxNumPRInfo); 1726 ASSERT(num_prinfo_ < kMaxNumPRInfo);
1726 prinfo_[num_prinfo_++] = rinfo; 1727 prinfo_[num_prinfo_++] = rinfo;
1727 // Make sure the constant pool is not emitted in place of the next 1728 // Make sure the constant pool is not emitted in place of the next
1728 // instruction for which we just recorded relocation info 1729 // instruction for which we just recorded relocation info.
1729 BlockConstPoolBefore(pc_offset() + kInstrSize); 1730 BlockConstPoolBefore(pc_offset() + kInstrSize);
1730 } 1731 }
1731 if (rinfo.rmode() != RelocInfo::NONE) { 1732 if (rinfo.rmode() != RelocInfo::NONE) {
1732 // Don't record external references unless the heap will be serialized. 1733 // Don't record external references unless the heap will be serialized.
1733 if (rmode == RelocInfo::EXTERNAL_REFERENCE) { 1734 if (rmode == RelocInfo::EXTERNAL_REFERENCE) {
1734 #ifdef DEBUG 1735 #ifdef DEBUG
1735 if (!Serializer::enabled()) { 1736 if (!Serializer::enabled()) {
1736 Serializer::TooLateToEnableNow(); 1737 Serializer::TooLateToEnableNow();
1737 } 1738 }
1738 #endif 1739 #endif
1739 if (!Serializer::enabled() && !FLAG_debug_code) { 1740 if (!Serializer::enabled() && !FLAG_debug_code) {
1740 return; 1741 return;
1741 } 1742 }
1742 } 1743 }
1743 ASSERT(buffer_space() >= kMaxRelocSize); // too late to grow buffer here 1744 ASSERT(buffer_space() >= kMaxRelocSize); // too late to grow buffer here
1744 reloc_info_writer.Write(&rinfo); 1745 reloc_info_writer.Write(&rinfo);
1745 } 1746 }
1746 } 1747 }
1747 1748
1748 1749
1749 void Assembler::CheckConstPool(bool force_emit, bool require_jump) { 1750 void Assembler::CheckConstPool(bool force_emit, bool require_jump) {
1750 // Calculate the offset of the next check. It will be overwritten 1751 // Calculate the offset of the next check. It will be overwritten
1751 // when a const pool is generated or when const pools are being 1752 // when a const pool is generated or when const pools are being
1752 // blocked for a specific range. 1753 // blocked for a specific range.
1753 next_buffer_check_ = pc_offset() + kCheckConstInterval; 1754 next_buffer_check_ = pc_offset() + kCheckConstInterval;
1754 1755
1755 // There is nothing to do if there are no pending relocation info entries 1756 // There is nothing to do if there are no pending relocation info entries.
1756 if (num_prinfo_ == 0) return; 1757 if (num_prinfo_ == 0) return;
1757 1758
1758 // We emit a constant pool at regular intervals of about kDistBetweenPools 1759 // We emit a constant pool at regular intervals of about kDistBetweenPools
1759 // or when requested by parameter force_emit (e.g. after each function). 1760 // or when requested by parameter force_emit (e.g. after each function).
1760 // We prefer not to emit a jump unless the max distance is reached or if we 1761 // We prefer not to emit a jump unless the max distance is reached or if we
1761 // are running low on slots, which can happen if a lot of constants are being 1762 // are running low on slots, which can happen if a lot of constants are being
1762 // emitted (e.g. --debug-code and many static references). 1763 // emitted (e.g. --debug-code and many static references).
1763 int dist = pc_offset() - last_const_pool_end_; 1764 int dist = pc_offset() - last_const_pool_end_;
1764 if (!force_emit && dist < kMaxDistBetweenPools && 1765 if (!force_emit && dist < kMaxDistBetweenPools &&
1765 (require_jump || dist < kDistBetweenPools) && 1766 (require_jump || dist < kDistBetweenPools) &&
1766 // TODO(1236125): Cleanup the "magic" number below. We know that 1767 // TODO(1236125): Cleanup the "magic" number below. We know that
1767 // the code generation will test every kCheckConstIntervalInst. 1768 // the code generation will test every kCheckConstIntervalInst.
1768 // Thus we are safe as long as we generate less than 7 constant 1769 // Thus we are safe as long as we generate less than 7 constant
1769 // entries per instruction. 1770 // entries per instruction.
1770 (num_prinfo_ < (kMaxNumPRInfo - (7 * kCheckConstIntervalInst)))) { 1771 (num_prinfo_ < (kMaxNumPRInfo - (7 * kCheckConstIntervalInst)))) {
1771 return; 1772 return;
1772 } 1773 }
1773 1774
1774 // If we did not return by now, we need to emit the constant pool soon. 1775 // If we did not return by now, we need to emit the constant pool soon.
1775 1776
1776 // However, some small sequences of instructions must not be broken up by the 1777 // However, some small sequences of instructions must not be broken up by the
1777 // insertion of a constant pool; such sequences are protected by setting 1778 // insertion of a constant pool; such sequences are protected by setting
1778 // no_const_pool_before_, which is checked here. Also, recursive calls to 1779 // no_const_pool_before_, which is checked here. Also, recursive calls to
1779 // CheckConstPool are blocked by no_const_pool_before_. 1780 // CheckConstPool are blocked by no_const_pool_before_.
1780 if (pc_offset() < no_const_pool_before_) { 1781 if (pc_offset() < no_const_pool_before_) {
1781 // Emission is currently blocked; make sure we try again as soon as possible 1782 // Emission is currently blocked; make sure we try again as soon as
1783 // possible.
1782 next_buffer_check_ = no_const_pool_before_; 1784 next_buffer_check_ = no_const_pool_before_;
1783 1785
1784 // Something is wrong if emission is forced and blocked at the same time 1786 // Something is wrong if emission is forced and blocked at the same time.
1785 ASSERT(!force_emit); 1787 ASSERT(!force_emit);
1786 return; 1788 return;
1787 } 1789 }
1788 1790
1789 int jump_instr = require_jump ? kInstrSize : 0; 1791 int jump_instr = require_jump ? kInstrSize : 0;
1790 1792
1791 // Check that the code buffer is large enough before emitting the constant 1793 // Check that the code buffer is large enough before emitting the constant
1792 // pool and relocation information (include the jump over the pool and the 1794 // pool and relocation information (include the jump over the pool and the
1793 // constant pool marker). 1795 // constant pool marker).
1794 int max_needed_space = 1796 int max_needed_space =
1795 jump_instr + kInstrSize + num_prinfo_*(kInstrSize + kMaxRelocSize); 1797 jump_instr + kInstrSize + num_prinfo_*(kInstrSize + kMaxRelocSize);
1796 while (buffer_space() <= (max_needed_space + kGap)) GrowBuffer(); 1798 while (buffer_space() <= (max_needed_space + kGap)) GrowBuffer();
1797 1799
1798 // Block recursive calls to CheckConstPool 1800 // Block recursive calls to CheckConstPool.
1799 BlockConstPoolBefore(pc_offset() + jump_instr + kInstrSize + 1801 BlockConstPoolBefore(pc_offset() + jump_instr + kInstrSize +
1800 num_prinfo_*kInstrSize); 1802 num_prinfo_*kInstrSize);
1801 // Don't bother to check for the emit calls below. 1803 // Don't bother to check for the emit calls below.
1802 next_buffer_check_ = no_const_pool_before_; 1804 next_buffer_check_ = no_const_pool_before_;
1803 1805
1804 // Emit jump over constant pool if necessary 1806 // Emit jump over constant pool if necessary.
1805 Label after_pool; 1807 Label after_pool;
1806 if (require_jump) b(&after_pool); 1808 if (require_jump) b(&after_pool);
1807 1809
1808 RecordComment("[ Constant Pool"); 1810 RecordComment("[ Constant Pool");
1809 1811
1810 // Put down constant pool marker 1812 // Put down constant pool marker "Undefined instruction" as specified by
1811 // "Undefined instruction" as specified by A3.1 Instruction set encoding 1813 // A3.1 Instruction set encoding.
1812 emit(0x03000000 | num_prinfo_); 1814 emit(0x03000000 | num_prinfo_);
1813 1815
1814 // Emit constant pool entries 1816 // Emit constant pool entries.
1815 for (int i = 0; i < num_prinfo_; i++) { 1817 for (int i = 0; i < num_prinfo_; i++) {
1816 RelocInfo& rinfo = prinfo_[i]; 1818 RelocInfo& rinfo = prinfo_[i];
1817 ASSERT(rinfo.rmode() != RelocInfo::COMMENT && 1819 ASSERT(rinfo.rmode() != RelocInfo::COMMENT &&
1818 rinfo.rmode() != RelocInfo::POSITION && 1820 rinfo.rmode() != RelocInfo::POSITION &&
1819 rinfo.rmode() != RelocInfo::STATEMENT_POSITION); 1821 rinfo.rmode() != RelocInfo::STATEMENT_POSITION);
1820 Instr instr = instr_at(rinfo.pc()); 1822 Instr instr = instr_at(rinfo.pc());
1821 1823
1822 // Instruction to patch must be a ldr/str [pc, #offset] 1824 // Instruction to patch must be a ldr/str [pc, #offset].
1823 // P and U set, B and W clear, Rn == pc, offset12 still 0 1825 // P and U set, B and W clear, Rn == pc, offset12 still 0.
1824 ASSERT((instr & (7*B25 | P | U | B | W | 15*B16 | Off12Mask)) == 1826 ASSERT((instr & (7*B25 | P | U | B | W | 15*B16 | Off12Mask)) ==
1825 (2*B25 | P | U | pc.code()*B16)); 1827 (2*B25 | P | U | pc.code()*B16));
1826 int delta = pc_ - rinfo.pc() - 8; 1828 int delta = pc_ - rinfo.pc() - 8;
1827 ASSERT(delta >= -4); // instr could be ldr pc, [pc, #-4] followed by targ32 1829 ASSERT(delta >= -4); // instr could be ldr pc, [pc, #-4] followed by targ32
1828 if (delta < 0) { 1830 if (delta < 0) {
1829 instr &= ~U; 1831 instr &= ~U;
1830 delta = -delta; 1832 delta = -delta;
1831 } 1833 }
1832 ASSERT(is_uint12(delta)); 1834 ASSERT(is_uint12(delta));
1833 instr_at_put(rinfo.pc(), instr + delta); 1835 instr_at_put(rinfo.pc(), instr + delta);
1834 emit(rinfo.data()); 1836 emit(rinfo.data());
1835 } 1837 }
1836 num_prinfo_ = 0; 1838 num_prinfo_ = 0;
1837 last_const_pool_end_ = pc_offset(); 1839 last_const_pool_end_ = pc_offset();
1838 1840
1839 RecordComment("]"); 1841 RecordComment("]");
1840 1842
1841 if (after_pool.is_linked()) { 1843 if (after_pool.is_linked()) {
1842 bind(&after_pool); 1844 bind(&after_pool);
1843 } 1845 }
1844 1846
1845 // Since a constant pool was just emitted, move the check offset forward by 1847 // Since a constant pool was just emitted, move the check offset forward by
1846 // the standard interval. 1848 // the standard interval.
1847 next_buffer_check_ = pc_offset() + kCheckConstInterval; 1849 next_buffer_check_ = pc_offset() + kCheckConstInterval;
1848 } 1850 }
1849 1851
1850 1852
1851 } } // namespace v8::internal 1853 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/assembler-arm.h ('k') | src/arm/assembler-thumb2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698