OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 // All Rights Reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions |
| 6 // are met: |
| 7 // |
| 8 // - Redistributions of source code must retain the above copyright notice, |
| 9 // this list of conditions and the following disclaimer. |
| 10 // |
| 11 // - Redistribution in binary form must reproduce the above copyright |
| 12 // notice, this list of conditions and the following disclaimer in the |
| 13 // documentation and/or other materials provided with the |
| 14 // distribution. |
| 15 // |
| 16 // - Neither the name of Sun Microsystems or the names of contributors may |
| 17 // be used to endorse or promote products derived from this software without |
| 18 // specific prior written permission. |
| 19 // |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 31 // OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
| 33 // The original source code covered by the above license above has been |
| 34 // modified significantly by Google Inc. |
| 35 // Copyright 2012 the V8 project authors. All rights reserved. |
| 36 |
| 37 // |
| 38 // Copyright IBM Corp. 2012, 2013. All rights reserved. |
| 39 // |
| 40 |
| 41 // A light-weight PPC Assembler |
| 42 // Generates user mode instructions for the PPC architecture up |
| 43 |
| 44 #ifndef V8_PPC_ASSEMBLER_PPC_H_ |
| 45 #define V8_PPC_ASSEMBLER_PPC_H_ |
| 46 |
| 47 #include <stdio.h> |
| 48 #include <vector> |
| 49 |
| 50 #include "src/assembler.h" |
| 51 #include "src/ppc/constants-ppc.h" |
| 52 #include "src/serialize.h" |
| 53 |
| 54 #define ABI_USES_FUNCTION_DESCRIPTORS \ |
| 55 (V8_HOST_ARCH_PPC && \ |
| 56 (V8_OS_AIX || \ |
| 57 (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN))) |
| 58 |
| 59 #define ABI_PASSES_HANDLES_IN_REGS \ |
| 60 (!V8_HOST_ARCH_PPC || V8_OS_AIX || V8_TARGET_ARCH_PPC64) |
| 61 |
| 62 #define ABI_RETURNS_HANDLES_IN_REGS \ |
| 63 (!V8_HOST_ARCH_PPC || V8_TARGET_LITTLE_ENDIAN) |
| 64 |
| 65 #define ABI_RETURNS_OBJECT_PAIRS_IN_REGS \ |
| 66 (!V8_HOST_ARCH_PPC || V8_TARGET_LITTLE_ENDIAN) |
| 67 |
| 68 #define ABI_TOC_ADDRESSABILITY_VIA_IP \ |
| 69 (V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC64 && \ |
| 70 V8_TARGET_LITTLE_ENDIAN) |
| 71 |
| 72 #if !V8_HOST_ARCH_PPC || V8_OS_AIX || V8_TARGET_ARCH_PPC64 |
| 73 #define ABI_TOC_REGISTER kRegister_r2_Code |
| 74 #else |
| 75 #define ABI_TOC_REGISTER kRegister_r13_Code |
| 76 #endif |
| 77 |
| 78 namespace v8 { |
| 79 namespace internal { |
| 80 |
| 81 // CPU Registers. |
| 82 // |
| 83 // 1) We would prefer to use an enum, but enum values are assignment- |
| 84 // compatible with int, which has caused code-generation bugs. |
| 85 // |
| 86 // 2) We would prefer to use a class instead of a struct but we don't like |
| 87 // the register initialization to depend on the particular initialization |
| 88 // order (which appears to be different on OS X, Linux, and Windows for the |
| 89 // installed versions of C++ we tried). Using a struct permits C-style |
| 90 // "initialization". Also, the Register objects cannot be const as this |
| 91 // forces initialization stubs in MSVC, making us dependent on initialization |
| 92 // order. |
| 93 // |
| 94 // 3) By not using an enum, we are possibly preventing the compiler from |
| 95 // doing certain constant folds, which may significantly reduce the |
| 96 // code generated for some assembly instructions (because they boil down |
| 97 // to a few constants). If this is a problem, we could change the code |
| 98 // such that we use an enum in optimized mode, and the struct in debug |
| 99 // mode. This way we get the compile-time error checking in debug mode |
| 100 // and best performance in optimized code. |
| 101 |
| 102 // Core register |
| 103 struct Register { |
| 104 static const int kNumRegisters = 32; |
| 105 static const int kMaxNumAllocatableRegisters = 9; // r3-r10 and cp |
| 106 static const int kSizeInBytes = kPointerSize; |
| 107 static const int kCpRegister = 18; // cp is r18 |
| 108 |
| 109 #if V8_TARGET_LITTLE_ENDIAN |
| 110 static const int kMantissaOffset = 0; |
| 111 static const int kExponentOffset = 4; |
| 112 #else |
| 113 static const int kMantissaOffset = 4; |
| 114 static const int kExponentOffset = 0; |
| 115 #endif |
| 116 |
| 117 inline static int NumAllocatableRegisters(); |
| 118 |
| 119 static int ToAllocationIndex(Register reg) { |
| 120 int index = reg.is(from_code(kCpRegister)) ? |
| 121 kMaxNumAllocatableRegisters - 1 : // Return last index for 'cp'. |
| 122 reg.code() - 3; // r0-r2 are skipped |
| 123 ASSERT(index < kMaxNumAllocatableRegisters); |
| 124 return index; |
| 125 } |
| 126 |
| 127 static Register FromAllocationIndex(int index) { |
| 128 ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters); |
| 129 return index == kMaxNumAllocatableRegisters - 1 ? |
| 130 from_code(kCpRegister) : // Last index is always the 'cp' register. |
| 131 from_code(index + 3); // r0-r2 are skipped |
| 132 } |
| 133 |
| 134 static const char* AllocationIndexToString(int index) { |
| 135 ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters); |
| 136 const char* const names[] = { |
| 137 "r3", |
| 138 "r4", |
| 139 "r5", |
| 140 "r6", |
| 141 "r7", |
| 142 "r8", |
| 143 "r9", |
| 144 "r10", |
| 145 "cp", |
| 146 }; |
| 147 return names[index]; |
| 148 } |
| 149 |
| 150 static Register from_code(int code) { |
| 151 Register r = { code }; |
| 152 return r; |
| 153 } |
| 154 |
| 155 bool is_valid() const { return 0 <= code_ && code_ < kNumRegisters; } |
| 156 bool is(Register reg) const { return code_ == reg.code_; } |
| 157 int code() const { |
| 158 ASSERT(is_valid()); |
| 159 return code_; |
| 160 } |
| 161 int bit() const { |
| 162 ASSERT(is_valid()); |
| 163 return 1 << code_; |
| 164 } |
| 165 |
| 166 void set_code(int code) { |
| 167 code_ = code; |
| 168 ASSERT(is_valid()); |
| 169 } |
| 170 |
| 171 // Unfortunately we can't make this private in a struct. |
| 172 int code_; |
| 173 }; |
| 174 |
| 175 // These constants are used in several locations, including static initializers |
| 176 const int kRegister_no_reg_Code = -1; |
| 177 const int kRegister_r0_Code = 0; |
| 178 const int kRegister_sp_Code = 1; |
| 179 const int kRegister_r2_Code = 2; // special on PowerPC |
| 180 const int kRegister_r3_Code = 3; |
| 181 const int kRegister_r4_Code = 4; |
| 182 const int kRegister_r5_Code = 5; |
| 183 const int kRegister_r6_Code = 6; |
| 184 const int kRegister_r7_Code = 7; |
| 185 const int kRegister_r8_Code = 8; |
| 186 const int kRegister_r9_Code = 9; |
| 187 const int kRegister_r10_Code = 10; |
| 188 const int kRegister_r11_Code = 11; |
| 189 const int kRegister_ip_Code = 12; |
| 190 const int kRegister_r13_Code = 13; |
| 191 const int kRegister_r14_Code = 14; |
| 192 const int kRegister_r15_Code = 15; |
| 193 |
| 194 const int kRegister_r16_Code = 16; |
| 195 const int kRegister_r17_Code = 17; |
| 196 const int kRegister_r18_Code = 18; |
| 197 const int kRegister_r19_Code = 19; |
| 198 const int kRegister_r20_Code = 20; |
| 199 const int kRegister_r21_Code = 21; |
| 200 const int kRegister_r22_Code = 22; |
| 201 const int kRegister_r23_Code = 23; |
| 202 const int kRegister_r24_Code = 24; |
| 203 const int kRegister_r25_Code = 25; |
| 204 const int kRegister_r26_Code = 26; |
| 205 const int kRegister_r27_Code = 27; |
| 206 const int kRegister_r28_Code = 28; |
| 207 const int kRegister_r29_Code = 29; |
| 208 const int kRegister_r30_Code = 30; |
| 209 const int kRegister_fp_Code = 31; |
| 210 |
| 211 const Register no_reg = { kRegister_no_reg_Code }; |
| 212 |
| 213 const Register r0 = { kRegister_r0_Code }; |
| 214 const Register sp = { kRegister_sp_Code }; |
| 215 const Register r2 = { kRegister_r2_Code }; |
| 216 const Register r3 = { kRegister_r3_Code }; |
| 217 const Register r4 = { kRegister_r4_Code }; |
| 218 const Register r5 = { kRegister_r5_Code }; |
| 219 const Register r6 = { kRegister_r6_Code }; |
| 220 const Register r7 = { kRegister_r7_Code }; |
| 221 const Register r8 = { kRegister_r8_Code }; |
| 222 const Register r9 = { kRegister_r9_Code }; |
| 223 const Register r10 = { kRegister_r10_Code }; |
| 224 const Register r11 = { kRegister_r11_Code }; |
| 225 const Register ip = { kRegister_ip_Code }; |
| 226 const Register r13 = { kRegister_r13_Code }; |
| 227 const Register r14 = { kRegister_r14_Code }; |
| 228 const Register r15 = { kRegister_r15_Code }; |
| 229 |
| 230 const Register r16 = { kRegister_r16_Code }; |
| 231 const Register r17 = { kRegister_r17_Code }; |
| 232 const Register r18 = { kRegister_r18_Code }; |
| 233 const Register r19 = { kRegister_r19_Code }; |
| 234 const Register r20 = { kRegister_r20_Code }; |
| 235 const Register r21 = { kRegister_r21_Code }; |
| 236 const Register r22 = { kRegister_r22_Code }; |
| 237 const Register r23 = { kRegister_r23_Code }; |
| 238 const Register r24 = { kRegister_r24_Code }; |
| 239 const Register r25 = { kRegister_r25_Code }; |
| 240 const Register r26 = { kRegister_r26_Code }; |
| 241 const Register r27 = { kRegister_r27_Code }; |
| 242 const Register r28 = { kRegister_r28_Code }; |
| 243 const Register r29 = { kRegister_r29_Code }; |
| 244 const Register r30 = { kRegister_r30_Code }; |
| 245 const Register fp = { kRegister_fp_Code }; |
| 246 |
| 247 // Give alias names to registers |
| 248 const Register cp = { kRegister_r18_Code }; // JavaScript context pointer |
| 249 const Register kRootRegister = { kRegister_r19_Code }; // Roots array pointer. |
| 250 #if V8_OOL_CONSTANT_POOL |
| 251 const Register kConstantPoolRegister = { kRegister_r20_Code }; // Constant pool |
| 252 #endif |
| 253 |
| 254 // Double word FP register. |
| 255 struct DoubleRegister { |
| 256 static const int kMaxNumRegisters = 32; |
| 257 static const int kNumVolatileRegisters = 14; // d0-d13 |
| 258 static const int kMaxNumAllocatableRegisters = 12; // d1-d12 |
| 259 static const int kSizeInBytes = 8; |
| 260 |
| 261 inline static int NumRegisters(); |
| 262 inline static int NumAllocatableRegisters(); |
| 263 inline static int ToAllocationIndex(DoubleRegister reg); |
| 264 static const char* AllocationIndexToString(int index); |
| 265 |
| 266 static DoubleRegister FromAllocationIndex(int index) { |
| 267 ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters); |
| 268 return from_code(index + 1); // d0 is skipped |
| 269 } |
| 270 |
| 271 static DoubleRegister from_code(int code) { |
| 272 DoubleRegister r = { code }; |
| 273 return r; |
| 274 } |
| 275 |
| 276 // Supporting d0 to d15, can be later extended to d31. |
| 277 bool is_valid() const { return 0 <= code_ && code_ < kMaxNumRegisters; } |
| 278 bool is(DoubleRegister reg) const { return code_ == reg.code_; } |
| 279 |
| 280 int code() const { |
| 281 ASSERT(is_valid()); |
| 282 return code_; |
| 283 } |
| 284 int bit() const { |
| 285 ASSERT(is_valid()); |
| 286 return 1 << code_; |
| 287 } |
| 288 void split_code(int* vm, int* m) const { |
| 289 ASSERT(is_valid()); |
| 290 *m = (code_ & 0x10) >> 4; |
| 291 *vm = code_ & 0x0F; |
| 292 } |
| 293 |
| 294 int code_; |
| 295 }; |
| 296 |
| 297 |
| 298 const DoubleRegister no_dreg = { -1 }; |
| 299 const DoubleRegister d0 = { 0 }; |
| 300 const DoubleRegister d1 = { 1 }; |
| 301 const DoubleRegister d2 = { 2 }; |
| 302 const DoubleRegister d3 = { 3 }; |
| 303 const DoubleRegister d4 = { 4 }; |
| 304 const DoubleRegister d5 = { 5 }; |
| 305 const DoubleRegister d6 = { 6 }; |
| 306 const DoubleRegister d7 = { 7 }; |
| 307 const DoubleRegister d8 = { 8 }; |
| 308 const DoubleRegister d9 = { 9 }; |
| 309 const DoubleRegister d10 = { 10 }; |
| 310 const DoubleRegister d11 = { 11 }; |
| 311 const DoubleRegister d12 = { 12 }; |
| 312 const DoubleRegister d13 = { 13 }; |
| 313 const DoubleRegister d14 = { 14 }; |
| 314 const DoubleRegister d15 = { 15 }; |
| 315 const DoubleRegister d16 = { 16 }; |
| 316 const DoubleRegister d17 = { 17 }; |
| 317 const DoubleRegister d18 = { 18 }; |
| 318 const DoubleRegister d19 = { 19 }; |
| 319 const DoubleRegister d20 = { 20 }; |
| 320 const DoubleRegister d21 = { 21 }; |
| 321 const DoubleRegister d22 = { 22 }; |
| 322 const DoubleRegister d23 = { 23 }; |
| 323 const DoubleRegister d24 = { 24 }; |
| 324 const DoubleRegister d25 = { 25 }; |
| 325 const DoubleRegister d26 = { 26 }; |
| 326 const DoubleRegister d27 = { 27 }; |
| 327 const DoubleRegister d28 = { 28 }; |
| 328 const DoubleRegister d29 = { 29 }; |
| 329 const DoubleRegister d30 = { 30 }; |
| 330 const DoubleRegister d31 = { 31 }; |
| 331 |
| 332 // Aliases for double registers. Defined using #define instead of |
| 333 // "static const DoubleRegister&" because Clang complains otherwise when a |
| 334 // compilation unit that includes this header doesn't use the variables. |
| 335 #define kFirstCalleeSavedDoubleReg d14 |
| 336 #define kLastCalleeSavedDoubleReg d31 |
| 337 #define kDoubleRegZero d14 |
| 338 #define kScratchDoubleReg d13 |
| 339 |
| 340 Register ToRegister(int num); |
| 341 |
| 342 // Coprocessor register |
| 343 struct CRegister { |
| 344 bool is_valid() const { return 0 <= code_ && code_ < 16; } |
| 345 bool is(CRegister creg) const { return code_ == creg.code_; } |
| 346 int code() const { |
| 347 ASSERT(is_valid()); |
| 348 return code_; |
| 349 } |
| 350 int bit() const { |
| 351 ASSERT(is_valid()); |
| 352 return 1 << code_; |
| 353 } |
| 354 |
| 355 // Unfortunately we can't make this private in a struct. |
| 356 int code_; |
| 357 }; |
| 358 |
| 359 |
| 360 const CRegister no_creg = { -1 }; |
| 361 |
| 362 const CRegister cr0 = { 0 }; |
| 363 const CRegister cr1 = { 1 }; |
| 364 const CRegister cr2 = { 2 }; |
| 365 const CRegister cr3 = { 3 }; |
| 366 const CRegister cr4 = { 4 }; |
| 367 const CRegister cr5 = { 5 }; |
| 368 const CRegister cr6 = { 6 }; |
| 369 const CRegister cr7 = { 7 }; |
| 370 const CRegister cr8 = { 8 }; |
| 371 const CRegister cr9 = { 9 }; |
| 372 const CRegister cr10 = { 10 }; |
| 373 const CRegister cr11 = { 11 }; |
| 374 const CRegister cr12 = { 12 }; |
| 375 const CRegister cr13 = { 13 }; |
| 376 const CRegister cr14 = { 14 }; |
| 377 const CRegister cr15 = { 15 }; |
| 378 |
| 379 // ----------------------------------------------------------------------------- |
| 380 // Machine instruction Operands |
| 381 |
| 382 #if V8_TARGET_ARCH_PPC64 |
| 383 const RelocInfo::Mode kRelocInfo_NONEPTR = RelocInfo::NONE64; |
| 384 #else |
| 385 const RelocInfo::Mode kRelocInfo_NONEPTR = RelocInfo::NONE32; |
| 386 #endif |
| 387 |
| 388 // Class Operand represents a shifter operand in data processing instructions |
| 389 class Operand BASE_EMBEDDED { |
| 390 public: |
| 391 // immediate |
| 392 INLINE(explicit Operand(intptr_t immediate, |
| 393 RelocInfo::Mode rmode = kRelocInfo_NONEPTR)); |
| 394 INLINE(static Operand Zero()) { |
| 395 return Operand(static_cast<intptr_t>(0)); |
| 396 } |
| 397 INLINE(explicit Operand(const ExternalReference& f)); |
| 398 explicit Operand(Handle<Object> handle); |
| 399 INLINE(explicit Operand(Smi* value)); |
| 400 |
| 401 // rm |
| 402 INLINE(explicit Operand(Register rm)); |
| 403 |
| 404 // Return true if this is a register operand. |
| 405 INLINE(bool is_reg() const); |
| 406 |
| 407 // For mov. Return the number of actual instructions required to |
| 408 // load the operand into a register. This can be anywhere from |
| 409 // one (constant pool small section) to five instructions (full |
| 410 // 64-bit sequence). |
| 411 // |
| 412 // The value returned is only valid as long as no entries are added to the |
| 413 // constant pool between this call and the actual instruction being emitted. |
| 414 bool must_output_reloc_info(const Assembler* assembler) const; |
| 415 |
| 416 inline intptr_t immediate() const { |
| 417 ASSERT(!rm_.is_valid()); |
| 418 return imm_; |
| 419 } |
| 420 |
| 421 Register rm() const { return rm_; } |
| 422 |
| 423 private: |
| 424 Register rm_; |
| 425 intptr_t imm_; // valid if rm_ == no_reg |
| 426 RelocInfo::Mode rmode_; |
| 427 |
| 428 friend class Assembler; |
| 429 friend class MacroAssembler; |
| 430 }; |
| 431 |
| 432 |
| 433 // Class MemOperand represents a memory operand in load and store instructions |
| 434 // On PowerPC we have base register + 16bit signed value |
| 435 // Alternatively we can have a 16bit signed value immediate |
| 436 class MemOperand BASE_EMBEDDED { |
| 437 public: |
| 438 explicit MemOperand(Register rn, int32_t offset = 0); |
| 439 |
| 440 explicit MemOperand(Register ra, Register rb); |
| 441 |
| 442 int32_t offset() const { |
| 443 ASSERT(rb_.is(no_reg)); |
| 444 return offset_; |
| 445 } |
| 446 |
| 447 // PowerPC - base register |
| 448 Register ra() const { |
| 449 ASSERT(!ra_.is(no_reg)); |
| 450 return ra_; |
| 451 } |
| 452 |
| 453 Register rb() const { |
| 454 ASSERT(offset_ == 0 && !rb_.is(no_reg)); |
| 455 return rb_; |
| 456 } |
| 457 |
| 458 private: |
| 459 Register ra_; // base |
| 460 int32_t offset_; // offset |
| 461 Register rb_; // index |
| 462 |
| 463 friend class Assembler; |
| 464 }; |
| 465 |
| 466 |
| 467 #if V8_OOL_CONSTANT_POOL |
| 468 // Class used to build a constant pool. |
| 469 class ConstantPoolBuilder BASE_EMBEDDED { |
| 470 public: |
| 471 explicit ConstantPoolBuilder(); |
| 472 ConstantPoolArray::LayoutSection AddEntry(Assembler* assm, |
| 473 const RelocInfo& rinfo); |
| 474 void Relocate(intptr_t pc_delta); |
| 475 bool IsEmpty(); |
| 476 Handle<ConstantPoolArray> New(Isolate* isolate); |
| 477 void Populate(Assembler* assm, ConstantPoolArray* constant_pool); |
| 478 |
| 479 inline ConstantPoolArray::LayoutSection current_section() const { |
| 480 return current_section_; |
| 481 } |
| 482 |
| 483 inline ConstantPoolArray::NumberOfEntries* number_of_entries( |
| 484 ConstantPoolArray::LayoutSection section) { |
| 485 return &number_of_entries_[section]; |
| 486 } |
| 487 |
| 488 inline ConstantPoolArray::NumberOfEntries* small_entries() { |
| 489 return number_of_entries(ConstantPoolArray::SMALL_SECTION); |
| 490 } |
| 491 |
| 492 inline ConstantPoolArray::NumberOfEntries* extended_entries() { |
| 493 return number_of_entries(ConstantPoolArray::EXTENDED_SECTION); |
| 494 } |
| 495 |
| 496 private: |
| 497 struct ConstantPoolEntry { |
| 498 ConstantPoolEntry(RelocInfo rinfo, ConstantPoolArray::LayoutSection section, |
| 499 int merged_index) |
| 500 : rinfo_(rinfo), section_(section), merged_index_(merged_index) {} |
| 501 |
| 502 RelocInfo rinfo_; |
| 503 ConstantPoolArray::LayoutSection section_; |
| 504 int merged_index_; |
| 505 }; |
| 506 |
| 507 ConstantPoolArray::Type GetConstantPoolType(RelocInfo::Mode rmode); |
| 508 |
| 509 std::vector<ConstantPoolEntry> entries_; |
| 510 ConstantPoolArray::LayoutSection current_section_; |
| 511 ConstantPoolArray::NumberOfEntries number_of_entries_[2]; |
| 512 }; |
| 513 #endif |
| 514 |
| 515 |
| 516 class Assembler : public AssemblerBase { |
| 517 public: |
| 518 // Create an assembler. Instructions and relocation information are emitted |
| 519 // into a buffer, with the instructions starting from the beginning and the |
| 520 // relocation information starting from the end of the buffer. See CodeDesc |
| 521 // for a detailed comment on the layout (globals.h). |
| 522 // |
| 523 // If the provided buffer is NULL, the assembler allocates and grows its own |
| 524 // buffer, and buffer_size determines the initial buffer size. The buffer is |
| 525 // owned by the assembler and deallocated upon destruction of the assembler. |
| 526 // |
| 527 // If the provided buffer is not NULL, the assembler uses the provided buffer |
| 528 // for code generation and assumes its size to be buffer_size. If the buffer |
| 529 // is too small, a fatal error occurs. No deallocation of the buffer is done |
| 530 // upon destruction of the assembler. |
| 531 Assembler(Isolate* isolate, void* buffer, int buffer_size); |
| 532 virtual ~Assembler() { } |
| 533 |
| 534 // GetCode emits any pending (non-emitted) code and fills the descriptor |
| 535 // desc. GetCode() is idempotent; it returns the same result if no other |
| 536 // Assembler functions are invoked in between GetCode() calls. |
| 537 void GetCode(CodeDesc* desc); |
| 538 |
| 539 // Label operations & relative jumps (PPUM Appendix D) |
| 540 // |
| 541 // Takes a branch opcode (cc) and a label (L) and generates |
| 542 // either a backward branch or a forward branch and links it |
| 543 // to the label fixup chain. Usage: |
| 544 // |
| 545 // Label L; // unbound label |
| 546 // j(cc, &L); // forward branch to unbound label |
| 547 // bind(&L); // bind label to the current pc |
| 548 // j(cc, &L); // backward branch to bound label |
| 549 // bind(&L); // illegal: a label may be bound only once |
| 550 // |
| 551 // Note: The same Label can be used for forward and backward branches |
| 552 // but it may be bound only once. |
| 553 |
| 554 void bind(Label* L); // binds an unbound label L to the current code position |
| 555 // Determines if Label is bound and near enough so that a single |
| 556 // branch instruction can be used to reach it. |
| 557 bool is_near(Label* L, Condition cond); |
| 558 |
| 559 // Returns the branch offset to the given label from the current code position |
| 560 // Links the label to the current position if it is still unbound |
| 561 // Manages the jump elimination optimization if the second parameter is true. |
| 562 int branch_offset(Label* L, bool jump_elimination_allowed); |
| 563 |
| 564 // Puts a labels target address at the given position. |
| 565 // The high 8 bits are set to zero. |
| 566 void label_at_put(Label* L, int at_offset); |
| 567 |
| 568 #if V8_OOL_CONSTANT_POOL |
| 569 INLINE(static bool IsConstantPoolLoadStart(Address pc)); |
| 570 INLINE(static bool IsConstantPoolLoadEnd(Address pc)); |
| 571 INLINE(static int GetConstantPoolOffset(Address pc)); |
| 572 INLINE(static void SetConstantPoolOffset(Address pc, int offset)); |
| 573 |
| 574 // Return the address in the constant pool of the code target address used by |
| 575 // the branch/call instruction at pc, or the object in a mov. |
| 576 INLINE(static Address target_constant_pool_address_at( |
| 577 Address pc, ConstantPoolArray* constant_pool)); |
| 578 #endif |
| 579 |
| 580 // Read/Modify the code target address in the branch/call instruction at pc. |
| 581 INLINE(static Address target_address_at(Address pc, |
| 582 ConstantPoolArray* constant_pool)); |
| 583 INLINE(static void set_target_address_at(Address pc, |
| 584 ConstantPoolArray* constant_pool, |
| 585 Address target, |
| 586 ICacheFlushMode icache_flush_mode = |
| 587 FLUSH_ICACHE_IF_NEEDED)); |
| 588 INLINE(static Address target_address_at(Address pc, Code* code)) { |
| 589 ConstantPoolArray* constant_pool = code ? code->constant_pool() : NULL; |
| 590 return target_address_at(pc, constant_pool); |
| 591 } |
| 592 INLINE(static void set_target_address_at(Address pc, |
| 593 Code* code, |
| 594 Address target, |
| 595 ICacheFlushMode icache_flush_mode = |
| 596 FLUSH_ICACHE_IF_NEEDED)) { |
| 597 ConstantPoolArray* constant_pool = code ? code->constant_pool() : NULL; |
| 598 set_target_address_at(pc, constant_pool, target, icache_flush_mode); |
| 599 } |
| 600 |
| 601 // Return the code target address at a call site from the return address |
| 602 // of that call in the instruction stream. |
| 603 inline static Address target_address_from_return_address(Address pc); |
| 604 |
| 605 // Given the address of the beginning of a call, return the address |
| 606 // in the instruction stream that the call will return to. |
| 607 INLINE(static Address return_address_from_call_start(Address pc)); |
| 608 |
| 609 // This sets the branch destination. |
| 610 // This is for calls and branches within generated code. |
| 611 inline static void deserialization_set_special_target_at( |
| 612 Address instruction_payload, Code* code, Address target); |
| 613 |
| 614 // Size of an instruction. |
| 615 static const int kInstrSize = sizeof(Instr); |
| 616 |
| 617 // Here we are patching the address in the LUI/ORI instruction pair. |
| 618 // These values are used in the serialization process and must be zero for |
| 619 // PPC platform, as Code, Embedded Object or External-reference pointers |
| 620 // are split across two consecutive instructions and don't exist separately |
| 621 // in the code, so the serializer should not step forwards in memory after |
| 622 // a target is resolved and written. |
| 623 static const int kSpecialTargetSize = 0; |
| 624 |
| 625 // Number of instructions to load an address via a mov sequence. |
| 626 #if V8_TARGET_ARCH_PPC64 |
| 627 static const int kMovInstructionsConstantPool = 2; |
| 628 static const int kMovInstructionsExtendedConstantPool = 3; |
| 629 static const int kMovInstructionsNoConstantPool = 5; |
| 630 #else |
| 631 static const int kMovInstructionsConstantPool = 1; |
| 632 static const int kMovInstructionsExtendedConstantPool = 2; |
| 633 static const int kMovInstructionsNoConstantPool = 2; |
| 634 #endif |
| 635 #if V8_OOL_CONSTANT_POOL |
| 636 static const int kMovInstructions = kMovInstructionsConstantPool; |
| 637 #else |
| 638 static const int kMovInstructions = kMovInstructionsNoConstantPool; |
| 639 #endif |
| 640 |
| 641 // Distance between the instruction referring to the address of the call |
| 642 // target and the return address. |
| 643 |
| 644 // Call sequence is a FIXED_SEQUENCE: |
| 645 // mov r8, @ call address |
| 646 // mtlr r8 |
| 647 // blrl |
| 648 // @ return address |
| 649 static const int kCallTargetAddressOffset = |
| 650 (kMovInstructions + 2) * kInstrSize; |
| 651 |
| 652 // Distance between start of patched return sequence and the emitted address |
| 653 // to jump to. |
| 654 // Patched return sequence is a FIXED_SEQUENCE: |
| 655 // mov r0, <address> |
| 656 // mtlr r0 |
| 657 // blrl |
| 658 static const int kPatchReturnSequenceAddressOffset = 0 * kInstrSize; |
| 659 |
| 660 // Distance between start of patched debug break slot and the emitted address |
| 661 // to jump to. |
| 662 // Patched debug break slot code is a FIXED_SEQUENCE: |
| 663 // mov r0, <address> |
| 664 // mtlr r0 |
| 665 // blrl |
| 666 static const int kPatchDebugBreakSlotAddressOffset = 0 * kInstrSize; |
| 667 |
| 668 // This is the length of the BreakLocationIterator::SetDebugBreakAtReturn() |
| 669 // code patch FIXED_SEQUENCE |
| 670 static const int kJSReturnSequenceInstructions = |
| 671 kMovInstructionsNoConstantPool + 3; |
| 672 |
| 673 // This is the length of the code sequence from SetDebugBreakAtSlot() |
| 674 // FIXED_SEQUENCE |
| 675 static const int kDebugBreakSlotInstructions = |
| 676 kMovInstructionsNoConstantPool + 2; |
| 677 static const int kDebugBreakSlotLength = |
| 678 kDebugBreakSlotInstructions * kInstrSize; |
| 679 |
| 680 static inline int encode_crbit(const CRegister& cr, enum CRBit crbit) { |
| 681 return ((cr.code() * CRWIDTH) + crbit); |
| 682 } |
| 683 |
| 684 // --------------------------------------------------------------------------- |
| 685 // Code generation |
| 686 |
| 687 // Insert the smallest number of nop instructions |
| 688 // possible to align the pc offset to a multiple |
| 689 // of m. m must be a power of 2 (>= 4). |
| 690 void Align(int m); |
| 691 // Aligns code to something that's optimal for a jump target for the platform. |
| 692 void CodeTargetAlign(); |
| 693 |
| 694 // Branch instructions |
| 695 void bclr(BOfield bo, LKBit lk); |
| 696 void blr(); |
| 697 void bc(int branch_offset, BOfield bo, int condition_bit, LKBit lk = LeaveLK); |
| 698 void b(int branch_offset, LKBit lk); |
| 699 |
| 700 void bcctr(BOfield bo, LKBit lk); |
| 701 void bctr(); |
| 702 |
| 703 // Convenience branch instructions using labels |
| 704 void b(Label* L, LKBit lk = LeaveLK) { |
| 705 b(branch_offset(L, false), lk); |
| 706 } |
| 707 |
| 708 void bc_short(Condition cond, Label* L, CRegister cr = cr7, |
| 709 LKBit lk = LeaveLK) { |
| 710 ASSERT(cond != al); |
| 711 ASSERT(cr.code() >= 0 && cr.code() <= 7); |
| 712 |
| 713 int b_offset = branch_offset(L, false); |
| 714 |
| 715 switch (cond) { |
| 716 case eq: |
| 717 bc(b_offset, BT, encode_crbit(cr, CR_EQ), lk); |
| 718 break; |
| 719 case ne: |
| 720 bc(b_offset, BF, encode_crbit(cr, CR_EQ), lk); |
| 721 break; |
| 722 case gt: |
| 723 bc(b_offset, BT, encode_crbit(cr, CR_GT), lk); |
| 724 break; |
| 725 case le: |
| 726 bc(b_offset, BF, encode_crbit(cr, CR_GT), lk); |
| 727 break; |
| 728 case lt: |
| 729 bc(b_offset, BT, encode_crbit(cr, CR_LT), lk); |
| 730 break; |
| 731 case ge: |
| 732 bc(b_offset, BF, encode_crbit(cr, CR_LT), lk); |
| 733 break; |
| 734 case unordered: |
| 735 bc(b_offset, BT, encode_crbit(cr, CR_FU), lk); |
| 736 break; |
| 737 case ordered: |
| 738 bc(b_offset, BF, encode_crbit(cr, CR_FU), lk); |
| 739 break; |
| 740 case overflow: |
| 741 bc(b_offset, BT, encode_crbit(cr, CR_SO), lk); |
| 742 break; |
| 743 case nooverflow: |
| 744 bc(b_offset, BF, encode_crbit(cr, CR_SO), lk); |
| 745 break; |
| 746 default: |
| 747 UNIMPLEMENTED(); |
| 748 } |
| 749 } |
| 750 |
| 751 void b(Condition cond, Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 752 if (cond == al) { |
| 753 b(L, lk); |
| 754 return; |
| 755 } |
| 756 |
| 757 if ((L->is_bound() && is_near(L, cond)) || |
| 758 !is_trampoline_emitted()) { |
| 759 bc_short(cond, L, cr, lk); |
| 760 return; |
| 761 } |
| 762 |
| 763 Label skip; |
| 764 Condition neg_cond = NegateCondition(cond); |
| 765 bc_short(neg_cond, &skip, cr); |
| 766 b(L, lk); |
| 767 bind(&skip); |
| 768 } |
| 769 |
| 770 void bne(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 771 b(ne, L, cr, lk); } |
| 772 void beq(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 773 b(eq, L, cr, lk); } |
| 774 void blt(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 775 b(lt, L, cr, lk); } |
| 776 void bge(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 777 b(ge, L, cr, lk); } |
| 778 void ble(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 779 b(le, L, cr, lk); } |
| 780 void bgt(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 781 b(gt, L, cr, lk); } |
| 782 void bunordered(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 783 b(unordered, L, cr, lk); } |
| 784 void bordered(Label* L, CRegister cr = cr7, LKBit lk = LeaveLK) { |
| 785 b(ordered, L, cr, lk); } |
| 786 void boverflow(Label* L, CRegister cr = cr0, LKBit lk = LeaveLK) { |
| 787 b(overflow, L, cr, lk); } |
| 788 void bnooverflow(Label* L, CRegister cr = cr0, LKBit lk = LeaveLK) { |
| 789 b(nooverflow, L, cr, lk); } |
| 790 |
| 791 // Decrement CTR; branch if CTR != 0 |
| 792 void bdnz(Label* L, LKBit lk = LeaveLK) { |
| 793 bc(branch_offset(L, false), DCBNZ, 0, lk); |
| 794 } |
| 795 |
| 796 // Data-processing instructions |
| 797 |
| 798 void sub(Register dst, Register src1, Register src2, |
| 799 OEBit s = LeaveOE, RCBit r = LeaveRC); |
| 800 |
| 801 void subfic(Register dst, Register src, const Operand& imm); |
| 802 |
| 803 void subfc(Register dst, Register src1, Register src2, |
| 804 OEBit s = LeaveOE, RCBit r = LeaveRC); |
| 805 |
| 806 void add(Register dst, Register src1, Register src2, |
| 807 OEBit s = LeaveOE, RCBit r = LeaveRC); |
| 808 |
| 809 void addc(Register dst, Register src1, Register src2, |
| 810 OEBit o = LeaveOE, RCBit r = LeaveRC); |
| 811 |
| 812 void addze(Register dst, Register src1, OEBit o, RCBit r); |
| 813 |
| 814 void mullw(Register dst, Register src1, Register src2, |
| 815 OEBit o = LeaveOE, RCBit r = LeaveRC); |
| 816 |
| 817 void mulhw(Register dst, Register src1, Register src2, |
| 818 OEBit o = LeaveOE, RCBit r = LeaveRC); |
| 819 |
| 820 void divw(Register dst, Register src1, Register src2, |
| 821 OEBit o = LeaveOE, RCBit r = LeaveRC); |
| 822 |
| 823 void addi(Register dst, Register src, const Operand& imm); |
| 824 void addis(Register dst, Register src, const Operand& imm); |
| 825 void addic(Register dst, Register src, const Operand& imm); |
| 826 |
| 827 void and_(Register dst, Register src1, Register src2, RCBit rc = LeaveRC); |
| 828 void andc(Register dst, Register src1, Register src2, RCBit rc = LeaveRC); |
| 829 void andi(Register ra, Register rs, const Operand& imm); |
| 830 void andis(Register ra, Register rs, const Operand& imm); |
| 831 void nor(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 832 void notx(Register dst, Register src, RCBit r = LeaveRC); |
| 833 void ori(Register dst, Register src, const Operand& imm); |
| 834 void oris(Register dst, Register src, const Operand& imm); |
| 835 void orx(Register dst, Register src1, Register src2, RCBit rc = LeaveRC); |
| 836 void xori(Register dst, Register src, const Operand& imm); |
| 837 void xoris(Register ra, Register rs, const Operand& imm); |
| 838 void xor_(Register dst, Register src1, Register src2, RCBit rc = LeaveRC); |
| 839 void cmpi(Register src1, const Operand& src2, CRegister cr = cr7); |
| 840 void cmpli(Register src1, const Operand& src2, CRegister cr = cr7); |
| 841 void cmpwi(Register src1, const Operand& src2, CRegister cr = cr7); |
| 842 void cmplwi(Register src1, const Operand& src2, CRegister cr = cr7); |
| 843 void li(Register dst, const Operand& src); |
| 844 void lis(Register dst, const Operand& imm); |
| 845 void mr(Register dst, Register src); |
| 846 |
| 847 void lbz(Register dst, const MemOperand& src); |
| 848 void lbzx(Register dst, const MemOperand& src); |
| 849 void lbzux(Register dst, const MemOperand& src); |
| 850 void lhz(Register dst, const MemOperand& src); |
| 851 void lhzx(Register dst, const MemOperand& src); |
| 852 void lhzux(Register dst, const MemOperand& src); |
| 853 void lwz(Register dst, const MemOperand& src); |
| 854 void lwzu(Register dst, const MemOperand& src); |
| 855 void lwzx(Register dst, const MemOperand& src); |
| 856 void lwzux(Register dst, const MemOperand& src); |
| 857 void lwa(Register dst, const MemOperand& src); |
| 858 void stb(Register dst, const MemOperand& src); |
| 859 void stbx(Register dst, const MemOperand& src); |
| 860 void stbux(Register dst, const MemOperand& src); |
| 861 void sth(Register dst, const MemOperand& src); |
| 862 void sthx(Register dst, const MemOperand& src); |
| 863 void sthux(Register dst, const MemOperand& src); |
| 864 void stw(Register dst, const MemOperand& src); |
| 865 void stwu(Register dst, const MemOperand& src); |
| 866 void stwx(Register rs, const MemOperand& src); |
| 867 void stwux(Register rs, const MemOperand& src); |
| 868 |
| 869 void extsb(Register rs, Register ra, RCBit r = LeaveRC); |
| 870 void extsh(Register rs, Register ra, RCBit r = LeaveRC); |
| 871 |
| 872 void neg(Register rt, Register ra, OEBit o = LeaveOE, RCBit c = LeaveRC); |
| 873 |
| 874 #if V8_TARGET_ARCH_PPC64 |
| 875 void ld(Register rd, const MemOperand &src); |
| 876 void ldx(Register rd, const MemOperand &src); |
| 877 void ldu(Register rd, const MemOperand &src); |
| 878 void ldux(Register rd, const MemOperand &src); |
| 879 void std(Register rs, const MemOperand &src); |
| 880 void stdx(Register rs, const MemOperand &src); |
| 881 void stdu(Register rs, const MemOperand &src); |
| 882 void stdux(Register rs, const MemOperand &src); |
| 883 void rldic(Register dst, Register src, int sh, int mb, RCBit r = LeaveRC); |
| 884 void rldicl(Register dst, Register src, int sh, int mb, RCBit r = LeaveRC); |
| 885 void rldcl(Register ra, Register rs, Register rb, int mb, RCBit r = LeaveRC); |
| 886 void rldicr(Register dst, Register src, int sh, int me, RCBit r = LeaveRC); |
| 887 void rldimi(Register dst, Register src, int sh, int mb, RCBit r = LeaveRC); |
| 888 void sldi(Register dst, Register src, const Operand& val, RCBit rc = LeaveRC); |
| 889 void srdi(Register dst, Register src, const Operand& val, RCBit rc = LeaveRC); |
| 890 void clrrdi(Register dst, Register src, const Operand& val, |
| 891 RCBit rc = LeaveRC); |
| 892 void clrldi(Register dst, Register src, const Operand& val, |
| 893 RCBit rc = LeaveRC); |
| 894 void sradi(Register ra, Register rs, int sh, RCBit r = LeaveRC); |
| 895 void srd(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 896 void sld(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 897 void srad(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 898 void rotld(Register ra, Register rs, Register rb, RCBit r = LeaveRC); |
| 899 void rotldi(Register ra, Register rs, int sh, RCBit r = LeaveRC); |
| 900 void rotrdi(Register ra, Register rs, int sh, RCBit r = LeaveRC); |
| 901 void cntlzd_(Register dst, Register src, RCBit rc = LeaveRC); |
| 902 void extsw(Register rs, Register ra, RCBit r = LeaveRC); |
| 903 void mulld(Register dst, Register src1, Register src2, |
| 904 OEBit o = LeaveOE, RCBit r = LeaveRC); |
| 905 void divd(Register dst, Register src1, Register src2, |
| 906 OEBit o = LeaveOE, RCBit r = LeaveRC); |
| 907 #endif |
| 908 |
| 909 void rlwinm(Register ra, Register rs, int sh, int mb, int me, |
| 910 RCBit rc = LeaveRC); |
| 911 void rlwimi(Register ra, Register rs, int sh, int mb, int me, |
| 912 RCBit rc = LeaveRC); |
| 913 void rlwnm(Register ra, Register rs, Register rb, int mb, int me, |
| 914 RCBit rc = LeaveRC); |
| 915 void slwi(Register dst, Register src, const Operand& val, RCBit rc = LeaveRC); |
| 916 void srwi(Register dst, Register src, const Operand& val, RCBit rc = LeaveRC); |
| 917 void clrrwi(Register dst, Register src, const Operand& val, |
| 918 RCBit rc = LeaveRC); |
| 919 void clrlwi(Register dst, Register src, const Operand& val, |
| 920 RCBit rc = LeaveRC); |
| 921 void srawi(Register ra, Register rs, int sh, RCBit r = LeaveRC); |
| 922 void srw(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 923 void slw(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 924 void sraw(Register dst, Register src1, Register src2, RCBit r = LeaveRC); |
| 925 void rotlw(Register ra, Register rs, Register rb, RCBit r = LeaveRC); |
| 926 void rotlwi(Register ra, Register rs, int sh, RCBit r = LeaveRC); |
| 927 void rotrwi(Register ra, Register rs, int sh, RCBit r = LeaveRC); |
| 928 |
| 929 void cntlzw_(Register dst, Register src, RCBit rc = LeaveRC); |
| 930 |
| 931 void subi(Register dst, Register src1, const Operand& src2); |
| 932 |
| 933 void cmp(Register src1, Register src2, CRegister cr = cr7); |
| 934 void cmpl(Register src1, Register src2, CRegister cr = cr7); |
| 935 void cmpw(Register src1, Register src2, CRegister cr = cr7); |
| 936 void cmplw(Register src1, Register src2, CRegister cr = cr7); |
| 937 |
| 938 void mov(Register dst, const Operand& src); |
| 939 |
| 940 // Load the position of the label relative to the generated code object |
| 941 // pointer in a register. |
| 942 void mov_label_offset(Register dst, Label* label); |
| 943 |
| 944 // Multiply instructions |
| 945 void mul(Register dst, Register src1, Register src2, |
| 946 OEBit s = LeaveOE, RCBit r = LeaveRC); |
| 947 |
| 948 // Miscellaneous arithmetic instructions |
| 949 |
| 950 // Special register access |
| 951 void crxor(int bt, int ba, int bb); |
| 952 void crclr(int bt) { crxor(bt, bt, bt); } |
| 953 void creqv(int bt, int ba, int bb); |
| 954 void crset(int bt) { creqv(bt, bt, bt); } |
| 955 void mflr(Register dst); |
| 956 void mtlr(Register src); |
| 957 void mtctr(Register src); |
| 958 void mtxer(Register src); |
| 959 void mcrfs(int bf, int bfa); |
| 960 void mfcr(Register dst); |
| 961 |
| 962 void fake_asm(enum FAKE_OPCODE_T fopcode); |
| 963 void marker_asm(int mcode); |
| 964 void function_descriptor(); |
| 965 |
| 966 // Exception-generating instructions and debugging support |
| 967 void stop(const char* msg, |
| 968 Condition cond = al, |
| 969 int32_t code = kDefaultStopCode, |
| 970 CRegister cr = cr7); |
| 971 |
| 972 void bkpt(uint32_t imm16); // v5 and above |
| 973 |
| 974 // Informational messages when simulating |
| 975 void info(const char* msg, |
| 976 Condition cond = al, |
| 977 int32_t code = kDefaultStopCode, |
| 978 CRegister cr = cr7); |
| 979 |
| 980 void dcbf(Register ra, Register rb); |
| 981 void sync(); |
| 982 void icbi(Register ra, Register rb); |
| 983 void isync(); |
| 984 |
| 985 // Support for floating point |
| 986 void lfd(const DoubleRegister frt, const MemOperand& src); |
| 987 void lfdu(const DoubleRegister frt, const MemOperand& src); |
| 988 void lfdx(const DoubleRegister frt, const MemOperand& src); |
| 989 void lfdux(const DoubleRegister frt, const MemOperand& src); |
| 990 void lfs(const DoubleRegister frt, const MemOperand& src); |
| 991 void lfsu(const DoubleRegister frt, const MemOperand& src); |
| 992 void lfsx(const DoubleRegister frt, const MemOperand& src); |
| 993 void lfsux(const DoubleRegister frt, const MemOperand& src); |
| 994 void stfd(const DoubleRegister frs, const MemOperand& src); |
| 995 void stfdu(const DoubleRegister frs, const MemOperand& src); |
| 996 void stfdx(const DoubleRegister frs, const MemOperand& src); |
| 997 void stfdux(const DoubleRegister frs, const MemOperand& src); |
| 998 void stfs(const DoubleRegister frs, const MemOperand& src); |
| 999 void stfsu(const DoubleRegister frs, const MemOperand& src); |
| 1000 void stfsx(const DoubleRegister frs, const MemOperand& src); |
| 1001 void stfsux(const DoubleRegister frs, const MemOperand& src); |
| 1002 |
| 1003 void fadd(const DoubleRegister frt, const DoubleRegister fra, |
| 1004 const DoubleRegister frb, RCBit rc = LeaveRC); |
| 1005 void fsub(const DoubleRegister frt, const DoubleRegister fra, |
| 1006 const DoubleRegister frb, RCBit rc = LeaveRC); |
| 1007 void fdiv(const DoubleRegister frt, const DoubleRegister fra, |
| 1008 const DoubleRegister frb, RCBit rc = LeaveRC); |
| 1009 void fmul(const DoubleRegister frt, const DoubleRegister fra, |
| 1010 const DoubleRegister frc, RCBit rc = LeaveRC); |
| 1011 void fcmpu(const DoubleRegister fra, const DoubleRegister frb, |
| 1012 CRegister cr = cr7); |
| 1013 void fmr(const DoubleRegister frt, const DoubleRegister frb, |
| 1014 RCBit rc = LeaveRC); |
| 1015 void fctiwz(const DoubleRegister frt, const DoubleRegister frb); |
| 1016 void fctiw(const DoubleRegister frt, const DoubleRegister frb); |
| 1017 void frim(const DoubleRegister frt, const DoubleRegister frb); |
| 1018 void frsp(const DoubleRegister frt, const DoubleRegister frb, |
| 1019 RCBit rc = LeaveRC); |
| 1020 void fcfid(const DoubleRegister frt, const DoubleRegister frb, |
| 1021 RCBit rc = LeaveRC); |
| 1022 void fctid(const DoubleRegister frt, const DoubleRegister frb, |
| 1023 RCBit rc = LeaveRC); |
| 1024 void fctidz(const DoubleRegister frt, const DoubleRegister frb, |
| 1025 RCBit rc = LeaveRC); |
| 1026 void fsel(const DoubleRegister frt, const DoubleRegister fra, |
| 1027 const DoubleRegister frc, const DoubleRegister frb, |
| 1028 RCBit rc = LeaveRC); |
| 1029 void fneg(const DoubleRegister frt, const DoubleRegister frb, |
| 1030 RCBit rc = LeaveRC); |
| 1031 void mtfsfi(int bf, int immediate, RCBit rc = LeaveRC); |
| 1032 void mffs(const DoubleRegister frt, RCBit rc = LeaveRC); |
| 1033 void mtfsf(const DoubleRegister frb, bool L = 1, int FLM = 0, bool W = 0, |
| 1034 RCBit rc = LeaveRC); |
| 1035 void fsqrt(const DoubleRegister frt, const DoubleRegister frb, |
| 1036 RCBit rc = LeaveRC); |
| 1037 void fabs(const DoubleRegister frt, const DoubleRegister frb, |
| 1038 RCBit rc = LeaveRC); |
| 1039 void fmadd(const DoubleRegister frt, const DoubleRegister fra, |
| 1040 const DoubleRegister frc, const DoubleRegister frb, |
| 1041 RCBit rc = LeaveRC); |
| 1042 void fmsub(const DoubleRegister frt, const DoubleRegister fra, |
| 1043 const DoubleRegister frc, const DoubleRegister frb, |
| 1044 RCBit rc = LeaveRC); |
| 1045 |
| 1046 // Pseudo instructions |
| 1047 |
| 1048 // Different nop operations are used by the code generator to detect certain |
| 1049 // states of the generated code. |
| 1050 enum NopMarkerTypes { |
| 1051 NON_MARKING_NOP = 0, |
| 1052 DEBUG_BREAK_NOP, |
| 1053 // IC markers. |
| 1054 PROPERTY_ACCESS_INLINED, |
| 1055 PROPERTY_ACCESS_INLINED_CONTEXT, |
| 1056 PROPERTY_ACCESS_INLINED_CONTEXT_DONT_DELETE, |
| 1057 // Helper values. |
| 1058 LAST_CODE_MARKER, |
| 1059 FIRST_IC_MARKER = PROPERTY_ACCESS_INLINED |
| 1060 }; |
| 1061 |
| 1062 void nop(int type = 0); // 0 is the default non-marking type. |
| 1063 |
| 1064 void push(Register src) { |
| 1065 #if V8_TARGET_ARCH_PPC64 |
| 1066 stdu(src, MemOperand(sp, -8)); |
| 1067 #else |
| 1068 stwu(src, MemOperand(sp, -4)); |
| 1069 #endif |
| 1070 } |
| 1071 |
| 1072 void pop(Register dst) { |
| 1073 #if V8_TARGET_ARCH_PPC64 |
| 1074 ld(dst, MemOperand(sp)); |
| 1075 addi(sp, sp, Operand(8)); |
| 1076 #else |
| 1077 lwz(dst, MemOperand(sp)); |
| 1078 addi(sp, sp, Operand(4)); |
| 1079 #endif |
| 1080 } |
| 1081 |
| 1082 void pop() { |
| 1083 addi(sp, sp, Operand(kPointerSize)); |
| 1084 } |
| 1085 |
| 1086 // Jump unconditionally to given label. |
| 1087 void jmp(Label* L) { b(L); } |
| 1088 |
| 1089 // Check the code size generated from label to here. |
| 1090 int SizeOfCodeGeneratedSince(Label* label) { |
| 1091 return pc_offset() - label->pos(); |
| 1092 } |
| 1093 |
| 1094 // Check the number of instructions generated from label to here. |
| 1095 int InstructionsGeneratedSince(Label* label) { |
| 1096 return SizeOfCodeGeneratedSince(label) / kInstrSize; |
| 1097 } |
| 1098 |
| 1099 // Class for scoping postponing the trampoline pool generation. |
| 1100 class BlockTrampolinePoolScope { |
| 1101 public: |
| 1102 explicit BlockTrampolinePoolScope(Assembler* assem) : assem_(assem) { |
| 1103 assem_->StartBlockTrampolinePool(); |
| 1104 } |
| 1105 ~BlockTrampolinePoolScope() { |
| 1106 assem_->EndBlockTrampolinePool(); |
| 1107 } |
| 1108 |
| 1109 private: |
| 1110 Assembler* assem_; |
| 1111 |
| 1112 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockTrampolinePoolScope); |
| 1113 }; |
| 1114 |
| 1115 // Debugging |
| 1116 |
| 1117 // Mark address of the ExitJSFrame code. |
| 1118 void RecordJSReturn(); |
| 1119 |
| 1120 // Mark address of a debug break slot. |
| 1121 void RecordDebugBreakSlot(); |
| 1122 |
| 1123 // Record the AST id of the CallIC being compiled, so that it can be placed |
| 1124 // in the relocation information. |
| 1125 void SetRecordedAstId(TypeFeedbackId ast_id) { |
| 1126 // PPC - this shouldn't be failing roohack ASSERT(recorded_ast_id_.IsNone()); |
| 1127 recorded_ast_id_ = ast_id; |
| 1128 } |
| 1129 |
| 1130 TypeFeedbackId RecordedAstId() { |
| 1131 // roohack - another issue??? ASSERT(!recorded_ast_id_.IsNone()); |
| 1132 return recorded_ast_id_; |
| 1133 } |
| 1134 |
| 1135 void ClearRecordedAstId() { recorded_ast_id_ = TypeFeedbackId::None(); } |
| 1136 |
| 1137 // Record a comment relocation entry that can be used by a disassembler. |
| 1138 // Use --code-comments to enable. |
| 1139 void RecordComment(const char* msg); |
| 1140 |
| 1141 // Writes a single byte or word of data in the code stream. Used |
| 1142 // for inline tables, e.g., jump-tables. |
| 1143 void db(uint8_t data); |
| 1144 void dd(uint32_t data); |
| 1145 void emit_ptr(uintptr_t data); |
| 1146 |
| 1147 PositionsRecorder* positions_recorder() { return &positions_recorder_; } |
| 1148 |
| 1149 // Read/patch instructions |
| 1150 Instr instr_at(int pos) { return *reinterpret_cast<Instr*>(buffer_ + pos); } |
| 1151 void instr_at_put(int pos, Instr instr) { |
| 1152 *reinterpret_cast<Instr*>(buffer_ + pos) = instr; |
| 1153 } |
| 1154 static Instr instr_at(byte* pc) { return *reinterpret_cast<Instr*>(pc); } |
| 1155 static void instr_at_put(byte* pc, Instr instr) { |
| 1156 *reinterpret_cast<Instr*>(pc) = instr; |
| 1157 } |
| 1158 static Condition GetCondition(Instr instr); |
| 1159 |
| 1160 static bool IsLis(Instr instr); |
| 1161 static bool IsLi(Instr instr); |
| 1162 static bool IsAddic(Instr instr); |
| 1163 static bool IsOri(Instr instr); |
| 1164 |
| 1165 static bool IsBranch(Instr instr); |
| 1166 static Register GetRA(Instr instr); |
| 1167 static Register GetRB(Instr instr); |
| 1168 #if V8_TARGET_ARCH_PPC64 |
| 1169 static bool Is64BitLoadIntoR12(Instr instr1, Instr instr2, |
| 1170 Instr instr3, Instr instr4, Instr instr5); |
| 1171 #else |
| 1172 static bool Is32BitLoadIntoR12(Instr instr1, Instr instr2); |
| 1173 #endif |
| 1174 |
| 1175 static bool IsCmpRegister(Instr instr); |
| 1176 static bool IsCmpImmediate(Instr instr); |
| 1177 static bool IsRlwinm(Instr instr); |
| 1178 #if V8_TARGET_ARCH_PPC64 |
| 1179 static bool IsRldicl(Instr instr); |
| 1180 #endif |
| 1181 static bool IsCrSet(Instr instr); |
| 1182 static Register GetCmpImmediateRegister(Instr instr); |
| 1183 static int GetCmpImmediateRawImmediate(Instr instr); |
| 1184 static bool IsNop(Instr instr, int type = NON_MARKING_NOP); |
| 1185 |
| 1186 // Postpone the generation of the trampoline pool for the specified number of |
| 1187 // instructions. |
| 1188 void BlockTrampolinePoolFor(int instructions); |
| 1189 void CheckTrampolinePool(); |
| 1190 |
| 1191 int instructions_required_for_mov(const Operand& x) const; |
| 1192 |
| 1193 #if V8_OOL_CONSTANT_POOL |
| 1194 // Decide between using the constant pool vs. a mov immediate sequence. |
| 1195 bool use_constant_pool_for_mov(const Operand& x, bool canOptimize) const; |
| 1196 #endif |
| 1197 |
| 1198 // Allocate a constant pool of the correct size for the generated code. |
| 1199 Handle<ConstantPoolArray> NewConstantPool(Isolate* isolate); |
| 1200 |
| 1201 // Generate the constant pool for the generated code. |
| 1202 void PopulateConstantPool(ConstantPoolArray* constant_pool); |
| 1203 |
| 1204 #if V8_OOL_CONSTANT_POOL |
| 1205 bool is_constant_pool_available() const { return constant_pool_available_; } |
| 1206 |
| 1207 bool use_extended_constant_pool() const { |
| 1208 return constant_pool_builder_.current_section() == |
| 1209 ConstantPoolArray::EXTENDED_SECTION; |
| 1210 } |
| 1211 #endif |
| 1212 |
| 1213 #if ABI_USES_FUNCTION_DESCRIPTORS || V8_OOL_CONSTANT_POOL |
| 1214 static void RelocateInternalReference(Address pc, intptr_t delta, |
| 1215 Address code_start, |
| 1216 ICacheFlushMode icache_flush_mode = |
| 1217 FLUSH_ICACHE_IF_NEEDED); |
| 1218 static int DecodeInternalReference(Vector<char> buffer, Address pc); |
| 1219 #endif |
| 1220 |
| 1221 protected: |
| 1222 // Relocation for a type-recording IC has the AST id added to it. This |
| 1223 // member variable is a way to pass the information from the call site to |
| 1224 // the relocation info. |
| 1225 TypeFeedbackId recorded_ast_id_; |
| 1226 |
| 1227 int buffer_space() const { return reloc_info_writer.pos() - pc_; } |
| 1228 |
| 1229 // Decode branch instruction at pos and return branch target pos |
| 1230 int target_at(int pos); |
| 1231 |
| 1232 // Patch branch instruction at pos to branch to given branch target pos |
| 1233 void target_at_put(int pos, int target_pos); |
| 1234 |
| 1235 // Record reloc info for current pc_ |
| 1236 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0); |
| 1237 void RecordRelocInfo(const RelocInfo& rinfo); |
| 1238 #if V8_OOL_CONSTANT_POOL |
| 1239 ConstantPoolArray::LayoutSection ConstantPoolAddEntry( |
| 1240 const RelocInfo& rinfo) { |
| 1241 return constant_pool_builder_.AddEntry(this, rinfo); |
| 1242 } |
| 1243 #endif |
| 1244 |
| 1245 // Block the emission of the trampoline pool before pc_offset. |
| 1246 void BlockTrampolinePoolBefore(int pc_offset) { |
| 1247 if (no_trampoline_pool_before_ < pc_offset) |
| 1248 no_trampoline_pool_before_ = pc_offset; |
| 1249 } |
| 1250 |
| 1251 void StartBlockTrampolinePool() { |
| 1252 trampoline_pool_blocked_nesting_++; |
| 1253 } |
| 1254 |
| 1255 void EndBlockTrampolinePool() { |
| 1256 trampoline_pool_blocked_nesting_--; |
| 1257 } |
| 1258 |
| 1259 bool is_trampoline_pool_blocked() const { |
| 1260 return trampoline_pool_blocked_nesting_ > 0; |
| 1261 } |
| 1262 |
| 1263 bool has_exception() const { |
| 1264 return internal_trampoline_exception_; |
| 1265 } |
| 1266 |
| 1267 bool is_trampoline_emitted() const { |
| 1268 return trampoline_emitted_; |
| 1269 } |
| 1270 |
| 1271 #if V8_OOL_CONSTANT_POOL |
| 1272 void set_constant_pool_available(bool available) { |
| 1273 constant_pool_available_ = available; |
| 1274 } |
| 1275 #endif |
| 1276 |
| 1277 private: |
| 1278 // Code generation |
| 1279 // The relocation writer's position is at least kGap bytes below the end of |
| 1280 // the generated instructions. This is so that multi-instruction sequences do |
| 1281 // not have to check for overflow. The same is true for writes of large |
| 1282 // relocation info entries. |
| 1283 static const int kGap = 32; |
| 1284 |
| 1285 // Repeated checking whether the trampoline pool should be emitted is rather |
| 1286 // expensive. By default we only check again once a number of instructions |
| 1287 // has been generated. |
| 1288 int next_buffer_check_; // pc offset of next buffer check. |
| 1289 |
| 1290 // Emission of the trampoline pool may be blocked in some code sequences. |
| 1291 int trampoline_pool_blocked_nesting_; // Block emission if this is not zero. |
| 1292 int no_trampoline_pool_before_; // Block emission before this pc offset. |
| 1293 |
| 1294 // Relocation info generation |
| 1295 // Each relocation is encoded as a variable size value |
| 1296 static const int kMaxRelocSize = RelocInfoWriter::kMaxSize; |
| 1297 RelocInfoWriter reloc_info_writer; |
| 1298 |
| 1299 // The bound position, before this we cannot do instruction elimination. |
| 1300 int last_bound_pos_; |
| 1301 |
| 1302 #if V8_OOL_CONSTANT_POOL |
| 1303 ConstantPoolBuilder constant_pool_builder_; |
| 1304 |
| 1305 // Indicates whether the constant pool can be accessed, which is only possible |
| 1306 // if kConstantPoolRegister points to the current code object's constant pool. |
| 1307 bool constant_pool_available_; |
| 1308 #endif |
| 1309 |
| 1310 // Code emission |
| 1311 inline void CheckBuffer(); |
| 1312 void GrowBuffer(); |
| 1313 inline void emit(Instr x); |
| 1314 inline void CheckTrampolinePoolQuick(); |
| 1315 |
| 1316 // Instruction generation |
| 1317 void a_form(Instr instr, DoubleRegister frt, DoubleRegister fra, |
| 1318 DoubleRegister frb, RCBit r); |
| 1319 void d_form(Instr instr, Register rt, Register ra, const intptr_t val, |
| 1320 bool signed_disp); |
| 1321 void x_form(Instr instr, Register ra, Register rs, Register rb, RCBit r); |
| 1322 void xo_form(Instr instr, Register rt, Register ra, Register rb, |
| 1323 OEBit o, RCBit r); |
| 1324 void md_form(Instr instr, Register ra, Register rs, int shift, int maskbit, |
| 1325 RCBit r); |
| 1326 void mds_form(Instr instr, Register ra, Register rs, Register rb, int maskbit, |
| 1327 RCBit r); |
| 1328 |
| 1329 // Labels |
| 1330 void print(Label* L); |
| 1331 int max_reach_from(int pos); |
| 1332 void bind_to(Label* L, int pos); |
| 1333 void next(Label* L); |
| 1334 |
| 1335 class Trampoline { |
| 1336 public: |
| 1337 Trampoline() { |
| 1338 next_slot_ = 0; |
| 1339 free_slot_count_ = 0; |
| 1340 } |
| 1341 Trampoline(int start, int slot_count) { |
| 1342 next_slot_ = start; |
| 1343 free_slot_count_ = slot_count; |
| 1344 } |
| 1345 int take_slot() { |
| 1346 int trampoline_slot = kInvalidSlotPos; |
| 1347 if (free_slot_count_ <= 0) { |
| 1348 // We have run out of space on trampolines. |
| 1349 // Make sure we fail in debug mode, so we become aware of each case |
| 1350 // when this happens. |
| 1351 ASSERT(0); |
| 1352 // Internal exception will be caught. |
| 1353 } else { |
| 1354 trampoline_slot = next_slot_; |
| 1355 free_slot_count_--; |
| 1356 next_slot_ += kTrampolineSlotsSize; |
| 1357 } |
| 1358 return trampoline_slot; |
| 1359 } |
| 1360 |
| 1361 private: |
| 1362 int next_slot_; |
| 1363 int free_slot_count_; |
| 1364 }; |
| 1365 |
| 1366 int32_t get_trampoline_entry(); |
| 1367 int unbound_labels_count_; |
| 1368 // If trampoline is emitted, generated code is becoming large. As |
| 1369 // this is already a slow case which can possibly break our code |
| 1370 // generation for the extreme case, we use this information to |
| 1371 // trigger different mode of branch instruction generation, where we |
| 1372 // no longer use a single branch instruction. |
| 1373 bool trampoline_emitted_; |
| 1374 static const int kTrampolineSlotsSize = kInstrSize; |
| 1375 static const int kMaxCondBranchReach = (1 << (16 - 1)) - 1; |
| 1376 static const int kMaxBlockTrampolineSectionSize = 64 * kInstrSize; |
| 1377 static const int kInvalidSlotPos = -1; |
| 1378 |
| 1379 Trampoline trampoline_; |
| 1380 bool internal_trampoline_exception_; |
| 1381 |
| 1382 friend class RegExpMacroAssemblerPPC; |
| 1383 friend class RelocInfo; |
| 1384 friend class CodePatcher; |
| 1385 friend class BlockTrampolinePoolScope; |
| 1386 #if V8_OOL_CONSTANT_POOL |
| 1387 friend class FrameAndConstantPoolScope; |
| 1388 friend class ConstantPoolUnavailableScope; |
| 1389 #endif |
| 1390 |
| 1391 PositionsRecorder positions_recorder_; |
| 1392 friend class PositionsRecorder; |
| 1393 friend class EnsureSpace; |
| 1394 }; |
| 1395 |
| 1396 |
| 1397 class EnsureSpace BASE_EMBEDDED { |
| 1398 public: |
| 1399 explicit EnsureSpace(Assembler* assembler) { |
| 1400 assembler->CheckBuffer(); |
| 1401 } |
| 1402 }; |
| 1403 |
| 1404 } } // namespace v8::internal |
| 1405 |
| 1406 #endif // V8_PPC_ASSEMBLER_PPC_H_ |
OLD | NEW |