OLD | NEW |
---|---|
1 //===- subzero/src/IceAssemblerX86BaseImpl.h - base x86 assembler -*- C++ -*-=// | 1 //===- subzero/src/IceAssemblerX86BaseImpl.h - base x86 assembler -*- C++ -*-=// |
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 // | 5 // |
6 // Modified by the Subzero authors. | 6 // Modified by the Subzero authors. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // The Subzero Code Generator | 10 // The Subzero Code Generator |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 } | 145 } |
146 | 146 |
147 template <typename TraitsType> | 147 template <typename TraitsType> |
148 void AssemblerX86Base<TraitsType>::pushl(GPRRegister reg) { | 148 void AssemblerX86Base<TraitsType>::pushl(GPRRegister reg) { |
149 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 149 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
150 emitRexB(RexTypeIrrelevant, reg); | 150 emitRexB(RexTypeIrrelevant, reg); |
151 emitUint8(0x50 + gprEncoding(reg)); | 151 emitUint8(0x50 + gprEncoding(reg)); |
152 } | 152 } |
153 | 153 |
154 template <typename TraitsType> | 154 template <typename TraitsType> |
155 void AssemblerX86Base<TraitsType>::pushl(const Immediate &Imm) { | |
156 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | |
157 emitUint8(0x68); | |
158 emitInt32(Imm.value()); | |
159 } | |
160 | |
161 template <typename TraitsType> | |
162 void AssemblerX86Base<TraitsType>::pushl(const ConstantRelocatable *Label) { | |
163 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | |
164 intptr_t call_start = Buffer.getPosition(); | |
Jim Stichnoth
2016/01/14 00:09:52
CallStart
John
2016/01/14 23:18:25
Well, this is no longer needed, so I removed it.
| |
165 emitUint8(0x68); | |
166 emitFixup(this->createFixup(Traits::FK_Abs, Label)); | |
167 // In x86-32, the emitted value is an addend to the relocation. Therefore, | |
Jim Stichnoth
2016/01/14 00:09:52
Reflow to 80-col, I think
John
2016/01/14 23:18:25
Done.
| |
168 // we must emit a 0 (because we're pushing an absolute relocation.) | |
169 // In x86-64, the emitted value does not matter (the addend lives in the | |
170 // relocation record as an extra field.) | |
171 emitInt32(0); | |
172 assert((Buffer.getPosition() - call_start) == kCallExternalLabelSize); | |
173 (void)call_start; | |
174 } | |
175 | |
176 template <typename TraitsType> | |
155 void AssemblerX86Base<TraitsType>::popl(GPRRegister reg) { | 177 void AssemblerX86Base<TraitsType>::popl(GPRRegister reg) { |
156 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 178 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
157 // Any type that would not force a REX prefix to be emitted can be provided | 179 // Any type that would not force a REX prefix to be emitted can be provided |
158 // here. | 180 // here. |
159 emitRexB(RexTypeIrrelevant, reg); | 181 emitRexB(RexTypeIrrelevant, reg); |
160 emitUint8(0x58 + gprEncoding(reg)); | 182 emitUint8(0x58 + gprEncoding(reg)); |
161 } | 183 } |
162 | 184 |
163 template <typename TraitsType> | 185 template <typename TraitsType> |
164 void AssemblerX86Base<TraitsType>::popl(const Address &address) { | 186 void AssemblerX86Base<TraitsType>::popl(const Address &address) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 assert(Traits::Is64Bit && SrcTy == IceType_i32); | 397 assert(Traits::Is64Bit && SrcTy == IceType_i32); |
376 emitUint8(0x63); | 398 emitUint8(0x63); |
377 } | 399 } |
378 emitOperand(gprEncoding(dst), src); | 400 emitOperand(gprEncoding(dst), src); |
379 } | 401 } |
380 | 402 |
381 template <typename TraitsType> | 403 template <typename TraitsType> |
382 void AssemblerX86Base<TraitsType>::lea(Type Ty, GPRRegister dst, | 404 void AssemblerX86Base<TraitsType>::lea(Type Ty, GPRRegister dst, |
383 const Address &src) { | 405 const Address &src) { |
384 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 406 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
385 assert(Ty == IceType_i16 || Ty == IceType_i32); | 407 assert(Ty == IceType_i16 || Ty == IceType_i32 || |
408 (Traits::Is64Bit && Ty == IceType_i64)); | |
386 if (Ty == IceType_i16) | 409 if (Ty == IceType_i16) |
387 emitOperandSizeOverride(); | 410 emitOperandSizeOverride(); |
388 emitAddrSizeOverridePrefix(); | 411 emitAddrSizeOverridePrefix(); |
389 emitRex(Ty, src, dst); | 412 emitRex(Ty, src, dst); |
390 emitUint8(0x8D); | 413 emitUint8(0x8D); |
391 emitOperand(gprEncoding(dst), src); | 414 emitOperand(gprEncoding(dst), src); |
392 } | 415 } |
393 | 416 |
394 template <typename TraitsType> | 417 template <typename TraitsType> |
395 void AssemblerX86Base<TraitsType>::cmov(Type Ty, BrCond cond, GPRRegister dst, | 418 void AssemblerX86Base<TraitsType>::cmov(Type Ty, BrCond cond, GPRRegister dst, |
(...skipping 2737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3133 emitUint8(0xEB); | 3156 emitUint8(0xEB); |
3134 emitNearLabelLink(label); | 3157 emitNearLabelLink(label); |
3135 } else { | 3158 } else { |
3136 emitUint8(0xE9); | 3159 emitUint8(0xE9); |
3137 emitLabelLink(label); | 3160 emitLabelLink(label); |
3138 } | 3161 } |
3139 } | 3162 } |
3140 | 3163 |
3141 template <typename TraitsType> | 3164 template <typename TraitsType> |
3142 void AssemblerX86Base<TraitsType>::jmp(const ConstantRelocatable *label) { | 3165 void AssemblerX86Base<TraitsType>::jmp(const ConstantRelocatable *label) { |
3143 llvm::report_fatal_error("Untested - please verify and then reenable."); | |
3144 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 3166 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
3145 emitUint8(0xE9); | 3167 emitUint8(0xE9); |
3146 emitFixup(this->createFixup(Traits::FK_PcRel, label)); | 3168 emitFixup(this->createFixup(Traits::FK_PcRel, label)); |
3147 emitInt32(-4); | 3169 emitInt32(-4); |
3148 } | 3170 } |
3149 | 3171 |
3150 template <typename TraitsType> void AssemblerX86Base<TraitsType>::mfence() { | 3172 template <typename TraitsType> void AssemblerX86Base<TraitsType>::mfence() { |
3151 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 3173 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
3152 emitUint8(0x0F); | 3174 emitUint8(0x0F); |
3153 emitUint8(0xAE); | 3175 emitUint8(0xAE); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3300 nop(MAX_NOP_SIZE); | 3322 nop(MAX_NOP_SIZE); |
3301 bytes_needed -= MAX_NOP_SIZE; | 3323 bytes_needed -= MAX_NOP_SIZE; |
3302 } | 3324 } |
3303 if (bytes_needed) { | 3325 if (bytes_needed) { |
3304 nop(bytes_needed); | 3326 nop(bytes_needed); |
3305 } | 3327 } |
3306 assert(((offset + Buffer.getPosition()) & (alignment - 1)) == 0); | 3328 assert(((offset + Buffer.getPosition()) & (alignment - 1)) == 0); |
3307 } | 3329 } |
3308 | 3330 |
3309 template <typename TraitsType> | 3331 template <typename TraitsType> |
3310 void AssemblerX86Base<TraitsType>::bind(Label *label) { | 3332 void AssemblerX86Base<TraitsType>::bind(Label *label) { |
Jim Stichnoth
2016/01/14 00:09:52
label==>Label while you're at it...
John
2016/01/14 23:18:25
Label is the type name. The code looks very confus
| |
3311 intptr_t bound = Buffer.size(); | 3333 const intptr_t Bound = Buffer.size(); |
3312 assert(!label->isBound()); // Labels can only be bound once. | 3334 assert(!label->isBound()); // Labels can only be bound once. |
3313 while (label->isLinked()) { | 3335 while (label->isLinked()) { |
3314 intptr_t position = label->getLinkPosition(); | 3336 const intptr_t Position = label->getLinkPosition(); |
3315 intptr_t next = Buffer.load<int32_t>(position); | 3337 const intptr_t Next = Buffer.load<int32_t>(Position); |
3316 Buffer.store<int32_t>(position, bound - (position + 4)); | 3338 const intptr_t Offset = Bound - (Position + 4); |
3317 label->Position = next; | 3339 Buffer.store<int32_t>(Position, Offset); |
3340 label->Position = Next; | |
3318 } | 3341 } |
3319 while (label->hasNear()) { | 3342 while (label->hasNear()) { |
3320 intptr_t position = label->getNearPosition(); | 3343 intptr_t Position = label->getNearPosition(); |
3321 intptr_t offset = bound - (position + 1); | 3344 const intptr_t Offset = Bound - (Position + 1); |
3322 assert(Utils::IsInt(8, offset)); | 3345 assert(Utils::IsInt(8, Offset)); |
3323 Buffer.store<int8_t>(position, offset); | 3346 Buffer.store<int8_t>(Position, Offset); |
3324 } | 3347 } |
3325 label->bindTo(bound); | 3348 label->bindTo(Bound); |
3326 } | 3349 } |
3327 | 3350 |
3328 template <typename TraitsType> | 3351 template <typename TraitsType> |
3329 void AssemblerX86Base<TraitsType>::emitOperand(int rm, const Operand &operand) { | 3352 void AssemblerX86Base<TraitsType>::emitOperand(int rm, const Operand &operand) { |
3330 assert(rm >= 0 && rm < 8); | 3353 assert(rm >= 0 && rm < 8); |
3331 const intptr_t length = operand.length_; | 3354 const intptr_t length = operand.length_; |
3332 assert(length > 0); | 3355 assert(length > 0); |
3333 intptr_t displacement_start = 1; | 3356 intptr_t displacement_start = 1; |
3334 // Emit the ModRM byte updated with the given RM value. | 3357 // Emit the ModRM byte updated with the given RM value. |
3335 assert((operand.encoding_[0] & 0x38) == 0); | 3358 assert((operand.encoding_[0] & 0x38) == 0); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3462 (void)shifter; | 3485 (void)shifter; |
3463 if (Ty == IceType_i16) | 3486 if (Ty == IceType_i16) |
3464 emitOperandSizeOverride(); | 3487 emitOperandSizeOverride(); |
3465 emitRexB(Ty, operand.rm()); | 3488 emitRexB(Ty, operand.rm()); |
3466 emitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3); | 3489 emitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3); |
3467 emitOperand(rm, operand); | 3490 emitOperand(rm, operand); |
3468 } | 3491 } |
3469 | 3492 |
3470 } // end of namespace X86NAMESPACE | 3493 } // end of namespace X86NAMESPACE |
3471 } // end of namespace Ice | 3494 } // end of namespace Ice |
OLD | NEW |