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

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

Issue 596065: Updating thumb2 stuff with assembler-arm changes (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-thumb2.h ('k') | src/arm/assembler-thumb2-inl.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 12 matching lines...) Expand all
23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 // OF THE POSSIBILITY OF SUCH DAMAGE. 31 // OF THE POSSIBILITY OF SUCH DAMAGE.
32 32
33 // The original source code covered by the above license above has been modified 33 // The original source code covered by the above license above has been
34 // significantly by Google Inc. 34 // modified significantly by Google Inc.
35 // Copyright 2006-2008 the V8 project authors. All rights reserved. 35 // Copyright 2010 the V8 project authors. All rights reserved.
36 36
37 #include "v8.h" 37 #include "v8.h"
38 38
39 #include "arm/assembler-thumb2-inl.h" 39 #include "arm/assembler-thumb2-inl.h"
40 #include "serialize.h" 40 #include "serialize.h"
41 41
42 namespace v8 { 42 namespace v8 {
43 namespace internal { 43 namespace internal {
44 44
45 // Safe default is no features. 45 // Safe default is no features.
46 unsigned CpuFeatures::supported_ = 0; 46 unsigned CpuFeatures::supported_ = 0;
47 unsigned CpuFeatures::enabled_ = 0; 47 unsigned CpuFeatures::enabled_ = 0;
48 unsigned CpuFeatures::found_by_runtime_probing_ = 0; 48 unsigned CpuFeatures::found_by_runtime_probing_ = 0;
49 49
50 void CpuFeatures::Probe() { 50 void CpuFeatures::Probe() {
51 // If the compiler is allowed to use vfp then we can use vfp too in our 51 // If the compiler is allowed to use vfp then we can use vfp too in our
52 // code generation. 52 // code generation.
53 #if !defined(__arm__) 53 #if !defined(__arm__)
54 // For the simulator=arm build, always use VFP since the arm simulator has 54 // For the simulator=arm build, use VFP when FLAG_enable_vfp3 is enabled.
55 // VFP support. 55 if (FLAG_enable_vfp3) {
56 supported_ |= 1u << VFP3; 56 supported_ |= 1u << VFP3;
57 }
58 // For the simulator=arm build, use ARMv7 when FLAG_enable_armv7 is enabled
59 if (FLAG_enable_armv7) {
60 supported_ |= 1u << ARMv7;
61 }
57 #else 62 #else
58 if (Serializer::enabled()) { 63 if (Serializer::enabled()) {
59 supported_ |= OS::CpuFeaturesImpliedByPlatform(); 64 supported_ |= OS::CpuFeaturesImpliedByPlatform();
60 return; // No features if we might serialize. 65 return; // No features if we might serialize.
61 } 66 }
62 67
63 if (OS::ArmCpuHasFeature(VFP3)) { 68 if (OS::ArmCpuHasFeature(VFP3)) {
64 // This implementation also sets the VFP flags if 69 // This implementation also sets the VFP flags if
65 // runtime detection of VFP returns true. 70 // runtime detection of VFP returns true.
66 supported_ |= 1u << VFP3; 71 supported_ |= 1u << VFP3;
67 found_by_runtime_probing_ |= 1u << VFP3; 72 found_by_runtime_probing_ |= 1u << VFP3;
68 } 73 }
74
75 if (OS::ArmCpuHasFeature(ARMv7)) {
76 supported_ |= 1u << ARMv7;
77 found_by_runtime_probing_ |= 1u << ARMv7;
78 }
69 #endif 79 #endif
70 } 80 }
71 81
72 82
73 // ----------------------------------------------------------------------------- 83 // -----------------------------------------------------------------------------
74 // Implementation of Register and CRegister 84 // Implementation of Register and CRegister
75 85
76 Register no_reg = { -1 }; 86 Register no_reg = { -1 };
77 87
78 Register r0 = { 0 }; 88 Register r0 = { 0 };
79 Register r1 = { 1 }; 89 Register r1 = { 1 };
80 Register r2 = { 2 }; 90 Register r2 = { 2 };
81 Register r3 = { 3 }; 91 Register r3 = { 3 };
82 Register r4 = { 4 }; 92 Register r4 = { 4 };
83 Register r5 = { 5 }; 93 Register r5 = { 5 };
84 Register r6 = { 6 }; 94 Register r6 = { 6 };
85 Register r7 = { 7 }; 95 Register r7 = { 7 };
86 Register r8 = { 8 }; 96 Register r8 = { 8 }; // Used as context register.
87 Register r9 = { 9 }; 97 Register r9 = { 9 };
88 Register r10 = { 10 }; 98 Register r10 = { 10 }; // Used as roots register.
89 Register fp = { 11 }; 99 Register fp = { 11 };
90 Register ip = { 12 }; 100 Register ip = { 12 };
91 Register sp = { 13 }; 101 Register sp = { 13 };
92 Register lr = { 14 }; 102 Register lr = { 14 };
93 Register pc = { 15 }; 103 Register pc = { 15 };
94 104
95 105
96 CRegister no_creg = { -1 }; 106 CRegister no_creg = { -1 };
97 107
98 CRegister cr0 = { 0 }; 108 CRegister cr0 = { 0 };
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 ASSERT(is_uint5(shift_imm)); 267 ASSERT(is_uint5(shift_imm));
258 rn_ = rn; 268 rn_ = rn;
259 rm_ = rm; 269 rm_ = rm;
260 shift_op_ = shift_op; 270 shift_op_ = shift_op;
261 shift_imm_ = shift_imm & 31; 271 shift_imm_ = shift_imm & 31;
262 am_ = am; 272 am_ = am;
263 } 273 }
264 274
265 275
266 // ----------------------------------------------------------------------------- 276 // -----------------------------------------------------------------------------
267 // Implementation of Assembler 277 // Implementation of Assembler.
268 278
269 // Instruction encoding bits 279 // Instruction encoding bits.
270 enum { 280 enum {
271 H = 1 << 5, // halfword (or byte) 281 H = 1 << 5, // halfword (or byte)
272 S6 = 1 << 6, // signed (or unsigned) 282 S6 = 1 << 6, // signed (or unsigned)
273 L = 1 << 20, // load (or store) 283 L = 1 << 20, // load (or store)
274 S = 1 << 20, // set condition code (or leave unchanged) 284 S = 1 << 20, // set condition code (or leave unchanged)
275 W = 1 << 21, // writeback base register (or leave unchanged) 285 W = 1 << 21, // writeback base register (or leave unchanged)
276 A = 1 << 21, // accumulate in multiply instruction (or not) 286 A = 1 << 21, // accumulate in multiply instruction (or not)
277 B = 1 << 22, // unsigned byte (or word) 287 B = 1 << 22, // unsigned byte (or word)
278 N = 1 << 22, // long (or short) 288 N = 1 << 22, // long (or short)
279 U = 1 << 23, // positive (or negative) offset/index 289 U = 1 << 23, // positive (or negative) offset/index
(...skipping 12 matching lines...) Expand all
292 B19 = 1 << 19, 302 B19 = 1 << 19,
293 B20 = 1 << 20, 303 B20 = 1 << 20,
294 B21 = 1 << 21, 304 B21 = 1 << 21,
295 B22 = 1 << 22, 305 B22 = 1 << 22,
296 B23 = 1 << 23, 306 B23 = 1 << 23,
297 B24 = 1 << 24, 307 B24 = 1 << 24,
298 B25 = 1 << 25, 308 B25 = 1 << 25,
299 B26 = 1 << 26, 309 B26 = 1 << 26,
300 B27 = 1 << 27, 310 B27 = 1 << 27,
301 311
302 // Instruction bit masks 312 // Instruction bit masks.
303 RdMask = 15 << 12, // in str instruction 313 RdMask = 15 << 12, // in str instruction
304 CondMask = 15 << 28, 314 CondMask = 15 << 28,
305 CoprocessorMask = 15 << 8, 315 CoprocessorMask = 15 << 8,
306 OpCodeMask = 15 << 21, // in data-processing instructions 316 OpCodeMask = 15 << 21, // in data-processing instructions
307 Imm24Mask = (1 << 24) - 1, 317 Imm24Mask = (1 << 24) - 1,
308 Off12Mask = (1 << 12) - 1, 318 Off12Mask = (1 << 12) - 1,
309 // Reserved condition 319 // Reserved condition.
310 nv = 15 << 28 320 nv = 15 << 28
311 }; 321 };
312 322
313 323
314 // add(sp, sp, 4) instruction (aka Pop()) 324 // add(sp, sp, 4) instruction (aka Pop())
315 static const Instr kPopInstruction = 325 static const Instr kPopInstruction =
316 al | 4 * B21 | 4 | LeaveCC | I | sp.code() * B16 | sp.code() * B12; 326 al | 4 * B21 | 4 | LeaveCC | I | sp.code() * B16 | sp.code() * B12;
317 // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r)) 327 // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r))
318 // register r is not encoded. 328 // register r is not encoded.
319 static const Instr kPushRegPattern = 329 static const Instr kPushRegPattern =
320 al | B26 | 4 | NegPreIndex | sp.code() * B16; 330 al | B26 | 4 | NegPreIndex | sp.code() * B16;
321 // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r)) 331 // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r))
322 // register r is not encoded. 332 // register r is not encoded.
323 static const Instr kPopRegPattern = 333 static const Instr kPopRegPattern =
324 al | B26 | L | 4 | PostIndex | sp.code() * B16; 334 al | B26 | L | 4 | PostIndex | sp.code() * B16;
325 // mov lr, pc 335 // mov lr, pc
326 const Instr kMovLrPc = al | 13*B21 | pc.code() | lr.code() * B12; 336 const Instr kMovLrPc = al | 13*B21 | pc.code() | lr.code() * B12;
327 // ldr pc, [pc, #XXX] 337 // ldr pc, [pc, #XXX]
328 const Instr kLdrPCPattern = al | B26 | L | pc.code() * B16; 338 const Instr kLdrPCPattern = al | B26 | L | pc.code() * B16;
329 339
330 // spare_buffer_ 340 // Spare buffer.
331 static const int kMinimalBufferSize = 4*KB; 341 static const int kMinimalBufferSize = 4*KB;
332 static byte* spare_buffer_ = NULL; 342 static byte* spare_buffer_ = NULL;
333 343
334 Assembler::Assembler(void* buffer, int buffer_size) { 344 Assembler::Assembler(void* buffer, int buffer_size) {
335 if (buffer == NULL) { 345 if (buffer == NULL) {
336 // do our own buffer management 346 // Do our own buffer management.
337 if (buffer_size <= kMinimalBufferSize) { 347 if (buffer_size <= kMinimalBufferSize) {
338 buffer_size = kMinimalBufferSize; 348 buffer_size = kMinimalBufferSize;
339 349
340 if (spare_buffer_ != NULL) { 350 if (spare_buffer_ != NULL) {
341 buffer = spare_buffer_; 351 buffer = spare_buffer_;
342 spare_buffer_ = NULL; 352 spare_buffer_ = NULL;
343 } 353 }
344 } 354 }
345 if (buffer == NULL) { 355 if (buffer == NULL) {
346 buffer_ = NewArray<byte>(buffer_size); 356 buffer_ = NewArray<byte>(buffer_size);
347 } else { 357 } else {
348 buffer_ = static_cast<byte*>(buffer); 358 buffer_ = static_cast<byte*>(buffer);
349 } 359 }
350 buffer_size_ = buffer_size; 360 buffer_size_ = buffer_size;
351 own_buffer_ = true; 361 own_buffer_ = true;
352 362
353 } else { 363 } else {
354 // use externally provided buffer instead 364 // Use externally provided buffer instead.
355 ASSERT(buffer_size > 0); 365 ASSERT(buffer_size > 0);
356 buffer_ = static_cast<byte*>(buffer); 366 buffer_ = static_cast<byte*>(buffer);
357 buffer_size_ = buffer_size; 367 buffer_size_ = buffer_size;
358 own_buffer_ = false; 368 own_buffer_ = false;
359 } 369 }
360 370
361 // setup buffer pointers 371 // Setup buffer pointers.
362 ASSERT(buffer_ != NULL); 372 ASSERT(buffer_ != NULL);
363 pc_ = buffer_; 373 pc_ = buffer_;
364 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); 374 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_);
365 num_prinfo_ = 0; 375 num_prinfo_ = 0;
366 next_buffer_check_ = 0; 376 next_buffer_check_ = 0;
367 no_const_pool_before_ = 0; 377 no_const_pool_before_ = 0;
368 last_const_pool_end_ = 0; 378 last_const_pool_end_ = 0;
369 last_bound_pos_ = 0; 379 last_bound_pos_ = 0;
370 current_statement_position_ = RelocInfo::kNoPosition; 380 current_statement_position_ = RelocInfo::kNoPosition;
371 current_position_ = RelocInfo::kNoPosition; 381 current_position_ = RelocInfo::kNoPosition;
372 written_statement_position_ = current_statement_position_; 382 written_statement_position_ = current_statement_position_;
373 written_position_ = current_position_; 383 written_position_ = current_position_;
374 } 384 }
375 385
376 386
377 Assembler::~Assembler() { 387 Assembler::~Assembler() {
378 if (own_buffer_) { 388 if (own_buffer_) {
379 if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) { 389 if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) {
380 spare_buffer_ = buffer_; 390 spare_buffer_ = buffer_;
381 } else { 391 } else {
382 DeleteArray(buffer_); 392 DeleteArray(buffer_);
383 } 393 }
384 } 394 }
385 } 395 }
386 396
387 397
388 void Assembler::GetCode(CodeDesc* desc) { 398 void Assembler::GetCode(CodeDesc* desc) {
389 // emit constant pool if necessary 399 // Emit constant pool if necessary.
390 CheckConstPool(true, false); 400 CheckConstPool(true, false);
391 ASSERT(num_prinfo_ == 0); 401 ASSERT(num_prinfo_ == 0);
392 402
393 // setup desc 403 // Setup code descriptor.
394 desc->buffer = buffer_; 404 desc->buffer = buffer_;
395 desc->buffer_size = buffer_size_; 405 desc->buffer_size = buffer_size_;
396 desc->instr_size = pc_offset(); 406 desc->instr_size = pc_offset();
397 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); 407 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
398 } 408 }
399 409
400 410
401 void Assembler::Align(int m) { 411 void Assembler::Align(int m) {
402 ASSERT(m >= 4 && IsPowerOf2(m)); 412 ASSERT(m >= 4 && IsPowerOf2(m));
403 while ((pc_offset() & (m - 1)) != 0) { 413 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 542 // Keep track of the last bound label so we don't eliminate any instructions
533 // before a bound label. 543 // before a bound label.
534 if (pos > last_bound_pos_) 544 if (pos > last_bound_pos_)
535 last_bound_pos_ = pos; 545 last_bound_pos_ = pos;
536 } 546 }
537 547
538 548
539 void Assembler::link_to(Label* L, Label* appendix) { 549 void Assembler::link_to(Label* L, Label* appendix) {
540 if (appendix->is_linked()) { 550 if (appendix->is_linked()) {
541 if (L->is_linked()) { 551 if (L->is_linked()) {
542 // append appendix to L's list 552 // Append appendix to L's list.
543 int fixup_pos; 553 int fixup_pos;
544 int link = L->pos(); 554 int link = L->pos();
545 do { 555 do {
546 fixup_pos = link; 556 fixup_pos = link;
547 link = target_at(fixup_pos); 557 link = target_at(fixup_pos);
548 } while (link > 0); 558 } while (link > 0);
549 ASSERT(link == kEndOfChain); 559 ASSERT(link == kEndOfChain);
550 target_at_put(fixup_pos, appendix->pos()); 560 target_at_put(fixup_pos, appendix->pos());
551 } else { 561 } else {
552 // L is empty, simply use appendix 562 // L is empty, simply use appendix.
553 *L = *appendix; 563 *L = *appendix;
554 } 564 }
555 } 565 }
556 appendix->Unuse(); // appendix should not be used anymore 566 appendix->Unuse(); // appendix should not be used anymore
557 } 567 }
558 568
559 569
560 void Assembler::bind(Label* L) { 570 void Assembler::bind(Label* L) {
561 ASSERT(!L->is_bound()); // label can only be bound once 571 ASSERT(!L->is_bound()); // label can only be bound once
562 bind_to(L, pc_offset()); 572 bind_to(L, pc_offset());
563 } 573 }
564 574
565 575
566 void Assembler::next(Label* L) { 576 void Assembler::next(Label* L) {
567 ASSERT(L->is_linked()); 577 ASSERT(L->is_linked());
568 int link = target_at(L->pos()); 578 int link = target_at(L->pos());
569 if (link > 0) { 579 if (link > 0) {
570 L->link_to(link); 580 L->link_to(link);
571 } else { 581 } else {
572 ASSERT(link == kEndOfChain); 582 ASSERT(link == kEndOfChain);
573 L->Unuse(); 583 L->Unuse();
574 } 584 }
575 } 585 }
576 586
577 587
578 // Low-level code emission routines depending on the addressing mode 588 // Low-level code emission routines depending on the addressing mode.
579 static bool fits_shifter(uint32_t imm32, 589 static bool fits_shifter(uint32_t imm32,
580 uint32_t* rotate_imm, 590 uint32_t* rotate_imm,
581 uint32_t* immed_8, 591 uint32_t* immed_8,
582 Instr* instr) { 592 Instr* instr) {
583 // imm32 must be unsigned 593 // imm32 must be unsigned.
584 for (int rot = 0; rot < 16; rot++) { 594 for (int rot = 0; rot < 16; rot++) {
585 uint32_t imm8 = (imm32 << 2*rot) | (imm32 >> (32 - 2*rot)); 595 uint32_t imm8 = (imm32 << 2*rot) | (imm32 >> (32 - 2*rot));
586 if ((imm8 <= 0xff)) { 596 if ((imm8 <= 0xff)) {
587 *rotate_imm = rot; 597 *rotate_imm = rot;
588 *immed_8 = imm8; 598 *immed_8 = imm8;
589 return true; 599 return true;
590 } 600 }
591 } 601 }
592 // if the opcode is mov or mvn and if ~imm32 fits, change the opcode 602 // If the opcode is mov or mvn and if ~imm32 fits, change the opcode.
593 if (instr != NULL && (*instr & 0xd*B21) == 0xd*B21) { 603 if (instr != NULL && (*instr & 0xd*B21) == 0xd*B21) {
594 if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) { 604 if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) {
595 *instr ^= 0x2*B21; 605 *instr ^= 0x2*B21;
596 return true; 606 return true;
597 } 607 }
598 } 608 }
599 return false; 609 return false;
600 } 610 }
601 611
602 612
(...skipping 16 matching lines...) Expand all
619 } 629 }
620 630
621 631
622 void Assembler::addrmod1(Instr instr, 632 void Assembler::addrmod1(Instr instr,
623 Register rn, 633 Register rn,
624 Register rd, 634 Register rd,
625 const Operand& x) { 635 const Operand& x) {
626 CheckBuffer(); 636 CheckBuffer();
627 ASSERT((instr & ~(CondMask | OpCodeMask | S)) == 0); 637 ASSERT((instr & ~(CondMask | OpCodeMask | S)) == 0);
628 if (!x.rm_.is_valid()) { 638 if (!x.rm_.is_valid()) {
629 // immediate 639 // Immediate.
630 uint32_t rotate_imm; 640 uint32_t rotate_imm;
631 uint32_t immed_8; 641 uint32_t immed_8;
632 if (MustUseIp(x.rmode_) || 642 if (MustUseIp(x.rmode_) ||
633 !fits_shifter(x.imm32_, &rotate_imm, &immed_8, &instr)) { 643 !fits_shifter(x.imm32_, &rotate_imm, &immed_8, &instr)) {
634 // The immediate operand cannot be encoded as a shifter operand, so load 644 // 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. 645 // 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 646 // However, if the original instruction is a 'mov rd, x' (not setting the
637 // condition code), then replace it with a 'ldr rd, [pc]' 647 // condition code), then replace it with a 'ldr rd, [pc]'.
638 RecordRelocInfo(x.rmode_, x.imm32_); 648 RecordRelocInfo(x.rmode_, x.imm32_);
639 CHECK(!rn.is(ip)); // rn should never be ip, or will be trashed 649 CHECK(!rn.is(ip)); // rn should never be ip, or will be trashed
640 Condition cond = static_cast<Condition>(instr & CondMask); 650 Condition cond = static_cast<Condition>(instr & CondMask);
641 if ((instr & ~CondMask) == 13*B21) { // mov, S not set 651 if ((instr & ~CondMask) == 13*B21) { // mov, S not set
642 ldr(rd, MemOperand(pc, 0), cond); 652 ldr(rd, MemOperand(pc, 0), cond);
643 } else { 653 } else {
644 ldr(ip, MemOperand(pc, 0), cond); 654 ldr(ip, MemOperand(pc, 0), cond);
645 addrmod1(instr, rn, rd, Operand(ip)); 655 addrmod1(instr, rn, rd, Operand(ip));
646 } 656 }
647 return; 657 return;
648 } 658 }
649 instr |= I | rotate_imm*B8 | immed_8; 659 instr |= I | rotate_imm*B8 | immed_8;
650 } else if (!x.rs_.is_valid()) { 660 } else if (!x.rs_.is_valid()) {
651 // immediate shift 661 // Immediate shift.
652 instr |= x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); 662 instr |= x.shift_imm_*B7 | x.shift_op_ | x.rm_.code();
653 } else { 663 } else {
654 // register shift 664 // Register shift.
655 ASSERT(!rn.is(pc) && !rd.is(pc) && !x.rm_.is(pc) && !x.rs_.is(pc)); 665 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(); 666 instr |= x.rs_.code()*B8 | x.shift_op_ | B4 | x.rm_.code();
657 } 667 }
658 emit(instr | rn.code()*B16 | rd.code()*B12); 668 emit(instr | rn.code()*B16 | rd.code()*B12);
659 if (rn.is(pc) || x.rm_.is(pc)) 669 if (rn.is(pc) || x.rm_.is(pc))
660 // block constant pool emission for one instruction after reading pc 670 // Block constant pool emission for one instruction after reading pc.
661 BlockConstPoolBefore(pc_offset() + kInstrSize); 671 BlockConstPoolBefore(pc_offset() + kInstrSize);
662 } 672 }
663 673
664 674
665 void Assembler::addrmod2(Instr instr, Register rd, const MemOperand& x) { 675 void Assembler::addrmod2(Instr instr, Register rd, const MemOperand& x) {
666 ASSERT((instr & ~(CondMask | B | L)) == B26); 676 ASSERT((instr & ~(CondMask | B | L)) == B26);
667 int am = x.am_; 677 int am = x.am_;
668 if (!x.rm_.is_valid()) { 678 if (!x.rm_.is_valid()) {
669 // immediate offset 679 // Immediate offset.
670 int offset_12 = x.offset_; 680 int offset_12 = x.offset_;
671 if (offset_12 < 0) { 681 if (offset_12 < 0) {
672 offset_12 = -offset_12; 682 offset_12 = -offset_12;
673 am ^= U; 683 am ^= U;
674 } 684 }
675 if (!is_uint12(offset_12)) { 685 if (!is_uint12(offset_12)) {
676 // immediate offset cannot be encoded, load it first to register ip 686 // 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 687 // 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))); 688 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip)));
679 mov(ip, Operand(x.offset_), LeaveCC, 689 mov(ip, Operand(x.offset_), LeaveCC,
680 static_cast<Condition>(instr & CondMask)); 690 static_cast<Condition>(instr & CondMask));
681 addrmod2(instr, rd, MemOperand(x.rn_, ip, x.am_)); 691 addrmod2(instr, rd, MemOperand(x.rn_, ip, x.am_));
682 return; 692 return;
683 } 693 }
684 ASSERT(offset_12 >= 0); // no masking needed 694 ASSERT(offset_12 >= 0); // no masking needed
685 instr |= offset_12; 695 instr |= offset_12;
686 } else { 696 } else {
687 // register offset (shift_imm_ and shift_op_ are 0) or scaled 697 // Register offset (shift_imm_ and shift_op_ are 0) or scaled
688 // register offset the constructors make sure than both shift_imm_ 698 // register offset the constructors make sure than both shift_imm_
689 // and shift_op_ are initialized 699 // and shift_op_ are initialized.
690 ASSERT(!x.rm_.is(pc)); 700 ASSERT(!x.rm_.is(pc));
691 instr |= B25 | x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); 701 instr |= B25 | x.shift_imm_*B7 | x.shift_op_ | x.rm_.code();
692 } 702 }
693 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback 703 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); 704 emit(instr | am | x.rn_.code()*B16 | rd.code()*B12);
695 } 705 }
696 706
697 707
698 void Assembler::addrmod3(Instr instr, Register rd, const MemOperand& x) { 708 void Assembler::addrmod3(Instr instr, Register rd, const MemOperand& x) {
699 ASSERT((instr & ~(CondMask | L | S6 | H)) == (B4 | B7)); 709 ASSERT((instr & ~(CondMask | L | S6 | H)) == (B4 | B7));
700 ASSERT(x.rn_.is_valid()); 710 ASSERT(x.rn_.is_valid());
701 int am = x.am_; 711 int am = x.am_;
702 if (!x.rm_.is_valid()) { 712 if (!x.rm_.is_valid()) {
703 // immediate offset 713 // Immediate offset.
704 int offset_8 = x.offset_; 714 int offset_8 = x.offset_;
705 if (offset_8 < 0) { 715 if (offset_8 < 0) {
706 offset_8 = -offset_8; 716 offset_8 = -offset_8;
707 am ^= U; 717 am ^= U;
708 } 718 }
709 if (!is_uint8(offset_8)) { 719 if (!is_uint8(offset_8)) {
710 // immediate offset cannot be encoded, load it first to register ip 720 // 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 721 // 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))); 722 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip)));
713 mov(ip, Operand(x.offset_), LeaveCC, 723 mov(ip, Operand(x.offset_), LeaveCC,
714 static_cast<Condition>(instr & CondMask)); 724 static_cast<Condition>(instr & CondMask));
715 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); 725 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_));
716 return; 726 return;
717 } 727 }
718 ASSERT(offset_8 >= 0); // no masking needed 728 ASSERT(offset_8 >= 0); // no masking needed
719 instr |= B | (offset_8 >> 4)*B8 | (offset_8 & 0xf); 729 instr |= B | (offset_8 >> 4)*B8 | (offset_8 & 0xf);
720 } else if (x.shift_imm_ != 0) { 730 } else if (x.shift_imm_ != 0) {
721 // scaled register offset not supported, load index first 731 // Scaled register offset not supported, load index first
722 // rn (and rd in a load) should never be ip, or will be trashed 732 // 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))); 733 ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip)));
724 mov(ip, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC, 734 mov(ip, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC,
725 static_cast<Condition>(instr & CondMask)); 735 static_cast<Condition>(instr & CondMask));
726 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); 736 addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_));
727 return; 737 return;
728 } else { 738 } else {
729 // register offset 739 // Register offset.
730 ASSERT((am & (P|W)) == P || !x.rm_.is(pc)); // no pc index with writeback 740 ASSERT((am & (P|W)) == P || !x.rm_.is(pc)); // no pc index with writeback
731 instr |= x.rm_.code(); 741 instr |= x.rm_.code();
732 } 742 }
733 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback 743 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); 744 emit(instr | am | x.rn_.code()*B16 | rd.code()*B12);
735 } 745 }
736 746
737 747
738 void Assembler::addrmod4(Instr instr, Register rn, RegList rl) { 748 void Assembler::addrmod4(Instr instr, Register rn, RegList rl) {
739 ASSERT((instr & ~(CondMask | P | U | W | L)) == B27); 749 ASSERT((instr & ~(CondMask | P | U | W | L)) == B27);
740 ASSERT(rl != 0); 750 ASSERT(rl != 0);
741 ASSERT(!rn.is(pc)); 751 ASSERT(!rn.is(pc));
742 emit(instr | rn.code()*B16 | rl); 752 emit(instr | rn.code()*B16 | rl);
743 } 753 }
744 754
745 755
746 void Assembler::addrmod5(Instr instr, CRegister crd, const MemOperand& x) { 756 void Assembler::addrmod5(Instr instr, CRegister crd, const MemOperand& x) {
747 // unindexed addressing is not encoded by this function 757 // Unindexed addressing is not encoded by this function.
748 ASSERT_EQ((B27 | B26), 758 ASSERT_EQ((B27 | B26),
749 (instr & ~(CondMask | CoprocessorMask | P | U | N | W | L))); 759 (instr & ~(CondMask | CoprocessorMask | P | U | N | W | L)));
750 ASSERT(x.rn_.is_valid() && !x.rm_.is_valid()); 760 ASSERT(x.rn_.is_valid() && !x.rm_.is_valid());
751 int am = x.am_; 761 int am = x.am_;
752 int offset_8 = x.offset_; 762 int offset_8 = x.offset_;
753 ASSERT((offset_8 & 3) == 0); // offset must be an aligned word offset 763 ASSERT((offset_8 & 3) == 0); // offset must be an aligned word offset
754 offset_8 >>= 2; 764 offset_8 >>= 2;
755 if (offset_8 < 0) { 765 if (offset_8 < 0) {
756 offset_8 = -offset_8; 766 offset_8 = -offset_8;
757 am ^= U; 767 am ^= U;
758 } 768 }
759 ASSERT(is_uint8(offset_8)); // unsigned word offset must fit in a byte 769 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 770 ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback
761 771
762 // post-indexed addressing requires W == 1; different than in addrmod2/3 772 // Post-indexed addressing requires W == 1; different than in addrmod2/3.
763 if ((am & P) == 0) 773 if ((am & P) == 0)
764 am |= W; 774 am |= W;
765 775
766 ASSERT(offset_8 >= 0); // no masking needed 776 ASSERT(offset_8 >= 0); // no masking needed
767 emit(instr | am | x.rn_.code()*B16 | crd.code()*B12 | offset_8); 777 emit(instr | am | x.rn_.code()*B16 | crd.code()*B12 | offset_8);
768 } 778 }
769 779
770 780
771 int Assembler::branch_offset(Label* L, bool jump_elimination_allowed) { 781 int Assembler::branch_offset(Label* L, bool jump_elimination_allowed) {
772 int target_pos; 782 int target_pos;
773 if (L->is_bound()) { 783 if (L->is_bound()) {
774 target_pos = L->pos(); 784 target_pos = L->pos();
775 } else { 785 } else {
776 if (L->is_linked()) { 786 if (L->is_linked()) {
777 target_pos = L->pos(); // L's link 787 target_pos = L->pos(); // L's link
778 } else { 788 } else {
779 target_pos = kEndOfChain; 789 target_pos = kEndOfChain;
780 } 790 }
781 L->link_to(pc_offset()); 791 L->link_to(pc_offset());
782 } 792 }
783 793
784 // Block the emission of the constant pool, since the branch instruction must 794 // Block the emission of the constant pool, since the branch instruction must
785 // be emitted at the pc offset recorded by the label 795 // be emitted at the pc offset recorded by the label.
786 BlockConstPoolBefore(pc_offset() + kInstrSize); 796 BlockConstPoolBefore(pc_offset() + kInstrSize);
787 return target_pos - (pc_offset() + kPcLoadDelta); 797 return target_pos - (pc_offset() + kPcLoadDelta);
788 } 798 }
789 799
790 800
791 void Assembler::label_at_put(Label* L, int at_offset) { 801 void Assembler::label_at_put(Label* L, int at_offset) {
792 int target_pos; 802 int target_pos;
793 if (L->is_bound()) { 803 if (L->is_bound()) {
794 target_pos = L->pos(); 804 target_pos = L->pos();
795 } else { 805 } else {
796 if (L->is_linked()) { 806 if (L->is_linked()) {
797 target_pos = L->pos(); // L's link 807 target_pos = L->pos(); // L's link
798 } else { 808 } else {
799 target_pos = kEndOfChain; 809 target_pos = kEndOfChain;
800 } 810 }
801 L->link_to(at_offset); 811 L->link_to(at_offset);
802 instr_at_put(at_offset, target_pos + (Code::kHeaderSize - kHeapObjectTag)); 812 instr_at_put(at_offset, target_pos + (Code::kHeaderSize - kHeapObjectTag));
803 } 813 }
804 } 814 }
805 815
806 816
807 // Branch instructions 817 // Branch instructions.
808 void Assembler::b(int branch_offset, Condition cond) { 818 void Assembler::b(int branch_offset, Condition cond) {
809 ASSERT((branch_offset & 3) == 0); 819 ASSERT((branch_offset & 3) == 0);
810 int imm24 = branch_offset >> 2; 820 int imm24 = branch_offset >> 2;
811 ASSERT(is_int24(imm24)); 821 ASSERT(is_int24(imm24));
812 emit(cond | B27 | B25 | (imm24 & Imm24Mask)); 822 emit(cond | B27 | B25 | (imm24 & Imm24Mask));
813 823
814 if (cond == al) 824 if (cond == al)
815 // dead code is a good location to emit the constant pool 825 // Dead code is a good location to emit the constant pool.
816 CheckConstPool(false, false); 826 CheckConstPool(false, false);
817 } 827 }
818 828
819 829
820 void Assembler::bl(int branch_offset, Condition cond) { 830 void Assembler::bl(int branch_offset, Condition cond) {
821 ASSERT((branch_offset & 3) == 0); 831 ASSERT((branch_offset & 3) == 0);
822 int imm24 = branch_offset >> 2; 832 int imm24 = branch_offset >> 2;
823 ASSERT(is_int24(imm24)); 833 ASSERT(is_int24(imm24));
824 emit(cond | B27 | B25 | B24 | (imm24 & Imm24Mask)); 834 emit(cond | B27 | B25 | B24 | (imm24 & Imm24Mask));
825 } 835 }
(...skipping 16 matching lines...) Expand all
842 } 852 }
843 853
844 854
845 void Assembler::bx(Register target, Condition cond) { // v5 and above, plus v4t 855 void Assembler::bx(Register target, Condition cond) { // v5 and above, plus v4t
846 WriteRecordedPositions(); 856 WriteRecordedPositions();
847 ASSERT(!target.is(pc)); // use of pc is actually allowed, but discouraged 857 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()); 858 emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | B4 | target.code());
849 } 859 }
850 860
851 861
852 // Data-processing instructions 862 // Data-processing instructions.
863
864 // UBFX <Rd>,<Rn>,#<lsb>,#<width - 1>
865 // Instruction details available in ARM DDI 0406A, A8-464.
866 // cond(31-28) | 01111(27-23)| 1(22) | 1(21) | widthm1(20-16) |
867 // Rd(15-12) | lsb(11-7) | 101(6-4) | Rn(3-0)
868 void Assembler::ubfx(Register dst, Register src1, const Operand& src2,
869 const Operand& src3, Condition cond) {
870 ASSERT(!src2.rm_.is_valid() && !src3.rm_.is_valid());
871 ASSERT(static_cast<uint32_t>(src2.imm32_) <= 0x1f);
872 ASSERT(static_cast<uint32_t>(src3.imm32_) <= 0x1f);
873 emit(cond | 0x3F*B21 | src3.imm32_*B16 |
874 dst.code()*B12 | src2.imm32_*B7 | 0x5*B4 | src1.code());
875 }
876
877
853 void Assembler::and_(Register dst, Register src1, const Operand& src2, 878 void Assembler::and_(Register dst, Register src1, const Operand& src2,
854 SBit s, Condition cond) { 879 SBit s, Condition cond) {
855 addrmod1(cond | 0*B21 | s, src1, dst, src2); 880 addrmod1(cond | 0*B21 | s, src1, dst, src2);
856 } 881 }
857 882
858 883
859 void Assembler::eor(Register dst, Register src1, const Operand& src2, 884 void Assembler::eor(Register dst, Register src1, const Operand& src2,
860 SBit s, Condition cond) { 885 SBit s, Condition cond) {
861 addrmod1(cond | 1*B21 | s, src1, dst, src2); 886 addrmod1(cond | 1*B21 | s, src1, dst, src2);
862 } 887 }
(...skipping 16 matching lines...) Expand all
879 addrmod1(cond | 4*B21 | s, src1, dst, src2); 904 addrmod1(cond | 4*B21 | s, src1, dst, src2);
880 905
881 // Eliminate pattern: push(r), pop() 906 // Eliminate pattern: push(r), pop()
882 // str(src, MemOperand(sp, 4, NegPreIndex), al); 907 // str(src, MemOperand(sp, 4, NegPreIndex), al);
883 // add(sp, sp, Operand(kPointerSize)); 908 // add(sp, sp, Operand(kPointerSize));
884 // Both instructions can be eliminated. 909 // Both instructions can be eliminated.
885 int pattern_size = 2 * kInstrSize; 910 int pattern_size = 2 * kInstrSize;
886 if (FLAG_push_pop_elimination && 911 if (FLAG_push_pop_elimination &&
887 last_bound_pos_ <= (pc_offset() - pattern_size) && 912 last_bound_pos_ <= (pc_offset() - pattern_size) &&
888 reloc_info_writer.last_pc() <= (pc_ - pattern_size) && 913 reloc_info_writer.last_pc() <= (pc_ - pattern_size) &&
889 // pattern 914 // Pattern.
890 instr_at(pc_ - 1 * kInstrSize) == kPopInstruction && 915 instr_at(pc_ - 1 * kInstrSize) == kPopInstruction &&
891 (instr_at(pc_ - 2 * kInstrSize) & ~RdMask) == kPushRegPattern) { 916 (instr_at(pc_ - 2 * kInstrSize) & ~RdMask) == kPushRegPattern) {
892 pc_ -= 2 * kInstrSize; 917 pc_ -= 2 * kInstrSize;
893 if (FLAG_print_push_pop_elimination) { 918 if (FLAG_print_push_pop_elimination) {
894 PrintF("%x push(reg)/pop() eliminated\n", pc_offset()); 919 PrintF("%x push(reg)/pop() eliminated\n", pc_offset());
895 } 920 }
896 } 921 }
897 } 922 }
898 923
899 924
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 SBit s, Condition cond) { 978 SBit s, Condition cond) {
954 addrmod1(cond | 14*B21 | s, src1, dst, src2); 979 addrmod1(cond | 14*B21 | s, src1, dst, src2);
955 } 980 }
956 981
957 982
958 void Assembler::mvn(Register dst, const Operand& src, SBit s, Condition cond) { 983 void Assembler::mvn(Register dst, const Operand& src, SBit s, Condition cond) {
959 addrmod1(cond | 15*B21 | s, r0, dst, src); 984 addrmod1(cond | 15*B21 | s, r0, dst, src);
960 } 985 }
961 986
962 987
963 // Multiply instructions 988 // Multiply instructions.
964 void Assembler::mla(Register dst, Register src1, Register src2, Register srcA, 989 void Assembler::mla(Register dst, Register src1, Register src2, Register srcA,
965 SBit s, Condition cond) { 990 SBit s, Condition cond) {
966 ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc) && !srcA.is(pc)); 991 ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc) && !srcA.is(pc));
967 emit(cond | A | s | dst.code()*B16 | srcA.code()*B12 | 992 emit(cond | A | s | dst.code()*B16 | srcA.code()*B12 |
968 src2.code()*B8 | B7 | B4 | src1.code()); 993 src2.code()*B8 | B7 | B4 | src1.code());
969 } 994 }
970 995
971 996
972 void Assembler::mul(Register dst, Register src1, Register src2, 997 void Assembler::mul(Register dst, Register src1, Register src2,
973 SBit s, Condition cond) { 998 SBit s, Condition cond) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 Register src2, 1047 Register src2,
1023 SBit s, 1048 SBit s,
1024 Condition cond) { 1049 Condition cond) {
1025 ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc)); 1050 ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc));
1026 ASSERT(!dstL.is(dstH)); 1051 ASSERT(!dstL.is(dstH));
1027 emit(cond | B23 | s | dstH.code()*B16 | dstL.code()*B12 | 1052 emit(cond | B23 | s | dstH.code()*B16 | dstL.code()*B12 |
1028 src2.code()*B8 | B7 | B4 | src1.code()); 1053 src2.code()*B8 | B7 | B4 | src1.code());
1029 } 1054 }
1030 1055
1031 1056
1032 // Miscellaneous arithmetic instructions 1057 // Miscellaneous arithmetic instructions.
1033 void Assembler::clz(Register dst, Register src, Condition cond) { 1058 void Assembler::clz(Register dst, Register src, Condition cond) {
1034 // v5 and above. 1059 // v5 and above.
1035 ASSERT(!dst.is(pc) && !src.is(pc)); 1060 ASSERT(!dst.is(pc) && !src.is(pc));
1036 emit(cond | B24 | B22 | B21 | 15*B16 | dst.code()*B12 | 1061 emit(cond | B24 | B22 | B21 | 15*B16 | dst.code()*B12 |
1037 15*B8 | B4 | src.code()); 1062 15*B8 | B4 | src.code());
1038 } 1063 }
1039 1064
1040 1065
1041 // Status register access instructions 1066 // Status register access instructions.
1042 void Assembler::mrs(Register dst, SRegister s, Condition cond) { 1067 void Assembler::mrs(Register dst, SRegister s, Condition cond) {
1043 ASSERT(!dst.is(pc)); 1068 ASSERT(!dst.is(pc));
1044 emit(cond | B24 | s | 15*B16 | dst.code()*B12); 1069 emit(cond | B24 | s | 15*B16 | dst.code()*B12);
1045 } 1070 }
1046 1071
1047 1072
1048 void Assembler::msr(SRegisterFieldMask fields, const Operand& src, 1073 void Assembler::msr(SRegisterFieldMask fields, const Operand& src,
1049 Condition cond) { 1074 Condition cond) {
1050 ASSERT(fields >= B16 && fields < B20); // at least one field set 1075 ASSERT(fields >= B16 && fields < B20); // at least one field set
1051 Instr instr; 1076 Instr instr;
1052 if (!src.rm_.is_valid()) { 1077 if (!src.rm_.is_valid()) {
1053 // immediate 1078 // Immediate.
1054 uint32_t rotate_imm; 1079 uint32_t rotate_imm;
1055 uint32_t immed_8; 1080 uint32_t immed_8;
1056 if (MustUseIp(src.rmode_) || 1081 if (MustUseIp(src.rmode_) ||
1057 !fits_shifter(src.imm32_, &rotate_imm, &immed_8, NULL)) { 1082 !fits_shifter(src.imm32_, &rotate_imm, &immed_8, NULL)) {
1058 // immediate operand cannot be encoded, load it first to register ip 1083 // Immediate operand cannot be encoded, load it first to register ip.
1059 RecordRelocInfo(src.rmode_, src.imm32_); 1084 RecordRelocInfo(src.rmode_, src.imm32_);
1060 ldr(ip, MemOperand(pc, 0), cond); 1085 ldr(ip, MemOperand(pc, 0), cond);
1061 msr(fields, Operand(ip), cond); 1086 msr(fields, Operand(ip), cond);
1062 return; 1087 return;
1063 } 1088 }
1064 instr = I | rotate_imm*B8 | immed_8; 1089 instr = I | rotate_imm*B8 | immed_8;
1065 } else { 1090 } else {
1066 ASSERT(!src.rs_.is_valid() && src.shift_imm_ == 0); // only rm allowed 1091 ASSERT(!src.rs_.is_valid() && src.shift_imm_ == 0); // only rm allowed
1067 instr = src.rm_.code(); 1092 instr = src.rm_.code();
1068 } 1093 }
1069 emit(cond | instr | B24 | B21 | fields | 15*B12); 1094 emit(cond | instr | B24 | B21 | fields | 15*B12);
1070 } 1095 }
1071 1096
1072 1097
1073 // Load/Store instructions 1098 // Load/Store instructions.
1074 void Assembler::ldr(Register dst, const MemOperand& src, Condition cond) { 1099 void Assembler::ldr(Register dst, const MemOperand& src, Condition cond) {
1075 if (dst.is(pc)) { 1100 if (dst.is(pc)) {
1076 WriteRecordedPositions(); 1101 WriteRecordedPositions();
1077 } 1102 }
1078 addrmod2(cond | B26 | L, dst, src); 1103 addrmod2(cond | B26 | L, dst, src);
1079 1104
1080 // Eliminate pattern: push(r), pop(r) 1105 // Eliminate pattern: push(r), pop(r)
1081 // str(r, MemOperand(sp, 4, NegPreIndex), al) 1106 // str(r, MemOperand(sp, 4, NegPreIndex), al)
1082 // ldr(r, MemOperand(sp, 4, PostIndex), al) 1107 // ldr(r, MemOperand(sp, 4, PostIndex), al)
1083 // Both instructions can be eliminated. 1108 // Both instructions can be eliminated.
1084 int pattern_size = 2 * kInstrSize; 1109 int pattern_size = 2 * kInstrSize;
1085 if (FLAG_push_pop_elimination && 1110 if (FLAG_push_pop_elimination &&
1086 last_bound_pos_ <= (pc_offset() - pattern_size) && 1111 last_bound_pos_ <= (pc_offset() - pattern_size) &&
1087 reloc_info_writer.last_pc() <= (pc_ - pattern_size) && 1112 reloc_info_writer.last_pc() <= (pc_ - pattern_size) &&
1088 // pattern 1113 // Pattern.
1089 instr_at(pc_ - 1 * kInstrSize) == (kPopRegPattern | dst.code() * B12) && 1114 instr_at(pc_ - 1 * kInstrSize) == (kPopRegPattern | dst.code() * B12) &&
1090 instr_at(pc_ - 2 * kInstrSize) == (kPushRegPattern | dst.code() * B12)) { 1115 instr_at(pc_ - 2 * kInstrSize) == (kPushRegPattern | dst.code() * B12)) {
1091 pc_ -= 2 * kInstrSize; 1116 pc_ -= 2 * kInstrSize;
1092 if (FLAG_print_push_pop_elimination) { 1117 if (FLAG_print_push_pop_elimination) {
1093 PrintF("%x push/pop (same reg) eliminated\n", pc_offset()); 1118 PrintF("%x push/pop (same reg) eliminated\n", pc_offset());
1094 } 1119 }
1095 } 1120 }
1096 } 1121 }
1097 1122
1098 1123
1099 void Assembler::str(Register src, const MemOperand& dst, Condition cond) { 1124 void Assembler::str(Register src, const MemOperand& dst, Condition cond) {
1100 addrmod2(cond | B26, src, dst); 1125 addrmod2(cond | B26, src, dst);
1101 1126
1102 // Eliminate pattern: pop(), push(r) 1127 // Eliminate pattern: pop(), push(r)
1103 // add sp, sp, #4 LeaveCC, al; str r, [sp, #-4], al 1128 // add sp, sp, #4 LeaveCC, al; str r, [sp, #-4], al
1104 // -> str r, [sp, 0], al 1129 // -> str r, [sp, 0], al
1105 int pattern_size = 2 * kInstrSize; 1130 int pattern_size = 2 * kInstrSize;
1106 if (FLAG_push_pop_elimination && 1131 if (FLAG_push_pop_elimination &&
1107 last_bound_pos_ <= (pc_offset() - pattern_size) && 1132 last_bound_pos_ <= (pc_offset() - pattern_size) &&
1108 reloc_info_writer.last_pc() <= (pc_ - pattern_size) && 1133 reloc_info_writer.last_pc() <= (pc_ - pattern_size) &&
1134 // Pattern.
1109 instr_at(pc_ - 1 * kInstrSize) == (kPushRegPattern | src.code() * B12) && 1135 instr_at(pc_ - 1 * kInstrSize) == (kPushRegPattern | src.code() * B12) &&
1110 instr_at(pc_ - 2 * kInstrSize) == kPopInstruction) { 1136 instr_at(pc_ - 2 * kInstrSize) == kPopInstruction) {
1111 pc_ -= 2 * kInstrSize; 1137 pc_ -= 2 * kInstrSize;
1112 emit(al | B26 | 0 | Offset | sp.code() * B16 | src.code() * B12); 1138 emit(al | B26 | 0 | Offset | sp.code() * B16 | src.code() * B12);
1113 if (FLAG_print_push_pop_elimination) { 1139 if (FLAG_print_push_pop_elimination) {
1114 PrintF("%x pop()/push(reg) eliminated\n", pc_offset()); 1140 PrintF("%x pop()/push(reg) eliminated\n", pc_offset());
1115 } 1141 }
1116 } 1142 }
1117 } 1143 }
1118 1144
(...skipping 21 matching lines...) Expand all
1140 void Assembler::ldrsb(Register dst, const MemOperand& src, Condition cond) { 1166 void Assembler::ldrsb(Register dst, const MemOperand& src, Condition cond) {
1141 addrmod3(cond | L | B7 | S6 | B4, dst, src); 1167 addrmod3(cond | L | B7 | S6 | B4, dst, src);
1142 } 1168 }
1143 1169
1144 1170
1145 void Assembler::ldrsh(Register dst, const MemOperand& src, Condition cond) { 1171 void Assembler::ldrsh(Register dst, const MemOperand& src, Condition cond) {
1146 addrmod3(cond | L | B7 | S6 | H | B4, dst, src); 1172 addrmod3(cond | L | B7 | S6 | H | B4, dst, src);
1147 } 1173 }
1148 1174
1149 1175
1150 // Load/Store multiple instructions 1176 // Load/Store multiple instructions.
1151 void Assembler::ldm(BlockAddrMode am, 1177 void Assembler::ldm(BlockAddrMode am,
1152 Register base, 1178 Register base,
1153 RegList dst, 1179 RegList dst,
1154 Condition cond) { 1180 Condition cond) {
1155 // ABI stack constraint: ldmxx base, {..sp..} base != sp is not restartable 1181 // ABI stack constraint: ldmxx base, {..sp..} base != sp is not restartable.
1156 ASSERT(base.is(sp) || (dst & sp.bit()) == 0); 1182 ASSERT(base.is(sp) || (dst & sp.bit()) == 0);
1157 1183
1158 addrmod4(cond | B27 | am | L, base, dst); 1184 addrmod4(cond | B27 | am | L, base, dst);
1159 1185
1160 // emit the constant pool after a function return implemented by ldm ..{..pc} 1186 // Emit the constant pool after a function return implemented by ldm ..{..pc}.
1161 if (cond == al && (dst & pc.bit()) != 0) { 1187 if (cond == al && (dst & pc.bit()) != 0) {
1162 // There is a slight chance that the ldm instruction was actually a call, 1188 // 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 1189 // 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 1190 // 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 1191 // 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. 1192 // the case, we emit a jump over the pool.
1167 CheckConstPool(true, no_const_pool_before_ == pc_offset() - kInstrSize); 1193 CheckConstPool(true, no_const_pool_before_ == pc_offset() - kInstrSize);
1168 } 1194 }
1169 } 1195 }
1170 1196
1171 1197
1172 void Assembler::stm(BlockAddrMode am, 1198 void Assembler::stm(BlockAddrMode am,
1173 Register base, 1199 Register base,
1174 RegList src, 1200 RegList src,
1175 Condition cond) { 1201 Condition cond) {
1176 addrmod4(cond | B27 | am, base, src); 1202 addrmod4(cond | B27 | am, base, src);
1177 } 1203 }
1178 1204
1179 1205
1180 // Semaphore instructions 1206 // Semaphore instructions.
1181 void Assembler::swp(Register dst, Register src, Register base, Condition cond) { 1207 void Assembler::swp(Register dst, Register src, Register base, Condition cond) {
1182 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc)); 1208 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc));
1183 ASSERT(!dst.is(base) && !src.is(base)); 1209 ASSERT(!dst.is(base) && !src.is(base));
1184 emit(cond | P | base.code()*B16 | dst.code()*B12 | 1210 emit(cond | P | base.code()*B16 | dst.code()*B12 |
1185 B7 | B4 | src.code()); 1211 B7 | B4 | src.code());
1186 } 1212 }
1187 1213
1188 1214
1189 void Assembler::swpb(Register dst, 1215 void Assembler::swpb(Register dst,
1190 Register src, 1216 Register src,
1191 Register base, 1217 Register base,
1192 Condition cond) { 1218 Condition cond) {
1193 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc)); 1219 ASSERT(!dst.is(pc) && !src.is(pc) && !base.is(pc));
1194 ASSERT(!dst.is(base) && !src.is(base)); 1220 ASSERT(!dst.is(base) && !src.is(base));
1195 emit(cond | P | B | base.code()*B16 | dst.code()*B12 | 1221 emit(cond | P | B | base.code()*B16 | dst.code()*B12 |
1196 B7 | B4 | src.code()); 1222 B7 | B4 | src.code());
1197 } 1223 }
1198 1224
1199 1225
1200 // Exception-generating instructions and debugging support 1226 // Exception-generating instructions and debugging support.
1201 void Assembler::stop(const char* msg) { 1227 void Assembler::stop(const char* msg) {
1202 #if !defined(__arm__) 1228 #if !defined(__arm__)
1203 // The simulator handles these special instructions and stops execution. 1229 // The simulator handles these special instructions and stops execution.
1204 emit(15 << 28 | ((intptr_t) msg)); 1230 emit(15 << 28 | ((intptr_t) msg));
1205 #else 1231 #else
1206 // Just issue a simple break instruction for now. Alternatively we could use 1232 // Just issue a simple break instruction for now. Alternatively we could use
1207 // the swi(0x9f0001) instruction on Linux. 1233 // the swi(0x9f0001) instruction on Linux.
1208 bkpt(0); 1234 bkpt(0);
1209 #endif 1235 #endif
1210 } 1236 }
1211 1237
1212 1238
1213 void Assembler::bkpt(uint32_t imm16) { // v5 and above 1239 void Assembler::bkpt(uint32_t imm16) { // v5 and above
1214 ASSERT(is_uint16(imm16)); 1240 ASSERT(is_uint16(imm16));
1215 emit(al | B24 | B21 | (imm16 >> 4)*B8 | 7*B4 | (imm16 & 0xf)); 1241 emit(al | B24 | B21 | (imm16 >> 4)*B8 | 7*B4 | (imm16 & 0xf));
1216 } 1242 }
1217 1243
1218 1244
1219 void Assembler::swi(uint32_t imm24, Condition cond) { 1245 void Assembler::swi(uint32_t imm24, Condition cond) {
1220 ASSERT(is_uint24(imm24)); 1246 ASSERT(is_uint24(imm24));
1221 emit(cond | 15*B24 | imm24); 1247 emit(cond | 15*B24 | imm24);
1222 } 1248 }
1223 1249
1224 1250
1225 // Coprocessor instructions 1251 // Coprocessor instructions.
1226 void Assembler::cdp(Coprocessor coproc, 1252 void Assembler::cdp(Coprocessor coproc,
1227 int opcode_1, 1253 int opcode_1,
1228 CRegister crd, 1254 CRegister crd,
1229 CRegister crn, 1255 CRegister crn,
1230 CRegister crm, 1256 CRegister crm,
1231 int opcode_2, 1257 int opcode_2,
1232 Condition cond) { 1258 Condition cond) {
1233 ASSERT(is_uint4(opcode_1) && is_uint3(opcode_2)); 1259 ASSERT(is_uint4(opcode_1) && is_uint3(opcode_2));
1234 emit(cond | B27 | B26 | B25 | (opcode_1 & 15)*B20 | crn.code()*B16 | 1260 emit(cond | B27 | B26 | B25 | (opcode_1 & 15)*B20 | crn.code()*B16 |
1235 crd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | crm.code()); 1261 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); 1326 addrmod5(cond | B27 | B26 | l | L | coproc*B8, crd, src);
1301 } 1327 }
1302 1328
1303 1329
1304 void Assembler::ldc(Coprocessor coproc, 1330 void Assembler::ldc(Coprocessor coproc,
1305 CRegister crd, 1331 CRegister crd,
1306 Register rn, 1332 Register rn,
1307 int option, 1333 int option,
1308 LFlag l, 1334 LFlag l,
1309 Condition cond) { 1335 Condition cond) {
1310 // unindexed addressing 1336 // Unindexed addressing.
1311 ASSERT(is_uint8(option)); 1337 ASSERT(is_uint8(option));
1312 emit(cond | B27 | B26 | U | l | L | rn.code()*B16 | crd.code()*B12 | 1338 emit(cond | B27 | B26 | U | l | L | rn.code()*B16 | crd.code()*B12 |
1313 coproc*B8 | (option & 255)); 1339 coproc*B8 | (option & 255));
1314 } 1340 }
1315 1341
1316 1342
1317 void Assembler::ldc2(Coprocessor coproc, 1343 void Assembler::ldc2(Coprocessor coproc,
1318 CRegister crd, 1344 CRegister crd,
1319 const MemOperand& src, 1345 const MemOperand& src,
1320 LFlag l) { // v5 and above 1346 LFlag l) { // v5 and above
(...skipping 18 matching lines...) Expand all
1339 addrmod5(cond | B27 | B26 | l | coproc*B8, crd, dst); 1365 addrmod5(cond | B27 | B26 | l | coproc*B8, crd, dst);
1340 } 1366 }
1341 1367
1342 1368
1343 void Assembler::stc(Coprocessor coproc, 1369 void Assembler::stc(Coprocessor coproc,
1344 CRegister crd, 1370 CRegister crd,
1345 Register rn, 1371 Register rn,
1346 int option, 1372 int option,
1347 LFlag l, 1373 LFlag l,
1348 Condition cond) { 1374 Condition cond) {
1349 // unindexed addressing 1375 // Unindexed addressing.
1350 ASSERT(is_uint8(option)); 1376 ASSERT(is_uint8(option));
1351 emit(cond | B27 | B26 | U | l | rn.code()*B16 | crd.code()*B12 | 1377 emit(cond | B27 | B26 | U | l | rn.code()*B16 | crd.code()*B12 |
1352 coproc*B8 | (option & 255)); 1378 coproc*B8 | (option & 255));
1353 } 1379 }
1354 1380
1355 1381
1356 void Assembler::stc2(Coprocessor 1382 void Assembler::stc2(Coprocessor
1357 coproc, CRegister crd, 1383 coproc, CRegister crd,
1358 const MemOperand& dst, 1384 const MemOperand& dst,
1359 LFlag l) { // v5 and above 1385 LFlag l) { // v5 and above
1360 stc(coproc, crd, dst, l, static_cast<Condition>(nv)); 1386 stc(coproc, crd, dst, l, static_cast<Condition>(nv));
1361 } 1387 }
1362 1388
1363 1389
1364 void Assembler::stc2(Coprocessor coproc, 1390 void Assembler::stc2(Coprocessor coproc,
1365 CRegister crd, 1391 CRegister crd,
1366 Register rn, 1392 Register rn,
1367 int option, 1393 int option,
1368 LFlag l) { // v5 and above 1394 LFlag l) { // v5 and above
1369 stc(coproc, crd, rn, option, l, static_cast<Condition>(nv)); 1395 stc(coproc, crd, rn, option, l, static_cast<Condition>(nv));
1370 } 1396 }
1371 1397
1372 1398
1373 // Support for VFP. 1399 // Support for VFP.
1400 void Assembler::vldr(const DwVfpRegister dst,
1401 const Register base,
1402 int offset,
1403 const Condition cond) {
1404 // Ddst = MEM(Rbase + offset).
1405 // Instruction details available in ARM DDI 0406A, A8-628.
1406 // cond(31-28) | 1101(27-24)| 1001(23-20) | Rbase(19-16) |
1407 // Vdst(15-12) | 1011(11-8) | offset
1408 ASSERT(CpuFeatures::IsEnabled(VFP3));
1409 ASSERT(offset % 4 == 0);
1410 emit(cond | 0xD9*B20 | base.code()*B16 | dst.code()*B12 |
1411 0xB*B8 | ((offset / 4) & 255));
1412 }
1413
1414
1415 void Assembler::vstr(const DwVfpRegister src,
1416 const Register base,
1417 int offset,
1418 const Condition cond) {
1419 // MEM(Rbase + offset) = Dsrc.
1420 // Instruction details available in ARM DDI 0406A, A8-786.
1421 // cond(31-28) | 1101(27-24)| 1000(23-20) | | Rbase(19-16) |
1422 // Vsrc(15-12) | 1011(11-8) | (offset/4)
1423 ASSERT(CpuFeatures::IsEnabled(VFP3));
1424 ASSERT(offset % 4 == 0);
1425 emit(cond | 0xD8*B20 | base.code()*B16 | src.code()*B12 |
1426 0xB*B8 | ((offset / 4) & 255));
1427 }
1428
1429
1374 void Assembler::vmov(const DwVfpRegister dst, 1430 void Assembler::vmov(const DwVfpRegister dst,
1375 const Register src1, 1431 const Register src1,
1376 const Register src2, 1432 const Register src2,
1377 const Condition cond) { 1433 const Condition cond) {
1378 // Dm = <Rt,Rt2>. 1434 // Dm = <Rt,Rt2>.
1379 // Instruction details available in ARM DDI 0406A, A8-646. 1435 // Instruction details available in ARM DDI 0406A, A8-646.
1380 // cond(31-28) | 1100(27-24)| 010(23-21) | op=0(20) | Rt2(19-16) | 1436 // cond(31-28) | 1100(27-24)| 010(23-21) | op=0(20) | Rt2(19-16) |
1381 // Rt(15-12) | 1011(11-8) | 00(7-6) | M(5) | 1(4) | Vm 1437 // Rt(15-12) | 1011(11-8) | 00(7-6) | M(5) | 1(4) | Vm
1382 ASSERT(CpuFeatures::IsEnabled(VFP3)); 1438 ASSERT(CpuFeatures::IsEnabled(VFP3));
1383 ASSERT(!src1.is(pc) && !src2.is(pc)); 1439 ASSERT(!src1.is(pc) && !src2.is(pc));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 emit(cond | 0xE*B24 | B20 | (src.code() >> 1)*B16 | 1483 emit(cond | 0xE*B24 | B20 | (src.code() >> 1)*B16 |
1428 dst.code()*B12 | 0xA*B8 | (0x1 & src.code())*B7 | B4); 1484 dst.code()*B12 | 0xA*B8 | (0x1 & src.code())*B7 | B4);
1429 } 1485 }
1430 1486
1431 1487
1432 void Assembler::vcvt(const DwVfpRegister dst, 1488 void Assembler::vcvt(const DwVfpRegister dst,
1433 const SwVfpRegister src, 1489 const SwVfpRegister src,
1434 const Condition cond) { 1490 const Condition cond) {
1435 // Dd = Sm (integer in Sm converted to IEEE 64-bit doubles in Dd). 1491 // Dd = Sm (integer in Sm converted to IEEE 64-bit doubles in Dd).
1436 // Instruction details available in ARM DDI 0406A, A8-576. 1492 // Instruction details available in ARM DDI 0406A, A8-576.
1437 // cond(31-28) | 11101(27-23)| D=?(22) | 11(21-20) | 1(19) |opc2=000(18-16) | 1493 // cond(31-28) | 11101(27-23)| D=?(22) | 11(21-20) | 1(19) | opc2=000(18-16) |
1438 // Vd(15-12) | 101(11-9) | sz(8)=1 | op(7)=1 | 1(6) | M=?(5) | 0(4) | Vm(3-0) 1494 // Vd(15-12) | 101(11-9) | sz(8)=1 | op(7)=1 | 1(6) | M=?(5) | 0(4) | Vm(3-0)
1439 ASSERT(CpuFeatures::IsEnabled(VFP3)); 1495 ASSERT(CpuFeatures::IsEnabled(VFP3));
1440 emit(cond | 0xE*B24 | B23 | 0x3*B20 | B19 | 1496 emit(cond | 0xE*B24 | B23 | 0x3*B20 | B19 |
1441 dst.code()*B12 | 0x5*B9 | B8 | B7 | B6 | 1497 dst.code()*B12 | 0x5*B9 | B8 | B7 | B6 |
1442 (0x1 & src.code())*B5 | (src.code() >> 1)); 1498 (0x1 & src.code())*B5 | (src.code() >> 1));
1443 } 1499 }
1444 1500
1445 1501
1446 void Assembler::vcvt(const SwVfpRegister dst, 1502 void Assembler::vcvt(const SwVfpRegister dst,
1447 const DwVfpRegister src, 1503 const DwVfpRegister src,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 void Assembler::vmrs(Register dst, Condition cond) { 1590 void Assembler::vmrs(Register dst, Condition cond) {
1535 // Instruction details available in ARM DDI 0406A, A8-652. 1591 // Instruction details available in ARM DDI 0406A, A8-652.
1536 // cond(31-28) | 1110 (27-24) | 1111(23-20)| 0001 (19-16) | 1592 // cond(31-28) | 1110 (27-24) | 1111(23-20)| 0001 (19-16) |
1537 // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0) 1593 // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0)
1538 ASSERT(CpuFeatures::IsEnabled(VFP3)); 1594 ASSERT(CpuFeatures::IsEnabled(VFP3));
1539 emit(cond | 0xE*B24 | 0xF*B20 | B16 | 1595 emit(cond | 0xE*B24 | 0xF*B20 | B16 |
1540 dst.code()*B12 | 0xA*B8 | B4); 1596 dst.code()*B12 | 0xA*B8 | B4);
1541 } 1597 }
1542 1598
1543 1599
1544 // Pseudo instructions 1600 // Pseudo instructions.
1545 void Assembler::lea(Register dst, 1601 void Assembler::lea(Register dst,
1546 const MemOperand& x, 1602 const MemOperand& x,
1547 SBit s, 1603 SBit s,
1548 Condition cond) { 1604 Condition cond) {
1549 int am = x.am_; 1605 int am = x.am_;
1550 if (!x.rm_.is_valid()) { 1606 if (!x.rm_.is_valid()) {
1551 // immediate offset 1607 // Immediate offset.
1552 if ((am & P) == 0) // post indexing 1608 if ((am & P) == 0) // post indexing
1553 mov(dst, Operand(x.rn_), s, cond); 1609 mov(dst, Operand(x.rn_), s, cond);
1554 else if ((am & U) == 0) // negative indexing 1610 else if ((am & U) == 0) // negative indexing
1555 sub(dst, x.rn_, Operand(x.offset_), s, cond); 1611 sub(dst, x.rn_, Operand(x.offset_), s, cond);
1556 else 1612 else
1557 add(dst, x.rn_, Operand(x.offset_), s, cond); 1613 add(dst, x.rn_, Operand(x.offset_), s, cond);
1558 } else { 1614 } else {
1559 // Register offset (shift_imm_ and shift_op_ are 0) or scaled 1615 // Register offset (shift_imm_ and shift_op_ are 0) or scaled
1560 // register offset the constructors make sure than both shift_imm_ 1616 // register offset the constructors make sure than both shift_imm_
1561 // and shift_op_ are initialized. 1617 // and shift_op_ are initialized.
(...skipping 13 matching lines...) Expand all
1575 uint32_t dummy2; 1631 uint32_t dummy2;
1576 return fits_shifter(imm32, &dummy1, &dummy2, NULL); 1632 return fits_shifter(imm32, &dummy1, &dummy2, NULL);
1577 } 1633 }
1578 1634
1579 1635
1580 void Assembler::BlockConstPoolFor(int instructions) { 1636 void Assembler::BlockConstPoolFor(int instructions) {
1581 BlockConstPoolBefore(pc_offset() + instructions * kInstrSize); 1637 BlockConstPoolBefore(pc_offset() + instructions * kInstrSize);
1582 } 1638 }
1583 1639
1584 1640
1585 // Debugging 1641 // Debugging.
1586 void Assembler::RecordJSReturn() { 1642 void Assembler::RecordJSReturn() {
1587 WriteRecordedPositions(); 1643 WriteRecordedPositions();
1588 CheckBuffer(); 1644 CheckBuffer();
1589 RecordRelocInfo(RelocInfo::JS_RETURN); 1645 RecordRelocInfo(RelocInfo::JS_RETURN);
1590 } 1646 }
1591 1647
1592 1648
1593 void Assembler::RecordComment(const char* msg) { 1649 void Assembler::RecordComment(const char* msg) {
1594 if (FLAG_debug_code) { 1650 if (FLAG_debug_code) {
1595 CheckBuffer(); 1651 CheckBuffer();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 CheckBuffer(); 1684 CheckBuffer();
1629 RecordRelocInfo(RelocInfo::POSITION, current_position_); 1685 RecordRelocInfo(RelocInfo::POSITION, current_position_);
1630 written_position_ = current_position_; 1686 written_position_ = current_position_;
1631 } 1687 }
1632 } 1688 }
1633 1689
1634 1690
1635 void Assembler::GrowBuffer() { 1691 void Assembler::GrowBuffer() {
1636 if (!own_buffer_) FATAL("external code buffer is too small"); 1692 if (!own_buffer_) FATAL("external code buffer is too small");
1637 1693
1638 // compute new buffer size 1694 // Compute new buffer size.
1639 CodeDesc desc; // the new buffer 1695 CodeDesc desc; // the new buffer
1640 if (buffer_size_ < 4*KB) { 1696 if (buffer_size_ < 4*KB) {
1641 desc.buffer_size = 4*KB; 1697 desc.buffer_size = 4*KB;
1642 } else if (buffer_size_ < 1*MB) { 1698 } else if (buffer_size_ < 1*MB) {
1643 desc.buffer_size = 2*buffer_size_; 1699 desc.buffer_size = 2*buffer_size_;
1644 } else { 1700 } else {
1645 desc.buffer_size = buffer_size_ + 1*MB; 1701 desc.buffer_size = buffer_size_ + 1*MB;
1646 } 1702 }
1647 CHECK_GT(desc.buffer_size, 0); // no overflow 1703 CHECK_GT(desc.buffer_size, 0); // no overflow
1648 1704
1649 // setup new buffer 1705 // Setup new buffer.
1650 desc.buffer = NewArray<byte>(desc.buffer_size); 1706 desc.buffer = NewArray<byte>(desc.buffer_size);
1651 1707
1652 desc.instr_size = pc_offset(); 1708 desc.instr_size = pc_offset();
1653 desc.reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); 1709 desc.reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
1654 1710
1655 // copy the data 1711 // Copy the data.
1656 int pc_delta = desc.buffer - buffer_; 1712 int pc_delta = desc.buffer - buffer_;
1657 int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_); 1713 int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_);
1658 memmove(desc.buffer, buffer_, desc.instr_size); 1714 memmove(desc.buffer, buffer_, desc.instr_size);
1659 memmove(reloc_info_writer.pos() + rc_delta, 1715 memmove(reloc_info_writer.pos() + rc_delta,
1660 reloc_info_writer.pos(), desc.reloc_size); 1716 reloc_info_writer.pos(), desc.reloc_size);
1661 1717
1662 // switch buffers 1718 // Switch buffers.
1663 DeleteArray(buffer_); 1719 DeleteArray(buffer_);
1664 buffer_ = desc.buffer; 1720 buffer_ = desc.buffer;
1665 buffer_size_ = desc.buffer_size; 1721 buffer_size_ = desc.buffer_size;
1666 pc_ += pc_delta; 1722 pc_ += pc_delta;
1667 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, 1723 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
1668 reloc_info_writer.last_pc() + pc_delta); 1724 reloc_info_writer.last_pc() + pc_delta);
1669 1725
1670 // none of our relocation types are pc relative pointing outside the code 1726 // None of our relocation types are pc relative pointing outside the code
1671 // buffer nor pc absolute pointing inside the code buffer, so there is no need 1727 // buffer nor pc absolute pointing inside the code buffer, so there is no need
1672 // to relocate any emitted relocation entries 1728 // to relocate any emitted relocation entries.
1673 1729
1674 // relocate pending relocation entries 1730 // Relocate pending relocation entries.
1675 for (int i = 0; i < num_prinfo_; i++) { 1731 for (int i = 0; i < num_prinfo_; i++) {
1676 RelocInfo& rinfo = prinfo_[i]; 1732 RelocInfo& rinfo = prinfo_[i];
1677 ASSERT(rinfo.rmode() != RelocInfo::COMMENT && 1733 ASSERT(rinfo.rmode() != RelocInfo::COMMENT &&
1678 rinfo.rmode() != RelocInfo::POSITION); 1734 rinfo.rmode() != RelocInfo::POSITION);
1679 if (rinfo.rmode() != RelocInfo::JS_RETURN) { 1735 if (rinfo.rmode() != RelocInfo::JS_RETURN) {
1680 rinfo.set_pc(rinfo.pc() + pc_delta); 1736 rinfo.set_pc(rinfo.pc() + pc_delta);
1681 } 1737 }
1682 } 1738 }
1683 } 1739 }
1684 1740
1685 1741
1686 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { 1742 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
1687 RelocInfo rinfo(pc_, rmode, data); // we do not try to reuse pool constants 1743 RelocInfo rinfo(pc_, rmode, data); // we do not try to reuse pool constants
1688 if (rmode >= RelocInfo::JS_RETURN && rmode <= RelocInfo::STATEMENT_POSITION) { 1744 if (rmode >= RelocInfo::JS_RETURN && rmode <= RelocInfo::STATEMENT_POSITION) {
1689 // Adjust code for new modes 1745 // Adjust code for new modes.
1690 ASSERT(RelocInfo::IsJSReturn(rmode) 1746 ASSERT(RelocInfo::IsJSReturn(rmode)
1691 || RelocInfo::IsComment(rmode) 1747 || RelocInfo::IsComment(rmode)
1692 || RelocInfo::IsPosition(rmode)); 1748 || RelocInfo::IsPosition(rmode));
1693 // these modes do not need an entry in the constant pool 1749 // These modes do not need an entry in the constant pool.
1694 } else { 1750 } else {
1695 ASSERT(num_prinfo_ < kMaxNumPRInfo); 1751 ASSERT(num_prinfo_ < kMaxNumPRInfo);
1696 prinfo_[num_prinfo_++] = rinfo; 1752 prinfo_[num_prinfo_++] = rinfo;
1697 // Make sure the constant pool is not emitted in place of the next 1753 // Make sure the constant pool is not emitted in place of the next
1698 // instruction for which we just recorded relocation info 1754 // instruction for which we just recorded relocation info.
1699 BlockConstPoolBefore(pc_offset() + kInstrSize); 1755 BlockConstPoolBefore(pc_offset() + kInstrSize);
1700 } 1756 }
1701 if (rinfo.rmode() != RelocInfo::NONE) { 1757 if (rinfo.rmode() != RelocInfo::NONE) {
1702 // Don't record external references unless the heap will be serialized. 1758 // Don't record external references unless the heap will be serialized.
1703 if (rmode == RelocInfo::EXTERNAL_REFERENCE) { 1759 if (rmode == RelocInfo::EXTERNAL_REFERENCE) {
1704 #ifdef DEBUG 1760 #ifdef DEBUG
1705 if (!Serializer::enabled()) { 1761 if (!Serializer::enabled()) {
1706 Serializer::TooLateToEnableNow(); 1762 Serializer::TooLateToEnableNow();
1707 } 1763 }
1708 #endif 1764 #endif
1709 if (!Serializer::enabled() && !FLAG_debug_code) { 1765 if (!Serializer::enabled() && !FLAG_debug_code) {
1710 return; 1766 return;
1711 } 1767 }
1712 } 1768 }
1713 ASSERT(buffer_space() >= kMaxRelocSize); // too late to grow buffer here 1769 ASSERT(buffer_space() >= kMaxRelocSize); // too late to grow buffer here
1714 reloc_info_writer.Write(&rinfo); 1770 reloc_info_writer.Write(&rinfo);
1715 } 1771 }
1716 } 1772 }
1717 1773
1718 1774
1719 void Assembler::CheckConstPool(bool force_emit, bool require_jump) { 1775 void Assembler::CheckConstPool(bool force_emit, bool require_jump) {
1720 // Calculate the offset of the next check. It will be overwritten 1776 // Calculate the offset of the next check. It will be overwritten
1721 // when a const pool is generated or when const pools are being 1777 // when a const pool is generated or when const pools are being
1722 // blocked for a specific range. 1778 // blocked for a specific range.
1723 next_buffer_check_ = pc_offset() + kCheckConstInterval; 1779 next_buffer_check_ = pc_offset() + kCheckConstInterval;
1724 1780
1725 // There is nothing to do if there are no pending relocation info entries 1781 // There is nothing to do if there are no pending relocation info entries.
1726 if (num_prinfo_ == 0) return; 1782 if (num_prinfo_ == 0) return;
1727 1783
1728 // We emit a constant pool at regular intervals of about kDistBetweenPools 1784 // We emit a constant pool at regular intervals of about kDistBetweenPools
1729 // or when requested by parameter force_emit (e.g. after each function). 1785 // or when requested by parameter force_emit (e.g. after each function).
1730 // We prefer not to emit a jump unless the max distance is reached or if we 1786 // We prefer not to emit a jump unless the max distance is reached or if we
1731 // are running low on slots, which can happen if a lot of constants are being 1787 // are running low on slots, which can happen if a lot of constants are being
1732 // emitted (e.g. --debug-code and many static references). 1788 // emitted (e.g. --debug-code and many static references).
1733 int dist = pc_offset() - last_const_pool_end_; 1789 int dist = pc_offset() - last_const_pool_end_;
1734 if (!force_emit && dist < kMaxDistBetweenPools && 1790 if (!force_emit && dist < kMaxDistBetweenPools &&
1735 (require_jump || dist < kDistBetweenPools) && 1791 (require_jump || dist < kDistBetweenPools) &&
1736 // TODO(1236125): Cleanup the "magic" number below. We know that 1792 // TODO(1236125): Cleanup the "magic" number below. We know that
1737 // the code generation will test every kCheckConstIntervalInst. 1793 // the code generation will test every kCheckConstIntervalInst.
1738 // Thus we are safe as long as we generate less than 7 constant 1794 // Thus we are safe as long as we generate less than 7 constant
1739 // entries per instruction. 1795 // entries per instruction.
1740 (num_prinfo_ < (kMaxNumPRInfo - (7 * kCheckConstIntervalInst)))) { 1796 (num_prinfo_ < (kMaxNumPRInfo - (7 * kCheckConstIntervalInst)))) {
1741 return; 1797 return;
1742 } 1798 }
1743 1799
1744 // If we did not return by now, we need to emit the constant pool soon. 1800 // If we did not return by now, we need to emit the constant pool soon.
1745 1801
1746 // However, some small sequences of instructions must not be broken up by the 1802 // However, some small sequences of instructions must not be broken up by the
1747 // insertion of a constant pool; such sequences are protected by setting 1803 // insertion of a constant pool; such sequences are protected by setting
1748 // no_const_pool_before_, which is checked here. Also, recursive calls to 1804 // no_const_pool_before_, which is checked here. Also, recursive calls to
1749 // CheckConstPool are blocked by no_const_pool_before_. 1805 // CheckConstPool are blocked by no_const_pool_before_.
1750 if (pc_offset() < no_const_pool_before_) { 1806 if (pc_offset() < no_const_pool_before_) {
1751 // Emission is currently blocked; make sure we try again as soon as possible 1807 // Emission is currently blocked; make sure we try again as soon as
1808 // possible.
1752 next_buffer_check_ = no_const_pool_before_; 1809 next_buffer_check_ = no_const_pool_before_;
1753 1810
1754 // Something is wrong if emission is forced and blocked at the same time 1811 // Something is wrong if emission is forced and blocked at the same time.
1755 ASSERT(!force_emit); 1812 ASSERT(!force_emit);
1756 return; 1813 return;
1757 } 1814 }
1758 1815
1759 int jump_instr = require_jump ? kInstrSize : 0; 1816 int jump_instr = require_jump ? kInstrSize : 0;
1760 1817
1761 // Check that the code buffer is large enough before emitting the constant 1818 // Check that the code buffer is large enough before emitting the constant
1762 // pool and relocation information (include the jump over the pool and the 1819 // pool and relocation information (include the jump over the pool and the
1763 // constant pool marker). 1820 // constant pool marker).
1764 int max_needed_space = 1821 int max_needed_space =
1765 jump_instr + kInstrSize + num_prinfo_*(kInstrSize + kMaxRelocSize); 1822 jump_instr + kInstrSize + num_prinfo_*(kInstrSize + kMaxRelocSize);
1766 while (buffer_space() <= (max_needed_space + kGap)) GrowBuffer(); 1823 while (buffer_space() <= (max_needed_space + kGap)) GrowBuffer();
1767 1824
1768 // Block recursive calls to CheckConstPool 1825 // Block recursive calls to CheckConstPool.
1769 BlockConstPoolBefore(pc_offset() + jump_instr + kInstrSize + 1826 BlockConstPoolBefore(pc_offset() + jump_instr + kInstrSize +
1770 num_prinfo_*kInstrSize); 1827 num_prinfo_*kInstrSize);
1771 // Don't bother to check for the emit calls below. 1828 // Don't bother to check for the emit calls below.
1772 next_buffer_check_ = no_const_pool_before_; 1829 next_buffer_check_ = no_const_pool_before_;
1773 1830
1774 // Emit jump over constant pool if necessary 1831 // Emit jump over constant pool if necessary.
1775 Label after_pool; 1832 Label after_pool;
1776 if (require_jump) b(&after_pool); 1833 if (require_jump) b(&after_pool);
1777 1834
1778 RecordComment("[ Constant Pool"); 1835 RecordComment("[ Constant Pool");
1779 1836
1780 // Put down constant pool marker 1837 // Put down constant pool marker "Undefined instruction" as specified by
1781 // "Undefined instruction" as specified by A3.1 Instruction set encoding 1838 // A3.1 Instruction set encoding.
1782 emit(0x03000000 | num_prinfo_); 1839 emit(0x03000000 | num_prinfo_);
1783 1840
1784 // Emit constant pool entries 1841 // Emit constant pool entries.
1785 for (int i = 0; i < num_prinfo_; i++) { 1842 for (int i = 0; i < num_prinfo_; i++) {
1786 RelocInfo& rinfo = prinfo_[i]; 1843 RelocInfo& rinfo = prinfo_[i];
1787 ASSERT(rinfo.rmode() != RelocInfo::COMMENT && 1844 ASSERT(rinfo.rmode() != RelocInfo::COMMENT &&
1788 rinfo.rmode() != RelocInfo::POSITION && 1845 rinfo.rmode() != RelocInfo::POSITION &&
1789 rinfo.rmode() != RelocInfo::STATEMENT_POSITION); 1846 rinfo.rmode() != RelocInfo::STATEMENT_POSITION);
1790 Instr instr = instr_at(rinfo.pc()); 1847 Instr instr = instr_at(rinfo.pc());
1791 1848
1792 // Instruction to patch must be a ldr/str [pc, #offset] 1849 // Instruction to patch must be a ldr/str [pc, #offset].
1793 // P and U set, B and W clear, Rn == pc, offset12 still 0 1850 // P and U set, B and W clear, Rn == pc, offset12 still 0.
1794 ASSERT((instr & (7*B25 | P | U | B | W | 15*B16 | Off12Mask)) == 1851 ASSERT((instr & (7*B25 | P | U | B | W | 15*B16 | Off12Mask)) ==
1795 (2*B25 | P | U | pc.code()*B16)); 1852 (2*B25 | P | U | pc.code()*B16));
1796 int delta = pc_ - rinfo.pc() - 8; 1853 int delta = pc_ - rinfo.pc() - 8;
1797 ASSERT(delta >= -4); // instr could be ldr pc, [pc, #-4] followed by targ32 1854 ASSERT(delta >= -4); // instr could be ldr pc, [pc, #-4] followed by targ32
1798 if (delta < 0) { 1855 if (delta < 0) {
1799 instr &= ~U; 1856 instr &= ~U;
1800 delta = -delta; 1857 delta = -delta;
1801 } 1858 }
1802 ASSERT(is_uint12(delta)); 1859 ASSERT(is_uint12(delta));
1803 instr_at_put(rinfo.pc(), instr + delta); 1860 instr_at_put(rinfo.pc(), instr + delta);
1804 emit(rinfo.data()); 1861 emit(rinfo.data());
1805 } 1862 }
1806 num_prinfo_ = 0; 1863 num_prinfo_ = 0;
1807 last_const_pool_end_ = pc_offset(); 1864 last_const_pool_end_ = pc_offset();
1808 1865
1809 RecordComment("]"); 1866 RecordComment("]");
1810 1867
1811 if (after_pool.is_linked()) { 1868 if (after_pool.is_linked()) {
1812 bind(&after_pool); 1869 bind(&after_pool);
1813 } 1870 }
1814 1871
1815 // Since a constant pool was just emitted, move the check offset forward by 1872 // Since a constant pool was just emitted, move the check offset forward by
1816 // the standard interval. 1873 // the standard interval.
1817 next_buffer_check_ = pc_offset() + kCheckConstInterval; 1874 next_buffer_check_ = pc_offset() + kCheckConstInterval;
1818 } 1875 }
1819 1876
1820 1877
1821 } } // namespace v8::internal 1878 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/assembler-thumb2.h ('k') | src/arm/assembler-thumb2-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698