Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/assembler_ia32.h - Assembler for x86-32 ------*- C++ -*-===// | 1 //===- subzero/src/assembler_ia32.h - Assembler for x86-32 ------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 // | 6 // |
| 7 // Modified by the Subzero authors. | 7 // Modified by the Subzero authors. |
| 8 // | 8 // |
| 9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
| 10 // | 10 // |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 149 |
| 150 void SetFixup(AssemblerFixup *fixup) { fixup_ = fixup; } | 150 void SetFixup(AssemblerFixup *fixup) { fixup_ = fixup; } |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 uint8_t length_; | 153 uint8_t length_; |
| 154 uint8_t encoding_[6]; | 154 uint8_t encoding_[6]; |
| 155 AssemblerFixup *fixup_; | 155 AssemblerFixup *fixup_; |
| 156 | 156 |
| 157 explicit Operand(GPRRegister reg) : fixup_(nullptr) { SetModRM(3, reg); } | 157 explicit Operand(GPRRegister reg) : fixup_(nullptr) { SetModRM(3, reg); } |
| 158 | 158 |
| 159 // Get the operand encoding byte at the given index. | 159 /// Get the operand encoding byte at the given index. |
| 160 uint8_t encoding_at(intptr_t index) const { | 160 uint8_t encoding_at(intptr_t index) const { |
| 161 assert(index >= 0 && index < length_); | 161 assert(index >= 0 && index < length_); |
| 162 return encoding_[index]; | 162 return encoding_[index]; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Returns whether or not this operand is really the given register in | 165 /// Returns whether or not this operand is really the given register in |
| 166 // disguise. Used from the assembler to generate better encodings. | 166 /// disguise. Used from the assembler to generate better encodings. |
| 167 bool IsRegister(GPRRegister reg) const { | 167 bool IsRegister(GPRRegister reg) const { |
| 168 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only. | 168 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only. |
| 169 && ((encoding_[0] & 0x07) == reg); // Register codes match. | 169 && ((encoding_[0] & 0x07) == reg); // Register codes match. |
| 170 } | 170 } |
| 171 | 171 |
| 172 friend class AssemblerX8632; | 172 friend class AssemblerX8632; |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 class Address : public Operand { | 175 class Address : public Operand { |
| 176 public: | 176 public: |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 263 |
| 264 void FinalCheck() const { | 264 void FinalCheck() const { |
| 265 // Assert if label is being destroyed with unresolved branches pending. | 265 // Assert if label is being destroyed with unresolved branches pending. |
| 266 assert(!IsLinked()); | 266 assert(!IsLinked()); |
| 267 assert(!HasNear()); | 267 assert(!HasNear()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 // TODO(jvoung): why are labels offset by this? | 270 // TODO(jvoung): why are labels offset by this? |
| 271 static const uint32_t kWordSize = sizeof(uint32_t); | 271 static const uint32_t kWordSize = sizeof(uint32_t); |
| 272 | 272 |
| 273 // Returns the position for bound labels (branches that come after this | 273 /// Returns the position for bound labels (branches that come after this |
| 274 // are considered backward branches). Cannot be used for unused or linked | 274 /// are considered backward branches). Cannot be used for unused or linked |
| 275 // labels. | 275 /// labels. |
| 276 intptr_t Position() const { | 276 intptr_t Position() const { |
| 277 assert(IsBound()); | 277 assert(IsBound()); |
| 278 return -position_ - kWordSize; | 278 return -position_ - kWordSize; |
| 279 } | 279 } |
| 280 | 280 |
| 281 // Returns the position of an earlier branch instruction that was linked | 281 /// Returns the position of an earlier branch instruction that was linked |
| 282 // to this label (branches that use this are considered forward branches). | 282 /// to this label (branches that use this are considered forward branches). |
| 283 // The linked instructions form a linked list, of sorts, using the | 283 /// The linked instructions form a linked list, of sorts, using the |
| 284 // instruction's displacement field for the location of the next | 284 /// instruction's displacement field for the location of the next |
| 285 // instruction that is also linked to this label. | 285 /// instruction that is also linked to this label. |
| 286 intptr_t LinkPosition() const { | 286 intptr_t LinkPosition() const { |
| 287 assert(IsLinked()); | 287 assert(IsLinked()); |
| 288 return position_ - kWordSize; | 288 return position_ - kWordSize; |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Returns the position of an earlier branch instruction which | 291 /// Returns the position of an earlier branch instruction which |
| 292 // assumes that this label is "near", and bumps iterator to the | 292 /// assumes that this label is "near", and bumps iterator to the |
| 293 // next near position. | 293 /// next near position. |
| 294 intptr_t NearPosition() { | 294 intptr_t NearPosition() { |
| 295 assert(HasNear()); | 295 assert(HasNear()); |
| 296 return unresolved_near_positions_[--num_unresolved_]; | 296 return unresolved_near_positions_[--num_unresolved_]; |
| 297 } | 297 } |
| 298 | 298 |
| 299 bool IsBound() const { return position_ < 0; } | 299 bool IsBound() const { return position_ < 0; } |
| 300 bool IsLinked() const { return position_ > 0; } | 300 bool IsLinked() const { return position_ > 0; } |
| 301 bool IsUnused() const { return (position_ == 0) && (num_unresolved_ == 0); } | 301 bool IsUnused() const { return (position_ == 0) && (num_unresolved_ == 0); } |
| 302 bool HasNear() const { return num_unresolved_ != 0; } | 302 bool HasNear() const { return num_unresolved_ != 0; } |
| 303 | 303 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 | 375 |
| 376 bool fixupIsPCRel(FixupKind Kind) const override { | 376 bool fixupIsPCRel(FixupKind Kind) const override { |
| 377 // Currently assuming this is the only PC-rel relocation type used. | 377 // Currently assuming this is the only PC-rel relocation type used. |
| 378 return Kind == llvm::ELF::R_386_PC32; | 378 return Kind == llvm::ELF::R_386_PC32; |
| 379 } | 379 } |
| 380 | 380 |
| 381 static bool classof(const Assembler *Asm) { | 381 static bool classof(const Assembler *Asm) { |
| 382 return Asm->getKind() == Asm_X8632; | 382 return Asm->getKind() == Asm_X8632; |
| 383 } | 383 } |
| 384 | 384 |
| 385 // Operations to emit GPR instructions (and dispatch on operand type). | 385 /// Operations to emit GPR instructions (and dispatch on operand type). |
| 386 typedef void (AssemblerX8632::*TypedEmitGPR)(Type, GPRRegister); | 386 typedef void (AssemblerX8632::*TypedEmitGPR)(Type, GPRRegister); |
| 387 typedef void (AssemblerX8632::*TypedEmitAddr)(Type, const Address &); | 387 typedef void (AssemblerX8632::*TypedEmitAddr)(Type, const Address &); |
| 388 struct GPREmitterOneOp { | 388 struct GPREmitterOneOp { |
| 389 TypedEmitGPR Reg; | 389 TypedEmitGPR Reg; |
| 390 TypedEmitAddr Addr; | 390 TypedEmitAddr Addr; |
| 391 }; | 391 }; |
| 392 | 392 |
| 393 typedef void (AssemblerX8632::*TypedEmitGPRGPR)(Type, GPRRegister, | 393 typedef void (AssemblerX8632::*TypedEmitGPRGPR)(Type, GPRRegister, |
| 394 GPRRegister); | 394 GPRRegister); |
| 395 typedef void (AssemblerX8632::*TypedEmitGPRAddr)(Type, GPRRegister, | 395 typedef void (AssemblerX8632::*TypedEmitGPRAddr)(Type, GPRRegister, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 421 | 421 |
| 422 typedef void (AssemblerX8632::*TypedEmitAddrGPR)(Type, const Address &, | 422 typedef void (AssemblerX8632::*TypedEmitAddrGPR)(Type, const Address &, |
| 423 GPRRegister); | 423 GPRRegister); |
| 424 typedef void (AssemblerX8632::*TypedEmitAddrImm)(Type, const Address &, | 424 typedef void (AssemblerX8632::*TypedEmitAddrImm)(Type, const Address &, |
| 425 const Immediate &); | 425 const Immediate &); |
| 426 struct GPREmitterAddrOp { | 426 struct GPREmitterAddrOp { |
| 427 TypedEmitAddrGPR AddrGPR; | 427 TypedEmitAddrGPR AddrGPR; |
| 428 TypedEmitAddrImm AddrImm; | 428 TypedEmitAddrImm AddrImm; |
| 429 }; | 429 }; |
| 430 | 430 |
| 431 // Operations to emit XMM instructions (and dispatch on operand type). | 431 /// Operations to emit XMM instructions (and dispatch on operand type). |
| 432 typedef void (AssemblerX8632::*TypedEmitXmmXmm)(Type, XmmRegister, | 432 typedef void (AssemblerX8632::*TypedEmitXmmXmm)(Type, XmmRegister, |
| 433 XmmRegister); | 433 XmmRegister); |
| 434 typedef void (AssemblerX8632::*TypedEmitXmmAddr)(Type, XmmRegister, | 434 typedef void (AssemblerX8632::*TypedEmitXmmAddr)(Type, XmmRegister, |
| 435 const Address &); | 435 const Address &); |
| 436 struct XmmEmitterRegOp { | 436 struct XmmEmitterRegOp { |
| 437 TypedEmitXmmXmm XmmXmm; | 437 TypedEmitXmmXmm XmmXmm; |
| 438 TypedEmitXmmAddr XmmAddr; | 438 TypedEmitXmmAddr XmmAddr; |
| 439 }; | 439 }; |
| 440 | 440 |
| 441 typedef void (AssemblerX8632::*EmitXmmXmm)(XmmRegister, XmmRegister); | 441 typedef void (AssemblerX8632::*EmitXmmXmm)(XmmRegister, XmmRegister); |
| 442 typedef void (AssemblerX8632::*EmitXmmAddr)(XmmRegister, const Address &); | 442 typedef void (AssemblerX8632::*EmitXmmAddr)(XmmRegister, const Address &); |
| 443 typedef void (AssemblerX8632::*EmitAddrXmm)(const Address &, XmmRegister); | 443 typedef void (AssemblerX8632::*EmitAddrXmm)(const Address &, XmmRegister); |
| 444 struct XmmEmitterMovOps { | 444 struct XmmEmitterMovOps { |
| 445 EmitXmmXmm XmmXmm; | 445 EmitXmmXmm XmmXmm; |
| 446 EmitXmmAddr XmmAddr; | 446 EmitXmmAddr XmmAddr; |
| 447 EmitAddrXmm AddrXmm; | 447 EmitAddrXmm AddrXmm; |
| 448 }; | 448 }; |
| 449 | 449 |
| 450 typedef void (AssemblerX8632::*TypedEmitXmmImm)(Type, XmmRegister, | 450 typedef void (AssemblerX8632::*TypedEmitXmmImm)(Type, XmmRegister, |
| 451 const Immediate &); | 451 const Immediate &); |
| 452 | 452 |
| 453 struct XmmEmitterShiftOp { | 453 struct XmmEmitterShiftOp { |
| 454 TypedEmitXmmXmm XmmXmm; | 454 TypedEmitXmmXmm XmmXmm; |
| 455 TypedEmitXmmAddr XmmAddr; | 455 TypedEmitXmmAddr XmmAddr; |
| 456 TypedEmitXmmImm XmmImm; | 456 TypedEmitXmmImm XmmImm; |
| 457 }; | 457 }; |
| 458 | 458 |
| 459 // Cross Xmm/GPR cast instructions. | 459 /// Cross Xmm/GPR cast instructions. |
| 460 template <typename DReg_t, typename SReg_t> struct CastEmitterRegOp { | 460 template <typename DReg_t, typename SReg_t> struct CastEmitterRegOp { |
| 461 typedef void (AssemblerX8632::*TypedEmitRegs)(Type, DReg_t, SReg_t); | 461 typedef void (AssemblerX8632::*TypedEmitRegs)(Type, DReg_t, SReg_t); |
| 462 typedef void (AssemblerX8632::*TypedEmitAddr)(Type, DReg_t, | 462 typedef void (AssemblerX8632::*TypedEmitAddr)(Type, DReg_t, |
| 463 const Address &); | 463 const Address &); |
| 464 | 464 |
| 465 TypedEmitRegs RegReg; | 465 TypedEmitRegs RegReg; |
| 466 TypedEmitAddr RegAddr; | 466 TypedEmitAddr RegAddr; |
| 467 }; | 467 }; |
| 468 | 468 |
| 469 // Three operand (potentially) cross Xmm/GPR instructions. | 469 /// Three operand (potentially) cross Xmm/GPR instructions. |
| 470 // The last operand must be an immediate. | 470 /// The last operand must be an immediate. |
| 471 template <typename DReg_t, typename SReg_t> struct ThreeOpImmEmitter { | 471 template <typename DReg_t, typename SReg_t> struct ThreeOpImmEmitter { |
| 472 typedef void (AssemblerX8632::*TypedEmitRegRegImm)(Type, DReg_t, SReg_t, | 472 typedef void (AssemblerX8632::*TypedEmitRegRegImm)(Type, DReg_t, SReg_t, |
| 473 const Immediate &); | 473 const Immediate &); |
| 474 typedef void (AssemblerX8632::*TypedEmitRegAddrImm)(Type, DReg_t, | 474 typedef void (AssemblerX8632::*TypedEmitRegAddrImm)(Type, DReg_t, |
| 475 const Address &, | 475 const Address &, |
| 476 const Immediate &); | 476 const Immediate &); |
| 477 | 477 |
| 478 TypedEmitRegRegImm RegRegImm; | 478 TypedEmitRegRegImm RegRegImm; |
| 479 TypedEmitRegAddrImm RegAddrImm; | 479 TypedEmitRegAddrImm RegAddrImm; |
| 480 }; | 480 }; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 void bsr(Type Ty, GPRRegister dst, GPRRegister src); | 810 void bsr(Type Ty, GPRRegister dst, GPRRegister src); |
| 811 void bsr(Type Ty, GPRRegister dst, const Address &src); | 811 void bsr(Type Ty, GPRRegister dst, const Address &src); |
| 812 | 812 |
| 813 void bswap(Type Ty, GPRRegister reg); | 813 void bswap(Type Ty, GPRRegister reg); |
| 814 | 814 |
| 815 void bt(GPRRegister base, GPRRegister offset); | 815 void bt(GPRRegister base, GPRRegister offset); |
| 816 | 816 |
| 817 void ret(); | 817 void ret(); |
| 818 void ret(const Immediate &imm); | 818 void ret(const Immediate &imm); |
| 819 | 819 |
| 820 // 'size' indicates size in bytes and must be in the range 1..8. | 820 /// 'size' indicates size in bytes and must be in the range 1..8. |
| 821 void nop(int size = 1); | 821 void nop(int size = 1); |
| 822 void int3(); | 822 void int3(); |
| 823 void hlt(); | 823 void hlt(); |
| 824 void ud2(); | 824 void ud2(); |
| 825 | 825 |
| 826 void j(CondX86::BrCond condition, Label *label, bool near = kFarJump); | 826 void j(CondX86::BrCond condition, Label *label, bool near = kFarJump); |
| 827 void j(CondX86::BrCond condition, const ConstantRelocatable *label); | 827 void j(CondX86::BrCond condition, const ConstantRelocatable *label); |
| 828 | 828 |
| 829 void jmp(GPRRegister reg); | 829 void jmp(GPRRegister reg); |
| 830 void jmp(Label *label, bool near = kFarJump); | 830 void jmp(Label *label, bool near = kFarJump); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 const Immediate &immediate); | 863 const Immediate &immediate); |
| 864 void emitLabel(Label *label, intptr_t instruction_size); | 864 void emitLabel(Label *label, intptr_t instruction_size); |
| 865 void emitLabelLink(Label *label); | 865 void emitLabelLink(Label *label); |
| 866 void emitNearLabelLink(Label *label); | 866 void emitNearLabelLink(Label *label); |
| 867 | 867 |
| 868 void emitGenericShift(int rm, Type Ty, GPRRegister reg, const Immediate &imm); | 868 void emitGenericShift(int rm, Type Ty, GPRRegister reg, const Immediate &imm); |
| 869 void emitGenericShift(int rm, Type Ty, const Operand &operand, | 869 void emitGenericShift(int rm, Type Ty, const Operand &operand, |
| 870 GPRRegister shifter); | 870 GPRRegister shifter); |
| 871 | 871 |
| 872 typedef std::vector<Label *> LabelVector; | 872 typedef std::vector<Label *> LabelVector; |
| 873 // A vector of pool-allocated x86 labels for CFG nodes. | 873 /// A vector of pool-allocated x86 labels for CFG nodes. |
| 874 LabelVector CfgNodeLabels; | 874 LabelVector CfgNodeLabels; |
| 875 // A vector of pool-allocated x86 labels for Local labels. | 875 /// A vector of pool-allocated x86 labels for Local labels. |
| 876 LabelVector LocalLabels; | 876 LabelVector LocalLabels; |
| 877 | 877 |
| 878 Label *GetOrCreateLabel(SizeT Number, LabelVector &Labels); | 878 Label *GetOrCreateLabel(SizeT Number, LabelVector &Labels); |
| 879 | 879 |
| 880 // The arith_int() methods factor out the commonality between the encodings of | 880 /// The arith_int() methods factor out the commonality between the encodings o f |
|
jvoung (off chromium)
2015/06/30 22:05:47
wrap comment?
ascull
2015/07/06 19:29:08
Done.
| |
| 881 // add(), Or(), adc(), sbb(), And(), sub(), Xor(), and cmp(). The Tag | 881 /// add(), Or(), adc(), sbb(), And(), sub(), Xor(), and cmp(). The Tag |
| 882 // parameter is statically asserted to be less than 8. | 882 /// parameter is statically asserted to be less than 8. |
| 883 template <uint32_t Tag> | 883 template <uint32_t Tag> |
| 884 void arith_int(Type Ty, GPRRegister reg, const Immediate &imm); | 884 void arith_int(Type Ty, GPRRegister reg, const Immediate &imm); |
| 885 | 885 |
| 886 template <uint32_t Tag> | 886 template <uint32_t Tag> |
| 887 void arith_int(Type Ty, GPRRegister reg0, GPRRegister reg1); | 887 void arith_int(Type Ty, GPRRegister reg0, GPRRegister reg1); |
| 888 | 888 |
| 889 template <uint32_t Tag> | 889 template <uint32_t Tag> |
| 890 void arith_int(Type Ty, GPRRegister reg, const Address &address); | 890 void arith_int(Type Ty, GPRRegister reg, const Address &address); |
| 891 | 891 |
| 892 template <uint32_t Tag> | 892 template <uint32_t Tag> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 920 inline void AssemblerX8632::emitFixup(AssemblerFixup *fixup) { | 920 inline void AssemblerX8632::emitFixup(AssemblerFixup *fixup) { |
| 921 Buffer.emitFixup(fixup); | 921 Buffer.emitFixup(fixup); |
| 922 } | 922 } |
| 923 | 923 |
| 924 inline void AssemblerX8632::emitOperandSizeOverride() { emitUint8(0x66); } | 924 inline void AssemblerX8632::emitOperandSizeOverride() { emitUint8(0x66); } |
| 925 | 925 |
| 926 } // end of namespace X8632 | 926 } // end of namespace X8632 |
| 927 } // end of namespace Ice | 927 } // end of namespace Ice |
| 928 | 928 |
| 929 #endif // SUBZERO_SRC_ICEASSEMBLERX8632_H | 929 #endif // SUBZERO_SRC_ICEASSEMBLERX8632_H |
| OLD | NEW |